Ejemplo n.º 1
0
        public bool TryBuild(byte[] bytes, out Package package)
        {
            package = null;
            try
            {
                using (var stream = new MemoryStream(bytes))
                {
                    var zipPackage = new ZipPackage(stream);
                    if (zipPackage.Id.IsTooLargeString() || zipPackage.Version.ToString().IsTooLargeString())
                    {
                        return false;
                    }

                    var now = dateTimeService.UtcNow;
                    package = new Package
                    {
                        Id = zipPackage.Id,
                        Version = zipPackage.Version.ToString(),
                        DisplayTitle = zipPackage.Title.ToStringSafe(),
                        IsAbsoluteLatestVersion = zipPackage.IsAbsoluteLatestVersion,
                        IsLatestVersion = zipPackage.IsLatestVersion,
                        IsPrerelease = zipPackage.IsPrerelease(),
                        PackageHash = cryptoService.Hash(bytes),
                        PackageHashAlgorithm = cryptoService.HashAlgorithmId,
                        PackageSize = bytes.LongLength,
                        Created = now,
                        LastUpdated = now,
                        Published = now,
                        Owners = zipPackage.Owners.Flatten().ToStringSafe(),
                        Authors = zipPackage.Authors.Flatten().ToStringSafe(),
                        Listed = true,
                        RequireLicenseAcceptance = zipPackage.RequireLicenseAcceptance,
                        Language = zipPackage.Language.ToStringSafe(),
                        DevelopmentDependency = zipPackage.DevelopmentDependency,
                        Title = zipPackage.Title.ToStringSafe(),
                        Tags = zipPackage.Tags.ToStringSafe(),
                        Copyright = zipPackage.Copyright.ToStringSafe(),
                        Dependencies = "".ToStringSafe(),
                        IconUrl = zipPackage.IconUrl.ToStringSafe(),
                        LicenseUrl = zipPackage.LicenseUrl.ToStringSafe(),
                        ProjectUrl = zipPackage.ProjectUrl.ToStringSafe(),
                        Description = zipPackage.Description.ToStringSafe(),
                        ReleaseNotes = zipPackage.ReleaseNotes.ToStringSafe(),
                        Summary = zipPackage.Summary.ToStringSafe(),
                        DownloadCount = 0,
                        Score = 0f,
                        VersionDownloadCount = 0,
                        BlobId = guidGenerator.NewGuid()
                    };
                    return true;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
Ejemplo n.º 2
0
        public void Add(Package package)
        {
            foreach (var p in context.Packages.Where(x => x.Id == package.Id))
            {
                p.IsLatestVersion = false;
                p.IsAbsoluteLatestVersion = false;
            }

            var latestPackage = context.Packages.Where(x => x.Id == package.Id).ToArray()
                .Concat(new[] {package})
                .OrderBy(x => new SemanticVersion(x.Version))
                .First();

            latestPackage.IsLatestVersion = true;
            latestPackage.IsAbsoluteLatestVersion = true;

            context.Packages.Add(package);
            context.SaveChanges();
        }
Ejemplo n.º 3
0
 private static string GetFilename(Package package)
 {
     return string.Format("{0}.{1}{2}", package.Id, package.Version, Constants.PackageExtension);
 }
Ejemplo n.º 4
0
 private static string GetBlobScope(Package package)
 {
     return Path.Combine(package.Id, package.Version);
 }