public static bool CanMerge(ModelItem source)
        {
            Contract.Requires(source != null);

            var task = source.GetTaskActivity();
            return task.Status == TaskActivityStatus.CheckedIn;
        }
 public DateTimeDesignerViewModel(ModelItem modelItem)
     : base(modelItem)
 {
     AddTitleBarHelpToggle();
     TimeModifierTypes = new List<string>(DateTimeFormatter.TimeModifierTypes);
     SelectedTimeModifierType = string.IsNullOrEmpty(TimeModifierType) ? TimeModifierTypes[0] : TimeModifierType;
 }
        public static bool CanAssign(ModelItem source)
        {
            Contract.Requires(source != null);

            return !CheckIsTask(source) &&
                !CompositeService.GetParents(source).Any(m => m.GetTaskActivity() != null);
        }
 ModelProperty CreateProperty(ModelItem parent, PropertyDescriptor propertyDescriptor)
 {
     bool isAttached = propertyDescriptor is AttachedPropertyDescriptor;
     return this.createFakeModelProperties ?
         (ModelProperty)(new FakeModelPropertyImpl((FakeModelItemImpl)parent, propertyDescriptor)) :
         (ModelProperty)(new ModelPropertyImpl(parent, propertyDescriptor, isAttached));
 }
Beispiel #5
0
        /// <summary>
        /// Add node key object in model view state
        /// </summary>
        public static void ApplyNodeKey(ModelItem model, NodeKey key)
        {
            Contract.Requires(model != null);
            Contract.Requires(key != null);

            StoreKey(model, key);
        }
 public ForeachDesignerViewModel(ModelItem modelItem)
     : base(modelItem)
 {
     AddTitleBarHelpToggle();
     ForeachTypes = Dev2EnumConverter.ConvertEnumsTypeToStringList<enForEachType>();
     SelectedForeachType = Dev2EnumConverter.ConvertEnumValueToString(ForEachType);
 }
 public ScriptDesignerViewModel(ModelItem modelItem)
     : base(modelItem)
 {
     AddTitleBarHelpToggle();
     ScriptTypes = Dev2EnumConverter.ConvertEnumsTypeToStringList<enScriptType>();
     SelectedScriptType = Dev2EnumConverter.ConvertEnumValueToString(ScriptType);
 }
        internal static TreeViewItemViewModel Expand(TreeViewItemModelItemViewModel rootTreeViewItem, ModelItem modelItemToExpandTo)
        {
            Fx.Assert(modelItemToExpandTo != null && rootTreeViewItem != null, "rootTreeViewItem and modelItemToExpand should not have null value");

            // ModelItems with HidePropertyInOutlineViewAttribute are invisible in the designerTree.
            if (ExtensibilityAccessor.GetAttribute<HidePropertyInOutlineViewAttribute>(modelItemToExpandTo) != null)
            {
                return null;
            }

            Stack pathStack = new Stack();

            TreeViewItemViewModel itemToBeSelected = null;

            if (GetExpandingPath(modelItemToExpandTo, pathStack, new HashSet<ModelItem>()))
            {
                // If the root of modelItemToExpandTo differs from the root of the designerTree, it means modelItemToExpandTo doesn't belong to the designerTree.
                if (pathStack.Pop() != rootTreeViewItem.VisualValue)
                {
                    return null;
                }

                object item = null;
                TreeViewItemViewModel treeViewItem = rootTreeViewItem;
                TreeViewItemViewModel tempTreeViewItem = rootTreeViewItem;

                // Using the path to the root, expand the corresponding tree node. Ignore the items which is not visible on the designerTree.
                while (pathStack.Count > 0)
                {
                    if (tempTreeViewItem != null)
                    {
                        treeViewItem = tempTreeViewItem;
                        treeViewItem.IsExpanded = true;
                    }

                    item = pathStack.Pop();
                    tempTreeViewItem = (from child in treeViewItem.Children
                                        where (child is TreeViewItemModelItemViewModel && ((TreeViewItemModelItemViewModel)child).VisualValue == item as ModelItem)
                                        || (child is TreeViewItemModelPropertyViewModel && ((TreeViewItemModelPropertyViewModel)child).VisualValue == item as ModelProperty)
                                        || (child is TreeViewItemKeyValuePairModelItemViewModel && ((TreeViewItemKeyValuePairModelItemViewModel)child).VisualValue.Value == item as ModelItem)
                                        select child).FirstOrDefault();

                    // For TreeViewItemKeyValuePairModelItemViewModel, its path to the children is very complicated.
                    // Take Switch as example: Switch(ModelItem) -> Cases(ModelProperty) -> KeyDictionaryCollection(ModelItem) -> ItemsCollection(ModelProperty) -> ModelItemKeyValuePair<T, Activity>(ModelItem) -> Value(ModelProperty) -> Children
                    // All the path nodes except Switch and Children are invisible and can be ignored, the child node in the path is used twice to search for TreeViewItemKeyValuePairModelItemViewModel and its children in designerTree.
                    if (tempTreeViewItem is TreeViewItemKeyValuePairModelItemViewModel)
                    {
                        // For further searching
                        pathStack.Push(item);
                    }

                    if (pathStack.Count == 0)
                    {
                        itemToBeSelected = tempTreeViewItem;
                    }
                }
            }

            return itemToBeSelected;
        }
        public ActivityDelegateItem(ModelItem modelItem, ActivityDelegateMetadataAttribute metadata = null)
        {
            Contract.Requires(modelItem != null);
            ModelItem = modelItem;

            if (metadata == null)
            {
                var pmi = modelItem.Parent.Properties.Where(p => p.Value == modelItem).First();
                metadata = pmi.Attributes[typeof(ActivityDelegateMetadataAttribute)] as ActivityDelegateMetadataAttribute;
            }

            if (metadata != null)
            {
                ObjectName = metadata.ObjectName;
                ResultName = metadata.ResultName;
                Argument1Name = metadata.Argument1Name;
                Argument2Name = metadata.Argument2Name;
                Argument3Name = metadata.Argument3Name;
                Argument4Name = metadata.Argument4Name;
                Argument5Name = metadata.Argument5Name;
                Argument6Name = metadata.Argument6Name;
                Argument7Name = metadata.Argument7Name;
                Argument8Name = metadata.Argument8Name;
            }
            if (string.IsNullOrWhiteSpace(ObjectName)) ObjectName = ModelItem.ItemType.GetGenericArguments()[0].Name;
        }
 public SharepointListReadDesignerViewModel(ModelItem modelItem)
     : base(modelItem, new AsyncWorker(), EnvironmentRepository.Instance.ActiveEnvironment, EventPublishers.Aggregator,false)
 {
     WhereOptions = new ObservableCollection<string>(SharepointSearchOptions.SearchOptions());
     dynamic mi = ModelItem;
     InitializeItems(mi.FilterCriteria);
 }
