/// <summary> /// Returns true if the <see cref="ILibraryInstallationState"/> is valid. /// </summary> /// <param name="state">The state to test.</param> /// <param name="errors">The errors contained in the <see cref="ILibraryInstallationState"/> if any.</param> /// <returns> /// <c>true</c> if the specified state is valid; otherwise, <c>false</c>. /// </returns> public static bool IsValid(this ILibraryInstallationState state, out IEnumerable <IError> errors) { errors = null; var list = new List <IError>(); if (state == null) { return(false); } if (string.IsNullOrEmpty(state.ProviderId)) { list.Add(PredefinedErrors.ProviderIsUndefined()); } if (string.IsNullOrEmpty(state.DestinationPath)) { list.Add(PredefinedErrors.PathIsUndefined()); } if (string.IsNullOrEmpty(state.LibraryId)) { list.Add(PredefinedErrors.LibraryIdIsUndefined()); } errors = list; return(list.Count == 0); }
public void Predefined() { TestError(PredefinedErrors.UnknownException(), "LIB000"); TestError(PredefinedErrors.ProviderUnknown("_prov_"), "LIB001", "_prov_"); TestError(PredefinedErrors.UnableToResolveSource("_libid_", "_prov_"), "LIB002", "_libid_", "_prov_"); TestError(PredefinedErrors.CouldNotWriteFile("file.js"), "LIB003", "file.js"); TestError(PredefinedErrors.ManifestMalformed(), "LIB004"); TestError(PredefinedErrors.PathIsUndefined(), "LIB005"); TestError(PredefinedErrors.LibraryIdIsUndefined(), "LIB006"); TestError(PredefinedErrors.ProviderIsUndefined(), "LIB007"); }
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); } }
/// <summary> /// Validates <see cref="ILibraryInstallationState"/> /// </summary> /// <param name="state">The <see cref="ILibraryInstallationState"/> to validate.</param> /// <param name="provider">The <see cref="IProvider"/> used to validate <see cref="ILibraryInstallationState"/></param> /// <returns><see cref="ILibraryOperationResult"/> with the result of the validation</returns> public static async Task <ILibraryOperationResult> IsValidAsync(this ILibraryInstallationState state, IProvider provider) { if (state == null) { return(new LibraryOperationResult(state, new[] { PredefinedErrors.UnknownError() })); } if (provider == null) { return(new LibraryOperationResult(state, new[] { PredefinedErrors.ProviderUnknown(provider.Id) })); } if (string.IsNullOrEmpty(state.Name)) { return(new LibraryOperationResult(state, new[] { PredefinedErrors.LibraryIdIsUndefined() })); } ILibraryCatalog catalog = provider.GetCatalog(); try { await catalog.GetLibraryAsync(state.Name, state.Version, CancellationToken.None).ConfigureAwait(false); } catch { return(new LibraryOperationResult(state, new[] { PredefinedErrors.UnableToResolveSource(state.Name, state.Version, provider.Id) })); } if (string.IsNullOrEmpty(state.DestinationPath)) { return(new LibraryOperationResult(state, new[] { PredefinedErrors.PathIsUndefined() })); } if (state.DestinationPath.IndexOfAny(Path.GetInvalidPathChars()) >= 0) { return(new LibraryOperationResult(state, new[] { PredefinedErrors.DestinationPathHasInvalidCharacters(state.DestinationPath) })); } return(LibraryOperationResult.FromSuccess(state)); }