Пример #1
0
 public Task PopulateStateAsync(
     PackageQueryContext context,
     PackageConsistencyState state,
     IProgressReporter progressReporter)
 {
     return(Task.CompletedTask);
 }
Пример #2
0
        public async Task <bool> IsConsistentAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter)
        {
            var report = await GetReportAsync(context, state, progressReporter, allowPartial : true);

            return(report.IsConsistent);
        }
        private bool IsMatch(PackageQueryContext context)
        {
            if (context.Nuspec.Document == null)
            {
                return(false);
            }

            return(_nuspecQuery.IsMatch(context.Nuspec.Document));
        }
        private async Task <MutableReport> GetReportAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter,
            bool allowPartial)
        {
            var report = new MutableReport {
                IsConsistent = true
            };
            var incrementalProgress = new IncrementalProgress(progressReporter, 3);
            var baseUrl             = await GetBaseUrlAsync();

            var shouldExist = !context.Package.Deleted;

            await PopulateStateAsync(context, state, progressReporter);

            report.PackageContentMetadata = state.FlatContainer.PackageContentMetadata;
            report.IsConsistent          &= shouldExist == report.PackageContentMetadata.Exists;
            await incrementalProgress.ReportProgressAsync("Check for the package content in flat container.");

            if (allowPartial && !report.IsConsistent)
            {
                return(report);
            }

            var hasPackageManifest = await _flatContainer.HasPackageManifestAsync(
                baseUrl,
                context.Package.Id,
                context.Package.Version);

            report.HasPackageManifest = hasPackageManifest;
            report.IsConsistent      &= shouldExist == hasPackageManifest;
            await incrementalProgress.ReportProgressAsync("Checked for the package manifest in flat container.");

            if (allowPartial && !report.IsConsistent)
            {
                return(report);
            }

            var isInIndex = await _flatContainer.HasPackageInIndexAsync(
                baseUrl,
                context.Package.Id,
                context.Package.Version);

            report.IsInIndex     = isInIndex;
            report.IsConsistent &= shouldExist == isInIndex;
            await incrementalProgress.ReportProgressAsync("Checked for the package in flat container index.");

            if (allowPartial && !report.IsConsistent)
            {
                return(report);
            }

            return(report);
        }
        public async Task <CrossCheckConsistencyReport> GetReportAsync(PackageQueryContext context, PackageConsistencyState state, IProgressReporter progressReporter)
        {
            await PopulateStateAsync(context, state, progressReporter);

            var doPackageContentsMatch = state.PackagesContainer.PackageContentMetadata?.ContentMD5 == state.FlatContainer.PackageContentMetadata?.ContentMD5;

            var isConsistent = doPackageContentsMatch;

            return(new CrossCheckConsistencyReport(
                       isConsistent,
                       doPackageContentsMatch));
        }
        public async Task <bool> IsConsistentAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter)
        {
            if (!(await _gallery.IsConsistentAsync(context, state, progressReporter)))
            {
                return(false);
            }

            if (!(await _v2.IsConsistentAsync(context, state, progressReporter)))
            {
                return(false);
            }

            if (!(await _packagesContainer.IsConsistentAsync(context, state, progressReporter)))
            {
                return(false);
            }

            if (!(await _flatContainer.IsConsistentAsync(context, state, progressReporter)))
            {
                return(false);
            }

            if (!(await _registrationOriginal.IsConsistentAsync(context, state, progressReporter)))
            {
                return(false);
            }

            if (!(await _registrationGzipped.IsConsistentAsync(context, state, progressReporter)))
            {
                return(false);
            }

            if (!(await _registrationOriginal.IsConsistentAsync(context, state, progressReporter)))
            {
                return(false);
            }

            if (!(await _search.IsConsistentAsync(context, state, progressReporter)))
            {
                return(false);
            }

            if (!(await _crossCheck.IsConsistentAsync(context, state, progressReporter)))
            {
                return(false);
            }

            return(true);
        }
        public async Task <FlatContainerConsistencyReport> GetReportAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter)
        {
            var report = await GetReportAsync(context, state, progressReporter, allowPartial : false);

            return(new FlatContainerConsistencyReport(
                       report.IsConsistent,
                       report.PackageContentMetadata,
                       report.HasPackageManifest.Value,
                       report.IsInIndex.Value));
        }
        public async Task <V2ConsistencyReport> GetReportAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter)
        {
            var report = await GetReportAsync(context, state, progressReporter, allowPartial : false);

            return(new V2ConsistencyReport(
                       report.IsConsistent,
                       report.HasPackageSemVer1.Value,
                       report.HasPackageSemVer2.Value,
                       report.IsListedSemVer1.Value,
                       report.IsListedSemVer2.Value));
        }
        private async Task <MutableReport> GetReportAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter,
            bool allowPartial)
        {
            var incrementalProgress   = new IncrementalProgress(progressReporter, 2);
            var shouldExistSemVer1    = !context.Package.Deleted && !context.IsSemVer2;
            var shouldBeListedSemVer1 = shouldExistSemVer1 && context.IsListed;
            var shouldExistSemVer2    = !context.Package.Deleted;
            var shouldBeListedSemVer2 = shouldExistSemVer2 && context.IsListed;

            var report = new MutableReport {
                IsConsistent = true
            };

            var packageSemVer1 = await _client.GetPackageOrNullAsync(
                _settings.V2BaseUrl,
                context.Package.Id,
                context.Package.Version,
                semVer2 : false);

            report.HasPackageSemVer1 = packageSemVer1 != null;
            report.IsListedSemVer1   = packageSemVer1?.Listed ?? false;
            report.IsConsistent     &= shouldExistSemVer1 == report.HasPackageSemVer1 && shouldBeListedSemVer1 == report.IsListedSemVer1;
            await incrementalProgress.ReportProgressAsync("Checked for the package in V2, SemVer 1.0.0.");

            if (allowPartial && !report.IsConsistent)
            {
                return(report);
            }

            var packageSemVer2 = await _client.GetPackageOrNullAsync(
                _settings.V2BaseUrl,
                context.Package.Id,
                context.Package.Version,
                semVer2 : true);

            report.HasPackageSemVer2 = packageSemVer2 != null;
            report.IsListedSemVer2   = packageSemVer2?.Listed ?? false;
            report.IsConsistent     &= shouldExistSemVer2 == report.HasPackageSemVer2 && shouldBeListedSemVer2 == report.IsListedSemVer2;
            await incrementalProgress.ReportProgressAsync("Checked for the package in V2, SemVer 2.0.0.");

            if (allowPartial && !report.IsConsistent)
            {
                return(report);
            }

            return(report);
        }
