private static string GetForwarderName(WebRole[] webRoles, WorkerRole[] workerRoles) { string forwarderName = null; WorkerRole workerForwarder = workerRoles.FirstOrDefault(r => r.Imports != null && r.Imports.Any(i => i.moduleName == "RemoteForwarder")); if (workerForwarder != null) { // a worker role has the forwarder forwarderName = workerForwarder.name; } else { WebRole webForwarder = webRoles.FirstOrDefault(r => r.Imports != null && r.Imports.Any(i => i.moduleName == "RemoteForwarder")); if (webForwarder != null) { // a web role has the forwarder forwarderName = webForwarder.name; } } return forwarderName; }
private static string GetForwarderName(WebRole[] webRoles, WorkerRole[] workerRoles) { string forwarderName = null; WorkerRole workerForwarder = workerRoles.FirstOrDefault(r => r.Imports != null && r.Imports.Any(i => i.moduleName == "RemoteForwarder")); if (workerForwarder != null) { // a worker role has the forwarder forwarderName = workerForwarder.name; } else { WebRole webForwarder = webRoles.FirstOrDefault(r => r.Imports != null && r.Imports.Any(i => i.moduleName == "RemoteForwarder")); if (webForwarder != null) { // a web role has the forwarder forwarderName = webForwarder.name; } else { // no role has the forwarder yet WorkerRole firstWorkerRole = workerRoles.FirstOrDefault(); if (firstWorkerRole != null) { firstWorkerRole.Imports = General.Append(firstWorkerRole.Imports, new Import { moduleName = "RemoteForwarder" }); forwarderName = firstWorkerRole.name; } else // no worker role, use a web role { WebRole firstWebRole = webRoles.FirstOrDefault(); if (firstWebRole != null) { firstWebRole.Imports = General.Append(firstWebRole.Imports, new Import { moduleName = "RemoteForwarder" }); forwarderName = firstWebRole.name; } else { throw new InvalidOperationException(Properties.Resources.EnableAzureRemoteDesktop_Enable_NoRoles); } } } } return forwarderName; }
private static void RemoveOtherRemoteForwarders(WebRole[] webRoles, WorkerRole[] workerRoles, string forwarderName) { // Remove RemoteForwarder from all but the chosen role foreach (WebRole webRole in webRoles) { if (webRole.name != forwarderName && webRole.Imports != null && webRole.Imports.Any(i => i.moduleName == "RemoteForwarder")) { webRole.Imports = webRole.Imports.Where(i => i.moduleName != "RemoteForwarder").ToArray(); } } foreach (WorkerRole workerRole in workerRoles) { if (workerRole.name != forwarderName && workerRole.Imports != null && workerRole.Imports.Any(i => i.moduleName == "RemoteForwarder")) { workerRole.Imports = workerRole.Imports.Where(i => i.moduleName != "RemoteForwarder").ToArray(); } } }
private static void AddRemoteAccess(WebRole[] webRoles, WorkerRole[] workerRoles) { // Add RemoteAccess to all roles foreach (WebRole webRole in webRoles.Where(r => r.Imports == null || !r.Imports.Any(i => i.moduleName == "RemoteAccess"))) { webRole.Imports = General.Append(webRole.Imports, new Import { moduleName = "RemoteAccess" }); } foreach (WorkerRole workerRole in workerRoles.Where(r => r.Imports == null || !r.Imports.Any(i => i.moduleName == "RemoteAccess"))) { workerRole.Imports = General.Append(workerRole.Imports, new Import { moduleName = "RemoteAccess" }); } }