Base class for classes that represent specific events with an object model.
Inheritance: System.EventArgs
Exemple #1
0
 /// <summary>
 /// Called by each <see cref="ModelEvent"/> to notify the context that a model event has occurred.
 /// </summary>
 /// <param name="modelEvent"></param>
 internal void Notify(ModelEvent modelEvent)
 {
     if (Event != null)
     {
         Event(this, modelEvent);
     }
 }
Exemple #2
0
 /// <summary>
 /// Creates a new <see cref="ModelEventScope"/> that represents a specific event
 /// within the object model.
 /// </summary>
 /// <param name="property"></param>
 ModelEventScope(ModelEvent @event)
     : this()
 {
     this.@event = @event;
 }
Exemple #3
0
 /// <summary>
 /// Performs the specified action inside a <see cref="ModelEventScope"/>.
 /// </summary>
 /// <param name="action"></param>
 internal static void Perform(ModelEvent @event, Action action)
 {
     new ModelEventScope(@event).PerformAction(action);
 }
Exemple #4
0
 protected internal override void OnInvoke(ModelInstance root, ModelEvent modelEvent)
 {
     // Marks the instance as pending delete if an owner property is set to null.
     if (Property is ModelReferenceProperty && !Property.IsList)
         root.IsPendingDelete = root.GetReference((ModelReferenceProperty)Property) == null;
 }
Exemple #5
0
        /// <summary>
        /// Merges a <see cref="ModelValueChangeEvent"/> into the current event.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        protected override bool OnMerge(ModelEvent e)
        {
            // Ensure the events are for the same reference property
            var listChange = (ModelListChangeEvent) e;
            if (listChange.Property != Property)
                return false;

            // Highly likely not to be right
            var mergeAdded = Added.ToList();
            mergeAdded.RemoveAll(i => listChange.Removed.Contains(i));

            var mergeRemoved = Removed.ToList();
            mergeRemoved.RemoveAll(i => listChange.Added.Contains(i));

            mergeAdded = mergeAdded.Union(listChange.Added.Where(i => !Removed.Contains(i))).ToList();
            mergeRemoved = mergeRemoved.Union(listChange.Removed.Where(i => !Added.Contains(i))).ToList();

            Added = mergeAdded.ToArray();
            Removed = mergeRemoved.ToArray();

            var mergeAddedIds = AddedIds.ToList();
            mergeAddedIds.RemoveAll(i => listChange.RemovedIds.Contains(i));

            var mergeRemovedIds = RemovedIds.ToList();
            mergeRemovedIds.RemoveAll(i => listChange.AddedIds.Contains(i));

            mergeAddedIds = mergeAddedIds.Union(listChange.AddedIds.Where(i => !RemovedIds.Contains(i))).ToList();
            mergeRemovedIds = mergeRemovedIds.Union(listChange.RemovedIds.Where(i => !AddedIds.Contains(i))).ToList();

            AddedIds = mergeAddedIds.ToArray();
            RemovedIds = mergeRemovedIds.ToArray();

            return true;
        }
Exemple #6
0
 protected internal override void OnInvoke(ModelInstance root, ModelEvent modelEvent)
 {
     ConditionTypes.First().When(root.Instance, () => ConditionApplies(root), new string[] { Property.Name });
 }
Exemple #7
0
 /// <summary>
 /// Attempts to merge two model events into a single event.
 /// </summary>
 /// <param name="e"></param>
 /// <returns></returns>
 internal bool Merge(ModelEvent e)
 {
     return Instance == e.Instance && GetType() == e.GetType() && OnMerge(e);
 }
Exemple #8
0
 protected virtual bool OnMerge(ModelEvent e)
 {
     return false;
 }
 /// <summary>
 /// Creates a new <see cref="ModelEventScope"/> that represents a specific event
 /// within the object model.
 /// </summary>
 /// <param name="property"></param>
 ModelEventScope(ModelEvent @event)
     : this()
 {
     this.@event = @event;
 }
 /// <summary>
 /// Performs the specified action inside a <see cref="ModelEventScope"/>.
 /// </summary>
 /// <param name="action"></param>
 internal static void Perform(ModelEvent @event, Action action)
 {
     new ModelEventScope(@event).PerformAction(action);
 }