本文整理汇总了C#中PackageIdentity类的典型用法代码示例。如果您正苦于以下问题:C# PackageIdentity类的具体用法?C# PackageIdentity怎么用?C# PackageIdentity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PackageIdentity类属于命名空间,在下文中一共展示了PackageIdentity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public static ServerPackageMetadata Parse(IPackage package)
{
var Version = NuGetVersion.Parse(package.Version.ToString());
var Published = package.Published;
var title = String.IsNullOrEmpty(package.Title) ? package.Id : package.Title;
var summary = package.Summary;
var desc = package.Description;
//*TODOs: Check if " " is the separator in the case of V3 jobjects ...
var authors = package.Authors;
var owners = package.Owners;
var iconUrl = package.IconUrl;
var licenseUrl = package.LicenseUrl;
var projectUrl = package.ProjectUrl;
IEnumerable<string> tags = package.Tags == null ? new string[0] : package.Tags.Split(' ');
var dependencySets = package.DependencySets.Select(p => GetVisualStudioUIPackageDependencySet(p));
var requiresLiceneseAcceptance = package.RequireLicenseAcceptance;
var identity = new PackageIdentity(package.Id, Version);
NuGetVersion minClientVersion = null;
if (package.MinClientVersion != null)
{
NuGetVersion.TryParse(package.MinClientVersion.ToString(), out minClientVersion);
}
var downloadCount = package.DownloadCount;
// This concept is not in v2 yet
IEnumerable<string> types = new string[] { "Package" };
return new ServerPackageMetadata(
identity, title, summary, desc, authors, iconUrl, licenseUrl,
projectUrl, tags, Published, dependencySets, requiresLiceneseAcceptance, minClientVersion, downloadCount, -1, owners, types);
}
示例2: Extract
public static async Task Extract (
Solution solution,
PackageIdentity packageIdentity,
DownloadResourceResult downloadResult,
CancellationToken token)
{
string globalPackagesFolder = await GetPackagesDirectory (solution);
var defaultPackagePathResolver = new VersionFolderPathResolver (globalPackagesFolder);
string hashPath = defaultPackagePathResolver.GetHashPath (packageIdentity.Id, packageIdentity.Version);
if (File.Exists (hashPath))
return;
var versionFolderPathContext = new VersionFolderPathContext (
packageIdentity,
globalPackagesFolder,
NullLogger.Instance,
PackageSaveMode.Defaultv3,
PackageExtractionBehavior.XmlDocFileSaveMode);
downloadResult.PackageStream.Position = 0;
await PackageExtractor.InstallFromSourceAsync (
stream => downloadResult.PackageStream.CopyToAsync (stream, BufferSize, token),
versionFolderPathContext,
token);
}
示例3: GetPackageStream
/// <summary>
/// Sets <param name="targetPackageStream"></param> for a given <param name="packageIdentity"></param>
/// from the given <param name="sourceRepository"></param>. If successfully set, returns true. Otherwise, false
/// </summary>
public static async Task<bool> GetPackageStream(SourceRepository sourceRepository, PackageIdentity packageIdentity, Stream targetPackageStream, CancellationToken token)
{
// TODO: Tie up machine cache with CacheClient?!
try
{
token.ThrowIfCancellationRequested();
// Step-1 : Get the download stream for packageIdentity
Stream downloadStream = await GetDownloadStream(sourceRepository, packageIdentity, token);
if(downloadStream == null)
{
return false;
}
token.ThrowIfCancellationRequested();
// Step-2: Copy download stream to targetPackageStream if it is not null
await downloadStream.CopyToAsync(targetPackageStream);
return true;
}
catch (Exception)
{
return false;
}
}
示例4: TestFolderNuGetProjectInstall
public async Task TestFolderNuGetProjectInstall()
{
// Arrange
var packageIdentity = new PackageIdentity("packageA", new NuGetVersion("1.0.0"));
var randomTestSourcePath = TestFilesystemUtility.CreateRandomTestFolder();
var packageFileInfo = TestPackages.GetLegacyTestPackage(randomTestSourcePath, packageIdentity.Id, packageIdentity.Version.ToNormalizedString());
var randomTestDestinationPath = TestFilesystemUtility.CreateRandomTestFolder();
var folderNuGetProject = new FolderNuGetProject(randomTestDestinationPath);
var packagePathResolver = new PackagePathResolver(randomTestDestinationPath);
var packageInstallPath = packagePathResolver.GetInstallPath(packageIdentity);
var nupkgFilePath = Path.Combine(packageInstallPath, packagePathResolver.GetPackageFileName(packageIdentity));
var testNuGetProjectContext = new TestNuGetProjectContext();
var token = CancellationToken.None;
using(var packageStream = packageFileInfo.OpenRead())
{
// Act
await folderNuGetProject.InstallPackageAsync(packageIdentity, packageStream, testNuGetProjectContext, token);
}
// Assert
Assert.True(File.Exists(nupkgFilePath));
Assert.True(File.Exists(Path.Combine(packageInstallPath, "lib/test.dll")));
using(var packageStream = File.OpenRead(nupkgFilePath))
{
var zipArchive = new ZipArchive(packageStream);
Assert.Equal(5, zipArchive.Entries.Count);
}
// Clean-up
TestFilesystemUtility.DeleteRandomTestFolders(randomTestSourcePath, randomTestDestinationPath);
}
示例5: ResolvePackage
/// <summary>
/// Retrieve dependency info for a single package.
/// </summary>
/// <param name="package">package id and version</param>
/// <param name="projectFramework">project target framework. This is used for finding the dependency group</param>
/// <param name="token">cancellation token</param>
/// <returns>
/// Returns dependency info for the given package if it exists. If the package is not found null is
/// returned.
/// </returns>
public override async Task<SourcePackageDependencyInfo> ResolvePackage(PackageIdentity package, NuGetFramework projectFramework, CancellationToken token)
{
try
{
SourcePackageDependencyInfo result = null;
// Construct the registration index url
var uri = _regResource.GetUri(package.Id);
// Retrieve the registration blob
var singleVersion = new VersionRange(minVersion: package.Version, includeMinVersion: true, maxVersion: package.Version, includeMaxVersion: true);
var regInfo = await ResolverMetadataClient.GetRegistrationInfo(_client, uri, singleVersion, projectFramework, token);
// regInfo is null if the server returns a 404 for the package to indicate that it does not exist
if (regInfo != null)
{
// Parse package and dependeny info from the blob
result = GetPackagesFromRegistration(regInfo, token).FirstOrDefault();
}
return result;
}
catch (Exception ex)
{
// Wrap exceptions coming from the server with a user friendly message
var error = String.Format(CultureInfo.CurrentUICulture, Strings.Protocol_PackageMetadataError, package, _source);
throw new NuGetProtocolException(error, ex);
}
}
示例6: CheckIfPackageCanBeUninstalled
private static void CheckIfPackageCanBeUninstalled(PackageIdentity packageIdentity,
IDictionary<PackageIdentity, HashSet<PackageIdentity>> dependenciesDict,
IDictionary<PackageIdentity, HashSet<PackageIdentity>> dependentsDict,
UninstallationContext uninstallationContext,
HashSet<PackageIdentity> packagesMarkedForUninstall)
{
HashSet<PackageIdentity> dependents;
if (dependentsDict.TryGetValue(packageIdentity, out dependents) && dependents != null)
{
if (!uninstallationContext.ForceRemove)
{
var unMarkedDependents = dependents.Where(d => !packagesMarkedForUninstall.Contains(d)).ToList();
if (unMarkedDependents.Count > 0)
{
throw CreatePackageHasDependentsException(packageIdentity, unMarkedDependents);
}
}
}
HashSet<PackageIdentity> dependencies;
if (uninstallationContext.RemoveDependencies && dependenciesDict.TryGetValue(packageIdentity, out dependencies) && dependencies != null)
{
foreach(var dependency in dependencies)
{
CheckIfPackageCanBeUninstalled(dependency,
dependenciesDict,
dependentsDict,
uninstallationContext,
packagesMarkedForUninstall);
}
}
}
示例7: Search
public override async Task<IEnumerable<ServerPackageMetadata>> Search(string searchTerm, SearchFilter filters, int skip, int take, CancellationToken cancellationToken)
{
List<ServerPackageMetadata> results = new List<ServerPackageMetadata>();
var searchResultJsonObjects = await _searchResource.Search(searchTerm, filters, skip, take, cancellationToken);
foreach (JObject package in searchResultJsonObjects)
{
// TODO: verify this parsing is needed
string id = package.Value<string>(Properties.PackageId);
NuGetVersion version = NuGetVersion.Parse(package.Value<string>(Properties.Version));
PackageIdentity topPackage = new PackageIdentity(id, version);
Uri iconUrl = GetUri(package, Properties.IconUrl);
string summary = package.Value<string>(Properties.Summary);
if (string.IsNullOrWhiteSpace(summary))
{
// summary is empty. Use its description instead.
summary = package.Value<string>(Properties.Description);
}
// retrieve metadata for the top package
results.Add(PackageMetadataParser.ParseMetadata(package));
}
return results;
}
示例8: RemoveAllVersionsForIdExcept
/// <summary>
/// Remove all versions of a package id from the list, except for the target version
/// </summary>
public static IEnumerable<SourceDependencyInfo> RemoveAllVersionsForIdExcept(IEnumerable<SourceDependencyInfo> packages, PackageIdentity target)
{
var comparer = VersionComparer.VersionRelease;
return packages.Where(p => !StringComparer.OrdinalIgnoreCase.Equals(target.Id, p.Id) ||
(StringComparer.OrdinalIgnoreCase.Equals(target.Id, p.Id) && comparer.Equals(p.Version, target.Version)));
}
示例9: GetStream
public override async Task<Stream> GetStream(PackageIdentity identity, CancellationToken token)
{
Stream result = null;
IPackage package = null;
SemanticVersion version = SemanticVersion.Parse(identity.Version.ToString());
// attempt a normal lookup first
if (!V2Client.TryFindPackage(identity.Id, version, out package))
{
// skip further look ups for online repos
DataServicePackageRepository v2Online = V2Client as DataServicePackageRepository;
if (v2Online == null)
{
IVersionComparer versionComparer = VersionComparer.VersionRelease;
// otherwise search further to find the package - this is needed for v2 non-normalized versions
V2Client.FindPackagesById(identity.Id).Any(p => versionComparer.Equals(identity.Version, NuGetVersion.Parse(p.ToString())));
}
}
if (package != null)
{
result = package.GetStream();
}
return result;
}
示例10: GetPackageDependents
public static IDictionary<PackageIdentity, HashSet<PackageIdentity>> GetPackageDependents(IEnumerable<PackageDependencyInfo> dependencyInfoEnumerable,
IEnumerable<PackageIdentity> installedPackages, out IDictionary<PackageIdentity, HashSet<PackageIdentity>> dependenciesDict)
{
Dictionary<PackageIdentity, HashSet<PackageIdentity>> dependentsDict = new Dictionary<PackageIdentity, HashSet<PackageIdentity>>(PackageIdentity.Comparer);
dependenciesDict = new Dictionary<PackageIdentity, HashSet<PackageIdentity>>(PackageIdentity.Comparer);
foreach (var dependencyInfo in dependencyInfoEnumerable)
{
var packageIdentity = new PackageIdentity(dependencyInfo.Id, dependencyInfo.Version);
foreach(var dependency in dependencyInfo.Dependencies)
{
var dependencyPackageIdentity = installedPackages.Where(i => dependency.Id.Equals(i.Id, StringComparison.OrdinalIgnoreCase)
&& dependency.VersionRange.Satisfies(i.Version)).FirstOrDefault();
if(dependencyPackageIdentity != null)
{
// Update the package dependents dictionary
HashSet<PackageIdentity> dependents;
if(!dependentsDict.TryGetValue(dependencyPackageIdentity, out dependents))
{
dependentsDict[dependencyPackageIdentity] = dependents = new HashSet<PackageIdentity>(PackageIdentity.Comparer);
}
dependents.Add(packageIdentity);
// Update the package dependencies dictionary
HashSet<PackageIdentity> dependencies;
if(!dependenciesDict.TryGetValue(packageIdentity, out dependencies))
{
dependenciesDict[packageIdentity] = dependencies = new HashSet<PackageIdentity>(PackageIdentity.Comparer);
}
dependencies.Add(dependencyPackageIdentity);
}
}
}
return dependentsDict;
}
示例11: RemoveAllVersionsLessThan
/// <summary>
/// Clear out all versions less than the minimuim. This can be used to prevent downgrading
/// </summary>
public static IEnumerable<SourceDependencyInfo> RemoveAllVersionsLessThan(IEnumerable<SourceDependencyInfo> packages, PackageIdentity minimum)
{
var comparer = VersionComparer.VersionRelease;
return packages.Where(p => !StringComparer.OrdinalIgnoreCase.Equals(minimum.Id, p.Id) ||
(StringComparer.OrdinalIgnoreCase.Equals(minimum.Id, p.Id) && comparer.Compare(p.Version, minimum.Version) >= 0));
}
示例12: Search
/// <summary>
/// Basic search
/// </summary>
public override async Task<IEnumerable<SimpleSearchMetadata>> Search(string searchTerm, SearchFilter filters, int skip, int take, CancellationToken cancellationToken)
{
var results = new List<SimpleSearchMetadata>();
foreach (var result in await _rawSearch.Search(searchTerm, filters, skip, take, cancellationToken))
{
var version = NuGetVersion.Parse(result["version"].ToString());
var identity = new PackageIdentity(result["id"].ToString(), version);
var description = result["description"].ToString();
var allVersions = new List<NuGetVersion>();
foreach (var versionObj in ((JArray)result["versions"]))
{
allVersions.Add(NuGetVersion.Parse(versionObj["version"].ToString()));
}
var data = new SimpleSearchMetadata(identity, description, allVersions);
results.Add(data);
}
return results;
}
示例13: GetNupkgUrlForDownload
public Task<PackageDownloadMetadata> GetNupkgUrlForDownload(PackageIdentity identity)
{
//*TODOs: Temp implementation. Need to do erorr handling and stuff.
return Task.Factory.StartNew(() =>
{
if(V2Client is DataServicePackageRepository)
{
//TODOs:Not sure if there is some other standard way to get the Url from a dataservice repo. DataServicePackage has downloadurl property but not sure how to get it.
return new PackageDownloadMetadata(new Uri(Path.Combine(V2Client.Source, "api/v2/" + identity.Id + "." + identity.Version + ".nupkg")));
}
else if(V2Client is LocalPackageRepository)
{
LocalPackageRepository lrepo = V2Client as LocalPackageRepository;
SemanticVersion semVer = new SemanticVersion(identity.Version.Version);
return new PackageDownloadMetadata(new Uri(Path.Combine(V2Client.Source, lrepo.PathResolver.GetPackageFileName(identity.Id, semVer))));
}
else
{
// TODO: move the string into a resoure file
throw new InvalidOperationException(string.Format(
CultureInfo.CurrentCulture,
"Unable to get download metadata for package {0}",identity.Id));
}
});
}
示例14: InstallFromStream
private async ThreadingTask InstallFromStream(Task<Stream> getStream, PackageIdentity package,
string packagesFolder, CancellationToken token)
{
bool isValid = true;
if (OfflineFeedUtility.PackageExists(package, packagesFolder, out isValid))
{
return;
}
var logger = new NugetMsBuildLogger(new TaskLoggingHelper(this));
var versionFolderPathContext = new VersionFolderPathContext(
package,
packagesFolder,
isLowercasePackagesDirectory: false,
logger: logger,
packageSaveMode: PackageSaveMode.Defaultv3,
xmlDocFileSaveMode: XmlDocFileSaveMode.None);
await PackageExtractor.InstallFromSourceAsync(
async dest =>
{
var source = await getStream;
await source.CopyToAsync(dest, bufferSize: DefaultBufferSize, cancellationToken: token);
},
versionFolderPathContext,
token);
}
示例15: InstallPackage
public override Task InstallPackage(
PackageIdentity id,
IEnumerable<FrameworkName> packageSupportedFrameworks,
IExecutionLogger logger,
CancellationToken cancelToken)
{
var args = new Dictionary<string, object>();
var projectFrameworks = _nugetAwareProject.GetSupportedFrameworksAsync(cancelToken).Result;
args["Frameworks"] = projectFrameworks.Where(
projectFramework =>
NuGet.VersionUtility.IsCompatible(
projectFramework,
packageSupportedFrameworks)).ToArray();
var task = _nugetAwareProject.InstallPackageAsync(
new NuGetPackageMoniker
{
Id = id.Id,
Version = id.Version.ToString()
},
args,
logger: null,
progress: null,
cancellationToken: cancelToken);
return task;
}