Beispiel #11
0
        public void UpdateReference(ModelItem source)
        {
            if (HasKey(source))
            {
                ModelItem updateSource = FindUpdateSource(source);
                if (updateSource != null)
                {
                    string message = string.Format(MSG_UpdateOtherActivities, GetSourceTypeName(updateSource));
                    MessageBoxResult result = AddInMessageBoxService.Show(message,
                           Title_UpdateOtherActivities,
                           MessageBoxButton.YesNo,
                           MessageBoxImage.Question);

                    if (result == MessageBoxResult.Yes)
                    {
                        NodeKeyManager.UpdateReference(updateSource);
                    }
                }
            }
            else
            {
                MessageBoxResult result = AddInMessageBoxService.Show(MSG_NoUpdatedActivity,
                                                   Title_UpdateOtherActivities,
                                                   MessageBoxButton.OK,
                                                   MessageBoxImage.Question);
            }
        }
 public RandomDesignerViewModel(ModelItem modelItem)
     : base(modelItem)
 {
     AddTitleBarHelpToggle();
     RandomTypes = Dev2EnumConverter.ConvertEnumsTypeToStringList<enRandomType>();
     SelectedRandomType = Dev2EnumConverter.ConvertEnumValueToString(RandomType);
 }
 public DateTimeDifferenceDesignerViewModel(ModelItem modelItem)
     : base(modelItem)
 {
     AddTitleBarHelpToggle();
     OutputTypes = new List<string>(DateTimeComparer.OutputFormatTypes);
     SelectedOutputType = string.IsNullOrEmpty(OutputType) ? OutputTypes[0] : OutputType;
 }
        public static bool CanUnassign(ModelItem source)
        {
            Contract.Requires(source != null);

            var task = source.GetTaskActivity();
            return task.Status != TaskActivityStatus.Editing;
        }
        public static bool IsItemInSequence(this ModelItem item, out ModelItem sequence)
        {
            if (null == item)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("item"));
            }

            bool result = false;
            int level = 0;

            Func<ModelItem, bool> isInSequencePredicate = (p) =>
            {
                switch (level)
                {
                    case 0:
                        ++level;
                        return (p is ModelItemCollection);

                    case 1:
                        ++level;
                        result = typeof(Sequence).IsAssignableFrom(p.ItemType);
                        return result;

                    default:
                        return false;
                };
            };

            ModelItem container = item.GetParentEnumerator(isInSequencePredicate).LastOrDefault();
            sequence = result ? container : null;
            return result;
        }
 public SortRecordsDesignerViewModel(ModelItem modelItem)
     : base(modelItem)
 {
     AddTitleBarHelpToggle();
     SortOrderTypes = new List<string> { "Forward", "Backwards" };
     SelectedSelectedSort = string.IsNullOrEmpty(SelectedSort) ? SortOrderTypes[0] : SelectedSort;
 }
 public void NotifyPropertyChanged(ModelItem modelItem)
 {
     if (null != modelItem)
     {
         ((IModelTreeItem)modelItem).OnPropertyChanged(this.Name);
     }
 }
 public CommandLineDesignerViewModel(ModelItem modelItem)
     : base(modelItem)
 {
     AddTitleBarLargeToggle();
     AddTitleBarHelpToggle();
     InitializeCommandPriorities();
 }
        // This updates back links
        public static void MorphObject(ModelItem oldModelItem, ModelItem newModelitem)
        {
            if (oldModelItem == null)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("oldModelItem"));
            }
            if (newModelitem == null)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("newModelitem"));
            }

            var collectionParents = from parent in oldModelItem.Parents
                                    where parent is ModelItemCollection
                                    select (ModelItemCollection)parent;
            foreach (ModelItemCollection collectionParent in collectionParents.ToList())
            {
                int index = collectionParent.IndexOf(oldModelItem);
                collectionParent.Remove(oldModelItem);
                collectionParent.Insert(index, newModelitem);
            }
            foreach (ModelProperty modelProperty in oldModelItem.Sources.ToList())
            {
                modelProperty.SetValue(newModelitem);
            }


        }
