コード例 #1
0
        public static void Run(UpdateSourceArgs args, Func <ILogger> getLogger)
        {
            var settings       = RunnerHelper.GetSettings(args.Configfile);
            var sourceProvider = RunnerHelper.GetSourceProvider(settings);

            var existingSource = sourceProvider.GetPackageSourceByName(args.Name);

            if (existingSource == null)
            {
                throw new CommandException(Strings.SourcesCommandNoMatchingSourcesFound, args.Name);
            }

            if (!string.IsNullOrEmpty(args.Source) && !existingSource.Source.Equals(args.Source, StringComparison.OrdinalIgnoreCase))
            {
                if (!PathValidator.IsValidSource(args.Source))
                {
                    throw new CommandException(Strings.SourcesCommandInvalidSource);
                }

                // If the user is updating the source, verify we don't have a duplicate.
                var duplicateSource = sourceProvider.GetPackageSourceBySource(args.Source);
                if (duplicateSource != null)
                {
                    throw new CommandException(Strings.SourcesCommandUniqueSource);
                }

                existingSource = new Configuration.PackageSource(args.Source, existingSource.Name);

                // If the existing source is not http, warn the user
                if (existingSource.IsHttp && !existingSource.IsHttps)
                {
                    getLogger().LogWarning(string.Format(CultureInfo.CurrentCulture, Strings.Warning_HttpServerUsage, "update source", args.Source));
                }
            }

            RunnerHelper.ValidateCredentials(args.Username, args.Password, args.ValidAuthenticationTypes);

            if (!string.IsNullOrEmpty(args.Username))
            {
                var hasExistingAuthTypes = existingSource.Credentials?.ValidAuthenticationTypes.Any() ?? false;
                if (hasExistingAuthTypes && string.IsNullOrEmpty(args.ValidAuthenticationTypes))
                {
                    getLogger().LogMinimal(string.Format(CultureInfo.CurrentCulture,
                                                         Strings.SourcesCommandClearingExistingAuthTypes, args.Name));
                }

                var credentials = Configuration.PackageSourceCredential.FromUserInput(
                    args.Name,
                    args.Username,
                    args.Password,
                    args.StorePasswordInClearText,
                    args.ValidAuthenticationTypes);
                existingSource.Credentials = credentials;
            }

            sourceProvider.UpdatePackageSource(existingSource, updateCredentials: existingSource.Credentials != null, updateEnabled: false);

            getLogger().LogMinimal(string.Format(CultureInfo.CurrentCulture,
                                                 Strings.SourcesCommandUpdateSuccessful, args.Name));
        }
コード例 #2
0
        public void TestSourceRepoPackageSourcesChanged()
        {
            // Arrange
            var localAppDataPath   = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            var localPackageSource = new Configuration.PackageSource(localAppDataPath);
            var oldPackageSources  = new List <Configuration.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 <Configuration.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);
        }
コード例 #3
0
ファイル: V2Utilities.cs プロジェクト: anthrax3/NuGet3
        public static IPackageRepository GetV2SourceRepository(Configuration.PackageSource source)
        {
            IPackageRepository     repo    = new PackageRepositoryFactory().CreateRepository(source.Source);
            LocalPackageRepository _lprepo = repo as LocalPackageRepository;

            if (_lprepo != null)
            {
                return(_lprepo);
            }
            string _userAgent = UserAgentUtil.GetUserAgent("NuGet.Client.Interop", "host");
            var    events     = repo as IHttpClientEvents;

            if (events != null)
            {
                events.SendingRequest += (sender, args) =>
                {
                    var httpReq = args.Request as HttpWebRequest;
                    if (httpReq != null)
                    {
                        httpReq.UserAgent = _userAgent;
                    }
                };
            }
            return(repo);
        }
コード例 #4
0
        /// <summary>
        /// Create a PreFetcher result for a downloaded package.
        /// </summary>
        public PackagePreFetcherResult(
            Task <DownloadResourceResult> downloadTask,
            PackageIdentity package,
            Configuration.PackageSource source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (downloadTask == null)
            {
                throw new ArgumentNullException(nameof(downloadTask));
            }

            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            _downloadTask      = downloadTask;
            Package            = package;
            InPackagesFolder   = false;
            Source             = source;
            _downloadStartTime = DateTimeOffset.Now;
        }
