/// <summary> /// Method implements Level-Order traversal via <see cref="TreeLib"/> nuget /// package to convert the <see cref="SolutionModel"/> model in <paramref name="model"/> /// into a <see cref="ISolution"/> viewmodel in <paramref name="solutionRoot"/>. /// </summary> /// <param name="model"></param> /// <param name="solutionRoot"></param> /// <returns></returns> public ISolution ToViewModel(ISolutionModel model , ISolution solutionRoot) { solutionRoot.ResetToDefaults(); // Reset current viewmodel to construction time defaults ISolutionRootItemModel treeRootModel = model.Root; long itemId = 0; var items = TreeLib.BreadthFirst.Traverse.LevelOrder <IItemModel>(treeRootModel , (i) => { var it = i as IItemChildrenModel; if (it != null) { return(it.Children); } // Emulate an emtpy list if items have no children return(new List <IItemChildrenModel>()); }); var dstIdItems = new Dictionary <long, IItemChildren>(); foreach (var item in items.Select(i => i.Node)) { item.Id = itemId++; if (item.Parent == null) { var rootItem = solutionRoot.AddSolutionRootItem(item.DisplayName); rootItem.SetId(item.Id); dstIdItems.Add(rootItem.GetId(), rootItem); } else { IItemChildren modelParentItem; IItem modelNewChild; dstIdItems.TryGetValue(item.Parent.Id, out modelParentItem); modelNewChild = ConvertToViewModel(solutionRoot, modelParentItem, item); modelNewChild.SetId(item.Id); // Store only items that can have children for later lock-up if (modelNewChild is IItemChildren) { dstIdItems.Add(modelNewChild.GetId(), modelNewChild as IItemChildren); } } } return(solutionRoot); }
internal static void Objects(ISolution solutionRoot) { var root = solutionRoot.AddSolutionRootItem("GitHub Projects"); root.IsItemExpanded = true; // Assume for this demo that the root item cannot be renamed // root.SetIsReadOnly(true); var xmlFolder = solutionRoot.AddRootChild("XML", SolutionItemType.Folder) as IItemChildren; if (xmlFolder == null) { throw new System.NotSupportedException(); } xmlFolder.IsItemExpanded = true; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX var newTest = new CreateTestObject("Open-XML-SDK" , new string [] { "BinaryFormatConverter" , "DocumentFormat.OpenXml.Tests" , "DocumentFormat.OpenXml" , "build" }, new string[] { ".gitattributes" , ".gitignore" , "DocumentFormat.OpenXml.snk" , "GitVersion.yml" , "LICENSE.txt" , "Open-XML-SDK.sln" , "README.md" , "appveyor.yml" , "dir.props" , "dir.targets" } ); CreateProject(solutionRoot, newTest.Project, xmlFolder, newTest.Folders, newTest.Files); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX newTest = new CreateTestObject("XmlNotePad" , new string[] { "images" , "src" }, new string[] { ".gitattributes" , ".gitignore" , "LICENSE" , "README.md" } ); CreateProject(solutionRoot, newTest.Project, xmlFolder, newTest.Folders, newTest.Files); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX newTest = new CreateTestObject("OpenXml" , new string[] { "Libs" , "WordToHtml", "ZipHelper" }, new string[] { ".gitattributes" , ".gitignore" , "LICENSE" , "OpenXml.sln" , "README.md" } ); CreateProject(solutionRoot, newTest.Project, xmlFolder, newTest.Folders, newTest.Files); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX newTest = new CreateTestObject("Microsoft_Virtual_Academy_Xml_To_Srt" , new string[] { "MVAXml2Subs.Tests" , "MVAXml2Subs" }, new string[] { ".gitattributes" , ".gitignore" , "LICENSE" , "MVAXml2Subs.sln" , "README.md" } ); CreateProject(solutionRoot, newTest.Project, xmlFolder, newTest.Folders, newTest.Files); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX newTest = new CreateTestObject("Xml2Markdown" , new string[] { "Xml2Markdown" }, new string[] { ".gitattributes" , ".gitignore" , "LICENSE" , "Xml2Markdown.sln" , "README.md" } ); CreateProject(solutionRoot, newTest.Project, xmlFolder, newTest.Folders, newTest.Files); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX newTest = new CreateTestObject("OpenXmlDocumentLibrary" , new string[] { "OpenXmlDocumentLibrary", "OpenXmlLibrary.Tests" }, new string[] { ".gitattributes" , ".gitignore" , "changelog.md" , "OpenXmlLibrary.sln" , "README.md" } ); CreateProject(solutionRoot, newTest.Project, xmlFolder, newTest.Folders, newTest.Files); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX newTest = new CreateTestObject("XslTransformer" , new string[] { "XslTransformer.Core", "XslTransformer" }, new string[] { ".gitattributes" , ".gitignore" , "LICENSE" , "XslTransformer.sln" , "README.md" } ); CreateProject(solutionRoot, newTest.Project, xmlFolder, newTest.Folders, newTest.Files); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX newTest = new CreateTestObject("vscode" , new string[] { "build", "extensions", "i18n", "resources" , "scripts", "src", "test" }, null); CreateProject(solutionRoot, newTest.Project, root, newTest.Folders, newTest.Files); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX newTest = new CreateTestObject("msbuild" , new string[] { "Samples", "branding", "build", "documentation" , "ref", "setup", "src", "targets" }, null); CreateProject(solutionRoot, newTest.Project, root, newTest.Folders, newTest.Files); string[] Projects = { "AvalonEdit", "AvalonDock", "Edi", "XmlNotePad", "XmlViewer", "MRULib", "MLib", "Visual Studio" }; foreach (var item in Projects) { CreateProject(solutionRoot, item, root, null, null); } var lastItem = xmlFolder.FindChild("Open-XML-SDK") as IItemChildren; if (lastItem == null) { throw new System.NotSupportedException(); } if (lastItem != null) { lastItem.IsItemExpanded = true; lastItem = lastItem.FindChild("DocumentFormat.OpenXml.Tests") as IItemChildren; if (lastItem == null) { throw new System.NotSupportedException(); } if (lastItem != null) { lastItem.IsItemExpanded = true; var lastFileItem = lastItem.FindChild("file_99"); if (lastFileItem != null) { solutionRoot.SelectionChangedCommand.Execute(lastFileItem); //lastFileItem.IsItemSelected = true; } } } }