Beispiel #20
0
        public static IEnumerable<ModelItem> Find(ModelItem startingItem, Predicate<Type> matcher)
        {
            Contract.Requires(startingItem != null);
            Contract.Requires(matcher != null);

            return ModelItemService.FindCore(startingItem, matcher);
        }
 public ViewStateChangedEventArgs(ModelItem modelItem, string key, object newValue, object oldValue)
 {
     this.parentModelItem = modelItem;
     this.key = key;
     this.newValue = newValue;
     this.oldValue = oldValue;
 }
        public ModelItemDictionaryImpl(ModelTreeManager modelTreeManager, Type itemType, Object instance, ModelItem parent)
        {
            Fx.Assert(modelTreeManager != null, "modelTreeManager cannot be null");
            Fx.Assert(itemType != null, "item type cannot be null");
            Fx.Assert(instance != null, "instance cannot be null");
            this.itemType = itemType;
            this.instance = new DictionaryWrapper(instance);
            this.modelTreeManager = modelTreeManager;
            this.parents = new List<ModelItem>(1);
            this.sources = new List<ModelProperty>(1);
            this.helper = new ModelTreeItemHelper();
            if (parent != null)
            {
                this.manuallySetParent = parent;
            }
            this.modelPropertyStore = new Dictionary<string, ModelItem>();
            this.subTreeNodesThatNeedBackLinkPatching = new List<ModelItem>();
            this.modelItems = new NullableKeyDictionary<ModelItem, ModelItem>();
            UpdateInstance();


            if (ItemsCollectionObject != null)
            {
                ItemsCollectionModelItemCollection.CollectionChanged += new NotifyCollectionChangedEventHandler(itemsCollection_CollectionChanged);
                this.ItemsCollectionObject.ModelDictionary = this;
            }
        }
        private static void UpdateTypeArgument(ModelItem modelItem, Type value)
        {
            if (value != null)
            {
                Type oldModelItemType = modelItem.ItemType;
                Fx.Assert(oldModelItemType.GetGenericArguments().Count() == 1, "we only support changing a single type parameter ?");
                Type newModelItemType = oldModelItemType.GetGenericTypeDefinition().MakeGenericType(value);
                Fx.Assert(newModelItemType != null, "New model item type needs to be non null or we cannot proceed further");
                ModelItem newModelItem = ModelFactory.CreateItem(modelItem.GetEditingContext(), Activator.CreateInstance(newModelItemType));
                MorphHelper.MorphObject(modelItem, newModelItem);
                MorphHelper.MorphProperties(modelItem, newModelItem);

                if (oldModelItemType.IsSubclassOf(typeof(Activity)) && newModelItemType.IsSubclassOf(typeof(Activity)))
                {
                    if (string.Equals((string)modelItem.Properties["DisplayName"].ComputedValue, GetActivityDefaultName(oldModelItemType), StringComparison.Ordinal))
                    {
                        newModelItem.Properties["DisplayName"].SetValue(GetActivityDefaultName(newModelItemType));
                    }
                }

                DesignerView designerView = modelItem.GetEditingContext().Services.GetService<DesignerView>();
                if (designerView != null)
                {
                    Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, (Action)(() =>
                    {
                        if (designerView.RootDesigner != null && ((WorkflowViewElement)designerView.RootDesigner).ModelItem == modelItem)
                        {
                            designerView.MakeRootDesigner(newModelItem, true);
                        }
                        Selection.SelectOnly(modelItem.GetEditingContext(), newModelItem);
                    }));
                }
            }
        }
 public override void StoreViewState(ModelItem modelItem, string key, object value)
 {
     if (modelItem == null)
     {
         throw FxTrace.Exception.AsError(new ArgumentNullException("modelItem"));
     }
     if (key == null)
     {
         throw FxTrace.Exception.AsError(new ArgumentNullException("key"));
     }
   
     object oldValue = null;
     Dictionary<string, object> viewState = WorkflowViewStateService.GetViewState(modelItem.GetCurrentValue());
     if (viewState == null)
     {
         viewState = new Dictionary<string, object>();
         WorkflowViewStateService.SetViewState(modelItem.GetCurrentValue(), viewState);
     }
     viewState.TryGetValue(key, out oldValue);
     if (value != null)
     {
         viewState[key] = value;
     }
     else
     {
         RemoveViewState(modelItem, key);
     }
     if (this.ViewStateChanged != null && value != oldValue)
     {
         this.ViewStateChanged(this, new ViewStateChangedEventArgs(modelItem, key, value, oldValue));
     }
 }
        public static object ActivityActionMorphHelper(ModelItem originalValue, ModelProperty newModelProperty)
        {
            Fx.Assert(newModelProperty.PropertyType.GetGenericArguments().Count() == 1, "This should only be applied for ActivityAction<T>");
            Type activityActionTypeArgument = newModelProperty.PropertyType.GetGenericArguments()[0];
            Type activityActionType = typeof(ActivityAction<>).MakeGenericType(activityActionTypeArgument);
            object activityAction = Activator.CreateInstance(activityActionType);
            ModelItem morphed = ModelFactory.CreateItem(originalValue.GetEditingContext(), activityAction);

            ModelItem originalActivityActionArgument = originalValue.Properties[PropertyNames.ActionArgument].Value;
            if (originalActivityActionArgument != null)
            {
                Type variableType = typeof(DelegateInArgument<>).MakeGenericType(activityActionTypeArgument);
                DelegateInArgument iterationDelegateArgument = (DelegateInArgument)Activator.CreateInstance(variableType);
                iterationDelegateArgument.Name = (string)originalActivityActionArgument.Properties[PropertyNames.NameProperty].Value.GetCurrentValue();
                morphed.Properties[PropertyNames.ActionArgument].SetValue(iterationDelegateArgument);
            }

            ModelItem originalActivityActionHandler = originalValue.Properties[PropertyNames.ActionHandler].Value;
            if (originalActivityActionHandler != null)
            {
                morphed.Properties[PropertyNames.ActionHandler].SetValue(originalActivityActionHandler);
                originalValue.Properties[PropertyNames.ActionHandler].SetValue(null);
            }

            return morphed;
        }
        internal static Argument MorphArgument(ModelItem originalValue, Type targetType)
        {
            Argument morphed = null;
            Argument original = (Argument)originalValue.GetCurrentValue();
            ActivityWithResult originalExpression = original.Expression;
            
            if (originalExpression != null)
            {
                Type expressionType = originalExpression.GetType();
                Type expressionGenericType = expressionType.IsGenericType ? expressionType.GetGenericTypeDefinition() : null;

                if (expressionGenericType != null)
                {       
                    bool isLocation = ExpressionHelper.IsGenericLocationExpressionType(originalExpression);
                    ActivityWithResult morphedExpression;
                    EditingContext context = originalValue.GetEditingContext();
                    morphed = Argument.Create(targetType, original.Direction);
                    if (ExpressionHelper.TryMorphExpression(originalExpression, isLocation, targetType, 
                        context, out morphedExpression))
                    {                        
                        morphed.Expression = morphedExpression;
                    }
                    //[....] 

                }
            }
            return morphed;
        }
        internal ActivityArgumentBinder(ModelItem activityModelItem)
        {
            Contract.Requires(activityModelItem != null);

            this.activityModelItem = activityModelItem;
            Init();
        }
        // referenceTransitionModelItem is used when a connector is re-linked.
        void CreateTransition(ConnectionPoint sourceConnPoint, ConnectionPoint destConnPoint, ModelItem referenceTransitionModelItem, bool isSourceMoved)
        {
            Debug.Assert(this.IsOutmostStateContainerEditor(), "Should only be called by the outmost editor.");

            WorkflowViewElement srcDesigner = sourceConnPoint.ParentDesigner as WorkflowViewElement;
            WorkflowViewElement destDesigner = destConnPoint.ParentDesigner as WorkflowViewElement;
            Debug.Assert(srcDesigner is StateDesigner && destDesigner is StateDesigner, "The source and destination designers should both be StateDesigner");

            ModelItem srcModelItem = srcDesigner.ModelItem;
            ModelItem destModelItem = destDesigner.ModelItem;
            ModelItem transitionModelItem = null;

            // We are moving the connector.
            if (referenceTransitionModelItem != null && referenceTransitionModelItem.ItemType == typeof(Transition))
            {
                transitionModelItem = referenceTransitionModelItem;
                // We are moving the start of the connector. We only preserve the trigger if it is not shared.
                if(isSourceMoved)
                {
                    Transition referenceTransition = referenceTransitionModelItem.GetCurrentValue() as Transition;
                    ModelItem stateModelItem = GetParentStateModelItemForTransition(referenceTransitionModelItem);
                    State state = stateModelItem.GetCurrentValue() as State;
                    bool isTriggerShared = false;
                    foreach (Transition transition in state.Transitions)
                    {
                        if (transition != referenceTransition && transition.Trigger == referenceTransition.Trigger)
                        {
                            isTriggerShared = true;
                            break;
                        }
                    }
                    if (isTriggerShared)
                    {
                        transitionModelItem.Properties[TransitionDesigner.TriggerPropertyName].SetValue(null);
                    }
                }
                transitionModelItem.Properties[TransitionDesigner.ToPropertyName].SetValue(destModelItem);
                srcModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.Add(transitionModelItem);
            }
            // We are creating a new connector. 
            else
            {
                Transition newTransition = new Transition() { DisplayName = string.Empty };
                newTransition.To = destModelItem.GetCurrentValue() as State;
                // Assign the shared trigger.
                if (sourceConnPoint.AttachedConnectors.Count > 0)
                {
                    Connector connector = sourceConnPoint.AttachedConnectors[0];
                    Transition existingTransition = StateContainerEditor.GetConnectorModelItem(connector).GetCurrentValue() as Transition;
                    newTransition.Trigger = existingTransition.Trigger;
                }
                transitionModelItem = srcModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.Add(newTransition);
            }
            if (transitionModelItem != null)
            {
                PointCollection connectorViewState = new PointCollection(ConnectorRouter.Route(this.panel, sourceConnPoint, destConnPoint));
                this.StoreConnectorLocationViewState(transitionModelItem, connectorViewState, true);
            }
        }
