public virtual void UpdateSetting(DcSetting setting) { if (setting == null) { throw new ArgumentNullException("setting is null"); } if (string.IsNullOrWhiteSpace(setting.Key)) { throw new ArgumentNullException("setting.key is null"); } _dcSettings.TryGetValue(setting, out DcSetting oldValue); if (oldValue != null) { if (object.Equals(oldValue.Value, setting.Value)) { return; } } setting = (DcSetting)setting.Clone(); _dcSettings[setting] = setting; RaiseChangeEvent(); }
public override bool Equals(object obj) { if (object.ReferenceEquals(this, obj)) { return(true); } if (obj == null) { return(false); } if (GetType() != obj.GetType()) { return(false); } DcSetting other = (DcSetting)obj; if (App == null) { if (other.App != null) { return(false); } } else if (!App.Equals(other.App)) { return(false); } if (Dc == null) { if (other.Dc != null) { return(false); } } else if (!Dc.Equals(other.Dc)) { return(false); } if (Key == null) { if (other.Key != null) { return(false); } } else if (!Key.Equals(other.Key)) { return(false); } return(true); }
public virtual void RemoveSetting(DcSetting setting) { if (setting == null) { throw new ArgumentNullException("setting is null"); } if (string.IsNullOrWhiteSpace(setting.Key)) { throw new ArgumentNullException("setting.key is null"); } _dcSettings.TryRemove(setting, out DcSetting oldValue); if (oldValue == null) { return; } RaiseChangeEvent(); }
public YamlDcConfigurationSource(YamlFileConfigurationSourceConfig config) : base(config) { _dcSettings = new Dictionary <DcSetting, DcSetting>(); try { using (Stream @is = new FileStream(config.FileName, FileMode.Open)) { if (@is == null) { Logger.Warn("file not found: {0}", config.FileName); return; } StreamReader fileReader = new StreamReader(config.FileName, new UTF8Encoding(false)); YamlStream yamlStream = new YamlStream(); yamlStream.Load(fileReader); if (!(yamlStream.Documents[0].RootNode is YamlSequenceNode)) { Logger.Error(typeof(YamlFileConfigurationSource).Name + " only accepts YAML file with Sequence root. Current is Mapping or Scala. YAML file: " + config.FileName); return; } YamlSequenceNode properties = (YamlSequenceNode)yamlStream.Documents[0].RootNode; properties.Children.ToList().ForEach(m => { DcSetting dcSetting = Convert <DcSetting>(m); _dcSettings[dcSetting] = dcSetting; }); } } catch (Exception e) { Logger.Warn(e, "failed to load yaml file: " + config.FileName); } }
protected override DcSetting GetPropertyValue(DcSetting setting) { _dcSettings.TryGetValue(setting, out DcSetting value); return(value); }
protected abstract DcSetting GetPropertyValue(DcSetting setting);
protected virtual String GetPropertyValue(String key, String app, String dc) { DcSetting dcSetting = GetPropertyValue(new DcSetting(key, app, dc, null)); return(dcSetting == null ? null : dcSetting.Value); }