Remote applications - several session hosts

This commit is contained in:
vfedosevich 2015-02-02 04:22:44 -08:00
parent d063e2ce2d
commit 7e8390d298
8 changed files with 243 additions and 15 deletions

View file

@ -104,6 +104,8 @@ namespace WebsitePanel.EnterpriseServer {
private System.Threading.SendOrPostCallback LogOffRdsUserOperationCompleted;
private System.Threading.SendOrPostCallback GetRdsCollectionSessionHostsOperationCompleted;
/// <remarks/>
public esRemoteDesktopServices() {
this.Url = "http://localhost:9002/esRemoteDesktopServices.asmx";
@ -220,6 +222,9 @@ namespace WebsitePanel.EnterpriseServer {
/// <remarks/>
public event LogOffRdsUserCompletedEventHandler LogOffRdsUserCompleted;
/// <remarks/>
public event GetRdsCollectionSessionHostsCompletedEventHandler GetRdsCollectionSessionHostsCompleted;
/// <remarks/>
[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 {
}
}
/// <remarks/>
[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]));
}
/// <remarks/>
public System.IAsyncResult BeginGetRdsCollectionSessionHosts(int collectionId, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetRdsCollectionSessionHosts", new object[] {
collectionId}, callback, asyncState);
}
/// <remarks/>
public string[] EndGetRdsCollectionSessionHosts(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((string[])(results[0]));
}
/// <remarks/>
public void GetRdsCollectionSessionHostsAsync(int collectionId) {
this.GetRdsCollectionSessionHostsAsync(collectionId, null);
}
/// <remarks/>
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));
}
}
/// <remarks/>
public new void CancelAsync(object userState) {
base.CancelAsync(userState);
@ -2865,4 +2911,30 @@ namespace WebsitePanel.EnterpriseServer {
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
public delegate void GetRdsCollectionSessionHostsCompletedEventHandler(object sender, GetRdsCollectionSessionHostsCompletedEventArgs e);
/// <remarks/>
[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;
}
/// <remarks/>
public string[] Result {
get {
this.RaiseExceptionIfNecessary();
return ((string[])(this.results[0]));
}
}
}
}

View file

@ -243,6 +243,11 @@ namespace WebsitePanel.EnterpriseServer
return LogOffRdsUserInternal(itemId, unifiedSessionId, hostServer);
}
public static List<string> GetRdsCollectionSessionHosts(int collectionId)
{
return GetRdsCollectionSessionHostsInternal(collectionId);
}
private static RdsCollection GetRdsCollectionInternal(int collectionId)
{
var collection = ObjectUtils.FillObjectFromDataReader<RdsCollection>(DataProvider.GetRDSCollectionById(collectionId));
@ -630,6 +635,23 @@ namespace WebsitePanel.EnterpriseServer
return result;
}
private static List<string> GetRdsCollectionSessionHostsInternal(int collectionId)
{
var result = new List<string>();
var collection = ObjectUtils.FillObjectFromDataReader<RdsCollection>(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);

View file

@ -283,5 +283,11 @@ namespace WebsitePanel.EnterpriseServer
{
return RemoteDesktopServicesController.LogOffRdsUser(itemId, unifiedSessionId, hostServer);
}
[WebMethod]
public List<string> GetRdsCollectionSessionHosts(int collectionId)
{
return RemoteDesktopServicesController.GetRdsCollectionSessionHosts(collectionId);
}
}
}

View file

@ -68,5 +68,6 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
void EditRdsCollectionSettings(RdsCollection collection);
List<RdsUserSession> GetRdsUserSessions(string collectionName);
void LogOffRdsUser(string unifiedSessionId, string hostServer);
List<string> GetRdsCollectionSessionHosts(string collectionName);
}
}

View file

@ -184,6 +184,35 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
#region RDS Collections
public List<string> GetRdsCollectionSessionHosts(string collectionName)
{
var result = new List<string>();
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;

View file

@ -79,6 +79,8 @@ namespace WebsitePanel.Providers.RemoteDesktopServices {
private System.Threading.SendOrPostCallback LogOffRdsUserOperationCompleted;
private System.Threading.SendOrPostCallback GetRdsCollectionSessionHostsOperationCompleted;
/// <remarks/>
public RemoteDesktopServices() {
this.Url = "http://localhost:9003/RemoteDesktopServices.asmx";
@ -159,6 +161,9 @@ namespace WebsitePanel.Providers.RemoteDesktopServices {
/// <remarks/>
public event LogOffRdsUserCompletedEventHandler LogOffRdsUserCompleted;
/// <remarks/>
public event GetRdsCollectionSessionHostsCompletedEventHandler GetRdsCollectionSessionHostsCompleted;
/// <remarks/>
[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 {
}
}
/// <remarks/>
[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]));
}
/// <remarks/>
public System.IAsyncResult BeginGetRdsCollectionSessionHosts(string collectionName, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetRdsCollectionSessionHosts", new object[] {
collectionName}, callback, asyncState);
}
/// <remarks/>
public string[] EndGetRdsCollectionSessionHosts(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((string[])(results[0]));
}
/// <remarks/>
public void GetRdsCollectionSessionHostsAsync(string collectionName) {
this.GetRdsCollectionSessionHostsAsync(collectionName, null);
}
/// <remarks/>
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));
}
}
/// <remarks/>
public new void CancelAsync(object userState) {
base.CancelAsync(userState);
@ -1753,4 +1800,30 @@ namespace WebsitePanel.Providers.RemoteDesktopServices {
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
public delegate void LogOffRdsUserCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
public delegate void GetRdsCollectionSessionHostsCompletedEventHandler(object sender, GetRdsCollectionSessionHostsCompletedEventArgs e);
/// <remarks/>
[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;
}
/// <remarks/>
public string[] Result {
get {
this.RaiseExceptionIfNecessary();
return ((string[])(this.results[0]));
}
}
}
}

View file

@ -477,5 +477,23 @@ namespace WebsitePanel.Server
throw;
}
}
[WebMethod, SoapHeader("settings")]
public List<string> 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;
}
}
}
}

View file

@ -110,15 +110,10 @@ namespace WebsitePanel.Portal.RDS.UserControls
{
RdsCollection collection = ES.Services.RDS.GetRdsCollection(PanelRequest.CollectionID);
List<StartMenuApp> 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);
}
}
}