Exemplo n.º 1
0
        public async Task Consume(ConsumeContext <TLGpsDataEvents> context)
        {
            if (SignalRHubManager.Clients == null)
            {
                return;
            }

            using (var dbContextScopeFactory = SignalRHubManager.DbContextScopeFactory.Create())
            {
                foreach (var @event in context.Message.Events)
                {
                    // get current gps device
                    var vehicleDto = await GetSenderBoxAsync(@event.Imei, dbContextScopeFactory).ConfigureAwait(false);

                    if (vehicleDto != null)
                    {
                        // set position
                        var lasPosition = await GetLastPositionAsync(vehicleDto.Id, dbContextScopeFactory).ConfigureAwait(false);

                        var position = new PositionViewModel(@event, vehicleDto, lasPosition);
                        if (string.IsNullOrEmpty(position.CustomerName))
                        {
                            return;
                        }
                        var reverseGeoCodingService = new ReverseGeoCodingService();
                        position.Address = await reverseGeoCodingService.ReverseGeocodeAsync(position.Latitude, position.Longitude).ConfigureAwait(false);

                        await SignalRHubManager.Clients.Group(position.CustomerName).receiveGpsStatements(position);
                    }
                }
            }
        }
Exemplo n.º 2
0
 private async Task GeoReverseCodeGpsDataAsync(List <TLGpsDataEvent> gpsResult)
 {
     foreach (var gpSdata in gpsResult)
     {
         Thread.Sleep(1000);
         gpSdata.Address = await _reverseGeoCodingService.ReverseGeocodeAsync(gpSdata.Lat, gpSdata.Long)
                           .ConfigureAwait(false);
     }
 }
Exemplo n.º 3
0
        public async Task Consume(ConsumeContext <CreateNewBoxGps> context)
        {
            using (var contextFScope = _dbContextScopeFactory.Create())
            {
                var db = contextFScope.DbContexts.Get <SmartFleetObjectContext>();
                Box box;
                using (DbContextTransaction scope = db.Database.BeginTransaction())
                {
                    box = await db.Boxes.FirstOrDefaultAsync(x => x.SerialNumber == context.Message.SerialNumber)
                          .ConfigureAwait(false);

                    scope.Commit();
                }
                if (box == null)
                {
                    box                 = new Box();
                    box.Id              = Guid.NewGuid();
                    box.BoxStatus       = BoxStatus.Prepared;
                    box.CreationDate    = DateTime.UtcNow;
                    box.LastGpsInfoTime = context.Message.TimeStampUtc;
                    box.Icci            = String.Empty;
                    box.PhoneNumber     = String.Empty;
                    box.Vehicle         = null;
                    box.Imei            = context.Message.IMEI;
                    box.SerialNumber    = context.Message.SerialNumber;
                    db.Boxes.Add(box);
                }
                if (box.BoxStatus == BoxStatus.WaitInstallation)
                {
                    box.BoxStatus = BoxStatus.Prepared;
                }
                box.LastGpsInfoTime = context.Message.TimeStampUtc;
                var address = await _geoCodingService.ReverseGeocodeAsync(context.Message.Latitude, context.Message.Longitude).ConfigureAwait(false);

                Position position = new Position
                {
                    Box_Id       = box.Id,
                    Altitude     = 0,
                    Direction    = 0,
                    Lat          = context.Message.Latitude,
                    Long         = context.Message.Longitude,
                    Speed        = context.Message.Speed,
                    Id           = Guid.NewGuid(),
                    Priority     = 0,
                    Satellite    = 0,
                    Timestamp    = context.Message.TimeStampUtc,
                    Address      = address,
                    MotionStatus = (int)context.Message.Speed > 2 ? MotionStatus.Moving : MotionStatus.Stopped
                };
                db.Positions.Add(position);
                await contextFScope.SaveChangesAsync().ConfigureAwait(false);
            }
        }