Example #1
0
        public V3SourceRepository(PackageSource source, string host)
        {
            _source = source;
            _root = new Uri(source.Url);

            // TODO: Get context from current UI activity (PowerShell, Dialog, etc.)
            _userAgent = UserAgentUtil.GetUserAgent("NuGet.Client", host);

            _http = new System.Net.Http.HttpClient(
                new TracingHttpHandler(
                    NuGetTraceSources.V3SourceRepository,
                    new SetUserAgentHandler(
                        _userAgent,
                        new HttpClientHandler())));

            // Check if we should disable the browser file cache
            FileCacheBase cache = new BrowserFileCache();
            if (String.Equals(Environment.GetEnvironmentVariable("NUGET_DISABLE_IE_CACHE"), "true", StringComparison.OrdinalIgnoreCase))
            {
                cache = new NullFileCache();
            }

            cache = new NullFileCache(); // +++ Disable caching for testing

            _client = new DataClient(
                _http,
                cache);
        }
        private static async Task<bool> IsV2Async(PackageSource source)
        {
            var url = new Uri(source.Url);
            if (url.IsFile || url.IsUnc)
            {
                return true;
            }

            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;
            }
        }
 public AutoDetectSourceRepository(
     PackageSource source, 
     string host,
     IPackageRepositoryFactory repoFactory)
 {
     _source = source;
     _host = host;
     _v2RepoFactory = repoFactory;
     _lock = new SemaphoreSlim(1);
 }
 public override async Task<Resource> Create(PackageSource source)
 {
     var resource = await base.Create(source);
     if (resource != null)
     {
         var v2DownloadResource = new V2DownloadResource((V2Resource)resource);
         return v2DownloadResource;
     }
     else
     {
         return null;
     }
 }
        private static SourceRepository CreateRepo(PackageSource source)
        {
            // For now, be awful. Detect V3 via the source URL itself
            Uri url;
            if (Uri.TryCreate(source.Source, UriKind.RelativeOrAbsolute, out url) &&
                StringComparer.OrdinalIgnoreCase.Equals(NuGetV3PreviewSource.Source, url.ToString()))
            {
                return new V3SourceRepository(new Client.PackageSource(source.Name, source.Source) , CommandLineConstants.UserAgent);
            }

            return null;
            //return new V2SourceRepository(source, _repoFactory.CreateRepository(source.Url), HostName);
        }
Example #6
0
        public V2SourceRepository(PackageSource source, IPackageRepository repository, string host)
        {
            _source = source;
            _repository = repository;

            // TODO: Get context from current UI activity (PowerShell, Dialog, etc.)
            _userAgent = UserAgentUtil.GetUserAgent("NuGet.Client.Interop", host);

            var events = _repository as IHttpClientEvents;
            if (events != null)
            {
                events.SendingRequest += (sender, args) =>
                {
                    var httpReq = args.Request as HttpWebRequest;
                    if (httpReq != null)
                    {
                        httpReq.UserAgent = _userAgent;
                    }
                    NuGetTraceSources.V2SourceRepository.Verbose("http", "{0} {1}", args.Request.Method, args.Request.RequestUri.ToString());
                };
            }

            _lprepo = _repository as LocalPackageRepository;
        }
        private static async Task<bool> IsV3Async(PackageSource source)
        {
            var url = new Uri(source.Url);
            if (url.IsFile || url.IsUnc)
            {
                return File.Exists(url.LocalPath);
            }

            using (var client = new Data.DataClient())
            {
                var v3index = await client.GetFile(url);
                if (v3index == null)
                {
                    return false;
                }

                var status = v3index.Value<string>("version");
                if (status != null && status.StartsWith("3.0"))
                {
                    return true;
                }

                return false;
            }
        }
 public bool IsPackageSourceEnabled(PackageSource source)
 {
     return source.IsEnabled;
 }
 public void DisablePackageSource(PackageSource source)
 {
     throw new NotSupportedException();
 }
 /// <summary>
 /// Changes the active source to the specified source.
 /// </summary>
 /// <param name="newSource"></param>
 public abstract void ChangeActiveSource(PackageSource newSource);
 public abstract SourceRepository CreateSourceRepository(PackageSource packageSource);