Example #1
0
        public SharedPopupM2M(LogEvento ev)
        {
            Id            = ev.Id;
            Sensor        = ev.Sensor.Descripcion;
            IdSensor      = ev.Sensor.Id;
            SubEntidad    = ev.SubEntidad.Descripcion;
            IdSubEntidad  = ev.SubEntidad.Id;
            CodigoMensaje = ev.Mensaje.Codigo;
            DateTime      = ev.Fecha;
            Text          = ev.Texto;

            if (ev.Accion != null)
            {
                Color = "#" + ev.Accion.RGB;

                if (ev.Accion.Sonido != null)
                {
                    Sound = ev.Accion.Sonido.URL;
                }
            }
            else
            {
                Color = "#CCCCCC";
            }
        }
Example #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);
        }
Example #3
0
        private static void SendMail(LogEvento log)
        {
            var link = string.Empty;

            var responsable = string.Empty;

            var parameters = log.SubEntidad != null
                                 ? new List <string>
            {
                log.SubEntidad.Linea != null ? log.SubEntidad.Linea.Descripcion : log.SubEntidad.Empresa != null ? log.SubEntidad.Empresa.RazonSocial : "Sistema",
                log.SubEntidad.Descripcion,
                responsable,
                log.SubEntidad.ToLocalString(log.Fecha, true),
                string.Empty,
                log.Texto,
                link
            }
                                 : new List <string>
            {
                "Sistema",
                "(Ninguno)",
                responsable,
                string.Format("{0} {1}", log.Fecha.ToShortDateString(), log.Fecha.ToShortTimeString()),
                string.Empty,
                log.Texto,
                link
            };

            SendMailToAllDestinations(log.Accion.DestinatariosMail, null, log.Accion.AsuntoMail, parameters);
        }
Example #4
0
        private static void SendMailToAllDestinations(LogEvento log, MailSender sender, List <string> parameters)
        {
            if (string.IsNullOrEmpty(log.Accion.DestinatariosMail))
            {
                return;
            }

            var originalSubject = !string.IsNullOrEmpty(log.Accion.AsuntoMail) ? log.Accion.AsuntoMail : sender.Config.Subject;

            var destinatariosMail = log.Accion.DestinatariosMail.Replace(',', ';');

            var destinos = destinatariosMail.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            if (destinos.Count().Equals(0))
            {
                return;
            }

            foreach (var destinatario in destinos)
            {
                if (string.IsNullOrEmpty(destinatario))
                {
                    continue;
                }

                sender.Config.Subject   = originalSubject;
                sender.Config.ToAddress = destinatario.Trim();
                sender.SendMail(parameters.ToArray());
            }
        }
Example #5
0
        private static void SendMail(LogEvento log)
        {
            var configFile = Config.Mailing.MailingConfiguration;

            if (string.IsNullOrEmpty(configFile))
            {
                throw new Exception("No pudo cargarse configuracion de mailing.");
            }

            var sender = new MailSender(configFile);

            var monitor = Config.Monitor.SubEntidadesMonitorLink;

            var link = string.Format(@"{0}?ID_SUBENTIDAD={1}", monitor, log.SubEntidad != null ? log.SubEntidad.Id : -1);

            var parameters = new List <string>
            {
                log.SubEntidad != null && log.SubEntidad.Linea != null ? log.SubEntidad.Linea.Descripcion : log.SubEntidad != null && log.SubEntidad.Empresa != null ? log.SubEntidad.Empresa.RazonSocial : "Sistema",
                log.SubEntidad != null ? log.SubEntidad.Descripcion : "",
                log.Sensor != null ? log.Sensor.Descripcion : "",
                GetFecha(log, true),
                AddresserHelper.GetDescripcionEsquinaMasCercana(log.SubEntidad != null ? log.SubEntidad.Entidad.ReferenciaGeografica.Latitude : 0, log.SubEntidad != null ? log.SubEntidad.Entidad.ReferenciaGeografica.Longitude : 0),
                log.Texto,
                link
            };

            SendMailToAllDestinations(log, sender, parameters);
        }
Example #6
0
 public static void GuardarEvento(LogEvento evento)
 {
     try
     {
         ApplicationDbContext db = new ApplicationDbContext();
         new Repositorio <LogEvento>(db).Crear(evento);
     }
     catch (Exception e) { }
 }
Example #7
0
 public LogEventoVo(LogEvento logEvento)
 {
     Fecha         = logEvento.Fecha.ToDisplayDateTime().ToString("dd/MM/yyyy HH:mm:ss");
     Mensaje       = logEvento.Mensaje.Descripcion;
     Texto         = logEvento.Texto;
     Dispositivo   = logEvento.Dispositivo.Codigo;
     IdDispositivo = logEvento.Dispositivo.Id;
     Entidad       = logEvento.SubEntidad.Entidad.Descripcion;
     SubEntidad    = logEvento.SubEntidad.Descripcion;
     Sensor        = logEvento.Sensor.Descripcion;
 }
Example #8
0
 public static void GuardarEvento(LogEvento evento)
 {
     try
     {
         ApplicationDbContext db = new ApplicationDbContext();
         new Repositorio <LogEvento>(db).Crear(evento);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Example #9
0
        private static IEnumerable <Accion> GetMatchingActions(IEnumerable actions, LogEvento evento)
        {
            if (actions == null)
            {
                return(new List <Accion>());
            }

            return(from action in actions.OfType <Accion>().ToList()
                   where action.Empresa == null || evento.Dispositivo.Empresa == null || action.Empresa.Id.Equals(evento.Dispositivo.Empresa.Id)
                   where action.Linea == null || evento.Dispositivo.Linea == null || action.Linea.Id.Equals(evento.Dispositivo.Linea.Id)
                   select action);
        }
        public bool InsertLog(LogEvento log)
        {
            var command   = $@"INSERT INTO [dbo].[LogEvento] ([EventID],[LogLevel],[Message],[CreatedTime]) VALUES (@EventID, @LogLevel, @Message, @CreatedTime)";
            var paramList = new List <SqlParameter>
            {
                new SqlParameter("EventID", log.EventId),
                new SqlParameter("LogLevel", log.LogLevel),
                new SqlParameter("Message", log.Message),
                new SqlParameter("CreatedTime", log.CreatedTime)
            };

            return(ExecuteNonQuery(command, paramList));
        }
Example #11
0
        public static void LogearEvento(string nombre, string usuarioId, Guid entidadGuid, AccionesLogEnum accion, EntidadLogEnum tipoEntidad)
        {
            var log = new LogEvento()
            {
                Nombre    = nombre,
                usuarioId = usuarioId,
                EntidadId = entidadGuid,
                Accion    = accion,
                Entidad   = tipoEntidad
            };

            var t = new Thread(() => GuardarEvento(log));

            t.Start();
        }
Example #12
0
        private static string GetFecha(LogEvento log, bool includeGmt)
        {
            var timeZoneId = log.SubEntidad.Linea != null ? log.SubEntidad.Linea.TimeZoneId : log.SubEntidad.Empresa != null ? log.SubEntidad.Empresa.TimeZoneId : null;

            if (timeZoneId == null)
            {
                return(string.Concat(log.Fecha.ToString(), " (GMT)"));
            }

            var culture = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);

            var referencia = log.Fecha.AddHours(culture.BaseUtcOffset.TotalHours);

            var fecha = string.Format("{0} {1}", referencia.ToShortDateString(), referencia.ToShortTimeString());

            return(includeGmt ? string.Concat(fecha, string.Format(" ({0})", culture.DisplayName)) : fecha);
        }
Example #13
0
        private IEnumerable <Accion> FilterActions(ICollection <Accion> actions, LogEvento evento)
        {
            if (actions == null || actions.Count.Equals(0))
            {
                return(new List <Accion>());
            }

            var actionsToCheck = GetMatchingActions(actions, evento);

            var actionsToApply = actionsToCheck.Where(action => ApplyAction(evento, action));

            var filteredActions = new List <Accion>(actionsToCheck.Count());

            filteredActions.AddRange(actionsToApply);

            return(filteredActions);
        }
Example #14
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);
        }
        public LogEvento InclusaoLogEvento(int codigo, DateTime dataAtivacao, string token, bool ativo)
        {
            var logEvento = new LogEvento();

            logEvento.CodigoDispositivo = codigo;
            logEvento.Status            = ativo;
            logEvento.Token             = token;
            logEvento.DataEvento        = dataAtivacao;

            db.LogEventoModels.Add(logEvento);
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                logEvento.MensagemErro = e.Message;
            }
            return(logEvento);
        }
