public void Initialize(CancellationToken token) { if (_configuration == null) { return; } string srcPath = _configuration?.Parent?.SrcPath; if (string.IsNullOrEmpty(srcPath) || !Directory.Exists(srcPath)) { Content = new CallbackMessage("Source Dir does not exist."); return; } string strategies = _configuration?.BuildStrategy; if (string.IsNullOrEmpty(strategies)) { Content = new CallbackMessage("No Build Strategies defined."); return; } Content = new CallbackMessage("Processing Build Strategies..."); try { token.ThrowIfCancellationRequested(); var compiledStrategy = BuildStrategyScanner.LoadCompiledStrategy(srcPath, strategies, token); log.Info($"Compiled Strategy contains {compiledStrategy.PartStrategies.Count} PartStrategies, {compiledStrategy.LocalRepositories.Count} LocalRepositories."); var dt = compiledStrategy.DefaultTarget; if (dt == null) { Content = new CallbackMessage("Strategy has no default target."); return; } if (string.IsNullOrEmpty(dt.PartFile) || string.IsNullOrEmpty(dt.Repository)) { Content = new CallbackMessage("Default Target requires a PartFile and Repository attribute."); return; } log.Info($"Default Target '{dt.PartName}' in File '{dt.PartFile}' Repository '{dt.Repository}'"); InitializePartVMs(compiledStrategy, srcPath, token); } catch (UserfriendlyException ue) { Content = new CallbackMessage(ue.Message); } catch (Exception e) { Content = new CallbackMessage("Could not load parts. " + e.Message); log.Error($"Failed to load parts. {e.Message}.", e); } }
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 }