Пример #10
0
        private async Task <MutableReport> GetReportAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter,
            bool allowPartial)
        {
            var report = new MutableReport {
                IsConsistent = true
            };
            var incrementalProgress = new IncrementalProgress(progressReporter, 2);
            var baseUrl             = await _serviceIndexCache.GetUrlAsync(_type);

            var shouldExist    = !context.Package.Deleted && (_hasSemVer2 || !context.IsSemVer2);
            var shouldBeListed = shouldExist && context.IsListed;

            var registrationLeafItem = await _client.GetRegistrationLeafItemOrNullAsync(
                baseUrl,
                context.Package.Id,
                context.Package.Version);

            report.IsInIndex       = registrationLeafItem != null;
            report.IsListedInIndex = registrationLeafItem?.CatalogEntry.Listed ?? false;
            report.IsConsistent   &= shouldExist == report.IsInIndex && shouldBeListed == report.IsListedInIndex;
            await incrementalProgress.ReportProgressAsync("Checked for the package in the registration index.");

            if (allowPartial && !report.IsConsistent)
            {
                return(report);
            }

            var registrationLeaf = await _client.GetRegistrationLeafOrNullAsync(
                baseUrl,
                context.Package.Id,
                context.Package.Version);

            report.HasLeaf        = registrationLeaf != null;
            report.IsListedInLeaf = registrationLeaf?.Listed ?? false;
            if ((!DeletedPackagesShouldHaveNoLeaves && !context.Package.Deleted) || DeletedPackagesShouldHaveNoLeaves)
            {
                report.IsConsistent &= shouldExist == report.HasLeaf && shouldBeListed == report.IsListedInLeaf;
            }
            await incrementalProgress.ReportProgressAsync("Checked for the package's registration leaf.");

            if (allowPartial && !report.IsConsistent)
            {
                return(report);
            }

            return(report);
        }
        public async Task <SearchConsistencyReport> GetReportAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter)
        {
            var report = await GetReportAsync(context, state, progressReporter, allowPartial : false);

            return(new SearchConsistencyReport(
                       report.IsConsistent,
                       report.BaseUrlHasPackageSemVer1,
                       report.BaseUrlHasPackageSemVer2,
                       report.BaseUrlIsListedSemVer1,
                       report.BaseUrlIsListedSemVer2));
        }
