|
|
@ -1,18 +1,26 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using System.IO.Compression;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
using isn.abst;
|
|
|
|
using isn.abst;
|
|
|
|
using isn.Abstract;
|
|
|
|
using isn.Abstract;
|
|
|
|
using isnd.Data;
|
|
|
|
using isnd.Data;
|
|
|
|
using isnd.Data.Catalog;
|
|
|
|
using isnd.Data.Catalog;
|
|
|
|
using isnd.Data.Packages;
|
|
|
|
using isnd.Data.Packages;
|
|
|
|
using isnd.Entities;
|
|
|
|
using isnd.Entities;
|
|
|
|
|
|
|
|
using isnd.Helpers;
|
|
|
|
using isnd.Interfaces;
|
|
|
|
using isnd.Interfaces;
|
|
|
|
using isnd.ViewModels;
|
|
|
|
using isnd.ViewModels;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using NuGet.Packaging.Core;
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
|
|
|
using NuGet.Versioning;
|
|
|
|
using NuGet.Versioning;
|
|
|
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
|
|
namespace isnd.Services
|
|
|
|
namespace isnd.Services
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -61,11 +69,26 @@ namespace isnd.Services
|
|
|
|
Comment = "Auto complete service"
|
|
|
|
Comment = "Auto complete service"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new Resource(apiBase + ApiConfig.Search,
|
|
|
|
|
|
|
|
"SearchQueryService")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Comment = "Query endpoint of NuGet Search service (primary) used by RC clients"
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
new Resource(apiBase + ApiConfig.Search,
|
|
|
|
|
|
|
|
"SearchQueryService/3.0.0-beta")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Comment = "Query endpoint of NuGet Search service (primary) used by RC clients"
|
|
|
|
|
|
|
|
},
|
|
|
|
new Resource(apiBase + ApiConfig.Search,
|
|
|
|
new Resource(apiBase + ApiConfig.Search,
|
|
|
|
"SearchQueryService/3.0.0-rc")
|
|
|
|
"SearchQueryService/3.0.0-rc")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Comment = "Query endpoint of NuGet Search service (primary) used by RC clients"
|
|
|
|
Comment = "Query endpoint of NuGet Search service (primary) used by RC clients"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
new Resource(apiBase + ApiConfig.Search,
|
|
|
|
|
|
|
|
"SearchQueryService/3.5.0")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Comment = "Query endpoint of NuGet Search service (primary) used by RC clients"
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
new Resource(apiBase + ApiConfig.Registration,
|
|
|
|
new Resource(apiBase + ApiConfig.Registration,
|
|
|
|
"RegistrationsBaseUrl/Versioned")
|
|
|
|
"RegistrationsBaseUrl/Versioned")
|
|
|
@ -107,7 +130,7 @@ namespace isnd.Services
|
|
|
|
v => v.PackageId == id
|
|
|
|
v => v.PackageId == id
|
|
|
|
&& (prerelease || !v.IsPrerelease)
|
|
|
|
&& (prerelease || !v.IsPrerelease)
|
|
|
|
&& (packageType == null || v.Type == packageType)
|
|
|
|
&& (packageType == null || v.Type == packageType)
|
|
|
|
&& (parsedVersion==null || parsedVersion.CompareTo
|
|
|
|
&& (parsedVersion == null || parsedVersion.CompareTo
|
|
|
|
(new SemanticVersion(v.Major, v.Minor, v.Patch)) < 0)
|
|
|
|
(new SemanticVersion(v.Major, v.Minor, v.Patch)) < 0)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.OrderBy(v => v.NugetVersion)
|
|
|
|
.OrderBy(v => v.NugetVersion)
|
|
|
@ -115,8 +138,6 @@ namespace isnd.Services
|
|
|
|
.Skip(skip).Take(take).ToArray();
|
|
|
|
.Skip(skip).Take(take).ToArray();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string CatalogBaseUrl => apiBase;
|
|
|
|
public string CatalogBaseUrl => apiBase;
|
|
|
|
|
|
|
|
|
|
|
|
private IsndSettings isndSettings;
|
|
|
|
private IsndSettings isndSettings;
|
|
|
@ -124,17 +145,17 @@ namespace isnd.Services
|
|
|
|
|
|
|
|
|
|
|
|
public virtual async Task<PackageRegistration> GetCatalogIndexAsync()
|
|
|
|
public virtual async Task<PackageRegistration> GetCatalogIndexAsync()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return await ÛpdateCatalogForAsync(null);
|
|
|
|
return await UpdateCatalogForAsync(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<PackageRegistration> ÛpdateCatalogForAsync
|
|
|
|
public async Task<PackageRegistration> UpdateCatalogForAsync
|
|
|
|
(Commit reason = null)
|
|
|
|
(Commit reason = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
|
|
string baseid = apiBase + ApiConfig.Catalog;
|
|
|
|
string baseId = apiBase + ApiConfig.Catalog;
|
|
|
|
string bidreg = $"{apiBase}{ApiConfig.Registration}";
|
|
|
|
string baseRegistrationId = $"{apiBase}{ApiConfig.Registration}";
|
|
|
|
PackageRegistration index = new PackageRegistration(baseid);
|
|
|
|
PackageRegistration index = new PackageRegistration(baseId);
|
|
|
|
|
|
|
|
|
|
|
|
var scope = await dbContext.Commits.OrderBy(c => c.TimeStamp).ToArrayAsync();
|
|
|
|
var scope = await dbContext.Commits.OrderBy(c => c.TimeStamp).ToArrayAsync();
|
|
|
|
|
|
|
|
|
|
|
@ -150,20 +171,20 @@ namespace isnd.Services
|
|
|
|
.ToArrayAsync())
|
|
|
|
.ToArrayAsync())
|
|
|
|
.GroupBy((q) => q.Id);
|
|
|
|
.GroupBy((q) => q.Id);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var pkgid in validPkgs)
|
|
|
|
foreach (var pkgIdGroup in validPkgs)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
CatalogPage page = index.Items.FirstOrDefault
|
|
|
|
CatalogPage page = index.Items.FirstOrDefault
|
|
|
|
(p => p.GetPackageId() == pkgid.Key);
|
|
|
|
(p => p.GetPackageId() == pkgIdGroup.Key);
|
|
|
|
if (page == null)
|
|
|
|
if (page == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
page = new CatalogPage(pkgid.Key, apiBase);
|
|
|
|
page = new CatalogPage(pkgIdGroup.Key, apiBase);
|
|
|
|
index.Items.Add(page);
|
|
|
|
index.Items.Add(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var pkgv in pkgid)
|
|
|
|
foreach (var package in pkgIdGroup)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
page.AddVersionRange(pkgv.Versions);
|
|
|
|
page.AddVersionRange(package.Versions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reason = commit;
|
|
|
|
reason = commit;
|
|
|
@ -173,7 +194,7 @@ namespace isnd.Services
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<PackageDeletionReport> DeletePackageAsync
|
|
|
|
public async Task<PackageDeletionReport> DeletePackageAsync
|
|
|
|
(string pkgid, string version, string type)
|
|
|
|
(string pkgId, string version, string type)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// TODO deletion on disk
|
|
|
|
// TODO deletion on disk
|
|
|
|
var commit = new Commit
|
|
|
|
var commit = new Commit
|
|
|
@ -183,7 +204,7 @@ namespace isnd.Services
|
|
|
|
};
|
|
|
|
};
|
|
|
|
dbContext.Commits.Add(commit);
|
|
|
|
dbContext.Commits.Add(commit);
|
|
|
|
var pkg = await dbContext.PackageVersions.SingleOrDefaultAsync(
|
|
|
|
var pkg = await dbContext.PackageVersions.SingleOrDefaultAsync(
|
|
|
|
v => v.PackageId == pkgid &&
|
|
|
|
v => v.PackageId == pkgId &&
|
|
|
|
v.FullString == version &&
|
|
|
|
v.FullString == version &&
|
|
|
|
v.Type == type
|
|
|
|
v.Type == type
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -193,15 +214,15 @@ namespace isnd.Services
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dbContext.PackageVersions.Remove(pkg);
|
|
|
|
dbContext.PackageVersions.Remove(pkg);
|
|
|
|
await dbContext.SaveChangesAsync();
|
|
|
|
await dbContext.SaveChangesAsync();
|
|
|
|
await ÛpdateCatalogForAsync(commit);
|
|
|
|
await UpdateCatalogForAsync(commit);
|
|
|
|
return new PackageDeletionReport { Deleted = true, DeletedVersion = pkg };
|
|
|
|
return new PackageDeletionReport { Deleted = true, DeletedVersion = pkg };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<PackageVersion> GetPackageAsync
|
|
|
|
public async Task<PackageVersion> GetPackageAsync
|
|
|
|
(string pkgid, string version, string type)
|
|
|
|
(string pkgId, string version, string type)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return await dbContext.PackageVersions.SingleOrDefaultAsync(
|
|
|
|
return await dbContext.PackageVersions.SingleOrDefaultAsync(
|
|
|
|
v => v.PackageId == pkgid &&
|
|
|
|
v => v.PackageId == pkgId &&
|
|
|
|
v.FullString == version &&
|
|
|
|
v.FullString == version &&
|
|
|
|
v.Type == type
|
|
|
|
v.Type == type
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -217,7 +238,7 @@ namespace isnd.Services
|
|
|
|
.Include(v => v.LatestCommit)
|
|
|
|
.Include(v => v.LatestCommit)
|
|
|
|
.Where(v => v.PackageId == pkgId
|
|
|
|
.Where(v => v.PackageId == pkgId
|
|
|
|
&& v.FullString == semver
|
|
|
|
&& v.FullString == semver
|
|
|
|
&& v.LatestCommit !=null
|
|
|
|
&& v.LatestCommit != null
|
|
|
|
).SingleOrDefaultAsync()).ToPackage(
|
|
|
|
).SingleOrDefaultAsync()).ToPackage(
|
|
|
|
apiBase);
|
|
|
|
apiBase);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -238,12 +259,13 @@ namespace isnd.Services
|
|
|
|
public IEnumerable<Data.Catalog.Package> SearchCatalogEntriesById
|
|
|
|
public IEnumerable<Data.Catalog.Package> SearchCatalogEntriesById
|
|
|
|
(string pkgId, string semver, string pkgType, bool preRelease)
|
|
|
|
(string pkgId, string semver, string pkgType, bool preRelease)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
// PackageDependency
|
|
|
|
return dbContext.PackageVersions
|
|
|
|
return dbContext.PackageVersions
|
|
|
|
.Include(v => v.Package)
|
|
|
|
.Include(v => v.Package)
|
|
|
|
.Include(v => v.Package.Owner)
|
|
|
|
.Include(v => v.Package.Owner)
|
|
|
|
.Include(v => v.Package.LatestCommit)
|
|
|
|
.Include(v => v.Package.LatestCommit)
|
|
|
|
.Include(v => v.LatestCommit)
|
|
|
|
.Include(v => v.LatestCommit)
|
|
|
|
|
|
|
|
.Include(v => v.DependencyGroups)
|
|
|
|
.Where(v => v.PackageId == pkgId && semver == v.FullString
|
|
|
|
.Where(v => v.PackageId == pkgId && semver == v.FullString
|
|
|
|
&& (pkgType == null || pkgType == v.Type)
|
|
|
|
&& (pkgType == null || pkgType == v.Type)
|
|
|
|
&& (preRelease || !v.IsPrerelease))
|
|
|
|
&& (preRelease || !v.IsPrerelease))
|
|
|
@ -271,11 +293,11 @@ namespace isnd.Services
|
|
|
|
.Include(p => p.Owner)
|
|
|
|
.Include(p => p.Owner)
|
|
|
|
.Include(p => p.LatestCommit)
|
|
|
|
.Include(p => p.LatestCommit)
|
|
|
|
.SingleOrDefaultAsync(p => p.Id.ToLower() == query.Query);
|
|
|
|
.SingleOrDefaultAsync(p => p.Id.ToLower() == query.Query);
|
|
|
|
if (scope==null) return null;
|
|
|
|
if (scope == null) return null;
|
|
|
|
if (scope.Versions.Count==0) return null;
|
|
|
|
if (scope.Versions.Count == 0) return null;
|
|
|
|
string bid = $"{apiBase}{ApiConfig.Registration}";
|
|
|
|
string bid = $"{apiBase}{ApiConfig.Registration}";
|
|
|
|
foreach (var version in scope.Versions)
|
|
|
|
foreach (var version in scope.Versions)
|
|
|
|
version.LatestCommit = dbContext.Commits.Single(c=>c.Id == version.CommitNId);
|
|
|
|
version.LatestCommit = dbContext.Commits.Single(c => c.Id == version.CommitNId);
|
|
|
|
return
|
|
|
|
return
|
|
|
|
new PackageRegistration(apiBase, scope);
|
|
|
|
new PackageRegistration(apiBase, scope);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -284,7 +306,7 @@ namespace isnd.Services
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string bid = $"{apiBase}{ApiConfig.Registration}";
|
|
|
|
string bid = $"{apiBase}{ApiConfig.Registration}";
|
|
|
|
if (string.IsNullOrWhiteSpace(query.Query))
|
|
|
|
if (string.IsNullOrWhiteSpace(query.Query))
|
|
|
|
query.Query="";
|
|
|
|
query.Query = "";
|
|
|
|
var scope = dbContext.Packages
|
|
|
|
var scope = dbContext.Packages
|
|
|
|
.Include(p => p.Owner)
|
|
|
|
.Include(p => p.Owner)
|
|
|
|
.Include(p => p.Versions)
|
|
|
|
.Include(p => p.Versions)
|
|
|
@ -293,11 +315,155 @@ namespace isnd.Services
|
|
|
|
.Where(p => p.Id.StartsWith(query.Query)
|
|
|
|
.Where(p => p.Id.StartsWith(query.Query)
|
|
|
|
&& p.LatestCommit != null
|
|
|
|
&& p.LatestCommit != null
|
|
|
|
&& (query.Prerelease || p.Versions.Any(p => !p.IsPrerelease))
|
|
|
|
&& (query.Prerelease || p.Versions.Any(p => !p.IsPrerelease))
|
|
|
|
&& p.Versions.Count()>0)
|
|
|
|
&& p.Versions.Count() > 0)
|
|
|
|
.OrderBy(p => p.CommitNId);
|
|
|
|
.OrderBy(p => p.CommitNId);
|
|
|
|
|
|
|
|
|
|
|
|
return new PackageSearchResult(await scope.Skip(query.Skip).Take(query.Take)
|
|
|
|
return new PackageSearchResult(await scope.Skip(query.Skip).Take(query.Take)
|
|
|
|
.ToListAsync(), apiBase, scope.Count());
|
|
|
|
.ToListAsync(), apiBase, scope.Count());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<PackageVersion> PutPackageAsync(Stream packageStream, string ownerId)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
PackageVersion version = null;
|
|
|
|
|
|
|
|
using (packageStream)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var archive = new ZipArchive(packageStream))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var spec = archive.Entries.FirstOrDefault(e => e.FullName.EndsWith("." + Constants.SpecFileExtension));
|
|
|
|
|
|
|
|
if (spec == null) throw new InvalidPackageException("no " + Constants.SpecFileExtension + " from archive");
|
|
|
|
|
|
|
|
string pkgPath;
|
|
|
|
|
|
|
|
NuGetVersion nugetVersion;
|
|
|
|
|
|
|
|
string pkgId;
|
|
|
|
|
|
|
|
string fullPath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using var specificationStream = spec.Open();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using XmlReader xmlReader = XmlReader.Create(specificationStream);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var xMeta = XElement.Load(xmlReader, LoadOptions.None).Descendants().First();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string packageDescription = xMeta.Descendants().FirstOrDefault(x => x.Name.LocalName == "description")?.Value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var frameWorks = xMeta
|
|
|
|
|
|
|
|
.Descendants().FirstOrDefault(x => x.Name.LocalName =="frameworkReferences")
|
|
|
|
|
|
|
|
.Descendants().Where(x => x.Name.LocalName =="group")
|
|
|
|
|
|
|
|
.Select(x=> x.Attribute("targetFramework").Value).ToArray();
|
|
|
|
|
|
|
|
var types = "Package";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pkgId = xMeta.Descendants().FirstOrDefault(x => x.Name.LocalName =="id")?.Value;
|
|
|
|
|
|
|
|
string pkgVersion = xMeta.Descendants().FirstOrDefault(x => x.Name.LocalName =="version")?.Value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!NuGetVersion.TryParse(pkgVersion, out nugetVersion))
|
|
|
|
|
|
|
|
throw new InvalidPackageException("metadata/version");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var frameworkReferences = frameWorks.Select(g => new PackageDependencyGroup
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
TargetFramework = g
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string packageIdPath = Path.Combine(isndSettings.PackagesRootDir,
|
|
|
|
|
|
|
|
pkgId);
|
|
|
|
|
|
|
|
pkgPath = Path.Combine(packageIdPath, nugetVersion.ToFullString());
|
|
|
|
|
|
|
|
string name = $"{pkgId}-{nugetVersion}." + Constants.PacketFileExtension;
|
|
|
|
|
|
|
|
fullPath = Path.Combine(pkgPath, name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var packageIdPathInfo = new DirectoryInfo(packageIdPath);
|
|
|
|
|
|
|
|
Data.Packages.Package pkg = dbContext.Packages.SingleOrDefault(p => p.Id == pkgId);
|
|
|
|
|
|
|
|
Commit commit = new Commit
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Action = PackageAction.PublishPackage,
|
|
|
|
|
|
|
|
TimeStamp = DateTimeOffset.Now.ToUniversalTime()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if (pkg != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Update
|
|
|
|
|
|
|
|
pkg.Description = packageDescription;
|
|
|
|
|
|
|
|
pkg.LatestCommit = commit;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// First version
|
|
|
|
|
|
|
|
pkg = new Data.Packages.Package
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Id = pkgId,
|
|
|
|
|
|
|
|
Description = packageDescription,
|
|
|
|
|
|
|
|
OwnerId = ownerId,
|
|
|
|
|
|
|
|
LatestCommit = commit
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
dbContext.Packages.Add(pkg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// here, the package is or new, or owned by the key owner
|
|
|
|
|
|
|
|
if (!packageIdPathInfo.Exists) packageIdPathInfo.Create();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dest = new FileInfo(fullPath);
|
|
|
|
|
|
|
|
var destDir = new DirectoryInfo(dest.DirectoryName);
|
|
|
|
|
|
|
|
if (dest.Exists) dest.Delete();
|
|
|
|
|
|
|
|
if (!destDir.Exists) destDir.Create();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
packageStream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
using (var fileStream = File.Create(fullPath))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await packageStream.CopyToAsync(fileStream);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string fullStringVersion = nugetVersion.ToFullString();
|
|
|
|
|
|
|
|
var pkgVersions = dbContext.PackageVersions.Where
|
|
|
|
|
|
|
|
(v => v.PackageId == pkg.Id && v.FullString == fullStringVersion);
|
|
|
|
|
|
|
|
if (pkgVersions.Count() > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var v in pkgVersions.ToArray())
|
|
|
|
|
|
|
|
dbContext.PackageVersions.Remove(v);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME default type or null
|
|
|
|
|
|
|
|
dbContext.PackageVersions.Add
|
|
|
|
|
|
|
|
(version = new PackageVersion
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Package = pkg,
|
|
|
|
|
|
|
|
Major = nugetVersion.Major,
|
|
|
|
|
|
|
|
Minor = nugetVersion.Minor,
|
|
|
|
|
|
|
|
Patch = nugetVersion.Patch,
|
|
|
|
|
|
|
|
Revision = nugetVersion.Revision,
|
|
|
|
|
|
|
|
IsPrerelease = nugetVersion.IsPrerelease,
|
|
|
|
|
|
|
|
FullString = nugetVersion.ToFullString(),
|
|
|
|
|
|
|
|
Type =types,
|
|
|
|
|
|
|
|
LatestCommit = commit
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dbContext.Commits.Add(commit);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await dbContext.SaveChangesAsync();
|
|
|
|
|
|
|
|
version.DependencyGroups = frameworkReferences;
|
|
|
|
|
|
|
|
await UpdateCatalogForAsync(commit);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var shaCrypto = System.Security.Cryptography.SHA512.Create())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var stream = System.IO.File.OpenRead(fullPath))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var hash = shaCrypto.ComputeHash(stream);
|
|
|
|
|
|
|
|
var shaFullName = fullPath + ".sha512";
|
|
|
|
|
|
|
|
var hashText = Convert.ToBase64String(hash);
|
|
|
|
|
|
|
|
var hashTextBytes = Encoding.ASCII.GetBytes(hashText);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var shaFile = System.IO.File.OpenWrite(shaFullName))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
shaFile.Write(hashTextBytes, 0, hashTextBytes.Length);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
string nugetSpecificationFullPath = Path.Combine(pkgPath, pkgId + "." + Constants.SpecFileExtension);
|
|
|
|
|
|
|
|
FileInfo nugetSpecificationFullPathInfo = new(nugetSpecificationFullPath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nugetSpecificationFullPathInfo.Exists)
|
|
|
|
|
|
|
|
nugetSpecificationFullPathInfo.Delete();
|
|
|
|
|
|
|
|
spec.ExtractToFile(nugetSpecificationFullPath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return version;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|