コード例 #5
0
        public UpdatePackageFeedTests()
        {
            // dependencies and data
            _metadataResource = Mock.Of <PackageMetadataResource>();

            var provider = Mock.Of <INuGetResourceProvider>();

            Mock.Get(provider)
            .Setup(x => x.TryCreate(It.IsAny <SourceRepository>(), It.IsAny <CancellationToken>()))
            .Returns(() => Task.FromResult(Tuple.Create(true, (INuGetResource)_metadataResource)));
            Mock.Get(provider)
            .Setup(x => x.ResourceType)
            .Returns(typeof(PackageMetadataResource));

            var logger        = new TestLogger();
            var packageSource = new Configuration.PackageSource("http://fake-source");
            var source        = new SourceRepository(packageSource, new[] { provider });

            // target
            _metadataProvider = new MultiSourcePackageMetadataProvider(
                new[] { source },
                optionalLocalRepository: null,
                optionalGlobalLocalRepositories: null,
                logger: logger);
        }
コード例 #6
0
        public void AddFromExtension(ISourceRepositoryProvider provider, string extensionId)
        {
            string path = GetExtensionRepositoryPath(extensionId, null, _errorHandler);

            var source = new Configuration.PackageSource(path);

            _repositories.Add(CreateRepository(source));
        }
コード例 #7
0
        private void UpdatePackageSource()
        {
            if (String.IsNullOrEmpty(Name))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired"));
            }

            var sourceList          = SourceProvider.LoadPackageSources().ToList();
            int existingSourceIndex = sourceList.FindIndex(ps => Name.Equals(ps.Name, StringComparison.OrdinalIgnoreCase));

            if (existingSourceIndex == -1)
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNoMatchingSourcesFound"), Name);
            }
            var existingSource = sourceList[existingSourceIndex];

            if (!String.IsNullOrEmpty(Source) && !existingSource.Source.Equals(Source, StringComparison.OrdinalIgnoreCase))
            {
                if (!PathValidator.IsValidSource(Source))
                {
                    throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandInvalidSource"));
                }

                // If the user is updating the source, verify we don't have a duplicate.
                bool duplicateSource = sourceList.Any(ps => String.Equals(Source, ps.Source, StringComparison.OrdinalIgnoreCase));
                if (duplicateSource)
                {
                    throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandUniqueSource"));
                }
                existingSource = new Configuration.PackageSource(Source, existingSource.Name);
            }

            ValidateCredentials();

            sourceList.RemoveAt(existingSourceIndex);

            if (!string.IsNullOrEmpty(UserName))
            {
                var hasExistingAuthTypes = existingSource.Credentials?.ValidAuthenticationTypes.Any() ?? false;
                if (hasExistingAuthTypes && string.IsNullOrEmpty(ValidAuthenticationTypes))
                {
                    Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandClearingExistingAuthTypes"), Name);
                }

                var credentials = Configuration.PackageSourceCredential.FromUserInput(
                    Name,
                    UserName,
                    Password,
                    StorePasswordInClearText,
                    ValidAuthenticationTypes);
                existingSource.Credentials = credentials;
            }


            sourceList.Insert(existingSourceIndex, existingSource);
            SourceProvider.SavePackageSources(sourceList);
            Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandUpdateSuccessful"), Name);
        }
コード例 #8
0
        public SettingsCredentialProvider(Configuration.PackageSource source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            _source = source;
        }
コード例 #9
0
 public GatherSingleCacheKey(
     PackageIdentity package,
     Configuration.PackageSource source,
     NuGetFramework framework)
 {
     Package   = package;
     Source    = source;
     Framework = framework;
 }
コード例 #10
0
 public GatherAllCacheKey(
     string packageId,
     Configuration.PackageSource source,
     NuGetFramework framework)
 {
     PackageId = packageId;
     Source    = source;
     Framework = framework;
 }
コード例 #11
0
        public SettingsCredentialProvider(Configuration.PackageSource source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            _source = source;
        }
コード例 #12
0
        /// <summary>
        /// Add a single package
        /// </summary>
        public void AddPackageFromSingleVersionLookup(
            Configuration.PackageSource source,
            PackageIdentity identity,
            NuGetFramework framework,
            SourcePackageDependencyInfo package)
        {
            var key = new GatherSingleCacheKey(identity, source, framework);

            _singleVersion.TryAdd(key, package);
        }
