Exemplo n.º 1
0
        public void IniciarServico()
        {
            logger.Debug("IniciarServico");

            // Inicializa Map de Instrumentos Monitorados
            instrumentosMonitorados = new Dictionary <string, DadosInstrumento>();

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

            // Inicializa base de dados
            dbAlertas = new GdbAlertas();

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

            // Configura timeout de conexão com MDS e ativa thread de monitoração
            TimeoutMDS = 300;
            if (ConfigurationManager.AppSettings["TimeoutMDS"] != null)
            {
                TimeoutMDS = Convert.ToInt32(ConfigurationManager.AppSettings["TimeoutMDS"].ToString());
            }
            TimeoutMDS       *= 1000;
            thrMonitorConexao = new Thread(new ThreadStart(MonitorConexaoMDS));
            thrMonitorConexao.Start();

            // Inicializa server Alertas
            serverAlertas = new SocketPackage();
            serverAlertas.OnClientConnected += new ClientConnectedHandler(serverAlertas_OnClientConnected);
            serverAlertas.OnRequestReceived += new MessageReceivedHandler(serverAlertas_OnRequestReceived);

            int portaServer = 55555;

            if (ConfigurationManager.AppSettings["AlertasServerPort"] != null)
            {
                portaServer = Convert.ToInt32(ConfigurationManager.AppSettings["AlertasServerPort"].ToString());
            }
            serverAlertas.StartListen(portaServer);

            _status = ServicoStatus.EmExecucao;
        }