本文整理汇总了C#中SourceRepository类的典型用法代码示例。如果您正苦于以下问题:C# SourceRepository类的具体用法?C# SourceRepository怎么用?C# SourceRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SourceRepository类属于命名空间,在下文中一共展示了SourceRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAllVersionsForPackageId
/// <summary>
/// Get all versions for a specific package Id.
/// </summary>
/// <param name="sourceRepository"></param>
/// <param name="packageId"></param>
/// <param name="project"></param>
/// <param name="includePrerelease"></param>
/// <returns></returns>
public static IEnumerable<NuGetVersion> GetAllVersionsForPackageId(SourceRepository sourceRepository, string packageId, NuGetProject project, bool includePrerelease)
{
IEnumerable<string> targetFrameworks = GetProjectTargetFrameworks(project);
SearchFilter searchfilter = new SearchFilter();
searchfilter.IncludePrerelease = includePrerelease;
searchfilter.SupportedFrameworks = targetFrameworks;
searchfilter.IncludeDelisted = false;
PSSearchResource resource = sourceRepository.GetResource<PSSearchResource>();
PSSearchMetadata result = null;
IEnumerable<NuGetVersion> allVersions = Enumerable.Empty<NuGetVersion>();
try
{
Task<IEnumerable<PSSearchMetadata>> task = resource.Search(packageId, searchfilter, 0, 30, CancellationToken.None);
result = task.Result
.Where(p => string.Equals(p.Identity.Id, packageId, StringComparison.OrdinalIgnoreCase))
.FirstOrDefault();
allVersions = result.Versions;
}
catch (Exception)
{
if (result == null || !allVersions.Any())
{
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
Resources.UnknownPackage, packageId));
}
}
return result.Versions;
}
示例2: MultiSourcePackageMetadataProvider
public MultiSourcePackageMetadataProvider(
IEnumerable<SourceRepository> sourceRepositories,
SourceRepository optionalLocalRepository,
IEnumerable<SourceRepository> optionalGlobalLocalRepositories,
NuGetProject[] projects,
bool isSolution,
Common.ILogger logger)
{
if (sourceRepositories == null)
{
throw new ArgumentNullException(nameof(sourceRepositories));
}
if (projects == null)
{
throw new ArgumentNullException(nameof(projects));
}
_sourceRepositories = sourceRepositories;
_localRepository = optionalLocalRepository;
_globalLocalRepositories = optionalGlobalLocalRepositories;
_projects = projects;
_isSolution = isSolution;
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}
_logger = logger;
}
示例3: CreateAction
void CreateAction (
string packageId = "Test",
string version = "2.1")
{
project = new FakeDotNetProject (@"d:\projects\MyProject\MyProject.csproj");
solutionManager = new FakeSolutionManager ();
nugetProject = new FakeNuGetProject (project);
solutionManager.NuGetProjects[project] = nugetProject;
var metadataResourceProvider = new FakePackageMetadataResourceProvider ();
packageMetadataResource = metadataResourceProvider.PackageMetadataResource;
var source = new PackageSource ("http://test.com");
var providers = new INuGetResourceProvider[] {
metadataResourceProvider
};
var sourceRepository = new SourceRepository (source, providers);
primaryRepositories = new [] {
sourceRepository
}.ToList ();
action = new TestableInstallNuGetPackageAction (
primaryRepositories,
solutionManager,
project);
packageManager = action.PackageManager;
packageManagementEvents = action.PackageManagementEvents;
fileRemover = action.FileRemover;
action.PackageId = packageId;
action.Version = new NuGetVersion (version);
}
示例4: ResolveVersion
public async Task ResolveVersion(SourceRepository localRepository,
IReadOnlyList<SourceRepository> remoteRepositories, bool updatePackages, ILogger logger)
{
string versionRangeString = _versionRange == null ? string.Empty : " " + _versionRange;
Trace.Verbose($"Resolving package version for {_packageId}{versionRangeString} (with dependencies)");
IReadOnlyList<SourceRepository> sourceRepositories = GetSourceRepositories(remoteRepositories);
NuGetVersion versionMatch = null;
if (!_getLatest && !updatePackages)
{
// Get the latest matching version in the local repository
versionMatch = await GetLatestMatchingVersion(localRepository, logger);
}
if (versionMatch != null)
{
Trace.Verbose($"Package {_packageId}{versionRangeString} is satisfied by version {versionMatch.Version}");
}
else
{
// The package either wasn't installed locally, the local version didn't match, or we requested a package update
// Get the latest remote version, but only if we actually have remote repositories
if (sourceRepositories != null && sourceRepositories.Count > 0)
{
versionMatch = await GetLatestMatchingVersion(sourceRepositories, logger);
}
if (versionMatch == null)
{
Trace.Verbose($"Package {_packageId}{versionRangeString} was not found on any remote source repositories");
}
}
_versionMatch = versionMatch;
}
示例5: 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;
}
}
示例6: CreateAction
void CreateAction ()
{
project = new FakeDotNetProject (@"d:\projects\MyProject\MyProject.csproj");
solutionManager = new FakeSolutionManager ();
nugetProject = new FakeNuGetProject (project);
solutionManager.NuGetProjects[project] = nugetProject;
var metadataResourceProvider = new FakePackageMetadataResourceProvider ();
packageMetadataResource = metadataResourceProvider.PackageMetadataResource;
var source = new PackageSource ("http://test.com");
var providers = new INuGetResourceProvider[] {
metadataResourceProvider
};
var sourceRepository = new SourceRepository (source, providers);
primaryRepositories = new [] {
sourceRepository
}.ToList ();
solutionManager.SourceRepositoryProvider.Repositories.AddRange (primaryRepositories);
action = new TestableUpdateAllNuGetPackagesInProjectAction (
solutionManager,
project);
packageManager = action.PackageManager;
packageManagementEvents = action.PackageManagementEvents;
fileRemover = action.FileRemover;
restoreManager = action.RestoreManager;
}
示例7: TryCreate
public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceRepository source, CancellationToken cancellationToken)
{
V3TotalsStatsResource totalsStatsResource = null;
var serviceIndex = await source.GetResourceAsync<ServiceIndexResourceV3>(cancellationToken);
if (serviceIndex != null)
{
// TODO: fix this for resource templates
throw new NotImplementedException();
//ResourceSelector resourceSelector = new ResourceSelector(source);
//IList<Uri> resourceUrls = serviceIndex[ServiceTypes.TotalStats];
//Uri resourceUri = await resourceSelector.DetermineResourceUrlAsync(resourceUrls, cancellationToken);
//var messageHandlerResource = await source.GetResourceAsync<HttpHandlerResource>(cancellationToken);
//DataClient client = new DataClient(messageHandlerResource.MessageHandler);
//// construct a new resource
//totalsStatsResource = new V3TotalsStatsResource(client, resourceUri);
}
return new Tuple<bool, INuGetResource>(totalsStatsResource != null, totalsStatsResource);
}
示例8: DetectVersionWhenNeccessary
private async Task DetectVersionWhenNeccessary()
{
await _lock.WaitAsync();
try
{
if (_repo != null)
{
return;
}
bool r = await IsV3Async(_source);
if (r)
{
_repo = new V3SourceRepository(_source, _host);
return;
}
r = await IsV2Async(_source);
if (r)
{
_repo = new NuGet.Client.Interop.V2SourceRepository(
_source, _v2RepoFactory.CreateRepository(_source.Url), _host);
return;
}
throw new InvalidOperationException(
String.Format("source {0} is not available", _source.Url));
}
finally
{
_lock.Release();
}
}
示例9: ResolvePackage
/// <summary>
/// Resolve package from online and local repository
/// Used for Install-Package and Update-Package command to verify the specified package version exists in the repo.
/// </summary>
/// <param name="sourceRepository"></param>
/// <param name="localRepository"></param>
/// <param name="identity"></param>
/// <param name="allowPrereleaseVersions"></param>
/// <returns></returns>
public static PackageIdentity ResolvePackage(SourceRepository sourceRepository, IPackageRepository localRepository,
PackageIdentity identity, bool allowPrereleaseVersions)
{
string packageId = identity.Id;
NuGetVersion nVersion = identity.Version;
string version = identity.Version.ToNormalizedString();
if (String.IsNullOrEmpty(identity.Id))
{
throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "packageId");
}
PackageIdentity resolvedIdentity = null;
// If we're looking for an exact version of a package then try local first
if (version != null)
{
SemanticVersion sVersion = new SemanticVersion(version);
IPackage package = localRepository.FindPackage(packageId, sVersion, allowPrereleaseVersions, allowUnlisted: false);
if (package != null)
{
resolvedIdentity = new PackageIdentity(packageId, NuGetVersion.Parse(package.Version.ToString()));
}
}
if (resolvedIdentity == null)
{
if (nVersion == null)
{
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
NuGetResources.UnknownPackageSpecificVersion, packageId, version));
}
else
{
Task<JObject> task = sourceRepository.GetPackageMetadata(packageId, nVersion);
JObject package = task.Result;
if (package == null)
{
if (version != null)
{
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
NuGetResources.UnknownPackageSpecificVersion, packageId, version));
}
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
NuGetResources.UnknownPackage, packageId));
}
else
{
resolvedIdentity = new PackageIdentity(packageId, nVersion);
}
}
}
return resolvedIdentity;
}
示例10: CreateInstallProjectAction
public static NuGetProjectAction CreateInstallProjectAction(PackageIdentity packageIdentity, SourceRepository sourceRepository)
{
if(sourceRepository == null)
{
throw new ArgumentNullException("sourceRepository");
}
return new NuGetProjectAction(packageIdentity, NuGetProjectActionType.Install, sourceRepository);
}
示例11: ActionResolver
public ActionResolver(
SourceRepository source,
SourceRepository dependencyResolutionSource,
ResolutionContext context)
{
_source = source;
_dependencyResolver = new DependencyResolverFromSourceRepo(dependencyResolutionSource);
_context = context;
}
示例12: SourceRepositoryDependencyProvider
public SourceRepositoryDependencyProvider(
SourceRepository sourceRepository,
ILogger logger,
bool noCache)
{
_sourceRepository = sourceRepository;
_logger = logger;
_noCache = noCache;
}
示例13: ValidateConnection
public override void ValidateConnection(SourceRepository repo)
{
if (repo != null)
{
if (string.IsNullOrEmpty(repo.RemoteUrl))
this.ExecuteGitCommand(repo, "log -n 1"); // show commit log, limit to 1 commit
else
this.ExecuteGitCommand(repo, "ls-remote --heads origin"); // list remote branches
}
}
示例14: PackageAction
public PackageAction(PackageActionType actionType, PackageIdentity packageName, JObject package, InstallationTarget target, SourceRepository source, PackageIdentity dependentPackage)
{
ActionType = actionType;
PackageIdentity = packageName;
Package = package;
Target = target;
Source = source;
DependentPackage = dependentPackage;
IsUpdate = false;
}
示例15: TryCreate
public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceRepository source, CancellationToken token)
{
PSSearchResource resource = null;
UISearchResource uiSearchResource = await source.GetResourceAsync<UISearchResource>(token);
if (uiSearchResource != null)
{
resource = new PowerShellSearchResourceV2(uiSearchResource);
}
return new Tuple<bool, INuGetResource>(resource != null, resource);
}