Exemplo n.º 1
0
        internal static IDictionary <string, object>?ProduceAdditionalData(this ITemplatePackageInfo package, IReadOnlyList <IAdditionalDataProducer> producers)
        {
            Dictionary <string, object>?additionalData = new Dictionary <string, object>();

            foreach (var producer in producers)
            {
                try
                {
                    var data = producer.CreateDataForTemplatePackage(package);
                    if (data != null)
                    {
                        additionalData[producer.DataUniqueName] = data;
                    }
                }
                catch (TaskCanceledException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    Verbose.WriteLine($"Failed to produce additional data for {package.Name}::{package.Version} with producer {producer.DataUniqueName}, details: {ex}");
                }
            }
            if (additionalData.Any())
            {
                return(additionalData);
            }
            return(null);
        }
Exemplo n.º 2
0
        public async Task <IDownloadedPackInfo> DownloadPackageAsync(ITemplatePackageInfo packinfo, CancellationToken token)
        {
            string packageFileName = string.Format(DownloadPackageFileNameFormat, packinfo.Name, packinfo.Version);
            string outputPackageFileNameFullPath = Path.Combine(_packageTempPath, packageFileName);

            try
            {
                using Stream packageStream = File.Create(outputPackageFileNameFullPath);
                if (await _downloadResource.CopyNupkgToStreamAsync(
                        packinfo.Name,
                        new NuGetVersion(packinfo.Version),
                        packageStream,
                        _cacheContext,
                        NullLogger.Instance,
                        token).ConfigureAwait(false))
                {
                    return(new DownloadedPackInfo(packinfo, outputPackageFileNameFullPath));
                }
                else
                {
                    throw new Exception($"Download failed: {nameof(_downloadResource.CopyNupkgToStreamAsync)} returned false.");
                }
            }
            catch (TaskCanceledException)
            {
                throw;
            }
            catch (Exception e)
            {
                Console.WriteLine($"Failed to download package {packinfo.Name} {packinfo.Version}, reason: {e}.");
                throw;
            }
        }
Exemplo n.º 3
0
        internal DownloadedPackInfo(ITemplatePackageInfo info, string filePath)
        {
            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentException($"'{nameof(filePath)}' cannot be null or whitespace.", nameof(filePath));
            }

            _info = info ?? throw new ArgumentNullException(nameof(info));
            Path  = filePath;
        }
Exemplo n.º 4
0
 internal FilteredPackageInfo(ITemplatePackageInfo info, string reason)
 {
     Reason         = reason;
     Name           = info.Name;
     Version        = info.Version;
     Owners         = info.Owners;
     TotalDownloads = info.TotalDownloads;
     Verified       = info.Verified;
     Description    = info.Description;
     IconUrl        = info.IconUrl;
 }
Exemplo n.º 5
0
 private bool CheckIfVersionIsKnownNonTemplatePackage(
     ITemplatePackageInfo sourceInfo,
     Dictionary <string, FilteredPackageInfo> filteredPackages,
     ScanningStats scanningStats,
     out string?currentVersion)
 {
     currentVersion = null;
     if (_knownFilteredPackages.TryGetValue(sourceInfo.Name, out FilteredPackageInfo? info))
     {
         if (sourceInfo.Version == info.Version)
         {
             Verbose.WriteLine($"Package {sourceInfo.Name}::{sourceInfo.Version} has not changed since last scan, skipping as it was filtered last time.");
             filteredPackages[sourceInfo.Name] = info;
             scanningStats.SameNonTemplatePacksCount++;
             return(true);
         }
         else
         {
             currentVersion = info.Version;
         }
     }
     return(false);
 }
Exemplo n.º 6
0
        public TemplatePackageSearchData(ITemplatePackageInfo packInfo, IEnumerable <TemplateSearchData> templates, IDictionary <string, object>?data = null)
        {
            if (packInfo is null)
            {
                throw new ArgumentNullException(nameof(packInfo));
            }

            if (templates is null)
            {
                throw new ArgumentNullException(nameof(templates));
            }

            Name = !string.IsNullOrWhiteSpace(packInfo.Name) ? packInfo.Name
                : throw new ArgumentException($"{nameof(packInfo.Name)} should not be null or empty", nameof(packInfo));
            Version        = packInfo.Version;
            TotalDownloads = packInfo.TotalDownloads;
            Owners         = packInfo.Owners;
            Verified       = packInfo.Verified;
            Templates      = templates.ToList();
            Description    = packInfo.Description;
            IconUrl        = packInfo.IconUrl;
            AdditionalData = data ?? new Dictionary <string, object>();
        }
Exemplo n.º 7
0
        private bool CheckIfVersionIsKnownTemplatePackage(
            ITemplatePackageInfo sourceInfo,
            Dictionary <string, TemplatePackageSearchData> newCache,
            ScanningStats scanningStats,
            out string?currentVersion)
        {
            currentVersion = null;
            if (_existingCache.TryGetValue(sourceInfo.Name, out TemplatePackageSearchData? existingInfo))
            {
                if (sourceInfo.Version == existingInfo.Version)
                {
                    Verbose.WriteLine($"Package {sourceInfo.Name}::{sourceInfo.Version} has not changed since last scan, updating metadata only.");
                    newCache[sourceInfo.Name] = new TemplatePackageSearchData(sourceInfo, existingInfo.Templates, sourceInfo.ProduceAdditionalData(_additionalDataProducers));

                    scanningStats.SameTemplatePacksCount++;
                    return(true);
                }
                else
                {
                    currentVersion = existingInfo.Version;
                }
            }
            return(false);
        }
Exemplo n.º 8
0
 public Task <IDownloadedPackInfo> DownloadPackageAsync(ITemplatePackageInfo packinfo, CancellationToken token)
 {
     return(Task.FromResult((IDownloadedPackInfo)packinfo));
 }