public void RememberOldValues(object sender, NotifyCollectionChangingEventArgs e)
        {
            if (List != null)
            {
                throw new InvalidOperationException("Old value is already initialized");
            }

            List = (IList)sender;

            Action = e.Action;

            Index = e.Index;

            switch(e.Action)
            {
                case NotifyCollectionChangeAction.Add:
                    break;
                case NotifyCollectionChangeAction.Remove:
                    OldValue = e.Item;
                    break;
                case NotifyCollectionChangeAction.Replace:
                    OldValue = List[e.Index]; // remember value being replaced
                    break;
            }
        }
Beispiel #2
0
        public void OnCollectionChanging(object sender, NotifyCollectionChangingEventArgs e)
        {
            if (CollectionChanging == null)
            {
                var change = Instance as ICustomNotifyCollectionChange;
                if (change != null)
                    change.FireCollectionChanging(sender, e);
                return;
            }

            EditActionAttribute.BubbleIndentCounter++;

            LogCollectionChanging(sender, e); 

            var previousSender = EventSettings.LastEventBubbler;
            EventSettings.LastEventBubbler = Instance;

            try
            {
                CollectionChanging(sender, e);
            }
            finally
            {
                EventSettings.LastEventBubbler = previousSender;
                EditActionAttribute.BubbleIndentCounter--;
            }
        }
        public void RememberNewValues(object list, NotifyCollectionChangingEventArgs e)
        {
            if (this.List != list)
            {
                throw new InvalidOperationException("Instance of the new value is not the same as for the old value");
            }

            if (NewValue != null)
            {
                throw new InvalidOperationException("New value is already initialized");
            }

            switch (e.Action)
            {
                case NotifyCollectionChangeAction.Add:
                    NewValue = e.Item;
                    break;
                case NotifyCollectionChangeAction.Remove:
                    break;
                case NotifyCollectionChangeAction.Replace:
                    if(e.Index != Index)
                    {
                        throw new NotImplementedException("Replace of element in collection with different index is not implemented yet.");
                    }

                    NewValue = e.Item;
                    break;
            }

            Filled = true;
        }
Beispiel #4
0
 private void LogCollectionChanging(object sender, NotifyCollectionChangingEventArgs e)
 {
     //if (EventSettings.EnableLogging)
     {
         var instance = Instance;
         if (instance == sender)
             Console.WriteLine(
                 EditActionAttribute.BubbleIndent +
                 "CollectionChanging >>> '{0}[{1}]', item:{2}, index:{3}, action:{4} - BEGIN >>>>>>>>>>>>>>",
                 instance, instance != null ? instance.GetType().Name : "null", e.Item, e.Index, e.Action);
         else if (sender.GetType().Name.Contains("EventedList"))
         {
             var senderTypeName = sender.GetType().GetGenericArguments()[0].Name;
             Console.WriteLine(
                 EditActionAttribute.BubbleIndent +
                 "CollectionChanging >>> '{0}[{1}]' -> '{5}[{6}]', item:{2}, index:{3}, action:{4}",
                 "EventedList", senderTypeName, e.Item, e.Index, e.Action, instance,
                 instance != null ? instance.GetType().Name : "null");
         }
         else
         {
             Console.WriteLine(
                 EditActionAttribute.BubbleIndent +
                 "CollectionChanging >>> '{0}[{1}]' -> '{5}[{6}]', item:{2}, index:{3}, action:{4}", sender,
                 sender.GetType().Name, e.Item, e.Index, e.Action, instance,
                 instance != null ? instance.GetType().Name : "null");
         }
     }
 }
Beispiel #5
0
        protected void LayersCollectionChanged(object sender, NotifyCollectionChangingEventArgs e)
        {
            // performance
            if (!created || cloning)
            {
                return;
            }

            OnLayersCollectionChanged(e);

            if(CollectionChanged != null)
            {
                CollectionChanged(sender, e);
            }
        }
Beispiel #6
0
 private void OnLayersCollectionChanged(NotifyCollectionChangingEventArgs e)
 {
     switch (e.Action)
     {
         case NotifyCollectionChangeAction.Add: //set map property for layers being added
             SetMapInLayer((ILayer) e.Item);
             ((ILayer) e.Item).RenderRequired = true;
             break;
         case NotifyCollectionChangeAction.Remove:
             RenderRequired = true;//render the group if a layer got removed.
             break;
         case NotifyCollectionChangeAction.Replace:
             throw new NotImplementedException();
     }
 }
