public static Package ConvertToPackage(Version version)
        {
            var metadataWrapper = new MetadataWrapper(version.Metadata);

            var package = new Package
            {
                Id = version.Project,
                Version = version.Name,


                Title = metadataWrapper["Title"],
                Authors = metadataWrapper["Authors"],
                Copyright = metadataWrapper["Copyrights"],
                Description = metadataWrapper["Description"],
                IconUrl = metadataWrapper["IconUrl"],
                LicenseUrl = metadataWrapper["LicenseUrl"],
                ProjectUrl = metadataWrapper["ProjectUrl"],
                ReleaseNotes = metadataWrapper["RequireLicenseAcceptance"],
                RequireLicenseAcceptance = (metadataWrapper["LicenseUrl"] ?? "").Equals("true", StringComparison.OrdinalIgnoreCase),
                Summary = metadataWrapper["Summary"],
                Tags = metadataWrapper["Tags"],
                Dependencies = metadataWrapper["Dependencies"],
                PackageHash = metadataWrapper["PackageHash"] ?? version.PackageHash,
                PackageHashAlgorithm = metadataWrapper["PackageHashAlgorithm"] ?? "SHA512",
                PackageSize = int.Parse(metadataWrapper["PackageSize"] ?? "-1"),
                DownloadCount = int.Parse(metadataWrapper["DownloadCount"] ?? "0"),
                LastUpdated = DateTime.UtcNow,
                Published = DateTime.UtcNow,
                IsLatestVersion = (metadataWrapper["IsLatestVersion"] ?? "").Equals("true", StringComparison.OrdinalIgnoreCase),
                IsAbsoluteLatestVersion = (metadataWrapper["IsAbsoluteLatestName"] ?? "").Equals("true", StringComparison.OrdinalIgnoreCase),
            };

            return package;
        }
        public string Download(Caller caller, string company, string repository, string projectName, string versionName, string contentType)
        {
            var container = new Version { Company = company, Repository = repository, Project = projectName, Name = versionName };

            using (var session = backendFactory.Create(caller))
                return session.GetPackageLink(ref container, contentType);
        }
