feat: Se implementan logs para auditoria
This commit is contained in:
parent
4b6204d9e7
commit
d455289087
3 changed files with 150 additions and 90 deletions
|
@ -21,107 +21,118 @@ namespace BLL.Recuperacion_DGA
|
|||
|
||||
public async Task<bool> RegistrarMedicionesAsync()
|
||||
{
|
||||
WriteLineAndLog("Iniciando el proceso de recuperación DGA...");
|
||||
WriteLineAndLog("Obteniendo Mediciones Scada", ConsoleColor.Green);
|
||||
var mediciones = await _dGAMedicionScadaRepository.ObtenerMedicionesAsync();
|
||||
|
||||
foreach (var medicion in mediciones)
|
||||
try
|
||||
{
|
||||
try
|
||||
await WriteLineAndLog("INICIO", "Inicio proceso de recuperación DGA", "");
|
||||
WriteLineAndLog("Obteniendo Mediciones Scada", ConsoleColor.Green);
|
||||
var mediciones = await _dGAMedicionScadaRepository.ObtenerMedicionesAsync();
|
||||
foreach (var medicion in mediciones)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(medicion.Code))
|
||||
try
|
||||
{
|
||||
var rutEmpresa = string.Empty;
|
||||
if (medicion.tipo_empresa == null)
|
||||
if (!string.IsNullOrEmpty(medicion.Code))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (medicion.tipo_empresa == "AV")
|
||||
{
|
||||
rutEmpresa = CredencialDGA.RutAv;
|
||||
}
|
||||
if (medicion.tipo_empresa =="EV")
|
||||
{
|
||||
rutEmpresa = CredencialDGA.RutEsval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var body = new MedicionSubterraneaRequest
|
||||
{
|
||||
Autenticacion = new Autenticacion
|
||||
var rutEmpresa = string.Empty;
|
||||
if (medicion.tipo_empresa == null)
|
||||
{
|
||||
Password = CredencialDGA.Password,
|
||||
RutEmpresa = rutEmpresa,
|
||||
RutUsuario = CredencialDGA.RutUsuario
|
||||
},
|
||||
MedicionSubterranea = new Medicion
|
||||
{
|
||||
Caudal = medicion.Caudal.ToString() ?? "",
|
||||
FechaMedicion = medicion.DateOrigen?.ToString("yyyy-MM-dd") ?? "",
|
||||
HoraMedicion = medicion.DateOrigen?.ToString("HH:mm:ss") ?? "",
|
||||
NivelFreaticoDelPozo = medicion.Nivel.ToString() ?? "",
|
||||
Totalizador = medicion.Totalizador.ToString() ?? "",
|
||||
continue;
|
||||
}
|
||||
};
|
||||
await _registrarMedicion.EnviarMedicionAsync(medicion.Code, body, medicion.Id);
|
||||
if (medicion.tipo_empresa == "AV")
|
||||
{
|
||||
rutEmpresa = CredencialDGA.RutAv;
|
||||
}
|
||||
if (medicion.tipo_empresa == "EV")
|
||||
{
|
||||
rutEmpresa = CredencialDGA.RutEsval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var body = new MedicionSubterraneaRequest
|
||||
{
|
||||
Autenticacion = new Autenticacion
|
||||
{
|
||||
Password = CredencialDGA.Password,
|
||||
RutEmpresa = rutEmpresa,
|
||||
RutUsuario = CredencialDGA.RutUsuario
|
||||
},
|
||||
MedicionSubterranea = new Medicion
|
||||
{
|
||||
Caudal = medicion.Caudal.ToString() ?? "",
|
||||
FechaMedicion = medicion.DateOrigen?.ToString("yyyy-MM-dd") ?? "",
|
||||
HoraMedicion = medicion.DateOrigen?.ToString("HH:mm:ss") ?? "",
|
||||
NivelFreaticoDelPozo = medicion.Nivel.ToString() ?? "",
|
||||
Totalizador = medicion.Totalizador.ToString() ?? "",
|
||||
}
|
||||
};
|
||||
//await _registrarMedicion.EnviarMedicionAsync(medicion.Code, body, medicion.Id);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex);
|
||||
WriteLineAndLog($"Error al enviar la medición con ID {medicion.Code}.", ConsoleColor.Red);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
await WriteLineAndLog("FIN","Fin proceso de recuperación DGA","");
|
||||
|
||||
await WriteLineAndLog("INICIO", "Inicio proceso de recuperación DGA los Vilos", "VILOS");
|
||||
WriteLineAndLog("Obteniendo Mediciones Scada los Vilos", ConsoleColor.Green);
|
||||
var medicionesVilos = await _dgaMedicionScadaVilosRepository.ObtenerMedicionesVilosAsync();
|
||||
foreach (var medicionVilos in medicionesVilos)
|
||||
{
|
||||
FileLoggerHelper.LogError($"[Error] {ex.Message}.",ex);
|
||||
WriteLineAndLog($"Error al enviar la medición con ID {medicion.Code}.", ConsoleColor.Red);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(medicionVilos.Code))
|
||||
{
|
||||
var rutEmpresa = string.Empty;
|
||||
|
||||
var medicionesVilos = await _dgaMedicionScadaVilosRepository.ObtenerMedicionesVilosAsync();
|
||||
foreach (var medicionVilos in medicionesVilos)
|
||||
if (medicionVilos.tipo_empresa.Equals("AV"))
|
||||
{
|
||||
rutEmpresa = CredencialDGA.RutAv;
|
||||
}
|
||||
else if (medicionVilos.tipo_empresa.Equals("EV"))
|
||||
{
|
||||
rutEmpresa = CredencialDGA.RutEsval;
|
||||
}
|
||||
|
||||
var body = new MedicionSubterraneaRequest
|
||||
{
|
||||
Autenticacion = new Autenticacion
|
||||
{
|
||||
Password = CredencialDGA.Password,
|
||||
RutEmpresa = rutEmpresa,
|
||||
RutUsuario = CredencialDGA.RutUsuario
|
||||
},
|
||||
MedicionSubterranea = new Medicion
|
||||
{
|
||||
Caudal = medicionVilos.Caudal.ToString() ?? "",
|
||||
FechaMedicion = medicionVilos.DateOrigen?.ToString("yyyy-MM-dd") ?? "",
|
||||
HoraMedicion = medicionVilos.DateOrigen?.ToString("HH:mm:ss") ?? "",
|
||||
NivelFreaticoDelPozo = medicionVilos.Nivel.ToString() ?? "",
|
||||
Totalizador = medicionVilos.Totalizador.ToString() ?? "",
|
||||
}
|
||||
};
|
||||
|
||||
//await _registrarMedicion.EnviarMedicionAsync(medicionVilos.Code, body, medicionVilos.Id);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex);
|
||||
WriteLineAndLog($"Error al enviar la medición vilos con ID {medicionVilos.Code}.", ConsoleColor.Red);
|
||||
}
|
||||
}
|
||||
await WriteLineAndLog("FIN", "Fin proceso de recuperación DGA los Vilos", "VILOS");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(medicionVilos.Code))
|
||||
{
|
||||
var rutEmpresa = string.Empty;
|
||||
|
||||
if (medicionVilos.tipo_empresa.Equals("AV"))
|
||||
{
|
||||
rutEmpresa = CredencialDGA.RutAv;
|
||||
}
|
||||
else if (medicionVilos.tipo_empresa.Equals("EV"))
|
||||
{
|
||||
rutEmpresa = CredencialDGA.RutEsval;
|
||||
}
|
||||
|
||||
var body = new MedicionSubterraneaRequest
|
||||
{
|
||||
Autenticacion = new Autenticacion
|
||||
{
|
||||
Password = CredencialDGA.Password,
|
||||
RutEmpresa = rutEmpresa,
|
||||
RutUsuario = CredencialDGA.RutUsuario
|
||||
},
|
||||
MedicionSubterranea = new Medicion
|
||||
{
|
||||
Caudal = medicionVilos.Caudal.ToString() ?? "",
|
||||
FechaMedicion = medicionVilos.DateOrigen?.ToString("yyyy-MM-dd") ?? "",
|
||||
HoraMedicion = medicionVilos.DateOrigen?.ToString("HH:mm:ss") ?? "",
|
||||
NivelFreaticoDelPozo = medicionVilos.Nivel.ToString() ?? "",
|
||||
Totalizador = medicionVilos.Totalizador.ToString() ?? "",
|
||||
}
|
||||
};
|
||||
|
||||
await _registrarMedicion.EnviarMedicionAsync(medicionVilos.Code, body, medicionVilos.Id);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex);
|
||||
WriteLineAndLog($"Error al enviar la medición vilos con ID {medicionVilos.Code}.", ConsoleColor.Red);
|
||||
}
|
||||
FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex);
|
||||
WriteLineAndLog($"Error al procesar las mediciones.", ConsoleColor.Red);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -140,5 +151,21 @@ namespace BLL.Recuperacion_DGA
|
|||
|
||||
FileLoggerHelper.LogInformation($"{msj}");
|
||||
}
|
||||
|
||||
static async Task WriteLineAndLog(string evento, string proceso, string operacion = null, ConsoleColor? color = null)
|
||||
{
|
||||
if (color.HasValue && Enum.IsDefined(typeof(ConsoleColor), color.Value))
|
||||
{
|
||||
Console.ForegroundColor = (ConsoleColor)color;
|
||||
Console.WriteLine($"{proceso}");
|
||||
Console.ResetColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{proceso}");
|
||||
}
|
||||
FileLoggerHelper.LogInformation($"{proceso}");
|
||||
await FileLoggerHelper.InsertarLogsAsync(evento,proceso,operacion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue