private List <InfoLog> AnalisarEventos(List <EventoLog> eventoLogs)
        {
            List <InfoLog> infoLogs = new List <InfoLog>();
            InfoLog        infoLog  = null;

            if (eventoLogs != null)
            {
                EventoLog eventoAnterior = null;
                eventoLogs.ForEach(x =>
                {
                    infoLog = getAlarmes(x);
                    if (infoLog != null)
                    {
                        infoLogs.Add(infoLog);
                    }

                    infoLog = getEOT(x, eventoAnterior);
                    if (infoLog != null)
                    {
                        infoLogs.Add(infoLog);
                    }

                    infoLog = getCorteTracaoEmergencia(x, eventoAnterior);
                    if (infoLog != null)
                    {
                        infoLogs.Add(infoLog);
                    }

                    eventoAnterior = x;
                }
                                   );
            }

            return(infoLogs);
        }
        List <EventoLog> LerArquivos()
        {
            List <EventoLog> eventoLogs = new List <EventoLog>();
            DirectoryInfo    dir        = new DirectoryInfo(Path.Combine(destino));
            List <FileInfo>  fileInfo   = dir.GetFiles().ToList();

            fileInfo.ForEach(x =>
            {
                if (x.Extension.ToUpper().Contains("TXT"))
                {
                    using (StreamReader sr = x.OpenText())
                    {
                        string s = "";
                        while ((s = sr.ReadLine()) != null)
                        {
                            if (s != null)
                            {
                                if (s.Count() == 157 && s.Substring(0, 1).Contains("#"))
                                {
                                    EventoLog eventoLog = new EventoLog(s);
                                    eventoLogs.Add(eventoLog);
                                }
                            }
                        }
                    }
                }
            });

            return(eventoLogs);
        }
        private InfoLog getCorteTracaoEmergencia(EventoLog x, EventoLog eventoAnterior)
        {
            InfoLog infoLog = new InfoLog();

            infoLog.Ativo     = Locomotiva;
            infoLog.Nome      = "CorteTracaoEmergencia";
            infoLog.Descricao = "";
            infoLog.Data      = x.time;
            infoLog.Log       = nomeLog;


            if (eventoAnterior != null)
            {
                if (x.CORTE_TRACAO == 1 && eventoAnterior.CORTE_TRACAO == 0)
                {
                    infoLog.Descricao = "|Locomotiva Helper apresentou *CORTE DE TRAÇÃO  ";
                }

                if (x.EMERGENCIA == 1 && eventoAnterior.EMERGENCIA == 0)
                {
                    infoLog.Descricao = infoLog.Descricao + "|Locomotiva Helper apresentou *EMERGÊNCIA";
                }

                if ((x.EMERGENCIA == 1 && eventoAnterior.EMERGENCIA == 0) || (x.CORTE_TRACAO == 1 && eventoAnterior.CORTE_TRACAO == 0))
                {
                    infoLog.Descricao = infoLog.Descricao + "|[ posição Locomotiva Helper : KM" + posicaoHelper_KM(x) + ", posição do EOT : KM" + posicaoTrem_KM(eventoAnterior) + " ]";

                    InfoLog i = getAlarmes(x);
                    if (i != null)
                    {
                        if (!i.Descricao.Equals(""))
                        {
                            infoLog.Descricao = infoLog.Descricao + "|Motivo Aparente => " + i.Descricao;
                        }
                    }
                }

                if (x.CILINDRO_PINO_ENGATE == 1 && eventoAnterior.CILINDRO_PINO_ENGATE == 0)
                {
                    infoLog.Descricao = infoLog.Descricao + "|Pino de Engate abaixado";
                }


                if (x.CILINDRO_PINO_ENGATE == 0 && eventoAnterior.CILINDRO_PINO_ENGATE == 1)
                {
                    infoLog.Descricao = infoLog.Descricao + "|Pino de Engate Levantado";
                }
            }

            if (infoLog.Descricao.Equals(""))
            {
                return(null);
            }
            else
            {
                infoLog.Descricao += (x.CHAVE_INTERLOCK == 1) ? "|Modo de Operação" : "|Modo de Manutenção";
                return(infoLog);
            }
        }
 public int posicaoTrem_KM(EventoLog ev)
 {
     if (ev.POSICAOHELPER_GPS < 0)
     {
         return(617000 + Math.Abs(ev.POSICAO_EOT_GPS));
     }
     else
     {
         return(617000 - Math.Abs(ev.POSICAO_EOT_GPS));
     }
 }
        private InfoLog getEOT(EventoLog x, EventoLog eventoAnterior)
        {
            InfoLog infoLog = new InfoLog();

            infoLog.Ativo     = EOT;
            infoLog.Nome      = "EOT";
            infoLog.Descricao = "";
            infoLog.Data      = x.time;
            infoLog.Log       = nomeLog;

            if (x.BAT_EOT < minBAT_EOT && x.ID_EOT > 0)
            {
                infoLog.Descricao = "EOT com Id: " + x.ID_EOT + " Apresentou " + x.BAT_EOT + " %  de Bateria";
            }

            if (eventoAnterior != null)
            {
                if (x.ESTADO_GPS_EOT == 0 && x.ID_EOT > 0)
                {
                    infoLog.Descricao = infoLog.Descricao + "| EOT com Id: " + x.ID_EOT + " Perdeu comunicação com GPS ";
                    infoLog.Descricao = infoLog.Descricao + "|[ posição Locomotiva Helper : KM" + posicaoHelper_KM(x) + ", posição do EOT : KM" + posicaoTrem_KM(eventoAnterior) + " ]";
                }

                if (eventoAnterior.ID_EOT == 0 && x.ID_EOT > 0)
                {
                    infoLog.Descricao = infoLog.Descricao + "| EOT com Id: " + x.ID_EOT + " Iniciou  comunicação com o Helper ~" + x.DIST_RELATIVA_GPS_EOT_HELPER + " metros ";
                    infoLog.Descricao = infoLog.Descricao + "|[ posição Locomotiva Helper : KM" + posicaoHelper_KM(x) + ", posição do EOT : KM" + posicaoTrem_KM(x) + " ]";
                }

                if (eventoAnterior.ID_EOT > 0 && x.ID_EOT == 0)
                {
                    infoLog.Descricao = infoLog.Descricao + "| EOT com Id: " + eventoAnterior.ID_EOT + " Perdeu comunicação com o Helper ~" + eventoAnterior.DIST_RELATIVA_GPS_EOT_HELPER + " metros ";
                    infoLog.Descricao = infoLog.Descricao + "|[ posição Locomotiva Helper : KM" + posicaoHelper_KM(x) + ", posição do EOT : KM" + posicaoTrem_KM(eventoAnterior) + " ]";
                }
            }

            if (infoLog.Descricao.Equals(""))
            {
                return(null);
            }
            else
            {
                return(infoLog);
            }
        }
 public int posicaoHelper_KM(EventoLog ev)
 {
     return(617000 - ev.POSICAOHELPER_GPS);
 }
        private InfoLog getAlarmes(EventoLog x)
        {
            InfoLog infoLog = new InfoLog();

            infoLog.Ativo     = Locomotiva;
            infoLog.Nome      = "Alarmes";
            infoLog.Descricao = "";
            infoLog.Data      = x.time;
            infoLog.Log       = nomeLog;

            String Alarme   = null;
            string lvAlarme = "";

            Alarme = x.ALARME1;
            if (!Alarme.Equals("000"))
            {
                if (Alarme1.TryGetValue(Alarme, out lvAlarme))
                {
                    bool flag = infoLog.Descricao != null && !infoLog.Descricao.Contains("");
                    infoLog.Descricao = (flag) ? infoLog.Descricao + "|" + lvAlarme : lvAlarme;
                }
                else
                {
                    infoLog.Descricao = Alarme + " Não Homologado";
                }
            }


            Alarme = x.ALARME2;
            if (!Alarme.Equals("000"))
            {
                if (Alarme2.TryGetValue(Alarme, out lvAlarme))
                {
                    bool flag = infoLog.Descricao != null && !infoLog.Descricao.Contains("");
                    infoLog.Descricao = (flag) ? infoLog.Descricao + "|" + lvAlarme : lvAlarme;
                }
                else
                {
                    infoLog.Descricao = Alarme + " Não Homologado";
                }
            }



            Alarme = x.ALARME3;
            if (!Alarme.Equals("000"))
            {
                if (Alarme3.TryGetValue(Alarme, out lvAlarme))
                {
                    bool flag = infoLog.Descricao != null && !infoLog.Descricao.Contains("");
                    infoLog.Descricao = (flag) ? infoLog.Descricao + "|" + lvAlarme : lvAlarme;
                }
                else
                {
                    infoLog.Descricao = Alarme + " Não Homologado";
                }
            }

            if (infoLog.Descricao.Equals(""))
            {
                return(null);
            }
            else
            {
                return(infoLog);
            }
        }