/// <summary> /// Converts a model item into a viewmodel item and /// inserts it into the solution viewmodel structure. /// </summary> /// <param name="solutionModel"></param> /// <param name="parent"></param> /// <param name="item"></param> /// <returns></returns> private IItem ConvertToViewModel( ISolution solutionModel , IItemChildren parent , IItemModel item) { IItem modelNewChild = null; switch (item.ItemType) { case SolutionModelItemType.File: modelNewChild = solutionModel.AddChild(item.DisplayName, SolutionItemType.File, parent); break; case SolutionModelItemType.Folder: modelNewChild = solutionModel.AddChild(item.DisplayName, SolutionItemType.Folder, parent); break; case SolutionModelItemType.Project: modelNewChild = solutionModel.AddChild(item.DisplayName, SolutionItemType.Project, parent); break; case SolutionModelItemType.SolutionRootItem: default: throw new NotSupportedException(); } return(modelNewChild); }
/// <summary> /// Creates a mockup project structure with items below it. /// </summary> /// <param name="solutionRoot"></param> /// <param name="project"></param> /// <param name="parent"></param> /// <param name="folders"></param> /// <param name="files"></param> private static void CreateProject( ISolution solutionRoot , string project , IItemChildren parent , List <string> folders , List <string> files ) { var projectItem = solutionRoot.AddChild(project, SolutionItemType.Project, parent) as IItemChildren; if (projectItem == null) { throw new System.NotImplementedException(); } var projectItemChanged = false; for (int i = 0; i < 13; i++) { solutionRoot.AddChild(string.Format("file_{0}", i), SolutionItemType.File, projectItem); projectItemChanged = true; } if (folders != null) { foreach (var item in folders) { var folder = solutionRoot.AddChild(item, SolutionItemType.Folder, projectItem) as IItemChildren; if (folder == null) { throw new System.NotImplementedException(); } for (int i = 0; i < 123; i++) { solutionRoot.AddChild(string.Format("file_{0}", i), SolutionItemType.File, folder); projectItemChanged = true; } } } if (files != null) { foreach (var item in files) { solutionRoot.AddChild(item, SolutionItemType.File, projectItem); } projectItemChanged = true; } parent.SortChildren(); if (projectItemChanged == true) { projectItem.SortChildren(); } }
/// <summary> /// Adds another file (child) item below the parent item. /// This will throw an Exception if parent is null. /// </summary> /// <param name="itemName"></param> /// <param name="parent"></param> /// <param name="itemType"></param> /// <returns></returns> public IItem AddChild(string itemName, SolutionItemType itemType, IItemChildren parent) { if (parent == null) { throw new System.ArgumentException("Paremeter parent cannot have children."); } switch (itemType) { case SolutionItemType.SolutionRootItem: return(AddSolutionRootItem(itemName)); case SolutionItemType.File: return(parent.AddFile(itemName)); case SolutionItemType.Folder: return(parent.AddFolder(itemName)); case SolutionItemType.Project: return(parent.AddProject(itemName)); default: throw new ArgumentOutOfRangeException(itemType.ToString()); } }