protected virtual void RaiseChangeEvent(IProperty property, IPropertyChangeEvent @event) { MethodInfo raiseChangeEventMethod = property.GetType() .GetMethod("RaiseChangeEvent", BindingFlags.Instance | BindingFlags.NonPublic); raiseChangeEventMethod.Invoke(property, new object[] { @event }); }
protected virtual void OnSourceChange(object source, IConfigurationSourceChangeEvent sourceEvent) { lock (_propertiesLock) { foreach (IProperty p in _properties.Values) { object oldValue = p.Value; Tuple <object, IConfigurationSource> valueSource = DoGetPropertyValue(p.Config); if (p.Config.IsStatic) { string message = string.Format("ignore dynamic change for static property, " + "dynamic change for static property will be applied when app restart, " + "static: {0}, dynamic: {1}, property: {2}", oldValue, valueSource.Item1, p.Config.Key); Logger.Warn(message); return; } if (valueSource.Item1 == null && p.Config.IsRequired) { string message = string.Format("ignore dynamic change for required property, " + "required property cannot be changed to None, " + "now keep its current value, you should fix the invalid change at once, " + "or app will panic when next app restart, property: {0}", p.Config.Key); Logger.Error(message); return; } if (p.Config.ValueComparator.Compare(oldValue, valueSource.Item1) == 0) { continue; } UpdateProperty(p, valueSource.Item1, valueSource.Item2); IPropertyChangeEvent @event = NewPropertyChangeEvent(p, oldValue, valueSource.Item1); _config.TaskExecutor(() => RaiseChangeEvent(p, @event)); _config.TaskExecutor(() => RaiseChangeEvent(@event)); } } }
protected virtual void OnSourceChange(object source, IConfigurationSourceChangeEvent sourceEvent) { lock (_propertiesLock) { foreach (IProperty p in _properties.Values) { object oldValue = p.Value; object newValue = GetPropertyValue(p.Config); if (Object.Equals(oldValue, newValue)) { continue; } SetPropertyValue(p, newValue); IPropertyChangeEvent @event = NewPropertyChangeEvent(p, oldValue, newValue); _config.TaskExecutor(() => RaiseChangeEvent(p, @event)); _config.TaskExecutor(() => RaiseChangeEvent(@event)); } } }
protected virtual void RaiseChangeEvent(IPropertyChangeEvent @event) { if (_changeListeners == null) { return; } lock (this) { _changeListeners.ForEach(l => { try { l(@event.Property, @event); } catch (Exception e) { Logger.Error(e, "property change listener failed to run"); } }); } }