예제 #1
0
        public async Task <List <Position> > GetLastVehiclPosition(string userName)
        {
            var positions = new List <Position>();
            var cst       = await _objectContext.UserAccounts.Include(x => x.Customer).Include(x => x.Customer.Vehicles)
                            .FirstOrDefaultAsync(x => x.UserName == userName);

            if (cst?.Customer.Vehicles != null)
            {
                var vehicles   = cst.Customer.Vehicles;
                var vehicleids = vehicles.Select(v => v.Id);
                var gpsDevices = _gpsDeviceRepository.Table.Where(x => vehicleids.Any(v => v == x.VehicleId));
                foreach (var geDevice in gpsDevices)
                {
                    var position = await _positionRepository.Table.OrderByDescending(x => x.Timestamp)
                                   .FirstOrDefaultAsync(p => p.Box_Id == geDevice.Id);

                    if (position == null)
                    {
                        continue;
                    }
                    position.Vehicle = vehicles.FirstOrDefault(v => v.Id == geDevice.VehicleId);
                    await _geoCodingService.ReverseGeoCoding(position);

                    positions.Add(position);
                }
            }

            return(positions);
        }
예제 #2
0
        public async Task <List <Position> > GetLastVehiclPosition(string userName)
        {
            using (var contextFScope = _dbContextScopeFactory.Create())
            {
                _objectContext = contextFScope.DbContexts.Get <SmartFleetObjectContext>();
                var positions = new List <Position>();
                // ReSharper disable once ComplexConditionExpression
                var vehicles = await _objectContext.UserAccounts
                               .Include(x => x.Customer)
                               .Include(x => x.Customer.Vehicles)
                               .Where(x => x.UserName == userName)
                               .SelectMany(x => x.Customer.Vehicles.Where(v => v.VehicleStatus == VehicleStatus.Active).Select(v => v))
                               .ToArrayAsync();

                if (!vehicles.Any())
                {
                    return(positions);
                }

                foreach (var vehicle in vehicles)
                {
                    var boxes = await _objectContext
                                .Boxes
                                .Where(b => b.VehicleId == vehicle.Id &&
                                       b.BoxStatus == BoxStatus.Valid)
                                .Select(x => x.Id)
                                .ToArrayAsync();

                    if (!boxes.Any())
                    {
                        continue;
                    }
                    foreach (var geDevice in boxes)
                    {
                        var position = await _objectContext
                                       .Positions
                                       .OrderByDescending(x => x.Timestamp)
                                       .FirstOrDefaultAsync(p => p.Box_Id == geDevice);

                        if (position == null)
                        {
                            continue;
                        }
                        position.Vehicle = vehicle;
                        await _geoCodingService.ReverseGeoCoding(position);

                        positions.Add(position);
                    }
                }
                return(positions);
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task Consume(ConsumeContext <CreateTk103Gps> context)
        {
            if (SignalRHubManager.Clients == null)
            {
                return;
            }
            var reverseGeoCodingService = new ReverseGeoCodingService();
            await reverseGeoCodingService.ReverseGeoCoding(context.Message);

            using (var dbContextScopeFactory = SignalRHubManager.DbContextScopeFactory.Create())
            {
                // get current gps device
                var box = await GetSenderBox(context.Message, dbContextScopeFactory);

                if (box != null)
                {
                    // set position
                    var position = new PositionViewModel(context.Message, box.Vehicle);
                    await SignalRHubManager.Clients.Group(position.CustomerName).receiveGpsStatements(position);
                }
            }
        }
예제 #4
0
        private async Task SendDecodedData(List <CreateTeltonikaGps> gpsResult, string imei)
        {
            if (gpsResult.Count > 0)
            {
                foreach (var gpSdata in gpsResult.OrderBy(x => x.Timestamp).Distinct())
                {
                    var r = await _reverseGeoCodingService.ExecuteQuery(gpSdata.Lat, gpSdata.Long);

                    Thread.Sleep(1000);
                    if (r.display_name != null)
                    {
                        gpSdata.Address = r.display_name;
                    }
                    else
                    {
                        var ad = await _reverseGeoCodingService.ReverseGeoCoding(gpSdata.Lat, gpSdata.Long)
                                 .ConfigureAwait(false);

                        if (ad != null)
                        {
                            //Console.WriteLine(ad);
                            gpSdata.Address = ad;
                        }

                        Thread.Sleep(1000);
                    }

                    await _bus.Publish(gpSdata);

                    var direction = SetDirection(gpSdata.Direction);
                    Console.WriteLine("IMEI: " + imei + " Date: " + gpSdata.Timestamp + " latitude : " + gpSdata.Lat +
                                      " Longitude:" + gpSdata.Long + " Speed: " + gpSdata.Speed + " Direction:" + direction +
                                      " address " + gpSdata.Address + " milage :" + gpSdata.Mileage);
                }
            }
        }