public void NotifyValueWillBeRemoved <T>(ITrackableCollection <T> trackableCollection, T removed) { AssertNotLocked(); if (!_isEnabled) { return; } var list = trackableCollection as IList <T>; if (list != null) { var index = list.IndexOf(removed); if (index == -1) { return; } _changeHistory.Push(() => trackableCollection.InsertWithoutTracking(removed, index)); return; } if (trackableCollection.Contains(removed)) { _changeHistory.Push(() => trackableCollection.AddWithoutTracking(removed)); } }
public void SetCollection(string property, ITrackableCollection list) { if (_collectionProxies.ContainsKey(property) == false) { _collectionProxies.Add(property, list); } else { _collectionProxies[property] = list; } }
public void NotifyValueAdded <T>(ITrackableCollection <T> trackableCollection, T added) { AssertNotLocked(); if (!_isEnabled) { return; } _changeHistory.Push(() => trackableCollection.RemoveWithoutTracking(added)); }
public async Task <bool> SaveTrackableList(ITrackableCollection <CategoryDTO> collection, CancellationToken token = new CancellationToken()) { try { var response = (await(ControllerPath + "editable").PostJsonAsync(collection, token).ReceiveJson <bool>()); return(response); } catch (Exception e) { throw e; } }
public async Task <bool> SaveEditableListAsync(ITrackableCollection <CategoryDTO> trackableCollection, CancellationToken token = new CancellationToken()) { await InsertHierarchical(trackableCollection.New.ToList()); foreach (var item in trackableCollection.Deleted) { await serviceProvider.GetService <ICategoryRepository>().RemoveAsync(Mapper.Map <Category>(item)); } foreach (var item in trackableCollection.Changed) { await serviceProvider.GetService <ICategoryRepository>().UpdateAsync(Mapper.Map <Category>(item)); } return(true); }
/// <summary> /// Adds/removes and registers/unregisters events associated with <see cref="DataGridExtensions.ScrollAddedIntoViewProperty"/>, respectively. /// </summary> /// <param name="DataGrid"></param> /// <param name="Collection"></param> /// <param name="Register"></param> static void OnScrollAddedIntoViewChanged(DataGrid DataGrid, ITrackableCollection Collection, bool Register) { var h = Collection.GetHashCode(); if (Register) { _ScrollAddedIntoView.Add(h, DataGrid); Collection.ItemAdded += OnScrollAddedIntoViewChanged; } else { Collection.ItemAdded -= OnScrollAddedIntoViewChanged; _ScrollAddedIntoView.Remove(h); } }
public void CollectionChildProxy() { Item item = new Item(); item.Childs.Add(new Item() { Name = "123" }); Item proxy = item.AsTrackable(); proxy.Childs.Add(new Item() { Name = "test" }); ITrackableCollection <Item> collectionProxy = proxy.Childs.CastToTrackableCollection(); Assert.Single(collectionProxy.Added); Assert.Equal(2, item.Childs.Count); Assert.Equal(2, proxy.Childs.Count); }
public void CollectionChanges() { IList <Item> list = new List <Item>().AsTrackableCollection(); bool result = false; INotifyCollectionChanged notifyList = list as INotifyCollectionChanged; notifyList.CollectionChanged += (a, args) => { result = true; }; list.Add(new Item() { Name = "test" }); ITrackableCollection <Item> listTracked = list.CastToTrackableCollection(); Assert.True(result); Assert.Single(listTracked.Added); Assert.Empty(listTracked.Removed); }
public void NotifyCollectionWillBeCleared <T>(ITrackableCollection <T> trackableCollection) { AssertNotLocked(); if (!_isEnabled) { return; } var elements = trackableCollection.ToList(); if (elements.Count == 0) { return; } _changeHistory.Push(() => { foreach (var element in elements) { trackableCollection.AddWithoutTracking(element); } }); }
public override void Intercept(IInvocation invocation) { //get is changed? if (invocation.Method.IsGetterMethod(nameof(ITrackableObject.IsChanged))) { invocation.ReturnValue = ObjectTrackingState.AnyChanges(); return; } //get changed properties if (invocation.Method.IsGetterMethod(nameof(ITrackableObject.ChangedProperties))) { invocation.ReturnValue = ObjectTrackingState.GetChangedProperties(); return; } //getter? if (invocation.Method.IsGetterMethod()) { String property = invocation.Method.GetPropertyName(); var p = invocation.InvocationTarget.GetType().GetProperty(property); bool collection = p.PropertyType.IsCollection(); if (collection) { ITrackableCollection col = ObjectTrackingState.GetCollection(property); if (col == null) { invocation.Proceed(); col = (ITrackableCollection)invocation.ReturnValue.AsTrackingCollection(property, ObjectTrackingState); ObjectTrackingState.SetCollection(property, col); } invocation.ReturnValue = col; } else { invocation.Proceed(); } } //setter? else if (invocation.Method.IsSetterMethod()) { string propertyName = invocation.Method.GetPropertyName(); var accessor = PropertyAccessor.Get(invocation.TargetType.GetProperty(propertyName)); ObjectTrackingState.AddChangedProperty(propertyName, accessor.GetValue(invocation.InvocationTarget)); invocation.Proceed(); } else { invocation.Proceed(); //stop leaking "this" if (invocation.ReturnValue == invocation.InvocationTarget) { invocation.ReturnValue = invocation.Proxy; } } }
public void NotifyValueWillBeRemoved <T>(ITrackableCollection <T> trackableCollection, T removed) { Fail(); }
public void NotifyValueAdded <T>(ITrackableCollection <T> trackableCollection, T added) { Fail(); }
public void NotifyCollectionWillBeCleared <T>(ITrackableCollection <T> trackableCollection) { Fail(); }