Пример #1
0
        public ActionResult Explore(string id, string version)
        {
            if (!StrictPackageIdValidator.IsValid(id) ||
                !NuGetVersion.TryParse(version, out var parsedVersion))
            {
                return(RedirectToAction(nameof(Index)));
            }

            return(View(nameof(Index), new ExploreViewModel(id, version)));
        }
Пример #2
0
        private async Task StartInternalAsync(string id, string version)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                await InvokeErrorAsync("You must provide a package ID.");

                return;
            }

            if (!StrictPackageIdValidator.IsValid(id))
            {
                await InvokeErrorAsync("The ID you provided is invalid.");

                return;
            }

            if (string.IsNullOrWhiteSpace(version))
            {
                await InvokeErrorAsync("You must provide a package version.");

                return;
            }

            if (!NuGetVersion.TryParse(version, out var parsedVersion))
            {
                await InvokeErrorAsync("The version you provided is invalid.");

                return;
            }

            await InvokeProgressAsync(0, $"Initializing package report for {id} {version}.");

            var state   = new PackageConsistencyState();
            var context = await _packageQueryContextBuilder.GetPackageQueryContextFromGalleryAsync(id, version, state);

            var    packageDeletedStatus = state.Gallery.PackageState.PackageDeletedStatus;
            var    isAvailable          = packageDeletedStatus == PackageDeletedStatus.NotDeleted;
            string availability;

            switch (packageDeletedStatus)
            {
            case PackageDeletedStatus.NotDeleted:
                availability = "is available";
                break;

            case PackageDeletedStatus.SoftDeleted:
                availability = "was soft deleted";
                break;

            case PackageDeletedStatus.Unknown:
                availability = "was hard deleted or never published";
                break;

            default:
                throw new NotImplementedException(
                          $"The package deleted status {packageDeletedStatus} is not supported.");
            }

            await InvokeProgressAsync(
                0,
                $"{context.Package.Id} {context.Package.Version} {availability}" +
                $"{(isAvailable && context.IsSemVer2 ? " and is SemVer 2.0.0" : string.Empty)}. " +
                $"The consistency report will now be generated.");

            var report = await _packageConsistencyService.GetReportAsync(context, state, new ProgressReporter(this));

            await InvokeCompleteAsync(report);
        }