private void AddRole(RoleSettings roleToAdd, string cscfgFileLoc) { ServiceConfigurationSchema.ServiceConfiguration config = SerializationUtils.DeserializeXmlFile <ServiceConfigurationSchema.ServiceConfiguration>(cscfgFileLoc); string roleNameToAdd = roleToAdd.name.ToUpperInvariant(); if (config.Role != null) { //Check if role to be added is already present inside the cscfg. If so just update instance count. RoleSettings matchingRoleInConfig = config.Role.Where(eachRole => eachRole.name.ToUpperInvariant() == roleNameToAdd).FirstOrDefault(); if (matchingRoleInConfig != null) { ConfigureInstCount(matchingRoleInConfig); SerializationUtils.SerializeXmlFile <ServiceConfigurationSchema.ServiceConfiguration>(config, cscfgFileLoc); WriteObject(string.Format(CultureInfo.InvariantCulture, Resources.RoleAlreadyPresentInCSCFG, roleNameToAdd, matchingRoleInConfig.Instances.count.ToString(CultureInfo.InvariantCulture))); return; } } List <ServiceConfigurationSchema.RoleSettings> roles = new List <ServiceConfigurationSchema.RoleSettings>(); //Retain existing roles inside the cscfg. if (config.Role != null) { roles.AddRange(config.Role); } roles.Add(roleToAdd); config.Role = roles.ToArray(); SerializationUtils.SerializeXmlFile <ServiceConfigurationSchema.ServiceConfiguration>(config, cscfgFileLoc); }
private void ConfigureRoleStorageAccountKeys(ServiceConfigurationSchema.ServiceConfiguration config, string primaryKey) { string cloudStorageFormat = "DefaultEndpointsProtocol={0};AccountName={1};AccountKey={2}"; string cloudStorageFormatCnHttp = "DefaultEndpointsProtocol={0};AccountName={1};AccountKey={2};" + "BlobEndpoint=http://{1}.blob.core.chinacloudapi.cn/;" + "QueueEndpoint=http://{1}.queue.core.chinacloudapi.cn/;" + "TableEndpoint=http://{1}.table.core.chinacloudapi.cn/"; string cloudStorageFormatCnHttps = "DefaultEndpointsProtocol={0};AccountName={1};AccountKey={2};" + "BlobEndpoint=https://{1}.blob.core.chinacloudapi.cn/;" + "QueueEndpoint=https://{1}.queue.core.chinacloudapi.cn/;" + "TableEndpoint=https://{1}.table.core.chinacloudapi.cn/"; string httpUrlformatBasedOnEnv = Utils.IsChinaCloud == false ? cloudStorageFormat : cloudStorageFormatCnHttp; string httpsUrlformatBasedOnEnv = Utils.IsChinaCloud == false ? cloudStorageFormat : cloudStorageFormatCnHttps; string storageHttpKey = string.Format(CultureInfo.InvariantCulture, httpUrlformatBasedOnEnv, "http", this.StorageAccount, primaryKey); string storageHttpsKey = string.Format(CultureInfo.InvariantCulture, httpsUrlformatBasedOnEnv, "https", this.StorageAccount, primaryKey); for (int i = 0; i < config.Role.Length; i++) { ServiceConfigurationSchema.ConfigurationSetting newSetting; newSetting = new ServiceConfigurationSchema.ConfigurationSetting() { name = Resources.DataConnectionString, value = storageHttpKey }; UpdateSetting(ref config.Role[i], newSetting); newSetting = new ServiceConfigurationSchema.ConfigurationSetting() { name = Resources.DiagnosticsConnectionString, value = storageHttpsKey }; UpdateSetting(ref config.Role[i], newSetting); } SerializationUtils.SerializeXmlFile <ServiceConfigurationSchema.ServiceConfiguration>(config, CloudCSCFGFile); }
private void SetStorageAccount() { if (!StorageAccountExists()) { CreateStorageAccount(); WriteObject(string.Format(CultureInfo.InvariantCulture, Resources.StorageAccCreatedMessage, this.StorageAccount)); } else { WriteObject(string.Format(CultureInfo.InvariantCulture, Resources.StorageAccAlreadyExistsMessage, this.StorageAccount)); } if (SetDefault.IsPresent == true) { SetAccountAsDefault(); } if (CreateOnly.IsPresent == true) { return; } ServiceConfigurationSchema.ServiceConfiguration config = SerializationUtils.DeserializeXmlFile <ServiceConfigurationSchema.ServiceConfiguration>(CloudCSCFGFile); string primaryKey = GetStorageAccKey(); ConfigureRoleStorageAccountKeys(config, primaryKey); WriteObject(Resources.StorageAccConfigSuccess); }
private void UpdateCSCFG() { string normalizedRoleName = this.RoleName.ToUpperInvariant(); ServiceConfigurationSchema.ServiceConfiguration sourceCSCFG = SerializationUtils.DeserializeXmlFile <ServiceConfigurationSchema.ServiceConfiguration>(CscfgFile); ServiceConfigurationSchema.RoleSettings roleToAdd = sourceCSCFG.Role.Where(eachRole => eachRole.name.ToUpperInvariant() == normalizedRoleName).FirstOrDefault(); if (roleToAdd == null) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.RoleNotFoundInCSCFG, this.RoleName)); } ConfigureInstCount(roleToAdd); OverrideSettings(roleToAdd); AddRole(roleToAdd, CloudCSCFGFile); AddRole(roleToAdd, LocalCSCFGFile); }