<commit_before>// Copyright (c) 2014-2020 <NAME>, All Rights Reserved.
// The Apache v2. See License.txt in the project root for license information.

using System;
using System.Linq;

using Microsoft.AspNetCore.Http;

namespace Wangkanai.Detection
{
    public class BaseResolver : IResolver
    {
        /// <summary>
        /// Get user agnet of the request client
        /// </summary>
        public IUserAgent UserAgent => _service.UserAgent;

        /// <summary>
        /// Get HttpContext of the application service
        /// </summary>
        protected HttpContext Context => _service.Context;

        protected readonly IUserAgentService _service;

        public BaseResolver(
            IUserAgentService service)
        {
            if (service == null)
                throw new BaseResolverArgumentNullException(nameof(service));

            _service = service;
        }

        protected string GetUserAgent()
        {
            if (Context == null || !Context.Request.Headers["User-Agent"].Any())
                return "";

            return new UserAgent(Context.Request.Headers["User-Agent"].FirstOrDefault())
                .ToString()
                .ToLowerInvariant();
        }
    }
}<commit_msg>refactor base resolver<commit_after>// Copyright (c) 2014-2020 <NAME>, All Rights Reserved.
// The Apache v2. See License.txt in the project root for license information.

using System;
using System.Linq;

using Microsoft.AspNetCore.Http;

namespace Wangkanai.Detection
{
    public class BaseResolver : IResolver
    {
        /// <summary>
        /// Get user agnet of the request client
        /// </summary>
        public IUserAgent UserAgent => _service.UserAgent;

        /// <summary>
        /// Get HttpContext of the application service
        /// </summary>
        protected HttpContext Context => _service.Context;
        protected readonly IUserAgentService _service;

        public BaseResolver(IUserAgentService service)
            => _service = service ?? throw new BaseResolverArgumentNullException(nameof(service));

        protected string GetUserAgent()
        {
            if (Context == null || !Context.Request.Headers["User-Agent"].Any())
                return "";

            return new UserAgent(Context.Request.Headers["User-Agent"].FirstOrDefault())
                .ToString()
                .ToLowerInvariant();
        }
    }
}
{'fraction_non_alphanumeric': 0.10132340777502068, 'fraction_numerical': 0.007444168734491315, 'mean_word_length': 2.1172680412371134, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6424224', 'n_tokens_mistral': 611, 'n_tokens_neox': 584, 'n_words': 170}