<commit_before>using System;
using System.Globalization;
using NuGet.Resources;

namespace NuGet {
    public class PackageRepositoryFactory {
        private static readonly PackageRepositoryFactory _default = new PackageRepositoryFactory();
        private IHttpClient _httpClient;

        public PackageRepositoryFactory() : this(new HttpClient()) { }

        public PackageRepositoryFactory(IHttpClient httpClient) {
            _httpClient = httpClient;
        }

        public static PackageRepositoryFactory Default {
            get {
                return _default;
            }
        }

        public virtual IPackageRepository CreateRepository(string source) {
            if (source == null) {
                throw new ArgumentNullException("source");
            }

            Uri uri = new Uri(source);
            try {
                uri = _httpClient.GetRedirectedUri(uri);
            }
            catch (Exception exception) {
                throw new InvalidOperationException(
                    String.Format(CultureInfo.CurrentCulture,
                    null, source), 
                    exception);
            }

            // Make sure we get resolve any fwlinks before creating the repository
            return new DataServicePackageRepository(uri, _httpClient);
        }
    }
}
<commit_msg>[Package Explorer] Set user agent when downloading packages from nuget feed.<commit_after>using System;
using System.Globalization;
using NuGet.Resources;

namespace NuGet {
    public class PackageRepositoryFactory {
        private static readonly PackageRepositoryFactory _default = new PackageRepositoryFactory();
        private IHttpClient _httpClient;
        private const string _UserAgentPattern = "NuGet Package Explorer/{0} ({1})";

        public PackageRepositoryFactory() : this(new HttpClient()) { }

        public PackageRepositoryFactory(IHttpClient httpClient) {
            _httpClient = httpClient;

            var version = typeof(GalleryServer).Assembly.GetNameSafe().Version;
            var userAgent = String.Format(CultureInfo.InvariantCulture, _UserAgentPattern, version, Environment.OSVersion);
            httpClient.UserAgent = userAgent;
        }

        public static PackageRepositoryFactory Default {
            get {
                return _default;
            }
        }

        public virtual IPackageRepository CreateRepository(string source) {
            if (source == null) {
                throw new ArgumentNullException("source");
            }

            Uri uri = new Uri(source);
            try {
                uri = _httpClient.GetRedirectedUri(uri);
            }
            catch (Exception exception) {
                throw new InvalidOperationException(
                    String.Format(CultureInfo.CurrentCulture,
                    null, source), 
                    exception);
            }

            // Make sure we get resolve any fwlinks before creating the repository
            return new DataServicePackageRepository(uri, _httpClient);
        }
    }
}

{'fraction_non_alphanumeric': 0.06372239747634069, 'fraction_numerical': 0.0006309148264984228, 'mean_word_length': 1.8388540734109222, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2018413', 'n_tokens_mistral': 711, 'n_tokens_neox': 664, 'n_words': 189}