Example #1
0
        protected virtual void MonitorConexaoMDS()
        {
            int i = 0;
            int iTrialInterval = 600;

            logger.Info("Iniciando thread de monitoracao de conexao com MDS");
            while (bKeepRunning)
            {
                try
                {
                    // Reconecta a cada 5 min
                    if (!lSocket.IsConectado())
                    {
                        if (i > iTrialInterval)
                        {
                            _enviaAlertaDesconexao(lSocket.IpAddr, lSocket.Port);

                            logger.Info("Reabrindo conexao com MDS...");
                            lSocket.OpenConnection();

                            _sendMDSLoginMSG(lSocket);

                            i = 0;
                        }
                        else
                        {
                            i++;
                            // Configura intervalos de 1 minuto durante o dia ou
                            // 5 minutos
                            if (DateTime.Now.Hour > 7 && DateTime.Now.Hour < 21)
                            {
                                iTrialInterval = 600;
                            }
                            else
                            {
                                iTrialInterval = 3000;
                            }
                        }
                    }
                    else
                    {
                        if (i > 600)
                        {
                            logger.Info("Conexao com MDS ativa " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " LastPkt: " + lSocket.LastPacket.ToString("dd/MM/yyyy HH:mm:ss.ffff") + " [" + lSocket.LastMsg + "]");
                            logger.Info("*** Ultimos pacotes: ");
                            logger.Info("Neg =[" + MemoriaCotacao.LastNegocioPacket.ToString("dd/MM/yyyy HH:mm:ss.ffff") + "] [" + MemoriaCotacao.LastNegocioMsg + "]");
                            logger.Info("Lof =[" + MemoriaCotacao.LastLofPacket.ToString("dd/MM/yyyy HH:mm:ss.ffff") + "] [" + MemoriaCotacao.LastLofMsg + "]");
                            logger.Info("Dest=[" + MemoriaCotacao.LastDestaquePacket.ToString("dd/MM/yyyy HH:mm:ss.ffff") + "] [" + MemoriaCotacao.LastDestaqueMsg + "]");
                            logger.Info("Rank=[" + MemoriaCotacao.LastRankingPacket.ToString("dd/MM/yyyy HH:mm:ss.ffff") + "] [" + MemoriaCotacao.LastRankingMsg + "]");
                            logger.Info("***");

                            // Verifica dessincronizacao de sinal
                            if (DateTime.Now.DayOfWeek != DayOfWeek.Saturday &&
                                DateTime.Now.DayOfWeek != DayOfWeek.Sunday)
                            {
                                if (DateTime.Now.Hour >= 9 && DateTime.Now.Hour < 18)
                                {
                                    TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - MemoriaCotacao.HorarioUltimaSonda.Ticks);
                                    if (ts.TotalMilliseconds > MaxDifHorarioBolsa)
                                    {
                                        _enviaAlertaAtraso(lSocket.IpAddr, lSocket.Port);
                                    }
                                }
                            }

                            // Verifica ultima comunicacao com MDS
                            TimeSpan tslastpkt = new TimeSpan(DateTime.Now.Ticks - lSocket.LastPacket.Ticks);
                            if (tslastpkt.TotalMilliseconds > TimeoutMDS)
                            {
                                logger.Warn("Finalizando conexao com MDS por timeout!!!");
                                lSocket.CloseConnection();
                            }

                            i = 0;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    Thread.Sleep(100);
                }
                catch (Exception ex)
                {
                    logger.Fatal("MonitorCotacaoMDS(): " + ex.Message, ex);
                    Thread.Sleep(1000);
                }
            }

            logger.Info("Thread de monitoracao de conexao com MDS finalizacao");
        }
Example #2
0
        public virtual void IniciarServico()
        {
            //composicaoIndice = new ComposicaoIndice();
            indiceGradual = new IndiceGradual();
            lIndiceGradualQuantidadeTeorica = new IndiceGradualQuantidadeTeorica();

            // Verifica se deve ser ativado o tratamento de delay da cotação
            MemoriaCotacaoDelay.GetInstance().DelayTickerOn = false;
            if (ConfigurationManager.AppSettings["DelayTicker"] != null &&
                ConfigurationManager.AppSettings["DelayTicker"].ToString().ToUpper().Equals("TRUE"))
            {
                MemoriaCotacaoDelay.GetInstance().DelayTickerOn = true;

                // Obtem o valor do Delay do sinal de cotação, em minutos
                MemoriaCotacaoDelay.GetInstance().DelayTickerAmount = 15 * 60 * 1000;
                if (ConfigurationManager.AppSettings["DelayTickerAmount"] != null)
                {
                    int delayAmount = Convert.ToInt32(ConfigurationManager.AppSettings["DelayTickerAmount"].ToString());
                    MemoriaCotacaoDelay.GetInstance().DelayTickerAmount = delayAmount * 60 * 1000;
                }

                MemoriaCotacaoDelay.GetInstance().StartProcessamento();
            }

            if (ConfigurationManager.AppSettings["FiltraIndiceCheio"] != null &&
                ConfigurationManager.AppSettings["FiltraIndiceCheio"].ToString().ToUpper().Equals("TRUE"))
            {
                _filtraIndiceCheio = true;
            }

            QueueManager.Instance.Start();
            //QueueManager.Instance.ComposicaoIndice = composicaoIndice;
            QueueManager.Instance.IndiceGradual = indiceGradual;

            logger.Info("MDS modelo tradicional");
            lSocket = new MDSPackageSocket();
            lSocket.FiltraIndiceCheio = _filtraIndiceCheio;
            lSocket.IpAddr            = ConfigurationManager.AppSettings["ASConnMDSIp"].ToString();
            lSocket.Port = ConfigurationManager.AppSettings["ASConnMDSPort"].ToString();
            //lSocket.setComposicaoIndice(composicaoIndice);
            lSocket.setIndiceGradual(indiceGradual);

            lSocket.OpenConnection();

            _sendMDSLoginMSG(lSocket);

            thrMonitorConexao = new Thread(new ThreadStart(MonitorConexaoMDS));
            thrMonitorConexao.Start();

            gTimer = new Timer(new TimerCallback(IniciarThread), null, 0, 5000);


            // Obtem o parametro de maxima diferenca de horario da ultima mensagem com a bolsa
            // para envio de alertas
            MaxDifHorarioBolsa = 75;
            if (ConfigurationManager.AppSettings["MaxDifHorarioBolsa"] != null)
            {
                MaxDifHorarioBolsa = Convert.ToDouble(ConfigurationManager.AppSettings["MaxDifHorarioBolsa"].ToString());
            }
            MaxDifHorarioBolsa *= 1000;

            // Obtem o timeout de mensagem com o MDS, em segundos
            TimeoutMDS = 300;
            if (ConfigurationManager.AppSettings["TimeoutMDS"] != null)
            {
                TimeoutMDS = Convert.ToDouble(ConfigurationManager.AppSettings["TimeoutMDS"].ToString());
            }
            TimeoutMDS *= 1000;

            logger.Info("Servico cotacao iniciado");

            this.Status = ServicoStatus.EmExecucao;
        }