コード例 #1
0
ファイル: Profiguration.cs プロジェクト: dekkerb115/Bam.Net
        /// <summary>
        /// Encrypts the appsetting values specified by the appsetting with the key EncryptAppSettings.
        /// Encrypts the connection strings specified by the appsetting with the key EncryptConnStrings.
        /// Values are expected to be comma and/or semi colon separated lists of keys or names.
        /// Saves the specified values to and injects values from Profiguration.Default
        /// </summary>
        public static void Initialize()
        {
            string appKeysString        = DefaultConfiguration.GetAppSetting(EncryptAppSettingsKey);
            string connStringKeysString = DefaultConfiguration.GetAppSetting(EncryptConnStringsKey);

            Profiguration prof = Profiguration.Default;

            if (!string.IsNullOrEmpty(appKeysString))
            {
                string[] appSettingKeys = appKeysString.DelimitSplit(",", ";");
                foreach (string key in appSettingKeys)
                {
                    prof.CopyAppSetting(key);
                }
            }

            if (!string.IsNullOrEmpty(connStringKeysString))
            {
                string[] connStringNames = connStringKeysString.DelimitSplit(",", ";");
                foreach (string name in connStringNames)
                {
                    prof.CopyConnectionString(name);
                }
            }

            prof.Save();
            prof.Inject();
        }