Beispiel #7
0
        private void NodeFeaturesCollectionChanging(object sender, NotifyCollectionChangingEventArgs e)
        {
            var nodeFeature = (INodeFeature) e.Item;
            if (nodeFeature == null) return;

            switch (e.Action)
            {
                case NotifyCollectionChangeAction.Replace:
                    throw new NotImplementedException();

                case NotifyCollectionChangeAction.Remove:
                    Log.DebugFormat("Removed {0} from the node {1}", nodeFeature, this);
                    nodeFeature.Node = null;
                    break;

                case NotifyCollectionChangeAction.Add:
                    nodeFeature.Node = this;
                    Log.DebugFormat("Added {0} to the node {1}", nodeFeature, this);
                    break;
            }
        }
        /// <summary>
        /// Listens for changes in reduce array and throws exception if reduction is 
        /// not possible for the given dimension
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ReduceCollectionChanged(object sender, NotifyCollectionChangingEventArgs e)
        {
            UpdateRank();

            //check whether reduced dimensions are bound by offsets
            for (int i = 0; i < parent.Rank; i++)
            {
                if (Reduce[i])
                {
                    bool isLimitedToOneIndex = OffsetEnd[i] == OffsetStart[i] || (SelectedIndexes[i] != null && SelectedIndexes[i].Length <= 1);
                    if (!isLimitedToOneIndex)
                        throw new InvalidOperationException("Reduction not possible because dimension " + i +
                                                            " is not bound to a single index");
                }
            }
        }
Beispiel #9
0
        private void BranchFeaturesOnCollectionChanged(object sender, NotifyCollectionChangingEventArgs e)
        {
            if (!Equals(sender, branchFeatures))
                return;

            var branchFeature = (IBranchFeature)e.Item;

            switch (e.Action)
            {
                case NotifyCollectionChangeAction.Add:
                    branchFeature.Branch = this;
                    break;
            }
        }
 private void DisconnectedCollectionChanged(object sender, NotifyCollectionChangingEventArgs e)
 {
     if (InEditAction())
     {
         if (lastCollectionChangeMemento == null ||
             !(Equals(lastCollectionChangeMemento.List, sender) && lastCollectionChangeMemento.Index == e.Index))
         {
             // track actual changes in disconnected objects
             handlingDisconnected = true;
             ObservableCollectionChanged(sender, e);
             handlingDisconnected = false;
         }
         else
         {
             // skip already handled event
             lastCollectionChangeMemento = null;
         }
     }
 }
 private void LogCollectionChanged(NotifyCollectionChangeMemento memento, NotifyCollectionChangingEventArgs e)
 {
     if (!EventSettings.EnableLogging)
         return;
     
     if (InEditableObjectAction())
     {
         if (e.Action == NotifyCollectionChangeAction.Replace)
         {
             log.DebugFormat("adding collection change to edit action {0}: index:{1} {2} -> {3}", memento.Action,
                             memento.Index, memento.OldValue ?? "null", memento.NewValue ?? "null");
         }
         else
         {
             log.DebugFormat("adding collection change to edit action {0}: index:{1} {2}", memento.Action,
                             memento.Index, memento.NewValue ?? "null");
         }
     }
     else
     {
         if (e.Action == NotifyCollectionChangeAction.Replace)
         {
             log.DebugFormat("saving undo for collection change {0}: index:{1} {2} -> {3}", memento.Action,
                             memento.Index, memento.OldValue ?? "null", memento.NewValue ?? "null");
         }
         else
         {
             log.DebugFormat("saving undo for collection change {0}: index: {1} {2}", memento.Action,
                             memento.Index, memento.NewValue ?? "null");
         }
     }
 }
Beispiel #12
0
        void LayersCollectionChanging(object sender, NotifyCollectionChangingEventArgs e)
        {
            // performance
            if (!created || cloning)
            {
                return;
            }

            if (sender == layers) //only for own layer collection
            {
                CheckIfLayersIsMutableOrThrow();
            }

            if (CollectionChanging != null)
            {
                CollectionChanging(sender, e);
            }
        }
        private void DisconnectedCollectionChanging(object sender, NotifyCollectionChangingEventArgs e)
        {
            if (!disconnectedObjectHashes.Contains(RuntimeHelpers.GetHashCode(EventSettings.LastEventBubbler)))
            {
                //see comments in DisconnectedPropertyChanging
                UnsubscribeDisconnected(sender);
                return; 
            }

            if (restoringMemento != null)
            {
                if (IsCollectionChangeEventPartOfRestore(sender, e.Index))
                {
                    handlingDisconnected = true;
                    // track actual changes in disconnected objects
                    ObservableCollectionChanging(sender, e);
                    handlingDisconnected = false;
                    return;
                }
            }
            else
            {
                if (InEditAction())
                {
                    if (collectionChangeMementos.ContainsKey(new CollectionChangeKey(sender, e.Item, e.Action)))
                    {
                        UnsubscribeDisconnected(sender);
                    }
                    else
                    {
                        handlingDisconnected = true;
                        // track actual changes in disconnected objects
                        ObservableCollectionChanging(sender, e);
                        handlingDisconnected = false;
                    }

                    return;
                }

                if (editActionCallCount > 0)
                {
                    return; // changes occuring in side effects (isolated)
                }
            }
            if (ExcludedTypes.Contains(sender.GetType()))
            {
                return;
            }

            throw new InvalidOperationException("Disconnected object which is removed from the main container object but remains in undo/redo stack is being changed, check if side-effect method is marked [EditAction]");
        }
