Example #1
0
        private void TrackObservableList(IObservableList obj)
        {
            List <object> items = ((IObservableList)obj).ListItems;

            ((INotifyCollectionChanged)obj).CollectionChanged += ((RepositoryItemBase)this).ChildCollectionChanged;

            foreach (object item in items)
            {
                if (item is RepositoryItemBase)
                {
                    RepositoryItemBase RI = ((RepositoryItemBase)item);
                    // Do start tracking only for item which are not already tracked
                    if (RI.DirtyStatus == eDirtyStatus.NoTracked)
                    {
                        RI.StartDirtyTracking();
                    }
                    RI.OnDirtyStatusChanged += this.RaiseDirtyChanged;
                }
                else
                {
                    // for now we ignore list of Guids - like Agents.Tags as user cannot change the value, but if he add/remove it will be tracked
                    if (item is Guid)
                    {
                        continue;
                    }
                    throw new Exception("Error: trying to track object which is Serialzied in a list but is not RepositoryItemBase " + this.GetType().FullName + " " + item.ToString());
                }
            }
        }
Example #2
0
        public void TrackObservableList(IObservableList obj)
        {
            // No need to track items which are lazy load
            List <object> items = ((IObservableList)obj).ListItems;

            ((INotifyCollectionChanged)obj).CollectionChanged += ((RepositoryItemBase)this).ChildCollectionChanged;

            Parallel.ForEach(items, item =>
            {
                if (item is RepositoryItemBase)
                {
                    RepositoryItemBase RI = ((RepositoryItemBase)item);
                    // Do start tracking only for item which are not already tracked
                    if (RI.DirtyStatus == eDirtyStatus.NoTracked)
                    {
                        RI.StartDirtyTracking();
                    }
                    RI.OnDirtyStatusChanged += this.RaiseDirtyChanged;
                }
                else
                {
                    // for now we ignore list of Guids - like Agents.Tags as user cannot change the value, but if he add/remove it will be tracked
                    if (item is Guid || item is RepositoryItemKey)
                    {
                        return;
                    }
                    throw new Exception("Error: trying to track object which is Serialized in a list but is not RepositoryItemBase " + this.GetType().FullName + " " + item.ToString());
                }
            });
        }
Example #3
0
        internal void ChildCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            // each change in Observavle will mark the item modified - all NotifyCollectionChangedAction.*
            DirtyStatus = eDirtyStatus.Modified;

            // if item added set tracking too
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (object obj in e.NewItems)
                {
                    if (obj is RepositoryItemBase)
                    {
                        RepositoryItemBase repositoryItemBase = (RepositoryItemBase)obj;
                        repositoryItemBase.StartDirtyTracking();
                        repositoryItemBase.OnDirtyStatusChanged += this.RaiseDirtyChanged;
                    }
                    else
                    {
                        // not RI no tracking...
                    }
                }
            }
        }