Пример #12
0
        public async Task <RegistrationConsistencyReport> GetReportAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter)
        {
            var report = await GetReportAsync(context, state, progressReporter, allowPartial : false);

            return(new RegistrationConsistencyReport(
                       report.IsConsistent,
                       report.IsInIndex.Value,
                       report.HasLeaf.Value,
                       report.IsListedInIndex.Value,
                       report.IsListedInLeaf.Value));
        }
        public async Task <PackagesContainerConsistencyReport> GetReportAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter)
        {
            var shouldExist = !context.Package.Deleted;

            await PopulateStateAsync(context, state, progressReporter);

            var isConsistent = shouldExist == state.PackagesContainer.PackageContentMetadata.Exists;

            return(new PackagesContainerConsistencyReport(
                       isConsistent,
                       state.PackagesContainer.PackageContentMetadata));
        }
        public async Task PopulateStateAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter)
        {
            if (state.Gallery.PackageState != null)
            {
                return;
            }

            var packageState = await _client.GetPackageStateAsync(
                _settings.GalleryBaseUrl,
                context.Package.Id,
                context.Package.Version);

            state.Gallery.PackageState = packageState;
        }
        public async Task PopulateStateAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter)
        {
            if (state.PackagesContainer.PackageContentMetadata != null)
            {
                return;
            }

            var packageContentMetadata = await _client.GetPackageContentMetadataAsync(
                _settings.PackagesContainerBaseUrl,
                context.Package.Id,
                context.Package.Version);

            state.PackagesContainer.PackageContentMetadata = packageContentMetadata;
        }
        public async Task PopulateStateAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter)
        {
            if (state.FlatContainer.PackageContentMetadata != null)
            {
                return;
            }

            var baseUrl = await GetBaseUrlAsync();

            var packageContentMetadata = await _flatContainer.GetPackageContentMetadataAsync(
                baseUrl,
                context.Package.Id,
                context.Package.Version);

            state.FlatContainer.PackageContentMetadata = packageContentMetadata;
        }
        public async Task <GalleryConsistencyReport> GetReportAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter)
        {
            var shouldExist = !context.Package.Deleted;

            await PopulateStateAsync(context, state, progressReporter);

            var actuallyExists = state.Gallery.PackageState.PackageDeletedStatus == PackageDeletedStatus.NotDeleted;

            var isConsistent = shouldExist == actuallyExists &&
                               ((shouldExist && state.Gallery.PackageState.IsSemVer2 == context.IsSemVer2) ||
                                !shouldExist) &&
                               state.Gallery.PackageState.IsListed == context.IsListed;

            return(new GalleryConsistencyReport(
                       isConsistent,
                       state.Gallery.PackageState));
        }
        public async Task <bool> IsMatchAsync(PackageQueryContext context, PackageConsistencyState state)
        {
            if (context.Package.Deleted)
            {
                return(false);
            }

            if (!context.Nuspec.Exists ||
                context.Nuspec.Document == null)
            {
                await _nuspecDownloader.StoreNuspecAsync(
                    context.Package.Id,
                    context.Package.Version,
                    CancellationToken.None);

                throw new InvalidOperationException($"The .nuspec for {context.Package.Id} {context.Package.Version} could not be loaded.");
            }

            return(false);
        }
        public async Task PopulateStateAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter)
        {
            await _gallery.PopulateStateAsync(context, state, progressReporter);

            await _v2.PopulateStateAsync(context, state, progressReporter);

            await _packagesContainer.PopulateStateAsync(context, state, progressReporter);

            await _flatContainer.PopulateStateAsync(context, state, progressReporter);

            await _registrationOriginal.PopulateStateAsync(context, state, progressReporter);

            await _registrationGzipped.PopulateStateAsync(context, state, progressReporter);

            await _registrationSemVer2.PopulateStateAsync(context, state, progressReporter);

            await _search.PopulateStateAsync(context, state, progressReporter);

            await _crossCheck.PopulateStateAsync(context, state, progressReporter);
        }
        public async Task <PackageConsistencyReport> GetReportAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter)
        {
            var report = new MutableReport
            {
                Context          = context,
                State            = state,
                ProgressReporter = progressReporter,
                Processed        = 0,
                IsConsistent     = true,
            };

            await AddAsync(report, _gallery, (r, s) => r.Gallery = s, "Fetched the gallery report.");
            await AddAsync(report, _v2, (r, s) => r.V2           = s, "Fetched the V2 report.");
            await AddAsync(report, _packagesContainer, (r, s) => r.PackagesContainer       = s, "Fetched the packages container report.");
            await AddAsync(report, _flatContainer, (r, s) => r.FlatContainer               = s, "Fetched the flat container report.");
            await AddAsync(report, _registrationOriginal, (r, s) => r.RegistrationOriginal = s, "Fetched the original registration report.");
            await AddAsync(report, _registrationGzipped, (r, s) => r.RegistrationGzipped   = s, "Fetched the gzipped registration report.");
            await AddAsync(report, _registrationSemVer2, (r, s) => r.RegistrationSemVer2   = s, "Fetched the SemVer 2.0.0 registration report.");
            await AddAsync(report, _search, (r, s) => r.Search         = s, "Fetched the search registration report.");
            await AddAsync(report, _crossCheck, (r, s) => r.CrossCheck = s, "Fetched the cross check report.");

            return(new PackageConsistencyReport(
                       context,
                       report.IsConsistent,
                       report.Gallery,
                       report.V2,
                       report.PackagesContainer,
                       report.FlatContainer,
                       report.RegistrationOriginal,
                       report.RegistrationGzipped,
                       report.RegistrationSemVer2,
                       report.Search,
                       report.CrossCheck));
        }
