Exemple #1
0
        public virtual void Run()
        {
            bool bWait = false;

            while (_bKeepRunning)
            {
                if (_mds == null || _mds.IsConectado() == false)
                {
                    _mds = new MDSPackageSocket();

                    _mds.IpAddr = _config.MDSAddress;
                    _mds.Port   = _config.MDSPort;

                    _mds.OnFastQuoteReceived      += new MDSMessageReceivedHandler(OnCotacao);
                    _mds.OnSerieHistoricaReceived += new MDSMessageReceivedHandler(OnSerieHistorica);
                    _mds.OpenConnection();
                }

                List <CotacaoANG> tmpQueue = new List <CotacaoANG>();

                lock (queueCotacao)
                {
                    tmpQueue = queueCotacao.ToList();
                    queueCotacao.Clear();
                }

                foreach (CotacaoANG cotacao in tmpQueue)
                {
                    //ProcessaCotacao(cotacao);
                    AtualizarCotacao(cotacao);
                }

                lock (queueCotacao)
                {
                    if (queueCotacao.Count == 0)
                    {
                        bWait = true;
                    }
                    else
                    {
                        bWait = false;
                    }
                }

                if (bWait)
                {
                    Thread.Sleep(250);
                }
            }
        }
        public override void IniciarServico()
        {
            logger.Info("*** Iniciando Processador de Cotacao ***");

            _bKeepRunning = true;

            _config = GerenciadorConfig.ReceberConfig <ProcessadorCotacaoConfig>();

            UMDFConfig _umdfconfig = GerenciadorConfig.ReceberConfig <UMDFConfig>();

            _umdfSockets = new MDSPackageSocket[_umdfconfig.Portas.Count];
            int i = 0;

            foreach (int porta in _umdfconfig.Portas)
            {
                _umdfSockets[i] = new MDSPackageSocket();

                _umdfSockets[i].IpAddr = _config.MDSAddress;
                _umdfSockets[i].Port   = porta;

                _umdfSockets[i].OnFastQuoteReceived      += new MDSMessageReceivedHandler(OnCotacao);
                _umdfSockets[i].OnSerieHistoricaReceived += new MDSMessageReceivedHandler(OnSerieHistorica);

                i++;
            }


            _db = new ANGPersistenciaDB();
            _db.ConnectionString    = _config.ConnectionString;
            _db.MDSConnectionString = _config.MDSConnectionString;

            _threadCotacao = new Thread(new ThreadStart(Run));
            _threadCotacao.Start();

            _threadSerieHistorica = new Thread(new ThreadStart(SerieHistoricaRun));
            _threadSerieHistorica.Start();

            _srvstatus = ServicoStatus.EmExecucao;
        }