///-------------------------------------------------------------------------------- /// <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 CodeTemplateViewModel RemoveTemplate(Guid templateID, bool removeFromTabs = true) { foreach (CodeTemplateViewModel template in Items.OfType <CodeTemplateViewModel>()) { if (template.CodeTemplate.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 (CodeTemplatesViewModel folder in Items.OfType <CodeTemplatesViewModel>()) { CodeTemplateViewModel 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 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 CodeTemplateViewModel PasteCodeTemplate(CodeTemplateViewModel copyItem, bool savePaste = true) { CodeTemplate newItem = new CodeTemplate(); newItem.ReverseInstance = new CodeTemplate(); newItem.TransformDataFromObject(copyItem.CodeTemplate, null, false); newItem.TemplateID = Guid.NewGuid(); newItem.IsAutoUpdated = false; newItem.Solution = Solution; newItem.Solution = Solution; CodeTemplateViewModel newView = new CodeTemplateViewModel(newItem, Solution); newView.ResetModified(true); AddCodeTemplate(newView); // paste children if (savePaste == true) { Solution.CodeTemplateList.Add(newItem); newView.OnUpdated(this, null); Solution.ResetModified(true); } return(newView); }
///-------------------------------------------------------------------------------- /// <summary>This method applies codetemplate deletes.</summary> ///-------------------------------------------------------------------------------- public void ProcessDeleteCodeTemplatePerformed(CodeTemplateEventArgs data) { try { #region protected if (data != null && data.CodeTemplate != null) { CodeTemplateViewModel template = RemoveTemplate(data.CodeTemplate.TemplateID); if (template != null && System.IO.File.Exists(template.CodeTemplate.FilePath)) { // delete file System.IO.File.Delete(template.CodeTemplate.FilePath); // remove from solution Solution.CodeTemplates.Remove(template.CodeTemplate.TemplateKey); Solution.CodeTemplateList.Remove(template.CodeTemplate); } else { ShowIssue(DisplayValues.Issue_DeleteItemNotFound); } } #endregion protected } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }
///-------------------------------------------------------------------------------- /// <summary>This method loads CodeTemplates 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 LoadCodeTemplates(Solution solution, bool loadChildren = true) { // attach the items Items.Clear(); if (CodeTemplates == null) { CodeTemplates = new EnterpriseDataObjectList <CodeTemplateViewModel>(); } if (loadChildren == true) { foreach (CodeTemplate item in solution.CodeTemplateList) { CodeTemplateViewModel itemView = new CodeTemplateViewModel(item, solution); itemView.Updated += new EventHandler(Children_Updated); CodeTemplates.Add(itemView); Items.Add(itemView); } } }
///-------------------------------------------------------------------------------- /// <summary>This method applies codetemplate updates.</summary> ///-------------------------------------------------------------------------------- public void ProcessEditCodeTemplatePerformed(CodeTemplateEventArgs data) { try { #region protected try { if (data != null && data.CodeTemplate != null) { data.CodeTemplate.SaveTemplateFile(); data.CodeTemplate.HasErrors = false; if (!String.IsNullOrEmpty(data.CodeTemplate.TemplateContent)) { data.CodeTemplate.ParseContent(false); } if (!String.IsNullOrEmpty(data.CodeTemplate.TemplateOutput)) { data.CodeTemplate.ParseOutput(false); } RemoveTemplate(data.CodeTemplate.TemplateID, false); // new template view model CodeTemplateViewModel template = new CodeTemplateViewModel(data.CodeTemplate, 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 AddTemplate(CodeTemplateViewModel template, bool refresh = true) { ModelContextTypeCode modelContextTypeEnum = ModelContextTypeCode.None; Enum.TryParse <ModelContextTypeCode>(template.CodeTemplate.TemplateType, out modelContextTypeEnum); switch (TemplateModelNode) { case "Solution": string templateName = String.Empty; 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.Project: templateName = Resources.DisplayValues.NodeName_Templates_Project; 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.View: templateName = Resources.DisplayValues.NodeName_Templates_View; break; case ModelContextTypeCode.ViewProperty: templateName = Resources.DisplayValues.NodeName_Templates_ViewProperty; 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; case ModelContextTypeCode.Model: templateName = Resources.DisplayValues.NodeName_Templates_Model; break; case ModelContextTypeCode.ModelObject: templateName = Resources.DisplayValues.NodeName_Templates_ModelObject; break; case ModelContextTypeCode.ModelProperty: templateName = Resources.DisplayValues.NodeName_Templates_ModelProperty; break; case ModelContextTypeCode.Enumeration: templateName = Resources.DisplayValues.NodeName_Templates_Enumeration; break; case ModelContextTypeCode.Value: templateName = Resources.DisplayValues.NodeName_Templates_Value; break; case ModelContextTypeCode.ObjectInstance: templateName = Resources.DisplayValues.NodeName_Templates_ObjectInstance; break; case ModelContextTypeCode.PropertyInstance: templateName = Resources.DisplayValues.NodeName_Templates_PropertyInstance; break; default: templateName = Resources.DisplayValues.NodeName_CodeTemplates; break; } if (modelContextTypeEnum == ModelContextTypeCode.Solution) { if (String.IsNullOrEmpty(template.CodeTemplate.CategoryName)) { Items.Add(template); template.Updated += new EventHandler(Children_Updated); if (refresh == true) { Items.Sort("Name", SortDirection.Ascending); } } else { bool foundCategory = false; foreach (CodeTemplatesViewModel folder in Items.OfType <CodeTemplatesViewModel>()) { if (folder.Name == template.CodeTemplate.CategoryName) { folder.AddTemplate(template, refresh); foundCategory = true; } } if (foundCategory == false) { CodeTemplatesViewModel folder = new CodeTemplatesViewModel(Solution, ModelContextTypeCode.None.ToString()); folder.Name = template.CodeTemplate.CategoryName; folder.AddTemplate(template); Items.Add(folder); folder.Updated += new EventHandler(Children_Updated); if (refresh == true) { Items.Sort("Name", SortDirection.Ascending); } } } } else { bool foundFolder = false; foreach (CodeTemplatesViewModel folder in Items.OfType <CodeTemplatesViewModel>()) { if (folder.Name == templateName) { folder.AddTemplate(template, refresh); foundFolder = true; } } if (foundFolder == false) { CodeTemplatesViewModel folder = new CodeTemplatesViewModel(Solution, modelContextTypeEnum.ToString()); folder.Name = templateName; folder.AddTemplate(template); Items.Add(folder); folder.Updated += new EventHandler(Children_Updated); if (refresh == true) { Items.Sort("Name", SortDirection.Ascending); } } } break; default: if (String.IsNullOrEmpty(template.CodeTemplate.CategoryName) || template.CodeTemplate.CategoryName == Name) { Items.Add(template); template.Updated += new EventHandler(Children_Updated); if (refresh == true) { Items.Sort("Name", SortDirection.Ascending); } } else { bool foundCategory = false; foreach (CodeTemplatesViewModel folder in Items.OfType <CodeTemplatesViewModel>()) { if (folder.Name == template.CodeTemplate.CategoryName) { folder.AddTemplate(template, refresh); foundCategory = true; } } if (foundCategory == false) { CodeTemplatesViewModel folder = new CodeTemplatesViewModel(Solution, modelContextTypeEnum.ToString()); folder.Name = template.CodeTemplate.CategoryName; folder.AddTemplate(template); 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 CodeTemplate from the view model.</summary> /// /// <param name="itemView">The CodeTemplate to delete.</param> ///-------------------------------------------------------------------------------- public void DeleteCodeTemplate(CodeTemplateViewModel itemView) { itemView.Updated -= Children_Updated; CodeTemplates.Remove(itemView); Delete(itemView); }
///-------------------------------------------------------------------------------- /// <summary>This method adds an instance of CodeTemplate to the view model.</summary> /// /// <param name="itemView">The CodeTemplate to add.</param> ///-------------------------------------------------------------------------------- public void AddCodeTemplate(CodeTemplateViewModel itemView) { itemView.Updated += new EventHandler(Children_Updated); CodeTemplates.Add(itemView); Add(itemView); }