Beispiel #29
0
 protected void SaveGlobalState()
 {
     DesignerView designerView = context.Services.GetService<DesignerView>();
     if (designerView != null && designerView.RootDesigner != null)
     {
         designerRoot = ((WorkflowViewElement)designerView.RootDesigner).ModelItem;
     }
 }
 protected override IEnumerable<IActionableErrorInfo> ValidateCollectionItem(ModelItem mi)
 {
     var dto = mi.GetCurrentValue() as SharepointSearchTo;
     if(dto == null)
     {
         yield break;
     }
 }
        public ModelItemDictionaryImpl(ModelTreeManager modelTreeManager, Type itemType, Object instance, ModelItem parent)
        {
            Fx.Assert(modelTreeManager != null, "modelTreeManager cannot be null");
            Fx.Assert(itemType != null, "item type cannot be null");
            Fx.Assert(instance != null, "instance cannot be null");
            this.itemType         = itemType;
            this.instance         = new DictionaryWrapper(instance);
            this.modelTreeManager = modelTreeManager;
            this.parents          = new List <ModelItem>(1);
            this.sources          = new List <ModelProperty>(1);
            this.helper           = new ModelTreeItemHelper();
            if (parent != null)
            {
                this.manuallySetParent = parent;
            }
            this.modelPropertyStore = new Dictionary <string, ModelItem>();
            this.subTreeNodesThatNeedBackLinkPatching = new List <ModelItem>();
            this.modelItems = new NullableKeyDictionary <ModelItem, ModelItem>();
            UpdateInstance();


            if (ItemsCollectionObject != null)
            {
                ItemsCollectionModelItemCollection.CollectionChanged += new NotifyCollectionChangedEventHandler(itemsCollection_CollectionChanged);
                this.ItemsCollectionObject.ModelDictionary            = this;
            }
        }
 public override bool Remove(ModelItem key)
 {
     this.modelTreeManager.DictionaryRemove(this, key);
     return(true);
 }
 internal void EditCore(ModelItem key, ModelItem value)
 {
     this.EditCore(key, value, true);
 }
 public override bool TryGetValue(ModelItem key, out ModelItem value)
 {
     return(this.modelItems.TryGetValue(key, out value));
 }
        private void EditCore(ModelItem key, ModelItem value, bool updateInstance)
        {
            try
            {
                ModelItem oldValue = this.modelItems[key];
                this.EditInProgress = true;
                Fx.Assert(this.instance != null, "instance should not be null");

                bool wasValueInKeysOrValuesCollection = this.IsInKeysOrValuesCollection(value);

                if (updateInstance)
                {
                    this.instance[(key == null) ? null : key.GetCurrentValue()] = null != value?value.GetCurrentValue() : null;

                    //this also makes sure ItemsCollectionModelItemCollection is not null
                    if (ItemsCollectionObject != null)
                    {
                        try
                        {
                            ItemsCollectionObject.ShouldUpdateDictionary = false;

                            foreach (ModelItem item in ItemsCollectionModelItemCollection)
                            {
                                ModelItem keyInCollection = item.Properties["Key"].Value;
                                bool      found           = (key == keyInCollection);

                                if (!found && key != null && keyInCollection != null)
                                {
                                    object keyValue = key.GetCurrentValue();

                                    // ValueType do not share ModelItem, a ModelItem is always created for a ValueType
                                    // ModelTreeManager always create a ModelItem even for the same string
                                    // So, we compare object instance instead of ModelItem for above cases.
                                    if (keyValue is ValueType || keyValue is string)
                                    {
                                        found = keyValue.Equals(keyInCollection.GetCurrentValue());
                                    }
                                }

                                if (found)
                                {
                                    ModelPropertyImpl valueImpl = item.Properties["Value"] as ModelPropertyImpl;
                                    if (valueImpl != null)
                                    {
                                        valueImpl.SetValueCore(value);
                                    }
                                }
                            }
                        }
                        finally
                        {
                            ItemsCollectionObject.ShouldUpdateDictionary = true;
                        }
                    }
                }

                this.modelItems[key] = null;
                if (oldValue != null && !this.IsInKeysOrValuesCollection(oldValue))
                {
                    this.modelTreeManager.OnItemEdgeRemoved(this, oldValue);
                }

                this.modelItems[key] = value;
                if (value != null && !wasValueInKeysOrValuesCollection)
                {
                    this.modelTreeManager.OnItemEdgeAdded(this, value);
                }

                if (null != this.CollectionChanged)
                {
                    this.CollectionChanged(this,
                                           new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace,
                                                                                new KeyValuePair <ModelItem, ModelItem>(key, value),
                                                                                new KeyValuePair <ModelItem, ModelItem>(key, oldValue)));
                }
            }
            finally
            {
                this.EditInProgress = false;
            }
        }
 internal void AddCore(ModelItem key, ModelItem value)
 {
     this.AddCore(key, value, true);
 }
 internal void RemoveCore(ModelItem key)
 {
     this.RemoveCore(key, true);
 }
        private void RemoveCore(ModelItem key, bool updateInstance)
        {
            try
            {
                this.EditInProgress = true;
                Fx.Assert(this.instance != null, "instance should not be null");
                ModelItem value = this.modelItems[key];
                this.modelItems.Remove(key);

                if (key != null && !this.IsInKeysOrValuesCollection(key))
                {
                    this.modelTreeManager.OnItemEdgeRemoved(this, key);
                }

                if (value != null && !this.IsInKeysOrValuesCollection(value) && value != key)
                {
                    this.modelTreeManager.OnItemEdgeRemoved(this, value);
                }

                if (updateInstance)
                {
                    ModelItemCollectionImpl itemsCollectionImpl = ItemsCollectionModelItemCollection as ModelItemCollectionImpl;
                    if (ItemsCollectionObject != null && itemsCollectionImpl != null)
                    {
                        try
                        {
                            ItemsCollectionObject.ShouldUpdateDictionary = false;

                            ModelItem itemToBeRemoved = null;
                            foreach (ModelItem item in itemsCollectionImpl)
                            {
                                ModelItem keyInCollection = item.Properties["Key"].Value;

                                if (key == keyInCollection)
                                {
                                    itemToBeRemoved = item;
                                    break;
                                }

                                if (key != null && keyInCollection != null)
                                {
                                    object keyValue = key.GetCurrentValue();

                                    // ValueType do not share ModelItem, a ModelItem is always created for a ValueType
                                    // ModelTreeManager always create a ModelItem even for the same string
                                    // So, we compare object instance instead of ModelItem for above cases.
                                    if (keyValue is ValueType || keyValue is string)
                                    {
                                        if (keyValue.Equals(keyInCollection.GetCurrentValue()))
                                        {
                                            itemToBeRemoved = item;
                                            break;
                                        }
                                    }
                                }
                            }

                            if (itemToBeRemoved != null)
                            {
                                itemsCollectionImpl.RemoveCore(itemToBeRemoved);
                            }
                        }
                        finally
                        {
                            ItemsCollectionObject.ShouldUpdateDictionary = true;
                        }
                    }
                    this.instance.Remove(key == null ? null : key.GetCurrentValue());
                }
                if (null != this.CollectionChanged)
                {
                    this.CollectionChanged(this,
                                           new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, new KeyValuePair <ModelItem, ModelItem>(key, value)));
                }
            }
            finally
            {
                this.EditInProgress = false;
            }
        }
 public override bool ContainsKey(ModelItem key)
 {
     return(this.modelItems.Keys.Contains <ModelItem>(key));
 }