Esempio n. 1
0
        private void AddChildVMs(Queue <Tuple <PartExplorerElementVM, SubPart> > externalSubparts, ExternalPartFile externalPartFile, PartExplorerElementVM currentVM,
                                 Part currentPart, string srcDir, CompiledBuildStrategy buildStrategy)
        {
            foreach (var subPart in currentPart.SubParts)
            {
                if (!string.IsNullOrEmpty(subPart.Repository) || !string.IsNullOrEmpty(subPart.PartFile))
                {
                    externalSubparts.Enqueue(new Tuple <PartExplorerElementVM, SubPart>(currentVM, subPart));
                    continue;
                }

                PartExplorerElementVM vm;
                if (!externalPartFile.LoadedParts.TryGetValue(subPart.Name, out vm))
                {
                    var bfs = buildStrategy.GetBuildFromSource(subPart.PartFile ?? externalPartFile.Key.Name, subPart.Name);
                    if (bfs == BuildFromSource.Never)
                    {
                        vm = new PartExplorerElementVM(_configuration)
                        {
                            Name       = subPart.Name,
                            Repository = subPart.Repository,
                            PartFile   = subPart.PartFile,
                            FromSource = BuildFromSource.Never,
                            PartType   = PartType.Reference
                        };
                    }
                    else
                    {
                        vm = LoadExternalSubpartVM(externalSubparts, subPart, externalPartFile, srcDir, bfs, buildStrategy);
                    }
                }

                currentVM.AddChild(vm);
            }
        }
Esempio n. 2
0
        private static CompiledBuildStrategy CompileStrategy(List <BuildStrategy> list)
        {
            var result = new CompiledBuildStrategy();

            result.DefaultPartOptions = list.Select(s => s.DefaultPartOptions).FirstOrDefault(dpo => dpo != null);
            result.DefaultTarget      = list.Select(s => s.DefaultTarget).FirstOrDefault(dt => dt != null);
            var partStrategies = list.SelectMany(s => s.PartStrategies.Reverse());

            foreach (var ps in partStrategies)
            {
                if (ps.PartFile?.Equals("$(strategy.defaultPartFile)", StringComparison.OrdinalIgnoreCase) == true)
                {
                    ps.PartFile = result.DefaultTarget?.PartFile;
                }

                if (string.IsNullOrEmpty(ps.PartFile))
                {
                    continue;
                }

                result.PartStrategies.Add(ps);
            }

            var localRepositories = list.SelectMany(s => s.LocalRepositories).Where(l => !string.IsNullOrEmpty(l.Directory));
            var dict = result.LocalRepositories;

            foreach (var lr in localRepositories)
            {
                dict[lr.Name] = lr;
            }

            return(result);
        }
Esempio n. 3
0
        private PartExplorerElementVM LoadExternalSubpartVM(Queue <Tuple <PartExplorerElementVM, SubPart> > externalSubparts, SubPart sp, ExternalPartFile externalPartFile, string srcDir, BuildFromSource bfs, CompiledBuildStrategy strategy)
        {
            PartExplorerElementVM subPartVM;

            if (externalPartFile.LoadedParts.TryGetValue(sp.Name, out subPartVM))
            {
                return(subPartVM);
            }

            Part newSubPart = null;

            if (sp.IsProduct)
            {
                newSubPart = externalPartFile.File.Products.FirstOrDefault(p => string.Equals(p.Name, sp.Name, StringComparison.OrdinalIgnoreCase));
            }
            else
            {
                newSubPart = externalPartFile.File.Parts.FirstOrDefault(p => string.Equals(p.Name, sp.Name, StringComparison.OrdinalIgnoreCase));
            }

            if (newSubPart == null)
            {
                log.Warn($"Failed to find part {sp.Name} in partfile {sp.PartFile}");
                newSubPart = new Part()
                {
                    Name = sp.Name
                };                                          //use a dummy instead
            }

            subPartVM = new PartExplorerElementVM(_configuration)
            {
                Name       = sp.Name,
                Repository = externalPartFile.Key.Repository,
                PartFile   = externalPartFile.Key.Name,
                MakeFile   = newSubPart.MakeFile,
                FromSource = bfs,
            };

            subPartVM.PartType = DeterminePartType(subPartVM, sp.IsProduct, externalPartFile.File.Directory, srcDir);

            externalPartFile.LoadedParts.Add(sp.Name, subPartVM);

            if (newSubPart != null)
            {
                AddChildVMs(externalSubparts, externalPartFile, subPartVM, newSubPart, srcDir, strategy);
            }

            return(subPartVM);
        }
Esempio n. 4
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. 5
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
        }