示例#1
0
        public override void EventProcessing(EventContext context)
        {
            if (String.IsNullOrWhiteSpace(context.Event.Geo))
            {
                context.Event.Geo = null;
                return;
            }

            Location location;

            if (Location.TryParse(context.Event.Geo, out location) && location.IsValid())
            {
                context.Event.Geo = location.ToString();
                return;
            }

            foreach (var ip in GetIpAddresses(context.Event))
            {
                location = _geoIpResolver.ResolveIp(ip);
                if (location == null || !location.IsValid())
                {
                    continue;
                }

                context.Event.Geo = location.ToString();
                return;
            }

            context.Event.Geo = null;
        }
示例#2
0
        public void CanResolveIp(string ip, bool canResolve)
        {
            if (_resolver == null)
            {
                return;
            }

            var result = _resolver.ResolveIp(ip);

            if (canResolve)
            {
                Assert.NotNull(result);
            }
            else
            {
                Assert.Null(result);
            }
        }