public async Task <IEnumerable <string> > GetLibraryVersions(CancellationToken cancellationToken)
        {
            if (!JsDelivrCatalog.IsGitHub(DisplayName))
            {
                NpmPackageInfo npmPackageInfo = await NpmPackageInfoCache.GetPackageInfoAsync(DisplayName, CancellationToken.None);

                if (npmPackageInfo != null)
                {
                    return(npmPackageInfo.Versions
                           .OrderByDescending(v => v)
                           .Select(v => v.ToString())
                           .ToList());
                }
            }

            return(Enumerable.Empty <string>());
        }
Пример #2
0
        /// <summary>
        /// Copies ILibraryInstallationState files to cache
        /// </summary>
        /// <param name="state"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private async Task <LibraryOperationResult> RefreshCacheAsync(ILibraryInstallationState state, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(LibraryOperationResult.FromCancelled(state));
            }

            var    tasks      = new List <Task>();
            string libraryDir = Path.Combine(CacheFolder, state.Name);

            try
            {
                List <CacheFileMetadata> librariesMetadata = new List <CacheFileMetadata>();
                foreach (string sourceFile in state.Files)
                {
                    string cacheFile = Path.Combine(libraryDir, state.Version, sourceFile);
                    string libraryId = LibraryIdToNameAndVersionConverter.Instance.GetLibraryId(state.Name, state.Version, state.ProviderId);
                    string url       = string.Format(JsDelivrCatalog.IsGitHub(libraryId) ? DownloadUrlFormatGH : DownloadUrlFormat, state.Name, state.Version, sourceFile);

                    CacheFileMetadata newEntry = new CacheFileMetadata(url, cacheFile);
                    if (!librariesMetadata.Contains(newEntry))
                    {
                        librariesMetadata.Add(new CacheFileMetadata(url, cacheFile));
                    }
                }
                await _cacheService.RefreshCacheAsync(librariesMetadata, cancellationToken);
            }
            catch (ResourceDownloadException ex)
            {
                HostInteraction.Logger.Log(ex.ToString(), LogLevel.Error);
                return(new LibraryOperationResult(state, PredefinedErrors.FailedToDownloadResource(ex.Url)));
            }
            catch (OperationCanceledException)
            {
                return(LibraryOperationResult.FromCancelled(state));
            }
            catch (Exception ex)
            {
                HostInteraction.Logger.Log(ex.InnerException.ToString(), LogLevel.Error);
                return(new LibraryOperationResult(state, PredefinedErrors.UnknownException()));
            }

            return(LibraryOperationResult.FromSuccess(state));
        }
Пример #3
0
        protected override string GetDownloadUrl(ILibraryInstallationState state, string sourceFile)
        {
            string libraryId = LibraryNamingScheme.GetLibraryId(state.Name, state.Version);

            return(string.Format(JsDelivrCatalog.IsGitHub(libraryId) ? DownloadUrlFormatGH : DownloadUrlFormat, state.Name, state.Version, sourceFile));
        }