Example #3
0
        public static Package ConvertToPackage(Version version)
        {
            var metadataWrapper = new MetadataWrapper(version.Metadata);

            var package = new Package
            {
                Id      = version.Project,
                Version = version.Name,


                Title                    = metadataWrapper["Title"],
                Authors                  = metadataWrapper["Authors"],
                Copyright                = metadataWrapper["Copyrights"],
                Description              = metadataWrapper["Description"],
                IconUrl                  = metadataWrapper["IconUrl"],
                LicenseUrl               = metadataWrapper["LicenseUrl"],
                ProjectUrl               = metadataWrapper["ProjectUrl"],
                ReleaseNotes             = metadataWrapper["RequireLicenseAcceptance"],
                RequireLicenseAcceptance = (metadataWrapper["LicenseUrl"] ?? "").Equals("true", StringComparison.OrdinalIgnoreCase),
                Summary                  = metadataWrapper["Summary"],
                Tags                    = metadataWrapper["Tags"],
                Dependencies            = metadataWrapper["Dependencies"],
                PackageHash             = metadataWrapper["PackageHash"] ?? version.PackageHash,
                PackageHashAlgorithm    = metadataWrapper["PackageHashAlgorithm"] ?? "SHA512",
                PackageSize             = int.Parse(metadataWrapper["PackageSize"] ?? "-1"),
                DownloadCount           = int.Parse(metadataWrapper["DownloadCount"] ?? "0"),
                LastUpdated             = DateTime.UtcNow,
                Published               = DateTime.UtcNow,
                IsLatestVersion         = (metadataWrapper["IsLatestVersion"] ?? "").Equals("true", StringComparison.OrdinalIgnoreCase),
                IsAbsoluteLatestVersion = (metadataWrapper["IsAbsoluteLatestName"] ?? "").Equals("true", StringComparison.OrdinalIgnoreCase),
            };

            return(package);
        }
        public string Download(Caller caller, string company, string repository, string projectName, string versionName, string contentType)
        {
            var container = new Version {
                Company = company, Repository = repository, Project = projectName, Name = versionName
            };

            using (var session = backendFactory.Create(caller))
                return(session.GetPackageLink(ref container, contentType));
        }
 private string GetPackagePathFromVersion(Version version, string packageFormat)
 {
     // ReSharper disable ReplaceWithSingleCallToFirstOrDefault
     return GetPackageNameCandidates(version, packageFormat)
         .Select(name => Path.Combine(version.Project, version.Name, name))
         .Where(candidate => File.Exists(Path.Combine(configuration.DataPath, candidate)))
         .FirstOrDefault();
     // ReSharper restore ReplaceWithSingleCallToFirstOrDefault
 }
 private string GetPackagePathFromVersion(Version version, string packageFormat)
 {
     // ReSharper disable ReplaceWithSingleCallToFirstOrDefault
     return(GetPackageNameCandidates(version, packageFormat)
            .Select(name => Path.Combine(version.Project, version.Name, name))
            .Where(candidate => File.Exists(Path.Combine(configuration.DataPath, candidate)))
            .FirstOrDefault());
     // ReSharper restore ReplaceWithSingleCallToFirstOrDefault
 }
        private IEnumerable<string> GetPackageNameCandidates(Version version, string packageFormat)
        {
            if (packageFormat != null)
                return new[] { GetPackageName(packageFormat, version.Project, version.Name) };

            return new[]
                       {
                           GetPackageName("NuGet", version.Project, version.Name),
                           GetPackageName("OpenWrap", version.Project, version.Name)
                       };
        }
        private IEnumerable <string> GetPackageNameCandidates(Version version, string packageFormat)
        {
            if (packageFormat != null)
            {
                return new[] { GetPackageName(packageFormat, version.Project, version.Name) }
            }
            ;

            return(new[]
            {
                GetPackageName("NuGet", version.Project, version.Name)
            });
        }
 public void CreateVersion(Version version)
 {
 }
 public Compilation[] GetCompilationList(ref Version version)
 {
     throw new NotImplementedException();
 }
 public void SetVersionHidden(ref Version version, bool hidden)
 {
     throw new NotImplementedException();
 }
 public string GetPackageLink(ref Version version, string contentType)
 {
     return(configuration.RemotePath + '/' + GetPackagePathFromVersion(version, null).Replace(Path.DirectorySeparatorChar, '/'));
 }
 public void CreateVersion(Version version)
 {
 }
 public string GetPackageLink(ref Version version, string contentType)
 {
     return configuration.RemotePath + '/' + GetPackagePathFromVersion(version, null).Replace(Path.DirectorySeparatorChar, '/');
 }
 public void SetVersionHidden(ref Version version, bool hidden)
 {
     throw new NotImplementedException();
 }
 public Compilation[] GetCompilationList(ref Version version)
 {
     throw new NotImplementedException();
 }
        public static Version ConvertToVersion(Stream stream)
        {
            var package = new ZipPackage(stream);

            var version = new Version
            {
                Project = package.Id,
                Name = package.Version.ToString(),
            };

            var metadata = new List<MetadataEntry>();
            var metadataWrapper = new MetadataWrapper(metadata);

            if (!package.Authors.IsEmpty())
                metadataWrapper["Authors"] = String.Join(",", package.Authors);

            if (!string.IsNullOrEmpty(package.Copyright))
                metadataWrapper["Copyrights"] = package.Copyright;

            if (!string.IsNullOrEmpty(package.Description))
                metadataWrapper["Description"] = package.Description;

            if (package.IconUrl != null)
                metadataWrapper["IconUrl"] = package.IconUrl.ToString();

            if (!string.IsNullOrEmpty(package.Language))
                metadataWrapper["Language"] = package.Language;

            if (package.LicenseUrl != null)
                metadataWrapper["LicenseUrl"] = package.LicenseUrl.ToString();

            if (!package.Owners.IsEmpty())
                metadataWrapper["Owners"] = String.Join(",", package.Owners);

            if (package.ProjectUrl != null)
                metadataWrapper["ProjectUrl"] = package.ProjectUrl.ToString();

            if (!string.IsNullOrEmpty(package.ReleaseNotes))
                metadataWrapper["ReleaseNotes"] = package.ReleaseNotes;

            metadataWrapper["RequireLicenseAcceptance"] = package.RequireLicenseAcceptance.ToString();

            if (!string.IsNullOrEmpty(package.Summary))
                metadataWrapper["Summary"] = package.Summary;

            if (!string.IsNullOrEmpty(package.Tags))
                metadataWrapper["Tags"] = package.Tags;

            if (package.DependencySets.SelectMany(ConvertDependencySetToStrings).Any())
                metadataWrapper["Dependencies"] = String.Join("|", package.DependencySets.SelectMany(ConvertDependencySetToStrings));

            if (!string.IsNullOrEmpty(package.Title))
                metadataWrapper["Title"] = package.Title;

            metadataWrapper["PackageSize"] = stream.Length.ToString();
            metadataWrapper["PackageHashAlgorithm"] = "SHA512";

            stream.Seek(0, SeekOrigin.Begin);
            using (var hasher = new SHA512Managed())
                metadataWrapper["PackageHash"] = Convert.ToBase64String(hasher.ComputeHash(stream));

            metadataWrapper["DownloadCount"] = "000000";
            metadataWrapper["CreatedDate"] = DateTime.UtcNow.ToString("s");

            version.Metadata = metadata.ToArray();

            return version;
        }
