예제 #1
0
        private bool UpdateCarPosition()
        {
            try {
                var routesIds = (yTreeViewDrivers.RepresentationModel.ItemsList as IList <Vodovoz.ViewModel.WorkingDriverVMNode>)
                                .SelectMany(x => x.RouteListsIds.Keys).ToArray();
                var start      = DateTime.Now;
                var lastPoints = Repository.Logistics.TrackRepository.GetLastPointForRouteLists(uow, routesIds);

                var movedDrivers = lastPoints.Where(x => x.Time > DateTime.Now.AddMinutes(-20)).Select(x => x.RouteListId).ToArray();
                var ere20Minuts  = Repository.Logistics.TrackRepository.GetLastPointForRouteLists(uow, movedDrivers, DateTime.Now.AddMinutes(-20));
                logger.Debug("Время запроса точек: {0}", DateTime.Now - start);
                carsOverlay.Clear();
                carMarkers = new Dictionary <int, CarMarker>();
                foreach (var pointsForDriver in lastPoints.GroupBy(x => x.DriverId))
                {
                    var lastPoint = pointsForDriver.OrderBy(x => x.Time).Last();
                    var driverRow = (yTreeViewDrivers.RepresentationModel.ItemsList as IList <WorkingDriverVMNode>)
                                    .First(x => x.Id == lastPoint.DriverId);

                    CarMarkerType iconType;
                    var           ere20 = ere20Minuts.Where(x => x.DriverId == pointsForDriver.Key).OrderBy(x => x.Time).LastOrDefault();
                    if (lastPoint.Time < DateTime.Now.AddMinutes(-20))
                    {
                        iconType = driverRow.IsVodovozAuto ? CarMarkerType.BlueCarVodovoz : CarMarkerType.BlueCar;
                    }
                    else if (ere20 != null)
                    {
                        var point1 = new PointLatLng(lastPoint.Latitude, lastPoint.Longitude);
                        var point2 = new PointLatLng(ere20.Latitude, ere20.Longitude);
                        var diff   = gmapWidget.MapProvider.Projection.GetDistance(point1, point2);
                        if (diff <= 0.1)
                        {
                            iconType = driverRow.IsVodovozAuto ? CarMarkerType.RedCarVodovoz : CarMarkerType.RedCar;
                        }
                        else
                        {
                            iconType = driverRow.IsVodovozAuto ? CarMarkerType.GreenCarVodovoz : CarMarkerType.GreenCar;
                        }
                    }
                    else
                    {
                        iconType = driverRow.IsVodovozAuto ? CarMarkerType.GreenCarVodovoz : CarMarkerType.GreenCar;
                    }

                    if (lastSelectedDrivers.ContainsKey(lastPoint.DriverId))
                    {
                        lastSelectedDrivers[lastPoint.DriverId] = iconType;
                        iconType = driverRow.IsVodovozAuto ? CarMarkerType.BlackCarVodovoz : CarMarkerType.BlackCar;
                    }

                    string text   = $"{driverRow.ShortName}({driverRow.CarNumber})";
                    var    marker = new CarMarker(new PointLatLng(lastPoint.Latitude, lastPoint.Longitude),
                                                  iconType);
                    if (lastPoint.Time < DateTime.Now.AddSeconds(-30))
                    {
                        text += lastPoint.Time.Date == DateTime.Today
                                                        ? $"\nБыл виден: {lastPoint.Time:t} "
                                                        : $"\nБыл виден: {lastPoint.Time:g} ";
                    }
                    marker.ToolTipText = text;
                    carsOverlay.Markers.Add(marker);
                    carMarkers.Add(lastPoint.DriverId, marker);
                }
            } catch (Exception ex) {
                logger.Error("Ошибка при обновлении позиции автомобиля", ex);
                return(false);
            }
            return(true);
        }
예제 #2
0
        private bool UpdateCarPosition()
        {
            var routesIds = (yTreeViewDrivers.RepresentationModel.ItemsList as IList<Vodovoz.ViewModel.WorkingDriverVMNode>)
                .SelectMany(x => x.RouteListsIds.Keys).ToArray();
            var start = DateTime.Now;
            var lastPoints = Repository.Logistics.TrackRepository.GetLastPointForRouteLists(uow, routesIds);

            var movedDrivers = lastPoints.Where(x => x.Time > DateTime.Now.AddMinutes(-20)).Select(x => x.RouteListId).ToArray();
            var ere20Minuts = Repository.Logistics.TrackRepository.GetLastPointForRouteLists(uow, movedDrivers, DateTime.Now.AddMinutes(-20));
            logger.Debug("Время запроса точек: {0}", DateTime.Now - start);
            carsOverlay.Clear();
            carMarkers = new Dictionary<int, CarMarker>();
            foreach(var pointsForDriver in lastPoints.GroupBy(x => x.DriverId))
            {
                var lastPoint = pointsForDriver.OrderBy(x => x.Time).Last();
                CarMarkerType iconType;
                var ere20 = ere20Minuts.Where(x => x.DriverId == pointsForDriver.Key).OrderBy(x => x.Time).LastOrDefault();
                if (lastPoint.Time < DateTime.Now.AddMinutes(-20))
                {
                    iconType = CarMarkerType.BlueCar;
                }
                else if (ere20 != null)
                {
                    var point1 = new PointLatLng(lastPoint.Latitude, lastPoint.Longitude);
                    var point2 = new PointLatLng(ere20.Latitude, ere20.Longitude);
                    var diff = gmapWidget.MapProvider.Projection.GetDistance(point1, point2);
                    if (diff <= 0.1)
                        iconType = CarMarkerType.RedCar;
                    else
                        iconType = CarMarkerType.GreenCar;
                }
                else
                    iconType = CarMarkerType.GreenCar;

                if(lastSelectedDriver == lastPoint.DriverId)
                {
                    lastMarkerType = iconType;
                    iconType = CarMarkerType.BlackCar;
                }

                var marker = new CarMarker(new PointLatLng(lastPoint.Latitude, lastPoint.Longitude),
                    iconType);
                var driverRow = (yTreeViewDrivers.RepresentationModel.ItemsList as IList<Vodovoz.ViewModel.WorkingDriverVMNode>)
                    .First(x => x.Id == lastPoint.DriverId);
                string text = String.Format("{0}({1})", driverRow.ShortName, driverRow.CarNumber);
                if (lastPoint.Time < DateTime.Now.AddSeconds(-30))
                    text += lastPoint.Time.Date == DateTime.Today
                        ? String.Format("\nБыл виден: {0:t} ", lastPoint.Time)
                        : String.Format("\nБыл виден: {0:g} ", lastPoint.Time);
                marker.ToolTipText = text;
                carsOverlay.Markers.Add(marker);
                carMarkers.Add(lastPoint.DriverId, marker);
            }
            return true;
        }