Пример #21
0
 public Work(IReadOnlyList <IPackageQuery> queries, PackageQueryContext context, PackageConsistencyState state)
 {
     Queries = queries;
     Context = context;
     State   = state;
 }
 public Task <bool> IsMatchAsync(PackageQueryContext context, PackageConsistencyState state)
 {
     return(Task.FromResult(IsMatch(context)));
 }
        public async Task PopulateStateAsync(PackageQueryContext context, PackageConsistencyState state, IProgressReporter progressReporter)
        {
            await _packagesContainer.PopulateStateAsync(context, state, progressReporter);

            await _flatContainer.PopulateStateAsync(context, state, progressReporter);
        }
        private async Task <MutableReport> GetReportAsync(
            PackageQueryContext context,
            PackageConsistencyState state,
            IProgressReporter progressReporter,
            bool allowPartial)
        {
            var baseUrls = await _discoverer.GetUrlsAsync(ServiceIndexTypes.V2Search, _specificInstances);

            var maxTries                 = _specificInstances ? 1 : 3;
            var incrementalProgress      = new IncrementalProgress(progressReporter, baseUrls.Count * 2);
            var baseUrlHasPackageSemVer1 = new Dictionary <string, bool>();
            var baseUrlHasPackageSemVer2 = new Dictionary <string, bool>();
            var baseUrlIsListedSemVer1   = new Dictionary <string, bool>();
            var baseUrlIsListedSemVer2   = new Dictionary <string, bool>();

            var report = new MutableReport
            {
                IsConsistent             = true,
                BaseUrlHasPackageSemVer1 = baseUrlHasPackageSemVer1,
                BaseUrlHasPackageSemVer2 = baseUrlHasPackageSemVer2,
                BaseUrlIsListedSemVer1   = baseUrlIsListedSemVer1,
                BaseUrlIsListedSemVer2   = baseUrlIsListedSemVer2,
            };

            var shouldExistSemVer1    = !context.Package.Deleted && !context.IsSemVer2;
            var shouldBeListedSemVer1 = shouldExistSemVer1 && context.IsListed;
            var shouldExistSemVer2    = !context.Package.Deleted;
            var shouldBeListedSemVer2 = shouldExistSemVer2 && context.IsListed;

            for (var i = 0; i < baseUrls.Count; i++)
            {
                var baseUrl       = baseUrls[i];
                var isLastBaseUrl = i == baseUrls.Count - 1;

                try
                {
                    var packageSemVer1 = await _searchClient.GetPackageOrNullAsync(
                        baseUrl,
                        context.Package.Id,
                        context.Package.Version,
                        semVer2 : false,
                        maxTries : maxTries);

                    var hasPackageSemVer1 = packageSemVer1 != null;
                    var isListedSemVer1   = packageSemVer1?.Listed ?? false;
                    baseUrlHasPackageSemVer1[baseUrl] = hasPackageSemVer1;
                    baseUrlIsListedSemVer1[baseUrl]   = isListedSemVer1;
                    report.IsConsistent &= hasPackageSemVer1 == shouldExistSemVer1 && shouldBeListedSemVer1 == isListedSemVer1;
                    await incrementalProgress.ReportProgressAsync($"Searched for the package on search {baseUrl}, SemVer 1.0.0.");

                    if (allowPartial && !report.IsConsistent)
                    {
                        return(report);
                    }

                    var packageSemVer2 = await _searchClient.GetPackageOrNullAsync(
                        baseUrl,
                        context.Package.Id,
                        context.Package.Version,
                        semVer2 : true,
                        maxTries : maxTries);

                    var hasPackageSemVer2 = packageSemVer2 != null;
                    var isListedSemVer2   = packageSemVer2?.Listed ?? false;
                    baseUrlHasPackageSemVer2[baseUrl] = hasPackageSemVer2;
                    baseUrlIsListedSemVer2[baseUrl]   = isListedSemVer2;
                    report.IsConsistent &= hasPackageSemVer2 == shouldExistSemVer2 && shouldBeListedSemVer2 == isListedSemVer2;
                    await incrementalProgress.ReportProgressAsync($"Searched for the package on search {baseUrl}, SemVer 2.0.0.");

                    if (allowPartial && !report.IsConsistent)
                    {
                        return(report);
                    }
                }
                catch (Exception ex)
                {
                    if (isLastBaseUrl && (!baseUrlHasPackageSemVer1.Any() || !baseUrlHasPackageSemVer2.Any()))
                    {
                        throw;
                    }

                    _logger.LogWarning(ex, "Failed to check the consistency of search base URL {BaseUrl}.", baseUrl);
                }
            }

            return(report);
        }
        public async Task <bool> IsMatchAsync(PackageQueryContext context, PackageConsistencyState state)
        {
            var isConsistent = await _service.IsConsistentAsync(context, state, NullProgressReporter.Instance);

            return(!isConsistent);
        }