Example #16
0
        private static void SendSms(LogEvento log)
        {
            var parameters = log.SubEntidad != null
                                 ? new List <string>
            {
                log.SubEntidad.Linea != null? log.SubEntidad.Linea.Descripcion : log.SubEntidad.Empresa != null ? log.SubEntidad.Empresa.RazonSocial : "Sistema",
                log.SubEntidad.Descripcion,
                log.SubEntidad.ToLocalString(log.Fecha, false),
                log.Texto
            }
                                 : new List <string>
            {
                "Sistema",
                "(Ninguno)",
                string.Format("{0} {1}", log.Fecha.ToShortDateString(), log.Fecha.ToShortTimeString()),
                log.Texto
            };

            SendSms(log.Accion.DestinatariosSms, parameters);
        }
Example #17
0
        private static string GetRowText(LogEvento evento)
        {
            const string template = "<table o='{8}' style='background-color:#{5};color:#{6};' onclick='s({7})'><tr><td class='r1'><h6>{0}</h6> {1}</td><td class='r2'>{2}</td><td class='r3'>{3}</td><td>{4}</td></tr></table>";
            var          col      = evento.Accion != null
                          ? Color.FromArgb(100, evento.Accion.Red, evento.Accion.Green, evento.Accion.Blue)
                          : Color.White;

            var fecha = evento.Fecha.ToDisplayDateTime();

            return(string.Format(template,
                                 fecha.ToString("dd-MM"),
                                 fecha.ToString("HH:mm:ss"),
                                 evento.SubEntidad.Entidad.Descripcion,
                                 evento.SubEntidad.Descripcion,
                                 evento.Texto,
                                 evento.Accion != null ? evento.Accion.RGB : "DDDDDD",
                                 col.GetBrightness() > 0.45 ? "000000" : "FFFFFF",
                                 evento.Id,
                                 fecha.ToString("yyyyMMddHHmmss")));
        }
    public static void CriaLogErro(Exception excpt)
    {
        RestClient  client  = new RestClient(string.Format("{0}/{1}", Constantes.WebApiLog, Constantes.CriaLogErro));
        RestRequest request = new RestRequest();

        request.Method = Method.POST;
        LogEvento param = new LogEvento()
        {
            Sistema    = "PORTAL ACESSO SMART",
            Mensagem   = excpt.Message,
            Message    = (excpt.InnerException != null ? excpt.InnerException.Message : string.Empty),
            FullName   = excpt.TargetSite.DeclaringType.FullName,
            Name       = excpt.TargetSite.Name,
            Source     = excpt.Source,
            StackTrace = excpt.StackTrace
        };
        string body = JsonConvert.SerializeObject(param);

        request.AddParameter("application/json", body, ParameterType.RequestBody);
        IRestResponse    response = client.Execute(request);
        WebReturn <bool> api      = JsonConvert.DeserializeObject <WebReturn <bool> >(response.Content);
    }
