public void Combine_ReturnsNoDuplicates()
    {
        const string id         = "mod.duplicate.id";
        const string idNonExist = "mod.nonexist.id";

        var resultOld = new ModDependencyResolveResult();

        resultOld.FoundDependencies.Add(new DummyDownloadablePackage()
        {
            Id = id
        });

        resultOld.NotFoundDependencies.Add(idNonExist);

        var resultNew = new ModDependencyResolveResult();

        resultNew.FoundDependencies.Add(new DummyDownloadablePackage()
        {
            Id = id
        });

        resultNew.NotFoundDependencies.Add(idNonExist);

        // Act
        var resultCombined = ModDependencyResolveResult.Combine(new[] { resultOld, resultNew });

        // Assert
        Assert.Single(resultCombined.FoundDependencies);
        Assert.Single(resultCombined.NotFoundDependencies);
    }
    public void Combine_ReturnsLatestVersion()
    {
        const string id         = "mod.duplicate.id";
        var          oldVersion = NuGetVersion.Parse("1.0.0");
        var          newVersion = NuGetVersion.Parse("1.0.1");

        var resultOld = new ModDependencyResolveResult();

        resultOld.FoundDependencies.Add(new DummyDownloadablePackage()
        {
            Id      = id,
            Version = oldVersion
        });

        var resultNew = new ModDependencyResolveResult();

        resultNew.FoundDependencies.Add(new DummyDownloadablePackage()
        {
            Id      = id,
            Version = newVersion
        });

        // Act
        var resultCombined = ModDependencyResolveResult.Combine(new[] { resultOld, resultNew });

        // Assert
        Assert.Single(resultCombined.FoundDependencies);
        Assert.Equal(newVersion, resultCombined.FoundDependencies[0].Version);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Resolves a list of missing packages.
    /// </summary>
    /// <param name="token">Used to cancel the operation.</param>
    public static async Task ResolveMissingPackagesAsync(CancellationToken token = default)
    {
        if (!HasInternetConnection)
        {
            return;
        }

        ModDependencyResolveResult resolveResult = null !;

        do
        {
            // Get missing dependencies for this update loop.
            var missingDeps = CheckMissingDependencies();

            // Get Dependencies
            var resolver = DependencyResolverFactory.GetInstance(IoC.Get <AggregateNugetRepository>());

            var results = new List <Task <ModDependencyResolveResult> >();
            foreach (var dependencyItem in missingDeps.Items)
            {
                foreach (var dependency in dependencyItem.Dependencies)
                {
                    results.Add(resolver.ResolveAsync(dependency, dependencyItem.Mod.PluginData, token));
                }
            }

            await Task.WhenAll(results);

            // Merge Results
            resolveResult = ModDependencyResolveResult.Combine(results.Select(x => x.Result));
            DownloadPackages(resolveResult, token);
        }while (resolveResult.FoundDependencies.Count > 0);

        if (resolveResult.NotFoundDependencies.Count > 0)
        {
            ActionWrappers.ExecuteWithApplicationDispatcher(() =>
            {
                Actions.DisplayMessagebox(Resources.ErrorMissingDependency.Get(),
                                          $"{Resources.FetchNugetNotFoundMessage.Get()}\n\n" +
                                          $"{string.Join('\n', resolveResult.NotFoundDependencies)}\n\n" +
                                          $"{Resources.FetchNugetNotFoundAdvice.Get()}",
                                          new Actions.DisplayMessageBoxParams()
                {
                    Type            = Actions.MessageBoxType.Ok,
                    StartupLocation = Actions.WindowStartupLocation.CenterScreen
                });
            });
        }
    }