Esempio n. 1
0
        private void SendMessage(string cmd, string param)
        {
            if (cbVehiculoMensaje.SelectedIndex < 0)
            {
                // No hay un vehiculo seleccionado
                JsAlert(string.Format(CultureManager.GetError("NO_SELECTED"), CultureManager.GetEntity("PARENTI03")));
                return;
            }

            var ok       = 0;
            var error    = 0;
            var nogarmin = 0;

            var sent           = string.Empty;
            var failed         = string.Empty;
            var nogarminfailed = string.Empty;

            foreach (ListItem li in cbVehiculoMensaje.Items)
            {
                if (!li.Selected)
                {
                    continue;
                }

                var c = DAOFactory.CocheDAO.FindById(Convert.ToInt32(li.Value));

                if (c.Dispositivo == null)
                {
                    // El vehiculo no tiene dispositivo asignado
                    JsAlert(string.Format(CultureManager.GetSystemMessage("UNASIGNED_VEHICLE"), c.Interno));
                    continue;
                }

                bool sendState;

                var dispositivo = c.Dispositivo;

                if (cmd == "PurgeConfiguration")
                {
                    DAOFactory.DispositivoDAO.PurgeConfiguration(dispositivo);
                    if (dispositivo.DetallesDispositivo.Any(detail => detail.TipoParametro.RequiereReset))
                    {
                        MessageSender.CreateReboot(dispositivo, null);
                    }
                    sendState = true;
                }
                else
                {
                    var message = MessageSender.Create(dispositivo, new MessageSaver(DAOFactory)).AddCommand(cmd);
                    switch (cmd)
                    {
                    case MessageSender.Comandos.Qtree: break;

                    case MessageSender.Comandos.FullQtree: break;

                    case MessageSender.Comandos.ReloadFirmware: break;

                    case MessageSender.Comandos.ReloadConfiguration: break;

                    case MessageSender.Comandos.ReloadMessages: break;

                    case MessageSender.Comandos.ResetFMIOnGarmin:
                        var detalle = DAOFactory.DetalleDispositivoDAO.GetGteMessagingDeviceValue(dispositivo.Id);
                        if (!(detalle != null && detalle == "GARMIN"))
                        {
                            nogarmin++;
                            nogarminfailed += "\\n" + li.Text;
                            continue;
                        }
                        break;

                    case MessageSender.Comandos.Reboot: break;

                    case MessageSender.Comandos.RebootSolicitation: break;

                    case MessageSender.Comandos.SubmitCannedMessage: message.AddCannedMessageCode(param); break;

                    case MessageSender.Comandos.SubmitTextMessage: message.AddMessageText(param); break;

                    case MessageSender.Comandos.SetWorkflowState: message.AddWorkflowState(param); break;

                    case MessageSender.Comandos.DeleteCannedMessage: message.AddCannedMessageInfo(param, 0); break;

                    case MessageSender.Comandos.ResetStateMachine: break;

                    case MessageSender.Comandos.RetrievePictures: message.AddDateRange(dtFotoDesde.SelectedDate.Value.ToDataBaseDateTime(), dtFotoHasta.SelectedDate.Value.ToDataBaseDateTime()); break;

                    case MessageSender.Comandos.DisableFuel: message.AddInmediately(param == "1"); break;

                    case MessageSender.Comandos.EnableFuel: break;

                    case MessageSender.Comandos.ClearFota: DeleteFota(dispositivo); return;
                    }
                    sendState = message.Send();
                }

                if (sendState)
                {
                    ok++;
                    sent += "\\n" + li.Text;
                }
                else
                {
                    error++;
                    failed += "\\n" + li.Text;
                }
            }

            if (ok > 0)
            {
                JsAlert(string.Format(CultureManager.GetSystemMessage("MESSAGE_SENT"), sent));
            }
            if (nogarmin > 0)
            {
                JsAlert(string.Format(CultureManager.GetError("DEVICE_WITHOUT_GARMIN_CONFIGURED"), nogarminfailed));
            }
            if (error > 0)
            {
                JsAlert(string.Format(CultureManager.GetError("MESSAGE_NOT_SENT"), failed));
            }
        }
