public override async Task EventProcessingAsync(EventContext context) { 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 = await _geoIpResolver.ResolveIpAsync(ip); if (location == null || !location.IsValid()) { continue; } context.Event.Geo = location.ToString(); return; } context.Event.Geo = null; }
public override async Task EventBatchProcessingAsync(ICollection <EventContext> contexts) { var geoGroups = contexts.GroupBy(c => c.Event.Geo); foreach (var geoGroup in geoGroups) { Location location; if (Location.TryParse(geoGroup.Key, out location) && location.IsValid()) { geoGroup.ForEach(c => c.Event.Geo = location.ToString()); continue; } foreach (var context in geoGroup) { foreach (var ip in GetIpAddresses(context.Event)) { location = await _geoIpResolver.ResolveIpAsync(ip).AnyContext(); if (location == null || !location.IsValid()) { continue; } context.Event.Geo = location.ToString(); return; } context.Event.Geo = null; } } }
public async Task CanResolveIp(string ip, bool canResolve) { if (_resolver == null) { return; } var result = await _resolver.ResolveIpAsync(ip); if (canResolve) { Assert.NotNull(result); } else { Assert.Null(result); } }