示例#1
0
    public async Task Install(List <string> itemsToInstall)
    {
        errors.Clear();
        eventAggregator.PublishOnUIThread(new InstallStartedEvent());
        installProgress = 0;
        var installationDefinitions = installers
                                      .Where(p => itemsToInstall.Contains(p.Name))
                                      .OrderBy(p => p.Name).ToList();

        if (pendingRestartAndResume.ResumedFromRestart)
        {
            var checkpoint = pendingRestartAndResume.Checkpoint();
            if (installationDefinitions.Any(p => p.Name.Equals(checkpoint)))
            {
                // Fast Forward to the step after the last successful step
                installationDefinitions = installationDefinitions
                                          .SkipWhile(p => !p.Name.Equals(checkpoint))
                                          .Skip(1)
                                          .ToList();
            }
        }
        pendingRestartAndResume.CleanupResume();
        installCount = installationDefinitions
                       .Select(p => p.NestedActionCount)
                       .Sum();

        foreach (var definition in installationDefinitions)
        {
            if (aborting)
            {
                break;
            }

            PublishProgressEvent();
            await definition.Execute(AddOutput, AddError).ConfigureAwait(false);

            if (InstallFailed)
            {
                eventAggregator.PublishOnUIThread(new InstallFailedEvent
                {
                    Reason   = $"Failed to install: {definition.Name}",
                    Failures = errors
                });
                return;
            }
            if (definition.RebootRequired)
            {
                return;
            }
            eventAggregator.PublishOnUIThread(new CheckPointInstallEvent
            {
                Item = definition.Name
            });
        }
        if (!InstallFailed)
        {
            eventAggregator.PublishOnUIThread(new InstallSucceededEvent
            {
                InstalledItems = itemsToInstall
            });
        }
    }