Ajuste de codigo para peticion a url de enpoint de task status

This commit is contained in:
2026-03-09 12:18:46 -06:00
parent c52344d7f8
commit 03230e0cba
4 changed files with 64 additions and 13 deletions

View File

@@ -28,6 +28,8 @@ public class ApiClient : IDisposable
private string? _currentRefreshToken;
private readonly object _tokenLock = new object();
private string DominioEFC = Helpers.DominioExpedienteElectronico();
public ApiClient(TimeSpan? timeout = null, int maxRetries = 3, TimeSpan? retryDelay = null)
{
@@ -57,6 +59,10 @@ public class ApiClient : IDisposable
return @"/api/v1/token/refresh/";
}
public string EndpointStatusTask()
{
return @"/api/v1/tasks/status/";
}
private void SetAuthorizationBearer(string token, string refresh_token)
{
@@ -277,6 +283,13 @@ public class ApiClient : IDisposable
return await SendWithRetriesAsync(() => new HttpRequestMessage(HttpMethod.Get, url));
}
public async Task<string> GetStatusTaskAsync(string taskId)
{
var apiClient = Globales.ApiClient;
string url = DominioEFC + EndpointStatusTask() + $"{taskId}/";
return await SendWithRetriesAsync(() => new HttpRequestMessage(HttpMethod.Get, url));
}
public async Task<string> PostJsonAsync(string url, string jsonContent)
{
using var content = new StringContent(jsonContent, System.Text.Encoding.UTF8, "application/json");

View File

@@ -498,7 +498,7 @@ namespace EFCDesk.Classes
Console.WriteLine($"Error: {ex.Message}");
}
}
public void MarcarCarpetaProcesada(string ruta, string estado)
public void MarcarCarpetaProcesada(string expediente, string estado)
{
try
{
@@ -510,7 +510,7 @@ namespace EFCDesk.Classes
using (var command = new SQLiteCommand(updateQuery, connection))
{
command.Parameters.AddWithValue("@r", ruta);
command.Parameters.AddWithValue("@r", expediente);
command.Parameters.AddWithValue("@e", estado);
command.ExecuteNonQuery();
}
@@ -545,6 +545,30 @@ namespace EFCDesk.Classes
}
}
public void ActaulizarStatusCarpeta(string expediente, string estado)
{
try
{
using (var connection = new SQLiteConnection(_connectionString))
{
connection.Open();
string updateQuery = "UPDATE Carpetas SET Estado=@e WHERE Ruta=@r OR Nombre=@r";
using (var command = new SQLiteCommand(updateQuery, connection))
{
command.Parameters.AddWithValue("@r", expediente);
command.Parameters.AddWithValue("@e", estado);
command.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
public bool EstaArchivoProcesado(string rutaArchivo)
{

View File

@@ -70,7 +70,7 @@ namespace EFCDesk.Forms
};
// Columna de acciones
//table.Columns.Add("Acciones", typeof(Image));
table.Columns.Add("Acciones", typeof(Image));
// Crear el icono UNA sola vez
Bitmap iconoVer = IconChar.Eye.ToBitmap(
@@ -87,7 +87,7 @@ namespace EFCDesk.Forms
row["Estatus"] = exp.Estado;
row["Fecha Registro"] = exp.FechaCreacion;
row["TaskId"] = exp.TaskId;
//row["Acciones"] = iconoVer;
row["Acciones"] = iconoVer;
table.Rows.Add(row);
}
return table;
@@ -115,9 +115,9 @@ namespace EFCDesk.Forms
dgwExpedientes.Columns["Fecha Registro"].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
dgwExpedientes.Columns["Fecha Registro"].Width = 180;
//dgwExpedientes.Columns["Acciones"].Width = 40;
//dgwExpedientes.Columns["Acciones"].HeaderText = "";
//((DataGridViewImageColumn)dgwExpedientes.Columns["Acciones"]).ImageLayout = DataGridViewImageCellLayout.Zoom;
dgwExpedientes.Columns["Acciones"].Width = 40;
dgwExpedientes.Columns["Acciones"].HeaderText = "";
((DataGridViewImageColumn)dgwExpedientes.Columns["Acciones"]).ImageLayout = DataGridViewImageCellLayout.Zoom;
_ = Task.Run(() =>
{
@@ -152,8 +152,8 @@ namespace EFCDesk.Forms
try
{
var apiClient = Globales.ApiClient;
string url = DominioEFC + $"/api/v1/tasks/status/?task_id={taskId}";
return await apiClient.GetAsync(url);
//string url = DominioEFC + $"/api/v1/tasks/status/{taskId}/";
return await apiClient.GetStatusTaskAsync(taskId);
}
catch (Exception ex)
{
@@ -209,7 +209,7 @@ namespace EFCDesk.Forms
}
// Actualizar en SQLite
_sqliteHelper.MarcarCarpetaProcesada(rutaExpediente, nuevoEstado);
_sqliteHelper.ActaulizarStatusCarpeta(rutaExpediente, nuevoEstado);
// Mostrar resultado
MessageBox.Show(mensaje, "Estado de Tarea", MessageBoxButtons.OK, MessageBoxIcon.Information);
@@ -384,6 +384,9 @@ namespace EFCDesk.Forms
if (string.IsNullOrEmpty(taskId))
return;
if (string.IsNullOrEmpty(expediente))
return;
//// Ejecutar trabajo pesado en segundo plano
//var resultado = await Task.Run(() =>
//{
@@ -394,7 +397,7 @@ namespace EFCDesk.Forms
//MessageBox.Show(resultado);
string responseJson = await ConsultarEstadoTareaAsync(taskId);
string responseJson = await ConsultarEstadoTareaAsync(taskId);
await ProcesarRespuestaTareaAsync(responseJson, expediente);

View File

@@ -1902,8 +1902,19 @@ namespace EFCDesk.Forms
private void btn_VisorExpedientes_Click(object sender, EventArgs e)
{
FormExpedientes winExpedientes = new FormExpedientes();
winExpedientes.Show();
var form = Application.OpenForms.OfType<FormExpedientes>().FirstOrDefault();
if (form != null)
{
form.BringToFront();
form.WindowState = FormWindowState.Normal;
}
else
{
FormExpedientes winExpedientes = new FormExpedientes();
winExpedientes.Show();
}
}
}
}