コード例 #13
0
        /// <summary>
        /// Add the full list of versions for a package
        /// </summary>
        public void AddAllPackagesForId(
            Configuration.PackageSource source,
            string packageId,
            NuGetFramework framework,
            List <SourcePackageDependencyInfo> packages)
        {
            var key = new GatherAllCacheKey(packageId, source, framework);

            _allPackageVersions.TryAdd(key, packages);
        }
コード例 #14
0
        private async Task AddNewSourceAsync()
        {
            if (string.IsNullOrEmpty(Name))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired"));
            }
            if (string.Equals(Name, LocalizedResourceManager.GetString("ReservedPackageNameAll")))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandAllNameIsReserved"));
            }
            if (string.IsNullOrEmpty(Source))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandSourceRequired"));
            }
            // Make sure that the Source given is a valid one.
            if (!PathValidator.IsValidSource(Source))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandInvalidSource"));
            }

            ValidateCredentials();

            // Check to see if we already have a registered source with the same name or source
            var sourceList = SourceProvider.LoadPackageSources().ToList();
            var hasName    = sourceList.Any(ps => string.Equals(Name, ps.Name, StringComparison.OrdinalIgnoreCase));

            if (hasName)
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandUniqueName"));
            }
            var hasSource = sourceList.Any(ps => string.Equals(Source, ps.Source, StringComparison.OrdinalIgnoreCase));

            if (hasSource)
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandUniqueSource"));
            }

            var newPackageSource = new Configuration.PackageSource(Source, Name);

            if (!string.IsNullOrEmpty(UserName))
            {
                var credentials = Configuration.PackageSourceCredential.FromUserInput(Name, UserName, Password, StorePasswordInClearText);
                newPackageSource.Credentials = credentials;
            }

            if (Trust)
            {
                await UpdateTrustedSourceAsync(newPackageSource);
            }

            sourceList.Add(newPackageSource);
            SourceProvider.SavePackageSources(sourceList);
            Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandSourceAddedSuccessfully"), Name);
        }
コード例 #15
0
        private void UpdatePackageSource()
        {
            if (string.IsNullOrEmpty(Name))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired"));
            }

            var existingSource = SourceProvider.GetPackageSourceByName(Name);

            if (existingSource == null)
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNoMatchingSourcesFound"), Name);
            }

            if (!string.IsNullOrEmpty(Source) && !existingSource.Source.Equals(Source, StringComparison.OrdinalIgnoreCase))
            {
                if (!PathValidator.IsValidSource(Source))
                {
                    throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandInvalidSource"));
                }

                // If the user is updating the source, verify we don't have a duplicate.
                var duplicateSource = SourceProvider.GetPackageSourceBySource(Source);
                if (duplicateSource != null)
                {
                    throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandUniqueSource"));
                }
                existingSource = new Configuration.PackageSource(Source, existingSource.Name);
            }

            ValidateCredentials();

            if (!string.IsNullOrEmpty(Username))
            {
                var hasExistingAuthTypes = existingSource.Credentials?.ValidAuthenticationTypes.Any() ?? false;
                if (hasExistingAuthTypes && string.IsNullOrEmpty(ValidAuthenticationTypes))
                {
                    Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandClearingExistingAuthTypes"), Name);
                }

                var credentials = Configuration.PackageSourceCredential.FromUserInput(
                    Name,
                    Username,
                    Password,
                    StorePasswordInClearText,
                    ValidAuthenticationTypes);
                existingSource.Credentials = credentials;
            }

            SourceProvider.UpdatePackageSource(existingSource, updateCredentials: existingSource.Credentials != null, updateEnabled: false);

            Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandUpdateSuccessful"), Name);
        }
