Beispiel #1
0
        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);
        }
Beispiel #2
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;
        }