예제 #1
0
        public LogEvento SaveLogEventoSensor(Dispositivo dispositivo, Sensor sensor, SubEntidad subEntidad, DateTime inicio, DateTime fin, String codigo, String texto, IMessage evento)
        {
            try
            {
                var device = dispositivo ?? GetGenericDevice();

                var mensaje = GetByCodigo(codigo, sensor);

                if (mensaje == null)
                {
                    return(null);
                }

                var msg = SaveLogEvento(device, sensor, subEntidad, mensaje, texto, inicio, fin);

                return(msg);
            }
            catch (Exception ex)
            {
                STrace.Exception(GetType().FullName, ex);

                return(null);
            }
            finally
            {
                DisposeResources();
            }
        }
예제 #2
0
        public LogEvento Save(string codigo, Dispositivo dispositivo, Sensor sensor, SubEntidad subEntidad, DateTime inicio, DateTime fin, string texto)
        {
            var mensaje = !String.IsNullOrEmpty(codigo) ? GetByCodigo(codigo, sensor) : null;

            if (mensaje == null)
            {
                DiscardEvent(null, dispositivo, null, null, inicio, null, null, DiscardReason.NoMessageFound, codigo);
                return(null);
            }

            var log = new LogEvento
            {
                Dispositivo = dispositivo,
                Sensor      = sensor,
                SubEntidad  = subEntidad,
                Mensaje     = DaoFactory.MensajeDAO.FindById(mensaje.Id),
                Fecha       = inicio,
                FechaFin    = fin,
                Expiracion  = DateTime.UtcNow.AddDays(1),
                Estado      = 0,
                Texto       = String.Concat(mensaje.Texto, ' ', texto)
            };

            ProcessActions(log, subEntidad);

            return(log);
        }
예제 #3
0
        private void LoadAlarmas(EntidadPadre entidad, SubEntidad subEntidad)
        {
            var alarmas = DAOFactory.LogEventoDAO.GetByEntitiesAndCodes(new List <int> {
                entidad.Id
            },
                                                                        new List <string> {
                _codigoPolicia, _codigoBomberos, _codigoAmbulancia, _codigoExcesoTemperatura, _codigoBajaTemperatura, _codigoDesconexionTemperatura
            },
                                                                        dtDesde.SelectedDate.HasValue ? SecurityExtensions.ToDataBaseDateTime(dtDesde.SelectedDate.Value) : DateTime.MinValue,
                                                                        dtHasta.SelectedDate.HasValue ? SecurityExtensions.ToDataBaseDateTime(dtHasta.SelectedDate.Value) : DateTime.MinValue);
            var validas = alarmas.Where(alarma => alarma.Sensor != null &&
                                        (subEntidad == null ||
                                         alarma.SubEntidad.Id == subEntidad.Id))
                          .ToList();

            gridAlarmas.Columns[0].HeaderText = CultureManager.GetLabel("DATE");
            gridAlarmas.Columns[1].HeaderText = CultureManager.GetEntity("PARENTI79");
            gridAlarmas.Columns[2].HeaderText = CultureManager.GetEntity("PARENTI81");
            gridAlarmas.Columns[3].HeaderText = CultureManager.GetLabel("TEXTO");
            gridAlarmas.DataSource            = validas;
            gridAlarmas.DataBind();

            lblTitAlarma.Text = subEntidad != null
                                    ? CultureManager.GetLabel("ALARMAS_SUBENTIDAD") + @" " + subEntidad.Descripcion + @":"
                                    : CultureManager.GetLabel("ALARMAS_ENTIDAD") + @" " + entidad.Descripcion + @":";

            lblTitAlarma.Visible  = true;
            gridAlarmas.Visible   = validas.Count > 0;
            lblSinAlarmas.Visible = validas.Count == 0;
        }
