private void UpdateServiceConfigurations(AzureService service, string forwarderName)
        {
            foreach (ServiceConfiguration config in new[] { service.Components.LocalConfig, service.Components.CloudConfig })
            {
                foreach (ServiceConfigurationSchema.RoleSettings role in config.Role)
                {
                    if (role.ConfigurationSettings != null)
                    {
                        ServiceConfigurationSchema.ConfigurationSetting setting = role.ConfigurationSettings.
                                                                                  FirstOrDefault <ServiceConfigurationSchema.ConfigurationSetting>(t => t.name.Equals(
                                                                                                                                                       "Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled"));
                        if (setting != null)
                        {
                            setting.value = "false";
                        }

                        if (role.name == forwarderName)
                        {
                            ServiceConfigurationSchema.ConfigurationSetting forwarderSetting = role.ConfigurationSettings.
                                                                                               FirstOrDefault <ServiceConfigurationSchema.ConfigurationSetting>(t => t.name.Equals(
                                                                                                                                                                    "Microsoft.WindowsAzure.Plugins.RemoteForwarder.Enabled"));
                            if (forwarderSetting != null)
                            {
                                forwarderSetting.value = "false";
                            }
                        }
                    }
                }
            }
        }
        private bool ConfigureRoleStorageAccountKeys()
        {
            string primaryKey;
            string secondaryKey;

            if (this.ExtractStorageKeys(this.subscriptionId, this.StorageAccountName, out primaryKey, out secondaryKey))
            {
                const string cloudStorageFormat = "DefaultEndpointsProtocol={0};AccountName={1};AccountKey={2}";
                string storageHttpKey = string.Format(cloudStorageFormat, "http", this.StorageAccountName, primaryKey);
                string storageHttpsKey = string.Format(cloudStorageFormat, "https", this.StorageAccountName, primaryKey);

                for (int i = 0; i < cloudSvcConfig.Role.Length; i++)
                {
                    ServiceConfigurationSchema.ConfigurationSetting newSetting;
                    newSetting = new ServiceConfigurationSchema.ConfigurationSetting() { name = Resources.DataConnectionString, value = storageHttpKey };
                    UpdateSetting(ref cloudSvcConfig.Role[i], newSetting);

                    newSetting = new ServiceConfigurationSchema.ConfigurationSetting() { name = Resources.DiagnosticsConnectionString, value= storageHttpsKey };
                    UpdateSetting(ref cloudSvcConfig.Role[i], newSetting);
                }
                General.SerializeXmlFile<ServiceConfiguration>(cloudSvcConfig, cloudSvcConfigFileName);
                return true;
            }
            return false;
        }
        private bool ConfigureRoleStorageAccountKeys()
        {
            string primaryKey;
            string secondaryKey;

            if (this.ExtractStorageKeys(this.subscriptionId, this.StorageAccountName, out primaryKey, out secondaryKey))
            {
                const string cloudStorageFormat = "DefaultEndpointsProtocol={0};AccountName={1};AccountKey={2}";
                string storageHttpKey = string.Format(cloudStorageFormat, "http", this.StorageAccountName, primaryKey);
                string storageHttpsKey = string.Format(cloudStorageFormat, "https", this.StorageAccountName, primaryKey);

                for (int i = 0; i < cloudSvcConfig.Role.Length; i++)
                {
                    if (cloudSvcConfig.Role[i].name.Equals(this.CouchDBRoleName))
                    {
                        CouchDBDeployCmdlets.ServiceConfigurationSchema.ConfigurationSetting newSetting;
                        newSetting = new ServiceConfigurationSchema.ConfigurationSetting() { name = Resources.DataConnectionStringSettingName, value = storageHttpKey };
                        UpdateSetting(ref cloudSvcConfig.Role[i], newSetting);

                        newSetting = new ServiceConfigurationSchema.ConfigurationSetting() { name = Resources.DiagnosticsConnectionString, value = storageHttpKey };
                        UpdateSetting(ref cloudSvcConfig.Role[i], newSetting);

                        newSetting = new CouchDBDeployCmdlets.ServiceConfigurationSchema.ConfigurationSetting() { name = Resources.DiagnosticsConnectionString, value = storageHttpsKey };
                        UpdateSetting(ref cloudSvcConfig.Role[i], newSetting);
                    }
                }

                if (svcDef.WorkerRole != null)
                {
                    foreach (WorkerRole role in svcDef.WorkerRole)
                    {
                        if (role.name.Equals(this.CouchDBRoleName))
                        {
                            if (role.LocalResources != null)
                            {
                                foreach (LocalStore store in role.LocalResources.LocalStorage)
                                {
                                    if (store.name.Equals(Resources.LocalStorageCouchInstall) && session[Resources.LocalStorageCouchInstall] != null)
                                    {
                                        store.sizeInMB = Convert.ToInt32(session[Resources.LocalStorageCouchInstall]);
                                    }
                                    if (store.name.Equals(Resources.LocalStorageAzureDriveCache) && session[Resources.LocalStorageAzureDriveCache] != null)
                                    {
                                        store.sizeInMB = Convert.ToInt32(session[Resources.LocalStorageAzureDriveCache]);
                                    }
                                }
                            }
                        }
                    }
                }

                // Serialize local.cscfg
                General.SerializeXmlFile<ServiceConfiguration>(cloudSvcConfig, cloudSvcConfigFileName);
                General.SerializeXmlFile<ServiceDefinition>(svcDef, serviceDefinitionFileName);

                return true;
            }
            return false;
        }