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); } }
private PartType DeterminePartType(PartExplorerElementVM subPartVM, bool isProduct, string repositorySrcDir, string srcDir) { if (isProduct) { return(PartType.Product); } if (string.IsNullOrWhiteSpace(subPartVM.MakeFile)) { return(PartType.Group); } var makeFile = subPartVM.MakeFile; if (!makeFile.EndsWith(".mke", StringComparison.OrdinalIgnoreCase)) { return(PartType.Unknown); } string fullPath; if (makeFile.StartsWith("${SrcRoot}", StringComparison.OrdinalIgnoreCase)) { fullPath = Path.Combine(srcDir, makeFile.Substring(10)); } else { fullPath = Path.Combine(repositorySrcDir, makeFile); } return(MakeFileScanner.GuessPartTypeFromMakeFile(fullPath)); }
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); }
internal void AddChild(PartExplorerElementVM vm) { Children.Add(vm); vm.HasParent = true; }
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); } }