public VerifyPackageRequest(PackageMetadata packageMetadata, IEnumerable <User> possibleOwners)
        {
            Id                   = packageMetadata.Id;
            Version              = packageMetadata.Version.ToFullStringSafe();
            OriginalVersion      = packageMetadata.Version.OriginalVersion;
            HasSemVer2Version    = packageMetadata.Version.IsSemVer2;
            HasSemVer2Dependency = packageMetadata.GetDependencyGroups().Any(d => d.Packages.Any(
                                                                                 p => (p.VersionRange.HasUpperBound && p.VersionRange.MaxVersion.IsSemVer2) ||
                                                                                 (p.VersionRange.HasLowerBound && p.VersionRange.MinVersion.IsSemVer2)));

            // Verifiable fields
            Language = packageMetadata.Language;
            MinClientVersionDisplay  = packageMetadata.MinClientVersion.ToFullStringSafe();
            FrameworkReferenceGroups = packageMetadata.GetFrameworkReferenceGroups();
            Dependencies             = new DependencySetsViewModel(packageMetadata.GetDependencyGroups().AsPackageDependencyEnumerable());
            DevelopmentDependency    = packageMetadata.GetValueFromMetadata("developmentDependency");
            Authors      = packageMetadata.Authors.Flatten();
            Copyright    = packageMetadata.Copyright;
            Description  = packageMetadata.Description;
            IconUrl      = packageMetadata.IconUrl.ToEncodedUrlStringOrNull();
            LicenseUrl   = packageMetadata.LicenseUrl.ToEncodedUrlStringOrNull();
            ProjectUrl   = packageMetadata.ProjectUrl.ToEncodedUrlStringOrNull();
            ReleaseNotes = packageMetadata.ReleaseNotes;
            RequiresLicenseAcceptance = packageMetadata.RequireLicenseAcceptance;
            Summary = packageMetadata.Summary;
            Tags    = PackageHelper.ParseTags(packageMetadata.Tags);
            Title   = packageMetadata.Title;

            // Editable server-state
            Listed = true;
            Edit   = new EditPackageVersionReadMeRequest();

            PossibleOwners = possibleOwners.Select(u => u.Username).ToList();
        }
