internal static bool TryRefCount <TValue>( this TValue value, out IRefCounted <TValue> refCounted) where TValue : class, IDisposable { return(TryRefCount(value, out refCounted, out var created)); }
internal static bool TryCreate(object x, object y, MemberSettings settings, out IRefCounted <DiffBuilder> subDiffBuilder) { bool created; subDiffBuilder = TrackerCache.GetOrAdd(x, y, settings, pair => new DiffBuilder(pair, settings), out created); return(created); }
/// <summary> /// Releases the given object if its reference count is 0. /// </summary> static public void TryRelease(this IRefCounted inRef) { if (inRef.ReferenceCount == 0) { inRef.OnReleased(); } }
internal IndexNode(T parent, T node, int index) { this.parent = parent; this.Index = index; this.node = node.RefCount(); this.node.Value.Changed += this.OnNodeChanged; }
internal PropertyNode(T parent, T node, PropertyInfo propertyInfo) { this.parent = parent; this.PropertyInfo = propertyInfo; this.node = node.RefCount(); this.node.Value.Changed += this.OnNodeChanged; }
internal static bool TryRefCount <TValue>(this TValue value, out IRefCounted <TValue> refCounted, out bool created) where TValue : class, IDisposable { refCounted = RefCountedItem <TValue> .AddOrUpdate(value, out var count, out created); return(count > 0); }
internal Synchronizer(INotifyPropertyChanged source, INotifyPropertyChanged target, PropertiesSettings settings) { this.Settings = settings; this.dirtyTrackerNode = DirtyTrackerNode.GetOrCreate(source, target, settings, true); this.dirtyTrackerNode.Value.Changed += this.OnDirtyTrackerNodeChanged; this.borrowedQueue = ConcurrentQueuePool<DirtyTrackerNode>.Borrow(); this.AddToSyncQueue(this.dirtyTrackerNode.Value); }
public ChangeTracker(INotifyPropertyChanged source, PropertiesSettings settings) { Ensure.NotNull(source, nameof(source)); Ensure.NotNull(settings, nameof(settings)); Track.Verify.CanTrackType(source.GetType(), settings); this.Settings = settings; this.node = ChangeTrackerNode.GetOrCreate(source, settings, true); this.node.Value.Changed += this.OnNodeChange; }
internal Synchronizer(INotifyPropertyChanged source, INotifyPropertyChanged target, PropertiesSettings settings) { this.Settings = settings; this.dirtyTrackerNode = DirtyTrackerNode.GetOrCreate(source, target, settings, true); this.dirtyTrackerNode.Value.Changed += this.OnDirtyTrackerNodeChanged; this.borrowedQueue = ConcurrentQueuePool <DirtyTrackerNode> .Borrow(); this.AddToSyncQueue(this.dirtyTrackerNode.Value); }
private DiffBuilder(IRefCounted <ReferencePair> refCountedPair, MemberSettings settings) { this.refCountedPair = refCountedPair; this.settings = settings; this.borrowedDiffs = DictionaryPool <object, SubDiff> .Borrow(); this.borrowedSubBuilders = DictionaryPool <object, IRefCounted <DiffBuilder> > .Borrow(); this.valueDiff = new ValueDiff(refCountedPair.Value.X, refCountedPair.Value.Y, this.diffs); }
private bool TrCreateChild(object xValue, object yValue, out IRefCounted <DirtyTrackerNode> childNode) { if (!IsTrackablePair(xValue, yValue, this.Settings) || this.Settings.ReferenceHandling != ReferenceHandling.Structural) { childNode = null; return(false); } childNode = GetOrCreate(xValue, yValue, this.Settings, false); return(true); }
/// <summary> /// Acquires a reference to the given object. /// </summary> static public void AcquireRef(this IRefCounted inRef, int inRefCount = 1) { if (inRefCount <= 0) { return; } inRef.ReferenceCount += inRefCount; if (inRef.ReferenceCount == inRefCount) { inRef.OnReferenced(); } }
/// <summary> /// Releases a reference to the given object. /// </summary> static public void ReleaseRef(this IRefCounted inRef, int inRefCount = 1) { if (inRefCount <= 0) { return; } inRef.ReferenceCount -= inRefCount; if (inRef.ReferenceCount == 0) { inRef.OnReleased(); } }
private ChangeTrackerNode(object source, PropertiesSettings settings, bool isRoot) { this.refcountedRootChanges = RootChanges.GetOrCreate(source, settings, isRoot); var sourceChanges = this.refcountedRootChanges.Value; this.children = ChildNodes <ChangeTrackerNode> .Borrow(); sourceChanges.PropertyChange += this.OnSourcePropertyChange; if (Is.NotifyingCollection(source)) { this.ItemType = this.SourceList.GetType() .GetItemType(); sourceChanges.Add += this.OnSourceAdd; sourceChanges.Remove += this.OnSourceRemove; sourceChanges.Replace += this.OnSourceReplace; sourceChanges.Move += this.OnSourceMove; sourceChanges.Reset += this.OnSourceReset; } }
/// <summary> /// Initializes a new instance of the <see cref="DirtyTrackerNode"/> class. /// A call to Initialize is needed after the ctor due to that we need to fetch child nodes and the graph can contain self /// </summary> private DirtyTrackerNode(IRefCounted <ReferencePair> refCountedPair, PropertiesSettings settings, bool isRoot) { this.refCountedPair = refCountedPair; var x = refCountedPair.Value.X; var y = refCountedPair.Value.Y; this.children = ChildNodes <DirtyTrackerNode> .Borrow(); this.xNode = RootChanges.GetOrCreate(x, settings, isRoot); this.yNode = RootChanges.GetOrCreate(y, settings, isRoot); this.xNode.Value.PropertyChange += this.OnTrackedPropertyChange; this.yNode.Value.PropertyChange += this.OnTrackedPropertyChange; this.IsTrackingCollectionItems = Is.Enumerable(x, y) && !settings.IsImmutable(x.GetType().GetItemType()) && !settings.IsImmutable(y.GetType().GetItemType()); if (Is.NotifyingCollections(x, y)) { this.xNode.Value.Add += this.OnTrackedAdd; this.xNode.Value.Remove += this.OnTrackedRemove; this.xNode.Value.Replace += this.OnTrackedReplace; this.xNode.Value.Move += this.OnTrackedMove; this.xNode.Value.Reset += this.OnTrackedReset; this.yNode.Value.Add += this.OnTrackedAdd; this.yNode.Value.Remove += this.OnTrackedRemove; this.yNode.Value.Replace += this.OnTrackedReplace; this.yNode.Value.Move += this.OnTrackedMove; this.yNode.Value.Reset += this.OnTrackedReset; } var builder = DiffBuilder.GetOrCreate(x, y, settings); builder.Value.UpdateDiffs(x, y, settings); builder.Value.Refresh(); this.refcountedDiffBuilder = builder; this.isDirty = !this.Builder.IsEmpty; }
public Recursive(IRefCounted<ReferencePair> pair, MemberSettings settings) { this.Next = TrackerCache.GetOrAdd(pair.Value.X, pair.Value.Y, settings, x => new Recursive(x, settings)); }
internal static bool TryGetOrCreate(object source, PropertiesSettings settings, bool isRoot, out IRefCounted <ChangeTrackerNode> result) { var inpc = source as INotifyPropertyChanged; if (inpc != null) { result = GetOrCreate(inpc, settings, isRoot); return(true); } var incc = source as INotifyCollectionChanged; if (incc != null) { result = GetOrCreate(incc, settings, isRoot); return(true); } result = null; return(false); }
internal DirtyTracker(INotifyPropertyChanged x, INotifyPropertyChanged y, PropertiesSettings settings) { this.Settings = settings; this.node = DirtyTrackerNode.GetOrCreate(x, y, settings, isRoot: true); this.node.Value.PropertyChanged += this.OnNodeChanged; }
public Recursive(IRefCounted <ReferencePair> pair, MemberSettings settings) { this.Next = TrackerCache.GetOrAdd(pair.Value.X, pair.Value.Y, settings, x => new Recursive(x, settings)); }
internal DirtyTracker(INotifyPropertyChanged x, INotifyPropertyChanged y, PropertiesSettings settings) { this.Settings = settings; this.node = DirtyTrackerNode.GetOrCreate(x, y, settings, true); this.node.Value.PropertyChanged += this.OnNodeChanged; }
/// <summary> /// Returns if this object has active references. /// </summary> static public bool IsReferenced(this IRefCounted inRef) { return(inRef.ReferenceCount > 0); }