예제 #1
0
        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));
            }
        }
예제 #2
0
 public void SetCollection(string property, ITrackableCollection list)
 {
     if (_collectionProxies.ContainsKey(property) == false)
     {
         _collectionProxies.Add(property, list);
     }
     else
     {
         _collectionProxies[property] = list;
     }
 }
예제 #3
0
        public void NotifyValueAdded <T>(ITrackableCollection <T> trackableCollection, T added)
        {
            AssertNotLocked();

            if (!_isEnabled)
            {
                return;
            }

            _changeHistory.Push(() => trackableCollection.RemoveWithoutTracking(added));
        }
예제 #4
0
 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;
     }
 }
예제 #5
0
        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);
        }
예제 #6
0
        /// <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);
            }
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        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;
                }
            }
        }
예제 #11
0
 public void NotifyValueWillBeRemoved <T>(ITrackableCollection <T> trackableCollection, T removed)
 {
     Fail();
 }
예제 #12
0
 public void NotifyValueAdded <T>(ITrackableCollection <T> trackableCollection, T added)
 {
     Fail();
 }
예제 #13
0
 public void NotifyCollectionWillBeCleared <T>(ITrackableCollection <T> trackableCollection)
 {
     Fail();
 }