Example #2
0
        public virtual async Task <ActionResult> VerifyPackage()
        {
            var currentUser = GetCurrentUser();

            PackageMetadata packageMetadata;

            using (Stream uploadFile = await _uploadFileService.GetUploadFileAsync(currentUser.Key))
            {
                if (uploadFile == null)
                {
                    return(RedirectToRoute(RouteName.UploadPackage));
                }

                var package = await SafeCreatePackage(currentUser, uploadFile);

                if (package == null)
                {
                    return(Redirect(Url.UploadPackage()));
                }

                try
                {
                    packageMetadata = PackageMetadata.FromNuspecReader(
                        package.GetNuspecReader());
                }
                catch (Exception ex)
                {
                    TempData["Message"] = ex.GetUserSafeMessage();
                    return(Redirect(Url.UploadPackage()));
                }
            }

            var model = new VerifyPackageRequest
            {
                Id         = packageMetadata.Id,
                Version    = packageMetadata.Version.ToNormalizedStringSafe(),
                LicenseUrl = packageMetadata.LicenseUrl.ToEncodedUrlStringOrNull(),
                Listed     = true,
                Edit       = new EditPackageVersionRequest
                {
                    Authors      = packageMetadata.Authors.Flatten(),
                    Copyright    = packageMetadata.Copyright,
                    Description  = packageMetadata.Description,
                    IconUrl      = packageMetadata.IconUrl.ToEncodedUrlStringOrNull(),
                    LicenseUrl   = packageMetadata.LicenseUrl.ToEncodedUrlStringOrNull(),
                    ProjectUrl   = packageMetadata.ProjectUrl.ToEncodedUrlStringOrNull(),
                    ReleaseNotes = packageMetadata.ReleaseNotes,
                    RequiresLicenseAcceptance = packageMetadata.RequireLicenseAcceptance,
                    Summary      = packageMetadata.Summary,
                    Tags         = PackageHelper.ParseTags(packageMetadata.Tags),
                    VersionTitle = packageMetadata.Title,
                }
            };

            return(View(model));
        }
        public virtual async Task <ActionResult> VerifyPackage()
        {
            var currentUser = GetCurrentUser();

            IPackageMetadata packageMetadata;

            using (Stream uploadFile = await _uploadFileService.GetUploadFileAsync(currentUser.Key))
            {
                if (uploadFile == null)
                {
                    return(RedirectToRoute(RouteName.UploadPackage));
                }

                try
                {
                    using (INupkg package = CreatePackage(uploadFile))
                    {
                        packageMetadata = package.Metadata;
                    }
                }
                catch (InvalidDataException e)
                {
                    // Log the exception in case we get support requests about it.
                    QuietLog.LogHandledException(e);

                    return(View("UnverifiablePackage"));
                }
            }

            var model = new VerifyPackageRequest
            {
                Id         = packageMetadata.Id,
                Version    = packageMetadata.Version.ToNormalizedStringSafe(),
                LicenseUrl = packageMetadata.LicenseUrl.ToEncodedUrlStringOrNull(),
                Listed     = true,
                Edit       = new EditPackageVersionRequest
                {
                    Authors      = packageMetadata.Authors.Flatten(),
                    Copyright    = packageMetadata.Copyright,
                    Description  = packageMetadata.Description,
                    IconUrl      = packageMetadata.IconUrl.ToEncodedUrlStringOrNull(),
                    LicenseUrl   = packageMetadata.LicenseUrl.ToEncodedUrlStringOrNull(),
                    ProjectUrl   = packageMetadata.ProjectUrl.ToEncodedUrlStringOrNull(),
                    ReleaseNotes = packageMetadata.ReleaseNotes,
                    RequiresLicenseAcceptance = packageMetadata.RequireLicenseAcceptance,
                    Summary      = packageMetadata.Summary,
                    Tags         = PackageHelper.ParseTags(packageMetadata.Tags),
                    VersionTitle = packageMetadata.Title,
                }
            };

            return(View(model));
        }
 public EditPackageVersionRequest(PackageMetadata packageMetadata)
 {
     Authors      = packageMetadata.Authors.Flatten();
     Copyright    = packageMetadata.Copyright;
     Description  = packageMetadata.Description;
     IconUrl      = packageMetadata.IconUrl.ToEncodedUrlStringOrNull();
     LicenseUrl   = packageMetadata.LicenseUrl.ToEncodedUrlStringOrNull();
     ProjectUrl   = packageMetadata.ProjectUrl.ToEncodedUrlStringOrNull();
     ReleaseNotes = packageMetadata.ReleaseNotes;
     RequiresLicenseAcceptance = packageMetadata.RequireLicenseAcceptance;
     Summary      = packageMetadata.Summary;
     Tags         = PackageHelper.ParseTags(packageMetadata.Tags);
     VersionTitle = packageMetadata.Title;
 }
Example #5
0
        public virtual async Task <ActionResult> VerifyPackage()
        {
            var currentUser = _userService.FindByUsername(GetIdentity().Name);

            IPackageMetadata packageMetadata;

            using (Stream uploadFile = await _uploadFileService.GetUploadFileAsync(currentUser.Key))
            {
                if (uploadFile == null)
                {
                    return(RedirectToRoute(RouteName.UploadPackage));
                }

                try
                {
                    using (INupkg package = CreatePackage(uploadFile))
                    {
                        packageMetadata = package.Metadata;
                    }
                }
                catch (InvalidDataException e)
                {
                    // Log the exception in case we get support requests about it.
                    QuietLog.LogHandledException(e);

                    return(View(Views.UnverifiablePackage));
                }
            }

            return(View(
                       new VerifyPackageViewModel
            {
                Id = packageMetadata.Id,
                Version = packageMetadata.Version.ToStringSafe(),
                Title = packageMetadata.Title,
                Summary = packageMetadata.Summary,
                Description = packageMetadata.Description,
                RequiresLicenseAcceptance = packageMetadata.RequireLicenseAcceptance,
                LicenseUrl = packageMetadata.LicenseUrl.ToStringSafe(),
                Tags = PackageHelper.ParseTags(packageMetadata.Tags),
                ProjectUrl = packageMetadata.ProjectUrl.ToStringSafe(),
                Authors = packageMetadata.Authors.Flatten(),
                Listed = true
            }));
        }
