/// <summary>
 /// The function to run if setting the runtime for a role
 /// </summary>
 /// <param name="roleName">The name of the role to modify</param>
 /// <param name="runtimeType">The type f role runtiem to configure</param>
 /// <param name="runtimeVersion">The version of the runtime</param>
 /// <param name="rootPath">The path to the service containing the role</param>
 /// <param name="manifest">The manifest containing available runtimes, defaults to the cloud manifest
 /// mainly used a s a test hook</param>
 public void SetAzureRuntimesProcess(string roleName, string runtimeType, string runtimeVersion, string rootPath, string manifest = null)
 {
     AzureService service = new AzureService(rootPath, null);
     service.AddRoleRuntime(service.Paths, roleName, runtimeType, runtimeVersion, manifest);
 }
        /// <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 = CloudServiceUtilities.InitializeIfNull<LocalResources>(webRole.LocalResources);
                DefConfigurationSetting[] 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 = CloudServiceUtilities.InitializeIfNull<LocalResources>(workerRole.LocalResources);
                DefConfigurationSetting[] 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 RoleSettings SetAzureRuntimesProcess(string roleName, string runtimeType, string runtimeVersion, string rootPath, string manifest = null)
        {
            AzureService service = new AzureService(rootPath, null);
            service.AddRoleRuntime(service.Paths, roleName, runtimeType, runtimeVersion, manifest);

            if (PassThru)
            {
                SafeWriteOutputPSObject(typeof(RoleSettings).FullName, Parameters.RoleName, roleName);
            }

            return service.Components.GetCloudConfigRole(roleName);
        }