/// <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> >(); foreach (ILibraryInstallationState state in Libraries) { if (cancellationToken.IsCancellationRequested) { results.Add(LibraryInstallationResult.FromCancelled(state)); _hostInteraction.Logger.Log(Resources.Text.RestoreCancelled, LogLevel.Task); return(results); } _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> /// Creates an instance of the <see cref="Manifest"/> class based on /// the provided JSON string. /// </summary> /// <param name="json">A string of JSON in the correct format.</param> /// <param name="dependencies">The host provided dependencies.</param> /// <returns></returns> public static Manifest FromJson(string json, IDependencies dependencies) { try { Manifest manifest = JsonConvert.DeserializeObject <Manifest>(json); manifest._dependencies = dependencies; manifest._hostInteraction = dependencies.GetHostInteractions(); foreach (LibraryInstallationState state in manifest.Libraries.Cast <LibraryInstallationState>()) { state.ProviderId = state.ProviderId ?? manifest.DefaultProvider; } return(manifest); } catch (Exception) { dependencies.GetHostInteractions().Logger.Log(PredefinedErrors.ManifestMalformed().Message, LogLevel.Task); return(null); } }