public EventSuppressor(ChangeTrackingManager manager, bool callConfigurationChangedWhenDisposed) { _manager = manager; _callConfigurationChangedWhenDisposed = callConfigurationChangedWhenDisposed; if (!manager._suppressEvents) { _didSuppress = true; _manager._suppressEvents = true; } }
private async Task UpdateAllIntern(ChangeTrackingManager changeTrackingManager) { IsBusy = true; var editables = changeTrackingManager.ToList(); try { foreach (var editable in editables) { await editable.UpdateCalculatedValuesAsync(); } } catch (Exception e) { Console.WriteLine(e); throw; } IsBusy = false; }
/// <summary> /// Creates IEditableConfig for each public get and set-able property of the given instance. /// Optionally gives a IEditableConfig for the given instance itself, instead of its properties. /// </summary> public IEnumerable <IEditableConfig> Reflect(object configurable, ChangeTrackingManager changeTrackingManager, bool useConfigurableItself = false) { using (changeTrackingManager.SuppressEvents(true)) { if (useConfigurableItself) { var wrapperType = typeof(InstanceWrapper <>).MakeGenericType(configurable.GetType()); var wrapper = Activator.CreateInstance(wrapperType, configurable); return(new List <IEditableConfig> { EditableConfigFromPropertyInfo(wrapper, wrapper.GetType().GetProperty(nameof(InstanceWrapper <int> .Value)), changeTrackingManager) }); } else { var editableProperties = EditableProperties(configurable.GetType()); var trackingManager = changeTrackingManager; return(editableProperties.Select(t => EditableConfigFromPropertyInfo(configurable, t, trackingManager))); } } }
private IEditableConfig EditableConfigFromPropertyInfo(object configurable, PropertyInfo propertyInfo, ChangeTrackingManager changeTrackingManager) { var editableType = EditableType(propertyInfo); object instance = null; try { if (IsComplex(propertyInfo) && HasCyclicTypes(propertyInfo, new[] { configurable.GetType() })) { throw new Exception("Cyclic type dependency detected. This is currently not supported."); } instance = Activator.CreateInstance(editableType, configurable, propertyInfo, this, changeTrackingManager); } catch (Exception e) { Debug.Fail($"Failed to create instance of type {editableType}. Exception: {e}"); } if (instance is IEditableConfig editableConfig) { if (configurable is INotifyPropertyChanged asNotifyPropertyChanged) { changeTrackingManager.RegisterPropertyChangedListener(asNotifyPropertyChanged, editableConfig); } return(editableConfig); } Debug.Fail($"Failed to cast type {editableType} to {typeof(IEditableConfig)}."); return(new EditableDummy(configurable, propertyInfo, this, changeTrackingManager)); }
public void UpdateAll(ChangeTrackingManager changeTrackingManager) { WaitForCurrentTask(); _currentTask = UpdateAllIntern(changeTrackingManager); }