コード例 #16
0
        private void AddNewSource()
        {
            if (string.IsNullOrEmpty(Name))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired"));
            }
            if (string.Equals(Name, LocalizedResourceManager.GetString("ReservedPackageNameAll")))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandAllNameIsReserved"));
            }
            if (string.IsNullOrEmpty(Source))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandSourceRequired"));
            }

            // Make sure that the Source given is a valid one.
            if (!PathValidator.IsValidSource(Source))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandInvalidSource"));
            }

            ValidateCredentials();

            // Check to see if we already have a registered source with the same name or source
            var existingSourceWithName = SourceProvider.GetPackageSourceByName(Name);

            if (existingSourceWithName != null)
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandUniqueName"));
            }
            var existingSourceWithSource = SourceProvider.GetPackageSourceBySource(Source);

            if (existingSourceWithSource != null)
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandUniqueSource"));
            }

            var newPackageSource = new Configuration.PackageSource(Source, Name);

            if (!string.IsNullOrEmpty(Username))
            {
                var credentials = Configuration.PackageSourceCredential.FromUserInput(
                    Name,
                    Username,
                    Password,
                    StorePasswordInClearText,
                    ValidAuthenticationTypes);
                newPackageSource.Credentials = credentials;
            }

            SourceProvider.AddPackageSource(newPackageSource);
            Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandSourceAddedSuccessfully"), Name);
        }
コード例 #17
0
        private SourceRepositoryProvider CreateSource(List <SourcePackageDependencyInfo> packages)
        {
            var resourceProviders = new List <Lazy <INuGetResourceProvider> >();

            resourceProviders.Add(new Lazy <INuGetResourceProvider>(() => new TestDependencyInfoProvider(packages)));
            resourceProviders.Add(new Lazy <INuGetResourceProvider>(() => new TestMetadataProvider(packages)));

            var packageSource         = new Configuration.PackageSource("http://temp");
            var packageSourceProvider = new TestPackageSourceProvider(new[] { packageSource });

            return(new SourceRepositoryProvider(packageSourceProvider, resourceProviders));
        }
コード例 #18
0
        private async Task UpdatePackageSourceAsync()
        {
            if (string.IsNullOrEmpty(Name))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired"));
            }

            var sourceList          = SourceProvider.LoadPackageSources().ToList();
            var existingSourceIndex = sourceList.FindIndex(ps => Name.Equals(ps.Name, StringComparison.OrdinalIgnoreCase));

            if (existingSourceIndex == -1)
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNoMatchingSourcesFound"), Name);
            }
            var existingSource = sourceList[existingSourceIndex];

            if (!string.IsNullOrEmpty(Source) && !existingSource.Source.Equals(Source, StringComparison.OrdinalIgnoreCase))
            {
                if (!PathValidator.IsValidSource(Source))
                {
                    throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandInvalidSource"));
                }

                // If the user is updating the source, verify we don't have a duplicate.
                var duplicateSource = sourceList.Any(ps => string.Equals(Source, ps.Source, StringComparison.OrdinalIgnoreCase));
                if (duplicateSource)
                {
                    throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandUniqueSource"));
                }
                existingSource = new Configuration.PackageSource(Source, existingSource.Name);
            }

            ValidateCredentials();

            sourceList.RemoveAt(existingSourceIndex);

            if (Trust)
            {
                await UpdateTrustedSourceAsync(existingSource);
            }

            if (!string.IsNullOrEmpty(UserName))
            {
                var credentials = Configuration.PackageSourceCredential.FromUserInput(Name, UserName, Password,
                                                                                      storePasswordInClearText: StorePasswordInClearText);
                existingSource.Credentials = credentials;
            }

            sourceList.Insert(existingSourceIndex, existingSource);
            SourceProvider.SavePackageSources(sourceList);
            Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandUpdateSuccessful"), Name);
        }
コード例 #19
0
        public static bool IsV2(Configuration.PackageSource source)
        {
            var url = source.SourceUri;

            // If the url is a directory, then it's a V2 source
            if (url.IsFile ||
                url.IsUnc)
            {
                return(!File.Exists(url.LocalPath));
            }

            return(true);
        }
コード例 #20
0
        /// <summary>
        /// Retrieve all versions of a package id
        /// </summary>
        public GatherCacheResult GetPackages(
            Configuration.PackageSource source,
            string packageId,
            NuGetFramework framework)
        {
            var key = new GatherAllCacheKey(packageId, source, framework);

            List <SourcePackageDependencyInfo> result;

            var hasEntry = _allPackageVersions.TryGetValue(key, out result);

            return(new GatherCacheResult(hasEntry, result));
        }
コード例 #21
0
ファイル: V2Utilities.cs プロジェクト: anthrax3/NuGet3
        public static async Task <bool> IsV2(Configuration.PackageSource source)
        {
            var url = new Uri(source.Source);

            // If the url is a directory, then it's a V2 source
            if (url.IsFile || url.IsUnc)
            {
                return(!File.Exists(url.LocalPath));
            }
            var result = await GetContent(url);

            return(true);
        }
