private static async Task ImportacaoDadosCompleto(IConfiguration configuration) { var rootPath = configuration["AppSettings:SiteRootFolder"]; var tempPath = System.IO.Path.Combine(rootPath, "static/temp"); var sDeputadosImagesPath = System.IO.Path.Combine(rootPath, "static/img/depfederal/"); var sSenadoressImagesPath = System.IO.Path.Combine(rootPath, "static/img/senador/"); try { var sb = new StringBuilder(); TimeSpan t; Stopwatch sw = Stopwatch.StartNew(); Stopwatch swGeral = Stopwatch.StartNew(); new Core.DAO.ParametrosDao().CarregarPadroes(); var inicioImportacao = DateTime.UtcNow.AddHours(-3).ToString("dd/MM/yyyy HH:mm"); sb.Append("<strong>-- Importar Deputados :: @duracao --</strong>"); sw.Restart(); try { sb.Append(Camara.ImportarDeputados()); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb = sb.Replace("@duracao", string.Format("{0:D2}h:{1:D2}m:{2:D2}s", t.Hours, t.Minutes, t.Seconds)); sb.Append("<strong>-- Importar Fotos Deputados :: @duracao --</strong>"); sw.Restart(); try { sb.Append(Camara.DownloadFotosDeputados(sDeputadosImagesPath)); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb = sb.Replace("@duracao", string.Format("{0:D2}h:{1:D2}m:{2:D2}s", t.Hours, t.Minutes, t.Seconds)); sb.AppendFormat("<strong>-- Importar Despesas Deputados {0} :: @duracao --</strong>", DateTime.Now.Year - 1); //sb.AppendFormat("<p>" + DateTime.UtcNow.ToString("dd/MM/yyyy HH:mm") + "</p>"); sw.Restart(); try { sb.Append(Camara.ImportarDespesasXml(tempPath, DateTime.Now.Year - 1)); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString() + ex.GetBaseException().StackTrace); } t = sw.Elapsed; sb = sb.Replace("@duracao", string.Format("{0:D2}h:{1:D2}m:{2:D2}s", t.Hours, t.Minutes, t.Seconds)); sb.AppendFormat("<strong>-- Importar Despesas Deputados {0} :: @duracao --</strong>", DateTime.Now.Year); //sb.AppendFormat("<p>" + DateTime.UtcNow.ToString("dd/MM/yyyy HH:mm") + "</p>"); sw.Restart(); try { sb.Append(Camara.ImportarDespesasXml(tempPath, DateTime.Now.Year)); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb = sb.Replace("@duracao", string.Format("{0:D2}h:{1:D2}m:{2:D2}s", t.Hours, t.Minutes, t.Seconds)); sb.Append("<strong>-- Importar Presenças Deputados :: @duracao --</strong>"); //sw.Restart(); //try //{ // sb.Append(Camara.ImportaPresencasDeputados()); //} //catch (Exception ex) //{ // sb.Append(ex.ToFullDescriptionString()); //} //t = sw.Elapsed; //sb = sb.Replace("@duracao", string.Format("{0:D2}h:{1:D2}m:{2:D2}s", t.Hours, t.Minutes, t.Seconds)); sb.AppendFormat("<strong>-- Importar Secretários parlamentares {0} :: @duracao --</strong>", DateTime.Now.Year); sw.Restart(); ////Instantiate DI container for the application //var serviceCollection = new ServiceCollection(); ////Register NodeServices //serviceCollection.AddNodeServices(); ////Request the DI container to supply the shared INodeServices instance //var nodeService = serviceCollection.BuildServiceProvider().GetRequiredService<INodeServices>(); ////Invoke the javascript module with parameters to execute in Node environment. //var taskResult = await nodeService.InvokeAsync<string>(@"D:\GitHub\operacao-politica-supervisionada\OPS.ImportacaoNodejs\app.js"); //sb.AppendFormat(taskResult); //t = sw.Elapsed; //sb = sb.Replace("@duracao", string.Format("{0:D2}h:{1:D2}m:{2:D2}s", t.Hours, t.Minutes, t.Seconds)); sb.AppendLine(); sb.AppendFormat("<strong>-- Importar Senadores {0} :: @duracao --</strong>", DateTime.Now.Year); sw.Restart(); try { sb.Append(Senado.AtualizaCadastroSenadores()); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb = sb.Replace("@duracao", string.Format("{0:D2}h:{1:D2}m:{2:D2}s", t.Hours, t.Minutes, t.Seconds)); sb.AppendLine(); sb.AppendFormat("<strong>-- Importar Imagens Senadores {0} :: @duracao --</strong>", DateTime.Now.Year); sw.Restart(); try { sb.Append(Senado.DownloadFotosSenadores(sSenadoressImagesPath)); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb = sb.Replace("@duracao", string.Format("{0:D2}h:{1:D2}m:{2:D2}s", t.Hours, t.Minutes, t.Seconds)); sb.AppendLine(); sb.AppendFormat("<strong>-- Importar Despesas Senado {0} :: @duracao --</strong>", DateTime.Now.Year - 1); sw.Restart(); try { sb.Append(Senado.ImportarDespesas(tempPath, DateTime.Now.Year - 1, false)); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb = sb.Replace("@duracao", string.Format("{0:D2}h:{1:D2}m:{2:D2}s", t.Hours, t.Minutes, t.Seconds)); sb.AppendFormat("<strong>-- Importar Despesas Senado {0} :: @duracao --</strong>", DateTime.Now.Year); sw.Restart(); try { sb.Append(Senado.ImportarDespesas(tempPath, DateTime.Now.Year, false)); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb = sb.Replace("@duracao", string.Format("{0:D2}h:{1:D2}m:{2:D2}s", t.Hours, t.Minutes, t.Seconds)); //try //{ // var data = new DateTime(DateTime.Now.Year, DateTime.Now.Month - (DateTime.Now.Day < 10 ? 1 : 0), 01); // sb.Append(Senado.ImportarRemuneracao(tempPath, Convert.ToInt32(data.ToString("yyyyMM")))); //} //catch (Exception ex) //{ // sb.Append(ex.ToFullDescriptionString()); //} //t = sw.Elapsed; //sb = sb.Replace("@duracao", string.Format("{0:D2}h:{1:D2}m:{2:D2}s", t.Hours, t.Minutes, t.Seconds)); sb.Append("<strong>-- Consultar Receita WS :: @duracao --</strong>"); sw.Restart(); try { sb.Append(Fornecedor.ConsultarReceitaWS()); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb = sb.Replace("@duracao", string.Format("{0:D2}h:{1:D2}m:{2:D2}s", t.Hours, t.Minutes, t.Seconds)); t = swGeral.Elapsed; sb.AppendFormat("<strong>Inicio da importação: {0} - Duração Total: {1:D2}h:{2:D2}m:{3:D2}s</strong>", inicioImportacao, t.Hours, t.Minutes, t.Seconds); using (WebClient client = new WebClient()) { await client.DownloadDataTaskAsync("http://127.0.0.1:5200/tarefa/limparcache"); } var lstEmails = Padrao.EmailEnvioResumoImportacao.Split(';'); var lstEmailTo = new MailAddressCollection(); foreach (string email in lstEmails) { lstEmailTo.Add(email); } Console.WriteLine(sb.ToString()); await Utils.SendMailAsync(configuration["AppSettings:SendGridAPIKey"], lstEmailTo, "OPS :: Resumo da Importação - " + DateTime.UtcNow.ToString("dd/MM/yyyy HH:mm"), sb.ToString()); } catch (Exception ex) { var ex1 = ex.GetBaseException(); var message = ex1.Message; if (ex1.StackTrace != null) { message += ex1.StackTrace; } await Utils.SendMailAsync(configuration["AppSettings:SendGridAPIKey"], new MailAddress(Padrao.EmailEnvioErros), "OPS :: Informe de erro na Importação", message); } }
private static async Task ImportacaoDadosCompleto(IConfiguration configuration) { var rootPath = configuration["AppSettings:SiteRootFolder"]; var tempPath = System.IO.Path.Combine(rootPath, "wwwroot/temp"); var sDeputadosImagesPath = System.IO.Path.Combine(rootPath, "wwwroot/images/Parlamentares/DEPFEDERAL/"); var sSenadoressImagesPath = System.IO.Path.Combine(rootPath, "wwwroot/images/Parlamentares/SENADOR/"); try { var sb = new StringBuilder(); TimeSpan t; Stopwatch sw = Stopwatch.StartNew(); Stopwatch swGeral = Stopwatch.StartNew(); sb.AppendFormat("<p> Iniciando importação: " + DateTime.UtcNow.ToString("dd/MM/yyyy HH:mm") + "</p>"); sb.AppendFormat("<h3>-- Importar Deputados --</h3>"); sw.Restart(); try { sb.Append(Camara.ImportarDeputados()); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb.AppendFormat("<p>Duração: {0:D2}h:{1:D2}m:{2:D2}s</p>", t.Hours, t.Minutes, t.Seconds); sb.AppendFormat("<h3>-- Importar Fotos Deputados --</h3>"); sw.Restart(); try { sb.Append(Camara.DownloadFotosDeputados(sDeputadosImagesPath)); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb.AppendFormat("<p>Duração: {0:D2}h:{1:D2}m:{2:D2}s</p>", t.Hours, t.Minutes, t.Seconds); sb.AppendFormat("<h3>-- Importar Despesas Deputados {0} --</h3>", DateTime.Now.Year - 1); //sb.AppendFormat("<p>" + DateTime.UtcNow.ToString("dd/MM/yyyy HH:mm") + "</p>"); sw.Restart(); try { sb.Append(Camara.ImportarDespesasXml(tempPath, DateTime.Now.Year - 1)); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString() + ex.GetBaseException().StackTrace); } t = sw.Elapsed; sb.AppendFormat("<p>Duração: {0:D2}h:{1:D2}m:{2:D2}s</p>", t.Hours, t.Minutes, t.Seconds); sb.AppendFormat("<h3>-- Importar Despesas Deputados {0} --</h3>", DateTime.Now.Year); //sb.AppendFormat("<p>" + DateTime.UtcNow.ToString("dd/MM/yyyy HH:mm") + "</p>"); sw.Restart(); try { sb.Append(Camara.ImportarDespesasXml(tempPath, DateTime.Now.Year)); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb.AppendFormat("<p>Duração: {0:D2}h:{1:D2}m:{2:D2}s</p>", t.Hours, t.Minutes, t.Seconds); sb.AppendFormat("<h3>-- Importar Presenças Deputados --</h3>"); sw.Restart(); try { sb.Append(Camara.ImportaPresencasDeputados()); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb.AppendFormat("<p>Duração: {0:D2}h:{1:D2}m:{2:D2}s</p>", t.Hours, t.Minutes, t.Seconds); sb.AppendFormat("<h3>-- Importar Secretários parlamentares {0} --</h3>", DateTime.Now.Year); sw.Restart(); ////Instantiate DI container for the application //var serviceCollection = new ServiceCollection(); ////Register NodeServices //serviceCollection.AddNodeServices(); ////Request the DI container to supply the shared INodeServices instance //var nodeService = serviceCollection.BuildServiceProvider().GetRequiredService<INodeServices>(); ////Invoke the javascript module with parameters to execute in Node environment. //var taskResult = await nodeService.InvokeAsync<string>(@"D:\GitHub\operacao-politica-supervisionada\OPS.ImportacaoNodejs\app.js"); //sb.AppendFormat(taskResult); //t = sw.Elapsed; //sb.AppendFormat("<p>Duração: {0:D2}h:{1:D2}m:{2:D2}s</p>", t.Hours, t.Minutes, t.Seconds); sb.AppendFormat("<h3>-- Importar Senadores {0} --</h3>", DateTime.Now.Year); sw.Restart(); try { sb.Append(Senado.CarregaSenadoresAtuais()); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb.AppendFormat("<p>Duração: {0:D2}h:{1:D2}m:{2:D2}s</p>", t.Hours, t.Minutes, t.Seconds); sb.AppendFormat("<h3>-- Importar Imagens Senadores {0} --</h3>", DateTime.Now.Year); sw.Restart(); try { sb.Append(Senado.DownloadFotosSenadores(sSenadoressImagesPath)); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb.AppendFormat("<p>Duração: {0:D2}h:{1:D2}m:{2:D2}s</p>", t.Hours, t.Minutes, t.Seconds); sb.AppendFormat("<h3>-- Importar Despesas Senado {0} --</h3>", DateTime.Now.Year - 1); sw.Restart(); try { sb.Append(Senado.ImportarDespesas(tempPath, DateTime.Now.Year - 1, false)); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb.AppendFormat("<p>Duração: {0:D2}h:{1:D2}m:{2:D2}s</p>", t.Hours, t.Minutes, t.Seconds); sb.AppendFormat("<h3>-- Importar Despesas Senado {0} --</h3>", DateTime.Now.Year); sw.Restart(); try { sb.Append(Senado.ImportarDespesas(tempPath, DateTime.Now.Year, false)); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb.AppendFormat("<p>Duração: {0:D2}h:{1:D2}m:{2:D2}s</p>", t.Hours, t.Minutes, t.Seconds); sb.AppendFormat("<h3>-- Consultar Receita WS --</h3>"); sw.Restart(); try { sb.Append(Fornecedor.ConsultarReceitaWS()); } catch (Exception ex) { sb.Append(ex.ToFullDescriptionString()); } t = sw.Elapsed; sb.AppendFormat("<p>Duração: {0:D2}h:{1:D2}m:{2:D2}s</p>", t.Hours, t.Minutes, t.Seconds); t = swGeral.Elapsed; sb.AppendFormat("<h3>Duração Total: {0:D2}h:{1:D2}m:{2:D2}s</h3>", t.Hours, t.Minutes, t.Seconds); using (WebClient client = new WebClient()) { await client.DownloadDataTaskAsync("http://127.0.0.1:5000/api/tarefa/limparcache"); } var lstEmails = Padrao.EmailEnvioResumoImportacao.Split(';'); var lstEmailTo = new MailAddressCollection(); foreach (string email in lstEmails) { lstEmailTo.Add(email); } Console.WriteLine(sb.ToString()); await Utils.SendMailAsync(configuration, lstEmailTo, "OPS :: Resumo da Importação - " + DateTime.UtcNow.ToString("dd/MM/yyyy HH:mm"), sb.ToString()); } catch (Exception ex) { var ex1 = ex.GetBaseException(); var message = ex1.Message; if (ex1.StackTrace != null) { message += ex1.StackTrace; } await Utils.SendMailAsync(configuration, new MailAddress(Padrao.EmailEnvioErros), "OPS :: Informe de erro na Importação", message); } }