Пример #1
0
 public override void Init(SubsystemConfig config)
 {
     _config = (ConfigurationManagerConfig)config;
     var keyAttributeNames = new Dictionary<string, string> { { "subsystem", "name" } };
     _mergeUtil = new XmlMerge(_config.PrivateConfigElementXPaths.ToList(), keyAttributeNames);
     _currentConfig = CoreApplication.Instance.Config;
     _currentConfigXml = _currentConfig.ToXml();
     _fileSystemManager = Application.GetSubsystemOrThrow<IFileSystemManager>();
     _electionManager = Application.GetSubsystemOrThrow<IElectionManager>();
     WorkingConfigLoaded = false;
     Application.ConfigUpdated += ApplicationConfigUpdated;
 }
Пример #2
0
 public static ApplicationConfig FromXml(string xml)
 {
     try
     {
         var config = new ApplicationConfig();
         using (var stream = new StringReader(xml))
         using (var reader = XmlReader.Create(stream))
             config.DeserializeSection(reader);
         return config;
     }
     catch (Exception ex)
     {
         throw new Exception("Ошибка загрузки конфиг-секции из xml: " + xml, ex);
     }
 }
Пример #3
0
 public bool LoadPartialConfig(ref string partialConfigXml)
 {
     if (string.IsNullOrEmpty(partialConfigXml))
     {
         var partialConfigFile = FindPartialConfigFile();
         if (partialConfigFile == null)
             return true;
         try
         {
             using (var reader = partialConfigFile.OpenText())
                 partialConfigXml = reader.ReadToEnd();
         }
         catch (Exception ex)
         {
             Logger.LogError(Message.ConfigReadPartialError, ex);
             return false;
         }
     }
     try
     {
         if (_mergeUtil.Merge(partialConfigXml, _currentConfigXml))
         {
             string resXml;
             using (var memStream = new MemoryStream())
             {
                 using (var xmlWriter = new PrettyPrintXmlWriter(memStream))
                 {
                     _mergeUtil.Result.WriteTo(xmlWriter);
                     resXml = xmlWriter.ToFormatString();
                 }
             }
             _currentConfig = ApplicationConfig.FromXml(resXml);
             _currentConfigXml = resXml;
         }
         return true;
     }
     catch (Exception ex)
     {
         Logger.LogError(Message.ConfigLoadPartialError, ex);
         return false;
     }
 }
Пример #4
0
 private void ApplicationConfigUpdated(object sender, ConfigUpdatedEventArgs e)
 {
     _currentConfig = Application.Config;
     _currentConfigXml = Application.Config.ToXml();
     SaveWorkingConfig();
     Logger.LogInfo(Message.ConfigSubsystemConfigUpdated,
                    e.UpdatedParameterName, e.SubsystemName, e.OldValue, e.NewValue);
 }
Пример #5
0
 public bool LoadWorkingConfig()
 {
     if (!File.Exists(_config.WorkingConfigFilePath.Value))
         return true;
     try
     {
         _currentConfig = ConfigurationUtils.GetSection<ApplicationConfig>(
             _config.WorkingConfigFilePath.Value, ApplicationConfig.SECTION_NAME);
         _currentConfigXml = _currentConfig.ToXml();
         return true;
     }
     catch (Exception ex)
     {
         Logger.LogError(Message.ConfigLoadWorkingError, ex);
         return false;
     }
 }