コード例 #22
0
 private void UpdateTextBoxes(Configuration.PackageSource packageSource)
 {
     if (packageSource != null)
     {
         NewPackageName.Text   = packageSource.Name;
         NewPackageSource.Text = packageSource.Source;
     }
     else
     {
         NewPackageName.Text   = String.Empty;
         NewPackageSource.Text = String.Empty;
     }
 }
コード例 #23
0
        public async Task MultipleSources_Works()
        {
            var solutionManager = Mock.Of <IVsSolutionManager>();
            var uiContext       = Mock.Of <INuGetUIContext>();

            Mock.Get(uiContext)
            .Setup(x => x.SolutionManager)
            .Returns(solutionManager);

            var source1 = new Configuration.PackageSource("https://dotnet.myget.org/F/nuget-volatile/api/v3/index.json", "NuGetVolatile");
            var source2 = new Configuration.PackageSource("https://api.nuget.org/v3/index.json", "NuGet.org");

            var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(new[] { source1, source2 });
            var repositories             = sourceRepositoryProvider.GetRepositories();

            var context = new PackageLoadContext(repositories, false, uiContext);

            var packageFeed = new MultiSourcePackageFeed(repositories, logger: null, telemetryService: null);
            var loader      = new PackageItemLoader(context, packageFeed, "nuget");

            var loaded = new List <PackageItemListViewModel>();

            foreach (var page in Enumerable.Range(0, 5))
            {
                await loader.LoadNextAsync(null, CancellationToken.None);

                while (loader.State.LoadingStatus == LoadingStatus.Loading)
                {
                    await Task.Delay(TimeSpan.FromSeconds(1));

                    await loader.UpdateStateAsync(null, CancellationToken.None);
                }

                var items = loader.GetCurrent();
                loaded.AddRange(items);

                if (loader.State.LoadingStatus != LoadingStatus.Ready)
                {
                    break;
                }
            }

            // All items should not have a prefix reserved because the feed is multisource
            foreach (var item in loaded)
            {
                Assert.False(item.PrefixReserved);
            }

            Assert.NotEmpty(loaded);
        }
コード例 #24
0
        private Configuration.PackageSource CreateNewPackageSource()
        {
            var sourcesList = (IEnumerable <Configuration.PackageSource>)_packageSources.List;

            for (int i = 0; ; i++)
            {
                var newName       = i == 0 ? "Package source" : "Package source " + i;
                var newSource     = i == 0 ? "http://packagesource" : "http://packagesource" + i;
                var packageSource = new Configuration.PackageSource(newSource, newName);
                if (sourcesList.All(ps => !ps.Equals(packageSource)))
                {
                    return(packageSource);
                }
            }
        }
コード例 #25
0
            protected static SourceRepository SetupSourceRepository(PackageMetadataResource resource)
            {
                var provider = Mock.Of <INuGetResourceProvider>();

                Mock.Get(provider)
                .Setup(x => x.TryCreate(It.IsAny <SourceRepository>(), It.IsAny <CancellationToken>()))
                .Returns(() => Task.FromResult(Tuple.Create(true, (INuGetResource)resource)));
                Mock.Get(provider)
                .Setup(x => x.ResourceType)
                .Returns(typeof(PackageMetadataResource));

                var packageSource = new Configuration.PackageSource("http://fake-source");

                return(new SourceRepository(packageSource, new[] { provider }));
            }
コード例 #26
0
        private static bool IsOfficial(Configuration.PackageSource source)
        {
            bool official = source.IsOfficial;

            // override the official flag if the domain is nuget.org
            if (source.Source.StartsWith("http://www.nuget.org/", StringComparison.OrdinalIgnoreCase) ||
                source.Source.StartsWith("https://www.nuget.org/", StringComparison.OrdinalIgnoreCase) ||
                source.Source.StartsWith("http://api.nuget.org/", StringComparison.OrdinalIgnoreCase) ||
                source.Source.StartsWith("https://api.nuget.org/", StringComparison.OrdinalIgnoreCase))
            {
                official = true;
            }

            return(official);
        }
