示例#1
0
        private void MonitorConexaoServicoAlertas()
        {
            TimeSpan iTrialInterval;

            logger.Info("Iniciando thread de monitoracao de conexao com ServicodeAlertas");
            Thread.Sleep(TimeoutSocket);

            while (bKeepRunning)
            {
                // ajusta Timeout, caso esteja em horário sem movimento
                if (DateTime.Now.Hour > 7 && DateTime.Now.Hour < 21)
                {
                    iTrialInterval = (new TimeSpan(0, 0, 0, 0, TimeoutSocket));
                }
                else
                {
                    iTrialInterval = (new TimeSpan(0, 0, 0, 0, TimeoutSocket * 5));
                }

                if (!socket.IsConectado())
                {
                    gerenciadorAlertas.Limpar();
                    logger.Info("Reabrindo conexao com MDS...");
                    socket.OpenConnection();
                }
                else
                {
                    // Verifica ultima comunicacao com MDS
                    TimeSpan tslastpkt = DateTime.Now.Subtract(socket.LastPacket);
                    if (tslastpkt.CompareTo(iTrialInterval) > 0)
                    {
                        if (!pingPending)
                        {
                            SendPing();
                        }
                        else
                        {
                            logger.Warn("Finalizando conexao com MDS por timeout!!!");
                            socket.CloseSocket();
                        }
                    }
                }
                Thread.Sleep(iTrialInterval);
            }

            logger.Info("Thread de monitoracao de conexao com ServicoAlertas finalizacao");
        }
示例#2
0
        public void IniciarServico()
        {
            logger.Debug("IniciarServico");


            if (ConfigurationManager.AppSettings["EndPointServicoAlertas"] != null)
            {
                urlalertas = ConfigurationManager.AppSettings["EndPointServicoAlertas"].ToString();
            }
            else
            {
                logger.Fatal("'EndPointServicoAlertas' nao foi definido. Finalizando!!!!!");
                return;
            }

            // Inicializa Gerenciador de Alertas Cadastrados
            gerenciadorAlertas = new MemoriaAlertas();

            // Inicializa conexão com MDS
            socket = new SocketPackage();
            socket.OnRequestReceived += new MessageReceivedHandler(socket_OnRequestReceived);
            socket.IpAddr             = ConfigurationManager.AppSettings["AlertasMDSIp"].ToString();
            socket.Port = ConfigurationManager.AppSettings["AlertasMDSPort"].ToString();
            socket.OpenConnection();


            // Configura timeout de conexão com MDS e ativa thread de monitoração
            TimeoutSocket = 60;
            if (ConfigurationManager.AppSettings["TimeoutSocket"] != null)
            {
                TimeoutSocket = Convert.ToInt32(ConfigurationManager.AppSettings["TimeoutSocket"].ToString());
            }
            TimeoutSocket *= 1000;

            bKeepRunning      = true;
            thrMonitorConexao = new Thread(new ThreadStart(MonitorConexaoServicoAlertas));
            thrMonitorConexao.Start();

            _status = ServicoStatus.EmExecucao;
        }