This commit is contained in:
Virtuworks 2015-01-10 10:34:27 -05:00
commit 4bdedeb25f
11 changed files with 226 additions and 22 deletions

View file

@ -543,8 +543,9 @@ namespace WebsitePanel.EnterpriseServer {
/// <remarks/> /// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/GetFreeRdsServersPaged", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/GetFreeRdsServersPaged", RequestNamespace="http://smbsaas/websitepanel/enterpriseserver", ResponseNamespace="http://smbsaas/websitepanel/enterpriseserver", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public RdsServersPaged GetFreeRdsServersPaged(string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows) { public RdsServersPaged GetFreeRdsServersPaged(int packageId, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows) {
object[] results = this.Invoke("GetFreeRdsServersPaged", new object[] { object[] results = this.Invoke("GetFreeRdsServersPaged", new object[] {
packageId,
filterColumn, filterColumn,
filterValue, filterValue,
sortColumn, sortColumn,
@ -554,8 +555,9 @@ namespace WebsitePanel.EnterpriseServer {
} }
/// <remarks/> /// <remarks/>
public System.IAsyncResult BeginGetFreeRdsServersPaged(string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows, System.AsyncCallback callback, object asyncState) { public System.IAsyncResult BeginGetFreeRdsServersPaged(int packageId, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetFreeRdsServersPaged", new object[] { return this.BeginInvoke("GetFreeRdsServersPaged", new object[] {
packageId,
filterColumn, filterColumn,
filterValue, filterValue,
sortColumn, sortColumn,
@ -570,16 +572,17 @@ namespace WebsitePanel.EnterpriseServer {
} }
/// <remarks/> /// <remarks/>
public void GetFreeRdsServersPagedAsync(string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows) { public void GetFreeRdsServersPagedAsync(int packageId, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows) {
this.GetFreeRdsServersPagedAsync(filterColumn, filterValue, sortColumn, startRow, maximumRows, null); this.GetFreeRdsServersPagedAsync(packageId, filterColumn, filterValue, sortColumn, startRow, maximumRows, null);
} }
/// <remarks/> /// <remarks/>
public void GetFreeRdsServersPagedAsync(string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows, object userState) { public void GetFreeRdsServersPagedAsync(int packageId, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows, object userState) {
if ((this.GetFreeRdsServersPagedOperationCompleted == null)) { if ((this.GetFreeRdsServersPagedOperationCompleted == null)) {
this.GetFreeRdsServersPagedOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetFreeRdsServersPagedOperationCompleted); this.GetFreeRdsServersPagedOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetFreeRdsServersPagedOperationCompleted);
} }
this.InvokeAsync("GetFreeRdsServersPaged", new object[] { this.InvokeAsync("GetFreeRdsServersPaged", new object[] {
packageId,
filterColumn, filterColumn,
filterValue, filterValue,
sortColumn, sortColumn,

View file

@ -93,9 +93,9 @@ namespace WebsitePanel.EnterpriseServer
return GetRdsServersPagedInternal(filterColumn, filterValue, sortColumn, startRow, maximumRows); return GetRdsServersPagedInternal(filterColumn, filterValue, sortColumn, startRow, maximumRows);
} }
public static RdsServersPaged GetFreeRdsServersPaged(string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows) public static RdsServersPaged GetFreeRdsServersPaged(int packageId, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows)
{ {
return GetFreeRdsServersPagedInternal(filterColumn, filterValue, sortColumn, startRow, maximumRows); return GetFreeRdsServersPagedInternal(packageId, filterColumn, filterValue, sortColumn, startRow, maximumRows);
} }
public static RdsServersPaged GetOrganizationRdsServersPaged(int itemId, int? collectionId, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows) public static RdsServersPaged GetOrganizationRdsServersPaged(int itemId, int? collectionId, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows)
@ -477,17 +477,26 @@ namespace WebsitePanel.EnterpriseServer
return result; return result;
} }
private static RdsServersPaged GetFreeRdsServersPagedInternal(string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows) private static RdsServersPaged GetFreeRdsServersPagedInternal(int itemId, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows)
{ {
DataSet ds = DataProvider.GetRDSServersPaged(null, null, filterColumn, filterValue, sortColumn, startRow, maximumRows);
RdsServersPaged result = new RdsServersPaged(); RdsServersPaged result = new RdsServersPaged();
Organization org = OrganizationController.GetOrganization(itemId);
if (org == null)
{
return result;
}
var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
var existingServers = rds.GetServersExistingInCollections();
DataSet ds = DataProvider.GetRDSServersPaged(null, null, filterColumn, filterValue, sortColumn, startRow, maximumRows);
result.RecordsCount = (int)ds.Tables[0].Rows[0][0]; result.RecordsCount = (int)ds.Tables[0].Rows[0][0];
List<RdsServer> tmpServers = new List<RdsServer>(); List<RdsServer> tmpServers = new List<RdsServer>();
ObjectUtils.FillCollectionFromDataView(tmpServers, ds.Tables[1].DefaultView); ObjectUtils.FillCollectionFromDataView(tmpServers, ds.Tables[1].DefaultView);
tmpServers = tmpServers.Where(x => !existingServers.Select(y => y.ToUpper()).Contains(x.FqdName.ToUpper())).ToList();
result.Servers = tmpServers.ToArray(); result.Servers = tmpServers.ToArray();
return result; return result;

View file

@ -99,10 +99,10 @@ namespace WebsitePanel.EnterpriseServer
} }
[WebMethod] [WebMethod]
public RdsServersPaged GetFreeRdsServersPaged(string filterColumn, string filterValue, public RdsServersPaged GetFreeRdsServersPaged(int packageId, string filterColumn, string filterValue,
string sortColumn, int startRow, int maximumRows) string sortColumn, int startRow, int maximumRows)
{ {
return RemoteDesktopServicesController.GetFreeRdsServersPaged(filterColumn, filterValue, return RemoteDesktopServicesController.GetFreeRdsServersPaged(packageId, filterColumn, filterValue,
sortColumn, startRow, maximumRows); sortColumn, startRow, maximumRows);
} }

View file

@ -64,5 +64,6 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
string[] GetApplicationUsers(string collectionName, string applicationName); string[] GetApplicationUsers(string collectionName, string applicationName);
bool SetApplicationUsers(string collectionName, RemoteApplication remoteApp, string[] users); bool SetApplicationUsers(string collectionName, RemoteApplication remoteApp, string[] users);
bool CheckRDSServerAvaliable(string hostname); bool CheckRDSServerAvaliable(string hostname);
List<string> GetServersExistingInCollections();
} }
} }

View file

@ -220,7 +220,15 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
try try
{ {
runSpace = OpenRunspace(); runSpace = OpenRunspace();
var existingServers = GetServersExistingInCollections(runSpace);
existingServers = existingServers.Select(x => x.ToUpper()).Intersect(collection.Servers.Select(x => x.FqdName.ToUpper())).ToList();
if (existingServers.Any())
{
throw new Exception(string.Format("Server{0} {1} already added to another collection", existingServers.Count == 1 ? "" : "s", string.Join(" ,", existingServers.ToArray())));
}
foreach (var server in collection.Servers) foreach (var server in collection.Servers)
{ {
@ -302,6 +310,24 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
return result; return result;
} }
public List<string> GetServersExistingInCollections()
{
Runspace runSpace = null;
List<string> existingServers = new List<string>();
try
{
runSpace = OpenRunspace();
existingServers = GetServersExistingInCollections(runSpace);
}
finally
{
CloseRunspace(runSpace);
}
return existingServers;
}
public RdsCollection GetCollection(string collectionName) public RdsCollection GetCollection(string collectionName)
{ {
RdsCollection collection =null; RdsCollection collection =null;
@ -1380,6 +1406,23 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
return ExecuteShellCommand(runSpace, invokeCommand, false); return ExecuteShellCommand(runSpace, invokeCommand, false);
} }
internal Collection<PSObject> ExecuteRemoteShellCommand(Runspace runSpace, string hostName, List<string> scripts, params string[] moduleImports)
{
Command invokeCommand = new Command("Invoke-Command");
invokeCommand.Parameters.Add("ComputerName", hostName);
RunspaceInvoke invoke = new RunspaceInvoke();
string commandString = moduleImports.Any() ? string.Format("import-module {0};", string.Join(",", moduleImports)) : string.Empty;
commandString = string.Format("{0};{1}", commandString, string.Join(";", scripts.ToArray()));
ScriptBlock sb = invoke.Invoke(string.Format("{{{0}}}", commandString))[0].BaseObject as ScriptBlock;
invokeCommand.Parameters.Add("ScriptBlock", sb);
return ExecuteShellCommand(runSpace, invokeCommand, false);
}
internal Collection<PSObject> ExecuteShellCommand(Runspace runSpace, Command cmd) internal Collection<PSObject> ExecuteShellCommand(Runspace runSpace, Command cmd)
{ {
return ExecuteShellCommand(runSpace, cmd, true); return ExecuteShellCommand(runSpace, cmd, true);
@ -1396,6 +1439,38 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
return ExecuteShellCommand(runSpace, cmd, true, out errors); return ExecuteShellCommand(runSpace, cmd, true, out errors);
} }
internal Collection<PSObject> ExecuteShellCommand(Runspace runspace, List<string> scripts, out object[] errors)
{
Log.WriteStart("ExecuteShellCommand");
var errorList = new List<object>();
Collection<PSObject> results;
using (Pipeline pipeLine = runspace.CreatePipeline())
{
foreach (string script in scripts)
{
pipeLine.Commands.AddScript(script);
}
results = pipeLine.Invoke();
if (pipeLine.Error != null && pipeLine.Error.Count > 0)
{
foreach (object item in pipeLine.Error.ReadToEnd())
{
errorList.Add(item);
string errorMessage = string.Format("Invoke error: {0}", item);
Log.WriteWarning(errorMessage);
}
}
}
errors = errorList.ToArray();
Log.WriteEnd("ExecuteShellCommand");
return results;
}
internal Collection<PSObject> ExecuteShellCommand(Runspace runSpace, Command cmd, bool useDomainController, internal Collection<PSObject> ExecuteShellCommand(Runspace runSpace, Command cmd, bool useDomainController,
out object[] errors) out object[] errors)
{ {
@ -1517,6 +1592,29 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
return result; return result;
} }
internal List<string> GetServersExistingInCollections(Runspace runSpace)
{
var existingHosts = new List<string>();
var scripts = new List<string>();
scripts.Add(string.Format("$sessions = Get-RDSessionCollection -ConnectionBroker {0}", ConnectionBroker));
scripts.Add(string.Format("foreach($session in $sessions){{Get-RDSessionHost $session.CollectionName -ConnectionBroker {0}|Select SessionHost}}", ConnectionBroker));
object[] errors;
var sessionHosts = ExecuteShellCommand(runSpace, scripts, out errors);
foreach(var host in sessionHosts)
{
var sessionHost = GetPSObjectProperty(host, "SessionHost");
if (sessionHost != null)
{
existingHosts.Add(sessionHost.ToString());
}
}
return existingHosts;
}
#endregion #endregion
} }
} }

