diff --git a/Program.cs b/Program.cs index 8c98877..8e67cdd 100644 --- a/Program.cs +++ b/Program.cs @@ -9,6 +9,9 @@ using Newtonsoft.Json.Linq; using System.Collections.Generic; using System.Reflection.Metadata; using Pipefy; +using Microsoft.VisualBasic; +using System.Net.Quic; + class Program { static async Task Main(string[] args) @@ -29,7 +32,7 @@ class Program { string strGestores = JsonConvert.SerializeObject(allGestores); // Desserialize o JSON em objetos C# - var jsonGestores = JsonConvert.DeserializeObject>(strGestores); + var jsonGestores = JsonConvert.DeserializeObject>(strGestores); List jsonListGestores = convertGestoresJson(jsonGestores); @@ -47,6 +50,30 @@ class Program if (recordsMissingInJson.Count != 0) { + string strQuery = "{\"query\":\"mutation {\\r\\n "; + + for (int i = 0; i < recordsMissingInJson.Count; i++) + { + if (i % 49 == 0) { strQuery = "{\"query\":\"mutation {\\r\\n "; } + + strQuery = strQuery + $"N{i}: createTableRecord(input: {{ table_id: \\\"{PipefyTokenTableID}\\\", fields_attributes: [ {{ field_id: \\\"nome_da_empresa\\\", field_value: \\\"{recordsMissingInJson[i].nome_da_empresa.ToString()}\\\" }} {{ field_id: \\\"c_digo_smart\\\", field_value: \\\"{recordsMissingInJson[i].c_digo_smart.ToString()}\\\" }} {{ field_id: \\\"modalidade\\\", field_value: \\\"{recordsMissingInJson[i].modalidade.ToString()}\\\" }} {{ field_id: \\\"gestores\\\", field_value: \\\"{recordsMissingInJson[i].gestores.ToString()}\\\" }}]}}) {{ table_record {{ id }}}}\\r\\n "; + + if (i % 48 == 0 && i != 0) { + + strQuery = strQuery + "}\",\"variables\":{}}"; + + bool success = await CreatePipefyDataAsync(apiUrl, PipefyToken, PipefyTokenTableID, strQuery); + + if (!success) { + int test2 = 10; + } + } + } + + strQuery = strQuery + "}\",\"variables\":{}}"; + + bool success1 = await CreatePipefyDataAsync(apiUrl, PipefyToken, PipefyTokenTableID, strQuery); + // Faça algo com os registros ausentes int maxCId = recordsMissingInJson.OrderByDescending(s => s.c_digo_smart.Length).First().c_digo_smart.Length; int maxCNome = recordsMissingInJson.OrderByDescending(s => s.nome_da_empresa.Length).First().nome_da_empresa.Length; @@ -66,6 +93,22 @@ class Program } } + private static async Task CreatePipefyDataAsync(string apiUrl, string PipefyToken, string PipefyTokenTableID, string query) + { + + var httpClient = new HttpClient(); + // Defina os headers da requisição (opcional) + httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + PipefyToken); + + var request = new HttpRequestMessage(HttpMethod.Post, apiUrl); + request.Headers.Add("Accept", "application/json"); + + var content = new StringContent(query, null, "application/json"); + request.Content = content; + var response = await httpClient.SendAsync(request); + + return response.IsSuccessStatusCode; + } private static async Task GetPipefyDataAsync(string apiUrl, string PipefyToken, string PipefyTokenTableID) { JArray allRecords = new JArray(); @@ -188,23 +231,21 @@ class Program return data; } - static List convertGestoresJson(List jsonData) + static List convertGestoresJson(List jsonData) { List data = new List(); for (int i = 0; i < jsonData.Count; i++) { + Pipefy.ClasseGestores record = new Pipefy.ClasseGestores(); + record.id = jsonData[i].node.id.ToString(); + for (int j = 0; j < jsonData[i].node.record_fields.Length; j++) { - switch (jsonData[i].node.record_fields[j].field.id) + if (jsonData[i].node.record_fields[j].field.id == "gest_o") { - case "gestor": - record.id = jsonData[i].node.record_fields.ToString(); - break; - case "gest_o": record.gestores = jsonData[i].node.record_fields[j].value; - break; } } @@ -218,7 +259,7 @@ class Program static List CompareData(List databaseData, List jsonList, List jsonListGestores) { - if (jsonList == null) + if (jsonList == null | jsonListGestores == null) { return databaseData; } diff --git a/data.cs b/data.cs index 428cc66..1a60b25 100644 --- a/data.cs +++ b/data.cs @@ -10,6 +10,10 @@ namespace Pipefy { public Node node { get; set; } } + public class RootGestor + { + public NodeGestor node { get; set; } + } public class Data { @@ -20,7 +24,11 @@ namespace Pipefy { public Record_Fields[] record_fields { get; set; } } - + public class NodeGestor + { + public string id { get; set; } + public Record_Fields[] record_fields { get; set; } + } public class Record_Fields { public Field field { get; set; }