65 lines
2.5 KiB
C#
65 lines
2.5 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Shared.DTO;
|
|
using DAL;
|
|
using DAS;
|
|
|
|
namespace BLL
|
|
{
|
|
public class EnvioDGA
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
private readonly MedicionScadaRepository _dGAMedicionScadaRepository;
|
|
private readonly RegistrarMedicion _registrarMedicion;
|
|
private static string? password;
|
|
private static string? rutEmpresa;
|
|
private static string? rutUsuario;
|
|
|
|
public EnvioDGA(IConfiguration configuration, MedicionScadaRepository dGAMedicionScadaRepository, RegistrarMedicion registrarMedicion)
|
|
{
|
|
_configuration = configuration ?? new ConfigurationBuilder()
|
|
.SetBasePath(AppContext.BaseDirectory)
|
|
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
|
.Build();
|
|
_dGAMedicionScadaRepository = dGAMedicionScadaRepository;
|
|
_registrarMedicion = registrarMedicion;
|
|
rutUsuario = _configuration["Credenciales:rutEmpresa"] ?? "";
|
|
rutEmpresa = _configuration["Credenciales:rutUsuario"] ?? "" ?? "";
|
|
password = _configuration["Credenciales:password"] ?? "";
|
|
}
|
|
|
|
public async Task<List<MedicionScada>> ObtenerMedicionesAsync()
|
|
{
|
|
var mediciones = await _dGAMedicionScadaRepository.ObtenerMedicionesAsync();
|
|
|
|
foreach (var medicion in mediciones)
|
|
{
|
|
if (!string.IsNullOrEmpty(medicion.Code))
|
|
{
|
|
var body = new MedicionSubterraneaRequest
|
|
{
|
|
Autenticacion = new Autenticacion
|
|
{
|
|
Password = password,
|
|
RutEmpresa = rutEmpresa,
|
|
RutUsuario = rutUsuario
|
|
},
|
|
MedicionSubterranea = new Medicion
|
|
{
|
|
Caudal = medicion.Caudal.ToString() ?? "",
|
|
FechaMedicion = medicion.DateOrigen?.ToString("yyyy-MM-dd") ?? "",
|
|
HoraMedicion = medicion.DateOrigen?.ToString("HH:mm:ss") ?? "",
|
|
NivelFreaticoDelPozo = "",
|
|
Totalizador = medicion.Totalizador.ToString() ?? "",
|
|
}
|
|
};
|
|
|
|
await _registrarMedicion.EnviarMedicionAsync(medicion.Code, body);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return mediciones;
|
|
}
|
|
}
|
|
}
|