public PositionViewModel(TLGpsDataEvent tk103Gps, Vehicle vehicle, GeofenceHelper.Position lasPosition) { double dir = 0; if (Math.Abs(lasPosition.Latitude - tk103Gps.Lat) > 0.0) { if (Math.Abs(lasPosition.Longitude - tk103Gps.Long) > 0.0) { dir = GetDirection(tk103Gps, lasPosition); } } Latitude = tk103Gps.Lat; Longitude = tk103Gps.Long; Address = tk103Gps.Address; IMEI = tk103Gps.Imei; // SerialNumber = tk103Gps.s; //Direction = tk103Gps.Address Speed = tk103Gps.Speed; VehicleName = vehicle.VehicleName; VehicleId = vehicle.Id.ToString(); CustomerName = vehicle.Customer?.Id.ToString(); TimeStampUtc = tk103Gps.DateTimeUtc; SetVehicleImage(vehicle, dir); }
public async Task Handle(TLGpsDataEvent notification, CancellationToken cancellationToken) { try { var box = await _context.Boxes .SingleOrDefaultAsync(b => b.Imei == notification.Imei, cancellationToken : cancellationToken) .ConfigureAwait(false); if (box != null) { var position = new Position(); position.Box_Id = box?.Id; position.Altitude = notification.Altitude; position.Direction = notification.Direction; position.Lat = notification.Lat; position.Long = notification.Long; position.Speed = notification.Speed; position.Address = notification.Address; position.Id = Guid.NewGuid(); position.Priority = notification.Priority; position.Satellite = notification.Satellite; position.Timestamp = notification.DateTimeUtc; position.MotionStatus = notification.Speed > 0.0 ? notification.Speed > 8 ? MotionStatus.Moving : MotionStatus.SlowMotion: MotionStatus.Stopped; box.LastGpsInfoTime = notification.DateTimeUtc; _context.Positions.Add(position); await _context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); } } catch (Exception e) { Trace.WriteLine(e); throw; } }
private async Task <Box> Item(TLGpsDataEvent context) { using (var contextFScope = _dbContextScopeFactory.Create()) { _db = contextFScope.DbContexts.Get <SmartFleetObjectContext>(); return(await _db.Boxes.SingleOrDefaultAsync(b => b.Imei == context.Imei)); } }
private static double GetDirection(TLGpsDataEvent tk103Gps, GeofenceHelper.Position lastPos) { var dir = !lastPos.Equals(default(GeofenceHelper.Position)) ? GeofenceHelper.DegreeBearing(lastPos.Latitude, lastPos.Longitude, tk103Gps.Lat, tk103Gps.Long) : 0; return(dir); }