本文整理汇总了C#中PackageSource类的典型用法代码示例。如果您正苦于以下问题:C# PackageSource类的具体用法?C# PackageSource怎么用?C# PackageSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PackageSource类属于命名空间,在下文中一共展示了PackageSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSourceRepoPackageSourcesChanged
public void TestSourceRepoPackageSourcesChanged()
{
// Arrange
var localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var localPackageSource = new PackageSource(localAppDataPath);
var oldPackageSources = new List<PackageSource>() { localPackageSource };
var packageSourceProvider = new TestPackageSourceProvider(oldPackageSources);
var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(packageSourceProvider);
// Act
var oldEffectivePackageSources = sourceRepositoryProvider.GetRepositories().ToList();
// Assert
Assert.Equal(1, oldEffectivePackageSources.Count);
Assert.Equal(localAppDataPath, oldEffectivePackageSources[0].PackageSource.Source);
// Main Act
var newPackageSources = new List<PackageSource>() { TestSourceRepositoryUtility.V3PackageSource, localPackageSource };
packageSourceProvider.SavePackageSources(newPackageSources);
var newEffectivePackageSources = sourceRepositoryProvider.GetRepositories().ToList();
// Main Assert
Assert.Equal(2, newEffectivePackageSources.Count);
Assert.Equal(TestSourceRepositoryUtility.V3PackageSource.Source, newEffectivePackageSources[0].PackageSource.Source);
Assert.Equal(localAppDataPath, newEffectivePackageSources[1].PackageSource.Source);
}
示例2: 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 repositoryProvider = solutionManager.SourceRepositoryProvider;
var source = new PackageSource ("http://test.com");
repositoryProvider.AddRepository (source);
primaryRepositories = repositoryProvider.Repositories;
action = new TestableReinstallNuGetPackageAction (
project,
solutionManager);
packageManagementEvents = action.PackageManagementEvents;
fileRemover = action.FileRemover;
action.PackageId = packageId;
action.Version = new NuGetVersion (version);
uninstallPackageManager = action.UninstallAction.PackageManager;
installPackageManager = action.InstallAction.PackageManager;
}
示例3: CreateRepository
public virtual IPackageRepository CreateRepository(PackageSource packageSource)
{
if (packageSource == null) {
throw new ArgumentNullException("packageSource");
}
if (packageSource.IsAggregate) {
throw new NotSupportedException();
}
Uri uri = new Uri(packageSource.Source);
if (uri.IsFile) {
return new LocalPackageRepository(uri.LocalPath);
}
try {
uri = _httpClient.GetRedirectedUri(uri);
}
catch (Exception exception) {
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
NuGetResources.UnavailablePackageSource, packageSource),
exception);
}
// Make sure we get resolve any fwlinks before creating the repository
return new DataServicePackageRepository(uri, _httpClient);
}
示例4: 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);
}
示例5: Create
public override async Task<Resource> Create(PackageSource source)
{
try
{
object repo = null;
string host = "TestHost";
// Check if the source is already present in the cache.
if (!packageSourceCache.TryGetValue(source.Url, out repo))
{
// if it's not in cache, then check if it is V2.
if (await V2Utilities.IsV2(source))
{
// Get a IPackageRepo object and add it to the cache.
repo = V2Utilities.GetV2SourceRepository(source, host);
packageSourceCache.Add(source.Url, repo);
}
else
{
// if it's not V2, returns null
return null;
}
}
// Create a resource and return it.
var resource = new V2Resource((IPackageRepository)repo, host);
return resource;
}
catch (Exception)
{
// *TODOs:Do tracing and throw apppropriate exception here.
return null;
}
}
示例6: CreateV3PreviewSource
private static PackageSource CreateV3PreviewSource()
{
var source = new PackageSource(
Strings.VsSourceRepositoryManager_V3SourceName,
NuGetConstants.V3FeedUrl);
return source;
}
示例7: TryGetCredentialAndProxy
private HttpMessageHandler TryGetCredentialAndProxy(PackageSource packageSource)
{
Uri uri = new Uri(packageSource.Source);
var proxy = ProxyCache.Instance.GetProxy(uri);
var credential = CredentialStore.Instance.GetCredentials(uri);
if (proxy != null && proxy.Credentials == null) {
proxy.Credentials = CredentialCache.DefaultCredentials;
}
if (credential == null && !String.IsNullOrEmpty(packageSource.UserName) && !String.IsNullOrEmpty(packageSource.Password))
{
var cache = new CredentialCache();
foreach (var scheme in _authenticationSchemes)
{
cache.Add(uri, scheme, new NetworkCredential(packageSource.UserName, packageSource.Password));
}
credential = cache;
}
if (proxy == null && credential == null) return null;
else
{
if(proxy != null) ProxyCache.Instance.Add(proxy);
if (credential != null) CredentialStore.Instance.Add(uri, credential);
return new WebRequestHandler()
{
Proxy = proxy,
Credentials = credential
};
}
}
示例8: TryLoad
public static bool TryLoad(string uriOrPath, out PackageSource packageSource)
{
try
{
Uri path;
if (!Uri.TryCreate(uriOrPath, UriKind.RelativeOrAbsolute, out path))
{
packageSource = null;
return false;
}
var resolvedPath = path.IsAbsoluteUri ? path.LocalPath : uriOrPath;
if (File.Exists(resolvedPath))
{
packageSource = PackageSource.FromJson(File.OpenRead(resolvedPath), uriOrPath);
return true;
}
}
catch (Exception e)
{
// TODO: proper logging
if (Environment.IsDebug)
{
Console.Error.WriteLine($"Unable to load local file index '{uriOrPath}'");
Console.Error.WriteLine(e);
}
}
packageSource = null;
return false;
}
示例9: IsV2
public static async Task<bool> IsV2(PackageSource source)
{
var url = new Uri(source.Url);
// If the url is a directory, then it's a V2 source
if (url.IsFile || url.IsUnc)
{
return !File.Exists(url.LocalPath);
}
using (var client = new Data.DataClient())
{
var result = await client.GetFile(url);
if (result == null)
{
return false;
}
var raw = result.Value<string>("raw");
if (raw != null && raw.IndexOf("Packages", StringComparison.OrdinalIgnoreCase) != -1)
{
return true;
}
return false;
}
}
示例10: 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;
}
示例11: RemoteV2FindPackageByIdResourcce
public RemoteV2FindPackageByIdResourcce(PackageSource packageSource)
{
_baseUri = packageSource.Source.EndsWith("/") ? packageSource.Source : (packageSource.Source + "/");
_httpSource = new HttpSource(new Uri(_baseUri), packageSource.UserName, packageSource.Password);
PackageSource = packageSource;
}
示例12: AddFromExtension
public void AddFromExtension(ISourceRepositoryProvider provider, string extensionId)
{
string path = GetExtensionRepositoryPath(extensionId, null, _errorHandler);
PackageSource source = new PackageSource(path);
_repositories.Add(provider.CreateRepository(source));
}
示例13: AddFromRegistry
public void AddFromRegistry(string keyName)
{
string path = GetRegistryRepositoryPath(keyName, null, _errorHandler);
PackageSource source = new PackageSource(path);
_repositories.Add(_provider.CreateRepository(source));
}
示例14: CreateRepository
public IPackageRepository CreateRepository(PackageSource packageSource)
{
IPackageRepository repository = GetExistingRepository(packageSource);
if (repository != null) {
return repository;
}
return CreateNewCachedRepository(packageSource);
}
示例15: RegisteredPackageSource
public RegisteredPackageSource(PackageSource packageSource)
{
Source = packageSource.Source;
Name = packageSource.Name;
IsEnabled = packageSource.IsEnabled;
UserName = packageSource.UserName;
Password = packageSource.Password;
}