예제 #4
0
        private void AddMarker(SubEntidad subentidad, string style)
        {
            if (subentidad == null)
            {
                return;
            }
            var ultimaMedicion = DAOFactory.MedicionDAO.GetUltimaMedicionHasta(subentidad.Sensor.Dispositivo.Id, subentidad.Sensor.Id, DateTime.UtcNow);

            var ctrl = divPlano.FindControl("sub" + subentidad.Id);

            if (ctrl != null)
            {
                return;
            }

            var panel = new Panel();

            divPlano.Controls.Add(panel);

            var styleSplit = style.Split('_');
            var color      = "grey";

            if (styleSplit.Length == 4)
            {
                color = styleSplit[3];
            }

            var bal = new BaloonTip {
                Url  = ImagesDir + "button-" + color + ".png",
                Text = GetValor(subentidad, ultimaMedicion),
                ID   = "sub" + subentidad.Id,
                Css  = "monitor"
            };

            var ratio = _imageSize.Width * 1.0 / ImageWidth;
            var x     = (short)(subentidad.X / ratio);
            var y     = (short)(subentidad.Y / ratio);

            bal.Style.Add(HtmlTextWriterStyle.Left, x + "px");
            bal.Style.Add(HtmlTextWriterStyle.Top, y + "px");
            bal.Style.Add(HtmlTextWriterStyle.Position, "absolute");
            bal.Style.Add(HtmlTextWriterStyle.Cursor, "pointer");

            panel.Controls.Add(bal);

            var lbl = new Label {
                Text = subentidad.Descripcion, CssClass = style
            };

            lbl.Style.Add(HtmlTextWriterStyle.Left, (x - 5) + "px");
            lbl.Style.Add(HtmlTextWriterStyle.Top, (y + 33) + "px");
            lbl.Style.Add(HtmlTextWriterStyle.Position, "absolute");

            divPlano.Controls.Add(lbl);
        }
예제 #5
0
        public SubEntidadVo(SubEntidad subEntidad)
        {
            Id           = subEntidad.Id;
            Codigo       = subEntidad.Codigo;
            Descripcion  = subEntidad.Descripcion;
            TipoEntidad  = subEntidad.Entidad.TipoEntidad.ToString();
            Entidad      = subEntidad.Entidad.ToString();
            TipoMedicion = subEntidad.Sensor != null?subEntidad.Sensor.TipoMedicion.ToString() : "";

            Sensor = subEntidad.Sensor != null?subEntidad.Sensor.ToString() : "";
        }
예제 #6
0
        private LogEvento SaveLogEvento(Dispositivo dispositivo, Sensor sensor, SubEntidad subEntidad, MensajeVO mensaje, string texto, DateTime inicio, DateTime fin)
        {
            var log = new LogEvento
            {
                Dispositivo = dispositivo,
                Sensor      = sensor,
                SubEntidad  = subEntidad,
                Mensaje     = DaoFactory.MensajeDAO.FindById(mensaje.Id),
                Fecha       = inicio,
                FechaFin    = fin,
                Expiracion  = DateTime.UtcNow.AddDays(1),
                Estado      = 0,
                Texto       = String.Concat(mensaje.Texto, ' ', texto)
            };

            SaveLogEvento(log);

            return(log);
        }