Esempio n. 2
0
        protected override HandleResults OnDeviceHandleMessage(TextEvent message)
        {
            var employee = GetChofer(message.UserIdentifier);

            var pos = message.GeoPoint;

            if (pos == null)
            {
                var pp = DaoFactory.LogPosicionDAO.GetLastOnlineVehiclePosition(Coche);
                pos = GPSPoint.Factory(message.GetDateTime(), pp == null ? (float)0.0 : (float)pp.Latitud, pp == null ? (float)0.0 : (float)pp.Longitud);
            }

            MessageSaver.Save(message, MessageCode.TextEvent.GetMessageCode(), Dispositivo, Coche, employee, pos.Date, pos, message.Text);

            if (Coche.Empresa.IntegrationServiceEnabled)
            {
                var text = message.Text.Trim().ToUpperInvariant();
                var ruta = DaoFactory.ViajeDistribucionDAO.FindEnCurso(Coche);
                if (ruta != null && text.Contains(Coche.Empresa.IntegrationServicePrefixConfirmation))
                {
                    var sosTicket = DaoFactory.SosTicketDAO.FindByCodigo(ruta.Codigo);
                    if (sosTicket != null)
                    {
                        text = text.Replace(Coche.Empresa.IntegrationServicePrefixConfirmation, string.Empty);
                        var intService = new IntegrationService(DaoFactory);
                        if (sosTicket.Patente.ToUpperInvariant().Contains(text))
                        {
                            intService.ConfirmaPatente(sosTicket, true);
                        }
                        else
                        {
                            intService.ConfirmaPatente(sosTicket, false);
                        }
                    }
                }
            }

            if (Coche.Empresa.AsignoDistribucionPorMensaje)
            {
                var text = message.Text.Trim().ToUpperInvariant();
                STrace.Trace("AsignoDistribucionPorMensaje", string.Format("Text: {0}", text));

                var prefijo = Coche.Empresa.AsignoDistribucionPrefijoMensaje.Trim().ToUpperInvariant();
                if (text.Contains(prefijo))
                {
                    STrace.Trace("AsignoDistribucionPorMensaje", string.Format("Empresa: {0} - Coche: {1} - Msj: {2}", Coche.Empresa.Id, Coche.Id, text));

                    var mensaje = MessageSender.Create(Dispositivo, new MessageSaver(DaoFactory))
                                  .AddCommand(MessageSender.Comandos.SubmitTextMessage);

                    var viajeEnCurso = DaoFactory.ViajeDistribucionDAO.FindEnCurso(Coche);
                    if (viajeEnCurso == null)
                    {
                        var codigoRuta = DateTime.Today.ToString("yyMMdd") + "|" + text.Replace(prefijo, string.Empty).Trim();
                        var viaje      = DaoFactory.ViajeDistribucionDAO.FindByCodigo(Coche.Empresa.Id, Coche.Linea.Id, codigoRuta);
                        if (viaje != null)
                        {
                            if (viaje.Estado == ViajeDistribucion.Estados.Pendiente)
                            {
                                viaje.Vehiculo = Coche;
                                DaoFactory.ViajeDistribucionDAO.SaveOrUpdate(viaje);

                                var ciclo  = new CicloLogisticoDistribucion(viaje, DaoFactory, new MessageSaver(DaoFactory));
                                var evento = new InitEvent(DateTime.UtcNow);
                                ciclo.ProcessEvent(evento);

                                mensaje = mensaje.AddMessageText("RUTA " + codigoRuta + " INICIADA");
                                STrace.Trace("AsignoDistribucionPorMensaje", string.Format("RUTA {0} INICIADA", codigoRuta));
                            }
                            else
                            {
                                mensaje = mensaje.AddMessageText("NO ES POSIBLE INICIAR LA RUTA " + codigoRuta);
                                STrace.Trace("AsignoDistribucionPorMensaje", string.Format("NO ES POSIBLE INICIAR LA RUTA {0}", codigoRuta));
                            }
                        }
                        else
                        {
                            mensaje = mensaje.AddMessageText("RUTA " + codigoRuta + " NO ENCONTRADA");
                            STrace.Trace("AsignoDistribucionPorMensaje", string.Format("RUTA {0} NO ENCONTRADA", codigoRuta));
                        }
                    }
                    else
                    {
                        mensaje = mensaje.AddMessageText("USTED YA TIENE ASIGNADA UNA RUTA INICIADA");
                        STrace.Trace("AsignoDistribucionPorMensaje", string.Format("USTED YA TIENE ASIGNADA UNA RUTA INICIADA"));
                    }
                    mensaje.Send();
                }
            }

            return(HandleResults.Success);
        }