Example #1
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method applies method deletes.</summary>
        ///--------------------------------------------------------------------------------
        public void ProcessDeleteMethodPerformed(MethodEventArgs data)
        {
            try
            {
                bool isItemMatch = false;
                if (data != null && data.Method != null)
                {
                    foreach (MethodViewModel item in Methods.ToList <MethodViewModel>())
                    {
                        if (item.Method.MethodID == data.Method.MethodID)
                        {
                            // remove item from tabs, if present
                            WorkspaceEventArgs message = new WorkspaceEventArgs();
                            message.ItemID = item.Method.MethodID;
                            Mediator.NotifyColleagues <WorkspaceEventArgs>(MediatorMessages.Command_CloseItemRequested, message);

                            // delete children
                            for (int i = item.Items.Count - 1; i >= 0; i--)
                            {
                                if (item.Items[i] is ParameterViewModel)
                                {
                                    ParameterViewModel child        = item.Items[i] as ParameterViewModel;
                                    ParameterEventArgs childMessage = new ParameterEventArgs();
                                    childMessage.Parameter   = child.Parameter;
                                    childMessage.MethodID    = item.Method.MethodID;
                                    childMessage.Solution    = Solution;
                                    childMessage.WorkspaceID = child.WorkspaceID;
                                    item.ProcessDeleteParameterPerformed(childMessage);
                                }
                            }

                            // delete item
                            isItemMatch = true;
                            Methods.Remove(item);
                            Entity.MethodList.Remove(item.Method);
                            Items.Remove(item);
                            Entity.ResetModified(true);
                            OnUpdated(this, null);
                            break;
                        }
                    }
                    if (isItemMatch == false)
                    {
                        ShowIssue(DisplayValues.Issue_DeleteItemNotFound);
                    }
                }
            }
            catch (Exception ex)
            {
                ShowIssue(ex.Message + ex.StackTrace);
            }
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method is used to copy/paste a new item.</summary>
        ///
        /// <param name="copyItem">The item to copy/paste.</param>
        /// <param name="savePaste">Flag to determine whether to save the results of the paste.</param>
        ///--------------------------------------------------------------------------------
        public ParameterViewModel PasteParameter(ParameterViewModel copyItem, bool savePaste = true)
        {
            Parameter newItem = new Parameter();

            newItem.ReverseInstance = new Parameter();
            newItem.TransformDataFromObject(copyItem.Parameter, null, false);
            newItem.ParameterID   = Guid.NewGuid();
            newItem.IsAutoUpdated = false;

            // try to find Entity by existing id first, second by old id, finally by name
            newItem.ReferencedEntity = Method.Entity.Feature.EntityList.FindByID((Guid)copyItem.Parameter.ReferencedEntityID);
            if (newItem.ReferencedEntity == null && Solution.PasteNewGuids[copyItem.Parameter.ReferencedEntityID.ToString()] is Guid)
            {
                newItem.ReferencedEntity = Method.Entity.Feature.EntityList.FindByID((Guid)Solution.PasteNewGuids[copyItem.Parameter.ReferencedEntityID.ToString()]);
            }
            if (newItem.ReferencedEntity == null)
            {
                newItem.ReferencedEntity = Method.Entity.Feature.EntityList.Find("Name", copyItem.Parameter.Name);
            }
            if (newItem.ReferencedEntity == null)
            {
                newItem.OldReferencedEntityID = newItem.ReferencedEntityID;
                newItem.ReferencedEntityID    = Guid.Empty;
            }

            // try to find Property by existing id first, second by old id, finally by name
            if (newItem.ReferencedEntity != null)
            {
                newItem.ReferencedPropertyBase = newItem.ReferencedEntity.PropertyList.FindByID((Guid)copyItem.Parameter.ReferencedPropertyID);
                if (newItem.ReferencedPropertyBase == null && Solution.PasteNewGuids[copyItem.Parameter.ReferencedPropertyID.ToString()] is Guid)
                {
                    newItem.ReferencedPropertyBase = newItem.ReferencedEntity.PropertyList.FindByID((Guid)Solution.PasteNewGuids[copyItem.Parameter.ReferencedPropertyID.ToString()]);
                }
                if (newItem.ReferencedPropertyBase == null)
                {
                    newItem.ReferencedPropertyBase = Solution.PropertyList.FindByID((Guid)copyItem.Parameter.ReferencedPropertyID);
                    if (newItem.ReferencedPropertyBase != null && newItem.ReferencedPropertyBase is Property)
                    {
                        newItem.ReferencedPropertyBase = newItem.ReferencedEntity.PropertyList.Find(p => p.PropertyName == (newItem.ReferencedPropertyBase as Property).PropertyName);
                    }
                    if (newItem.ReferencedPropertyBase == null && copyItem.Parameter.ReferencedPropertyBase is Property)
                    {
                        newItem.ReferencedPropertyBase = newItem.ReferencedEntity.PropertyList.Find(p => p.PropertyName == (copyItem.Parameter.ReferencedPropertyBase as Property).PropertyName);
                    }
                }
            }
            if (newItem.ReferencedPropertyBase == null)
            {
                newItem.OldReferencedPropertyID = newItem.ReferencedPropertyID;
                newItem.ReferencedPropertyID    = Guid.Empty;
            }
            newItem.Method   = Method;
            newItem.Solution = Solution;
            ParameterViewModel newView = new ParameterViewModel(newItem, Solution);

            newView.ResetModified(true);
            AddParameter(newView);
            if (savePaste == true)
            {
                Solution.ParameterList.Add(newItem);
                Method.ParameterList.Add(newItem);
                newView.OnUpdated(this, null);
                Solution.ResetModified(true);
            }
            return(newView);
        }