Ajustes para trasmitir expedientes

This commit is contained in:
2026-03-06 12:56:41 -07:00
parent dcfd606a1c
commit c52344d7f8
13 changed files with 924 additions and 401 deletions

View File

@@ -801,96 +801,96 @@ namespace EFCDesk.Forms
sqliteHelper.AgregarRegistroErrorLog(e, sNombreClase, currentMethod);
}
}
private async Task<bool> SubirArchivoApiAsync(string pedimento, string filePath)
{
// private async Task<bool> SubirArchivoApiAsync(string pedimento, string filePath)
// {
try
{
var config = ConfiguracionJSON.LoadFromJson();
string Token = SecureDataHandler.ReadDataAsPlainText() ?? "";
// try
// {
// var config = ConfiguracionJSON.LoadFromJson();
// string Token = SecureDataHandler.ReadDataAsPlainText() ?? "";
if (string.IsNullOrWhiteSpace(DominioEFC))
{
logger.LogError("No se ha configurado el dominio", null);
return false;
}
// if (string.IsNullOrWhiteSpace(DominioEFC))
// {
// logger.LogError("No se ha configurado el dominio", null);
// return false;
// }
if (!string.IsNullOrEmpty(Token))
{
using var apiClient = new ApiClient(timeout: TimeSpan.FromSeconds(10), maxRetries: 3, retryDelay: TimeSpan.FromSeconds(2));
string UrlGetPedimento = DominioEFC + ApiGetPedimento + pedimento;
string jsonResponse = await apiClient.GetAsync(url: UrlGetPedimento);
// if (!string.IsNullOrEmpty(Token))
// {
// var apiClient = Globales.ApiClient;
// string UrlGetPedimento = DominioEFC + ApiGetPedimento + pedimento;
// string jsonResponse = await apiClient.GetAsync(url: UrlGetPedimento);
if (!apiClient.IsJson(jsonResponse))
{
logger.LogError("Error en la respuesta de la peticion de pedimento al intentar subir el archivo al api:" + DominioEFC, new Exception("Error API"));
return false;
}
// if (!apiClient.IsJson(jsonResponse))
// {
// logger.LogError("Error en la respuesta de la peticion de pedimento al intentar subir el archivo al api:" + DominioEFC, new Exception("Error API"));
// return false;
// }
if (!apiClient.HasJsonData(jsonResponse))
{
logger.LogError("No se obtuvo informacion del api:" + DominioEFC, null);
return false;
}
// if (!apiClient.HasJsonData(jsonResponse))
// {
// logger.LogError("No se obtuvo informacion del api:" + DominioEFC, null);
// return false;
// }
var pedimentos = apiClient.TryParseJson<List<Pedimentos>>(jsonResponse);
// var pedimentos = apiClient.TryParseJson<List<Pedimentos>>(jsonResponse);
if (pedimentos != null)
{
// Obtener el primer pedimento de la lista
var primerPedimento = pedimentos.FirstOrDefault();
string guiOrganizacion = primerPedimento.organizacion;
string guiPedimento = primerPedimento.id;
// if (pedimentos != null)
// {
// // Obtener el primer pedimento de la lista
// var primerPedimento = pedimentos.FirstOrDefault();
// string guiOrganizacion = primerPedimento.organizacion;
// string guiPedimento = primerPedimento.id;
string UrlPostArchivo = DominioEFC + ApiPostDocuments;
// string UrlPostArchivo = DominioEFC + ApiPostDocuments;
string respuesta = await apiClient.PostMultipartAsync(
url: UrlPostArchivo,
filePath: filePath,
organizacion: guiOrganizacion,
pedimento: guiPedimento,
documentType: "9",
fuente: "1"
);
//string respuesta = await apiClient.PostMultipartAsync(
// url: UrlPostArchivo,
// filePath: filePath,
// organizacion: guiOrganizacion,
// pedimento: guiPedimento,
// documentType: "9",
// fuente: "1"
// );
if (!apiClient.IsJson(jsonResponse))
{
return false;
}
if (!apiClient.HasJsonData(jsonResponse))
{
return false;
}
// if (!apiClient.IsJson(jsonResponse))
// {
// return false;
// }
// if (!apiClient.HasJsonData(jsonResponse))
// {
// return false;
// }
var documentos = apiClient.TryParseJson<List<Documentos>>(jsonResponse);
if (documentos == null)
{
return false;
}
}
else
{
logger.LogInfo("No se encontro el pedimento");
return false;
}
// var documentos = apiClient.TryParseJson<List<Documentos>>(jsonResponse);
// if (documentos == null)
// {
// return false;
// }
// }
// else
// {
// logger.LogInfo("No se encontro el pedimento");
// return false;
// }
}
else
{
logger.LogError("Error en la configuracion del Id de Usuario:" + DominioEFC, new Exception("Error Id Usuario"));
return false;
}
}
catch (Exception ex)
{
logger.LogError("Error inesperado SubirArchivoApiAsync", ex);
return false;
}
// }
// else
// {
// logger.LogError("Error en la configuracion del Id de Usuario:" + DominioEFC, new Exception("Error Id Usuario"));
// return false;
// }
// }
// catch (Exception ex)
// {
// logger.LogError("Error inesperado SubirArchivoApiAsync", ex);
// return false;
// }
return true;
}
// return true;
// }
private void RegistrarArchivoEnAPI(string file)
{
try