コード例 #1
0
        public void Regenerate(DateTime desde, DateTime hasta)
        {
            Regeneracion = true;
            var maxMonths   = Vehiculo.Empresa != null ? Vehiculo.Empresa.MesesConsultaPosiciones : 3;
            var logMensajes = DaoFactory.LogMensajeDAO.GetEvents(Vehiculo.Id, desde, hasta, maxMonths);

            foreach (var logMensaje in logMensajes)
            {
                if (logMensaje.Latitud == 0 || logMensaje.Longitud == 0)
                {
                    var pos = DaoFactory.LogPosicionDAO.GetFirstPositionOlderThanDate(Vehiculo.Id, logMensaje.Fecha, maxMonths);
                    logMensaje.Latitud  = pos.Latitud;
                    logMensaje.Longitud = pos.Longitud;
                    DaoFactory.LogMensajeDAO.SaveOrUpdate(logMensaje);
                }
                var evento = EventFactory.GetEvent(DaoFactory, logMensaje);
                if (evento == null)
                {
                    continue;
                }
                ProcessEvent(evento);
            }

            var positions = DaoFactory.LogPosicionDAO.GetPositionsBetweenDates(Vehiculo.Id, desde, hasta, maxMonths);

            foreach (var logPosicion in positions)
            {
                var pos = new PositionEvent(logPosicion.FechaMensaje, logPosicion.Latitud, logPosicion.Longitud);
                ProcessEvent(pos);
            }
            Regeneracion = false;
        }
コード例 #2
0
        /// <summary>
        /// Procesa una posicion y genera los eventos de entrada y salida de geocerca.
        /// </summary>
        /// <param name="data"></param>
        protected void ProcessGeocercas(PositionEvent data)
        {
            try
            {
                var geocercas = Puntos;
                var point     = new GPSPoint(data.Date, (float)data.Latitud, (float)data.Longitud);

                foreach (var geocerca in geocercas)
                {
                    var key = GetKeyGeocerca(geocerca);
                    if (Regeneracion)
                    {
                        key = "recalc_" + key;
                    }

                    var lastState = LogicCache.KeyExists(typeof(EstadosEntrega), key)
                        ? LogicCache.Retrieve <EstadosEntrega>(typeof(EstadosEntrega), key).Estado
                        : EstadosGeocerca.Desconocido;

                    var geo = DaoFactory.ReferenciaGeograficaDAO.FindGeocerca(geocerca);

                    var p      = new PointF(point.Lon, point.Lat);
                    var inside = geo.IsInBounds(p) && geo.Contains(p.Y, p.X);

                    var newState = inside ? EstadosGeocerca.Dentro : EstadosGeocerca.Fuera;

                    if (lastState != newState)
                    {
                        var state = new EstadosEntrega(newState);
                        LogicCache.Store(typeof(EstadosEntrega), key, state, Regeneracion ? DateTime.UtcNow.AddMinutes(5) : DateTime.UtcNow.AddHours(5));

                        IEvent evento = null;
                        if (lastState == EstadosGeocerca.Dentro && newState == EstadosGeocerca.Fuera)
                        {
                            evento = EventFactory.GetEvent(DaoFactory, point, MessageCode.OutsideGeoRefference.GetMessageCode(), geocerca, 0, null, Empleado);
                        }
                        else if (lastState == EstadosGeocerca.Fuera && newState == EstadosGeocerca.Dentro)
                        {
                            evento = EventFactory.GetEvent(DaoFactory, point, MessageCode.InsideGeoRefference.GetMessageCode(), geocerca, 0, null, Empleado);
                        }
                        if (evento == null)
                        {
                            continue;
                        }

                        ProcessEvent(evento, true);
                    }
                }
            }
            catch (Exception ex)
            {
                STrace.Exception(typeof(CicloLogisticoFactory).FullName, ex);
            }
        }
コード例 #3
0
        public static void Process(DAOFactory daoFactory, string codigo, Coche vehiculo, GPSPoint point, IMessage message, bool ignoreMessages, Empleado chofer)
        {
            try
            {
                // Si no es uno de los codigos que cambian estados automáticos, salgo directamente;))
                if (!IsAutomaticCode(codigo))
                {
                    return;
                }

                var evento = EventFactory.GetEvent(daoFactory, point, codigo, null, message, vehiculo, chofer);
                if (evento == null)
                {
                    return;
                }

                Process(vehiculo, evento, ignoreMessages);
            }
            catch (Exception ex)
            {
                STrace.Exception(typeof(CicloLogisticoFactory).FullName, ex, "Code: " + (codigo ?? "null") + " vehicle: " + (vehiculo == null ? "null" : vehiculo.Id.ToString("#0")) + " message:" + (message == null ? "null" : message.ToString()) + " gpspoint:" + (point == null ? "null" : point.ToString()));
            }
        }