Example #6
0
        public VerifyPackageRequest(PackageMetadata packageMetadata, IEnumerable <User> possibleOwners, PackageRegistration existingPackageRegistration)
        {
            Id                   = packageMetadata.Id;
            Version              = packageMetadata.Version.ToFullStringSafe();
            OriginalVersion      = packageMetadata.Version.OriginalVersion;
            HasSemVer2Version    = packageMetadata.Version.IsSemVer2;
            HasSemVer2Dependency = packageMetadata.GetDependencyGroups().Any(d => d.Packages.Any(
                                                                                 p => (p.VersionRange.HasUpperBound && p.VersionRange.MaxVersion.IsSemVer2) ||
                                                                                 (p.VersionRange.HasLowerBound && p.VersionRange.MinVersion.IsSemVer2)));

            // Verifiable fields
            Language = packageMetadata.Language;
            MinClientVersionDisplay  = packageMetadata.MinClientVersion.ToFullStringSafe();
            FrameworkReferenceGroups = packageMetadata.GetFrameworkReferenceGroups();
            Dependencies             = new DependencySetsViewModel(packageMetadata.GetDependencyGroups().AsPackageDependencyEnumerable());
            DevelopmentDependency    = packageMetadata.DevelopmentDependency;
            Authors                   = packageMetadata.Authors.Flatten();
            Copyright                 = packageMetadata.Copyright;
            Description               = packageMetadata.Description;
            IconUrl                   = packageMetadata.IconUrl.ToEncodedUrlStringOrNull();
            LicenseUrl                = packageMetadata.LicenseUrl.ToEncodedUrlStringOrNull();
            LicenseExpression         = packageMetadata.LicenseMetadata?.Type == LicenseType.Expression ? packageMetadata.LicenseMetadata?.License : null;
            ProjectUrl                = packageMetadata.ProjectUrl.ToEncodedUrlStringOrNull();
            RepositoryUrl             = packageMetadata.RepositoryUrl.ToEncodedUrlStringOrNull();
            RepositoryType            = packageMetadata.RepositoryType;
            ReleaseNotes              = packageMetadata.ReleaseNotes;
            RequiresLicenseAcceptance = packageMetadata.RequireLicenseAcceptance;
            Summary                   = packageMetadata.Summary;
            Tags    = PackageHelper.ParseTags(packageMetadata.Tags);
            Title   = packageMetadata.Title;
            IsNewId = existingPackageRegistration == null;
            if (!IsNewId)
            {
                ExistingOwners = string.Join(", ", ParseUserList(existingPackageRegistration.Owners));
            }

            // Editable server-state
            Listed         = true;
            Edit           = new EditPackageVersionReadMeRequest();
            PossibleOwners = ParseUserList(possibleOwners);
        }
