From 82d6df6a3570c968c7ca8accff6b6218a9d75127 Mon Sep 17 00:00:00 2001 From: Adriano Serighelli Date: Fri, 19 Apr 2024 14:53:08 -0300 Subject: [PATCH] =?UTF-8?q?-=20Remo=C3=A7=C3=A3o=20de=20log=20para=20conta?= =?UTF-8?q?s=20"saud=C3=A1veis"=20-=20Adi=C3=A7=C3=A3o=20de=20contas=20n?= =?UTF-8?q?=C3=A3o=20encontradas=20=C3=A0=20tabela=20de=20erros=20"AgVirtu?= =?UTF-8?q?al4DocsErros"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Webhook 4docs/Program.cs | 60 ++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/Webhook 4docs/Program.cs b/Webhook 4docs/Program.cs index b0d9ae8..aac865f 100644 --- a/Webhook 4docs/Program.cs +++ b/Webhook 4docs/Program.cs @@ -181,7 +181,7 @@ namespace Webhook_4docs { double errorID = 0; - switch (JsonBody.GetProperty("healthy").GetBoolean(), JsonBody.GetProperty("blame").ToString()) + switch (JsonBody.GetProperty("healthy").GetBoolean(), JsonBody.GetProperty("blame").ToString().ToLower()) { case (false, "user"): logger.LogError("Loc ID: " + JsonBody.GetProperty("locationID").ToString() + " Sem acesso"); @@ -196,40 +196,66 @@ namespace Webhook_4docs errorID = 3; break; case (true, _): - logger.LogInformation("Loc ID: " + JsonBody.GetProperty("locationID").ToString() + " está saudável"); + //logger.LogInformation("Loc ID: " + JsonBody.GetProperty("locationID").ToString() + " está saudável"); break; } - UpdateErrorIdStatus(CaminhoDB, JsonBody.GetProperty("locationID").GetInt64(), errorID); + int test = UpdateErrorIdStatus(CaminhoDB, JsonBody.GetProperty("locationID").GetInt64(), errorID); + if (test == 0) + { + InsertErrorIdStatus(CaminhoDB, errorID, requestBody); + } } }); }); app.Run(); } - public static void UpdateErrorIdStatus(string CaminhoDB, double location_id, double errorID) + public static void InsertErrorIdStatus(string CaminhoDB, double errorID, string requestBody) + { + var JsonBody = JsonDocument.Parse(requestBody).RootElement; + + double locationID = JsonBody.GetProperty("locationID").GetInt64() ; + string accountID = JsonBody.GetProperty("accountID").ToString() ; + string deliveryTimeStamp = JsonBody.GetProperty("deliveryTimestamp").ToString() ; + string provider = JsonBody.GetProperty("provider").ToString() ; + string accessPoint = JsonBody.GetProperty("accessPoint").ToString() ; + string slaStatus = JsonBody.GetProperty("slaStatus").ToString() ; + string healthy = JsonBody.GetProperty("healthy").ToString() ; + string blame = JsonBody.GetProperty("blame").ToString() ; + string lastSuccess = JsonBody.GetProperty("lastSuccess").ToString() ; + string active = JsonBody.GetProperty("active").ToString() ; + string blacklistStatus = JsonBody.GetProperty("blacklistStatus").ToString() ; + string lastActivated = JsonBody.GetProperty("lastActivated").ToString() ; + string lastDeactivated = JsonBody.GetProperty("lastDeactivated").ToString() ; + string lastDeactivatedBy = JsonBody.GetProperty("lastDeactivatedBy").ToString() ; + + using (OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + CaminhoDB + ";Jet OLEDB:Database Password=gds21")) + { + conn.Open(); + int test = 0; + using (OleDbCommand cmd = new OleDbCommand($"INSERT INTO AgVirtual4DocsErros (locationID, accountID, errorID, deliveryTimeStamp, provider, accessPoint, slaStatus, healthy, blame, lastSuccess, active, blacklistStatus, lastActivated, lastDeactivated, lastDeactivatedBy) VALUES ({locationID}, {accountID}, {errorID}, \'{deliveryTimeStamp}\', \'{provider}\', \'{accessPoint}\', \'{slaStatus}\', \'{healthy}\', \'{blame}\', \'{lastSuccess}\', \'{active}\', \'{blacklistStatus}\', \'{lastActivated}\', \'{lastDeactivated}\', \'{lastDeactivatedBy}\')", conn)) + { + //cmd.Parameters.AddWithValue("@location_id", location_id); + //cmd.Parameters.AddWithValue("@errorID", errorID); + test = cmd.ExecuteNonQuery(); + } + } + } + public static int UpdateErrorIdStatus(string CaminhoDB, double location_id, double errorID) { using (OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + CaminhoDB + ";Jet OLEDB:Database Password=gds21")) { conn.Open(); - + int test = 0; using (OleDbCommand cmd = new OleDbCommand($"UPDATE AgVirtual4Docs SET AgVirtual4Docs.errorID = {errorID}\r\nWHERE (((AgVirtual4Docs.location_id)={location_id}));\r\n", conn)) { //cmd.Parameters.AddWithValue("@location_id", location_id); //cmd.Parameters.AddWithValue("@errorID", errorID); - int test = cmd.ExecuteNonQuery(); - } - using (OleDbCommand cmd = new OleDbCommand($"SELECT location_id, errorID FROM AgVirtual4Docs WHERE location_id = @location_id", conn)) - { - cmd.Parameters.AddWithValue("@location_id", location_id); - using (OleDbDataReader reader = cmd.ExecuteReader()) - { - while(reader.Read()) - { - string? test = reader["errorID"].ToString(); - } - } + test = cmd.ExecuteNonQuery(); } + + return test; } } public static bool CriarArquivo(string fatura_arquivo, string pdfFile64)