| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- namespace CommonTool
- {
- public class AppConfig
- {
- public AppConfig(string pcConfigFilePath)
- {
- _configFile = pcConfigFilePath;
- }
- private void LoadSetting()
- {
- string text1 = FileFuns.ReadFileAsString(FileName);
- if (text1 != "")
- {
- _settings = SnXmlNode.ParseGenericXml(text1);
- }
- }
- public bool ReadBool(string pcConfigId)
- {
- return UtilStr.StrToBool(ReadString(pcConfigId));
- }
- public int ReadInt(string pcConfigId)
- {
- return Utils.ValI(ReadString(pcConfigId));
- }
- public decimal ReadDouble(string pcConfigId)
- {
- return Utils.ValD(ReadString(pcConfigId));
- }
- public string ReadString(string pcConfigId)
- {
- return Settings.GetChildValue(pcConfigId);
- }
- public SnXmlNode ReadNode(string pcConfigId)
- {
- return Settings.GetChildNode(pcConfigId);
- }
- public string ReadString(string pcConfigId, string defaultValue)
- {
- string lcStr = Settings.GetChildValue(pcConfigId);
- if (string.IsNullOrEmpty(lcStr))
- {
- lcStr = defaultValue;
- }
- return lcStr;
- }
- public void SaveSetting()
- {
- FileFuns.WriteStringToFile(Settings.ToAllXmlString(), FileName);
- }
- public void SetString(string pcConfigId, string pcValue)
- {
- string text1 = UtilStr.UAndT(pcConfigId);
- Settings.SetChildValue(text1, pcValue);
- SaveSetting();
- }
- //读取指定文件的配置信息,保存到当前的配置文件中
- public void ResetSetting(string pcString)
- {
- if (pcString != "")
- {
- _settings = SnXmlNode.ParseGenericXml(pcString);
- }
- else
- {
- LoadSetting();
- }
- SaveSetting();
- }
- //重新装载配置信息
- public void RelandConfig(string pcPath)
- {
- LoadSetting();
- }
- #region Properties
- private string FileName
- {
- get
- {
- if (_configFile == "")
- {
- _configFile = AppEnv.ConfigFile;
- }
- return _configFile;
- }
- }
- string _configFile;
- public SnXmlNode Settings
- {
- get
- {
- if (_settings == null)
- {
- LoadSetting();
- }
- return _settings;
- }
- }
- #endregion
- #region Fields
- private SnXmlNode _settings;
- #endregion
- static AppConfig _defConfig;
- public static AppConfig DefConfig => _defConfig ?? (_defConfig = new AppConfig(""));
- static AppConfig _languages;
- public static AppConfig Languages
- {
- get
- {
- if (_languages != null) return _languages;
- _languages = new AppConfig(DefConfig.ReadString("LanguagesPath"));
- return _languages;
- }
- }
- }
- }
|