コード例 #27
0
        public PackageSearchResourceV2Feed(HttpSourceResource httpSourceResource, string baseAddress, Configuration.PackageSource packageSource)
        {
            if (httpSourceResource == null)
            {
                throw new ArgumentNullException(nameof(httpSourceResource));
            }

            if (packageSource == null)
            {
                throw new ArgumentNullException(nameof(packageSource));
            }

            _httpSource    = httpSourceResource.HttpSource;
            _packageSource = packageSource;
            _feedParser    = new V2FeedParser(_httpSource, baseAddress, packageSource);
        }
コード例 #28
0
        public void AddFromRegistry(string keyName, bool isPreUnzipped)
        {
            string path = GetRegistryRepositoryPath(keyName, null, _errorHandler);

            Configuration.PackageSource source;
            if (isPreUnzipped)
            {
                source = new V2PackageSource(path, () => new UnzippedPackageRepository(path));
            }
            else
            {
                source = new Configuration.PackageSource(path);
            }

            _repositories.Add(_provider.CreateRepository(source));
        }
コード例 #29
0
        public async Task GetTotalCountAsync_Works()
        {
            var uiContext = Mock.Of <INuGetUIContext>();

            var source1 = new Configuration.PackageSource("https://dotnet.myget.org/F/nuget-volatile/api/v3/index.json", "NuGetVolatile");
            var source2 = new Configuration.PackageSource("https://api.nuget.org/v3/index.json", "NuGet.org");

            var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(new[] { source1, source2 });
            var repositories             = sourceRepositoryProvider.GetRepositories();

            var context     = new PackageLoadContext(repositories, false, uiContext);
            var packageFeed = new MultiSourcePackageFeed(repositories, logger: null);
            var loader      = new PackageItemLoader(context, packageFeed, "nuget");

            var totalCount = await loader.GetTotalCountAsync(100, CancellationToken.None);

            Assert.NotInRange(totalCount, 0, 99);
        }
コード例 #30
0
        public InstalledAndTransitivePackageFeedTests(ITestOutputHelper testOutputHelper)
        {
            _logger = new TestLogger(testOutputHelper);

            var _metadataResource = Mock.Of <PackageMetadataResource>();
            var provider          = Mock.Of <INuGetResourceProvider>();

            Mock.Get(provider)
            .Setup(x => x.TryCreate(It.IsAny <SourceRepository>(), It.IsAny <CancellationToken>()))
            .Returns(() => Task.FromResult(Tuple.Create(true, (INuGetResource)_metadataResource)));
            Mock.Get(provider)
            .Setup(x => x.ResourceType)
            .Returns(typeof(PackageMetadataResource));
            var packageSource = new Configuration.PackageSource("http://fake-source");
            var source        = new SourceRepository(source: packageSource, providers: new[] { provider });

            _packageMetadataProvider = new MultiSourcePackageMetadataProvider(sourceRepositories: new[] { source }, optionalLocalRepository: null, optionalGlobalLocalRepositories: null, logger: _logger);
        }
コード例 #31
0
        /// <summary>
        /// Create a package repository from the source by trying to resolve relative paths.
        /// </summary>
        protected SourceRepository CreateRepositoryFromSource(string source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            var packageSource = new Configuration.PackageSource(source);
            var repository    = _sourceRepositoryProvider.CreateRepository(packageSource);
            var resource      = repository.GetResource <PackageSearchResource>();

            // resource can be null here for relative path package source.
            if (resource == null)
            {
                Uri uri;
                // if it's not an absolute path, treat it as relative path
                if (Uri.TryCreate(source, UriKind.Relative, out uri))
                {
                    string outputPath;
                    bool?  exists;
                    string errorMessage;
                    // translate relative path to absolute path
                    if (TryTranslatePSPath(source, out outputPath, out exists, out errorMessage) &&
                        exists == true)
                    {
                        source        = outputPath;
                        packageSource = new Configuration.PackageSource(outputPath);
                    }
                }
            }

            var sourceRepo = _sourceRepositoryProvider.CreateRepository(packageSource);
            // Right now if packageSource is invalid, CreateRepository will not throw. Instead, resource returned is null.
            var newResource = repository.GetResource <PackageSearchResource>();

            if (newResource == null)
            {
                // Try to create Uri again to throw UriFormat exception for invalid source input.
                new Uri(source);
            }
            return(sourceRepo);
        }
コード例 #32
0
 private bool IsLocalSource()
 {
     var packageSource = new Configuration.PackageSource(V2Client.Source);
     return !packageSource.IsHttp;
 }