private async Task ResolveDependenciesAsync(IDependencyResolver dependencyResolver,
                                                    CancellationToken cancellation)
        {
            var unresolvedDependencies    = InstalledModules.Unresolved;
            var unresolvedInstallationSet = new UnresolvedInstallationSet(resolved: Enumerable.Empty <ModuleReleaseIdentifier>(),
                                                                          unresolved: unresolvedDependencies);

            var resolvedInstallationSets = (await unresolvedInstallationSet.ResolveAsync(dependencyResolver, cancellation)).ToList();

            if (resolvedInstallationSets.Count() == 0)
            {
                Notify(new InstallationSetConflict());

                // TODO: Replace with logging. We cannot access the logger in the domain currently, as we do not have DI in the domain.
                Console.WriteLine("---> InstallationSetConflict");
            }
            else
            {
                resolvedInstallationSets.Sort();
                ResolvedModules = resolvedInstallationSets.First();
                Notify(new InstallationSetChanged(ResolvedModules));

                // TODO: Replace with logging. We cannot access the logger in the domain currently, as we do not have DI in the domain.
                Console.WriteLine("---> InstallationSetChanged: ");

                foreach (var release in ResolvedModules.Resolved)
                {
                    Console.WriteLine(release.Module + " " + release.Version);
                }
            }
        }
        public Task ModuleUninstalledAsync(ModuleIdentifier module,
                                           IDependencyResolver dependencyResolver, // TODO: This should be injected via DI
                                           CancellationToken cancellation = default)
        {
            if (module == default)
            {
                throw new ArgumentDefaultException(nameof(module));
            }

            InstalledModules = InstalledModules.WithoutUnresolved(module);

            return(ResolveDependenciesAsync(dependencyResolver, cancellation));
        }
示例#3
0
        private async Task <IEnumerable <ResolvedInstallationSet> > TryResolveSingleDependencyAsync(ModuleDependency dependency,
                                                                                                    IDependencyResolver dependencyResolver,
                                                                                                    CancellationToken cancellation)
        {
            // We have a resolved dependency that does not match our version filter => This is a version conflict
            if (_resolved != null &&
                _resolved.TryGetValue(dependency.Module, out var resolvedDependency) &&
                !dependency.VersionRange.IsMatch(resolvedDependency))
            {
                return(Enumerable.Empty <ResolvedInstallationSet>());
            }

            var matchingReleases = await dependencyResolver.GetMatchingReleasesAsync(dependency, cancellation);

            var resolvedInstallationSets = new List <ResolvedInstallationSet>();
            var resolveTasks             = new List <Task <IEnumerable <ResolvedInstallationSet> > >();

            foreach (var matchingRelease in matchingReleases)
            {
                var dependencies = await dependencyResolver.GetDependenciesAsync(matchingRelease, cancellation);

                if (!TryCombine(matchingRelease, dependencies, out var unresolved))
                {
                    continue;
                }

                var resolved = (_resolved ?? ImmutableDictionary <ModuleIdentifier, ModuleVersion> .Empty).Add(matchingRelease.Module, matchingRelease.Version);

                // If there are no unresolved dependencies for the release, we can short circuit.
                if (unresolved.Count == 0)
                {
                    resolvedInstallationSets.Add(new ResolvedInstallationSet(resolved.Select(p => new ModuleReleaseIdentifier(p.Key, p.Value))));
                }
                else
                {
                    var unresolvedInstallationSet = new UnresolvedInstallationSet(resolved, unresolved);

                    resolveTasks.Add(unresolvedInstallationSet.ResolveAsync(dependencyResolver, cancellation));
                }
            }

            // TODO: Is it possible that there are duplicates?
            return((await Task.WhenAll(resolveTasks)).SelectMany(_ => _).Concat(resolvedInstallationSets));
        }
        public Task ModuleUpdatedAsync(ModuleIdentifier module,
                                       ModuleVersion version,
                                       IDependencyResolver dependencyResolver, // TODO: This should be injected via DI
                                       CancellationToken cancellation = default)
        {
            if (module == default)
            {
                throw new ArgumentDefaultException(nameof(module));
            }

            if (!InstalledModules.ContainsModule(module))
            {
                throw new InvalidOperationException("The specified module is not installed.");
            }

            InstalledModules = InstalledModules.SetVersionRange(module, ModuleVersionRange.SingleVersion(version));

            return(ResolveDependenciesAsync(dependencyResolver, cancellation));
        }