예제 #7
0
        private void ProcessActions(LogEvento log, SubEntidad subEntidad)
        {
            var appliesToAnyAction = false;

            var actions = DaoFactory.AccionDAO.FindByMensaje(log.Mensaje).Cast <Accion>().ToList();

            if (subEntidad.Empresa != null)
            {
                actions = actions.Where(a => a.Empresa == null ||
                                        a.Empresa.Id == -1 ||
                                        a.Empresa.Id == subEntidad.Empresa.Id)
                          .ToList();
            }
            if (subEntidad.Linea != null)
            {
                actions = actions.Where(a => a.Linea == null ||
                                        a.Linea.Id == -1 ||
                                        a.Linea.Id == subEntidad.Linea.Id)
                          .ToList();
            }

            var filteredActions = FilterActions(actions, log);

            foreach (var accion in filteredActions)
            {
                appliesToAnyAction = true;

                DaoFactory.RemoveFromSession(log);

                log.Id     = 0;
                log.Accion = accion;

                if (accion.CambiaMensaje)
                {
                    log.Texto += string.Concat(" ", accion.MensajeACambiar);
                }
                //if (accion.PideFoto) PedirFoto(log);
                if (accion.GrabaEnBase)
                {
                    DaoFactory.LogEventoDAO.Save(log);
                    DaoFactory.LogEventoDAO.Save(log);
                }
                if (accion.EsAlarmaDeMail)
                {
                    SendMail(log);
                }
                if (accion.EsAlarmaSms)
                {
                    SendSms(log);
                }
                if (accion.Habilita)
                {
                    HabilitarUsuario(log.Accion);
                }
                if (accion.Inhabilita)
                {
                    InhabilitarUsuario(log.Accion);
                }
                //if (accion.ReportarAssistCargo) ReportarAssistCargo(log, accion.CodigoAssistCargo);
            }

            if (!appliesToAnyAction)
            {
                DaoFactory.LogEventoDAO.Save(log);
                DaoFactory.LogEventoDAO.Save(log);
            }
        }
예제 #8
0
        private string GetMarkerStyle(SubEntidad subEntidad)
        {
            var style = "";

            var ultimaMedicion = DAOFactory.MedicionDAO.GetUltimaMedicionHasta(subEntidad.Sensor.Dispositivo.Id, subEntidad.Sensor.Id, DateTime.UtcNow);
            var ultimoEventoDescongelamiento = DAOFactory.LogEventoDAO.GetLastBySensoresAndCodes(new[] { subEntidad.Sensor.Id },
                                                                                                 new[] { Convert.ToInt32(MessageIdentifier.TemperatureThawingButtonPressed).ToString(),
                                                                                                         Convert.ToInt32(MessageIdentifier.TemperatureThawingButtonUnpressed).ToString() });
            var ultimoEventoConexion = DAOFactory.LogEventoDAO.GetLastBySensoresAndCodes(new[] { subEntidad.Sensor.Id },
                                                                                         new[] { Convert.ToInt32(MessageIdentifier.TemperaturePowerReconected).ToString(),
                                                                                                 Convert.ToInt32(MessageIdentifier.TemperaturePowerDisconected).ToString() });
            var ultimoEventoBotonera = DAOFactory.LogEventoDAO.GetLastBySensoresAndCodes(new[] { subEntidad.Sensor.Id },
                                                                                         new[] { Convert.ToInt32(MessageIdentifier.KeyboardButton1).ToString(),
                                                                                                 Convert.ToInt32(MessageIdentifier.KeyboardButton2).ToString(),
                                                                                                 Convert.ToInt32(MessageIdentifier.KeyboardButton3).ToString() });
            var enDescogelamiento = ultimoEventoDescongelamiento != null &&
                                    ultimoEventoDescongelamiento.Mensaje != null &&
                                    ultimoEventoDescongelamiento.Mensaje.Codigo == Convert.ToInt32(MessageIdentifier.TemperatureThawingButtonPressed).ToString();

            var energiaDesconectada = ultimoEventoConexion != null &&
                                      ultimoEventoConexion.Mensaje != null &&
                                      ultimoEventoConexion.Mensaje.Codigo == Convert.ToInt32(MessageIdentifier.TemperaturePowerDisconected).ToString();

            var enEmergencia = ultimoEventoBotonera != null && ultimoEventoBotonera.Fecha > DateTime.UtcNow.AddMinutes(-10);

            if (ultimaMedicion != null)
            {
                switch (ultimaMedicion.TipoMedicion.Codigo)
                {
                case "TEMP":
                    if (enDescogelamiento)
                    {
                        style = "ol_marker_labeled_blue";
                    }
                    else
                    {
                        if (energiaDesconectada ||
                            (ultimaMedicion.ValorDouble > subEntidad.Maximo && subEntidad.ControlaMaximo) ||
                            (ultimaMedicion.ValorDouble < subEntidad.Minimo && subEntidad.ControlaMinimo))
                        {
                            return("ol_marker_labeled_red");
                        }

                        if (ultimaMedicion.FechaMedicion < DateTime.UtcNow.AddHours(-3))
                        {
                            if (style != "ol_marker_labeled_blue")
                            {
                                style = "ol_marker_labeled";
                            }
                        }
                        else
                        {
                            if (style == "")
                            {
                                style = "ol_marker_labeled_green";
                            }
                        }
                    }
                    break;

                case "EST":
                    if (enEmergencia)
                    {
                        return("ol_marker_labeled_red");
                    }

                    if (ultimaMedicion.FechaMedicion < DateTime.UtcNow.AddHours(-3))
                    {
                        if (style != "ol_marker_labeled_blue")
                        {
                            style = "ol_marker_labeled";
                        }
                    }
                    else
                    {
                        if (style == "")
                        {
                            style = "ol_marker_labeled_green";
                        }
                    }
                    break;

                case "NU":
                    if (ultimaMedicion.FechaMedicion < DateTime.UtcNow.AddHours(-2))
                    {
                        if (style != "ol_marker_labeled_blue")
                        {
                            style = "ol_marker_labeled";
                        }
                    }
                    else
                    {
                        if (ultimaMedicion.FechaMedicion < DateTime.UtcNow.AddHours(-1))
                        {
                            if (style == "ol_marker_labeled_green" || style == "")
                            {
                                style = "ol_marker_labeled_yellow";
                            }
                        }
                        else
                        {
                            if (style == "")
                            {
                                style = "ol_marker_labeled_green";
                            }
                        }
                    }
                    break;

                default:
                    if (ultimaMedicion.FechaMedicion < DateTime.UtcNow.AddHours(-2))
                    {
                        if (style != "ol_marker_labeled_blue")
                        {
                            style = "ol_marker_labeled";
                        }
                    }
                    else
                    {
                        if (ultimaMedicion.FechaMedicion < DateTime.UtcNow.AddHours(-1))
                        {
                            if (style == "ol_marker_labeled_green" || style == "")
                            {
                                style = "ol_marker_labeled_yellow";
                            }
                        }
                        else
                        {
                            if (style == "")
                            {
                                style = "ol_marker_labeled_green";
                            }
                        }
                    }
                    break;
                }
            }

            return(style != "" ? style : "ol_marker_labeled");
        }
