private string GetNomeCorretoArquivo(string pInicialArquivo) { string lRetorno = string.Empty; try { DateTime lDtUil = new ImportacaoDbLib().SelecionaUltimoPregao(); string[] filePaths = Directory.GetFiles(gPath, pInicialArquivo + "*"); foreach (string arquivo in filePaths) { string[] lNomeSplitado = arquivo.Split('_'); int lAno = Convert.ToInt32(lNomeSplitado[2].Substring(0, 4)); int lMes = Convert.ToInt32(lNomeSplitado[2].Substring(4, 2)); int lDia = Convert.ToInt32(lNomeSplitado[2].Substring(6, 2)); DateTime lDtArquivo = new DateTime(lAno, lMes, lDia); if (lDtArquivo == lDtUil || arquivo.Contains("anvalind")) { lRetorno = arquivo; } } } catch (Exception ex) { gLogger.ErrorFormat("Erro encontrado no método GetNomeCorretoArquivo - [{0}]", ex.StackTrace); } return(lRetorno); }
private void btnImportarTodosFundos_Click(object sender, EventArgs e) { try { DateTime lDataInicial = DateTime.Now.AddYears(-5);// DateTime.Parse(txtDate.Text); var lServico = new ImportacaoDbLib(); //lServico.ImportarFundosTipo(); //lServico.ImportarInstituicoes(); //lServico.ImportarFundos(); //lServico.ImportarTaxaAdm(); //lServico.ImportarFundosMovimentoCota(); //lServico.ImportarFundosStatus(); lServico.ImportarRentabilidadeDia(lDataInicial); //lServico.ImportarRentabilidadeMes(lDataInicial); MessageBox.Show("Importação dos fundos efetuada com sucesso", "Importação de todos os fundos", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro na importação de todos os fundos", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void ImportacaoAvulsaANBIMA() { try { gLogger.Debug("Obtendo relacao de arquivos para serem importados"); ImportacaoDbLib lImpDB = new ImportacaoDbLib(); List <ProdutosInfo> lProdutos = lImpDB.PesquisarProduto(); List <ProdutosInfo> ListaProduto = lImpDB.ListarProduto(); Dictionary <string, int> ListaIdProdutoAnbima = new Dictionary <string, int>(); ListaProduto.ForEach(produto => { if (!ListaIdProdutoAnbima.ContainsKey(produto.IdCodigoAnbima)) { ListaIdProdutoAnbima.Add(produto.IdCodigoAnbima, produto.IdProduto); } }); this.gListaCodigoAnbima.Clear(); lProdutos.ForEach(produto => { gLogger.InfoFormat("Fundo encontrado: [{0} - {1}] ", produto.IdCodigoAnbima, produto.NomeProduto); gListaCodigoAnbima.Add(produto.IdCodigoAnbima); }); LeituraArquivos lLeitura = new LeituraArquivos(); //List<FundosDiaInfo> lFundosDia = lLeitura.LeArquivoFundosDiaAvulsa(); List <FundosMesInfo> lFundosMes = lLeitura.LeArquivoFundosMesAvulsa(); //List<FundosMovCotaInfo> lFundosMovCota = lLeitura.LeArquivoFundosMovCotaAvulsa(); //List<TaxaAdministracaoInfo> lFundosTaxaAdm = lLeitura.LeArquivoFundosTaxaAdm(); //lFundosDia.ForEach( // fundo => // { // if (gListaCodigoAnbima.Count > 0 && gListaCodigoAnbima.Contains(fundo.CodigoFundo)) // { // lImpDB.SalvarRentabilidadeDiaria(fundo); // gLogger.InfoFormat("Rentabilidade Dia -> [{0}] importado com sucesso", fundo.CodigoFundo); // } // }); lFundosMes.ForEach( fundo => { if (gListaCodigoAnbima.Count > 0 && gListaCodigoAnbima.Contains(fundo.CodigoFundo)) { lImpDB.SalvarRentabilidadeMes(fundo); gLogger.InfoFormat("Rentabiliadde Mês -> [{0}] importado com sucesso", fundo.CodigoFundo); } }); //lFundosMovCota.ForEach( // fundo => // { // if (gListaCodigoAnbima.Count > 0 ) // { // if (ListaIdProdutoAnbima.ContainsKey(fundo.CodigoFundo)) // { // fundo.IdProduto = ListaIdProdutoAnbima[fundo.CodigoFundo]; // lImpDB.SalvarProdutoMovimento(fundo); // gLogger.InfoFormat("Fundos Mov Cota -> [{0}] importado com sucesso", fundo.CodigoFundo); // } // } // }); } catch (Exception ex) { gLogger.Error("Ocorreu um erro ao acessar o metodo ImportacaoAvulsaANBIMA.", ex); } }
public void ThreadImportacaoAnbima(object sender, bool signed) { DateTime lNow = DateTime.Now; List <string> listHorarios = ListaHorarios(this.HorariosImportacaoRentabilidade); try { if (listHorarios.Contains(lNow.ToString("HH:mm"))) { gLogger.Debug("Obtendo relacao de arquivos para serem importados"); SharpSSH lSftp = new SharpSSH(); bool lTransferiu = lSftp.TranferirArquivo(); if (lTransferiu) { ImportacaoDbLib lImpDB = new ImportacaoDbLib(); List <ProdutosInfo> lProdutos = lImpDB.PesquisarProduto(); List <ProdutosInfo> ListaProduto = lImpDB.ListarProduto(); Dictionary <string, int> ListaIdProdutoAnbima = new Dictionary <string, int>(); ListaProduto.ForEach(produto => { if (!ListaIdProdutoAnbima.ContainsKey(produto.IdCodigoAnbima)) { ListaIdProdutoAnbima.Add(produto.IdCodigoAnbima, produto.IdProduto); } }); this.gListaCodigoAnbima.Clear(); lProdutos.ForEach(produto => { gLogger.InfoFormat("Fundo encontrado: [{0} - {1}] ", produto.IdCodigoAnbima, produto.NomeProduto); gListaCodigoAnbima.Add(produto.IdCodigoAnbima); }); LeituraArquivos lLeitura = new LeituraArquivos(); List <FundosDiaInfo> lFundosDia = lLeitura.LeArquivoFundosDia(); List <FundosMesInfo> lFundosMes = lLeitura.LeArquivoFundosMes(); //List<FundosMovCotaInfo> lFundosMovCota = lLeitura.LeArquivoFundosMovCota(); List <TaxaAdministracaoInfo> lTaxaAdministracao = lLeitura.LeArquivoFundosTaxaAdm(); List <ANBIMAIndicadoresMesInfo> lIndicadoresMes = lLeitura.LerArquivoIndcadoresMes(); List <FundosInfo> lCadFundos = lLeitura.LeArquivoCadFundos(); lIndicadoresMes.ForEach( indicador => { lImpDB.SalvarIndicadoresMes(indicador); gLogger.InfoFormat("Indicador -> [{0}] importado com sucesso", indicador.CodigoIndicador); }); lTaxaAdministracao.ForEach( taxa => { if (gListaCodigoAnbima.Count > 0 && gListaCodigoAnbima.Contains(taxa.CodigoFundo)) { lImpDB.SalvarTaxaAdministrador(taxa); gLogger.InfoFormat("Taxa administracao -> [{0}] importada com sucesso", taxa.CodigoFundo); } } ); lFundosDia.ForEach( fundo => { if (gListaCodigoAnbima.Count > 0 && gListaCodigoAnbima.Contains(fundo.CodigoFundo)) { lImpDB.SalvarRentabilidadeDiaria(fundo); gLogger.InfoFormat("Rentabilidade Dia -> [{0}] importado com sucesso", fundo.CodigoFundo); } }); lFundosMes.ForEach( fundo => { if (gListaCodigoAnbima.Count > 0 && gListaCodigoAnbima.Contains(fundo.CodigoFundo)) { lImpDB.SalvarRentabilidadeMes(fundo); gLogger.InfoFormat("Rentabiliadde Mês -> [{0}] importado com sucesso", fundo.CodigoFundo); } }); lCadFundos.ForEach( fundo => { lImpDB.SalvarCadastroFundos(fundo); gLogger.InfoFormat("Cadastro do fundo -> [{0}] importado com sucesso", fundo.CodigoFundo); }); //lFundosMovCota.ForEach( // fundo => // { // if (gListaCodigoAnbima.Count > 0 && gListaCodigoAnbima.Contains(fundo.CodigoFundo)) // // if (gListaCodigoAnbima.Count > 0) // { // if (ListaIdProdutoAnbima.ContainsKey(fundo.CodigoFundo)) // { // fundo.IdProduto = ListaIdProdutoAnbima[fundo.CodigoFundo]; // lImpDB.SalvarProdutoMovimento(fundo); // gLogger.InfoFormat("Fundos Mov Cota -> [{0}] importado com sucesso", fundo.CodigoFundo); // } // } // }); } } } catch (Exception ex) { gLogger.Error("Ocorreu um erro ao acessar o método ThreadImportacaoAnbima:" + ex.Message, ex); } //Thread.Sleep(250); }
public bool TranferirArquivo() { bool lRetorno = false; Sftp sshCp = null; try { gLogger.InfoFormat("*******************************************************************"); gLogger.InfoFormat("SharpSSH > Abrindo conexão com ANBIMA******************************"); gLogger.InfoFormat("*******************************************************************"); DateTime lDtUil = new ImportacaoDbLib().SelecionaUltimoPregao(); //SshTransferProtocolBase sshCp; SshConnectionInfo lInfo = new SshConnectionInfo(); lInfo.Host = this.HostAnbimaSFTP; lInfo.User = this.UserAnbimaSFTP; lInfo.Pass = this.PasswordAnbimaSFTP; sshCp = new Sftp(lInfo.Host, lInfo.User); sshCp.Password = lInfo.Pass; gLogger.InfoFormat("Dados de conexão ANBIMA Host: [{0}] User: [{1}] password: [{2}]", lInfo.Host, lInfo.User, lInfo.Pass); sshCp.Connect(); int lTentativaConexao = 0; while (!sshCp.Connected && lTentativaConexao != 10) { gLogger.InfoFormat("SharpSSH > Aguardando conexão SFTP com ANBIMA ******************************"); sshCp.Connect(); if (lTentativaConexao == 10) { gLogger.InfoFormat("Já tentou conectar 10 vez, saindo do loop de tentativa de conexão"); return(false); } Thread.Sleep(2000); lTentativaConexao++; } sshCp.OnTransferStart += new FileTransferEvent(sshCp_OnTransferStart); sshCp.OnTransferProgress += new FileTransferEvent(sshCp_OnTransferProgress); sshCp.OnTransferEnd += new FileTransferEvent(sshCp_OnTransferEnd); string lpath = ConfigurationManager.AppSettings["ArquivosAnbima"]; foreach (KeyValuePair <string, string> lDir in ListaDir) { ArrayList list = sshCp.GetFileList(lDir.Value); foreach (string arquivo in list) { gLogger.InfoFormat("SharpSSH > Arquivo encontrado no ambiente na ANBIMA -> [{0}] ", arquivo); } foreach (var item in list) { string lNome = item.ToString(); if (lNome.Length > 2) { string[] lNomeSplitado = lNome.Split('_'); int lAno = Convert.ToInt32(lNomeSplitado[2].Substring(0, 4)); int lMes = Convert.ToInt32(lNomeSplitado[2].Substring(4, 2)); int lDia = Convert.ToInt32(lNomeSplitado[2].Substring(6, 2)); DateTime lDtArquivo = new DateTime(lAno, lMes, lDia); if (lDtArquivo == lDtUil || lDir.Key.ToLower() == "indicmes") { sshCp.Get(string.Concat(lDir.Value, lNome), lpath); } } } gLogger.InfoFormat("SharpSSH > Arquivo [{0}] transferido com sucesso.", lpath); } sshCp.Close(); lRetorno = true; } catch (Exception ex) { gLogger.Error("SharpSSH > TranferirArquivo -", ex); } finally { if (sshCp != null && sshCp.Connected) { sshCp.Close(); } } return(lRetorno); }