/// <summary> /// Restores all libraries in the <see cref="Libraries"/> collection. /// </summary> /// <param name="cancellationToken">A token that allows for cancellation of the operation.</param> public async Task <IEnumerable <ILibraryInstallationResult> > RestoreAsync(CancellationToken cancellationToken) { //TODO: This should have an "undo scope" var results = new List <ILibraryInstallationResult>(); var tasks = new List <Task <ILibraryInstallationResult> >(); if (!IsValidManifestVersion(Version)) { results.Add(LibraryInstallationResult.FromErrors(new IError[] { PredefinedErrors.VersionIsNotSupported(Version) })); return(results); } foreach (ILibraryInstallationState state in Libraries) { if (cancellationToken.IsCancellationRequested) { results.Add(LibraryInstallationResult.FromCancelled(state)); _hostInteraction.Logger.Log(Resources.Text.RestoreCancelled, LogLevel.Task); return(results); } if (!state.IsValid(out IEnumerable <IError> errors)) { results.Add(new LibraryInstallationResult(state, errors.ToArray())); continue; } _hostInteraction.Logger.Log(string.Format(Resources.Text.RestoringLibrary, state.LibraryId), LogLevel.Operation); IProvider provider = _dependencies.GetProvider(state.ProviderId); if (provider != null) { tasks.Add(provider.InstallAsync(state, cancellationToken)); } else { results.Add(new LibraryInstallationResult(state, PredefinedErrors.ProviderUnknown(state.ProviderId))); } } await Task.WhenAll(tasks).ConfigureAwait(false); results.AddRange(tasks.Select(t => t.Result)); return(results); }
/// <summary> /// Returns a collection of <see cref="ILibraryOperationResult"/> that represents the status for validation of the Manifest and its libraries /// </summary> /// <param name="manifest">The <see cref="Manifest"/> to be validated</param> /// <param name="dependencies"><see cref="IDependencies"/>used to validate the libraries</param> /// <param name="cancellationToken"></param> /// <returns></returns> public static async Task <IEnumerable <ILibraryOperationResult> > GetManifestErrorsAsync( Manifest manifest, IDependencies dependencies, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (manifest == null) { return(new ILibraryOperationResult[] { LibraryOperationResult.FromError(PredefinedErrors.ManifestMalformed()) }); } if (!IsValidManifestVersion(manifest.Version)) { return(new ILibraryOperationResult[] { LibraryOperationResult.FromError(PredefinedErrors.VersionIsNotSupported(manifest.Version)) }); } return(await GetLibrariesErrorsAsync(manifest.Libraries, dependencies, manifest.DefaultDestination, manifest.DefaultProvider, cancellationToken)); }