Ajuste de codigo para peticion a url de enpoint de task status
This commit is contained in:
@@ -28,6 +28,8 @@ public class ApiClient : IDisposable
|
|||||||
private string? _currentRefreshToken;
|
private string? _currentRefreshToken;
|
||||||
private readonly object _tokenLock = new object();
|
private readonly object _tokenLock = new object();
|
||||||
|
|
||||||
|
private string DominioEFC = Helpers.DominioExpedienteElectronico();
|
||||||
|
|
||||||
|
|
||||||
public ApiClient(TimeSpan? timeout = null, int maxRetries = 3, TimeSpan? retryDelay = null)
|
public ApiClient(TimeSpan? timeout = null, int maxRetries = 3, TimeSpan? retryDelay = null)
|
||||||
{
|
{
|
||||||
@@ -57,6 +59,10 @@ public class ApiClient : IDisposable
|
|||||||
return @"/api/v1/token/refresh/";
|
return @"/api/v1/token/refresh/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string EndpointStatusTask()
|
||||||
|
{
|
||||||
|
return @"/api/v1/tasks/status/";
|
||||||
|
}
|
||||||
|
|
||||||
private void SetAuthorizationBearer(string token, string refresh_token)
|
private void SetAuthorizationBearer(string token, string refresh_token)
|
||||||
{
|
{
|
||||||
@@ -277,6 +283,13 @@ public class ApiClient : IDisposable
|
|||||||
return await SendWithRetriesAsync(() => new HttpRequestMessage(HttpMethod.Get, url));
|
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)
|
public async Task<string> PostJsonAsync(string url, string jsonContent)
|
||||||
{
|
{
|
||||||
using var content = new StringContent(jsonContent, System.Text.Encoding.UTF8, "application/json");
|
using var content = new StringContent(jsonContent, System.Text.Encoding.UTF8, "application/json");
|
||||||
|
|||||||
@@ -498,7 +498,7 @@ namespace EFCDesk.Classes
|
|||||||
Console.WriteLine($"Error: {ex.Message}");
|
Console.WriteLine($"Error: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void MarcarCarpetaProcesada(string ruta, string estado)
|
public void MarcarCarpetaProcesada(string expediente, string estado)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -510,7 +510,7 @@ namespace EFCDesk.Classes
|
|||||||
|
|
||||||
using (var command = new SQLiteCommand(updateQuery, connection))
|
using (var command = new SQLiteCommand(updateQuery, connection))
|
||||||
{
|
{
|
||||||
command.Parameters.AddWithValue("@r", ruta);
|
command.Parameters.AddWithValue("@r", expediente);
|
||||||
command.Parameters.AddWithValue("@e", estado);
|
command.Parameters.AddWithValue("@e", estado);
|
||||||
command.ExecuteNonQuery();
|
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)
|
public bool EstaArchivoProcesado(string rutaArchivo)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ namespace EFCDesk.Forms
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Columna de acciones
|
// Columna de acciones
|
||||||
//table.Columns.Add("Acciones", typeof(Image));
|
table.Columns.Add("Acciones", typeof(Image));
|
||||||
|
|
||||||
// Crear el icono UNA sola vez
|
// Crear el icono UNA sola vez
|
||||||
Bitmap iconoVer = IconChar.Eye.ToBitmap(
|
Bitmap iconoVer = IconChar.Eye.ToBitmap(
|
||||||
@@ -87,7 +87,7 @@ namespace EFCDesk.Forms
|
|||||||
row["Estatus"] = exp.Estado;
|
row["Estatus"] = exp.Estado;
|
||||||
row["Fecha Registro"] = exp.FechaCreacion;
|
row["Fecha Registro"] = exp.FechaCreacion;
|
||||||
row["TaskId"] = exp.TaskId;
|
row["TaskId"] = exp.TaskId;
|
||||||
//row["Acciones"] = iconoVer;
|
row["Acciones"] = iconoVer;
|
||||||
table.Rows.Add(row);
|
table.Rows.Add(row);
|
||||||
}
|
}
|
||||||
return table;
|
return table;
|
||||||
@@ -115,9 +115,9 @@ namespace EFCDesk.Forms
|
|||||||
dgwExpedientes.Columns["Fecha Registro"].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
|
dgwExpedientes.Columns["Fecha Registro"].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
|
||||||
dgwExpedientes.Columns["Fecha Registro"].Width = 180;
|
dgwExpedientes.Columns["Fecha Registro"].Width = 180;
|
||||||
|
|
||||||
//dgwExpedientes.Columns["Acciones"].Width = 40;
|
dgwExpedientes.Columns["Acciones"].Width = 40;
|
||||||
//dgwExpedientes.Columns["Acciones"].HeaderText = "";
|
dgwExpedientes.Columns["Acciones"].HeaderText = "";
|
||||||
//((DataGridViewImageColumn)dgwExpedientes.Columns["Acciones"]).ImageLayout = DataGridViewImageCellLayout.Zoom;
|
((DataGridViewImageColumn)dgwExpedientes.Columns["Acciones"]).ImageLayout = DataGridViewImageCellLayout.Zoom;
|
||||||
|
|
||||||
_ = Task.Run(() =>
|
_ = Task.Run(() =>
|
||||||
{
|
{
|
||||||
@@ -152,8 +152,8 @@ namespace EFCDesk.Forms
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var apiClient = Globales.ApiClient;
|
var apiClient = Globales.ApiClient;
|
||||||
string url = DominioEFC + $"/api/v1/tasks/status/?task_id={taskId}";
|
//string url = DominioEFC + $"/api/v1/tasks/status/{taskId}/";
|
||||||
return await apiClient.GetAsync(url);
|
return await apiClient.GetStatusTaskAsync(taskId);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -209,7 +209,7 @@ namespace EFCDesk.Forms
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualizar en SQLite
|
// Actualizar en SQLite
|
||||||
_sqliteHelper.MarcarCarpetaProcesada(rutaExpediente, nuevoEstado);
|
_sqliteHelper.ActaulizarStatusCarpeta(rutaExpediente, nuevoEstado);
|
||||||
|
|
||||||
// Mostrar resultado
|
// Mostrar resultado
|
||||||
MessageBox.Show(mensaje, "Estado de Tarea", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show(mensaje, "Estado de Tarea", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
@@ -384,6 +384,9 @@ namespace EFCDesk.Forms
|
|||||||
if (string.IsNullOrEmpty(taskId))
|
if (string.IsNullOrEmpty(taskId))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(expediente))
|
||||||
|
return;
|
||||||
|
|
||||||
//// Ejecutar trabajo pesado en segundo plano
|
//// Ejecutar trabajo pesado en segundo plano
|
||||||
//var resultado = await Task.Run(() =>
|
//var resultado = await Task.Run(() =>
|
||||||
//{
|
//{
|
||||||
@@ -394,7 +397,7 @@ namespace EFCDesk.Forms
|
|||||||
|
|
||||||
//MessageBox.Show(resultado);
|
//MessageBox.Show(resultado);
|
||||||
|
|
||||||
string responseJson = await ConsultarEstadoTareaAsync(taskId);
|
string responseJson = await ConsultarEstadoTareaAsync(taskId);
|
||||||
|
|
||||||
await ProcesarRespuestaTareaAsync(responseJson, expediente);
|
await ProcesarRespuestaTareaAsync(responseJson, expediente);
|
||||||
|
|
||||||
|
|||||||
@@ -1902,8 +1902,19 @@ namespace EFCDesk.Forms
|
|||||||
|
|
||||||
private void btn_VisorExpedientes_Click(object sender, EventArgs e)
|
private void btn_VisorExpedientes_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
FormExpedientes winExpedientes = new FormExpedientes();
|
var form = Application.OpenForms.OfType<FormExpedientes>().FirstOrDefault();
|
||||||
winExpedientes.Show();
|
|
||||||
|
if (form != null)
|
||||||
|
{
|
||||||
|
form.BringToFront();
|
||||||
|
form.WindowState = FormWindowState.Normal;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FormExpedientes winExpedientes = new FormExpedientes();
|
||||||
|
winExpedientes.Show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user