private void ProcessEntradaObra(GeofenceEvent data) { // Obtengo el estado a procesar var detalle = GetDetalle(data, Estado.Evento.LlegaAObra); if (detalle == null) { return; } if (!detalle.Automatico.HasValue) { // Guardo la fecha del evento detalle.Automatico = data.Date; DaoFactory.DetalleTicketDAO.SaveOrUpdate(detalle); SaveMessage(MessageCode.EstadoLogisticoCumplido.GetMessageCode(), detalle.EstadoLogistico.Descripcion, data); SaveMessageAtraso(data, detalle); } else { var salida = Detalles.Where(d => d.EstadoLogistico.EsPuntoDeControl == Estado.Evento.SaleDeObra && d.Automatico.HasValue).FirstOrDefault(); if (salida != null) { // Si ya hay una fecha para el evento de salida, la borro: la salida siempre es la ultima. salida.Automatico = null; DaoFactory.DetalleTicketDAO.SaveOrUpdate(salida); } } }
private void ProcessEntradaBase(GeofenceEvent data) { // Obtengo el estado a procesar var detalle = GetDetalle(data, Estado.Evento.LlegaAPlanta); if (detalle == null) { return; } // Si ya hay una fecha para sale de planta de menos de 5 minutos antes, tomo esta entrada como una "entrada-salida" var salida = Detalles.Where(d => d.EstadoLogistico.EsPuntoDeControl == Estado.Evento.SaleDePlanta && d.Automatico.HasValue).FirstOrDefault(); if (salida != null && data.Date.Subtract(salida.Automatico.Value) < TimeSpan.FromMinutes(InOutGecercaMinutes)) { return; } if (!detalle.Automatico.HasValue) { // Guardo la fecha del evento detalle.Automatico = data.Date; DaoFactory.DetalleTicketDAO.SaveOrUpdate(detalle); Ticket.FechaFin = data.Date; Ticket.BaseLlegada = DaoFactory.LineaDAO.GetList(new[] { Ticket.Empresa != null ? Ticket.Empresa.Id : Ticket.Linea.Empresa.Id }) .Where(lin => lin.ReferenciaGeografica != null && lin.ReferenciaGeografica.Id == data.Id) .FirstOrDefault(); DaoFactory.TicketDAO.SaveOrUpdate(Ticket); SaveMessage(MessageCode.EstadoLogisticoCumplido.GetMessageCode(), detalle.EstadoLogistico.Descripcion, data); SaveMessageAtraso(data, detalle); } }
protected override void Process(GeofenceEvent data) { var isLinea = data.Id == Ticket.Linea.ReferenciaGeografica.Id; var isObra = data.Id == Ticket.PuntoEntrega.ReferenciaGeografica.Id; var isLlegada = Ticket.BaseDestino == null ? !isObra : data.Id == Ticket.BaseDestino.ReferenciaGeografica.Id; var entrada = data.Evento == GeofenceEvent.EventoGeofence.Entrada; var salida = data.Evento == GeofenceEvent.EventoGeofence.Salida; if (isLlegada && entrada) { ProcessEntradaBase(data); } if (isLinea && salida) { ProcessSalidaBase(data); } if (isObra && entrada) { ProcessEntradaObra(data); } if (isObra && salida) { ProcessSalidaObra(data); } }
private void ProcessSalidaBase(GeofenceEvent data) { // Obtengo el estado a procesar var detalle = GetDetalle(data, Estado.Evento.SaleDePlanta); if (detalle == null) { return; } if (!detalle.Automatico.HasValue) { // Guardo la fecha del evento detalle.Automatico = data.Date; DaoFactory.DetalleTicketDAO.SaveOrUpdate(detalle); if (!Ticket.FechaDescarga.HasValue) { Ticket.FechaDescarga = data.Date; } DaoFactory.TicketDAO.SaveOrUpdate(Ticket); SaveMessage(MessageCode.EstadoLogisticoCumplido.GetMessageCode(), detalle.EstadoLogistico.Descripcion, data); SaveMessageAtraso(data, detalle); } else { // Si ya hay una fecha para el mismo evento analizo si la anterior es una "posicion loca" var entrada = Detalles.Where(d => d.EstadoLogistico.EsPuntoDeControl == Estado.Evento.LlegaAPlanta && d.Automatico.HasValue).FirstOrDefault(); if (entrada != null && entrada.Automatico.Value.Subtract(detalle.Automatico.Value) < TimeSpan.FromMinutes(InOutGecercaMinutes)) { // Si el evento anterior era por una "posicion loca" guardo el nuevo horario // y elimino el otro valor. detalle.Automatico = data.Date; entrada.Automatico = null; DaoFactory.DetalleTicketDAO.SaveOrUpdate(detalle); DaoFactory.DetalleTicketDAO.SaveOrUpdate(entrada); if (!Ticket.FechaDescarga.HasValue) { Ticket.FechaDescarga = data.Date; } DaoFactory.TicketDAO.SaveOrUpdate(Ticket); SaveMessage(MessageCode.EstadoLogisticoCumplido.GetMessageCode(), detalle.EstadoLogistico.Descripcion + " (Corrección)", data); SaveMessageAtraso(data, detalle); } } }
private void ProcessSalidaObra(GeofenceEvent data) { // Obtengo el estado a procesar var detalle = GetDetalle(data, Estado.Evento.SaleDeObra); if (detalle == null) { return; } // Guardo la fecha del evento detalle.Automatico = data.Date; DaoFactory.DetalleTicketDAO.SaveOrUpdate(detalle); SaveMessage(MessageCode.EstadoLogisticoCumplido.GetMessageCode(), detalle.EstadoLogistico.Descripcion, data); SaveMessageAtraso(data, detalle); }
public async Task OnStatusChanged(GeofenceState newStatus, GeofenceRegion region) { var e = new GeofenceEvent { Id = Guid.NewGuid().ToString(), DateCreated = DateTimeOffset.UtcNow, Identifier = region.Identifier, Entered = newStatus == GeofenceState.Entered }; await this.repository.Set(e.Id, e); if (!this.jobManager.IsRunning) { await this.jobManager.RunJobAsTask(Constants.GeofenceJobIdentifer); } }
public void ExecuteAction(string actionName, GeofenceEvent ev, Geofence geofence) { if (!string.IsNullOrEmpty(actionName)) { Task.Run(() => { var pheidiParams = new Dictionary <string, string>(); pheidiParams.Add("GeofenceName", geofence.Name); pheidiParams.Add("GeofenceEvent", ev.ToString()); pheidiParams.Add("GeofenceLatitude", geofence.Latitude.ToString()); pheidiParams.Add("GeofenceLongitude", geofence.Longitude.ToString()); pheidiParams.Add("GeofenceNoseq", geofence.NoSeq); var action = new Action() { Name = actionName, Params = pheidiParams }; ActionManager.ExecuteAction(action); }); } }
protected virtual void Process(GeofenceEvent data) { }
public static IEvent GetEvent(DAOFactory daoFactory, GPSPoint inicio, string codigo, Int32?idPuntoDeInteres, Int64 extraData, Int64 extraData2, Int64 extraData3, Coche vehiculo, Empleado chofer) { IEvent evento = null; int cod; if (int.TryParse(codigo, out cod) && cod > 0 && cod < 20) { evento = new ManualEvent(inicio.Date, inicio.Lat, inicio.Lon, codigo); } else if (codigo == MessageCode.InsideGeoRefference.GetMessageCode() && idPuntoDeInteres.HasValue) { evento = new GeofenceEvent(inicio.Date, idPuntoDeInteres.Value, GeofenceEvent.EventoGeofence.Entrada, inicio.Lat, inicio.Lon, chofer); } else if (codigo == MessageCode.OutsideGeoRefference.GetMessageCode() && idPuntoDeInteres.HasValue) { evento = new GeofenceEvent(inicio.Date, idPuntoDeInteres.Value, GeofenceEvent.EventoGeofence.Salida, inicio.Lat, inicio.Lon, chofer); } else if (codigo == MessageCode.TolvaDeactivated.GetMessageCode()) { evento = new TolvaEvent(inicio.Date, TolvaEvent.EstadoTolva.Off, inicio.Lat, inicio.Lon); } else if (codigo == MessageCode.TolvaActivated.GetMessageCode()) { evento = new TolvaEvent(inicio.Date, TolvaEvent.EstadoTolva.On, inicio.Lat, inicio.Lon); } else if (codigo == MessageCode.MixerStopped.GetMessageCode()) { evento = new TrompoEvent(inicio.Date, TrompoEvent.SentidoTrompo.Detenido, TrompoEvent.VelocidadTrompo.Undefined, inicio.Lat, inicio.Lon); } else if (codigo == MessageCode.MixerClockwiseFast.GetMessageCode()) { evento = new TrompoEvent(inicio.Date, TrompoEvent.SentidoTrompo.HorarioDerecha, TrompoEvent.VelocidadTrompo.Fast, inicio.Lat, inicio.Lon); } else if (codigo == MessageCode.MixerClockwiseSlow.GetMessageCode()) { evento = new TrompoEvent(inicio.Date, TrompoEvent.SentidoTrompo.HorarioDerecha, TrompoEvent.VelocidadTrompo.Slow, inicio.Lat, inicio.Lon); } else if (codigo == MessageCode.MixerClockwise.GetMessageCode()) { evento = new TrompoEvent(inicio.Date, TrompoEvent.SentidoTrompo.HorarioDerecha, TrompoEvent.VelocidadTrompo.Undefined, inicio.Lat, inicio.Lon); } else if (codigo == MessageCode.MixerCounterClockwiseFast.GetMessageCode()) { evento = new TrompoEvent(inicio.Date, TrompoEvent.SentidoTrompo.AntihorarioIzquierda, TrompoEvent.VelocidadTrompo.Fast, inicio.Lat, inicio.Lon); } else if (codigo == MessageCode.MixerCounterClockwiseSlow.GetMessageCode()) { evento = new TrompoEvent(inicio.Date, TrompoEvent.SentidoTrompo.AntihorarioIzquierda, TrompoEvent.VelocidadTrompo.Slow, inicio.Lat, inicio.Lon); } else if (codigo == MessageCode.MixerCounterClockwise.GetMessageCode()) { evento = new TrompoEvent(inicio.Date, TrompoEvent.SentidoTrompo.AntihorarioIzquierda, TrompoEvent.VelocidadTrompo.Undefined, inicio.Lat, inicio.Lon); } else if (codigo == MessageCode.GarminTextMessageCannedResponse.GetMessageCode()) { // extraData = ID Device // extraData2 = ID Entrega / ID Ruta // extraData3 = Codigo Mensaje STrace.Debug(typeof(EventFactory).FullName, Convert.ToInt32(extraData), "extraData=" + extraData + " extraData2=" + extraData2 + " extraData3=" + extraData3); var veh = daoFactory.CocheDAO.FindMobileByDevice(Convert.ToInt32(extraData)); if (veh != null && veh.Empresa.IntegrationServiceEnabled) { var intService = new IntegrationService(daoFactory); if (veh.Empresa.IntegrationServiceCodigoMensajeAceptacion == extraData3.ToString()) { var distribucion = daoFactory.ViajeDistribucionDAO.FindById(Convert.ToInt32(extraData2)); if (distribucion != null) { var enCurso = daoFactory.ViajeDistribucionDAO.FindEnCurso(veh); if (enCurso == null) { intService.ResponseAsigno(distribucion, true); var eventoInicio = new InitEvent(inicio.Date); var ciclo = new CicloLogisticoDistribucion(distribucion, daoFactory, new MessageSaver(daoFactory)); ciclo.ProcessEvent(eventoInicio); } else { intService.ResponsePreasigno(distribucion, true); } } return(null); } else if (veh.Empresa.IntegrationServiceCodigoMensajeRechazo == extraData3.ToString()) { var distribucion = daoFactory.ViajeDistribucionDAO.FindById(Convert.ToInt32(extraData2)); distribucion.Vehiculo = null; daoFactory.ViajeDistribucionDAO.SaveOrUpdate(distribucion); var enCurso = daoFactory.ViajeDistribucionDAO.FindEnCurso(veh); if (enCurso == null) { intService.ResponseAsigno(distribucion, false); } else { intService.ResponsePreasigno(distribucion, false); } return(null); } } if (extraData2 == 0) { return(null); } var entrega = daoFactory.EntregaDistribucionDAO.FindById(Convert.ToInt32(extraData2)); var mensajeVo = daoFactory.MensajeDAO.GetByCodigo(extraData3.ToString("#0"), veh.Empresa, veh.Linea); try { var mensaje = daoFactory.MensajeDAO.FindById(mensajeVo.Id); try { var descriptiva = " - " + entrega.Viaje.Codigo + " - " + entrega.Descripcion; var ms = new MessageSaver(daoFactory); var log = ms.Save(null, Convert.ToString(extraData3), veh.Dispositivo, veh, chofer, inicio.Date, inicio, descriptiva, entrega.Viaje, entrega); try { entrega.MensajeConfirmacion = log as LogMensaje; daoFactory.EntregaDistribucionDAO.SaveOrUpdate(entrega); } catch (Exception) { } if (mensaje.TipoMensaje.DeConfirmacion) { evento = new GarminEvent(inicio.Date, extraData2, inicio.Lat, inicio.Lon, EntregaDistribucion.Estados.Completado, chofer); } else if (mensaje.TipoMensaje.DeRechazo) { evento = new GarminEvent(inicio.Date, extraData2, inicio.Lat, inicio.Lon, EntregaDistribucion.Estados.NoCompletado, chofer); } else { STrace.Error(typeof(CicloLogisticoFactory).FullName, Convert.ToInt32(extraData), "Respuesta de mensaje de Canned Response inválida sin tipo de mensaje adecuado para la ocasión. (" + extraData2 + "-" + extraData + ")"); } } catch (Exception e) { STrace.Exception(typeof(EventFactory).FullName, e, "E#2 Vehicle=" + veh.Id + " entrega=" + (entrega == null ? "null" : entrega.Id.ToString("#0")) + " mensajeVo=" + mensajeVo.Id + " mensaje=" + (mensaje == null ? "null" : mensaje.Id.ToString("#0"))); } } catch (Exception e) { STrace.Exception(typeof(EventFactory).FullName, e, "E#1 Vehicle=" + veh.Id + " entrega=" + (entrega == null ? "null" : entrega.Id.ToString("#0")) + " mensajeVo=" + (mensajeVo == null ? "null" : mensajeVo.Id.ToString("#0"))); } } else if (codigo == MessageCode.ValidacionRuteo.GetMessageCode()) { var deviceId = inicio.DeviceId; var vehicle = daoFactory.CocheDAO.FindMobileByDevice(deviceId); if (vehicle != null) { var ruta = daoFactory.ViajeDistribucionDAO.FindEnCurso(vehicle); if (ruta != null) { evento = new RouteEvent(inicio.Date, ruta.Id, inicio.Lat, inicio.Lon, RouteEvent.Estados.Enviado); } } } else if (codigo == MessageCode.GarminETAReceived.GetMessageCode()) { if (vehiculo.HasActiveStop()) { var activeStop = vehiculo.GetActiveStop(); if (activeStop > 0) { var edDAO = daoFactory.EntregaDistribucionDAO; var vdDAO = daoFactory.ViajeDistribucionDAO; var detalle = edDAO.FindById(activeStop); if (detalle != null) { var utcnow = DateTime.UtcNow; var fechora = vehiculo.EtaEstimated(); var minutos = fechora != null && fechora > utcnow?fechora.Value.Subtract(utcnow).TotalMinutes : 0; var texto = String.Format(CultureManager.GetLabel("GARMIN_STOP_ETA_ARRIVAL"), minutos, fechora); if (minutos > 0) { using (var transaction = SmartTransaction.BeginTransaction()) { try { try { new MessageSaver(daoFactory).Save(null, codigo, vehiculo.Dispositivo, vehiculo, chofer, DateTime.UtcNow, null, texto, detalle.Viaje, detalle); } catch (Exception ex) { STrace.Exception(typeof(EventFactory).FullName, ex, vehiculo.Dispositivo.Id, String.Format("Exception doing MessageSaver.Save({0})", texto)); throw ex; } try { detalle.GarminETA = fechora; detalle.GarminETAInformedAt = utcnow; vdDAO.SaveOrUpdate(detalle.Viaje); } catch (Exception ex) { STrace.Exception(typeof(EventFactory).FullName, ex, vehiculo.Dispositivo.Id, String.Format("Exception doing MessageSaver.Save({0})", texto)); throw ex; } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } } else { STrace.Error(typeof(EventFactory).FullName, vehiculo.Dispositivo.Id, String.Format("Processing GarminETAReceived cannot be processed because EntregaDistribucion #{0} is null.", activeStop)); } } else { STrace.Error(typeof(EventFactory).FullName, vehiculo.Dispositivo.Id, "Processing GarminETAReceived cannot be processed because ActiveStop # is not valid."); } } } else { var stopstatus = TranslateStopStatus(codigo); if (stopstatus != -1) { evento = new GarminEvent(inicio.Date, extraData, inicio.Lat, inicio.Lon, stopstatus, chofer); } } return(evento); }