diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/RemoteDesktopServicesProxy.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/RemoteDesktopServicesProxy.cs index aa2f44e7..bf847f10 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/RemoteDesktopServicesProxy.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/RemoteDesktopServicesProxy.cs @@ -104,6 +104,8 @@ namespace WebsitePanel.EnterpriseServer { private System.Threading.SendOrPostCallback LogOffRdsUserOperationCompleted; + private System.Threading.SendOrPostCallback GetRdsCollectionSessionHostsOperationCompleted; + /// public esRemoteDesktopServices() { this.Url = "http://localhost:9002/esRemoteDesktopServices.asmx"; @@ -220,6 +222,9 @@ namespace WebsitePanel.EnterpriseServer { /// public event LogOffRdsUserCompletedEventHandler LogOffRdsUserCompleted; + /// + public event GetRdsCollectionSessionHostsCompletedEventHandler GetRdsCollectionSessionHostsCompleted; + /// [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/GetRdsCollection", 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 RdsCollection GetRdsCollection(int collectionId) { @@ -1898,6 +1903,47 @@ namespace WebsitePanel.EnterpriseServer { } } + /// + [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/enterpriseserver/GetRdsCollectionSessionHosts", 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 string[] GetRdsCollectionSessionHosts(int collectionId) { + object[] results = this.Invoke("GetRdsCollectionSessionHosts", new object[] { + collectionId}); + return ((string[])(results[0])); + } + + /// + public System.IAsyncResult BeginGetRdsCollectionSessionHosts(int collectionId, System.AsyncCallback callback, object asyncState) { + return this.BeginInvoke("GetRdsCollectionSessionHosts", new object[] { + collectionId}, callback, asyncState); + } + + /// + public string[] EndGetRdsCollectionSessionHosts(System.IAsyncResult asyncResult) { + object[] results = this.EndInvoke(asyncResult); + return ((string[])(results[0])); + } + + /// + public void GetRdsCollectionSessionHostsAsync(int collectionId) { + this.GetRdsCollectionSessionHostsAsync(collectionId, null); + } + + /// + public void GetRdsCollectionSessionHostsAsync(int collectionId, object userState) { + if ((this.GetRdsCollectionSessionHostsOperationCompleted == null)) { + this.GetRdsCollectionSessionHostsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetRdsCollectionSessionHostsOperationCompleted); + } + this.InvokeAsync("GetRdsCollectionSessionHosts", new object[] { + collectionId}, this.GetRdsCollectionSessionHostsOperationCompleted, userState); + } + + private void OnGetRdsCollectionSessionHostsOperationCompleted(object arg) { + if ((this.GetRdsCollectionSessionHostsCompleted != null)) { + System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg)); + this.GetRdsCollectionSessionHostsCompleted(this, new GetRdsCollectionSessionHostsCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)); + } + } + /// public new void CancelAsync(object userState) { base.CancelAsync(userState); @@ -2865,4 +2911,30 @@ namespace WebsitePanel.EnterpriseServer { } } } + + /// + [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] + public delegate void GetRdsCollectionSessionHostsCompletedEventHandler(object sender, GetRdsCollectionSessionHostsCompletedEventArgs e); + + /// + [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.ComponentModel.DesignerCategoryAttribute("code")] + public partial class GetRdsCollectionSessionHostsCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs { + + private object[] results; + + internal GetRdsCollectionSessionHostsCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : + base(exception, cancelled, userState) { + this.results = results; + } + + /// + public string[] Result { + get { + this.RaiseExceptionIfNecessary(); + return ((string[])(this.results[0])); + } + } + } } diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs index 8a9f9136..064ba20e 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/RemoteDesktopServices/RemoteDesktopServicesController.cs @@ -243,6 +243,11 @@ namespace WebsitePanel.EnterpriseServer return LogOffRdsUserInternal(itemId, unifiedSessionId, hostServer); } + public static List GetRdsCollectionSessionHosts(int collectionId) + { + return GetRdsCollectionSessionHostsInternal(collectionId); + } + private static RdsCollection GetRdsCollectionInternal(int collectionId) { var collection = ObjectUtils.FillObjectFromDataReader(DataProvider.GetRDSCollectionById(collectionId)); @@ -630,6 +635,23 @@ namespace WebsitePanel.EnterpriseServer return result; } + private static List GetRdsCollectionSessionHostsInternal(int collectionId) + { + var result = new List(); + var collection = ObjectUtils.FillObjectFromDataReader(DataProvider.GetRDSCollectionById(collectionId)); + Organization org = OrganizationController.GetOrganization(collection.ItemId); + + if (org == null) + { + return result; + } + + var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId)); + result = rds.GetRdsCollectionSessionHosts(collection.Name).ToList(); + + return result; + } + private static RdsServersPaged GetOrganizationRdsServersPagedInternal(int itemId, int? collectionId, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows) { DataSet ds = DataProvider.GetRDSServersPaged(itemId, collectionId, filterColumn, filterValue, sortColumn, startRow, maximumRows, ignoreRdsCollectionId: !collectionId.HasValue); diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esRemoteDesktopServices.asmx.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esRemoteDesktopServices.asmx.cs index de7dfb0f..82127d09 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esRemoteDesktopServices.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esRemoteDesktopServices.asmx.cs @@ -283,5 +283,11 @@ namespace WebsitePanel.EnterpriseServer { return RemoteDesktopServicesController.LogOffRdsUser(itemId, unifiedSessionId, hostServer); } + + [WebMethod] + public List GetRdsCollectionSessionHosts(int collectionId) + { + return RemoteDesktopServicesController.GetRdsCollectionSessionHosts(collectionId); + } } } diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs index 942d0ced..e434048d 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/RemoteDesktopServices/IRemoteDesktopServices.cs @@ -68,5 +68,6 @@ namespace WebsitePanel.Providers.RemoteDesktopServices void EditRdsCollectionSettings(RdsCollection collection); List GetRdsUserSessions(string collectionName); void LogOffRdsUser(string unifiedSessionId, string hostServer); + List GetRdsCollectionSessionHosts(string collectionName); } } diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs index 15cadff0..875c9844 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.TerminalServices.Windows2012/Windows2012.cs @@ -184,6 +184,35 @@ namespace WebsitePanel.Providers.RemoteDesktopServices #region RDS Collections + public List GetRdsCollectionSessionHosts(string collectionName) + { + var result = new List(); + Runspace runspace = null; + + try + { + runspace = OpenRunspace(); + + Command cmd = new Command("Get-RDSessionHost"); + cmd.Parameters.Add("CollectionName", collectionName); + cmd.Parameters.Add("ConnectionBroker", ConnectionBroker); + object[] errors; + + var hosts = ExecuteShellCommand(runspace, cmd, false, out errors); + + foreach (var host in hosts) + { + result.Add(GetPSObjectProperty(host, "SessionHost").ToString()); + } + } + finally + { + CloseRunspace(runspace); + } + + return result; + } + public bool AddRdsServersToDeployment(RdsServer[] servers) { var result = true; diff --git a/WebsitePanel/Sources/WebsitePanel.Server.Client/RemoteDesktopServicesProxy.cs b/WebsitePanel/Sources/WebsitePanel.Server.Client/RemoteDesktopServicesProxy.cs index 3f06e32a..d32659ee 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server.Client/RemoteDesktopServicesProxy.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server.Client/RemoteDesktopServicesProxy.cs @@ -79,6 +79,8 @@ namespace WebsitePanel.Providers.RemoteDesktopServices { private System.Threading.SendOrPostCallback LogOffRdsUserOperationCompleted; + private System.Threading.SendOrPostCallback GetRdsCollectionSessionHostsOperationCompleted; + /// public RemoteDesktopServices() { this.Url = "http://localhost:9003/RemoteDesktopServices.asmx"; @@ -159,6 +161,9 @@ namespace WebsitePanel.Providers.RemoteDesktopServices { /// public event LogOffRdsUserCompletedEventHandler LogOffRdsUserCompleted; + /// + public event GetRdsCollectionSessionHostsCompletedEventHandler GetRdsCollectionSessionHostsCompleted; + /// [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)] @@ -1252,6 +1257,48 @@ namespace WebsitePanel.Providers.RemoteDesktopServices { } } + /// + [System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")] + [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/GetRdsCollectionSessionHosts", 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[] GetRdsCollectionSessionHosts(string collectionName) { + object[] results = this.Invoke("GetRdsCollectionSessionHosts", new object[] { + collectionName}); + return ((string[])(results[0])); + } + + /// + public System.IAsyncResult BeginGetRdsCollectionSessionHosts(string collectionName, System.AsyncCallback callback, object asyncState) { + return this.BeginInvoke("GetRdsCollectionSessionHosts", new object[] { + collectionName}, callback, asyncState); + } + + /// + public string[] EndGetRdsCollectionSessionHosts(System.IAsyncResult asyncResult) { + object[] results = this.EndInvoke(asyncResult); + return ((string[])(results[0])); + } + + /// + public void GetRdsCollectionSessionHostsAsync(string collectionName) { + this.GetRdsCollectionSessionHostsAsync(collectionName, null); + } + + /// + public void GetRdsCollectionSessionHostsAsync(string collectionName, object userState) { + if ((this.GetRdsCollectionSessionHostsOperationCompleted == null)) { + this.GetRdsCollectionSessionHostsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetRdsCollectionSessionHostsOperationCompleted); + } + this.InvokeAsync("GetRdsCollectionSessionHosts", new object[] { + collectionName}, this.GetRdsCollectionSessionHostsOperationCompleted, userState); + } + + private void OnGetRdsCollectionSessionHostsOperationCompleted(object arg) { + if ((this.GetRdsCollectionSessionHostsCompleted != null)) { + System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg)); + this.GetRdsCollectionSessionHostsCompleted(this, new GetRdsCollectionSessionHostsCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)); + } + } + /// public new void CancelAsync(object userState) { base.CancelAsync(userState); @@ -1753,4 +1800,30 @@ namespace WebsitePanel.Providers.RemoteDesktopServices { /// [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] public delegate void LogOffRdsUserCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e); + + /// + [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] + public delegate void GetRdsCollectionSessionHostsCompletedEventHandler(object sender, GetRdsCollectionSessionHostsCompletedEventArgs e); + + /// + [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.ComponentModel.DesignerCategoryAttribute("code")] + public partial class GetRdsCollectionSessionHostsCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs { + + private object[] results; + + internal GetRdsCollectionSessionHostsCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : + base(exception, cancelled, userState) { + this.results = results; + } + + /// + public string[] Result { + get { + this.RaiseExceptionIfNecessary(); + return ((string[])(this.results[0])); + } + } + } } diff --git a/WebsitePanel/Sources/WebsitePanel.Server/RemoteDesktopServices.asmx.cs b/WebsitePanel/Sources/WebsitePanel.Server/RemoteDesktopServices.asmx.cs index 796a6448..cb3e79dd 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server/RemoteDesktopServices.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server/RemoteDesktopServices.asmx.cs @@ -477,5 +477,23 @@ namespace WebsitePanel.Server throw; } } + + [WebMethod, SoapHeader("settings")] + public List GetRdsCollectionSessionHosts(string collectionName) + { + try + { + Log.WriteStart("'{0}' GetRdsCollectionSessionHosts", ProviderSettings.ProviderName); + var result = RDSProvider.GetRdsCollectionSessionHosts(collectionName); + Log.WriteEnd("'{0}' GetRdsCollectionSessionHosts", ProviderSettings.ProviderName); + + return result; + } + catch(Exception ex) + { + Log.WriteError(String.Format("'{0}' GetRdsCollectionSessionHosts", ProviderSettings.ProviderName), ex); + throw; + } + } } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionApps.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionApps.ascx.cs index 403eea17..ba781532 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionApps.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/RDS/UserControls/RDSCollectionApps.ascx.cs @@ -110,15 +110,10 @@ namespace WebsitePanel.Portal.RDS.UserControls { RdsCollection collection = ES.Services.RDS.GetRdsCollection(PanelRequest.CollectionID); List apps = ES.Services.RDS.GetAvailableRemoteApplications(PanelRequest.ItemID, collection.Name).ToList(); + var sessionHosts = ES.Services.RDS.GetRdsCollectionSessionHosts(PanelRequest.CollectionID); - var fullRemote = new StartMenuApp - { - DisplayName = "Session Host", - FilePath = "%SystemRoot%\\system32\\mstsc.exe", - RequiredCommandLine = string.Format("/v:{0}", collection.Servers.First().FqdName) - }; - - var displayNames = GetApps().Select(p => p.DisplayName); + var addedApplications = GetApps(); + var displayNames = addedApplications.Select(p => p.DisplayName); apps = apps.Where(x => !displayNames.Contains(x.DisplayName)).ToList(); if (Direction == SortDirection.Ascending) @@ -132,15 +127,27 @@ namespace WebsitePanel.Portal.RDS.UserControls Direction = SortDirection.Ascending; } - if (!displayNames.Contains(fullRemote.DisplayName)) + var requiredParams = addedApplications.Select(a => a.RequiredCommandLine.ToLower()); + + foreach (var host in sessionHosts) { - if (apps.Count > 0) + if (!requiredParams.Contains(string.Format("/v:{0}", host.ToLower()))) { - apps.Insert(0, fullRemote); - } - else - { - apps.Add(fullRemote); + var fullRemote = new StartMenuApp + { + DisplayName = string.Format("Full Desktop - {0}", host.ToLower()), + FilePath = "%SystemRoot%\\system32\\mstsc.exe", + RequiredCommandLine = string.Format("/v:{0}", host.ToLower()) + }; + + if (apps.Count > 0) + { + apps.Insert(0, fullRemote); + } + else + { + apps.Add(fullRemote); + } } }