예제 #9
0
        private string GetValor(SubEntidad subentidad, Medicion ultimaMedicion)
        {
            var valor = "<b>" + CultureManager.GetLabel("DESCRIPCION") + ":</b> " + subentidad.Descripcion + "<br>";

            switch (subentidad.Sensor.TipoMedicion.Codigo)
            {
            case "TEMP":
                if (ultimaMedicion != null)
                {
                    valor += "<b>" + CultureManager.GetLabel("ULTIMO_REPORTE") + ":</b> " + ultimaMedicion.FechaMedicion.ToDisplayDateTime().ToString("dd/MM/yyyy HH:mm");
                    valor += "<br><b>";
                    valor += CultureManager.GetLabel("VALOR") + ":</b> ";
                    valor += ultimaMedicion.Valor;
                    valor += "<br>";

                    //EVALUO CONEXION
                    valor += "<b>" + CultureManager.GetLabel("ENERGIA") + ":</b> ";
                    var ultimoEventoConexion =
                        DAOFactory.LogEventoDAO.GetLastBySensoresAndCodes(new[] { subentidad.Sensor.Id },
                                                                          new[] { Convert.ToInt32(MessageIdentifier.TemperaturePowerDisconected).ToString(),
                                                                                  Convert.ToInt32(MessageIdentifier.TemperaturePowerReconected).ToString() });

                    if (ultimoEventoConexion != null &&
                        ultimoEventoConexion.Mensaje.Codigo == Convert.ToInt32(MessageIdentifier.TemperaturePowerDisconected).ToString())
                    {
                        valor += "Off";
                    }
                    else
                    {
                        valor += "On";
                    }

                    if (ultimoEventoConexion != null)
                    {
                        valor += " (" + ultimoEventoConexion.Fecha.ToDisplayDateTime().ToString("dd/MM/yyyy HH:mm") + ")";
                    }

                    valor += "<br>";

                    //EVALUO DESCONGELAMIENTO
                    valor += "<b>" + CultureManager.GetLabel("DESCONGELAMIENTO") + ":</b> ";

                    var ultimoEventoDescongelamiento =
                        DAOFactory.LogEventoDAO.GetLastBySensoresAndCodes(new[] { subentidad.Sensor.Id },
                                                                          new[] { Convert.ToInt32(MessageIdentifier.TemperatureThawingButtonPressed).ToString(),
                                                                                  Convert.ToInt32(MessageIdentifier.TemperatureThawingButtonUnpressed).ToString() });

                    if (ultimoEventoDescongelamiento != null &&
                        ultimoEventoDescongelamiento.Mensaje.Codigo == Convert.ToInt32(MessageIdentifier.TemperatureThawingButtonPressed).ToString())
                    {
                        valor += "On";
                    }
                    else
                    {
                        valor += "Off";
                    }

                    if (ultimoEventoDescongelamiento != null)
                    {
                        valor += " (" + ultimoEventoDescongelamiento.Fecha.ToDisplayDateTime().ToString("dd/MM/yyyy HH:mm") + ")";
                    }
                }
                else
                {
                    valor += "<b>" + CultureManager.GetLabel("ULTIMO_REPORTE") + ":</b> -<br>";
                    valor += "<b>" + CultureManager.GetLabel("VALOR") + ":</b> -<br>";
                    valor += "<b>" + CultureManager.GetLabel("ENERGIA") + ":</b> -<br>";
                    valor += "<b>" + CultureManager.GetLabel("DESCONGELAMIENTO") + ":</b> -";
                }
                break;

            case "EST":
                if (ultimaMedicion != null)
                {
                    valor += "<b>" + CultureManager.GetLabel("ULTIMO_REPORTE") + ":</b> " + ultimaMedicion.FechaMedicion.ToDisplayDateTime().ToString("dd/MM/yyyy HH:mm");
                    valor += "<br>";

                    //EVALUO CHECK
                    var ultimoCheckPoint =
                        DAOFactory.LogEventoDAO.GetLastBySensoresAndCodes(new[] { subentidad.Sensor.Id },
                                                                          new[] { Convert.ToInt32(MessageIdentifier.CheckpointReached).ToString() });

                    if (ultimoCheckPoint == null)
                    {
                        //EVALUO 911
                        valor += "<b>911:</b> ";
                        var ultimoEvento911 =
                            DAOFactory.LogEventoDAO.GetLastBySensoresAndCodes(new[] { subentidad.Sensor.Id },
                                                                              new[] { Convert.ToInt32(MessageIdentifier.KeyboardButton1).ToString() });

                        if (ultimoEvento911 != null &&
                            ultimoEvento911.Fecha > DateTime.UtcNow.AddMinutes(-10))
                        {
                            valor += "On (" + ultimoEvento911.Fecha.ToDisplayDateTime().ToString("dd/MM/yyyy HH:mm") + ")";
                        }
                        else
                        {
                            valor += "Off";
                        }
                        valor += "<br>";

                        //EVALUO AMBULANCIA
                        valor += "<b>" + CultureManager.GetLabel("AMBULANCIA") + ":</b> ";
                        var ultimoEventoAmbulancia =
                            DAOFactory.LogEventoDAO.GetLastBySensoresAndCodes(new[] { subentidad.Sensor.Id },
                                                                              new[] { Convert.ToInt32(MessageIdentifier.KeyboardButton2).ToString() });

                        if (ultimoEventoAmbulancia != null &&
                            ultimoEventoAmbulancia.Fecha > DateTime.UtcNow.AddMinutes(-10))
                        {
                            valor += "On (" + ultimoEventoAmbulancia.Fecha.ToDisplayDateTime().ToString("dd/MM/yyyy HH:mm") + ")";
                        }
                        else
                        {
                            valor += "Off";
                        }
                        valor += "<br>";

                        //EVALUO BOMBEROS
                        valor += "<b>" + CultureManager.GetLabel("BOMBEROS") + ":</b> ";
                        var ultimoEventoBombero =
                            DAOFactory.LogEventoDAO.GetLastBySensoresAndCodes(new[] { subentidad.Sensor.Id },
                                                                              new[] { Convert.ToInt32(MessageIdentifier.KeyboardButton3).ToString() });

                        if (ultimoEventoBombero != null &&
                            ultimoEventoBombero.Fecha > DateTime.UtcNow.AddMinutes(-10))
                        {
                            valor += "On (" + ultimoEventoBombero.Fecha.ToDisplayDateTime().ToString("dd/MM/yyyy HH:mm") + ")";
                        }
                        else
                        {
                            valor += "Off";
                        }
                    }
                }
                else
                {
                    valor += "<b>" + CultureManager.GetLabel("ULTIMO_REPORTE") + ":</b> -<br>";
                    valor += "<b>911:</b> -<br>";
                    valor += "<b>" + CultureManager.GetLabel("AMBULANCIA") + ":</b> -<br>";
                    valor += "<b>" + CultureManager.GetLabel("BOMBEROS") + ":</b> -";
                }
                break;

            case "NU":
                if (ultimaMedicion != null)
                {
                    valor += "<b>" + CultureManager.GetLabel("ULTIMO_REPORTE") + ":</b> " + ultimaMedicion.FechaMedicion.ToDisplayDateTime().ToString("dd/MM/yyyy HH:mm");
                    valor += "<br>";
                    valor += "<b>" + CultureManager.GetLabel("VALOR") + ":</b> ";
                    valor += ultimaMedicion.Valor;
                }
                else
                {
                    valor += "<b>" + CultureManager.GetLabel("ULTIMO_REPORTE") + ":</b> -<br>";
                    valor += "<b>" + CultureManager.GetLabel("VALOR") + ":</b> -";
                }
                break;

            case "TIME":
                if (ultimaMedicion != null)
                {
                    valor += "<b>" + CultureManager.GetLabel("ULTIMO_REPORTE") + ":</b> " + ultimaMedicion.FechaMedicion.ToDisplayDateTime().ToString("dd/MM/yyyy HH:mm");
                    valor += "<br>";
                    valor += "<b>" + CultureManager.GetLabel("VALOR") + ":</b> ";
                    var time = new TimeSpan(0, 0, 0, int.Parse(ultimaMedicion.Valor));
                    valor += time.ToString();
                }
                else
                {
                    valor += "<b>" + CultureManager.GetLabel("ULTIMO_REPORTE") + ":</b> -<br>";
                    valor += "<b>" + CultureManager.GetLabel("VALOR") + ":</b> -";
                }
                break;

            default:
                if (ultimaMedicion != null)
                {
                    valor += "<b>" + CultureManager.GetLabel("ULTIMO_REPORTE") + ":</b> " + ultimaMedicion.FechaMedicion.ToDisplayDateTime().ToString("dd/MM/yyyy HH:mm");
                    valor += "<br>";
                    valor += "<b>" + CultureManager.GetLabel("VALOR") + ":</b> ";
                    valor += ultimaMedicion.Valor;
                }
                else
                {
                    valor += "<b>" + CultureManager.GetLabel("ULTIMO_REPORTE") + ":</b> -<br>";
                    valor += "<b>" + CultureManager.GetLabel("VALOR") + ":</b> -";
                }
                break;
            }

            return(valor);
        }