Example #7
0
        private Package CreatePackageFromNuGetPackage(PackageRegistration packageRegistration, INupkg nugetPackage, User user)
        {
            var package = packageRegistration.Packages.SingleOrDefault(pv => pv.Version == nugetPackage.Metadata.Version.ToString());

            if (package != null)
            {
                throw new EntityException(
                          "A package with identifier '{0}' and version '{1}' already exists.", packageRegistration.Id, package.Version);
            }

            var now = DateTime.UtcNow;
            var packageFileStream = nugetPackage.GetStream();

            package = new Package
            {
                // Version must always be the exact string from the nuspec, which ToString will return to us.
                // However, we do also store a normalized copy for looking up later.
                Version           = nugetPackage.Metadata.Version.ToString(),
                NormalizedVersion = nugetPackage.Metadata.Version.ToNormalizedString(),

                Description               = nugetPackage.Metadata.Description,
                ReleaseNotes              = nugetPackage.Metadata.ReleaseNotes,
                HashAlgorithm             = Constants.Sha512HashAlgorithmId,
                Hash                      = Crypto.GenerateHash(packageFileStream.ReadAllBytes()),
                PackageFileSize           = packageFileStream.Length,
                Created                   = now,
                Language                  = nugetPackage.Metadata.Language,
                LastUpdated               = now,
                Published                 = now,
                Copyright                 = nugetPackage.Metadata.Copyright,
                FlattenedAuthors          = nugetPackage.Metadata.Authors.Flatten(),
                IsPrerelease              = !nugetPackage.Metadata.IsReleaseVersion(),
                Listed                    = true,
                PackageRegistration       = packageRegistration,
                RequiresLicenseAcceptance = nugetPackage.Metadata.RequireLicenseAcceptance,
                Summary                   = nugetPackage.Metadata.Summary,
                Tags                      = PackageHelper.ParseTags(nugetPackage.Metadata.Tags),
                Title                     = nugetPackage.Metadata.Title,
                User                      = user,
            };

            package.IconUrl          = nugetPackage.Metadata.IconUrl.ToEncodedUrlStringOrNull();
            package.LicenseUrl       = nugetPackage.Metadata.LicenseUrl.ToEncodedUrlStringOrNull();
            package.ProjectUrl       = nugetPackage.Metadata.ProjectUrl.ToEncodedUrlStringOrNull();
            package.MinClientVersion = nugetPackage.Metadata.MinClientVersion.ToStringOrNull();

#pragma warning disable 618 // TODO: remove Package.Authors completely once prodution services definitely no longer need it
            foreach (var author in nugetPackage.Metadata.Authors)
            {
                package.Authors.Add(new PackageAuthor {
                    Name = author
                });
            }
#pragma warning restore 618

            var supportedFrameworks = GetSupportedFrameworks(nugetPackage).Select(fn => fn.ToShortNameOrNull()).ToArray();
            if (!supportedFrameworks.AnySafe(sf => sf == null))
            {
                foreach (var supportedFramework in supportedFrameworks)
                {
                    package.SupportedFrameworks.Add(new PackageFramework {
                        TargetFramework = supportedFramework
                    });
                }
            }

            foreach (var dependencySet in nugetPackage.Metadata.DependencySets)
            {
                if (dependencySet.Dependencies.Count == 0)
                {
                    package.Dependencies.Add(
                        new PackageDependency
                    {
                        Id              = null,
                        VersionSpec     = null,
                        TargetFramework = dependencySet.TargetFramework.ToShortNameOrNull()
                    });
                }
                else
                {
                    foreach (var dependency in dependencySet.Dependencies.Select(d => new { d.Id, d.VersionSpec, dependencySet.TargetFramework }))
                    {
                        package.Dependencies.Add(
                            new PackageDependency
                        {
                            Id              = dependency.Id,
                            VersionSpec     = dependency.VersionSpec == null ? null : dependency.VersionSpec.ToString(),
                            TargetFramework = dependency.TargetFramework.ToShortNameOrNull()
                        });
                    }
                }
            }

            package.FlattenedDependencies = package.Dependencies.Flatten();

            return(package);
        }
