// // Internal API that calls OnItemChanged. This is invoked from the // abstract ContextItemCollection class so deriving classes can still // invoke it. // internal void InvokeOnItemChanged(EditingContext context, ContextItem previousItem) { OnItemChanged(context, previousItem); }
/// <summary> /// This API supports the Entity Framework infrastructure and is not intended to be used directly from your code. /// </summary> /// <param name="context">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param> /// <param name="previousItem">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param> protected virtual void OnItemChanged(EditingContext context, ContextItem previousItem) { }
/// <summary> /// Called when an item changes value. This happens in one of two ways: /// either the user has called Change, or the user has removed a layer. /// </summary> /// <param name="item"></param> private void OnItemChanged(ContextItem item) { SubscribeContextCallback callback; Debug.Assert(item != null, "You cannot pass a null item here."); if (_subscriptions != null && _subscriptions.TryGetValue(item.ItemType, out callback)) { callback(item); } }
/// <summary> /// This changes a context item to the given value. It is illegal to pass /// null here. If you want to set a context item to its empty value create /// an instance of the item using a default constructor. /// </summary> /// <param name="value"></param> public override void SetValue(ContextItem value) { if (value == null) { throw new ArgumentNullException("value"); } // The rule for change is that we store the new value, // raise a change on the item, and then raise a change // to everyone else. If changing the item fails, we recover // the previous item. ContextItem existing = GetValueNull(value.ItemType); if (existing != null && !existing.CanBeReplaced) { throw new InvalidOperationException(); } var success = false; try { _currentLayer.Items[value.ItemType] = value; NotifyItemChanged(_context, value, existing); success = true; } finally { if (success) { var d = existing as IDisposable; if (d != null) { d.Dispose(); } OnItemChanged(value); } else { // The item threw during its transition to // becoming active. Put the old one back. // We must put the old one back by re-activating // it. This could throw a second time, so we // cover this case by removing the value first. // Should it throw again, we won't recurse because // the existing raw value would be null. _currentLayer.Items.Remove(value.ItemType); if (existing != null) { SetValue(existing); } } } }