View file

@ -99,6 +99,8 @@ namespace WebsitePanel.Providers.RemoteDesktopServices {
private System.Threading.SendOrPostCallback CheckRDSServerAvaliableOperationCompleted; private System.Threading.SendOrPostCallback CheckRDSServerAvaliableOperationCompleted;
private System.Threading.SendOrPostCallback GetServersExistingInCollectionsOperationCompleted;
/// <remarks/> /// <remarks/>
public RemoteDesktopServices() { public RemoteDesktopServices() {
this.Url = "http://localhost:9003/RemoteDesktopServices.asmx"; this.Url = "http://localhost:9003/RemoteDesktopServices.asmx";
@ -167,6 +169,9 @@ namespace WebsitePanel.Providers.RemoteDesktopServices {
/// <remarks/> /// <remarks/>
public event CheckRDSServerAvaliableCompletedEventHandler CheckRDSServerAvaliableCompleted; public event CheckRDSServerAvaliableCompletedEventHandler CheckRDSServerAvaliableCompleted;
/// <remarks/>
public event GetServersExistingInCollectionsCompletedEventHandler GetServersExistingInCollectionsCompleted;
/// <remarks/> /// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")] [System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/CreateCollection", RequestNamespace="http://smbsaas/websitepanel/server/", ResponseNamespace="http://smbsaas/websitepanel/server/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/CreateCollection", RequestNamespace="http://smbsaas/websitepanel/server/", ResponseNamespace="http://smbsaas/websitepanel/server/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
@ -1096,6 +1101,45 @@ namespace WebsitePanel.Providers.RemoteDesktopServices {
} }
} }
/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/GetServersExistingInCollections", RequestNamespace="http://smbsaas/websitepanel/server/", ResponseNamespace="http://smbsaas/websitepanel/server/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string[] GetServersExistingInCollections() {
object[] results = this.Invoke("GetServersExistingInCollections", new object[0]);
return ((string[])(results[0]));
}
/// <remarks/>
public System.IAsyncResult BeginGetServersExistingInCollections(System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetServersExistingInCollections", new object[0], callback, asyncState);
}
/// <remarks/>
public string[] EndGetServersExistingInCollections(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((string[])(results[0]));
}
/// <remarks/>
public void GetServersExistingInCollectionsAsync() {
this.GetServersExistingInCollectionsAsync(null);
}
/// <remarks/>
public void GetServersExistingInCollectionsAsync(object userState) {
if ((this.GetServersExistingInCollectionsOperationCompleted == null)) {
this.GetServersExistingInCollectionsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetServersExistingInCollectionsOperationCompleted);
}
this.InvokeAsync("GetServersExistingInCollections", new object[0], this.GetServersExistingInCollectionsOperationCompleted, userState);
}
private void OnGetServersExistingInCollectionsOperationCompleted(object arg) {
if ((this.GetServersExistingInCollectionsCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.GetServersExistingInCollectionsCompleted(this, new GetServersExistingInCollectionsCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/> /// <remarks/>
public new void CancelAsync(object userState) { public new void CancelAsync(object userState) {
base.CancelAsync(userState); base.CancelAsync(userState);
@ -1537,4 +1581,30 @@ namespace WebsitePanel.Providers.RemoteDesktopServices {
} }
} }
} }
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
public delegate void GetServersExistingInCollectionsCompletedEventHandler(object sender, GetServersExistingInCollectionsCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class GetServersExistingInCollectionsCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal GetServersExistingInCollectionsCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public string[] Result {
get {
this.RaiseExceptionIfNecessary();
return ((string[])(this.results[0]));
}
}
}
} }

