예제 #1
0
        private async Task SetBrowserOsAndDeviceFromUserAgent(RequestInfo request, EventContext context) {
            var info = await _parser.ParseAsync(request.UserAgent, context.Project.Id).AnyContext();
            if (info != null) {
                if (!String.Equals(info.UserAgent.Family, "Other")) {
                    request.Data[RequestInfo.KnownDataKeys.Browser] = info.UserAgent.Family;
                    if (!String.IsNullOrEmpty(info.UserAgent.Major)) {
                        request.Data[RequestInfo.KnownDataKeys.BrowserVersion] = String.Join(".", new[] { info.UserAgent.Major, info.UserAgent.Minor, info.UserAgent.Patch }.Where(v => !String.IsNullOrEmpty(v)));
                        request.Data[RequestInfo.KnownDataKeys.BrowserMajorVersion] = info.UserAgent.Major;
                    }
                }

                if (!String.Equals(info.Device.Family, "Other"))
                    request.Data[RequestInfo.KnownDataKeys.Device] = info.Device.Family;

                if (!String.Equals(info.OS.Family, "Other")) {
                    request.Data[RequestInfo.KnownDataKeys.OS] = info.OS.Family;
                    if (!String.IsNullOrEmpty(info.OS.Major)) {
                        request.Data[RequestInfo.KnownDataKeys.OSVersion] = String.Join(".", new[] { info.OS.Major, info.OS.Minor, info.OS.Patch }.Where(v => !String.IsNullOrEmpty(v)));
                        request.Data[RequestInfo.KnownDataKeys.OSMajorVersion] = info.OS.Major;
                    }
                }

                var botPatterns = context.Project.Configuration.Settings.GetStringCollection(SettingsDictionary.KnownKeys.UserAgentBotPatterns).ToList();
                request.Data[RequestInfo.KnownDataKeys.IsBot] = info.Device.IsSpider || request.UserAgent.AnyWildcardMatches(botPatterns);
            }
        }
예제 #2
0
        private void AddClientIPAddress(RequestInfo request, string clientIPAddress) {
            if (String.IsNullOrEmpty(clientIPAddress))
                return;

            if (clientIPAddress.IsLocalHost())
                clientIPAddress = "127.0.0.1";

            var ips = (request.ClientIpAddress ?? String.Empty)
                .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(ip => ip.Trim())
                .Where(ip => !ip.IsLocalHost())
                .ToList();

            if (ips.Count == 0 || !clientIPAddress.IsLocalHost())
                ips.Add(clientIPAddress);

            request.ClientIpAddress = ips.Distinct().ToDelimitedString();
        }
예제 #3
0
        /// <summary>
        /// Adds the request info to the event.
        /// </summary>
        public static void AddRequestInfo(this Event ev, RequestInfo request) {
            if (request == null)
                return;

            ev.Data[Event.KnownDataKeys.RequestInfo] = request;
        }
예제 #4
0
 protected bool Equals(RequestInfo other)
 {
     return string.Equals(UserAgent, other.UserAgent) && string.Equals(HttpMethod, other.HttpMethod) && IsSecure == other.IsSecure && string.Equals(Host, other.Host) && Port == other.Port && string.Equals(Path, other.Path) && string.Equals(Referrer, other.Referrer) && string.Equals(ClientIpAddress, other.ClientIpAddress) && Cookies.CollectionEquals(other.Cookies) && QueryString.CollectionEquals(other.QueryString) && Equals(Data, other.Data);
 }