public async Task AddUserLocation( IUserLocation userLocation, CancellationToken cancellationToken = default(CancellationToken) ) { ThrowIfDisposed(); cancellationToken.ThrowIfCancellationRequested(); if (userLocation == null) { throw new ArgumentException("userLocation must not be null"); } if (userLocation.Id == Guid.Empty) { throw new ArgumentException("Id must not be empty guid"); } if (userLocation.UserId == Guid.Empty) { throw new ArgumentException("UserId must not be empty guid"); } if (userLocation.SiteId == Guid.Empty) { throw new ArgumentException("SiteId must not be empty guid"); } await EnsureProjectId().ConfigureAwait(false); var ul = UserLocation.FromIUserLocation(userLocation); await locationCommands.CreateAsync( projectId, ul.Id.ToString(), ul, cancellationToken).ConfigureAwait(false); }
public async Task UpdateUserLocation( IUserLocation userLocation, CancellationToken cancellationToken = default(CancellationToken) ) { ThrowIfDisposed(); cancellationToken.ThrowIfCancellationRequested(); if (userLocation == null) { throw new ArgumentException("userLocation can't be null"); } var ul = UserLocation.FromIUserLocation(userLocation); cancellationToken.ThrowIfCancellationRequested(); bool tracking = dbContext.ChangeTracker.Entries <UserLocation>().Any(x => x.Entity.Id == ul.Id); if (!tracking) { dbContext.UserLocations.Update(ul); } int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken) .ConfigureAwait(false); }
public async Task InitializeAsync() { var filePath = Path.Combine(AppContext.BaseDirectory, DataConstants.DAT_FILE_PATH); await using var stream = _readerService.Read(filePath); DatInfo = new DatInfo(stream, 1); var records = DatInfo.Records; var ipIntervalsInformations = new IUserIp[records]; var coordinateInformations = new IUserLocation[records]; for (var index = 0; index < records; index++) { ipIntervalsInformations[index] = new UserIp(stream, index + 1); } for (var index = 0; index < records; index++) { coordinateInformations[index] = new UserLocation(stream, index + 1); } UserIps = new ConcurrentQueue <IUserIp>(ipIntervalsInformations); UserLocations = new ConcurrentQueue <IUserLocation>(coordinateInformations); }
public async Task AddUserLocation( IUserLocation userLocation, CancellationToken cancellationToken = default(CancellationToken) ) { cancellationToken.ThrowIfCancellationRequested(); if (userLocation == null) { throw new ArgumentException("userLocation can't be null"); } var ul = UserLocation.FromIUserLocation(userLocation); if (ul.Id == Guid.Empty) { ul.Id = Guid.NewGuid(); } using (var dbContext = _contextFactory.CreateContext()) { dbContext.UserLocations.Add(ul); int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken); } }
public static void LoadFromReader(this IUserLocation location, DbDataReader reader) { location.Id = new Guid(reader["RowID"].ToString()); location.UserId = new Guid(reader["UserGuid"].ToString()); location.SiteId = new Guid(reader["SiteGuid"].ToString()); location.IpAddress = reader["IPAddress"].ToString(); location.IpAddressLong = Convert.ToInt64(reader["IPAddressLong"]); location.HostName = reader["Hostname"].ToString(); location.Longitude = Convert.ToDouble(reader["Longitude"]); location.Latitude = Convert.ToDouble(reader["Latitude"]); location.Isp = reader["ISP"].ToString(); location.Continent = reader["Continent"].ToString(); location.Country = reader["Country"].ToString(); location.Region = reader["Region"].ToString(); location.City = reader["City"].ToString(); location.TimeZone = reader["TimeZone"].ToString(); location.CaptureCount = Convert.ToInt32(reader["CaptureCount"]); location.FirstCaptureUtc = Convert.ToDateTime(reader["FirstCaptureUTC"]); location.LastCaptureUtc = Convert.ToDateTime(reader["LastCaptureUTC"]); }
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 UpdateUserLocation( IUserLocation userLocation, CancellationToken cancellationToken = default(CancellationToken) ) { ThrowIfDisposed(); cancellationToken.ThrowIfCancellationRequested(); if (userLocation == null) { throw new ArgumentException("userLocation can't be null"); } var ul = UserLocation.FromIUserLocation(userLocation); cancellationToken.ThrowIfCancellationRequested(); bool tracking = dbContext.ChangeTracker.Entries<UserLocation>().Any(x => x.Entity.Id == ul.Id); if (!tracking) { dbContext.UserLocations.Update(ul); } int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken) .ConfigureAwait(false); }
public async Task AddUserLocation( IUserLocation userLocation, CancellationToken cancellationToken = default(CancellationToken) ) { ThrowIfDisposed(); cancellationToken.ThrowIfCancellationRequested(); if (userLocation == null) { throw new ArgumentException("userLocation can't be null"); } var ul = UserLocation.FromIUserLocation(userLocation); if (ul.Id == Guid.Empty) { ul.Id = Guid.NewGuid(); } dbContext.UserLocations.Add(ul); int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken); }
public async Task<bool> UpdateUserLocation( IUserLocation userLocation, CancellationToken cancellationToken = default(CancellationToken) ) { cancellationToken.ThrowIfCancellationRequested(); return await dbUserLocation.Update( userLocation.RowId, userLocation.UserGuid, userLocation.SiteGuid, userLocation.IpAddress, userLocation.IpAddressLong, userLocation.HostName, userLocation.Longitude, userLocation.Latitude, userLocation.Isp, userLocation.Continent, userLocation.Country, userLocation.Region, userLocation.City, userLocation.TimeZone, userLocation.CaptureCount, userLocation.LastCaptureUtc, cancellationToken ); }
public async Task<bool> UpdateUserLocation( IUserLocation userLocation, CancellationToken cancellationToken = default(CancellationToken) ) { if (userLocation == null) { return false; } UserLocation ul = UserLocation.FromIUserLocation(userLocation); cancellationToken.ThrowIfCancellationRequested(); bool tracking = dbContext.ChangeTracker.Entries<UserLocation>().Any(x => x.Entity.RowId == ul.RowId); if (!tracking) { dbContext.UserLocations.Update(ul); } int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken) .ConfigureAwait(false); return rowsAffected > 0; }
public async Task<bool> AddUserLocation( IUserLocation userLocation, CancellationToken cancellationToken = default(CancellationToken) ) { if (userLocation == null) { return false; } UserLocation ul = UserLocation.FromIUserLocation(userLocation); if (ul.RowId == Guid.Empty) { ul.RowId = Guid.NewGuid(); } cancellationToken.ThrowIfCancellationRequested(); dbContext.UserLocations.Add(ul); cancellationToken.ThrowIfCancellationRequested(); int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken); return rowsAffected > 0; }
public async Task UpdateUserLocation( IUserLocation userLocation, CancellationToken cancellationToken = default(CancellationToken) ) { ThrowIfDisposed(); cancellationToken.ThrowIfCancellationRequested(); if (userLocation == null) throw new ArgumentException("userLocation must not be null"); if (userLocation.Id == Guid.Empty) throw new ArgumentException("Id must not be empty guid"); if (userLocation.UserId == Guid.Empty) throw new ArgumentException("UserId must not be empty guid"); if (userLocation.SiteId == Guid.Empty) throw new ArgumentException("SiteId must not be empty guid"); //await EnsureProjectId().ConfigureAwait(false); var projectId = userLocation.SiteId.ToString(); var ul = UserLocation.FromIUserLocation(userLocation); await locationCommands.UpdateAsync( projectId, ul.Id.ToString(), ul, cancellationToken).ConfigureAwait(false); }