Example #19
0
        public void Log <TState>(LogLevel logLevel, EventId eventoId,
                                 TState state, Exception exception, Func <TState, Exception, string> formato)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }

            if (formato == null)
            {
                throw new ArgumentNullException(nameof(formato));
            }

            var mensagem = formato(state, exception);

            if (string.IsNullOrEmpty(mensagem))
            {
                return;
            }

            if (exception != null)
            {
                mensagem += $"\n{exception.ToString()}";
            }

            mensagem = mensagem.Length > _messageMaxLength?mensagem.Substring(0, _messageMaxLength) : mensagem;

            var eventLog = new LogEvento()
            {
                Message     = mensagem,
                EventId     = eventoId.Id,
                LogLevel    = logLevel.ToString(),
                CreatedTime = DateTime.UtcNow
            };

            _repositorio.SaveLog(eventLog);
        }
Example #20
0
        public void LogEvento(Dispositivo dispositivo)
        {
            string devpath  = "http://localhost:52526";
            string prodpath = "http://Fusionexchangeconfiguration.azurewebsites.net";

            var logEvento = new LogEvento();

            var urlAplicacao = "";

            if (Debugger.IsAttached)
            {
                urlAplicacao = devpath;
            }
            else
            {
                urlAplicacao = prodpath;
            }

            var acao = "?action=InclusaoLogEvento&codigo={0}&dataAtivacao={1}&token={2}&status={3}";
            var uri  = "/api/LogEvento/InclusaoLogEvento" + acao;

            uri = string.Format(uri,
                                dispositivo.Codigo,
                                dispositivo.DataAtivacao,
                                dispositivo.Token,
                                dispositivo.Ativo);

            var client  = new RestClient(urlAplicacao);
            var request = new RestRequest(uri, Method.POST);

            request.OnBeforeDeserialization    = resp => { resp.ContentType = "application/json"; };
            request.JsonSerializer.ContentType = "application/json; charset=utf-8";
            var response = client.Execute <LogEvento>(request);

            var teste = response.Data.MensagemErro;
        }
