Example #1
0
        public NuGetPackageRepository(PackageRepositoryCreateParameters parameters)
        {
            // First validate the input package source location
            if (!parameters.ValidateLocation())
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Messages.InvalidQueryUrl, parameters.Location));
            }

            this.ResourceProvider = NuGetResourceCollectionFactory.GetResources(parameters.Location, parameters.Request);
            this.baseUrl          = parameters.Location;
        }
Example #2
0
        public IPackageRepository CreateRepository(PackageRepositoryCreateParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (parameters.Location == null)
            {
                throw new ArgumentNullException("parameters.Location");
            }

            if (parameters.Request == null)
            {
                throw new ArgumentNullException("parameters.Request");
            }

            IPackageRepository repository = ConcurrentInMemoryCache.Instance.GetOrAdd <IPackageRepository>(parameters.Location, () =>
            {
                // we cannot call new uri on file path on linux because it will error out
                if (System.IO.Directory.Exists(parameters.Location))
                {
                    return(new LocalPackageRepository(parameters.Location, parameters.Request));
                }

                Uri uri = new Uri(parameters.Location);

                if (uri.IsFile)
                {
                    return(new LocalPackageRepository(uri.LocalPath, parameters.Request));
                }

                return(new NuGetPackageRepository(parameters));
            });

            return(repository);
        }