Example #1
0
        private void RecadastrarInstrumentosMDS()
        {
            DateTime dataHoraCadastro = DateTime.Now;

            HashSet <String> instrumentosCadastrados = gerenciadorAlertas.ObterInstrumentos();

            logger.Debug("Recadastrando instrumentos no MDS: " + instrumentosCadastrados.Count + " itens");

            foreach (String instrumento in instrumentosCadastrados)
            {
                if (!instrumentosMonitorados.Keys.Contains(instrumento))
                {
                    DadosInstrumento dadosInstrumento = new DadosInstrumento();
                    dadosInstrumento.minimo = Decimal.MaxValue;
                    dadosInstrumento.maximo = Decimal.MinValue;
                    instrumentosMonitorados.Add(instrumento, dadosInstrumento);

                    StringBuilder requisicaoAlerta = new StringBuilder();

                    requisicaoAlerta.Append("AL");
                    requisicaoAlerta.Append("  ");
                    requisicaoAlerta.Append(dataHoraCadastro.ToString(string.Format("{0}{1}", "yyyyMMddHHmmssmmm", "0")));
                    string instrumentoFormatado = String.Format("{0,-20}", instrumento);
                    requisicaoAlerta.Append(instrumentoFormatado);
                    requisicaoAlerta.Append("1");

                    logger.Info("Vai recadastrar Alerta [" + requisicaoAlerta.ToString() + "]");
                    if (mdsSocket.IsConectado())
                    {
                        logger.Info("Recadastrando Alerta [" + requisicaoAlerta.ToString() + "]");
                        mdsSocket.Send(requisicaoAlerta.ToString());
                    }
                }
            }
        }
Example #2
0
        private void RecadastrarInstrumentosMDS(SocketPackage mdsSocket)
        {
            DateTime dataHoraCadastro = DateTime.Now;

            HashSet <String> instrumentosCadastrados = gerenciadorAlertas.ObterInstrumentos();

            foreach (String instrumento in instrumentosCadastrados)
            {
                if (!instrumentosMonitorados.Keys.Contains(instrumento))
                {
                    DadosInstrumento dadosInstrumento = new DadosInstrumento();
                    dadosInstrumento.minimo = Decimal.MaxValue;
                    dadosInstrumento.maximo = Decimal.MinValue;
                    instrumentosMonitorados.Add(instrumento, dadosInstrumento);

                    StringBuilder requisicaoAlerta = new StringBuilder();

                    requisicaoAlerta.Append("AL");
                    requisicaoAlerta.Append("  ");
                    requisicaoAlerta.Append(dataHoraCadastro.ToString(string.Format("{0}{1}", "yyyyMMddHHmmssmmm", "0")));
                    string instrumentoFormatado = String.Format("{0,-20}", instrumento);
                    requisicaoAlerta.Append(instrumentoFormatado);
                    requisicaoAlerta.Append("1");

                    try
                    {
                        if (mdsSocket != null && mdsSocket.IsConectado())
                        {
                            mdsSocket.Send(requisicaoAlerta.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error("RecadastrarInstrumentosMDS():" + ex.Message, ex);
                    }
                }
            }
        }
Example #3
0
        public CadastrarAlertaResponse CadastrarAlerta(CadastrarAlertaRequest request)
        {
            CadastrarAlertaResponse responseAlerta = new CadastrarAlertaResponse();

            try
            {
                logger.Debug("Executando Cadastrar Alerta - IdCliente=[" + request.Alerta.IdCliente + "] " +
                             "Instrumento=[" + request.Alerta.Instrumento + "] " +
                             "TipoOperador=[" + (int)request.Alerta.TipoOperador + "] " +
                             "TipoOperando=[" + (int)request.Alerta.TipoOperando + "] " +
                             "Valor=[" + request.Alerta.Valor + "] "
                             );

                DateTime dataHoraCadastro = DateTime.Now;

                if (!instrumentosMonitorados.Keys.Contains(request.Alerta.Instrumento))
                {
                    DadosInstrumento dadosInstrumento = new DadosInstrumento();
                    dadosInstrumento.minimo = Decimal.MaxValue;
                    dadosInstrumento.maximo = Decimal.MinValue;
                    instrumentosMonitorados.Add(request.Alerta.Instrumento, dadosInstrumento);

                    StringBuilder requisicaoAlerta = new StringBuilder();

                    requisicaoAlerta.Append("AL");
                    requisicaoAlerta.Append("  ");
                    requisicaoAlerta.Append(dataHoraCadastro.ToString(string.Format("{0}{1}", "yyyyMMddHHmmssmmm", "0")));
                    string instrumento = String.Format("{0,-20}", request.Alerta.Instrumento);
                    requisicaoAlerta.Append(instrumento);
                    requisicaoAlerta.Append("1");

                    if (mdsSocket.IsConectado())
                    {
                        logger.Debug("Cadastrando alerta MDS [" + requisicaoAlerta.ToString() + "]");
                        mdsSocket.Send(requisicaoAlerta.ToString());
                    }
                }

                String idCadastrado = dbAlertas.CadastrarAlerta(
                    request.Alerta.IdCliente,
                    request.Alerta.Instrumento,
                    request.Alerta.TipoOperando,
                    request.Alerta.TipoOperador,
                    request.Alerta.Valor,
                    dataHoraCadastro
                    );

                if (idCadastrado == null)
                {
                    logger.Error("CadastrarAlerta: Erro na inserção na base.");
                    responseAlerta.StatusResposta = Library.MensagemResponseStatusEnum.ErroPrograma;
                    responseAlerta.DescricaoErro  = "Ocorreu erro na inserção das informações na base de dados. Alerta não foi cadastrado";
                }
                else
                {
                    logger.Debug("Cadastrar Alerta - Atribuído IdAlerta=[" + idCadastrado + "]");

                    responseAlerta.IdAlerta       = idCadastrado;
                    responseAlerta.StatusResposta = Library.MensagemResponseStatusEnum.OK;

                    DadosAlerta dados = gerenciadorAlertas.Cadastrar(
                        idCadastrado,
                        request.Alerta.IdCliente,
                        request.Alerta.Instrumento,
                        request.Alerta.TipoOperando,
                        request.Alerta.TipoOperador,
                        request.Alerta.Valor,
                        dataHoraCadastro);

                    // Serializa alerta cadastrado e envia para AlertasCliente
                    string alertaCadastradoSerializado = JsonConvert.SerializeObject(dados);

                    StringBuilder retornoCadastrado = new StringBuilder();
                    retornoCadastrado.Append("CA");
                    retornoCadastrado.Append(alertaCadastradoSerializado);

                    logger.Debug("Server - Enviando alertas cadastrado: [" + retornoCadastrado.ToString() + "]");
                    serverAlertas.SendToAll(retornoCadastrado.ToString());
                }
            }
            catch (Exception e)
            {
                logger.Debug("CadastrarAlerta: Exception [" + e.Message + "]");
                logger.Debug(e.StackTrace);
                responseAlerta.StatusResposta = Library.MensagemResponseStatusEnum.ErroPrograma;
                responseAlerta.IdAlerta       = null;
            }

            return(responseAlerta);
        }