Beispiel #1
0
        public BuildItemBaseVM[] GetBuildTreeReq(IEnumerable <BuildDefinitionItem> builds, int level)
        {
            var newItemsTree = new List <BuildItemBaseVM>();

            string[] levelNames = (
                from build in builds
                select build.HierarchyName[level])
                                  .Distinct()
                                  .ToArray();

            foreach (var levelName in levelNames)
            {
                var catalogBuilds = builds
                                    .Where(b => b.HierarchyName[level] == levelName && b.HierarchyName.Length > level + 1)
                                    .ToArray();

                var definitionBuilds = builds
                                       .Where(b => b.HierarchyName[level] == levelName && b.HierarchyName.Length == level + 1)
                                       .ToArray();

                if (catalogBuilds.Length > 0)
                {
                    var newBuildCatalog = new BuildCatalogItemVM()
                    {
                        Name = levelName,
                    };
                    newItemsTree.Add(newBuildCatalog);
                    var children = GetBuildTreeReq(catalogBuilds, level + 1);

                    foreach (var child in children)
                    {
                        newBuildCatalog.Children.Add(child);
                    }
                }

                //add single builds
                foreach (var definitionBuild in definitionBuilds)
                {
                    var newDefinitionBuild = new BuildDefinitionItemVM(CurrentBuildFacade)
                    {
                        Id    = definitionBuild.Id,
                        Name  = definitionBuild.HierarchyName[level],
                        Model = definitionBuild,
                    };
                    newItemsTree.Add(newDefinitionBuild);
                }
            }

            return(newItemsTree.ToArray());
        }
Beispiel #2
0
        public BuildDefinitionItemVM SearchBuildById(IEnumerable <BuildItemBaseVM> tree, string id)
        {
            BuildDefinitionItemVM result = null;

            foreach (var buildItem in tree)
            {
                if (buildItem.Id == id)
                {
                    result = buildItem as BuildDefinitionItemVM;
                }
                else if (buildItem is BuildCatalogItemVM)
                {
                    var catalog = buildItem as BuildCatalogItemVM;
                    result = SearchBuildById(catalog.Children, id);
                }
                if (result != null)
                {
                    break;
                }
            }
            return(result);
        }