Microsoft.WindowsAzure.Commands.Utilities.CloudService.CloudServiceProject.AddRoleRuntime C# (CSharp) Method

AddRoleRuntime() public method

Add the specified runtime to a role, checking that the runtime and version are currently available int he cloud
public AddRoleRuntime ( CloudProjectPathInfo paths, string roleName, string runtimeType, string runtimeVersion, string manifest = null ) : void
paths CloudProjectPathInfo service path info
roleName string Name of the role to change
runtimeType string The runtime identifier
runtimeVersion string The runtime version
manifest string Location fo the manifest file, default is the cloud manifest
return void
        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);
                }
            }
        }

Usage Example

        /// <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);
        }
All Usage Examples Of Microsoft.WindowsAzure.Commands.Utilities.CloudService.CloudServiceProject::AddRoleRuntime