public async Task TackUserIpAddress(Guid siteId, Guid userGuid) { if (context == null) { return; } if( userGuid == Guid.Empty) { return; } try { var connection = context.Connection; if (connection == null) return; var ip = connection.RemoteIpAddress; if (ip == null) return; var ipv4 = ip.MapToIPv4(); string ipv4Address = ipv4.ToString(); //Connection.RemoteIpAddress.MapToIPv4().ToLong() if (string.IsNullOrEmpty(ipv4Address)) { return; } long ip4aslong = ipv4.ToLong(); if (ip4aslong == 0) { return; } //string hostName = context.Connection. //doesnt seem a good way to get client host name but that doesn't often have any meaning value anyway var userLocation = await queries.FetchLocationByUserAndIpv4Address(siteId, userGuid, ip4aslong, CancellationToken); if (userLocation == null) { userLocation = new UserLocation(); userLocation.SiteId = siteId; userLocation.UserId = userGuid; userLocation.IpAddress = ipv4Address; userLocation.IpAddressLong = ip4aslong; userLocation.FirstCaptureUtc = DateTime.UtcNow; userLocation.LastCaptureUtc = userLocation.FirstCaptureUtc; userLocation.CaptureCount = 1; await commands.AddUserLocation(userLocation, CancellationToken.None) .ConfigureAwait(false); } else { userLocation.LastCaptureUtc = DateTime.UtcNow; userLocation.CaptureCount += 1; await commands.UpdateUserLocation(userLocation, CancellationToken.None) .ConfigureAwait(false); } } catch (Exception ex) { log.LogError("error in iptracker", ex); } }
public static UserLocation FromIUserLocation(IUserLocation i) { UserLocation l = new UserLocation(); l.CaptureCount = i.CaptureCount; l.City = i.City; l.Continent = i.Continent; l.Country = i.Country; l.FirstCaptureUtc = i.FirstCaptureUtc; l.HostName = i.HostName; l.IpAddress = i.IpAddress; l.IpAddressLong = i.IpAddressLong; l.LastCaptureUtc = i.LastCaptureUtc; l.Latitude = i.Latitude; l.Longitude = i.Longitude; l.Region = i.Region; l.Id = i.Id; l.SiteId = i.SiteId; l.TimeZone = i.TimeZone; l.UserId = i.UserId; return(l); }
public static UserLocation FromIUserLocation(IUserLocation i) { UserLocation l = new UserLocation(); l.CaptureCount = i.CaptureCount; l.City = i.City; l.Continent = i.Continent; l.Country = i.Country; l.FirstCaptureUtc = i.FirstCaptureUtc; l.HostName = i.HostName; l.IpAddress = i.IpAddress; l.IpAddressLong = i.IpAddressLong; l.LastCaptureUtc = i.LastCaptureUtc; l.Latitude = i.Latitude; l.Longitude = i.Longitude; l.Region = i.Region; l.RowId = i.RowId; l.SiteGuid = i.SiteGuid; l.TimeZone = i.TimeZone; l.UserGuid = i.UserGuid; return l; }
public static UserLocation FromIUserLocation(IUserLocation i) { UserLocation l = new UserLocation { CaptureCount = i.CaptureCount, City = i.City, Continent = i.Continent, Country = i.Country, FirstCaptureUtc = i.FirstCaptureUtc, HostName = i.HostName, IpAddress = i.IpAddress, IpAddressLong = i.IpAddressLong, LastCaptureUtc = i.LastCaptureUtc, Latitude = i.Latitude, Longitude = i.Longitude, Region = i.Region, Id = i.Id, SiteId = i.SiteId, TimeZone = i.TimeZone, UserId = i.UserId }; return(l); }
public async Task<IList<IUserLocation>> GetUserLocationsByUser( Guid userGuid, int pageNumber, int pageSize, CancellationToken cancellationToken = default(CancellationToken) ) { cancellationToken.ThrowIfCancellationRequested(); List<IUserLocation> userLocationList = new List<IUserLocation>(); using (DbDataReader reader = await dbUserLocation.GetPageByUser( userGuid, pageNumber, pageSize, cancellationToken) ) { while (reader.Read()) { UserLocation userLocation = new UserLocation(); userLocation.LoadFromReader(reader); userLocationList.Add(userLocation); } } return userLocationList; }
public async Task<IUserLocation> FetchByUserAndIpv4Address( Guid userGuid, long ipv4AddressAsLong, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); using (DbDataReader reader = await dbUserLocation.GetOne( userGuid, ipv4AddressAsLong, cancellationToken) ) { if (reader.Read()) { UserLocation userLocation = new UserLocation(); userLocation.LoadFromReader(reader); return userLocation; } } return null; }