Correção de avisos
This commit is contained in:
parent
f11bc9f194
commit
857e13d667
@ -30,6 +30,7 @@
|
|||||||
this.faturaParsed = JsonDocument.Parse(fatura_response.Content.ReadAsStringAsync().Result).RootElement;
|
this.faturaParsed = JsonDocument.Parse(fatura_response.Content.ReadAsStringAsync().Result).RootElement;
|
||||||
this.Agrupada = this.faturaParsed.TryGetProperty("multiple", out var _);
|
this.Agrupada = this.faturaParsed.TryGetProperty("multiple", out var _);
|
||||||
this.Status = this.faturaParsed.GetProperty("status").GetString() !;
|
this.Status = this.faturaParsed.GetProperty("status").GetString() !;
|
||||||
|
this.Arquivo = fatura_path;
|
||||||
if (this.Agrupada)
|
if (this.Agrupada)
|
||||||
{
|
{
|
||||||
this.Agrupada_children = this.faturaParsed.GetProperty("children").EnumerateArray();
|
this.Agrupada_children = this.faturaParsed.GetProperty("children").EnumerateArray();
|
||||||
@ -41,6 +42,8 @@
|
|||||||
|
|
||||||
public string? Pasta_middle { get; private set; }
|
public string? Pasta_middle { get; private set; }
|
||||||
|
|
||||||
|
public string? Arquivo { get; private set; }
|
||||||
|
|
||||||
public string? UC { get; private set; }
|
public string? UC { get; private set; }
|
||||||
|
|
||||||
public int Mes { get; private set; }
|
public int Mes { get; private set; }
|
||||||
@ -341,6 +344,30 @@
|
|||||||
|
|
||||||
public void Mover()
|
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)
|
private HttpResponseMessage GetStatus(HttpClient httpClient, string token, string id)
|
||||||
|
|||||||
@ -5,5 +5,5 @@
|
|||||||
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Reviewed.")]
|
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Revisado.")]
|
||||||
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "<Pendente>")]
|
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "Revisado.")]
|
||||||
|
|||||||
9
Upload Faturas/GlobalSuppressions.cs
Normal file
9
Upload Faturas/GlobalSuppressions.cs
Normal file
@ -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.")]
|
||||||
@ -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.Text.Json;
|
||||||
using System.Web;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
public class program
|
public class Program
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#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
|
#else
|
||||||
public const String log_faturas = "import.txt";
|
public const String log_faturas = "import.txt";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private static HttpClient httpClient = new HttpClient();
|
private static HttpClient httpClient = new HttpClient();
|
||||||
|
|
||||||
public static async Task Main()
|
public static async Task Main()
|
||||||
{
|
{
|
||||||
for (int i = 1; i < 3; i++)
|
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 = 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");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task<bool> LerPasta(DirectoryInfo pasta, bool agrupada)
|
||||||
//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<bool> ler_pasta(DirectoryInfo pasta, bool agrupada)
|
|
||||||
{
|
{
|
||||||
if (pasta.Exists)
|
if (pasta.Exists)
|
||||||
{
|
{
|
||||||
string token = "UFY4VWzqcHYcGNd0gkBOMFL9G5ZThV6gXBQIJ79F5HSqITzavz4Fe7iXvAbJLvZJ";
|
string token = "UFY4VWzqcHYcGNd0gkBOMFL9G5ZThV6gXBQIJ79F5HSqITzavz4Fe7iXvAbJLvZJ";
|
||||||
//token = await req_token();
|
|
||||||
FileInfo[] faturas = pasta.GetFiles("*.pdf");
|
|
||||||
|
|
||||||
StreamWriter sw = new StreamWriter(log_faturas, true);
|
// token = await req_token();
|
||||||
|
FileInfo[] faturas = pasta.GetFiles("*.pdf");
|
||||||
|
StreamWriter sw = new StreamWriter(LogFaturas, true);
|
||||||
|
|
||||||
foreach (FileInfo fatura in faturas)
|
foreach (FileInfo fatura in faturas)
|
||||||
{
|
{
|
||||||
if (!IsFileLocked(fatura))
|
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)
|
if ((int)response.StatusCode == 202)
|
||||||
{
|
{
|
||||||
var ID = JsonDocument.Parse(response.Content.ReadAsStringAsync().Result).RootElement.GetProperty("requestId");
|
var iD = JsonDocument.Parse(response.Content.ReadAsStringAsync().Result).RootElement.GetProperty("requestId");
|
||||||
fatura.MoveTo(fatura.Directory?.Parent?.FullName + $@"\3 - PROCESSANDO\{ID} - " + fatura.Name);
|
fatura.MoveTo(fatura.Directory?.Parent?.FullName + $@"\3 - PROCESSANDO\{iD} - " + fatura.Name);
|
||||||
sw.Write(ID);
|
sw.Write(iD);
|
||||||
sw.Write(",");
|
sw.Write(",");
|
||||||
sw.Write(",");
|
sw.Write(",");
|
||||||
sw.WriteLine(fatura.FullName);
|
sw.WriteLine(fatura.FullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.Close();
|
sw.Close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -130,7 +65,7 @@ public class program
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<string?> req_token()
|
public static async Task<string?> ReqToken()
|
||||||
{
|
{
|
||||||
var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.4docs.cloud/v2/oauth2/token");
|
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();
|
return JsonDocument.Parse(response.Content.ReadAsStringAsync().Result).RootElement.GetProperty("access_token").GetString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<HttpResponseMessage> send_fatura(string token, string fatura, bool agrupada)
|
public static async Task<HttpResponseMessage> SendFatura(string token, string fatura, bool agrupada)
|
||||||
{
|
{
|
||||||
var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.4docs.cloud/v2/parse");
|
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);
|
return await httpClient.SendAsync(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsFileLocked(FileInfo file)
|
public static bool IsFileLocked(FileInfo file)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -174,14 +110,14 @@ public class program
|
|||||||
}
|
}
|
||||||
catch (IOException)
|
catch (IOException)
|
||||||
{
|
{
|
||||||
//the file is unavailable because it is:
|
// the file is unavailable because it is:
|
||||||
//still being written to
|
// still being written to
|
||||||
//or being processed by another thread
|
// or being processed by another thread
|
||||||
//or does not exist (has already been processed)
|
// or does not exist (has already been processed)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//file is not locked
|
// file is not locked
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user