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);
        }
예제 #2
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);
        }
        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);
        }
        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);
        }