Example #21
0
        protected void ShowEvento(LogEvento evento)
        {
            var iconDir = IconDir;

            var color = evento.Accion != null
                            ? Color.FromArgb(100, evento.Accion.Red, evento.Accion.Green, evento.Accion.Blue)
                            : Color.Gray;

            panelTitle.BackColor = color;
            panelTitle.ForeColor = color.GetBrightness() < 40 ? Color.White : Color.Black;

            if (evento.Accion != null && evento.Accion.PopIcon > 0)
            {
                imgAccion.ImageUrl = string.Format("{0}/{1}", iconDir, evento.Accion.PopUpIcon.PathIcono);
            }
            else
            {
                imgAccion.Visible = false;
            }

            lbMensaje.Text     = evento.Texto;
            lblHora.Text       = evento.Fecha.ToDisplayDateTime().ToString("dd \"de\" MMMM \"de\" yyyy HH:mm");
            lblEntidad.Text    = evento.SubEntidad != null ? evento.SubEntidad.Entidad.Descripcion : string.Empty;
            lblSubEntidad.Text = evento.SubEntidad != null ? evento.SubEntidad.Descripcion : string.Empty;
            if (evento.SubEntidad != null)
            {
                foreach (DetalleValor detalle in evento.SubEntidad.Entidad.Detalles)
                {
                    var valor = string.Empty;
                    switch (detalle.Detalle.Tipo)
                    {
                    case 1:
                        valor = detalle.ValorStr;
                        break;

                    case 2:
                        valor = detalle.ValorNum.ToString("#0.00");
                        break;

                    case 3:
                        valor = detalle.ValorDt.HasValue ? detalle.ValorDt.Value.ToString("dd/MM/yyyy HH:mm") : string.Empty;
                        break;
                    }

                    var lbl = new Label {
                        Text = @"<b>" + detalle.Detalle.Nombre + @":</b> " + valor + @"<br/><br/>"
                    };
                    panelDetalles.Controls.Add(lbl);
                }

                lblDireccion.Text = GeocoderHelper.GetDescripcionEsquinaMasCercana(evento.SubEntidad.Entidad.ReferenciaGeografica.Latitude, evento.SubEntidad.Entidad.ReferenciaGeografica.Longitude);
            }

            Monitor1.ImgPath          = Config.Monitor.GetMonitorImagesFolder(this);
            Monitor1.GoogleMapsScript = GoogleMapsKey;
            Monitor1.EnableTimer      = false;
            Monitor1.AddLayers(LayerFactory.GetGoogleStreet(CultureManager.GetLabel("LAYER_GSTREET"), 8),
                               //LayerFactory.GetCompumap(CultureManager.GetLabel("LAYER_COMPUMAP"), Config.Map.CompumapTiles, 8),
                               LayerFactory.GetOpenStreetMap(CultureManager.GetLabel("LAYER_OSM")),
                               LayerFactory.GetGoogleSatellite(CultureManager.GetLabel("LAYER_GSAT"), 8),
                               LayerFactory.GetGoogleHybrid(CultureManager.GetLabel("LAYER_GHIBRIDO"), 8),
                               LayerFactory.GetGooglePhysical(CultureManager.GetLabel("LAYER_GFISICO"), 8),
                               LayerFactory.GetMarkers(LayerEntidades, true));
            Monitor1.AddControls(ControlFactory.GetLayerSwitcher(), ControlFactory.GetNavigation());

            if (evento.SubEntidad != null)
            {
                Monitor1.SetCenter(evento.SubEntidad.Entidad.ReferenciaGeografica.Latitude, evento.SubEntidad.Entidad.ReferenciaGeografica.Longitude, 7);
                var imgEntidad = string.Format("{0}{1}", iconDir, evento.SubEntidad.Entidad.ReferenciaGeografica.Icono.PathIcono);

                Monitor1.AddMarkers(LayerEntidades, MarkerFactory.CreateMarker(evento.SubEntidad.Entidad.Id.ToString("#0"),
                                                                               imgEntidad,
                                                                               evento.SubEntidad.Entidad.ReferenciaGeografica.Latitude,
                                                                               evento.SubEntidad.Entidad.ReferenciaGeografica.Longitude));
            }

            if (evento.Estado > 0)
            {
                btAceptar.Visible  = false;
                btIgnorar.ImageUrl = "~/Operacion/btAtras.gif";
            }
        }
Example #22
0
        public void SaveLog(LogEvento evento)
        {
            var collection = base._database.GetCollection <LogEvento>("Log");

            collection.InsertOne(evento);
        }
Example #23
0
        private static string GetRow(LogEvento evento)
        {
            const string template = "\"{0}\"";

            return(string.Format(template, GetRowText(evento)));
        }
Example #24
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);
            }
        }
Example #25
0
        private void SaveLogEvento(LogEvento log)
        {
            var appliesToAnyAction = false;

            var actions = GetActions(log.Mensaje);

            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);
                }

                if (accion.EsAlarmaDeMail)
                {
                    SendMail(log);
                }

                //if (accion.EsAlarmaSMS) SendSms(log);

                if (accion.Habilita)
                {
                    HabilitarUsuario(log);
                }

                if (accion.Inhabilita)
                {
                    InhabilitarUsuario(log);
                }

                //if (accion.ReportarAssistCargo) ReportarAssistCargo(log, accion.CodigoAssistCargo);
            }

            if (!appliesToAnyAction)
            {
                if (DaoFactory.Session.Transaction != null && DaoFactory.Session.Transaction.IsActive)
                {
                    DaoFactory.LogEventoDAO.SaveWithoutTransaction(log);
                }
                else
                {
                    DaoFactory.LogEventoDAO.Save(log);
                }
            }
        }
Example #26
0
        private static IEnumerable <Accion> FilterActions(ICollection <Accion> actions, LogEvento logEvento)
        {
            if (actions == null || actions.Count.Equals(0))
            {
                return(new List <Accion>());
            }

            return(actions.Where(act => act.Mensaje != null &&
                                 act.Mensaje.Id.Equals(logEvento.Mensaje.Id)));
        }