/// <summary> /// Create a WebServiceContext instance. /// </summary> /// <param name='clientInformation'>Client information.</param> public WebServiceContext(WebClientInformation clientInformation) { // Init context. _database = null; _clientToken = new WebClientToken(clientInformation.Token, WebServiceData.WebServiceManager.Key); _locale = clientInformation.Locale; if (_locale.IsNull()) { _locale = GetDefaultLocale(); } _currentRole = clientInformation.Role; _requestId = GetNextRequestId(); if (_isTracing) { _traceStart = DateTime.Now; } _transactionTimeout = Settings.Default.TransactionDefaultTimeout; // Unit is seconds. // Check arguments. try { clientInformation.CheckNotNull("clientInformation"); CheckUser(); CheckClientIpAddress(); CheckHttpsProtocol(); CheckWebServiceName(); CheckCurrentRole(); } catch (Exception exception) { WebServiceData.LogManager.LogSecurityError(this, exception); throw; } }
/// <summary> /// If current role has been specified check that /// user has this role in the specified context. /// Authorities for specified role is replaced /// with information from UserService for /// security reasons. /// </summary> /// <exception cref="ArgumentException">Thrown if user does not have the specified role in this context.</exception> private void CheckCurrentRole() { WebRole verifiedRole; if (CurrentRole.IsNotNull()) { // Don't trust client information. Verify role information // and get authorities from UserService. verifiedRole = null; foreach (WebRole role in WebServiceData.UserManager.GetRoles(this)) { if (role.Id == CurrentRole.Id) { verifiedRole = role; break; } } if (verifiedRole.IsNull()) { // User does not have specified role. throw new ArgumentException("User " + GetUser().UserName + " is not in role name:" + CurrentRole.Name + " id:" + CurrentRole.Id); } else { _currentRole = verifiedRole; } } }
public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) { if (string.IsNullOrEmpty(roleName)) { return(false); } using (CmsContext Context = new CmsContext()) { WebRole Role = null; Role = Context.Set <WebRole>().FirstOrDefault(Rl => Rl.RoleName == roleName); if (Role == null) { return(false); } if (throwOnPopulatedRole) { if (Role.Users.Any()) { return(false); } } else { Role.Users.Clear(); } Context.Set <WebRole>().Remove(Role); Context.SaveChanges(); return(true); } }
/// <summary> /// Get a copy of the role object. /// </summary> /// <param name='role'>The role.</param> /// <returns>A copy of the role object.</returns> public static WebRole Clone(this WebRole role) { WebRole clone; clone = new WebRole(); clone.AdministrationRoleId = role.AdministrationRoleId; clone.Authorities = role.Authorities; clone.CreatedBy = role.CreatedBy; clone.CreatedDate = role.CreatedDate; clone.DataFields = role.DataFields; clone.Description = role.Description; clone.GUID = role.GUID; clone.Id = role.Id; clone.Identifier = role.Identifier; clone.IsActivationRequired = role.IsActivationRequired; clone.IsAdministrationRoleIdSpecified = role.IsAdministrationRoleIdSpecified; clone.IsOrganizationIdSpecified = role.IsOrganizationIdSpecified; clone.IsUserAdministrationRole = role.IsUserAdministrationRole; clone.IsUserAdministrationRoleIdSpecified = role.IsUserAdministrationRoleIdSpecified; clone.MessageTypeId = role.MessageTypeId; clone.ModifiedBy = role.ModifiedBy; clone.ModifiedDate = role.ModifiedDate; clone.Name = role.Name; clone.OrganizationId = role.OrganizationId; clone.ShortName = role.ShortName; clone.UserAdministrationRoleId = clone.UserAdministrationRoleId; clone.ValidFromDate = role.ValidFromDate; clone.ValidToDate = role.ValidToDate; return(clone); }
/// <summary> /// Checks for equality between provided object and this object /// </summary> /// <param name="obj">This object can be type of RoleInfo, WebRoleInfo, WorkerRoleInfo, WebRole or WorkerRole</param> /// <returns>True if they are equals, false if not</returns> public override bool Equals(object obj) { Validate.ValidateNullArgument(obj, string.Empty); bool equals; RoleInfo roleInfo = obj as RoleInfo; WebRole webRole = obj as WebRole; WorkerRole workerRole = obj as WorkerRole; RoleSettings role = obj as RoleSettings; if (roleInfo != null) { equals = this.InstanceCount.Equals(roleInfo.InstanceCount) && this.Name.Equals(roleInfo.Name); } else if (webRole != null) { equals = this.Name.Equals(webRole.name); } else if (workerRole != null) { equals = this.Name.Equals(workerRole.name); } else if (role != null) { equals = this.Name.Equals(role.name) && this.InstanceCount.Equals(role.Instances.count); } else { equals = false; } return(equals); }
/// <summary> /// Add the specified runtime to a role, checking that the runtime and version are currently available int he cloud /// </summary> /// <param name="paths">service path info</param> /// <param name="roleName">Name of the role to change</param> /// <param name="runtimeType">The runtime identifier</param> /// <param name="runtimeVersion">The runtime version</param> /// <param name="manifest">Location fo the manifest file, default is the cloud manifest</param> public void AddRoleRuntime( CloudProjectPathInfo paths, string roleName, string runtimeType, string runtimeVersion, string manifest = null) { if (this.Components.RoleExists(roleName)) { CloudRuntimeCollection collection; CloudRuntimeCollection.CreateCloudRuntimeCollection(out collection, manifest); CloudRuntime desiredRuntime = CloudRuntime.CreateCloudRuntime(runtimeType, runtimeVersion, roleName, Path.Combine(paths.RootPath, roleName)); CloudRuntimePackage foundPackage; if (collection.TryFindMatch(desiredRuntime, out foundPackage)) { WorkerRole worker = (this.Components.Definition.WorkerRole == null ? null : this.Components.Definition.WorkerRole.FirstOrDefault <WorkerRole>(r => string.Equals(r.name, roleName, StringComparison.OrdinalIgnoreCase))); WebRole web = (this.Components.Definition.WebRole == null ? null : this.Components.Definition.WebRole.FirstOrDefault <WebRole>(r => string.Equals(r.name, roleName, StringComparison.OrdinalIgnoreCase))); desiredRuntime.CloudServiceProject = this; if (worker != null) { desiredRuntime.ApplyRuntime(foundPackage, worker); } else if (web != null) { desiredRuntime.ApplyRuntime(foundPackage, web); } this.Components.Save(this.Paths); } } }
/// <summary> /// Decides if the given role is web or worker role. /// </summary> /// <param name="roleName">The role name</param> /// <returns>Boolean flag indicates if the role is web or not</returns> public bool IsWebRole(string roleName) { WebRole webRole = GetWebRole(roleName); WorkerRole workerRole = GetWorkerRole(roleName); return(webRole != null ? true : false); }
private string MergeCSV(Tuple <string, string[]>[] requests) { string tempFile = Path.GetTempFileName(); try { using (CsvDataSet result = new CsvDataSet(new CsvUri() { FileName = tempFile, Encoding = Encoding.UTF8, OpenMode = ResourceOpenMode.Create, Separator = Delimiter.Comma, AppendMetadata = false, NoHeader = false }.ToString())) { result.IsAutocommitEnabled = false; MergeCSV(result, requests); } return(File.ReadAllText(tempFile)); } finally { try { File.Delete(tempFile); } catch (Exception exc) { WebRole.TraceInfo("Error deleting temporary file: " + exc.Message); } } }
/// <summary> /// Sets the VM size of a role /// </summary> /// <param name="roleName">The role name</param> /// <param name="vmSize">The VM size</param> public void SetRoleVMSize(string roleName, string vmSize) { Validate.ValidateStringIsNullOrEmpty(roleName, Resources.RoleName); bool isDefined = Enum.GetNames(typeof(RoleSize)).Any(x => x.ToLower() == vmSize.ToLower()); if (!isDefined) { throw new ArgumentException(string.Format(Resources.InvalidVMSize, roleName)); } if (!RoleExists(roleName)) { throw new ArgumentException(string.Format(Resources.RoleNotFoundMessage, roleName)); } WebRole webRole = GetWebRole(roleName); RoleSize size = (RoleSize)Enum.Parse(typeof(RoleSize), vmSize, true); if (webRole != null) { webRole.vmsize = size; } else { WorkerRole workerRole = GetWorkerRole(roleName); workerRole.vmsize = size; } }
/// <summary> /// Load data into the WebRole instance. /// </summary> /// <param name='role'>The role.</param> /// <param name='dataReader'>An open data reader.</param> public static void LoadData(this WebRole role, DataReader dataReader) { Int32 isUserAdministrationRole; // Role role.Id = dataReader.GetInt32(RoleData.ID); role.GUID = dataReader.GetString(RoleData.GUID); role.Name = dataReader.GetString(RoleData.ROLE_NAME); role.ShortName = dataReader.GetString(RoleData.SHORT_NAME); role.Description = dataReader.GetString(RoleData.DESCRIPTION); role.IsAdministrationRoleIdSpecified = dataReader.IsNotDbNull(RoleData.ADMINISTRATION_ROLE_ID); role.AdministrationRoleId = dataReader.GetInt32(RoleData.ADMINISTRATION_ROLE_ID, 0); role.IsActivationRequired = dataReader.GetBoolean(RoleData.IS_ACTIVATION_REQUIRED); role.MessageTypeId = dataReader.GetInt32(RoleData.MESSAGE_TYPE_ID); role.IsUserAdministrationRoleIdSpecified = dataReader.IsNotDbNull(RoleData.USER_ADMINISTRATION_ROLE_ID); role.UserAdministrationRoleId = dataReader.GetInt32(RoleData.USER_ADMINISTRATION_ROLE_ID, 0); role.CreatedDate = dataReader.GetDateTime(RoleData.CREATED_DATE); role.CreatedBy = dataReader.GetInt32(RoleData.CREATED_BY); role.ModifiedDate = dataReader.GetDateTime(RoleData.MODIFIED_DATE); role.ModifiedBy = dataReader.GetInt32(RoleData.MODIFIED_BY); role.ValidFromDate = dataReader.GetDateTime(RoleData.VALID_FROM_DATE); role.ValidToDate = dataReader.GetDateTime(RoleData.VALID_TO_DATE); role.IsOrganizationIdSpecified = dataReader.IsNotDbNull(RoleData.ORGANIZATION_ID); role.OrganizationId = dataReader.GetInt32(RoleData.ORGANIZATION_ID, 0); role.Identifier = dataReader.GetString(RoleData.IDENTIFIER); isUserAdministrationRole = dataReader.GetInt32(RoleData.IS_USER_ADMINISTRATION_ROLE); role.IsUserAdministrationRole = (isUserAdministrationRole != 0); }
/// <summary> /// Create a WebServiceContext instance. /// This contructor should only be used during login. /// </summary> /// <param name="userName">User name.</param> /// <param name="applicationIdentifier"> /// Identifier of the application that the user uses. /// </param> public WebServiceContext(String userName, String applicationIdentifier) { // Init object. _database = null; _clientToken = new WebClientToken(userName, applicationIdentifier, WebServiceData.WebServiceManager.Key); _requestId = GetNextRequestId(); if (_isTracing) { _traceStart = DateTime.Now; } _transactionTimeout = Settings.Default.TransactionDefaultTimeout; // Unit is seconds. // Check arguments. try { CheckHttpsProtocol(); } catch (Exception exception) { WebServiceData.LogManager.LogSecurityError(this, exception); throw; } _currentRole = null; // This is only a temporary value. // Real value is set by UserManager when user has logged in. _locale = GetDefaultLocale(); }
public override bool IsUserInRole(string username, string roleName) { if (string.IsNullOrEmpty(username)) { return(false); } if (string.IsNullOrEmpty(roleName)) { return(false); } using (CmsContext Context = new CmsContext()) { WebUser User = null; User = Context.Set <WebUser>().FirstOrDefault(Usr => Usr.AdName == username); if (User == null) { return(false); } WebRole Role = Context.Set <WebRole>().FirstOrDefault(Rl => Rl.RoleName == roleName); if (Role == null) { return(false); } return(User.Roles.Contains(Role)); } }
public void Constructor() { WebRole role; role = new WebRole(); Assert.IsNotNull(role); }
// POST: IMMessage/Create public void Post([FromBody] InventoryMessage value) { WebRole webRole = new WebRole(); webRole.AddMessage(value); webRole.Send(); }
public WebRole GetRole(Boolean refresh) { if (_role.IsNull() || refresh) { _role = ArtDatabanken.WebService.UserService.Data.UserManager.GetRole(GetContext(), Settings.Default.TestRoleId); } return(_role); }
/// <summary> /// Check the data in current object. /// </summary> /// <param name='role'>The role.</param> public static void CheckData(this WebRole role) { if (!role.IsDataChecked) { role.CheckStrings(); role.IsDataChecked = true; } }
private WebRole GetRole(Boolean refresh) { if (_role.IsNull() || refresh) { _role = new WebRole(); } return(_role); }
public static void ClearRuntime(WebRole role) { Task startupTask = GetRuntimeStartupTask(role.Startup); if (startupTask != null) { ClearEnvironmentValue(startupTask.Environment, Resources.RuntimeUrlKey); } }
/// <summary> /// Configuration action to enable using dedicated caching on the client role. /// </summary> /// <param name="cloudServiceProject">The cloud service project instance</param> /// <param name="roleName">The role name</param> /// <param name="cacheWorkerRoleName">The dedicated cache worker role name</param> private static void CacheClientRole180( CloudServiceProject cloudServiceProject, string roleName, string cacheWorkerRoleName) { // Add MemcacheShim runtime installation. cloudServiceProject.AddRoleRuntime( cloudServiceProject.Paths, roleName, Resources.CacheRuntimeValue, CurrentVersion); // Fetch web role information. Startup startup = cloudServiceProject.Components.GetRoleStartup(roleName); // Assert that cache runtime is added to the runtime startup. Debug.Assert(Array.Exists <Variable>(CloudRuntime.GetRuntimeStartupTask(startup).Environment, v => v.name.Equals(Resources.RuntimeTypeKey) && v.value.Contains(Resources.CacheRuntimeValue))); if (cloudServiceProject.Components.IsWebRole(roleName)) { WebRole webRole = cloudServiceProject.Components.GetWebRole(roleName); webRole.LocalResources = GeneralUtilities.InitializeIfNull <LocalResources>(webRole.LocalResources); DefinitionConfigurationSetting[] configurationSettings = webRole.ConfigurationSettings; CacheClientCommonConfiguration( cloudServiceProject, roleName, true, cacheWorkerRoleName, webRole.Startup, webRole.Endpoints, webRole.LocalResources, ref configurationSettings); webRole.ConfigurationSettings = configurationSettings; } else { WorkerRole workerRole = cloudServiceProject.Components.GetWorkerRole(roleName); workerRole.LocalResources = GeneralUtilities.InitializeIfNull <LocalResources>(workerRole.LocalResources); DefinitionConfigurationSetting[] configurationSettings = workerRole.ConfigurationSettings; CacheClientCommonConfiguration( cloudServiceProject, roleName, false, cacheWorkerRoleName, workerRole.Startup, workerRole.Endpoints, workerRole.LocalResources, ref configurationSettings); workerRole.ConfigurationSettings = configurationSettings; } // Save changes cloudServiceProject.Components.Save(cloudServiceProject.Paths); }
private void AssertCachingEnabled( FileSystemHelper files, string serviceName, string rootPath, string webRoleName, string expectedMessage) { WebRole webRole = Testing.GetWebRole(rootPath, webRoleName); RoleSettings roleSettings = Testing.GetCloudRole(rootPath, webRoleName); AzureAssert.RuntimeUrlAndIdExists(webRole.Startup.Task, Resources.CacheRuntimeValue); Assert.AreEqual <string>(Resources.CacheRuntimeVersionKey, webRole.Startup.Task[0].Environment[0].name); Assert.AreEqual <string>(enableCacheCmdlet.CacheRuntimeVersion, webRole.Startup.Task[0].Environment[0].value); Assert.AreEqual <string>(Resources.EmulatedKey, webRole.Startup.Task[2].Environment[0].name); Assert.AreEqual <string>("/RoleEnvironment/Deployment/@emulated", webRole.Startup.Task[2].Environment[0].RoleInstanceValue.xpath); Assert.AreEqual <string>(Resources.CacheRuntimeUrl, webRole.Startup.Task[2].Environment[1].name); Assert.AreEqual <string>(TestResources.CacheRuntimeUrl, webRole.Startup.Task[2].Environment[1].value); Assert.AreEqual(1, webRole.Startup.Task.Count(t => t.commandLine.Equals(Resources.CacheStartupCommand))); AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, serviceName, webRoleName), Path.Combine(Resources.CacheScaffolding, Resources.WebRole)); AzureAssert.StartupTaskExists(webRole.Startup.Task, Resources.CacheStartupCommand); AzureAssert.InternalEndpointExists(webRole.Endpoints.InternalEndpoint, new InternalEndpoint { name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort }); LocalStore localStore = new LocalStore { name = Resources.CacheDiagnosticStoreName, cleanOnRoleRecycle = false }; AzureAssert.LocalResourcesLocalStoreExists(localStore, webRole.LocalResources); DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName }; AzureAssert.ConfigurationSettingExist(diagnosticLevel, webRole.ConfigurationSettings); ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting { name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue }; AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, roleSettings.ConfigurationSettings); AssertWebConfig(string.Format(@"{0}\{1}\{2}", rootPath, webRoleName, Resources.WebCloudConfig)); AssertWebConfig(string.Format(@"{0}\{1}\{2}", rootPath, webRoleName, Resources.WebConfigTemplateFileName)); Assert.AreEqual <string>(expectedMessage, mockCommandRuntime.VerboseStream[0]); Assert.AreEqual <string>(webRoleName, (mockCommandRuntime.OutputPipeline[0] as PSObject).GetVariableValue <string>(Parameters.RoleName)); }
public static void AddWebRoleToDef(string path, Dictionary <string, object> parameters) { RoleInfo role = parameters["Role"] as RoleInfo; ServiceComponents components = parameters["Components"] as ServiceComponents; PowerShellProjectPathInfo paths = parameters["Paths"] as PowerShellProjectPathInfo; WebRole webRole = General.DeserializeXmlFile <ServiceDefinition>(path).WebRole[0]; role.AddRoleToDefinition(components.Definition, webRole); components.Save(paths); }
private static Dictionary <string, string> GetStartupEnvironment(WebRole webRole) { Dictionary <string, string> settings = new Dictionary <string, string>(); foreach (Variable variable in webRole.Startup.Task[0].Environment) { settings[variable.name] = variable.value; } return(settings); }
/// <summary> /// Create a cloud runtime application, essentialy this is a tuple of runtime X package X role /// </summary> /// <param name="cloudRuntime">The runtime in the tuple</param> /// <param name="cloudRuntimePackage">The package in the tuple</param> /// <param name="role">The role to apply the package to</param> /// <returns>The tuple, use the apply method to apply the runtime as specified</returns> public static CloudRuntimeApplicator CreateCloudRuntimeApplicator(CloudRuntime cloudRuntime, CloudRuntimePackage cloudRuntimePackage, WebRole role) { CloudRuntimeApplicator applicator = new CloudRuntimeApplicator { Runtime = cloudRuntime, Package = cloudRuntimePackage, WebRole = role }; return applicator; }
/// <summary> /// Main entry for enabling memcache. /// </summary> /// <param name="roleName">The web role name</param> /// <param name="cacheWorkerRoleName">The cache worker role name</param> /// <param name="rootPath">The service root path</param> /// <param name="message">The resulted message</param> /// <param name="azureService">The azure service instance</param> /// <param name="webRole">The web role to enable caching one</param> private void EnableMemcache(string roleName, string cacheWorkerRoleName, ref string message, ref AzureService azureService) { // Add MemcacheShim runtime installation. azureService.AddRoleRuntime(azureService.Paths, roleName, Resources.CacheRuntimeValue, CacheRuntimeVersion); // Fetch web role information. Startup startup = azureService.Components.GetRoleStartup(roleName); // Assert that cache runtime is added to the runtime startup. Debug.Assert(Array.Exists <Variable>(CloudRuntime.GetRuntimeStartupTask(startup).Environment, v => v.name.Equals(Resources.RuntimeTypeKey) && v.value.Contains(Resources.CacheRuntimeValue))); if (azureService.Components.IsWebRole(roleName)) { WebRole webRole = azureService.Components.GetWebRole(roleName); webRole.LocalResources = General.InitializeIfNull <LocalResources>(webRole.LocalResources); DefinitionConfigurationSetting[] configurationSettings = webRole.ConfigurationSettings; CachingConfigurationFactoryMethod( azureService, roleName, true, cacheWorkerRoleName, webRole.Startup, webRole.Endpoints, webRole.LocalResources, ref configurationSettings, CacheRuntimeVersion); webRole.ConfigurationSettings = configurationSettings; } else { WorkerRole workerRole = azureService.Components.GetWorkerRole(roleName); workerRole.LocalResources = General.InitializeIfNull <LocalResources>(workerRole.LocalResources); DefinitionConfigurationSetting[] configurationSettings = workerRole.ConfigurationSettings; CachingConfigurationFactoryMethod( azureService, roleName, false, cacheWorkerRoleName, workerRole.Startup, workerRole.Endpoints, workerRole.LocalResources, ref configurationSettings, CacheRuntimeVersion); workerRole.ConfigurationSettings = configurationSettings; } // Save changes azureService.Components.Save(azureService.Paths); message = string.Format(Resources.EnableMemcacheMessage, roleName, cacheWorkerRoleName, Resources.MemcacheEndpointPort); }
public virtual void ApplyRuntime(CloudRuntimePackage package, WebRole webRole) { Dictionary <string, string> changes; if (this.GetChanges(package, out changes)) { ApplyRoleXmlChanges(changes, webRole); } ApplyScaffoldingChanges(package); }
/// <summary> /// Check if user has access right to a species observation. /// </summary> /// <param name="context">Web service request context.</param> /// <param name="role">Check access right in this role.</param> /// <returns>True if user has access right to provided observation.</returns> private Boolean CheckAccessRights(WebServiceContext context, WebRole role) { foreach (WebAuthority authority in role.Authorities) { if (CheckAccessRights(context, authority)) { return(true); } } return(false); }
/// <summary> /// Gets role startup. /// </summary> /// <param name="roleName">The role name</param> /// <returns>The role startup</returns> public Startup GetRoleStartup(string roleName) { if (!RoleExists(roleName)) { throw new ArgumentException(string.Format(Resources.RoleNotFoundMessage, roleName)); } WebRole webRole = GetWebRole(roleName); WorkerRole workerRole = GetWorkerRole(roleName); Startup startup = webRole != null ? webRole.Startup : workerRole.Startup; return(startup); }
internal override void AddRoleToDefinition(ServiceDefinition def, object template) { WebRole webRole = template as WebRole; var toAdd = new WebRole[] { webRole }; if (def.WebRole != null) { def.WebRole = def.WebRole.Concat(toAdd).ToArray(); } else { def.WebRole = toAdd; } }
private WebRole[] GetRoles() { string[] names = Enum.GetNames(typeof(Role)); WebRole[] array = new WebRole[names.Length]; for (int i = 0; i < names.Length; ++i) { array[i] = new WebRole() { Id = i + 1, Description = names[i] }; } return(array); }
public object Get(RolesGrantGetRequest request) { List <WebRoleGrant> result = new List <WebRoleGrant> (); var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/role/grant GET")); Domain domain = Domain.FromId(context, request.DomainId); var webdomain = new WebDomain(domain); EntityList <Role> roles = new EntityList <Role> (context); roles.Load(); foreach (var role in roles) { var webrole = new WebRole(role); //get users var usrs = role.GetUsers(domain.Id); foreach (var usrid in usrs) { var webuser = new WebUser(User.FromId(context, usrid)); result.Add(new WebRoleGrant { Domain = webdomain, Role = webrole, User = webuser }); } //get groups var grps = role.GetGroups(domain.Id); foreach (var grpid in grps) { var webgroup = new WebGroup(Group.FromId(context, grpid)); result.Add(new WebRoleGrant { Domain = webdomain, Role = webrole, Group = webgroup }); } } context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
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(Resources.EnableAzureRemoteDesktop_Enable_NoRoles); } } } } 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; } } 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 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 = GeneralUtilities.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 = GeneralUtilities.Append(firstWebRole.Imports, new Import { moduleName = "RemoteForwarder" }); forwarderName = firstWebRole.name; } else { throw new InvalidOperationException(Resources.EnableAzureRemoteDesktop_Enable_NoRoles); } } } } return forwarderName; }
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 = GeneralUtilities.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 = GeneralUtilities.Append(workerRole.Imports, new Import { moduleName = "RemoteAccess" }); } }
/// <summary> /// Try to get the specified web role from the given definiiton /// </summary> /// <param name="definition">The service definiiton</param> /// <param name="roleName">The name of the role</param> /// <param name="role">output variable where the webRole is returned</param> /// <returns>true if the web role is found in the given definition</returns> private static bool TryGetWebRole(ServiceDefinition definition, string roleName, out WebRole role) { role = definition.WebRole.FirstOrDefault<WebRole>(r => string.Equals(r.name, roleName, StringComparison.OrdinalIgnoreCase)); return role != null; }
public static void VerifyWebRole(WebRole role, bool isForwarder) { Assert.AreEqual(isForwarder ? 1 : 0, role.Imports.Where(i => i.moduleName == "RemoteForwarder").Count()); Assert.AreEqual(1, role.Imports.Where(i => i.moduleName == "RemoteAccess").Count()); }
public static Collection<CloudRuntime> CreateRuntime(WebRole webRole, string rolePath) { return GetRuntimes(GetStartupEnvironment(webRole), webRole.name, rolePath); }
private static Dictionary<string, string> GetStartupEnvironment(WebRole webRole) { Dictionary<string, string> settings = new Dictionary<string, string>(); foreach (Variable variable in GetRuntimeStartupTask(webRole.Startup).Environment) { settings[variable.name] = variable.value; } return settings; }
private static void ApplyRoleXmlChanges(Dictionary<string, string> changes, WebRole webRole) { GetRuntimeStartupTask(webRole.Startup).Environment = ApplySettingChanges(changes, GetRuntimeStartupTask(webRole.Startup).Environment); }
public static void ClearRuntime(WebRole role) { Task startupTask = GetRuntimeStartupTask(role.Startup); if (startupTask != null) { ClearEnvironmentValue(startupTask.Environment, Resources.RuntimeUrlKey); ClearEnvironmentValue(startupTask.Environment, Resources.CacheRuntimeUrl); } }
public virtual void ApplyRuntime(CloudRuntimePackage package, WebRole webRole) { Dictionary<string, string> changes; if (this.GetChanges(package, out changes)) { ApplyRoleXmlChanges(changes, webRole); } ApplyScaffoldingChanges(package); }