View file

@ -410,5 +410,22 @@ namespace WebsitePanel.Server
throw; throw;
} }
} }
[WebMethod, SoapHeader("settings")]
public List<string> GetServersExistingInCollections()
{
try
{
Log.WriteStart("'{0}' GetServersExistingInCollections", ProviderSettings.ProviderName);
var result = RDSProvider.GetServersExistingInCollections();
Log.WriteEnd("'{0}' GetServersExistingInCollections", ProviderSettings.ProviderName);
return result;
}
catch (Exception ex)
{
Log.WriteError(String.Format("'{0}' GetServersExistingInCollections", ProviderSettings.ProviderName), ex);
throw;
}
}
} }
} }

View file

@ -5626,4 +5626,7 @@
<data name="ERROR.IDNDOMAIN_NO_ORGANIZATION" xml:space="preserve"> <data name="ERROR.IDNDOMAIN_NO_ORGANIZATION" xml:space="preserve">
<value>You cannot use a IDN domain name for organizations</value> <value>You cannot use a IDN domain name for organizations</value>
</data> </data>
<data name="ERROR.RDSCOLLECTION_NOT_CREATED" xml:space="preserve">
<value>Collection not created</value>
</data>
</root> </root>

View file

@ -71,9 +71,9 @@ namespace WebsitePanel.Portal
return rdsServers.Servers; return rdsServers.Servers;
} }
public RdsServer[] GetFreeRDSServers() public RdsServer[] GetFreeRDSServers(int packageId)
{ {
return ES.Services.RDS.GetFreeRdsServersPaged("", "", "", 0, 1000).Servers; return ES.Services.RDS.GetFreeRdsServersPaged(packageId, "", "", "", 0, 1000).Servers;
} }
#endregion #endregion