Beispiel #14
0
 public virtual void OnMapCollectionChanged(object sender, NotifyCollectionChangingEventArgs e)
 {
 }
        void ObservableCollectionChanging(object sender, NotifyCollectionChangingEventArgs e)
        {
            if (!TrackChanges)
            {
                return;
            }
            ThrowIfFromDifferentThread();

            if (ExcludedTypes.Contains(sender.GetType()))
            {
                return;
            }

            if (!handlingDisconnected)
            {
                //we got an event through the normal path, so we're sure this object is still connected
                UnsubscribeDisconnected(sender);
            }

            // normally this will not happen unless event handlers are subscribed before undo/redo, check nevertheless
            if (e.Cancel)
            {
                log.DebugFormat("CollectionChanging event was cancelled, skipping undo");
                return;
            }

            FixCancelledCollectionChangingEvents();
            var key = new CollectionChangeKey(sender, e.Item, e.Action);
            if (collectionChangeMementos.ContainsKey(key))
            {
                if (handlingDisconnected)
                {
                    return; //already received
                }

                throw new NotSupportedException("The same CollectionChanging event fired twice (probably two different event paths)");
            }

            if (restoringMemento != null)
            {
                if (!IsCollectionChangeEventPartOfRestore(sender, e.Index))
                {
                    throw new InvalidOperationException("Side-effect code detected (code which changes object tree in setters or in event handlers) which is not marked with [EditAction]");
                }
            }

            if (eventCascadeCallLevel > 1 && !handlingDisconnected)
            {
                if (eventCascadeCallLevel < expectedEventCascadeCallLevel)
                {
                    expectedEventCascadeCallLevel = eventCascadeCallLevel;
                }

                // we must be in a side-effect
                if (expectedEventCascadeCallLevel != eventCascadeCallLevel)
                {
                    log.DebugFormat("CascadeEventLevel: {0}, ExpectedCascadeEventLevel: {1}", eventCascadeCallLevel, expectedEventCascadeCallLevel); 
                    throw new InvalidOperationException("Side-effect code detected (code which changes object tree in setters or in event handlers) which is not marked with [EditAction]");
                }
            }

            var memento = (NotifyCollectionChangeMemento)mementoStack.Peek();
            memento.RememberOldValues(sender, e);

            collectionChangeMementos[key] = memento;

            if (!handlingDisconnected && !TypeUtils.IsAggregationList(sender))
            {
                if (restoringMemento == null)
                {
                    HandleIfTransactional(memento.OldValue, true);
                }
                SubscribeDisconnected(memento.OldValue); // listen to the changes in disconnected objects
            }
        }
Beispiel #16
0
 void ChildCollectionChanged(object sender, NotifyCollectionChangingEventArgs e)
 {
     OnEntityEventMethod(sender, e, EntityEventType.CollectionChanged);
 }
        void ObservableCollectionChanged(object sender, NotifyCollectionChangingEventArgs e)
        {
            if (!TrackChanges)
            {
                return;
            }

            ThrowIfFromDifferentThread();

            if (ExcludedTypes.Contains(sender.GetType()))
            {
                return;
            }

            if (!handlingDisconnected)
            {
                //we got an event through the normal path, so we're sure this object is still connected
                UnsubscribeDisconnected(sender);
            }

            NotifyCollectionChangeMemento memento;
            var key = new CollectionChangeKey(sender, e.Item, e.Action);
            collectionChangeMementos.TryGetValue(key, out memento);

            if (memento == null)
            {
                throw new NotSupportedException("CollectionChanged received without CollectionChanging");
            }

            memento.RememberNewValues(sender, e);
            collectionChangeMementos.Remove(key);

            lastCollectionChangeMemento = memento;

            // exceptional situation, same object!
            if (!TypeUtils.IsAggregationList(sender))
            {
                if (ReferenceEquals(memento.OldValue, memento.NewValue))
                {
                    UnsubscribeDisconnected(memento.OldValue);
                }
                UnsubscribeDisconnected(memento.NewValue); // newly added value
            }

            LogCollectionChanged(memento, e);
        }
Beispiel #18
0
        public override void OnMapCollectionChanged(object sender, NotifyCollectionChangingEventArgs e)
        {
            switch (e.Action)
            {
                case NotifyCollectionChangeAction.Remove:
                    {
                        if(e.Item is ILayer)
                        {
                            RefreshSelection();
                        }

                        if (sender is Map)
                        {
                            var layer = (ILayer)e.Item;
                            if (layer is GroupLayer)
                            {
                                var layerGroup = (GroupLayer)layer;
                                foreach (ILayer layerGroupLayer in layerGroup.Layers)
                                {
                                    HandleLayerStatusChanged(layerGroupLayer);
                                }
                            }
                            else
                            {
                                HandleLayerStatusChanged(layer);
                            }
                        }
                        break;
                    }
                case NotifyCollectionChangeAction.Replace:
                    throw new NotImplementedException();
            }
        }
 private void FeaturesCollectionChanged(object sender, NotifyCollectionChangingEventArgs e)
 {
     themeIsDirty = true;
     base.RenderRequired = true;
 }