Example #18
0
        public static Version ConvertToVersion(Stream stream)
        {
            long   length   = stream.Length;
            string hashCode = string.Empty;

            stream.Seek(0, SeekOrigin.Begin);
            using (var hasher = new SHA512Managed())
                hashCode = Convert.ToBase64String(hasher.ComputeHash(stream));

            stream.Seek(0, SeekOrigin.Begin);

            var package = new ZipPackage(stream);

            var version = new Version
            {
                Project = package.Id,
                Name    = package.Version.ToString(),
            };

            var metadata        = new List <MetadataEntry>();
            var metadataWrapper = new MetadataWrapper(metadata);

            if (!package.Authors.IsEmpty())
            {
                metadataWrapper["Authors"] = String.Join(",", package.Authors);
            }

            if (!string.IsNullOrEmpty(package.Copyright))
            {
                metadataWrapper["Copyrights"] = package.Copyright;
            }

            if (!string.IsNullOrEmpty(package.Description))
            {
                metadataWrapper["Description"] = package.Description;
            }

            if (package.IconUrl != null)
            {
                metadataWrapper["IconUrl"] = package.IconUrl.ToString();
            }

            if (!string.IsNullOrEmpty(package.Language))
            {
                metadataWrapper["Language"] = package.Language;
            }

            if (package.LicenseUrl != null)
            {
                metadataWrapper["LicenseUrl"] = package.LicenseUrl.ToString();
            }

            if (!package.Owners.IsEmpty())
            {
                metadataWrapper["Owners"] = String.Join(",", package.Owners);
            }

            if (package.ProjectUrl != null)
            {
                metadataWrapper["ProjectUrl"] = package.ProjectUrl.ToString();
            }

            if (!string.IsNullOrEmpty(package.ReleaseNotes))
            {
                metadataWrapper["ReleaseNotes"] = package.ReleaseNotes;
            }

            metadataWrapper["RequireLicenseAcceptance"] = package.RequireLicenseAcceptance.ToString();

            if (!string.IsNullOrEmpty(package.Summary))
            {
                metadataWrapper["Summary"] = package.Summary;
            }

            if (!string.IsNullOrEmpty(package.Tags))
            {
                metadataWrapper["Tags"] = package.Tags;
            }

            if (package.DependencySets.SelectMany(ConvertDependencySetToStrings).Any())
            {
                metadataWrapper["Dependencies"] = String.Join("|", package.DependencySets.SelectMany(ConvertDependencySetToStrings));
            }

            if (!string.IsNullOrEmpty(package.Title))
            {
                metadataWrapper["Title"] = package.Title;
            }

            metadataWrapper["PackageSize"]          = length.ToString();
            metadataWrapper["PackageHashAlgorithm"] = "SHA512";

            metadataWrapper["PackageHash"] = hashCode;

            metadataWrapper["DownloadCount"] = "000000";
            metadataWrapper["CreatedDate"]   = DateTime.UtcNow.ToString("s");

            version.Metadata = metadata.ToArray();

            return(version);
        }