You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.8 KiB
68 lines
1.8 KiB
using System.Configuration;
|
|
|
|
namespace EC.AutoWeightServer.Model.Config
|
|
{
|
|
public class BaseConfig
|
|
{
|
|
#region App.config (*.exe.config)
|
|
|
|
public static string GetAppConfig(string key)
|
|
{
|
|
return ConfigurationManager.AppSettings[key].Trim();
|
|
}
|
|
|
|
public static void SetAppConfig(string key, string value)
|
|
{
|
|
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
|
config.AppSettings.Settings[key].Value = value;
|
|
// Save the configuration file.
|
|
config.AppSettings.SectionInformation.ForceSave = true;
|
|
config.Save(ConfigurationSaveMode.Modified);
|
|
// Force a reload of the changed section.
|
|
ConfigurationManager.RefreshSection("appSettings");
|
|
}
|
|
|
|
#endregion App.config (*.exe.config)
|
|
|
|
#region other.config
|
|
|
|
/// <summary>
|
|
/// 打开指定的配置文件;
|
|
/// </summary>
|
|
public static Configuration GetConfiguration(string configFile)
|
|
{
|
|
var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = configFile };
|
|
return ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
|
|
}
|
|
|
|
public static string GetConfig(Configuration config, string key)
|
|
{
|
|
return config.AppSettings.Settings[key].Value.Trim();
|
|
}
|
|
|
|
public static void SetConfig(Configuration config, string key, string value)
|
|
{
|
|
config.AppSettings.Settings[key].Value = value;
|
|
config.AppSettings.SectionInformation.ForceSave = true;
|
|
config.Save(ConfigurationSaveMode.Modified);
|
|
}
|
|
|
|
#endregion other.config
|
|
|
|
#region Voice.config
|
|
|
|
private static readonly Configuration VoiceConfig = GetConfiguration("Voice.config");
|
|
|
|
public static string GetVoiceConfig(string key)
|
|
{
|
|
return GetConfig(VoiceConfig, key);
|
|
}
|
|
|
|
public static void SetVoiceConfig(string key, string value)
|
|
{
|
|
SetConfig(VoiceConfig, key, value);
|
|
}
|
|
|
|
#endregion Voice.config
|
|
}
|
|
}
|