コード例 #1
0
        private void OverrideSettings(RoleSettings roleToAdd)
        {
            if (string.IsNullOrEmpty(this.Settings) == true)
            {
                return;
            }
            if (roleToAdd.ConfigurationSettings == null)
            {
                WriteWarning(Resources.SettingsAbsentInCSCFG);
                return;
            }
            string[] separatedSetting = Settings.Split(SettingSplitter, StringSplitOptions.RemoveEmptyEntries);
            foreach (string eachSetting in separatedSetting)
            {
                string[] settingsPart = eachSetting.Split(SettingPartSplitter, StringSplitOptions.RemoveEmptyEntries);

                //Find setting in the role to add.
                ServiceConfigurationSchema.ConfigurationSetting settingToOverride =
                    roleToAdd.ConfigurationSettings.Where(e => e.name.ToLowerInvariant() == settingsPart[0].ToLowerInvariant()).FirstOrDefault();
                //OOPS not found.
                if (settingToOverride == null)
                {
                    WriteWarning(string.Format(CultureInfo.InvariantCulture, Resources.SettingsAbsentInCSCFG, settingsPart[0]));
                    continue;
                }
                //Update.
                settingToOverride.value = settingsPart[1];
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 private static void UpdateSetting(ref RoleSettings rs, ServiceConfigurationSchema.ConfigurationSetting cs)
 {
     if (rs.ConfigurationSettings == null)
     {
         return;
     }
     for (int i = 0; i < rs.ConfigurationSettings.Length; i++)
     {
         ServiceConfigurationSchema.ConfigurationSetting setting = rs.ConfigurationSettings[i];
         if (setting.name == cs.name)
         {
             setting.value = cs.value;
             break;
         }
     }
 }
コード例 #4
0
        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);
        }