public async Task <DependencyGraph> GetGraph(AppxPackage package, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null) { var dependencyGraph = new DependencyGraph(); var list = await this.GetConsideredPackages(package, cancellationToken, progress).ConfigureAwait(false); var packages = this.GetPackageDependencies(0, list).ToList(); var operatingSystems = this.GetOperatingSystemDependencies(packages.Count, list).ToList(); var unresolvedDependencies = new List <MissingPackageGraphElement>(); var id = packages.Count + operatingSystems.Count; foreach (var pkg in packages) { foreach (var packageDependency in pkg.Package.PackageDependencies) { var findDependency = packages.FirstOrDefault(depPkg => depPkg.Package.Name == packageDependency.Name && depPkg.Package.Publisher == packageDependency.Publisher); if (findDependency != null) { dependencyGraph.Relations.Add(new Relation(findDependency, packageDependency.Version + "˄", pkg)); } else { var findUnresolved = unresolvedDependencies.FirstOrDefault(unresolved => unresolved.PackageName == packageDependency.Name); if (findUnresolved == null) { id++; findUnresolved = new MissingPackageGraphElement(id, packageDependency.Name); unresolvedDependencies.Add(findUnresolved); dependencyGraph.Elements.Add(findUnresolved); } dependencyGraph.Relations.Add(new Relation(findUnresolved, packageDependency.Version + "˄", pkg)); } } foreach (var systemDependency in pkg.Package.OperatingSystemDependencies) { var findSystem = operatingSystems.First(os => os.OperatingSystem == GetOsFamily(systemDependency)); dependencyGraph.Relations.Add(new Relation(findSystem, findSystem.MaxRequiredVersion + "˄", pkg)); } foreach (var mainPackage in pkg.Package.MainPackages) { var findParent = packages.FirstOrDefault(depPkg => depPkg.Package.Name == mainPackage.Name); if (findParent != null) { dependencyGraph.Relations.Add(new Relation(findParent, "main package", pkg)); } else { var findUnresolved = unresolvedDependencies.FirstOrDefault(unresolved => unresolved.PackageName == mainPackage.Name); if (findUnresolved == null) { id++; findUnresolved = new MissingPackageGraphElement(id, mainPackage.Name); unresolvedDependencies.Add(findUnresolved); dependencyGraph.Elements.Add(findUnresolved); } dependencyGraph.Relations.Add(new Relation(findUnresolved, "main package", pkg)); } } } foreach (var pkg in packages) { dependencyGraph.Elements.Add(pkg); } foreach (var os in operatingSystems) { dependencyGraph.Elements.Add(os); } return(dependencyGraph); }
private static string VertexToString(MissingPackageGraphElement element) { return(element.PackageName); }