Esempio n. 1
0
        private void LoadExternalSubparts(Queue <Tuple <PartExplorerElementVM, SubPart> > externalSubparts, CompiledBuildStrategy buildStrategy, string srcPath, CancellationToken token)
        {
            var externalPartFiles = new Dictionary <PartFileKey, ExternalPartFile>();

            while (externalSubparts.Count > 0)
            {
                var currentPart = externalSubparts.Dequeue();
                var sp          = currentPart.Item2;

                var bfs = buildStrategy.GetBuildFromSource(sp.PartFile, sp.Name);
                if (bfs == BuildFromSource.Never)
                {
                    var earlyResult = new PartExplorerElementVM(_configuration)
                    {
                        Name       = sp.Name,
                        Repository = sp.Repository,
                        PartFile   = sp.PartFile,
                        FromSource = BuildFromSource.Never,
                        PartType   = PartType.Reference
                    };

                    currentPart.Item1.AddChild(earlyResult);
                    continue;
                }

                var key = new PartFileKey()
                {
                    Name = sp.PartFile, Repository = sp.Repository
                };
                ExternalPartFile externalPartFile;
                if (!externalPartFiles.TryGetValue(key, out externalPartFile))
                {
                    try
                    {
                        var epf = PartFileScanner.LoadPartFile(key.Name, key.Repository,
                                                               buildStrategy.LocalRepositories, srcPath);

                        if (epf == null)
                        {
                            throw new UserfriendlyException();
                        }
                        externalPartFile = new ExternalPartFile()
                        {
                            File = epf, Key = key
                        };
                    }
                    catch (Exception e)
                    {
                        log.Error($"Part Explorer Tree will not be complete! Failed to load part file {key.Name} in repository {key.Repository}.", e);
                        //we don't consider this a failure, just act as if that part file was set to "never build"
                        externalPartFile = new ExternalPartFile()
                        {
                            File = null, Key = key
                        };
                    }

                    externalPartFiles.Add(key, externalPartFile);
                }

                PartExplorerElementVM subPartVM = LoadExternalSubpartVM(externalSubparts, sp, externalPartFile, srcPath, bfs, buildStrategy);
                currentPart.Item1.AddChild(subPartVM);
            }
        }
Esempio n. 2
0
        private void InitializePartVMs(CompiledBuildStrategy buildStrategy, string srcPath, CancellationToken token)
        {
            Content = new CallbackMessage("Processing Parts...");
            var defaultPartFile = PartFileScanner.LoadPartFile(buildStrategy.DefaultTarget.PartFile, buildStrategy.DefaultTarget.Repository,
                                                               buildStrategy.LocalRepositories, srcPath);

            var products = defaultPartFile.Products.Select(p =>
            {
                return(new { VM = new PartExplorerElementVM(_configuration)
                             {
                                 Name = p.Name, PartType = PartType.Product,
                                 FromSource = buildStrategy.GetBuildFromSource(buildStrategy.DefaultTarget.PartFile, p.Name)
                             }, Product = p });
            }).ToList();
            var productVMsByName = new Dictionary <string, PartExplorerElementVM>(StringComparer.OrdinalIgnoreCase);

            foreach (var a in products)
            {
                productVMsByName[a.Product.Name] = a.VM;
            }

            var parts = defaultPartFile.Parts.Select(p =>
            {
                return(new { VM = new PartExplorerElementVM(_configuration)
                             {
                                 Name = p.Name, MakeFile = p.MakeFile,
                                 FromSource = buildStrategy.GetBuildFromSource(buildStrategy.DefaultTarget.PartFile, p.Name)
                             }, Part = p });
            }).ToList();
            var partVMsByName = new Dictionary <string, PartExplorerElementVM>(StringComparer.OrdinalIgnoreCase);

            foreach (var a in parts)
            {
                partVMsByName[a.Part.Name] = a.VM;
            }

            token.ThrowIfCancellationRequested();

            Queue <Tuple <PartExplorerElementVM, SubPart> > externalSubparts = new Queue <Tuple <PartExplorerElementVM, SubPart> >();

            foreach (var product in products)
            {
                foreach (var subPart in product.Product.SubParts)
                {
                    PartExplorerElementVM vm;
                    if (subPart.IsProduct)
                    {
                        if (productVMsByName.TryGetValue(subPart.Name, out vm) && vm != null)
                        {
                            product.VM.AddChild(vm);
                            continue;
                        }
                    }
                    else if (partVMsByName.TryGetValue(subPart.Name, out vm) && vm != null)
                    {
                        product.VM.AddChild(vm);
                        continue;
                    }

                    externalSubparts.Enqueue(new Tuple <PartExplorerElementVM, SubPart>(product.VM, subPart));
                }
            }

            foreach (var part in parts)
            {
                part.VM.PartType = DeterminePartType(part.VM, false, defaultPartFile.Directory, srcPath);
                foreach (var subPart in part.Part.SubParts)
                {
                    PartExplorerElementVM vm;
                    if (subPart.IsProduct)
                    {
                        if (productVMsByName.TryGetValue(subPart.Name, out vm) && vm != null)
                        {
                            part.VM.AddChild(vm);
                            continue;
                        }
                    }
                    else if (partVMsByName.TryGetValue(subPart.Name, out vm) && vm != null)
                    {
                        part.VM.AddChild(vm);
                        continue;
                    }

                    externalSubparts.Enqueue(new Tuple <PartExplorerElementVM, SubPart>(part.VM, subPart));
                }
            }

            var all         = products.Select(p => p.VM).Concat(parts.Select(p => p.VM)).ToList();
            var defaultPart = all.FirstOrDefault(e => string.Equals(e.Name, buildStrategy.DefaultTarget.PartName));

            if (defaultPart != null)
            {
                var container = new PartElementContainerVM()
                {
                    Title = "Default Target"
                };
                container.Items.Add(defaultPart);
                container.IsExpanded = true;
                Items.Add(container);
            }

            var roots = all.Where(p => !p.HasParent);
            var wop   = new PartElementContainerVM()
            {
                Title = "Roots"
            };

            foreach (var e in roots)
            {
                wop.Items.Add(e);
            }
            Items.Add(wop);

            var flatContainer = new PartElementContainerVM()
            {
                Title = "All"
            };

            foreach (var e in all)
            {
                flatContainer.Items.Add(e);
            }
            Items.Add(flatContainer);

            LoadExternalSubparts(externalSubparts, buildStrategy, srcPath, token);
            Content = this;//using this view model as both, the container and the content
        }