static DadosSaida Avalia(string nome, Func <AchaRaizesResult> metodo) { //Nome DadosSaida saida = new DadosSaida() { Nome = nome }; Stopwatch sw = new Stopwatch(); try { sw.Start(); var res = metodo.Invoke(); sw.Stop(); //Resultado saida.Result = res; saida.TimeMilisseconds = sw.ElapsedMilliseconds; saida.TimeTicks = sw.ElapsedTicks; } catch (Exception) { //Erro saida.MensagemErro = $"Erro em {nome}."; saida.Erro = true; } return(saida); }
public BoletoClientResult ManutencaoBoleto(BoletoClient boletoClient) { try { //cria xml conforme manual http://www.caixa.gov.br/Downloads/cobranca-caixa/Manual_Leiaute_Webservice.pdf string _xmlBoleto = GeraXmlBoleto(boletoClient); XmlDocument document = new XmlDocument(); document.LoadXml(_xmlBoleto); string _operacao = "CONSULTA_BOLETO"; string _endPoint = "https://barramento.caixa.gov.br/sibar/ConsultaCobrancaBancaria/Boleto"; switch (boletoClient.Operacao) { case Operacao.INCLUI_BOLETO: _operacao = "INCLUI_BOLETO"; _endPoint = "https://barramento.caixa.gov.br/sibar/ManutencaoCobrancaBancaria/Boleto/Externo"; break; case Operacao.ALTERA_BOLETO: _operacao = "ALTERA_BOLETO"; _endPoint = "https://barramento.caixa.gov.br/sibar/ManutencaoCobrancaBancaria/Boleto/Externo"; break; default: break; } string _xmlRetorno = UtilHelper.CallWebRequest(_endPoint, document.InnerXml, _operacao); var retorno = XmlHelper.Deserialize <SoapEnvelopeSaida>(_xmlRetorno); BoletoClientResult result = new BoletoClientResult(); DadosSaida saida = null; if (boletoClient.Operacao == Operacao.CONSULTA_BOLETO && retorno.body.SERVICO_SAIDA_Consulta.DADOS.CONSULTA_BOLETO == null) { return(null); } else { if (boletoClient.Operacao == Operacao.CONSULTA_BOLETO) { saida = retorno.body.SERVICO_SAIDA_Consulta.DADOS; } else { saida = retorno.body.SERVICO_SAIDA.DADOS; } switch (boletoClient.Operacao) { case Operacao.INCLUI_BOLETO: result.LINHA_DIGITAVEL = saida.INCLUI_BOLETO.LINHA_DIGITAVEL; result.CODIGO_BARRAS = saida.INCLUI_BOLETO.CODIGO_BARRAS; result.NOSSO_NUMERO = (!string.IsNullOrEmpty(saida.INCLUI_BOLETO.NOSSO_NUMERO) && saida.INCLUI_BOLETO.NOSSO_NUMERO != "0") ? saida.INCLUI_BOLETO.NOSSO_NUMERO : boletoClient.NossoNumero.ToString(); result.URL = saida.INCLUI_BOLETO.URL; result.Operacao = "INCLUI_BOLETO"; break; case Operacao.ALTERA_BOLETO: result.LINHA_DIGITAVEL = saida.ALTERA_BOLETO.LINHA_DIGITAVEL; result.CODIGO_BARRAS = saida.ALTERA_BOLETO.CODIGO_BARRAS; result.NOSSO_NUMERO = (!string.IsNullOrEmpty(saida.ALTERA_BOLETO.NOSSO_NUMERO) || saida.ALTERA_BOLETO.NOSSO_NUMERO == "0") ? saida.ALTERA_BOLETO.NOSSO_NUMERO : boletoClient.NossoNumero.ToString(); result.URL = saida.ALTERA_BOLETO.URL; result.Operacao = "ALTERA_BOLETO"; break; default: _operacao = "CONSULTA_BOLETO"; result.URL = saida.CONSULTA_BOLETO.TITULO.URL; result.Consulta = saida.CONSULTA_BOLETO; break; } return(result); } } catch (Exception err) { throw new Exception(err.Message); } }