private CommonConfigurationAgent GetConfigurationAgentInternal(Guid id, object changeSource = null) { if (_configDictionary.ContainsKey(id)) { return(_configDictionary[id]); } // Create a new configuration entity var agent = new CommonConfigurationAgent(id, _logger); var s = agent.Updated.Do(Agent_Updated).Subscribe(); _agentUpdateSubscriptions.Add(s); _configDictionary.Add(id, agent); return(agent); }
public void LoadConfiguration(string fileName) { _logger?.Info($"Loading configuration from file '{fileName}'."); _logger?.Debug("Clearing configuration dictionary."); _configDictionary.Clear(); CommonConfigurationAgent GetOrCreate(Guid id) { if (_configDictionary.ContainsKey(id)) { return(_configDictionary[id]); } var agent = new CommonConfigurationAgent(id, _logger); var s = agent.Updated.Do(Agent_Updated).Subscribe(); _agentUpdateSubscriptions.Add(s); _configDictionary.Add(id, agent); return(agent); } if (File.Exists(fileName)) { try { _logger?.Debug("Loading configuration xml document."); var doc = XDocument.Load(fileName); var xmlElements = doc.Root?.Elements(ConfigurationConstants.ConfigurationEntityTag); if (xmlElements == null) { return; } foreach (var el in xmlElements) { var id = (Guid)el.Attribute("Id"); _logger?.Debug($"Entity discovered with Id '{id}'."); var agent = GetOrCreate(id); agent.Update(el, this); } } catch (Exception ex) { _logger?.Error("An error occured whilst loading configuration."); _logger?.Error(ex); _configDictionary.Clear(); throw new Exception("Unable to load configuration from the specified path.", ex); } } else { _logger?.Warning("An attempt was made to load configuration that doesn't exist."); } }