private void handlePropertyHolderPropertyChanged(object sender, PropertyChangedEventArgs e) { TResult value = getValue(); _destinationOcDispatcher.Invoke( () => setValue(value), _destinationOcDispatcherPriority, _destinationOcDispatcherParameter, this); }
private void HandleSourcePropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName != _propertyName) { return; } TResult value = getValue(); _destinationOcDispatcher.Invoke( () => setValue(value), _destinationOcDispatcherPriority, _destinationOcDispatcherParameter, this); }
protected override void processSource() { if (_sourceReadAndSubscribed) { _source.PropertyChanged -= handleSourceScalarPropertyChanged; _sourceReadAndSubscribed = false; } if (_isActive) { void readAndSubscribe() { TResult newValue = _source.Value; void setNewValue() => setValue(newValue); _source.PropertyChanged += handleSourceScalarPropertyChanged; _destinationOcDispatcher.Invoke( setNewValue, _destinationOcDispatcherPriority, _destinationOcDispatcherParameter, this); } if (_sourceOcDispatcher != null) { _sourceOcDispatcher.Invoke( readAndSubscribe, _sourceOcDispatcherPriority, _sourceOcDispatcherParameter, this); } else { readAndSubscribe(); } _sourceReadAndSubscribed = true; } else { void setNewValue() => setDefaultValue(); _destinationOcDispatcher.Invoke( setNewValue, _destinationOcDispatcherPriority, _destinationOcDispatcherParameter, this); } }
public ScalarDispatching( IReadScalar <TResult> source, IOcDispatcher destinationOcDispatcher, IOcDispatcher sourceOcDispatcher = null, int destinationOcDispatcherPriority = 0, int sourceOcDispatcherPriority = 0, object destinationOcDispatcherParameter = null, object sourceOcDispatcherParameter = null) { _destinationOcDispatcher = destinationOcDispatcher; _source = source; _sourceOcDispatcher = sourceOcDispatcher; _changeValueAction = () => { TResult newValue = _source.Value; void setNewValue() => setValue(newValue); _destinationOcDispatcher.Invoke( setNewValue, _destinationOcDispatcherPriority, _destinationOcDispatcherParameter, this); }; _destinationOcDispatcherPriority = destinationOcDispatcherPriority; _sourceOcDispatcherPriority = sourceOcDispatcherPriority; _destinationOcDispatcherParameter = destinationOcDispatcherParameter; _sourceOcDispatcherParameter = sourceOcDispatcherParameter; }
private void invokeProcessSource(object sender, EventArgs e) { if (_source != null) { _source.CollectionChanged -= handleSourceCollectionChanged; } _destinationOcDispatcher.Invoke( () => doProcessSource(sender, e), _destinationOcDispatcherPriority, _destinationOcDispatcherParameter, this); }
public ThrottlingDispatcher(TimeSpan timeSpan, IOcDispatcher destinationOcDispatcher) { _timeSpan = timeSpan; _destinationOcDispatcher = destinationOcDispatcher; _actions = new Subject <Action>(); _cleanUp = _actions.Throttle(timeSpan).Subscribe(action => { _destinationOcDispatcher.Invoke(action, 0, null, this); }); }
private void invokeSourceDispatcher(Action action) { if (_sourceOcDispatcher != null) { _sourceOcDispatcher.Invoke( action, _sourceOcDispatcherPriority, _sourceOcDispatcherParameter, this); } else { action(); } }
private void doProcessSource(object sender, EventArgs e) { int originalCount = _items.Count; if (_sourceReadAndSubscribed) { uninitializeSource(); _sourceReadAndSubscribed = false; void uninitializeSource() { _source.CollectionChanged -= handleSourceCollectionChanged; if (_sourceAsINotifyPropertyChanged != null) { _sourceAsINotifyPropertyChanged.PropertyChanged -= ((ISourceIndexerPropertyTracker)this).HandleSourcePropertyChanged; _sourceAsINotifyPropertyChanged = null; } } if (_sourceOcDispatcher != null) { _sourceOcDispatcher.Invoke( uninitializeSource, _sourceOcDispatcherPriority, _sourceOcDispatcherParameter, this); } else { uninitializeSource(); } } Utils.changeSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this, out _sourceAsList, true); if (_sourceAsList != null && _isActive) { void readAndSubscribe() { Utils.initializeFromHasChangeMarker( out _sourceAsIHasChangeMarker, _sourceAsList, ref _lastProcessedSourceChangeMarker, ref _sourceAsINotifyPropertyChanged, (ISourceIndexerPropertyTracker)this); int count = _sourceAsList.Count; TSourceItem[] sourceCopy = new TSourceItem[count]; _sourceAsList.CopyTo(sourceCopy, 0); _source.CollectionChanged += handleSourceCollectionChanged; void resetAction() { _handledEventSender = sender; _handledEventArgs = e; int sourceIndex = 0; for (int index = 0; index < count; index++) { if (originalCount > sourceIndex) { _items[sourceIndex] = sourceCopy[index]; } else { _items.Insert(sourceIndex, sourceCopy[index]); } sourceIndex++; } for (int index = originalCount - 1; index >= sourceIndex; index--) { _items.RemoveAt(index); } reset(); _handledEventSender = null; _handledEventArgs = null; } _destinationOcDispatcher.Invoke( resetAction, _destinationOcDispatcherPriority, _destinationOcDispatcherParameter, this); } if (_sourceOcDispatcher != null) { _sourceOcDispatcher.Invoke( readAndSubscribe, _sourceOcDispatcherPriority, _sourceOcDispatcherParameter, this); } else { readAndSubscribe(); } _sourceReadAndSubscribed = true; } else { void clearItemsAction() { _handledEventSender = sender; _handledEventArgs = e; baseClearItems(); _handledEventSender = null; _handledEventArgs = null; } _destinationOcDispatcher.Invoke( clearItemsAction, _destinationOcDispatcherPriority, _destinationOcDispatcherParameter, this); } }
protected override void initialize() { PropertyInfo propertyInfo = _source.GetType().GetProperty(_propertyName); if (!_propertyAccessors.TryGetValue(propertyInfo, out PropertyAccessors propertyAccessors)) { ParameterExpression valueParameterExpression = Expression.Parameter(typeof(TResult)); ParameterExpression holderParameterExpression = Expression.Parameter(typeof(TSource)); Action <TSource, TResult> setter = Expression.Lambda <Action <TSource, TResult> >( Expression.Assign(Expression.Property(holderParameterExpression, propertyInfo), valueParameterExpression), holderParameterExpression, valueParameterExpression).Compile(); Func <TSource, TResult> getter = Expression.Lambda <Func <TSource, TResult> >( Expression.Property(holderParameterExpression, propertyInfo), holderParameterExpression).Compile(); propertyAccessors = new PropertyAccessors(getter, setter); _propertyAccessors.TryAdd(propertyInfo, propertyAccessors); } _getter = propertyAccessors.Getter; _setter = propertyAccessors.Setter; _setValueRequestHandler = value => { void set() => _setter(_source, value); if (_sourceOcDispatcher != null) { _sourceOcDispatcher.Invoke( set, _sourceOcDispatcherPriority, _sourceOcDispatcherParameter, this); } else { set(); } }; void readAndSubscribe() { TResult value = getValue(); _source.PropertyChanged += HandleSourcePropertyChanged; _destinationOcDispatcher.Invoke( () => setValue(value), _destinationOcDispatcherPriority, _destinationOcDispatcherParameter, this); } if (_sourceOcDispatcher != null) { _sourceOcDispatcher.Invoke( readAndSubscribe, _sourceOcDispatcherPriority, _sourceOcDispatcherParameter, this); } else { readAndSubscribe(); } }
public static void Invoke(this IOcDispatcher ocDispatcher, Action action, int priority = 0, object parameter = null, object context = null) { ocDispatcher.Invoke(action, priority, parameter, context); }
private void doProcessSource(object sender, EventArgs e, bool replaceSource) { if (_sourceReadAndSubscribed) { _sourceReadAndSubscribed = false; if (replaceSource) { Utils.unsubscribeSource( _source, ref _sourceAsINotifyPropertyChanged, this, handleSourceCollectionChanged); } } if (replaceSource) { Utils.replaceSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this, out _sourceAsList, true); } if (_sourceAsList != null && _isActive) { if (replaceSource) { Utils.subscribeSource( out _sourceAsIHasTickTackVersion, _sourceAsList, ref _lastProcessedSourceTickTackVersion, ref _sourceAsINotifyPropertyChanged, (ISourceIndexerPropertyTracker)this, _source, handleSourceCollectionChanged); } int count = _sourceAsList.Count; TSourceItem[] sourceCopy = new TSourceItem[count]; _sourceAsList.CopyTo(sourceCopy, 0); void resetAction() { int originalCount = _items.Count; _handledEventSender = sender; _handledEventArgs = e; int sourceIndex = 0; for (int index = 0; index < count; index++) { if (originalCount > sourceIndex) { _items[sourceIndex] = sourceCopy[index]; } else { _items.Insert(sourceIndex, sourceCopy[index]); } sourceIndex++; } for (int index = originalCount - 1; index >= sourceIndex; index--) { _items.RemoveAt(index); } reset(); _handledEventSender = null; _handledEventArgs = null; } _destinationOcDispatcher.Invoke( resetAction, _destinationOcDispatcherPriority, _destinationOcDispatcherParameter, this); _sourceReadAndSubscribed = true; } else { void clearItemsAction() { _handledEventSender = sender; _handledEventArgs = e; baseClearItems(); _handledEventSender = null; _handledEventArgs = null; } _destinationOcDispatcher.Invoke( clearItemsAction, _destinationOcDispatcherPriority, _destinationOcDispatcherParameter, this); } }