View file

@ -50,7 +50,7 @@ namespace WebsitePanel.Portal.RDS
private void BindRDSServers() private void BindRDSServers()
{ {
ddlServers.DataSource = new RDSHelper().GetFreeRDSServers(); ddlServers.DataSource = new RDSHelper().GetFreeRDSServers(PanelRequest.ItemID);
ddlServers.DataTextField = "Name"; ddlServers.DataTextField = "Name";
ddlServers.DataValueField = "Id"; ddlServers.DataValueField = "Id";
ddlServers.DataBind(); ddlServers.DataBind();

View file

@ -50,7 +50,9 @@ namespace WebsitePanel.Portal.RDS
protected void btnSave_Click(object sender, EventArgs e) protected void btnSave_Click(object sender, EventArgs e)
{ {
if (!Page.IsValid) if (!Page.IsValid)
{
return; return;
}
try try
{ {
@ -59,14 +61,15 @@ namespace WebsitePanel.Portal.RDS
messageBox.ShowErrorMessage("RDS_CREATE_COLLECTION_RDSSERVER_REQUAIRED"); messageBox.ShowErrorMessage("RDS_CREATE_COLLECTION_RDSSERVER_REQUAIRED");
return; return;
} }
RdsCollection collection = new RdsCollection{ Name = txtCollectionName.Text, Servers = servers.GetServers(), Description = "" }; RdsCollection collection = new RdsCollection{ Name = txtCollectionName.Text, Servers = servers.GetServers(), Description = "" };
ES.Services.RDS.AddRdsCollection(PanelRequest.ItemID, collection); ES.Services.RDS.AddRdsCollection(PanelRequest.ItemID, collection);
Response.Redirect(EditUrl("ItemID", PanelRequest.ItemID.ToString(), "rds_collections", "SpaceID=" + PanelSecurity.PackageId));
Response.Redirect(EditUrl("ItemID", PanelRequest.ItemID.ToString(), "rds_collections", }
"SpaceID=" + PanelSecurity.PackageId)); catch (Exception ex)
{
messageBox.ShowErrorMessage("RDSCOLLECTION_NOT_CREATED", ex);
} }
catch { }
} }
} }
} }