Import inicial: migração de arquivos da rede

This commit is contained in:
Giuliano Paschoalino 2025-07-15 13:47:35 -03:00
commit 6a42037c71
8 changed files with 1501 additions and 0 deletions

63
.gitattributes vendored Normal file
View File

@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

363
.gitignore vendored Normal file
View File

@ -0,0 +1,363 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd

57
PI_Assync_SCDE.csproj Normal file
View File

@ -0,0 +1,57 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PlatformTarget>x64</PlatformTarget>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>True</Optimize>
<DefineConstants>$(DefineConstants)TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<Optimize>True</Optimize>
<DefineConstants>$(DefineConstants)TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<COMReference Include="WinHttp">
<WrapperTool>tlbimp</WrapperTool>
<VersionMinor>1</VersionMinor>
<VersionMajor>5</VersionMajor>
<Guid>662901fc-6951-4854-9eb2-d9a2570f2b2e</Guid>
<Lcid>0</Lcid>
<Isolated>false</Isolated>
<EmbedInteropTypes>true</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Databasic" Version="1.2.7" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Npgsql" Version="6.0.4" />
<PackageReference Include="System.Data.OleDb" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

25
PI_Assync_SCDE.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32319.34
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PI_Assync_SCDE", "PI_Assync_SCDE.csproj", "{48DFCC70-0352-4394-9821-2B243EB389AB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{48DFCC70-0352-4394-9821-2B243EB389AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48DFCC70-0352-4394-9821-2B243EB389AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48DFCC70-0352-4394-9821-2B243EB389AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48DFCC70-0352-4394-9821-2B243EB389AB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {021BF0AB-A7C7-4A87-99CC-9C85ABD1E990}
EndGlobalSection
EndGlobal

819
Program.cs Normal file
View File

@ -0,0 +1,819 @@
// See https://aka.ms/new-console-template for more information
using Npgsql;
using System.Data;
using System.Data.OleDb;
using System.Globalization;
using System.Text;
using System.Xml;
using System.Xml.Linq;
internal class Plat_integ
{
static string PG_CONN_STRING_DEV = "Server = smart-energia-dev-pgsql.cykff7tj7mik.us-east-1.rds.amazonaws.com; Port = 5432; Database = smartimptest; User Id = postgres; Password = VfHml#Z78!%kvvNM;";
static string PG_CONN_STRING_PROD = "Server = smart-energia-dev-pgsql.cykff7tj7mik.us-east-1.rds.amazonaws.com; Port = 5432; Database = smartenergiaprod; User Id = postgres; Password = VfHml#Z78!%kvvNM; Timeout = 300;CommandTimeout = 300";
static string ENVIRONMENT = "dev"; // "dev" | "prod"
static Boolean SAVE_XML_IN = false;
static Boolean SAVE_XML_OUT = false;
public static IEnumerable<XElement>? pag_ant;
static void Main(string[] args)
{
bool loadFromArgs = false;
if (args.Length > 0)
{
loadFromArgs = true;
}
//MainAsync().GetAwaiter().GetResult();
//MainAsync(); //Metodo Assincrono
down_sync(loadFromArgs, args); //metodo sincrono
//ler_xml_salvos(); //teste ler arquivos salvos - POSTGRESQL
Console.WriteLine("" +
"Pressione qualquer tecla para finalizar");
_ = Console.ReadLine();
Environment.Exit(0);
return;
}
public static async Task<int> MainAsync()
{
string caminho_BD, caminho_log;
Task tk_proces;
DateTime tempo_ini;
List<Tuple<string, string>> lt_perf_pto;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");
//auxiliar para calculo do tempo de execucao do codigo
tempo_ini = DateTime.Now;
//busca os dados para compor a lista perfis x
caminho_BD = @"X:\Middle\Informativo Setorial\Modelo Word\BD1_dados cadastrais e faturas.accdb";
caminho_log = @"X:\Back\Carteira x.x\Codigo\log_erros.csv";
lt_perf_pto = Busca_dad_BD(caminho_BD);
//exlclui os dados do mes atual salvos no BD
caminho_BD = @"X:\Back\Carteira x.x\Gestão Geral v1\Access\BDs teste\DB_med_5min.accdb";
DateTime now = DateTime.Now;
DateTime data_ini = new DateTime(now.Year, now.Month, 1);
DateTime data_fim = new DateTime(now.Year, now.Month, now.Day);
Exclui_med(data_ini.ToOADate(), data_fim.ToOADate(), caminho_BD);
//abre a conexao com o BD onde serao salvos os dados
caminho_BD = @"X:\Back\Carteira x.x\Gestão Geral v1\Access\BDs teste\DB_med_5min.accdb";
OleDbConnection conn = new("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + caminho_BD + ";Jet OLEDB:Database Password=gds21");
conn.Open();
//loop para cada dia e cada cod ponto salvando os dados no BD
await assync_requisicao_http(data_ini, data_fim, lt_perf_pto, conn, caminho_log);
//await Task.WhenAll(tk_proces);
Thread.Sleep(2000);
Console.WriteLine("Concluido. Tempo TOTAL de execucao: {0}", DateTime.Now - tempo_ini);
//conn.Close();
return 0;
}
public static async Task<int> assync_requisicao_http(DateTime data_inicial, DateTime data_final, List<Tuple<string, string>> lt_perf_pto, OleDbConnection conn, string caminho_log)
{
string log_erros;
int i;
long erros = 0;
var handler = new HttpClientHandler();
int tam_arr;
tam_arr = ((data_final - data_inicial).Days) * lt_perf_pto.Count;
Task<HttpResponseMessage>[] arr_Tks = new Task<HttpResponseMessage>[tam_arr - 1];
Task[] arr_Tks_gen = new Task[tam_arr - 1];
var arr_Var = new HttpResponseMessage[tam_arr - 1];
//handler.ClientCertificateOptions = ClientCertificateOption.Manual;
//CURRENT_USER\My\Smart
//handler.ClientCertificates.Add(new X509Certificate2(@"X:\Back\APP Smart\Certificado\Nova\certificado-20207591.pfx", "appsmart"));
//handler.ClientCertificates.Add(new certificate);
handler.ClientCertificateOptions = ClientCertificateOption.Automatic;
DateTime aux_tempo = DateTime.Now;
var client = new HttpClient(handler);
client.DefaultRequestHeaders.Add("SOAPAction", "listarMedidaCincoMinutos");
var endpoint = new Uri("https://servicos.ccee.org.br:443/ws/v2/MedidaCincoMinutosBSv2");
i = 0;
while (data_inicial < data_final)
{
foreach (Tuple<string, string> item in lt_perf_pto)
{
var payload = new StringContent(Xml_requisicao(data_inicial, item.Item1, item.Item2, 1), Encoding.UTF8, "application/json");
//Salva_arquivos_entrada(Xml_requisicao(data_inicial, item.Item1, item.Item2), conn, i);
arr_Tks[i] = client.PostAsync(endpoint, payload);
Console.WriteLine("Iteracao {0,3}: {1,20} - {2,15}", i, item.Item1, item.Item2);
i++;
}
data_inicial = data_inicial.AddDays(1);
}
Console.WriteLine("{0} Requisicoes realizadas", i);
tam_arr = i;
//Parallel.For(0, tam_arr, (i, state) => {
// //Parallel.For(1, 3, (i, state) => {
// var retorno = arr_Tks[i].Result;
// try {
// arr_Tks_gen[i] = processar_XML_assync(retorno.Content.ReadAsStringAsync().Result, conn);
// Console.WriteLine("Processando requisicao {0,2}", i);
// } catch (Exception) {
// Task.Delay(1000);
// //arr_Tks_gen[i] = processar_XML_assync(retorno.Content.ReadAsStringAsync().Result, conn);
// erros++;
// }
//});
log_erros = "Perfil;Ponto;\n";
await Task.Run(() =>
{
//for (i = 0; i < tam_arr; i++) {
Parallel.For(1, tam_arr, async (i, state) =>
{
var retorno = await arr_Tks[i];
try
{
if (retorno.IsSuccessStatusCode)
{
arr_Tks_gen[i] = processar_XML_assync(retorno.Content.ReadAsStringAsync().Result, conn);
Console.WriteLine("Processando requisicao {0,2}", i);
}
else
{
erros++;
log_erros += lt_perf_pto[i].Item1 + ";" + lt_perf_pto[i].Item2 + ";\n";
}
}
catch (Exception)
{
await Task.Delay(1000);
arr_Tks_gen[i] = processar_XML_assync(retorno.Content.ReadAsStringAsync().Result, conn);
erros++;
}
});
});
await Task.WhenAll(arr_Tks_gen.ToArray());
await Task.WhenAll(arr_Tks_gen);
Task.WaitAll(arr_Tks_gen);
Task.WaitAll(arr_Tks_gen.ToArray());
Console.WriteLine("Houve {0} requisicoes, com {1} erros", tam_arr, erros);
File.WriteAllText(caminho_log, log_erros);
client.Dispose();
//Console.WriteLine("Tempo esperando o processamento {0}", DateTime.Now - aux_tempo);
return 2;
}
//processa as respostas de forma assincrona
#pragma warning disable CS8602 // Dereference of a possibly null reference.
public static async Task processar_XML_assync(string entrada, OleDbConnection conn)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(entrada);
//doc.Save(@"X:\Back\PLD Horário\xmlresposta.xml
DateTime aux_data = new DateTime(2005, 01, 01);
DateTime tempo_xml;
string strCOM;
tempo_xml = DateTime.Now;
double data, ativa_g, ativa_c, reat_g, reat_c;
long min;
string ponto, origem;
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("hdr", "http://xmlns.energia.org.br/MH/v2");
nsmgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope");
nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
nsmgr.AddNamespace("bmv2", "http://xmlns.energia.org.br/BM/v2");
nsmgr.AddNamespace("bov2", "http://xmlns.energia.org.br/BO/v2");
await Task.Run(() =>
{
foreach (XmlNode n1 in doc.SelectNodes("//bmv2:medidas//bov2:medida", nsmgr))
{
if (n1.SelectSingleNode("bov2:tipoEnergia//bov2:codigo", nsmgr).InnerText == "L")
{
aux_data = DateTime.ParseExact(n1.SelectSingleNode("bov2:data", nsmgr).InnerText, "yyyy-MM-dd'T'HH:mm:ss'-03:00'", null);
data = (aux_data.ToOADate() - aux_data.ToOADate() % 1);
min = aux_data.Hour * 60 + aux_data.Minute;
if (min == 0)
{
min = 1440;
data--;
}
ponto = n1.SelectSingleNode("bov2:medidor//bov2:codigo", nsmgr).InnerText;
origem = n1.SelectSingleNode("bov2:coletaMedicao//bov2:tipo//bov2:nome", nsmgr).InnerText;
Double.TryParse(n1.SelectSingleNode("bov2:energiaAtiva//bov2:consumo//bov2:valor", nsmgr).InnerText, out ativa_c);
Double.TryParse(n1.SelectSingleNode("bov2:energiaAtiva//bov2:geracao//bov2:valor", nsmgr).InnerText, out ativa_g);
Double.TryParse(n1.SelectSingleNode("bov2:energiaReativa//bov2:consumo//bov2:valor", nsmgr).InnerText, out reat_c);
Double.TryParse(n1.SelectSingleNode("bov2:energiaReativa//bov2:geracao//bov2:valor", nsmgr).InnerText, out reat_g);
strCOM = "INSERT INTO Med_5min (Origem, Data, Minuto, Ativa_consumo, Ativa_geracao, Reativa_consumo, Reativa_geracao, Ponto)";
strCOM += " VALUES (\"" + origem + "\"," + data + "," + min + "," + ativa_c + "," + ativa_g + "," + reat_c + "," + reat_g + ",\"" + ponto + "\")";
OleDbCommand tcMed = new(strCOM, conn);
OleDbDataReader reader = tcMed.ExecuteReader();
reader.Close();
}
}
});
}
#pragma warning restore CS8602 // Dereference of a possibly null reference.
//salva arquivos RESPOSTA - APENAS PARA TESTES
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
public static async Task Salva_arquivos(string entrada, int i, int pagina)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(entrada);
doc.Save(@"X:\Back\Carteira x.x\Codigo\__Medicoes\Dev\Resposta " + i + "_" + pagina + ".xml");
}
//salva arquivos REQUISICAO - APENAS PARA TESTES
public static async Task Salva_arquivos_entrada(string entrada, int i, int pagina)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(entrada);
doc.Save(@"X:\Back\Carteira x.x\Codigo\__Medicoes\Dev\Entrada " + i + "_" + pagina + ".xml");
}
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------BUSCA_DAD-------------------------------------------------------------
//prepara o xml de entrada a ser enviado à CCEE
public static string Xml_requisicao(DateTime data_req, string perfil, string cod_ponto, int pagina)
{
string cam_ent, tex_req, sdat_req;
//cam_ent = @"X:\Back\Plataforma de Integração CCEE\Medições\RequestPaginate.txt";
cam_ent = @"X:\Back\Plataforma de Integração CCEE\RequestPaginate.txt";
cod_ponto += "P";
sdat_req = data_req.ToString("yyyy-MM-ddT00:00:00"); //2022-12-31T00:00:00
tex_req = File.ReadAllText(cam_ent);
tex_req = tex_req.Replace("DATAALTERADA", sdat_req);
tex_req = tex_req.Replace("PONTOMEDICAO", cod_ponto);
tex_req = tex_req.Replace("CODPERFIL", perfil);
tex_req = tex_req.Replace("PAGNUM", pagina.ToString());
return tex_req;
}
//busca lista de PerfisCCEE e codigos ponto de medicao no BD cadastral
public static List<Tuple<string, string>> Busca_dad_BD(string caminho_BD)
{
var lt_perf_pto = new List<Tuple<string, string>>();
//lt_perf_pto.Add(new Tuple<string, string>(2, "USA", "328 Millionen"));
string strCOM;
int i;
//strCOM = "SELECT Cod_5min, Codigo_SCDE FROM Dados_cadastrais WHERE LEN(Codigo_SCDE) > 5 AND Unidade_gerenciada = TRUE ORDER BY PerfilCCEE";
strCOM = "SELECT Cod_5min, Codigo_SCDE FROM Dados_cadastrais WHERE LEN(Codigo_SCDE) > 5 and Cliente = 'PENHASCO GRANITOS' ORDER BY PerfilCCEE";
//strCOM = "SELECT Cod_5min, Codigo_SCDE FROM Dados_cadastrais WHERE LEN(Codigo_SCDE) > 5 and Cliente = 'ALMAVIVA' and Unidade = 'GUARULHOS' ORDER BY PerfilCCEE";
OleDbConnection conn = new("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + caminho_BD + ";Jet OLEDB:Database Password=gds21");
conn.Open();
OleDbCommand tcDC = new(strCOM, conn);
OleDbDataReader reader = tcDC.ExecuteReader();
i = 0;
while (reader.Read())
{
#pragma warning disable CS8604 // Possible null reference argument.
lt_perf_pto.Add(new Tuple<string, string>(reader["Cod_5min"].ToString(), reader["Codigo_SCDE"].ToString()));
#pragma warning restore CS8604 // Possible null reference argument.
i++;
}
conn.Close();
return lt_perf_pto;
}
//Exlclui dados do mes atual no BD medicoes
public static void Exclui_med(double data_ini, double data_fim, string caminho_BD)
{
//ACCESS DB
string strCOM;
//strCOM = "DELETE FROM Med_5min WHERE Data >= " + data_ini + " AND Data <= "+data_fim;
//OleDbConnection conn = new("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + caminho_BD + ";Jet OLEDB:Database Password=gds21");
//conn.Open();
//OleDbCommand tcSCDE = new(strCOM, conn);
//tcSCDE.ExecuteReader();
//conn.Close();
//POSTGRE
NpgsqlConnection pg_conn;
if (ENVIRONMENT is "dev")
{
pg_conn = new(PG_CONN_STRING_DEV);
}
else
{
pg_conn = new(PG_CONN_STRING_PROD);
}
pg_conn.Open();
//string pg_strCOM = "DELETE FROM med_5min WHERE dia_num >= " + data_ini + " AND dia_num < " + data_fim;
string pg_strCOM = "DELETE FROM med_5min WHERE dia_num >= " + data_ini + " AND dia_num < " + data_fim + " AND ponto = 'ESPMSOENTR101P'";
NpgsqlCommand pg_tcSCDE = new(pg_strCOM, pg_conn);
NpgsqlDataReader pg_reader = pg_tcSCDE.ExecuteReader();
pg_reader.Close();
pg_conn.Close();
return;
}
//MÉTODO SÍNCRONO
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma warning disable CS8602 // Possible null reference argument.
public static void down_sync(bool loadFromArgs, string[] args)
{
string caminho_BD, caminho_log, caminho_log_sec;
DateTime tempo_ini;
List<Tuple<string, string>> lt_perf_pto;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");
//auxiliar para calculo do tempo de execucao do codigo
tempo_ini = DateTime.Now;
//busca os dados para compor a lista perfis x
caminho_BD = @"\\srv-dados\documentos\Middle\Informativo Setorial\Modelo Word\BD1_dados cadastrais e faturas.accdb";
caminho_log = @"\\srv-dados\documentos\Back\Carteira x.x\Codigo\Erros\log_erros_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Second + ".csv";
lt_perf_pto = Busca_dad_BD(caminho_BD); //ACCESS OK - PG OK
//exlclui os dados do mes atual salvos no BD
caminho_BD = @"\\srv-dados\documentos\Back\Carteira x.x\Gestão Geral v1\Access\BDs teste\DB_med_5min.accdb";
DateTime now = DateTime.Now;
//PROD
DateTime data_ini;
DateTime data_fim;
if (loadFromArgs)
{
/*
args[0] ano inicio
args[1] mes inicio
args[2] ano fim
args[3] mes fim
*/
int ano_ini = Int32.Parse(args[0]);
int mes_ini = Int32.Parse(args[1]);
int ano_fim = Int32.Parse(args[2]);
int mes_fim = Int32.Parse(args[3]);
//DateTime now = DateTime.Now.AddMonths(-1);
//DateTime data_ini = new DateTime(now.Year, now.Month, 1);
//DateTime data_fim = new DateTime(now.Year, now.Month, now.Day);
data_ini = new DateTime(ano_ini, mes_ini, 1);
data_fim = new DateTime(ano_fim, mes_fim, 1).AddMonths(1);
}
else
{
if (ENVIRONMENT is "dev")
{
data_ini = new DateTime(2021, 3, 1);
data_fim = new DateTime(2021, 3, 2);
}
else
{
//configuração puxar desde o início do ano anterior
//data_ini = new DateTime(now.Year - 1, 1, 1);
//data_fim = new DateTime(now.Year, now.Month, now.Day);
//configuração mês anterior
//data_ini = new DateTime(now.Year, now.Month, 1).AddMonths(-1);
//data_fim = new DateTime(now.Year, now.Month, 1);
//configuração mês atual
data_ini = new DateTime(now.Year, now.Month, 1);
data_fim = new DateTime(now.Year, now.Month, now.Day);
//configuração mês especifico
//data_ini = new DateTime(2022, 6, 1);
//data_fim = new DateTime(2022, 7, 1);
}
}
Exclui_med(data_ini.ToOADate(), data_fim.ToOADate(), caminho_BD);
//abre a conexao com o BD onde serao salvos os dados
caminho_BD = @"\\srv-dados\documentos\Back\Carteira x.x\Gestão Geral v1\Access\BDs teste\DB_med_5min.accdb";
OleDbConnection access_conn = new("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + caminho_BD + ";Jet OLEDB:Database Password=gds21");
//OleDbConnection conn = new("Provider=PostgreSQL OLE DB Provider;Data Source=Local;location=primeira_DB;User ID=postgres;password=bdnp;");
//conn.Open();
NpgsqlConnection pg_conn;
if (ENVIRONMENT is "dev")
{
pg_conn = new(PG_CONN_STRING_DEV);
}
else
{
pg_conn = new(PG_CONN_STRING_PROD);
}
//loop para cada dia e cada cod ponto salvando os dados no BD
req_sincrona(data_ini, data_fim, lt_perf_pto, access_conn, pg_conn, caminho_log);
Console.WriteLine("Concluido. Tempo TOTAL de execucao: {0}", DateTime.Now - tempo_ini);
}
public static int processar_XML_sincrono(string entrada, OleDbConnection access_conn, NpgsqlConnection pg_conn)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(entrada);
//doc.Save(@"X:\Back\PLD Horário\xmlresposta.xml
DateTime aux_data = new DateTime(2005, 01, 01);
DateTime tempo_xml;
string access_strCOM, pg_strCOM, log_erros;
XElement pag_atual;
pag_atual = XElement.Parse(entrada);
tempo_xml = DateTime.Now;
double data, ativa_g, ativa_c, reat_g, reat_c;
long min;
string ponto, origem;
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("hdr", "http://xmlns.energia.org.br/MH/v2");
nsmgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope");
nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
nsmgr.AddNamespace("bmv2", "http://xmlns.energia.org.br/BM/v2");
nsmgr.AddNamespace("bov2", "http://xmlns.energia.org.br/BO/v2");
if (access_conn.State != ConnectionState.Open)
{
access_conn.Open();
}
if (pg_conn.State != ConnectionState.Open)
{
pg_conn.Open();
}
log_erros = "Origem;Ponto;Status;Message\n";
ponto = "";
origem = "";
if (pag_ant == null)
{
XNamespace ns = "http://xmlns.energia.org.br/BO/v2";
pag_ant = pag_atual.Descendants(ns + "medida").Where(x => x.Element(ns + "tipoEnergia").Value == "L");
}
else
{
XNamespace ns = "http://xmlns.energia.org.br/BO/v2";
pag_ant = pag_ant.Concat(pag_atual.Descendants(ns + "medida").Where(x => x.Element(ns + "tipoEnergia").Value == "L"));
}
try
{
int num_pag = 1;
foreach (XmlNode n1 in doc.GetElementsByTagName("hdr:totalPaginas"))
{
int.TryParse(n1.InnerText, out num_pag);
}
int num_pag_atual = 1;
foreach (XmlNode n1 in doc.GetElementsByTagName("hdr:numero"))
{
int.TryParse(n1.InnerText, out num_pag_atual);
}
if (num_pag_atual == num_pag)
{
XmlNode node_ant = doc.SelectNodes("//bov2:medida", nsmgr).Item(5);
using (var pg_writer = pg_conn.BeginBinaryImport("COPY med_5min (origem, dia_num, minuto, ativa_consumo, ativa_geracao, reativa_consumo, reativa_geracao, ponto) FROM STDIN (FORMAT BINARY)"))
{
for (int i = 0; i < pag_ant.Count(); i++)
{
XmlDocument nodeDoc = new XmlDocument();
nodeDoc.LoadXml(pag_ant.ElementAt(i).ToString());
XmlNode node = nodeDoc.SelectSingleNode("//bov2:medida", nsmgr);
if (node.SelectSingleNode("bov2:coletaMedicao//bov2:tipo//bov2:nome", nsmgr).InnerText == "Inspeção Lógica")
{
aux_data = DateTime.ParseExact(node.SelectSingleNode("bov2:data", nsmgr).InnerText, "yyyy-MM-dd'T'HH:mm:ss'-03:00'", null);
data = (aux_data.ToOADate() - aux_data.ToOADate() % 1);
min = aux_data.Hour * 60 + aux_data.Minute;
if (min == 0)
{
min = 1440;
data = data - 1;
}
ponto = node.SelectSingleNode("bov2:medidor//bov2:codigo", nsmgr).InnerText;
origem = node.SelectSingleNode("bov2:coletaMedicao//bov2:tipo//bov2:nome", nsmgr).InnerText;
Double.TryParse(node.SelectSingleNode("bov2:energiaAtiva//bov2:consumo//bov2:valor", nsmgr).InnerText, out ativa_c);
Double.TryParse(node.SelectSingleNode("bov2:energiaAtiva//bov2:geracao//bov2:valor", nsmgr).InnerText, out ativa_g);
Double.TryParse(node.SelectSingleNode("bov2:energiaReativa//bov2:consumo//bov2:valor", nsmgr).InnerText, out reat_c);
Double.TryParse(node.SelectSingleNode("bov2:energiaReativa//bov2:geracao//bov2:valor", nsmgr).InnerText, out reat_g);
/*
TODO:
- Study -> Batch insert + Single transaction
*/
//ACCESS DB START
access_strCOM = "INSERT INTO Med_5min (Origem, Data, Minuto, Ativa_consumo, Ativa_geracao, Reativa_consumo, Reativa_geracao, Ponto)";
access_strCOM += " VALUES (\"" + origem + "\"," + data + "," + min + "," + ativa_c + "," + ativa_g + "," + reat_c + "," + reat_g + ",\"" + ponto + "\")";
//OleDbCommand access_tcMed = new(access_strCOM, access_conn);
//OleDbDataReader access_reader = access_tcMed.ExecuteReader();
//access_reader.Close();
//ACCESS DB END
/*
TODO:
- Multi/batch insert
- Single transaction insert (or batch size)
*/
//PGSQL START
//pg_strCOM = "INSERT INTO \"med_5min\"(\"origem\", \"dia_num\", \"minuto\", \"ativa_consumo\", \"ativa_geracao\", \"reativa_consumo\", \"reativa_geracao\", \"ponto\")\n";
//NpgsqlCommand pg_tcMed = new(pg_strCOM, pg_conn);
//NpgsqlDataReader pg_reader = pg_tcMed.ExecuteReader();
//pg_reader.Close();
//pg_strCOM += " VALUES ('" + origem + "'," + data + "," + min + "," + ativa_c + "," + ativa_g + "," + reat_c + "," + reat_g + ",'" + ponto + "');";
pg_writer.StartRow();
pg_writer.Write(origem);
pg_writer.Write(data, NpgsqlTypes.NpgsqlDbType.Numeric);
pg_writer.Write(min, NpgsqlTypes.NpgsqlDbType.Integer);
pg_writer.Write(ativa_c, NpgsqlTypes.NpgsqlDbType.Numeric);
pg_writer.Write(ativa_g, NpgsqlTypes.NpgsqlDbType.Numeric);
pg_writer.Write(reat_c, NpgsqlTypes.NpgsqlDbType.Numeric);
pg_writer.Write(reat_g, NpgsqlTypes.NpgsqlDbType.Numeric);
pg_writer.Write(ponto);
//PGSQL END
node_ant = node;
}
else if (node.SelectSingleNode("bov2:coletaMedicao//bov2:tipo//bov2:nome", nsmgr).InnerText == "Coleta Diária")
{
var data_fut = "a";
if (i + 1 < pag_ant.Count())
{
//XmlDocument node_futDoc = new XmlDocument();
//node_futDoc.LoadXml(pag_ant.ElementAt(i + 1).ToString());
//XmlNode node_fut = node_futDoc.SelectSingleNode("//bov2:medida", nsmgr);
//data_fut = node_fut.SelectSingleNode("bov2:data", nsmgr).InnerText;
data_fut = pag_ant.ElementAt(i + 1).Element("{http://xmlns.energia.org.br/BO/v2}data").Value;
}
var data_atual = node.SelectSingleNode("bov2:data", nsmgr).InnerText;
var data_ant = "a";
if (i != 0)
{
data_ant = node_ant.SelectSingleNode("bov2:data", nsmgr).InnerText;
}
if (data_ant != data_atual && data_fut != data_atual)
{
aux_data = DateTime.ParseExact(node.SelectSingleNode("bov2:data", nsmgr).InnerText, "yyyy-MM-dd'T'HH:mm:ss'-03:00'", null);
data = (aux_data.ToOADate() - aux_data.ToOADate() % 1);
min = aux_data.Hour * 60 + aux_data.Minute;
if (min == 0)
{
min = 1440;
data = data - 1;
}
ponto = node.SelectSingleNode("bov2:medidor//bov2:codigo", nsmgr).InnerText;
origem = node.SelectSingleNode("bov2:coletaMedicao//bov2:tipo//bov2:nome", nsmgr).InnerText;
Double.TryParse(node.SelectSingleNode("bov2:energiaAtiva//bov2:consumo//bov2:valor", nsmgr).InnerText, out ativa_c);
Double.TryParse(node.SelectSingleNode("bov2:energiaAtiva//bov2:geracao//bov2:valor", nsmgr).InnerText, out ativa_g);
Double.TryParse(node.SelectSingleNode("bov2:energiaReativa//bov2:consumo//bov2:valor", nsmgr).InnerText, out reat_c);
Double.TryParse(node.SelectSingleNode("bov2:energiaReativa//bov2:geracao//bov2:valor", nsmgr).InnerText, out reat_g);
/*
TODO:
- Study -> Batch insert + Single transaction
*/
//ACCESS DB START
access_strCOM = "INSERT INTO Med_5min (Origem, Data, Minuto, Ativa_consumo, Ativa_geracao, Reativa_consumo, Reativa_geracao, Ponto)";
access_strCOM += " VALUES (\"" + origem + "\"," + data + "," + min + "," + ativa_c + "," + ativa_g + "," + reat_c + "," + reat_g + ",\"" + ponto + "\")";
//OleDbCommand access_tcMed = new(access_strCOM, access_conn);
//OleDbDataReader access_reader = access_tcMed.ExecuteReader();
//access_reader.Close();
//ACCESS DB END
/*
TODO:
- Multi/batch insert
- Single transaction insert (or batch size)
*/
//PGSQL START
//pg_strCOM = "INSERT INTO \"med_5min\"(\"origem\", \"dia_num\", \"minuto\", \"ativa_consumo\", \"ativa_geracao\", \"reativa_consumo\", \"reativa_geracao\", \"ponto\")\n";
//NpgsqlCommand pg_tcMed = new(pg_strCOM, pg_conn);
//NpgsqlDataReader pg_reader = pg_tcMed.ExecuteReader();
//pg_reader.Close();
//pg_strCOM += " VALUES ('" + origem + "'," + data + "," + min + "," + ativa_c + "," + ativa_g + "," + reat_c + "," + reat_g + ",'" + ponto + "');";
pg_writer.StartRow();
pg_writer.Write(origem);
pg_writer.Write(data, NpgsqlTypes.NpgsqlDbType.Numeric);
pg_writer.Write(min, NpgsqlTypes.NpgsqlDbType.Integer);
pg_writer.Write(ativa_c, NpgsqlTypes.NpgsqlDbType.Numeric);
pg_writer.Write(ativa_g, NpgsqlTypes.NpgsqlDbType.Numeric);
pg_writer.Write(reat_c, NpgsqlTypes.NpgsqlDbType.Numeric);
pg_writer.Write(reat_g, NpgsqlTypes.NpgsqlDbType.Numeric);
pg_writer.Write(ponto);
//PGSQL END
}
node_ant = node;
}
}
pg_writer.Complete();
}
}
return num_pag;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
log_erros += origem + ";" + ponto + ";Erro;" + ex.Message.Replace("\n", "-n-") + "\n";
string caminho_log_sec = @"\\srv-dados\documentos\Back\Carteira x.x\Codigo\Erros\log_sec_erros_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Second + "_" + DateTime.Now.Millisecond + "_sec.csv";
File.WriteAllText(caminho_log_sec, log_erros);
return 1;
}
}
#pragma warning restore CS8602 // Possible null reference argument.
public static void req_sincrona(DateTime data_inicial, DateTime data_final, List<Tuple<string, string>> lt_perf_pto, OleDbConnection access_conn, NpgsqlConnection pg_conn, string caminho_log)
{
string log_erros;
int i;
long erros = 0;
var handler = new HttpClientHandler();
int tam_arr;
//data_inicial = new DateTime(2022, 4, 2);
tam_arr = ((data_final - data_inicial).Days) * lt_perf_pto.Count;
//handler.ClientCertificateOptions = ClientCertificateOption.Manual;
//CURRENT_USER\My\Smart
//handler.ClientCertificates.Add(new X509Certificate2(@"X:\Back\APP Smart\Certificado\Nova\certificado-20207591.pfx", "appsmart"));
//handler.ClientCertificates.Add(new certificate);
handler.ClientCertificateOptions = ClientCertificateOption.Automatic;
DateTime aux_tempo = DateTime.Now;
var client = new HttpClient(handler);
client.DefaultRequestHeaders.Add("SOAPAction", "listarMedidaCincoMinutos");
var endpoint = new Uri("https://servicos.ccee.org.br:443/ws/v2/MedidaCincoMinutosBSv2");
i = 0;
log_erros = "Perfil;Ponto;Status;Message\n";
while (data_inicial < data_final)
{
foreach (Tuple<string, string> item in lt_perf_pto)
{
/*
TODO:
- Incluir paginação
*/
int pagina = 1;
int paginasTotal = 1;
try
{
while (pagina <= paginasTotal)
{
var payload = new StringContent(Xml_requisicao(data_inicial, item.Item1, item.Item2, pagina), Encoding.UTF8, "application/json");
if (SAVE_XML_IN)
{
Salva_arquivos_entrada(Xml_requisicao(data_inicial, item.Item1, item.Item2, pagina), i, pagina).Wait();
}
var retorno = client.PostAsync(endpoint, payload).Result.Content.ReadAsStringAsync().Result.ToString();
Console.WriteLine("Processando requisicao {0,5}, Perf: {1,6}, Ponto: {2,10}, Página: {3}", i, item.Item1, item.Item2, pagina);
if (SAVE_XML_OUT)
{
Salva_arquivos(retorno, i, pagina).Wait();
}
if (access_conn != null && access_conn.State == ConnectionState.Closed)
{
access_conn.Open();
}
if (pg_conn != null && pg_conn.State == ConnectionState.Closed)
{
pg_conn.Open();
}
paginasTotal = processar_XML_sincrono(retorno, access_conn, pg_conn);
//log_erros += item.Item1 + ";" + item.Item2 + ";OK;\n";
pagina++;
}
}
catch (Exception he)
{
Console.WriteLine(he.Message);
Console.WriteLine("caught exception");
erros++;
log_erros += item.Item1 + ";" + item.Item2 + ";Erro;" + he.Message.Replace("\n", "-n-") + "\n";
//Console.ReadKey();
continue;
}
//} catch (IOException ie) {
// Console.WriteLine("caught exception" + ie.Message);
// erros++;
// log_erros += item.Item1 + ";" + item.Item2 + ";Erro;\n";
//} catch (SocketException se) {
// Console.WriteLine("caught exception" + se.Message);
// erros++;
// log_erros += item.Item1 + ";" + item.Item2 + ";Erro;\n";
//} finally {
//}
i++;
pag_ant = null;
}
data_inicial = data_inicial.AddDays(1);
}
Console.WriteLine("Houve {0} requisicoes, com {1} erros", i, erros);
File.WriteAllText(caminho_log, log_erros);
client.Dispose();
}
//public static void ler_xml_salvos() {
// long i=0, max_i,err=0;
// string caminho_BD = @"X:\Back\Carteira x.x\Gestão Geral v1\Access\BDs teste\DB_med_5min.accdb";
// string caminho_xmls = @"X:\Back\Carteira x.x\Codigo\__Medicoes";
// OleDbConnection conn = new("Provider =Microsoft.ACE.OLEDB.12.0;Data Source=" + caminho_BD + ";Jet OLEDB:Database Password=gds21");
// //OleDbConnection conn = new("Provider=PostgreSQL OLE DB Provider;Data Source=Local;location=primeira_DB;User ID=postgres;password=bdnp;");
// //NpgsqlConnection conn = new("Server = 127.0.0.1; Port = 5432; Database = primeira_db; User Id = postgres; Password = bdnp;");
// var pasta = Directory.GetFiles(caminho_xmls);
// max_i=pasta.Length;
// //var files = from file in Directory.EnumerateFiles(caminho_xml) select file;
// conn.Open();
// foreach (string arqs in pasta) {
// try {
// processar_XML_sincrono(System.IO.File.ReadAllText(arqs), conn);
// } catch (Exception e) {
// if (conn.State != ConnectionState.Open) {
// conn.Open();
// }
// err++;
// }
// Console.WriteLine("Processando arquivo {0} de {1}",i,max_i);
// i++;
// }
// Console.WriteLine("Finalizado. Arquivos armazenados lidos e salvos no BD, com {0} erros",err);
// conn.Close();
//}
}

63
Properties/Resources.Designer.cs generated Normal file
View File

@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace PI_Assync_SCDE.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PI_Assync_SCDE.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

101
Properties/Resources.resx Normal file
View File

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,10 @@
{
"profiles": {
"PI_Assync_SCDE": {
"commandName": "Project",
"jsWebView2Debugging": false,
"sqlDebugging": false,
"nativeDebugging": false
}
}
}