diff --git a/Download Faturas/Fatura.cs b/Download Faturas/Fatura.cs index 1d149ec..c4fd706 100644 --- a/Download Faturas/Fatura.cs +++ b/Download Faturas/Fatura.cs @@ -30,6 +30,7 @@ this.faturaParsed = JsonDocument.Parse(fatura_response.Content.ReadAsStringAsync().Result).RootElement; this.Agrupada = this.faturaParsed.TryGetProperty("multiple", out var _); this.Status = this.faturaParsed.GetProperty("status").GetString() !; + this.Arquivo = fatura_path; if (this.Agrupada) { this.Agrupada_children = this.faturaParsed.GetProperty("children").EnumerateArray(); @@ -41,6 +42,8 @@ public string? Pasta_middle { get; private set; } + public string? Arquivo { get; private set; } + public string? UC { get; private set; } public int Mes { get; private set; } @@ -341,6 +344,30 @@ public void Mover() { + switch (this.Status) + { + case "UNIDADE CONSUMIDORA NÃO LOCALIZADA NO BD": + + break; + + case "FATURA DUPLICADA NO BD": + + break; + + case "FATURA INCLUIDA NO BD": + + break; + + case "INVALID": + + break; + + case "DELAYED": + + break; + } + + } private HttpResponseMessage GetStatus(HttpClient httpClient, string token, string id) diff --git a/Download Faturas/GlobalSuppressions.cs b/Download Faturas/GlobalSuppressions.cs index 9969062..3375312 100644 --- a/Download Faturas/GlobalSuppressions.cs +++ b/Download Faturas/GlobalSuppressions.cs @@ -5,5 +5,5 @@ using System.Diagnostics.CodeAnalysis; -[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Reviewed.")] -[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "")] +[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Revisado.")] +[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "Revisado.")] diff --git a/Upload Faturas/GlobalSuppressions.cs b/Upload Faturas/GlobalSuppressions.cs new file mode 100644 index 0000000..eb4b385 --- /dev/null +++ b/Upload Faturas/GlobalSuppressions.cs @@ -0,0 +1,9 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "Revisado.")] +[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "Revisado.")] diff --git a/Upload Faturas/Program.cs b/Upload Faturas/Program.cs index c64773d..d1caacb 100644 --- a/Upload Faturas/Program.cs +++ b/Upload Faturas/Program.cs @@ -1,19 +1,17 @@ -using System.Text; -using System.Net.Http.Headers; +using System.Net.Http.Headers; +using System.Text; using System.Text.Json; -using System.Web; -using System.Text.RegularExpressions; -using System.IO; -public class program +public class Program { #if DEBUG - public const String log_faturas = @"X:\Back\Carteira x.x\4Docs\import.txt"; + public const string LogFaturas = @"X:\Back\Carteira x.x\4Docs\import.txt"; #else public const String log_faturas = "import.txt"; #endif private static HttpClient httpClient = new HttpClient(); + public static async Task Main() { for (int i = 1; i < 3; i++) @@ -23,104 +21,41 @@ public class program DirectoryInfo pasta = new DirectoryInfo(@"X:\Middle\Carteira " + i + @"\Carteira " + i + "." + j + @"\Faturas fourdocs\1 - INDIVIDUAIS"); DirectoryInfo pasta_agrupadas = new DirectoryInfo(@"X:\Middle\Carteira " + i + @"\Carteira " + i + "." + j + @"\Faturas fourdocs\2 - AGRUPADAS"); - if (ler_pasta(pasta, agrupada: false).Result) + if (LerPasta(pasta, agrupada: false).Result) { - await ler_pasta(pasta_agrupadas, agrupada: true); + await LerPasta(pasta_agrupadas, agrupada: true); } } } - - - //string? fim = "n"; - - //while (fim != "s") - //{ - // Console.WriteLine("Escolha a carteira: (todas - 1.1 - 1.2 - 1.3 - ...)\n"); - // string? carteira = Console.ReadLine(); - - // if (carteira != null & carteira!.Length == 3) - // { - // DirectoryInfo pasta = new DirectoryInfo(@"X:\Middle\Carteira " + carteira[0] + @"\Carteira " + carteira + @"\Faturas fourdocs"); - // DirectoryInfo pasta_agrupadas = new DirectoryInfo(@"X:\Middle\Carteira " + carteira[0] + @"\Carteira " + carteira + @"\Faturas fourdocs\Agrupadas"); - - // if (ler_pasta(pasta, agrupada: false).Result) - // { - // if (ler_pasta(pasta_agrupadas, agrupada: true).Result) - // { - // Console.WriteLine("\nDeseja finalizar? (s/n)\n"); - // fim = Console.ReadLine(); - // Console.WriteLine("\n"); - // } - // else - // { - // Console.WriteLine("\nAgrupadas não localizadas\n"); - // } - // } - // else - // { - // Console.WriteLine("\nCarteira não encontrada\n"); - // } - // } - // else if (carteira == "todas") - // { - // for (int i = 1; i < 3; i++) - // { - // for (int j = 1; j < 7; j++) - // { - // DirectoryInfo pasta = new DirectoryInfo(@"X:\Middle\Carteira " + i + @"\Carteira " + i + "." + j + @"\Faturas fourdocs"); - // DirectoryInfo pasta_agrupadas = new DirectoryInfo(@"X:\Middle\Carteira " + i + @"\Carteira " + i + "." + j + @"\Faturas fourdocs\Agrupadas"); - - // if (ler_pasta(pasta, agrupada: false).Result) - // { - // if (!ler_pasta(pasta_agrupadas, agrupada: true).Result) - // { - // Console.WriteLine($"\nCarteira {i}.{j} Agrupada - Erro"); - // } - // } - // else - // { - // Console.WriteLine($"\nCarteira {i}.{j} - Erro"); - // } - // } - // } - // Console.WriteLine("\nDeseja finalizar? (s/n)\n"); - // fim = Console.ReadLine(); - // Console.WriteLine("\n"); - // } - // else - // { - // Console.WriteLine("\nCarteira não encontrada\n"); - // } - //} - //await Task.Delay(1); } - public static async Task ler_pasta(DirectoryInfo pasta, bool agrupada) + public static async Task LerPasta(DirectoryInfo pasta, bool agrupada) { if (pasta.Exists) { string token = "UFY4VWzqcHYcGNd0gkBOMFL9G5ZThV6gXBQIJ79F5HSqITzavz4Fe7iXvAbJLvZJ"; - //token = await req_token(); + + // token = await req_token(); FileInfo[] faturas = pasta.GetFiles("*.pdf"); - - StreamWriter sw = new StreamWriter(log_faturas, true); + StreamWriter sw = new StreamWriter(LogFaturas, true); foreach (FileInfo fatura in faturas) { if (!IsFileLocked(fatura)) { - HttpResponseMessage response = await send_fatura(token, fatura.FullName, agrupada); + HttpResponseMessage response = await SendFatura(token, fatura.FullName, agrupada); if ((int)response.StatusCode == 202) { - var ID = JsonDocument.Parse(response.Content.ReadAsStringAsync().Result).RootElement.GetProperty("requestId"); - fatura.MoveTo(fatura.Directory?.Parent?.FullName + $@"\3 - PROCESSANDO\{ID} - " + fatura.Name); - sw.Write(ID); + var iD = JsonDocument.Parse(response.Content.ReadAsStringAsync().Result).RootElement.GetProperty("requestId"); + fatura.MoveTo(fatura.Directory?.Parent?.FullName + $@"\3 - PROCESSANDO\{iD} - " + fatura.Name); + sw.Write(iD); sw.Write(","); sw.Write(","); sw.WriteLine(fatura.FullName); } } } + sw.Close(); return true; } @@ -130,7 +65,7 @@ public class program } } - public static async Task req_token() + public static async Task ReqToken() { var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.4docs.cloud/v2/oauth2/token"); @@ -145,7 +80,7 @@ public class program return JsonDocument.Parse(response.Content.ReadAsStringAsync().Result).RootElement.GetProperty("access_token").GetString(); } - public static async Task send_fatura(string token, string fatura, bool agrupada) + public static async Task SendFatura(string token, string fatura, bool agrupada) { var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.4docs.cloud/v2/parse"); @@ -163,6 +98,7 @@ public class program return await httpClient.SendAsync(request); } + public static bool IsFileLocked(FileInfo file) { try @@ -174,14 +110,14 @@ public class program } catch (IOException) { - //the file is unavailable because it is: - //still being written to - //or being processed by another thread - //or does not exist (has already been processed) + // the file is unavailable because it is: + // still being written to + // or being processed by another thread + // or does not exist (has already been processed) return true; } - //file is not locked + // file is not locked return false; } }