Example #8
0
        public virtual Package EnrichPackageFromNuGetPackage(
            Package package,
            PackageArchiveReader packageArchive,
            PackageMetadata packageMetadata,
            PackageStreamMetadata packageStreamMetadata,
            User user)
        {
            // Version must always be the exact string from the nuspec, which OriginalVersion will return to us.
            // However, we do also store a normalized copy for looking up later.
            package.Version           = packageMetadata.Version.OriginalVersion;
            package.NormalizedVersion = packageMetadata.Version.ToNormalizedString();

            package.Description               = packageMetadata.Description;
            package.ReleaseNotes              = packageMetadata.ReleaseNotes;
            package.HashAlgorithm             = packageStreamMetadata.HashAlgorithm;
            package.Hash                      = packageStreamMetadata.Hash;
            package.PackageFileSize           = packageStreamMetadata.Size;
            package.Language                  = packageMetadata.Language;
            package.Copyright                 = packageMetadata.Copyright;
            package.FlattenedAuthors          = packageMetadata.Authors.Flatten();
            package.IsPrerelease              = packageMetadata.Version.IsPrerelease;
            package.Listed                    = true;
            package.RequiresLicenseAcceptance = packageMetadata.RequireLicenseAcceptance;
            package.Summary                   = packageMetadata.Summary;
            package.Tags                      = PackageHelper.ParseTags(packageMetadata.Tags);
            package.Title                     = packageMetadata.Title;
            package.User                      = user;

            package.IconUrl          = packageMetadata.IconUrl.ToEncodedUrlStringOrNull();
            package.LicenseUrl       = packageMetadata.LicenseUrl.ToEncodedUrlStringOrNull();
            package.ProjectUrl       = packageMetadata.ProjectUrl.ToEncodedUrlStringOrNull();
            package.MinClientVersion = packageMetadata.MinClientVersion.ToStringOrNull();

#pragma warning disable 618 // TODO: remove Package.Authors completely once production services definitely no longer need it
            foreach (var author in packageMetadata.Authors)
            {
                package.Authors.Add(new PackageAuthor {
                    Name = author
                });
            }
#pragma warning restore 618

            var supportedFrameworks = GetSupportedFrameworks(packageArchive)
                                      .ToArray();

            if (!supportedFrameworks.Any(fx => fx != null && fx.IsAny))
            {
                var supportedFrameworkNames = supportedFrameworks
                                              .Select(fn => fn.ToShortNameOrNull())
                                              .Where(fn => fn != null)
                                              .ToArray();

                ValidateSupportedFrameworks(supportedFrameworkNames);

                foreach (var supportedFramework in supportedFrameworkNames)
                {
                    package.SupportedFrameworks.Add(new PackageFramework {
                        TargetFramework = supportedFramework
                    });
                }
            }

            package.Dependencies = packageMetadata
                                   .GetDependencyGroups()
                                   .AsPackageDependencyEnumerable()
                                   .ToList();

            package.PackageTypes = packageMetadata
                                   .GetPackageTypes()
                                   .AsPackageTypeEnumerable()
                                   .ToList();

            package.FlattenedDependencies = package.Dependencies.Flatten();

            package.FlattenedPackageTypes = package.PackageTypes.Flatten();

            // Identify the SemVerLevelKey using the original package version string and package dependencies
            package.SemVerLevelKey = SemVerLevelKey.ForPackage(packageMetadata.Version, package.Dependencies);

            return(package);
        }
Example #9
0
        private Package CreatePackageFromNuGetPackage(PackageRegistration packageRegistration, PackageArchiveReader nugetPackage, PackageMetadata packageMetadata, PackageStreamMetadata packageStreamMetadata, User user)
        {
            var package = packageRegistration.Packages.SingleOrDefault(pv => pv.Version == packageMetadata.Version.ToString());

            if (package != null)
            {
                throw new EntityException(
                          "A package with identifier '{0}' and version '{1}' already exists.", packageRegistration.Id, package.Version);
            }

            package = new Package
            {
                // Version must always be the exact string from the nuspec, which ToString will return to us.
                // However, we do also store a normalized copy for looking up later.
                Version           = packageMetadata.Version.ToString(),
                NormalizedVersion = packageMetadata.Version.ToNormalizedString(),

                Description               = packageMetadata.Description,
                ReleaseNotes              = packageMetadata.ReleaseNotes,
                HashAlgorithm             = packageStreamMetadata.HashAlgorithm,
                Hash                      = packageStreamMetadata.Hash,
                PackageFileSize           = packageStreamMetadata.Size,
                Language                  = packageMetadata.Language,
                Copyright                 = packageMetadata.Copyright,
                FlattenedAuthors          = packageMetadata.Authors.Flatten(),
                IsPrerelease              = packageMetadata.Version.IsPrerelease,
                Listed                    = true,
                PackageRegistration       = packageRegistration,
                RequiresLicenseAcceptance = packageMetadata.RequireLicenseAcceptance,
                Summary                   = packageMetadata.Summary,
                Tags                      = PackageHelper.ParseTags(packageMetadata.Tags),
                Title                     = packageMetadata.Title,
                User                      = user,
            };

            package.IconUrl          = packageMetadata.IconUrl.ToEncodedUrlStringOrNull();
            package.LicenseUrl       = packageMetadata.LicenseUrl.ToEncodedUrlStringOrNull();
            package.ProjectUrl       = packageMetadata.ProjectUrl.ToEncodedUrlStringOrNull();
            package.MinClientVersion = packageMetadata.MinClientVersion.ToStringOrNull();

#pragma warning disable 618 // TODO: remove Package.Authors completely once prodution services definitely no longer need it
            foreach (var author in packageMetadata.Authors)
            {
                package.Authors.Add(new PackageAuthor {
                    Name = author
                });
            }
#pragma warning restore 618

            var supportedFrameworks = GetSupportedFrameworks(nugetPackage).Select(fn => fn.ToShortNameOrNull()).ToArray();
            if (!supportedFrameworks.AnySafe(sf => sf == null))
            {
                ValidateSupportedFrameworks(supportedFrameworks);

                foreach (var supportedFramework in supportedFrameworks)
                {
                    package.SupportedFrameworks.Add(new PackageFramework {
                        TargetFramework = supportedFramework
                    });
                }
            }

            package.Dependencies = packageMetadata
                                   .GetDependencyGroups()
                                   .AsPackageDependencyEnumerable()
                                   .ToList();
            package.FlattenedDependencies = package.Dependencies.Flatten();

            return(package);
        }
