///--------------------------------------------------------------------------------
        /// <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 SpecTemplateViewModel PasteSpecTemplate(SpecTemplateViewModel copyItem, bool savePaste = true)
        {
            SpecTemplate newItem = new SpecTemplate();

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

            newItem.Solution = Solution;
            newItem.Solution = Solution;
            SpecTemplateViewModel newView = new SpecTemplateViewModel(newItem, Solution);

            newView.ResetModified(true);
            AddSpecTemplate(newView);

            // paste children
            if (savePaste == true)
            {
                Solution.SpecTemplateList.Add(newItem);
                newView.OnUpdated(this, null);
                Solution.ResetModified(true);
            }
            return(newView);
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method removes a template from the view models (and tree and designer).</summary>
        ///
        /// <param name="templateID">The ID of the template to remove.</param>
        ///--------------------------------------------------------------------------------
        public SpecTemplateViewModel RemoveTemplate(Guid templateID, bool removeFromTabs = true)
        {
            foreach (SpecTemplateViewModel template in Items.OfType <SpecTemplateViewModel>())
            {
                if (template.SpecTemplate.TemplateID == templateID)
                {
                    if (removeFromTabs == true)
                    {
                        // remove item from tabs, if present
                        WorkspaceEventArgs message = new WorkspaceEventArgs();
                        message.ItemID = templateID;
                        Mediator.NotifyColleagues <WorkspaceEventArgs>(MediatorMessages.Command_CloseItemRequested, message);
                    }

                    // remove item from Items and tree
                    Items.Remove(template);
                    template.Updated -= Children_Updated;
                    return(template);
                }
            }
            foreach (SpecTemplatesViewModel folder in Items.OfType <SpecTemplatesViewModel>())
            {
                SpecTemplateViewModel template = folder.RemoveTemplate(templateID, removeFromTabs);
                if (template != null)
                {
                    if (folder.TemplateModelNode != ModelContextTypeCode.Solution.ToString() && folder.Items.Count == 0)
                    {
                        Items.Remove(folder);
                        folder.Updated -= Children_Updated;
                    }
                    return(template);
                }
            }
            return(null);
        }
 ///--------------------------------------------------------------------------------
 /// <summary>This method applies spectemplate deletes.</summary>
 ///--------------------------------------------------------------------------------
 public void ProcessDeleteSpecTemplatePerformed(SpecTemplateEventArgs data)
 {
     try
     {
         #region protected
         if (data != null && data.SpecTemplate != null)
         {
             SpecTemplateViewModel template = RemoveTemplate(data.SpecTemplate.TemplateID);
             if (template != null && System.IO.File.Exists(template.SpecTemplate.FilePath))
             {
                 // delete file
                 System.IO.File.Delete(template.SpecTemplate.FilePath);
             }
             else
             {
                 ShowIssue(DisplayValues.Issue_DeleteItemNotFound);
             }
         }
         #endregion protected
     }
     catch (Exception ex)
     {
         ShowIssue(ex.Message + ex.StackTrace);
     }
 }
 ///--------------------------------------------------------------------------------
 /// <summary>This method loads SpecTemplates into the view model.</summary>
 ///
 /// <param name="solution">The associated solution.</param>
 /// <param name="loadChildren">Flag indicating whether to perform a deeper load.</param>
 ///--------------------------------------------------------------------------------
 public void LoadSpecTemplates(Solution solution, bool loadChildren = true)
 {
     // attach the items
     Items.Clear();
     if (SpecTemplates == null)
     {
         SpecTemplates = new EnterpriseDataObjectList <SpecTemplateViewModel>();
     }
     if (loadChildren == true)
     {
         foreach (SpecTemplate item in solution.SpecTemplateList)
         {
             SpecTemplateViewModel itemView = new SpecTemplateViewModel(item, solution);
             itemView.Updated += new EventHandler(Children_Updated);
             SpecTemplates.Add(itemView);
             Items.Add(itemView);
         }
     }
 }
        ///--------------------------------------------------------------------------------
        /// <summary>This method applies spectemplate updates.</summary>
        ///--------------------------------------------------------------------------------
        public void ProcessEditSpecTemplatePerformed(SpecTemplateEventArgs data)
        {
            try
            {
                #region protected
                try
                {
                    if (data != null && data.SpecTemplate != null)
                    {
                        data.SpecTemplate.SaveTemplateFile();
                        data.SpecTemplate.HasErrors = false;
                        if (!String.IsNullOrEmpty(data.SpecTemplate.TemplateContent))
                        {
                            data.SpecTemplate.ParseContent(false);
                        }
                        if (!String.IsNullOrEmpty(data.SpecTemplate.TemplateOutput))
                        {
                            data.SpecTemplate.ParseOutput(false);
                        }
                        RemoveTemplate(data.SpecTemplate.TemplateID, false);

                        // new template view model
                        SpecTemplateViewModel template = new SpecTemplateViewModel(data.SpecTemplate, Solution);
                        AddTemplate(template);
                        template.ShowInTreeView();
                    }
                }
                catch (System.Exception ex)
                {
                    ShowException(ex);
                }
                #endregion protected
            }
            catch (Exception ex)
            {
                ShowIssue(ex.Message + ex.StackTrace);
            }
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method adds a template to the view models (and tree).</summary>
        ///
        /// <param name="template">The template to add.</param>
        /// <param name="refresh">Flag whether to refresh view.</param>
        ///--------------------------------------------------------------------------------
        public void AddSpecTemplate(SpecTemplateViewModel template, bool refresh = true)
        {
            string templateName = String.Empty;
            ModelContextTypeCode modelContextTypeEnum = ModelContextTypeCode.None;

            Enum.TryParse <ModelContextTypeCode>(template.SpecTemplate.TemplateType, out modelContextTypeEnum);
            switch (modelContextTypeEnum)
            {
            case ModelContextTypeCode.AuditProperty:
                templateName = Resources.DisplayValues.NodeName_Templates_AuditProperty;
                break;

            case ModelContextTypeCode.Collection:
                templateName = Resources.DisplayValues.NodeName_Templates_Collection;
                break;

            case ModelContextTypeCode.Entity:
                templateName = Resources.DisplayValues.NodeName_Templates_Entity;
                break;

            case ModelContextTypeCode.EntityReference:
                templateName = Resources.DisplayValues.NodeName_Templates_EntityReference;
                break;

            case ModelContextTypeCode.Feature:
                templateName = Resources.DisplayValues.NodeName_Templates_Feature;
                break;

            case ModelContextTypeCode.Index:
                templateName = Resources.DisplayValues.NodeName_Templates_Index;
                break;

            case ModelContextTypeCode.IndexProperty:
                templateName = Resources.DisplayValues.NodeName_Templates_IndexProperty;
                break;

            case ModelContextTypeCode.Method:
                templateName = Resources.DisplayValues.NodeName_Templates_Method;
                break;

            case ModelContextTypeCode.Parameter:
                templateName = Resources.DisplayValues.NodeName_Templates_Parameter;
                break;

            case ModelContextTypeCode.Property:
                templateName = Resources.DisplayValues.NodeName_Templates_Property;
                break;

            case ModelContextTypeCode.PropertyReference:
                templateName = Resources.DisplayValues.NodeName_Templates_PropertyReference;
                break;

            case ModelContextTypeCode.Relationship:
                templateName = Resources.DisplayValues.NodeName_Templates_Relationship;
                break;

            case ModelContextTypeCode.RelationshipProperty:
                templateName = Resources.DisplayValues.NodeName_Templates_RelationshipProperty;
                break;

            case ModelContextTypeCode.Workflow:
                templateName = Resources.DisplayValues.NodeName_Templates_Workflow;
                break;

            case ModelContextTypeCode.Stage:
                templateName = Resources.DisplayValues.NodeName_Templates_Stage;
                break;

            case ModelContextTypeCode.StageTransition:
                templateName = Resources.DisplayValues.NodeName_Templates_StageTransition;
                break;

            case ModelContextTypeCode.Step:
                templateName = Resources.DisplayValues.NodeName_Templates_Step;
                break;

            case ModelContextTypeCode.StepTransition:
                templateName = Resources.DisplayValues.NodeName_Templates_StepTransition;
                break;

            case ModelContextTypeCode.StateModel:
                templateName = Resources.DisplayValues.NodeName_Templates_StateModel;
                break;

            case ModelContextTypeCode.State:
                templateName = Resources.DisplayValues.NodeName_Templates_State;
                break;

            case ModelContextTypeCode.StateTransition:
                templateName = Resources.DisplayValues.NodeName_Templates_StateTransition;
                break;

            default:
                SpecModelContextTypeCode specModelContextTypeEnum = SpecModelContextTypeCode.None;
                Enum.TryParse <SpecModelContextTypeCode>(template.SpecTemplate.TemplateType, out specModelContextTypeEnum);
                switch (specModelContextTypeEnum)
                {
                case SpecModelContextTypeCode.SqlColumn:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlColumn;
                    break;

                case SpecModelContextTypeCode.SqlDatabase:
                    Name = Resources.DisplayValues.NodeName_Templates_SqlDatabase;
                    break;

                case SpecModelContextTypeCode.SqlExtendedProperty:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlExtendedProperty;
                    break;

                case SpecModelContextTypeCode.SqlForeignKey:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlForeignKey;
                    break;

                case SpecModelContextTypeCode.SqlForeignKeyColumn:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlForeignKeyColumn;
                    break;

                case SpecModelContextTypeCode.SqlIndex:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlIndex;
                    break;

                case SpecModelContextTypeCode.SqlIndexedColumn:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlIndexedColumn;
                    break;

                case SpecModelContextTypeCode.SqlProperty:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlProperty;
                    break;

                case SpecModelContextTypeCode.SqlTable:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlTable;
                    break;

                case SpecModelContextTypeCode.SqlView:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlView;
                    break;

                case SpecModelContextTypeCode.SqlViewProperty:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlViewProperty;
                    break;

                case SpecModelContextTypeCode.XmlAttribute:
                    templateName = Resources.DisplayValues.NodeName_Templates_XmlAttribute;
                    break;

                case SpecModelContextTypeCode.XmlDocument:
                    templateName = Resources.DisplayValues.NodeName_Templates_XmlDocument;
                    break;

                case SpecModelContextTypeCode.XmlNode:
                    templateName = Resources.DisplayValues.NodeName_Templates_XmlNode;
                    break;

                default:
                    templateName = Resources.DisplayValues.NodeName_SpecTemplates;
                    break;
                }
                break;
            }
            if (template.SpecTemplate.TemplateType == SpecModelContextTypeCode.SpecificationSource.ToString())
            {
                if (String.IsNullOrEmpty(template.SpecTemplate.CategoryName))
                {
                    Items.Add(template);
                    template.Updated += new EventHandler(Children_Updated);
                    if (refresh == true)
                    {
                        Items.Sort("Name", SortDirection.Ascending);
                    }
                }
                else
                {
                    bool foundCategory = false;
                    foreach (SpecTemplatesViewModel folder in Items.OfType <SpecTemplatesViewModel>())
                    {
                        if (folder.Name == template.SpecTemplate.CategoryName)
                        {
                            folder.AddTemplate(template, refresh);
                            foundCategory = true;
                        }
                    }
                    if (foundCategory == false)
                    {
                        SpecTemplatesViewModel folder = new SpecTemplatesViewModel(Solution, ModelContextTypeCode.None.ToString(), SpecificationDirectory);
                        folder.Name = template.SpecTemplate.CategoryName;
                        folder.AddTemplate(template, refresh);
                        Items.Add(folder);
                        folder.Updated += new EventHandler(Children_Updated);
                        if (refresh == true)
                        {
                            Items.Sort("Name", SortDirection.Ascending);
                        }
                    }
                }
            }
            else
            {
                bool foundFolder = false;
                foreach (SpecTemplatesViewModel folder in Items.OfType <SpecTemplatesViewModel>())
                {
                    if (folder.Name == templateName)
                    {
                        folder.AddTemplate(template, refresh);
                        foundFolder = true;
                    }
                }
                if (foundFolder == false)
                {
                    SpecTemplatesViewModel folder = new SpecTemplatesViewModel(Solution, template.SpecTemplate.TemplateType, SpecificationDirectory);
                    folder.Name = templateName;
                    folder.AddTemplate(template, refresh);
                    Items.Add(folder);
                    folder.Updated += new EventHandler(Children_Updated);
                    if (refresh == true)
                    {
                        Items.Sort("Name", SortDirection.Ascending);
                    }
                }
            }
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method adds a template to the view models (and tree).</summary>
        ///
        /// <param name="template">The template to add.</param>
        /// <param name="refresh">Flag whether to refresh view.</param>
        ///--------------------------------------------------------------------------------
        public void AddTemplate(SpecTemplateViewModel template, bool refresh = true)
        {
            switch (TemplateModelNode)
            {
            case "Solution":
                bool folderFound = false;
                foreach (SpecTemplatesViewModel view in Items.OfType <SpecTemplatesViewModel>())
                {
                    if (view.SpecificationDirectory == template.SpecTemplate.SpecificationDirectory)
                    {
                        view.AddTemplate(template, refresh);
                        folderFound = true;
                        break;
                    }
                }
                if (folderFound == false)
                {
                    AddSpecTemplate(template, refresh);
                }
                break;

            case "SpecificationSource":
                AddSpecTemplate(template, refresh);
                break;

            default:
                if (String.IsNullOrEmpty(template.SpecTemplate.CategoryName) || template.SpecTemplate.CategoryName == Name)
                {
                    Items.Add(template);
                    template.Updated += new EventHandler(Children_Updated);
                    if (refresh == true)
                    {
                        Items.Sort("Name", SortDirection.Ascending);
                    }
                }
                else
                {
                    bool foundCategory = false;
                    foreach (SpecTemplatesViewModel folder in Items.OfType <SpecTemplatesViewModel>())
                    {
                        if (folder.Name == template.SpecTemplate.CategoryName)
                        {
                            folder.AddTemplate(template, refresh);
                            foundCategory = true;
                        }
                    }
                    if (foundCategory == false)
                    {
                        SpecTemplatesViewModel folder = new SpecTemplatesViewModel(Solution, template.SpecTemplate.TemplateType, SpecificationDirectory);
                        folder.Name = template.SpecTemplate.CategoryName;
                        folder.AddTemplate(template, refresh);
                        Items.Add(folder);
                        folder.Updated += new EventHandler(Children_Updated);
                        if (refresh == true)
                        {
                            Items.Sort("Name", SortDirection.Ascending);
                        }
                    }
                }
                break;
            }
        }
 ///--------------------------------------------------------------------------------
 /// <summary>This method deletes an instance of SpecTemplate from the view model.</summary>
 ///
 /// <param name="itemView">The SpecTemplate to delete.</param>
 ///--------------------------------------------------------------------------------
 public void DeleteSpecTemplate(SpecTemplateViewModel itemView)
 {
     itemView.Updated -= Children_Updated;
     SpecTemplates.Remove(itemView);
     Delete(itemView);
 }
 ///--------------------------------------------------------------------------------
 /// <summary>This method adds an instance of SpecTemplate to the view model.</summary>
 ///
 /// <param name="itemView">The SpecTemplate to add.</param>
 ///--------------------------------------------------------------------------------
 public void AddSpecTemplate(SpecTemplateViewModel itemView)
 {
     itemView.Updated += new EventHandler(Children_Updated);
     SpecTemplates.Add(itemView);
     Add(itemView);
 }