private IEnumerable <ILibraryInstallationState> ValidateParametersAndGetLibrariesToUpdate(Manifest manifest) { var errors = new List <string>(); if (string.IsNullOrWhiteSpace(LibraryName.Value)) { errors.Add(Resources.LibraryIdRequiredForUpdate); } IProvider provider = null; if (Provider.HasValue()) { provider = ManifestDependencies.GetProvider(Provider.Value()); if (provider == null) { errors.Add(string.Format(Resources.ProviderNotInstalled, Provider.Value())); } } if (ToVersion.HasValue() && string.IsNullOrWhiteSpace(ToVersion.Value())) { errors.Add(string.Format(Resources.InvalidToVersion, ToVersion.Value())); } if (errors.Any()) { throw new InvalidOperationException(string.Join(Environment.NewLine, errors)); } return(manifest.Libraries.Where(l => l.Name.Equals(LibraryName.Value, StringComparison.OrdinalIgnoreCase))); }
private IEnumerable <ILibraryInstallationState> ValidateParametersAndGetLibrariesToUninstall( Manifest manifest) { var errors = new List <string>(); if (string.IsNullOrWhiteSpace(LibraryId.Value)) { errors.Add(Resources.Text.LibraryIdRequiredForUnInstall); } IProvider provider = null; if (Provider.HasValue()) { provider = ManifestDependencies.GetProvider(Provider.Value()); if (provider == null) { errors.Add(string.Format(Resources.Text.ProviderNotInstalled, Provider.Value())); } } if (errors.Any()) { throw new InvalidOperationException(string.Join(Environment.NewLine, errors)); } return(LibraryResolver.Resolve(LibraryId.Value, manifest, provider)); }
protected async Task <Manifest> CreateManifestAsync(string defaultProvider, string defaultDestination, EnvironmentSettings settings, CancellationToken cancellationToken) { if (File.Exists(Settings.ManifestFileName)) { throw new InvalidOperationException(Resources.Text.InitFailedLibmanJsonFileExists); } Manifest manifest = await Manifest.FromFileAsync(Settings.ManifestFileName, ManifestDependencies, cancellationToken); manifest.AddVersion(Manifest.SupportedVersions.Last().ToString()); manifest.DefaultDestination = string.IsNullOrEmpty(defaultDestination) ? null : defaultDestination; defaultProvider = string.IsNullOrEmpty(defaultProvider) ? HostEnvironment.InputReader.GetUserInputWithDefault(nameof(settings.DefaultProvider), settings.DefaultProvider) : defaultProvider; if (ManifestDependencies.GetProvider(defaultProvider) == null) { IError unknownProviderError = PredefinedErrors.ProviderUnknown(defaultProvider); string message = string.Format(Resources.Text.InitFailedUnknownProvider, unknownProviderError.Code, unknownProviderError.Message); throw new InvalidOperationException(message); } manifest.DefaultProvider = defaultProvider; await manifest.SaveAsync(Settings.ManifestFileName, cancellationToken); return(manifest); }
private async Task <string> GetLatestVersionAsync(ILibraryInstallationState libraryToUpdate, CancellationToken cancellationToken) { ILibraryCatalog catalog = ManifestDependencies.GetProvider(libraryToUpdate.ProviderId)?.GetCatalog(); if (catalog == null) { throw new InvalidOperationException(PredefinedErrors.LibraryIdIsUndefined().Message); } try { return(await catalog.GetLatestVersion(libraryToUpdate.LibraryId, PreRelease.HasValue(), cancellationToken)); } catch (Exception ex) { throw new InvalidOperationException(string.Format(Resources.UnableToFindLatestVersionForLibrary, libraryToUpdate.LibraryId), ex); } }