Example #10
0
        private Package CreatePackageFromNuGetPackage(PackageRegistration packageRegistration, INupkg nugetPackage)
        {
            var package = packageRegistration.Packages.SingleOrDefault(pv => pv.Version == nugetPackage.Metadata.Version.ToString());

            if (package != null)
            {
                throw new EntityException(
                          "A package with identifier '{0}' and version '{1}' already exists.", packageRegistration.Id, package.Version);
            }

            var now = DateTime.UtcNow;
            var packageFileStream = nugetPackage.GetStream();

            package = new Package
            {
                Version      = nugetPackage.Metadata.Version.ToString(),
                Description  = nugetPackage.Metadata.Description,
                ReleaseNotes = nugetPackage.Metadata.ReleaseNotes,
                RequiresLicenseAcceptance = nugetPackage.Metadata.RequireLicenseAcceptance,
                HashAlgorithm             = Constants.Sha512HashAlgorithmId,
                Hash                = Crypto.GenerateHash(packageFileStream.ReadAllBytes()),
                PackageFileSize     = packageFileStream.Length,
                Created             = now,
                Language            = nugetPackage.Metadata.Language,
                LastUpdated         = now,
                Published           = now,
                Copyright           = nugetPackage.Metadata.Copyright,
                IsPrerelease        = !nugetPackage.Metadata.IsReleaseVersion(),
                Listed              = true,
                PackageRegistration = packageRegistration,
                Summary             = nugetPackage.Metadata.Summary,
                Tags                = PackageHelper.ParseTags(nugetPackage.Metadata.Tags),
                Title               = nugetPackage.Metadata.Title,
            };

            package.IconUrl          = nugetPackage.Metadata.IconUrl.ToStringOrNull();
            package.LicenseUrl       = nugetPackage.Metadata.LicenseUrl.ToStringOrNull();
            package.ProjectUrl       = nugetPackage.Metadata.ProjectUrl.ToStringOrNull();
            package.MinClientVersion = nugetPackage.Metadata.MinClientVersion.ToStringOrNull();

            foreach (var author in nugetPackage.Metadata.Authors)
            {
                package.Authors.Add(new PackageAuthor {
                    Name = author
                });
            }

            var supportedFrameworks = GetSupportedFrameworks(nugetPackage).Select(fn => fn.ToShortNameOrNull()).ToArray();

            if (!supportedFrameworks.AnySafe(sf => sf == null))
            {
                foreach (var supportedFramework in supportedFrameworks)
                {
                    package.SupportedFrameworks.Add(new PackageFramework {
                        TargetFramework = supportedFramework
                    });
                }
            }

            foreach (var dependencySet in nugetPackage.Metadata.DependencySets)
            {
                if (dependencySet.Dependencies.Count == 0)
                {
                    package.Dependencies.Add(
                        new PackageDependency
                    {
                        Id              = null,
                        VersionSpec     = null,
                        TargetFramework = dependencySet.TargetFramework.ToShortNameOrNull()
                    });
                }
                else
                {
                    foreach (var dependency in dependencySet.Dependencies.Select(d => new { d.Id, d.VersionSpec, dependencySet.TargetFramework }))
                    {
                        package.Dependencies.Add(
                            new PackageDependency
                        {
                            Id              = dependency.Id,
                            VersionSpec     = dependency.VersionSpec == null ? null : dependency.VersionSpec.ToString(),
                            TargetFramework = dependency.TargetFramework.ToShortNameOrNull()
                        });
                    }
                }
            }

            package.FlattenedAuthors      = package.Authors.Flatten();
            package.FlattenedDependencies = package.Dependencies.Flatten();

            return(package);
        }