feat: se agregan logs, y se hacen cambios en el modulo registrar mediciones
This commit is contained in:
parent
5bd9c2a1a6
commit
4b6204d9e7
32 changed files with 648 additions and 625 deletions
|
@ -1,228 +1,221 @@
|
||||||
using Azure;
|
using System.Text.Json;
|
||||||
using DAL;
|
using DAL;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Shared.DTO;
|
|
||||||
using Shared.DTO.Integracion_DGA;
|
using Shared.DTO.Integracion_DGA;
|
||||||
using Shared.DTO.VariablesEntorno;
|
using Shared.DTO.VariablesEntorno;
|
||||||
using Shared.Helper;
|
using Shared.Helper;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BLL.Integracion_DGA
|
namespace BLL.Integracion_DGA
|
||||||
{
|
{
|
||||||
public class BusinessLogic
|
public class BusinessLogic
|
||||||
{
|
|
||||||
private readonly IConfiguration _configuration;
|
|
||||||
private readonly ApiService _apiService;
|
|
||||||
private readonly JobsDgaRepository _jobs;
|
|
||||||
private readonly JobsDgaVilosRepository _jobsVilos;
|
|
||||||
private readonly JobsDgaSupFlujRepository _jobsSupFluj;
|
|
||||||
private readonly FileLoggerHelper _fileLoggerHelper;
|
|
||||||
|
|
||||||
public BusinessLogic(IConfiguration configuration, ApiService apiService, JobsDgaRepository jobs, JobsDgaVilosRepository jobsVilos, JobsDgaSupFlujRepository jobsSupFluj) {
|
|
||||||
_configuration = configuration;
|
|
||||||
_apiService = apiService;
|
|
||||||
_jobs = jobs;
|
|
||||||
_jobsVilos = jobsVilos;
|
|
||||||
_jobsSupFluj = jobsSupFluj;
|
|
||||||
FileLoggerHelper.ConfigureLogger(_configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Run()
|
|
||||||
{
|
{
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
private readonly ApiService _apiService;
|
||||||
|
private readonly JobsDgaRepository _jobs;
|
||||||
|
private readonly JobsDgaVilosRepository _jobsVilos;
|
||||||
|
private readonly JobsDgaSupFlujRepository _jobsSupFluj;
|
||||||
|
private readonly FileLoggerHelper _fileLoggerHelper;
|
||||||
|
|
||||||
DateTimeOffset dateEnd = DateTimeOffset.Now;
|
public BusinessLogic(IConfiguration configuration, ApiService apiService, JobsDgaRepository jobs, JobsDgaVilosRepository jobsVilos, JobsDgaSupFlujRepository jobsSupFluj)
|
||||||
DateTimeOffset dateStart = dateEnd.AddHours(-1);
|
{
|
||||||
|
_configuration = configuration;
|
||||||
|
_apiService = apiService;
|
||||||
|
_jobs = jobs;
|
||||||
|
_jobsVilos = jobsVilos;
|
||||||
|
_jobsSupFluj = jobsSupFluj;
|
||||||
|
FileLoggerHelper.ConfigureLogger(_configuration);
|
||||||
|
}
|
||||||
|
|
||||||
JsonSerializerOptions options = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true };
|
public async Task Run()
|
||||||
|
{
|
||||||
|
|
||||||
//FileLoggerHelper.ConfigureLogger(_configuration);
|
DateTimeOffset dateEnd = DateTimeOffset.Now;
|
||||||
WriteLineAndLog($"Inicia Proceso DGA");
|
DateTimeOffset dateStart = dateEnd.AddHours(-1);
|
||||||
try
|
|
||||||
{
|
JsonSerializerOptions options = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true };
|
||||||
string apiUrlBase = NexusApiUrl.ApiUrl;
|
|
||||||
Dictionary<string, string> headers = new Dictionary<string, string>
|
//FileLoggerHelper.ConfigureLogger(_configuration);
|
||||||
|
WriteLineAndLog($"Inicia Proceso DGA");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string apiUrlBase = NexusApiUrl.ApiUrl;
|
||||||
|
Dictionary<string, string> headers = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "nexustoken", NexusApiUrl.ApiKey },
|
{ "nexustoken", NexusApiUrl.ApiKey },
|
||||||
{ "nexusapiversion", NexusApiUrl.Version },
|
{ "nexusapiversion", NexusApiUrl.Version },
|
||||||
{ "accept", "application/json" }
|
{ "accept", "application/json" }
|
||||||
};
|
};
|
||||||
|
|
||||||
WriteLineAndLog($"Obteniendo Documentos");
|
WriteLineAndLog($"Obteniendo Documentos");
|
||||||
string apiUrlDocuments = apiUrlBase + "/api/Documents";
|
string apiUrlDocuments = apiUrlBase + "/api/Documents";
|
||||||
|
|
||||||
// Utiliza el servicio para realizar la solicitud a la API con URL y encabezados personalizados
|
// Utiliza el servicio para realizar la solicitud a la API con URL y encabezados personalizados
|
||||||
string responseData = await _apiService.GetApiResponseAsync(apiUrlDocuments, headers);
|
string responseData = await _apiService.GetApiResponseAsync(apiUrlDocuments, headers);
|
||||||
|
|
||||||
var documento = JsonSerializer.Deserialize<List<DocumentResponse>>(responseData, options);
|
var documento = JsonSerializer.Deserialize<List<DocumentResponse>>(responseData, options);
|
||||||
foreach (DocumentResponse item in documento)
|
foreach (DocumentResponse item in documento)
|
||||||
{
|
{
|
||||||
WriteLineAndLog($"Obteniendo Tagviews");
|
WriteLineAndLog($"Obteniendo Tagviews");
|
||||||
string apiUrlTagViews = $"{apiUrlBase}/api/Documents/tagviews/{item.uid}";
|
string apiUrlTagViews = $"{apiUrlBase}/api/Documents/tagviews/{item.uid}";
|
||||||
responseData = await _apiService.GetApiResponseAsync(apiUrlTagViews, headers);
|
responseData = await _apiService.GetApiResponseAsync(apiUrlTagViews, headers);
|
||||||
TagviewsResponse tagviews = JsonSerializer.Deserialize<TagviewsResponse>(responseData, options);
|
TagviewsResponse tagviews = JsonSerializer.Deserialize<TagviewsResponse>(responseData, options);
|
||||||
|
|
||||||
List<string> listTagsID = new List<string>();
|
List<string> listTagsID = new List<string>();
|
||||||
foreach (Column tag in tagviews.Columns)
|
foreach (Column tag in tagviews.Columns)
|
||||||
{
|
{
|
||||||
listTagsID.Add(tag.Uid);
|
listTagsID.Add(tag.Uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoricRequest historicRequest = new HistoricRequest();
|
HistoricRequest historicRequest = new HistoricRequest();
|
||||||
historicRequest.DataSource = NexusApiUrl.DataSource;
|
historicRequest.DataSource = NexusApiUrl.DataSource;
|
||||||
historicRequest.Resolution = NexusApiUrl.Resolution;
|
historicRequest.Resolution = NexusApiUrl.Resolution;
|
||||||
historicRequest.Uids = listTagsID;
|
historicRequest.Uids = listTagsID;
|
||||||
historicRequest.StartTs = dateStart.ToUnixTimeSeconds();
|
historicRequest.StartTs = dateStart.ToUnixTimeSeconds();
|
||||||
historicRequest.EndTs = dateEnd.ToUnixTimeSeconds();
|
historicRequest.EndTs = dateEnd.ToUnixTimeSeconds();
|
||||||
|
|
||||||
WriteLineAndLog($"Obteniendo Tagviews Historic");
|
WriteLineAndLog($"Obteniendo Tagviews Historic");
|
||||||
string apiUrlHistoric = $"{apiUrlBase}/api/Documents/tagviews/{item.uid}/historic";
|
string apiUrlHistoric = $"{apiUrlBase}/api/Documents/tagviews/{item.uid}/historic";
|
||||||
responseData = await _apiService.PostApiResponseAsync(apiUrlHistoric, headers, historicRequest);
|
responseData = await _apiService.PostApiResponseAsync(apiUrlHistoric, headers, historicRequest);
|
||||||
List<HistoricResponse> historicResponse = JsonSerializer.Deserialize<List<HistoricResponse>>(responseData, options);
|
List<HistoricResponse> historicResponse = JsonSerializer.Deserialize<List<HistoricResponse>>(responseData, options);
|
||||||
|
|
||||||
List<DgaMacroResultado> listDgaMacroResultados = new List<DgaMacroResultado>();
|
List<DgaMacroResultado> listDgaMacroResultados = new List<DgaMacroResultado>();
|
||||||
foreach (Column tag in tagviews.Columns)
|
foreach (Column tag in tagviews.Columns)
|
||||||
{
|
{
|
||||||
IEnumerable<HistoricResponse> filter = historicResponse.Where(h => h.Uid == tag.Uid);
|
IEnumerable<HistoricResponse> filter = historicResponse.Where(h => h.Uid == tag.Uid);
|
||||||
foreach (HistoricResponse historic in filter)
|
foreach (HistoricResponse historic in filter)
|
||||||
{
|
{
|
||||||
TimeZoneInfo zonaHorariaChile = TimeZoneInfo.FindSystemTimeZoneById("Pacific SA Standard Time");
|
TimeZoneInfo zonaHorariaChile = TimeZoneInfo.FindSystemTimeZoneById("Pacific SA Standard Time");
|
||||||
DateTime now = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(historic.TimeStamp);
|
DateTime now = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(historic.TimeStamp);
|
||||||
DateTime fechaHoraChile = TimeZoneInfo.ConvertTimeFromUtc(now, zonaHorariaChile);
|
DateTime fechaHoraChile = TimeZoneInfo.ConvertTimeFromUtc(now, zonaHorariaChile);
|
||||||
|
|
||||||
|
|
||||||
DgaMacroResultado dgaMacroResultado = new DgaMacroResultado();
|
DgaMacroResultado dgaMacroResultado = new DgaMacroResultado();
|
||||||
dgaMacroResultado.TagName = $"SCADA001.{tag.Name}.F_CV";
|
dgaMacroResultado.TagName = $"SCADA001.{tag.Name}.F_CV";
|
||||||
dgaMacroResultado.Value = historic.Value;
|
dgaMacroResultado.Value = historic.Value;
|
||||||
//dgaMacroResultado.TimeStamp = new DateTime(historic.TimeStamp);
|
//dgaMacroResultado.TimeStamp = new DateTime(historic.TimeStamp);
|
||||||
dgaMacroResultado.TimeStamp = fechaHoraChile;
|
dgaMacroResultado.TimeStamp = fechaHoraChile;
|
||||||
|
|
||||||
listDgaMacroResultados.Add(dgaMacroResultado);
|
listDgaMacroResultados.Add(dgaMacroResultado);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************/
|
||||||
|
WriteLineAndLog($"Inicia Envio DGA", ConsoleColor.Green);
|
||||||
|
WriteLineAndLog($"\t Descargar datos historian: Insertar DgaMacroResultado");
|
||||||
|
var resultMacro = await _jobs.InsertarDgaMacroResultado(listDgaMacroResultados);
|
||||||
|
|
||||||
|
WriteLineAndLog($"\t Descargar datos historian: Insertar DgaSensorResultado");
|
||||||
|
List<DgaSensorResultado> listDgaSensorResultado = listDgaMacroResultados.Select(item => new DgaSensorResultado
|
||||||
|
{
|
||||||
|
TagName = item.TagName,
|
||||||
|
TimeStamp = item.TimeStamp,
|
||||||
|
Value = item.Value,
|
||||||
|
Quality = item.Quality
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
var resultSensor = await _jobs.InsertarDgaSensorResultado(listDgaSensorResultado);
|
||||||
|
|
||||||
|
WriteLineAndLog($"\t Calculo DGA");
|
||||||
|
var resultCalculo = await _jobs.SpCalculoDga();
|
||||||
|
|
||||||
|
WriteLineAndLog($"\t descargar datos suma reversibilidad : Insertar DgaMacroResultadoSupFlujSuma");
|
||||||
|
List<DgaMacroResultadoSupFlujSuma> listDgaMacroResultadoSupFlujSuma = listDgaMacroResultados.Select(item => new DgaMacroResultadoSupFlujSuma
|
||||||
|
{
|
||||||
|
TagName = item.TagName,
|
||||||
|
TimeStamp = item.TimeStamp,
|
||||||
|
Value = item.Value,
|
||||||
|
Quality = item.Quality
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
var resultSupFlujSuma = await _jobs.InsertarDgaMacroResultadoSupFlujSuma(listDgaMacroResultadoSupFlujSuma);
|
||||||
|
|
||||||
|
WriteLineAndLog($"\t Calculo Suma");
|
||||||
|
var resultCalculoDgaSup = await _jobs.SpCalculoDgaSupFlujSumaSnreversibilidad();
|
||||||
|
|
||||||
|
|
||||||
|
WriteLineAndLog($"\t Traspaso datos achird");
|
||||||
|
var result = await _jobs.SpTraspasoDatosAchird();
|
||||||
|
WriteLineAndLog($"Fin Envio DGA", ConsoleColor.Green);
|
||||||
|
/**************/
|
||||||
|
/**************/
|
||||||
|
WriteLineAndLog($"Inicio Envio DGA Vilos", ConsoleColor.Green);
|
||||||
|
WriteLineAndLog($"\t Descargar datos historian: Insertar InsertarDgaMacroResultadoVilos");
|
||||||
|
List<DgaMacroResultadoVilos> listDgaMacroResultadoVilos = listDgaMacroResultados.Select(item => new DgaMacroResultadoVilos
|
||||||
|
{
|
||||||
|
TagName = item.TagName,
|
||||||
|
TimeStamp = item.TimeStamp,
|
||||||
|
Value = item.Value,
|
||||||
|
Quality = item.Quality
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
var resultVilos = await _jobsVilos.InsertarDgaMacroResultadoVilos(listDgaMacroResultadoVilos);
|
||||||
|
|
||||||
|
WriteLineAndLog($"\t Descargar datos historian: Insertar InsertarDgaSensorResultadoVilos");
|
||||||
|
List<DgaSensorResultadoVilos> listDgaSensorResultadoVilos = listDgaMacroResultados.Select(item => new DgaSensorResultadoVilos
|
||||||
|
{
|
||||||
|
TagName = item.TagName,
|
||||||
|
TimeStamp = item.TimeStamp,
|
||||||
|
Value = item.Value,
|
||||||
|
Quality = item.Quality
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
var resultSensorVilos = await _jobsVilos.InsertarDgaSensorResultadoVilos(listDgaSensorResultadoVilos);
|
||||||
|
|
||||||
|
WriteLineAndLog($"\t Calculo Suma");
|
||||||
|
var resultCalculoVilos = await _jobsVilos.SpCalculoDgaVilos();
|
||||||
|
|
||||||
|
|
||||||
|
WriteLineAndLog($"\t Traspaso datos achird");
|
||||||
|
var resultAchirdVilos = await _jobsVilos.SpTraspasoDatosAchirdVilos();
|
||||||
|
WriteLineAndLog($"Fin Envio DGA Vilos", ConsoleColor.Green);
|
||||||
|
/**************/
|
||||||
|
/**************/
|
||||||
|
WriteLineAndLog($"Inicio Envio DGA Sup Fluj", ConsoleColor.Green);
|
||||||
|
WriteLineAndLog($"\t Descargar datos historian: Insertar InsertarDgaMacroResultadoSupFluj");
|
||||||
|
List<DgaMacroResultadoSupFluj> listDgaMacroResultadoSupFluj = listDgaMacroResultados.Select(item => new DgaMacroResultadoSupFluj
|
||||||
|
{
|
||||||
|
TagName = item.TagName,
|
||||||
|
TimeStamp = item.TimeStamp,
|
||||||
|
Value = item.Value,
|
||||||
|
Quality = item.Quality
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
var resultSensorSup = await _jobsSupFluj.InsertarDgaMacroResultadoSupFluj(listDgaMacroResultadoSupFluj);
|
||||||
|
|
||||||
|
WriteLineAndLog($"\t Calculo Suma");
|
||||||
|
var resultCalculoSup = await _jobsSupFluj.SpCalculoDgaSupFluj();
|
||||||
|
|
||||||
|
|
||||||
|
WriteLineAndLog($"\t Traspaso datos achird");
|
||||||
|
var resultAchirdSup = await _jobsSupFluj.SpTraspasoDatosAchirdSupFluj();
|
||||||
|
WriteLineAndLog($"Fin Envio DGA Sup Fluj", ConsoleColor.Green);
|
||||||
|
/**************/
|
||||||
|
/**************/
|
||||||
|
}
|
||||||
|
WriteLineAndLog($"FIN Proceso DGA");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
FileLoggerHelper.LogError($"{ex.Message}", ex);
|
||||||
|
WriteLineAndLog($"{ex.Message}", ConsoleColor.Red);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**************/
|
|
||||||
WriteLineAndLog($"Inicia Envio DGA", ConsoleColor.Green);
|
|
||||||
WriteLineAndLog($"\t Descargar datos historian: Insertar DgaMacroResultado");
|
|
||||||
var resultMacro = await _jobs.InsertarDgaMacroResultado(listDgaMacroResultados);
|
|
||||||
|
|
||||||
WriteLineAndLog($"\t Descargar datos historian: Insertar DgaSensorResultado");
|
|
||||||
List<DgaSensorResultado> listDgaSensorResultado = listDgaMacroResultados.Select(item => new DgaSensorResultado
|
|
||||||
{
|
|
||||||
TagName = item.TagName,
|
|
||||||
TimeStamp = item.TimeStamp,
|
|
||||||
Value = item.Value,
|
|
||||||
Quality = item.Quality
|
|
||||||
}).ToList();
|
|
||||||
|
|
||||||
var resultSensor = await _jobs.InsertarDgaSensorResultado(listDgaSensorResultado);
|
|
||||||
|
|
||||||
WriteLineAndLog($"\t Calculo DGA");
|
|
||||||
var resultCalculo = await _jobs.SpCalculoDga();
|
|
||||||
|
|
||||||
WriteLineAndLog($"\t descargar datos suma reversibilidad : Insertar DgaMacroResultadoSupFlujSuma");
|
|
||||||
List<DgaMacroResultadoSupFlujSuma> listDgaMacroResultadoSupFlujSuma = listDgaMacroResultados.Select(item => new DgaMacroResultadoSupFlujSuma
|
|
||||||
{
|
|
||||||
TagName = item.TagName,
|
|
||||||
TimeStamp = item.TimeStamp,
|
|
||||||
Value = item.Value,
|
|
||||||
Quality = item.Quality
|
|
||||||
}).ToList();
|
|
||||||
|
|
||||||
var resultSupFlujSuma = await _jobs.InsertarDgaMacroResultadoSupFlujSuma(listDgaMacroResultadoSupFlujSuma);
|
|
||||||
|
|
||||||
WriteLineAndLog($"\t Calculo Suma");
|
|
||||||
var resultCalculoDgaSup = await _jobs.SpCalculoDgaSupFlujSumaSnreversibilidad();
|
|
||||||
|
|
||||||
|
|
||||||
WriteLineAndLog($"\t Traspaso datos achird");
|
|
||||||
var result = await _jobs.SpTraspasoDatosAchird();
|
|
||||||
WriteLineAndLog($"Fin Envio DGA", ConsoleColor.Green);
|
|
||||||
/**************/
|
|
||||||
/**************/
|
|
||||||
WriteLineAndLog($"Inicio Envio DGA Vilos", ConsoleColor.Green);
|
|
||||||
WriteLineAndLog($"\t Descargar datos historian: Insertar InsertarDgaMacroResultadoVilos");
|
|
||||||
List<DgaMacroResultadoVilos> listDgaMacroResultadoVilos = listDgaMacroResultados.Select(item => new DgaMacroResultadoVilos
|
|
||||||
{
|
|
||||||
TagName = item.TagName,
|
|
||||||
TimeStamp = item.TimeStamp,
|
|
||||||
Value = item.Value,
|
|
||||||
Quality = item.Quality
|
|
||||||
}).ToList();
|
|
||||||
|
|
||||||
var resultVilos = await _jobsVilos.InsertarDgaMacroResultadoVilos(listDgaMacroResultadoVilos);
|
|
||||||
|
|
||||||
WriteLineAndLog($"\t Descargar datos historian: Insertar InsertarDgaSensorResultadoVilos");
|
|
||||||
List<DgaSensorResultadoVilos> listDgaSensorResultadoVilos = listDgaMacroResultados.Select(item => new DgaSensorResultadoVilos
|
|
||||||
{
|
|
||||||
TagName = item.TagName,
|
|
||||||
TimeStamp = item.TimeStamp,
|
|
||||||
Value = item.Value,
|
|
||||||
Quality = item.Quality
|
|
||||||
}).ToList();
|
|
||||||
|
|
||||||
var resultSensorVilos = await _jobsVilos.InsertarDgaSensorResultadoVilos(listDgaSensorResultadoVilos);
|
|
||||||
|
|
||||||
WriteLineAndLog($"\t Calculo Suma");
|
|
||||||
var resultCalculoVilos = await _jobsVilos.SpCalculoDgaVilos();
|
|
||||||
|
|
||||||
|
|
||||||
WriteLineAndLog($"\t Traspaso datos achird");
|
|
||||||
var resultAchirdVilos = await _jobsVilos.SpTraspasoDatosAchirdVilos();
|
|
||||||
WriteLineAndLog($"Fin Envio DGA Vilos", ConsoleColor.Green);
|
|
||||||
/**************/
|
|
||||||
/**************/
|
|
||||||
WriteLineAndLog($"Inicio Envio DGA Sup Fluj", ConsoleColor.Green);
|
|
||||||
WriteLineAndLog($"\t Descargar datos historian: Insertar InsertarDgaMacroResultadoSupFluj");
|
|
||||||
List<DgaMacroResultadoSupFluj> listDgaMacroResultadoSupFluj = listDgaMacroResultados.Select(item => new DgaMacroResultadoSupFluj
|
|
||||||
{
|
|
||||||
TagName = item.TagName,
|
|
||||||
TimeStamp = item.TimeStamp,
|
|
||||||
Value = item.Value,
|
|
||||||
Quality = item.Quality
|
|
||||||
}).ToList();
|
|
||||||
|
|
||||||
var resultSensorSup = await _jobsSupFluj.InsertarDgaMacroResultadoSupFluj(listDgaMacroResultadoSupFluj);
|
|
||||||
|
|
||||||
WriteLineAndLog($"\t Calculo Suma");
|
|
||||||
var resultCalculoSup = await _jobsSupFluj.SpCalculoDgaSupFluj();
|
|
||||||
|
|
||||||
|
|
||||||
WriteLineAndLog($"\t Traspaso datos achird");
|
|
||||||
var resultAchirdSup = await _jobsSupFluj.SpTraspasoDatosAchirdSupFluj();
|
|
||||||
WriteLineAndLog($"Fin Envio DGA Sup Fluj", ConsoleColor.Green);
|
|
||||||
/**************/
|
|
||||||
/**************/
|
|
||||||
}
|
}
|
||||||
WriteLineAndLog($"FIN Proceso DGA");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
FileLoggerHelper.LogError($"{ex.Message}", ex);
|
|
||||||
WriteLineAndLog($"{ex.Message}", ConsoleColor.Red);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
static void WriteLineAndLog(string msj, ConsoleColor? color = null)
|
||||||
|
{
|
||||||
|
if (color.HasValue && Enum.IsDefined(typeof(ConsoleColor), color.Value))
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = (ConsoleColor)color;
|
||||||
|
Console.WriteLine(msj);
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{msj}");
|
||||||
|
}
|
||||||
|
|
||||||
static void WriteLineAndLog(string msj, ConsoleColor? color = null)
|
FileLoggerHelper.LogInformation($"{msj}");
|
||||||
{
|
}
|
||||||
if (color.HasValue && Enum.IsDefined(typeof(ConsoleColor), color.Value))
|
|
||||||
{
|
|
||||||
Console.ForegroundColor = (ConsoleColor)color;
|
|
||||||
Console.WriteLine(msj);
|
|
||||||
Console.ResetColor();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine($"{msj}");
|
|
||||||
}
|
|
||||||
|
|
||||||
FileLoggerHelper.LogInformation($"{msj}");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,28 @@
|
||||||
using Microsoft.Extensions.Configuration;
|
using DAL;
|
||||||
using Shared.DTO;
|
|
||||||
using DAL;
|
|
||||||
using DAS;
|
using DAS;
|
||||||
using Shared.DTO.Envios_DGA;
|
using Shared.DTO.Envios_DGA;
|
||||||
|
using Shared.DTO.VariablesEntorno;
|
||||||
|
using Shared.Helper;
|
||||||
|
|
||||||
namespace BLL.Recuperacion_DGA
|
namespace BLL.Recuperacion_DGA
|
||||||
{
|
{
|
||||||
public class EnvioDGA
|
public class EnvioDGA
|
||||||
{
|
{
|
||||||
private readonly MedicionScadaRepository _dGAMedicionScadaRepository;
|
private readonly MedicionScadaRepository _dGAMedicionScadaRepository;
|
||||||
|
private readonly MedicionScadaVilosRepository _dgaMedicionScadaVilosRepository;
|
||||||
private readonly RegistrarMedicion _registrarMedicion;
|
private readonly RegistrarMedicion _registrarMedicion;
|
||||||
|
|
||||||
public EnvioDGA(MedicionScadaRepository dGAMedicionScadaRepository, RegistrarMedicion registrarMedicion)
|
public EnvioDGA(MedicionScadaRepository dGAMedicionScadaRepository, RegistrarMedicion registrarMedicion, MedicionScadaVilosRepository dgaMedicionScadaVilosRepository)
|
||||||
{
|
{
|
||||||
_dGAMedicionScadaRepository = dGAMedicionScadaRepository;
|
_dGAMedicionScadaRepository = dGAMedicionScadaRepository;
|
||||||
_registrarMedicion = registrarMedicion;
|
_registrarMedicion = registrarMedicion;
|
||||||
|
_dgaMedicionScadaVilosRepository = dgaMedicionScadaVilosRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool>RegistrarMedicionesAsync()
|
public async Task<bool> RegistrarMedicionesAsync()
|
||||||
{
|
{
|
||||||
|
WriteLineAndLog("Iniciando el proceso de recuperación DGA...");
|
||||||
|
WriteLineAndLog("Obteniendo Mediciones Scada", ConsoleColor.Green);
|
||||||
var mediciones = await _dGAMedicionScadaRepository.ObtenerMedicionesAsync();
|
var mediciones = await _dGAMedicionScadaRepository.ObtenerMedicionesAsync();
|
||||||
|
|
||||||
foreach (var medicion in mediciones)
|
foreach (var medicion in mediciones)
|
||||||
|
@ -27,38 +31,114 @@ namespace BLL.Recuperacion_DGA
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(medicion.Code))
|
if (!string.IsNullOrEmpty(medicion.Code))
|
||||||
{
|
{
|
||||||
|
var rutEmpresa = string.Empty;
|
||||||
|
if (medicion.tipo_empresa == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (medicion.tipo_empresa == "AV")
|
||||||
|
{
|
||||||
|
rutEmpresa = CredencialDGA.RutAv;
|
||||||
|
}
|
||||||
|
if (medicion.tipo_empresa =="EV")
|
||||||
|
{
|
||||||
|
rutEmpresa = CredencialDGA.RutEsval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var body = new MedicionSubterraneaRequest
|
var body = new MedicionSubterraneaRequest
|
||||||
{
|
{
|
||||||
Autenticacion = new Autenticacion
|
Autenticacion = new Autenticacion
|
||||||
{
|
{
|
||||||
Password = string.Empty,
|
Password = CredencialDGA.Password,
|
||||||
RutEmpresa = string.Empty,
|
RutEmpresa = rutEmpresa,
|
||||||
RutUsuario = string.Empty
|
RutUsuario = CredencialDGA.RutUsuario
|
||||||
},
|
},
|
||||||
MedicionSubterranea = new Medicion
|
MedicionSubterranea = new Medicion
|
||||||
{
|
{
|
||||||
Caudal = medicion.Caudal.ToString() ?? "",
|
Caudal = medicion.Caudal.ToString() ?? "",
|
||||||
FechaMedicion = medicion.DateOrigen?.ToString("yyyy-MM-dd") ?? "",
|
FechaMedicion = medicion.DateOrigen?.ToString("yyyy-MM-dd") ?? "",
|
||||||
HoraMedicion = medicion.DateOrigen?.ToString("HH:mm:ss") ?? "",
|
HoraMedicion = medicion.DateOrigen?.ToString("HH:mm:ss") ?? "",
|
||||||
NivelFreaticoDelPozo = "",
|
NivelFreaticoDelPozo = medicion.Nivel.ToString() ?? "",
|
||||||
Totalizador = medicion.Totalizador.ToString() ?? "",
|
Totalizador = medicion.Totalizador.ToString() ?? "",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
await _registrarMedicion.EnviarMedicionAsync(medicion.Code, body, medicion.Id);
|
||||||
//TODO: Agregar log texto
|
|
||||||
|
|
||||||
await _registrarMedicion.EnviarMedicionAsync(medicion.Code, body,medicion.Id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
//TODO: Agregar log texto
|
FileLoggerHelper.LogError($"[Error] {ex.Message}.",ex);
|
||||||
throw;
|
WriteLineAndLog($"Error al enviar la medición con ID {medicion.Code}.", ConsoleColor.Red);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var medicionesVilos = await _dgaMedicionScadaVilosRepository.ObtenerMedicionesVilosAsync();
|
||||||
|
foreach (var medicionVilos in medicionesVilos)
|
||||||
|
{
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void WriteLineAndLog(string msj, ConsoleColor? color = null)
|
||||||
|
{
|
||||||
|
if (color.HasValue && Enum.IsDefined(typeof(ConsoleColor), color.Value))
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = (ConsoleColor)color;
|
||||||
|
Console.WriteLine(msj);
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{msj}");
|
||||||
|
}
|
||||||
|
|
||||||
|
FileLoggerHelper.LogInformation($"{msj}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,58 +1,54 @@
|
||||||
using System;
|
using System.Security.Cryptography;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DAL
|
namespace DAL
|
||||||
{
|
{
|
||||||
public static class Encriptador
|
public static class Encriptador
|
||||||
{
|
|
||||||
private static readonly byte[] key = Encoding.ASCII.GetBytes("1234567891234567");
|
|
||||||
private static readonly byte[] iv = Encoding.ASCII.GetBytes("Devjoker7.37hAES");
|
|
||||||
|
|
||||||
public static string Encripta(string Cadena)
|
|
||||||
{
|
{
|
||||||
|
private static readonly byte[] key = Encoding.ASCII.GetBytes("1234567891234567");
|
||||||
|
private static readonly byte[] iv = Encoding.ASCII.GetBytes("Devjoker7.37hAES");
|
||||||
|
|
||||||
using Aes aesAlg = Aes.Create();
|
public static string Encripta(string Cadena)
|
||||||
aesAlg.Key = key;
|
|
||||||
aesAlg.IV = iv;
|
|
||||||
|
|
||||||
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
|
|
||||||
|
|
||||||
using (MemoryStream msEncrypt = new MemoryStream())
|
|
||||||
{
|
|
||||||
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
|
|
||||||
{
|
{
|
||||||
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
|
|
||||||
{
|
using Aes aesAlg = Aes.Create();
|
||||||
swEncrypt.Write(Cadena);
|
aesAlg.Key = key;
|
||||||
}
|
aesAlg.IV = iv;
|
||||||
|
|
||||||
|
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
|
||||||
|
|
||||||
|
using (MemoryStream msEncrypt = new MemoryStream())
|
||||||
|
{
|
||||||
|
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
|
||||||
|
{
|
||||||
|
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
|
||||||
|
{
|
||||||
|
swEncrypt.Write(Cadena);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Convert.ToBase64String(msEncrypt.ToArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Convert.ToBase64String(msEncrypt.ToArray());
|
public static string Desencripta(string Cadena)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string Desencripta(string Cadena)
|
|
||||||
{
|
|
||||||
using Aes aesAlg = Aes.Create();
|
|
||||||
aesAlg.Key = key;
|
|
||||||
aesAlg.IV = iv;
|
|
||||||
|
|
||||||
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
|
|
||||||
|
|
||||||
using (MemoryStream msDecrypt = new MemoryStream(Convert.FromBase64String(Cadena)))
|
|
||||||
{
|
|
||||||
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
|
|
||||||
{
|
{
|
||||||
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
|
using Aes aesAlg = Aes.Create();
|
||||||
{
|
aesAlg.Key = key;
|
||||||
return srDecrypt.ReadToEnd();
|
aesAlg.IV = iv;
|
||||||
}
|
|
||||||
|
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
|
||||||
|
|
||||||
|
using (MemoryStream msDecrypt = new MemoryStream(Convert.FromBase64String(Cadena)))
|
||||||
|
{
|
||||||
|
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
|
||||||
|
{
|
||||||
|
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
|
||||||
|
{
|
||||||
|
return srDecrypt.ReadToEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
using Microsoft.Data.SqlClient;
|
using System.Data;
|
||||||
using Microsoft.Win32;
|
|
||||||
using Shared.DTO.Integracion_DGA;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Data;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Dapper;
|
using Dapper;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Data.SqlClient;
|
||||||
|
using Shared.DTO.Integracion_DGA;
|
||||||
using Shared.DTO.VariablesEntorno;
|
using Shared.DTO.VariablesEntorno;
|
||||||
|
|
||||||
namespace DAL
|
namespace DAL
|
||||||
{
|
{
|
||||||
public class JobsDgaRepository
|
public class JobsDgaRepository
|
||||||
{
|
{
|
||||||
public async Task<bool> InsertarDgaMacroResultado(List<DgaMacroResultado> dgaMacroResultados)
|
public async Task<bool> InsertarDgaMacroResultado(List<DgaMacroResultado> dgaMacroResultados)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -66,29 +59,30 @@ namespace DAL
|
||||||
|
|
||||||
public async Task<bool> InsertarDgaMacroResultadoSupFlujSuma(List<DgaMacroResultadoSupFlujSuma> dgaMacroResultadoSupFlujSuma)
|
public async Task<bool> InsertarDgaMacroResultadoSupFlujSuma(List<DgaMacroResultadoSupFlujSuma> dgaMacroResultadoSupFlujSuma)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
|
||||||
// Configurar la conexión a la base de datos
|
|
||||||
using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection))
|
|
||||||
{
|
{
|
||||||
await connection.OpenAsync();
|
// Configurar la conexión a la base de datos
|
||||||
// Truncar la tabla antes de insertar
|
using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection))
|
||||||
await connection.ExecuteAsync("TRUNCATE TABLE DGA_MACRO_RESULTADO_SUP_FLUJ_SUMA");
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
// Truncar la tabla antes de insertar
|
||||||
|
await connection.ExecuteAsync("TRUNCATE TABLE DGA_MACRO_RESULTADO_SUP_FLUJ_SUMA");
|
||||||
|
|
||||||
// Crear un adaptador de datos
|
// Crear un adaptador de datos
|
||||||
SqlDataAdapter adapter = new SqlDataAdapter();
|
SqlDataAdapter adapter = new SqlDataAdapter();
|
||||||
|
|
||||||
// Configurar el comando de inserción
|
// Configurar el comando de inserción
|
||||||
string sql = "INSERT INTO DGA_MACRO_RESULTADO_SUP_FLUJ_SUMA (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)";
|
string sql = "INSERT INTO DGA_MACRO_RESULTADO_SUP_FLUJ_SUMA (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)";
|
||||||
await connection.ExecuteAsync(sql, dgaMacroResultadoSupFlujSuma);
|
await connection.ExecuteAsync(sql, dgaMacroResultadoSupFlujSuma);
|
||||||
|
|
||||||
return true; // Éxito
|
return true; // Éxito
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new Exception($"Error: {ex.Message}");
|
throw new Exception($"Error: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> SpCalculoDga()
|
public async Task<bool> SpCalculoDga()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,80 +1,74 @@
|
||||||
using Dapper;
|
using System.Data;
|
||||||
|
using Dapper;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Shared.DTO.Integracion_DGA;
|
using Shared.DTO.Integracion_DGA;
|
||||||
using Shared.DTO.VariablesEntorno;
|
using Shared.DTO.VariablesEntorno;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Data;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DAL
|
namespace DAL
|
||||||
{
|
{
|
||||||
public class JobsDgaSupFlujRepository
|
public class JobsDgaSupFlujRepository
|
||||||
{
|
|
||||||
public async Task<bool> InsertarDgaMacroResultadoSupFluj(List<DgaMacroResultadoSupFluj> dgaMacroResultadoSupFluj)
|
|
||||||
{
|
{
|
||||||
try
|
public async Task<bool> InsertarDgaMacroResultadoSupFluj(List<DgaMacroResultadoSupFluj> dgaMacroResultadoSupFluj)
|
||||||
{
|
|
||||||
// Configurar la conexión a la base de datos
|
|
||||||
using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection))
|
|
||||||
{
|
{
|
||||||
await connection.OpenAsync();
|
try
|
||||||
await connection.ExecuteAsync("TRUNCATE TABLE DGA_MACRO_RESULTADO_SUP_FLUJ");
|
|
||||||
|
|
||||||
await SpCalculoDgaSupFluj();
|
|
||||||
|
|
||||||
string sql = "INSERT INTO DGA_MACRO_RESULTADO_SUP_FLUJ (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)";
|
|
||||||
await connection.ExecuteAsync(sql, dgaMacroResultadoSupFluj);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new Exception($"Error: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> SpCalculoDgaSupFluj()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
|
||||||
{
|
{
|
||||||
await connection.OpenAsync();
|
// Configurar la conexión a la base de datos
|
||||||
await connection.ExecuteAsync(
|
using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection))
|
||||||
"SP_CALCULO_DGA_SUP_FLUJ",
|
{
|
||||||
commandType: CommandType.StoredProcedure
|
await connection.OpenAsync();
|
||||||
);
|
await connection.ExecuteAsync("TRUNCATE TABLE DGA_MACRO_RESULTADO_SUP_FLUJ");
|
||||||
}
|
|
||||||
return true; // Éxito
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new Exception($"Error: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> SpTraspasoDatosAchirdSupFluj()
|
await SpCalculoDgaSupFluj();
|
||||||
{
|
|
||||||
try
|
string sql = "INSERT INTO DGA_MACRO_RESULTADO_SUP_FLUJ (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)";
|
||||||
{
|
await connection.ExecuteAsync(sql, dgaMacroResultadoSupFluj);
|
||||||
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
return true;
|
||||||
{
|
}
|
||||||
await connection.OpenAsync();
|
}
|
||||||
await connection.ExecuteAsync(
|
catch (Exception ex)
|
||||||
"SP_TRASPASO_DATOS_ACHIRD_SUP_FLUJ",
|
{
|
||||||
commandType: CommandType.StoredProcedure
|
throw new Exception($"Error: {ex.Message}");
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return true; // Éxito
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
|
public async Task<bool> SpCalculoDgaSupFluj()
|
||||||
{
|
{
|
||||||
throw new Exception($"Error: {ex.Message}");
|
try
|
||||||
|
{
|
||||||
|
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||||
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
await connection.ExecuteAsync(
|
||||||
|
"SP_CALCULO_DGA_SUP_FLUJ",
|
||||||
|
commandType: CommandType.StoredProcedure
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return true; // Éxito
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception($"Error: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> SpTraspasoDatosAchirdSupFluj()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||||
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
await connection.ExecuteAsync(
|
||||||
|
"SP_TRASPASO_DATOS_ACHIRD_SUP_FLUJ",
|
||||||
|
commandType: CommandType.StoredProcedure
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return true; // Éxito
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception($"Error: {ex.Message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
using Dapper;
|
using System.Data;
|
||||||
|
using Dapper;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Shared.DTO.Integracion_DGA;
|
using Shared.DTO.Integracion_DGA;
|
||||||
using Shared.DTO.VariablesEntorno;
|
using Shared.DTO.VariablesEntorno;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Data;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DAL
|
namespace DAL
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
using System;
|
using Dapper;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Dapper;
|
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Shared.DTO.Envios_DGA;
|
using Shared.DTO.Envios_DGA;
|
||||||
using Shared.DTO.VariablesEntorno;
|
using Shared.DTO.VariablesEntorno;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
using Dapper;
|
using System.Data;
|
||||||
|
using Dapper;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Shared.DTO.Envios_DGA;
|
using Shared.DTO.Envios_DGA;
|
||||||
using Shared.DTO.VariablesEntorno;
|
using Shared.DTO.VariablesEntorno;
|
||||||
using System.Data;
|
|
||||||
|
|
||||||
namespace DAL
|
namespace DAL
|
||||||
{
|
{
|
||||||
|
|
22
DAL/MedicionScadaVilosRepository.cs
Normal file
22
DAL/MedicionScadaVilosRepository.cs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
using System.Data;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Data.SqlClient;
|
||||||
|
using Shared.DTO.Envios_DGA;
|
||||||
|
using Shared.DTO.VariablesEntorno;
|
||||||
|
|
||||||
|
namespace DAL
|
||||||
|
{
|
||||||
|
public class MedicionScadaVilosRepository
|
||||||
|
{
|
||||||
|
public async Task<List<MedicionScada>> ObtenerMedicionesVilosAsync()
|
||||||
|
{
|
||||||
|
await using var connection = new SqlConnection(BdConexion.StringConnection);
|
||||||
|
|
||||||
|
var result = await connection.QueryAsync<MedicionScada>(
|
||||||
|
"SP_OBTENER_MEDICION_SMARTSCADA_OPERACION_VILOS",
|
||||||
|
commandType: CommandType.StoredProcedure);
|
||||||
|
|
||||||
|
return result.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,106 +3,107 @@ using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace BLL.Integracion_DGA
|
namespace BLL.Integracion_DGA
|
||||||
{
|
{
|
||||||
public class ApiService
|
public class ApiService
|
||||||
{
|
|
||||||
private readonly HttpClient _httpClient;
|
|
||||||
|
|
||||||
public ApiService(HttpClient httpClient)
|
|
||||||
{
|
{
|
||||||
_httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
|
private readonly HttpClient _httpClient;
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<string> GetApiResponseAsync(string apiUrl, Dictionary<string, string> headers = null)
|
public ApiService(HttpClient httpClient)
|
||||||
{
|
|
||||||
|
|
||||||
using (var httpClient = new HttpClient())
|
|
||||||
{
|
|
||||||
// Configura la URL base
|
|
||||||
httpClient.BaseAddress = new Uri(apiUrl);
|
|
||||||
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
||||||
|
|
||||||
// Configura los encabezados personalizados si se proporcionan
|
|
||||||
if (headers != null)
|
|
||||||
{
|
{
|
||||||
foreach (var header in headers)
|
_httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
|
||||||
{
|
|
||||||
request.Headers.Add(header.Key, header.Value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Realiza la solicitud con la solicitud personalizada
|
public async Task<string> GetApiResponseAsync(string apiUrl, Dictionary<string, string> headers = null)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
var response = await httpClient.SendAsync(request);
|
|
||||||
if (response.IsSuccessStatusCode)
|
|
||||||
{
|
|
||||||
return await response.Content.ReadAsStringAsync();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Maneja errores aquí según sea necesario.
|
|
||||||
Console.WriteLine($"Error en la solicitud: {response.StatusCode}");
|
|
||||||
throw new HttpRequestException($"Error en la solicitud HTTP. Código de estado: {response.StatusCode}");
|
|
||||||
}
|
|
||||||
}catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Error: " + ex.Message);
|
|
||||||
throw new Exception($"Error en la solicitud HTTP: {ex.Message}");
|
|
||||||
// Maneja la excepción según sea necesario
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<string> PostApiResponseAsync(string apiUrl, Dictionary<string, string> headers = null, object data = null)
|
using (var httpClient = new HttpClient())
|
||||||
{
|
|
||||||
using (var httpClient = new HttpClient())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
httpClient.BaseAddress = new Uri(apiUrl);
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
|
||||||
|
|
||||||
// Serializa el objeto data a JSON
|
|
||||||
//string jsonData = JsonSerializer.Serialize(data);
|
|
||||||
string jsonData = JsonConvert.SerializeObject(data);
|
|
||||||
// Crea el contenido de la solicitud HTTP con el cuerpo JSON
|
|
||||||
HttpContent contenido = new StringContent(jsonData, Encoding.UTF8, "application/json");
|
|
||||||
request.Content = contenido;
|
|
||||||
|
|
||||||
// Configura los encabezados personalizados si se proporcionan
|
|
||||||
if (headers != null)
|
|
||||||
{
|
|
||||||
foreach (var header in headers)
|
|
||||||
{
|
{
|
||||||
request.Headers.Add(header.Key, header.Value);
|
// Configura la URL base
|
||||||
|
httpClient.BaseAddress = new Uri(apiUrl);
|
||||||
|
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
||||||
|
|
||||||
|
// Configura los encabezados personalizados si se proporcionan
|
||||||
|
if (headers != null)
|
||||||
|
{
|
||||||
|
foreach (var header in headers)
|
||||||
|
{
|
||||||
|
request.Headers.Add(header.Key, header.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Realiza la solicitud con la solicitud personalizada
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await httpClient.SendAsync(request);
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
return await response.Content.ReadAsStringAsync();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Maneja errores aquí según sea necesario.
|
||||||
|
Console.WriteLine($"Error en la solicitud: {response.StatusCode}");
|
||||||
|
throw new HttpRequestException($"Error en la solicitud HTTP. Código de estado: {response.StatusCode}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error: " + ex.Message);
|
||||||
|
throw new Exception($"Error en la solicitud HTTP: {ex.Message}");
|
||||||
|
// Maneja la excepción según sea necesario
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Realiza la solicitud POST
|
|
||||||
HttpResponseMessage response = await httpClient.SendAsync(request);
|
|
||||||
|
|
||||||
// Verifica si la solicitud fue exitosa
|
|
||||||
if (response.IsSuccessStatusCode)
|
|
||||||
{
|
|
||||||
// Lee la respuesta como una cadena
|
|
||||||
return await response.Content.ReadAsStringAsync();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// La solicitud no fue exitosa, maneja el error según sea necesario
|
|
||||||
Console.WriteLine($"Error en la solicitud HTTP. Código de estado: {response.StatusCode}");
|
|
||||||
throw new HttpRequestException($"Error en la solicitud HTTP. Código de estado: {response.StatusCode}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
|
public async Task<string> PostApiResponseAsync(string apiUrl, Dictionary<string, string> headers = null, object data = null)
|
||||||
{
|
{
|
||||||
// Maneja excepciones si ocurren
|
using (var httpClient = new HttpClient())
|
||||||
Console.WriteLine($"Error en la solicitud HTTP: {ex.Message}");
|
{
|
||||||
throw new Exception($"Error en la solicitud HTTP: {ex.Message}");
|
try
|
||||||
|
{
|
||||||
|
httpClient.BaseAddress = new Uri(apiUrl);
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
||||||
|
|
||||||
|
// Serializa el objeto data a JSON
|
||||||
|
//string jsonData = JsonSerializer.Serialize(data);
|
||||||
|
string jsonData = JsonConvert.SerializeObject(data);
|
||||||
|
// Crea el contenido de la solicitud HTTP con el cuerpo JSON
|
||||||
|
HttpContent contenido = new StringContent(jsonData, Encoding.UTF8, "application/json");
|
||||||
|
request.Content = contenido;
|
||||||
|
|
||||||
|
// Configura los encabezados personalizados si se proporcionan
|
||||||
|
if (headers != null)
|
||||||
|
{
|
||||||
|
foreach (var header in headers)
|
||||||
|
{
|
||||||
|
request.Headers.Add(header.Key, header.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Realiza la solicitud POST
|
||||||
|
HttpResponseMessage response = await httpClient.SendAsync(request);
|
||||||
|
|
||||||
|
// Verifica si la solicitud fue exitosa
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
// Lee la respuesta como una cadena
|
||||||
|
return await response.Content.ReadAsStringAsync();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// La solicitud no fue exitosa, maneja el error según sea necesario
|
||||||
|
Console.WriteLine($"Error en la solicitud HTTP. Código de estado: {response.StatusCode}");
|
||||||
|
throw new HttpRequestException($"Error en la solicitud HTTP. Código de estado: {response.StatusCode}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// Maneja excepciones si ocurren
|
||||||
|
Console.WriteLine($"Error en la solicitud HTTP: {ex.Message}");
|
||||||
|
throw new Exception($"Error en la solicitud HTTP: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
using DAL;
|
using System.Text;
|
||||||
using Microsoft.Extensions.Configuration;
|
using System.Text.Json;
|
||||||
|
using DAL;
|
||||||
using Shared.DTO.Envios_DGA;
|
using Shared.DTO.Envios_DGA;
|
||||||
using Shared.DTO.VariablesEntorno;
|
using Shared.DTO.VariablesEntorno;
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace DAS
|
namespace DAS
|
||||||
{
|
{
|
||||||
public class RegistrarMedicion
|
public class RegistrarMedicion
|
||||||
{
|
{
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
private readonly LogMedicionScadaRepository _logMedicionScadaRepository;
|
private readonly LogMedicionScadaRepository _logMedicionScadaRepository;
|
||||||
|
@ -20,10 +19,6 @@ namespace DAS
|
||||||
|
|
||||||
public async Task<bool> EnviarMedicionAsync(string codigoObra, MedicionSubterraneaRequest request, long idMedicion)
|
public async Task<bool> EnviarMedicionAsync(string codigoObra, MedicionSubterraneaRequest request, long idMedicion)
|
||||||
{
|
{
|
||||||
request.Autenticacion.Password = CredencialDGA.Password;
|
|
||||||
request.Autenticacion.RutEmpresa = CredencialDGA.RutEmpresa; //TODO: condicionar rut empresa
|
|
||||||
request.Autenticacion.RutUsuario = CredencialDGA.RutUsuario;
|
|
||||||
|
|
||||||
var timeStamp = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss-0000");
|
var timeStamp = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss-0000");
|
||||||
|
|
||||||
var json = JsonSerializer.Serialize(request);
|
var json = JsonSerializer.Serialize(request);
|
||||||
|
@ -32,7 +27,7 @@ namespace DAS
|
||||||
content.Headers.Add("codigoObra", codigoObra);
|
content.Headers.Add("codigoObra", codigoObra);
|
||||||
content.Headers.Add("timeStampOrigen", timeStamp);
|
content.Headers.Add("timeStampOrigen", timeStamp);
|
||||||
|
|
||||||
var response = await _httpClient.PostAsync($"{SubterraneaApiUrl.BaseUrl}{SubterraneaApiUrl.EndPoint}", content);
|
/*var response = await _httpClient.PostAsync($"{SubterraneaApiUrl.BaseUrl}{SubterraneaApiUrl.EndPoint}", content);
|
||||||
string jsonRecibido = await response.Content.ReadAsStringAsync();
|
string jsonRecibido = await response.Content.ReadAsStringAsync();
|
||||||
string estado = response.IsSuccessStatusCode ? "OK" : "ERROR";
|
string estado = response.IsSuccessStatusCode ? "OK" : "ERROR";
|
||||||
string comprobante = string.Empty;
|
string comprobante = string.Empty;
|
||||||
|
@ -62,10 +57,10 @@ namespace DAS
|
||||||
FechaEnvio = DateTime.UtcNow,
|
FechaEnvio = DateTime.UtcNow,
|
||||||
IdMedicionSmartscadaOperacion = idMedicion
|
IdMedicionSmartscadaOperacion = idMedicion
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
//await _logMedicionScadaRepository.InsertarLogMedicionScadaAsync(logMedicionScada);
|
||||||
|
|
||||||
await _logMedicionScadaRepository.InsertarLogMedicionScadaAsync(logMedicionScada);
|
return true;
|
||||||
|
|
||||||
return response.IsSuccessStatusCode;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using BLL.Integracion_DGA;
|
||||||
using Microsoft.Extensions.Hosting;
|
using BLL.Recuperacion_DGA;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using DAL;
|
using DAL;
|
||||||
using DAS;
|
using DAS;
|
||||||
using BLL.Recuperacion_DGA;
|
using Microsoft.Extensions.Configuration;
|
||||||
using BLL.Integracion_DGA;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Shared.Helper;
|
||||||
using Shared.Utils;
|
using Shared.Utils;
|
||||||
|
|
||||||
namespace Integracion_DGA
|
namespace Integracion_DGA
|
||||||
|
@ -13,10 +14,23 @@ namespace Integracion_DGA
|
||||||
{
|
{
|
||||||
static async Task Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
ObtenerVariablesEntorno.AmbientarApiUrlNexus("NEXUS_API_URL");
|
try
|
||||||
ObtenerVariablesEntorno.AmbientarUrlApiSubterranea("SUBTERRANEAS_API_URL");
|
{
|
||||||
ObtenerVariablesEntorno.AmbientarConexionBd("CONEXION_BD_ENVIO_DGA");
|
Console.Write("Obteniendo variables de entorno...");
|
||||||
ObtenerVariablesEntorno.AmbientarCredencialesDGA("DGA_CREDENCIALES");
|
ObtenerVariablesEntorno.AmbientarApiUrlNexus("NEXUS_API_URL");
|
||||||
|
ObtenerVariablesEntorno.AmbientarUrlApiSubterranea("SUBTERRANEAS_API_URL");
|
||||||
|
ObtenerVariablesEntorno.AmbientarConexionBd("CONEXION_BD_ENVIO_DGA");
|
||||||
|
ObtenerVariablesEntorno.AmbientarCredencialesDGA("DGA_CREDENCIALES");
|
||||||
|
ObtenerVariablesEntorno.ValidarVariablesEntorno();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine($"[Error] {ex.Message}");
|
||||||
|
Console.ResetColor();
|
||||||
|
FileLoggerHelper.LogInformation($"{ex.Message}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
using IHost host = Host.CreateDefaultBuilder(args)
|
using IHost host = Host.CreateDefaultBuilder(args)
|
||||||
.ConfigureServices((context, services) =>
|
.ConfigureServices((context, services) =>
|
||||||
|
@ -27,7 +41,6 @@ namespace Integracion_DGA
|
||||||
services.AddScoped<MedicionScadaRepository>();
|
services.AddScoped<MedicionScadaRepository>();
|
||||||
services.AddScoped<EnvioDGA>();
|
services.AddScoped<EnvioDGA>();
|
||||||
services.AddHttpClient<RegistrarMedicion>();
|
services.AddHttpClient<RegistrarMedicion>();
|
||||||
//Estos dos servicios son los que migre del otro proyecto
|
|
||||||
services.AddScoped<JobsDgaRepository>();
|
services.AddScoped<JobsDgaRepository>();
|
||||||
services.AddScoped<JobsDgaVilosRepository>();
|
services.AddScoped<JobsDgaVilosRepository>();
|
||||||
services.AddScoped<JobsDgaSupFlujRepository>();
|
services.AddScoped<JobsDgaSupFlujRepository>();
|
||||||
|
@ -37,8 +50,6 @@ namespace Integracion_DGA
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
//TODO: Controlar si las variables de ambiente existen
|
|
||||||
|
|
||||||
var envioDGA = host.Services.GetRequiredService<EnvioDGA>();
|
var envioDGA = host.Services.GetRequiredService<EnvioDGA>();
|
||||||
var bussinessLogic = host.Services.GetRequiredService<BusinessLogic>();
|
var bussinessLogic = host.Services.GetRequiredService<BusinessLogic>();
|
||||||
var apiService = host.Services.GetRequiredService<ApiService>();
|
var apiService = host.Services.GetRequiredService<ApiService>();
|
||||||
|
|
|
@ -5,6 +5,7 @@ using DAS;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Shared.Helper;
|
||||||
using Shared.Utils;
|
using Shared.Utils;
|
||||||
|
|
||||||
namespace Recuperacion_DGA
|
namespace Recuperacion_DGA
|
||||||
|
@ -13,10 +14,23 @@ namespace Recuperacion_DGA
|
||||||
{
|
{
|
||||||
static async Task Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
ObtenerVariablesEntorno.AmbientarApiUrlNexus("NEXUS_API_URL");
|
try
|
||||||
ObtenerVariablesEntorno.AmbientarUrlApiSubterranea("SUBTERRANEAS_API_URL");
|
{
|
||||||
ObtenerVariablesEntorno.AmbientarConexionBd("CONEXION_BD_ENVIO_DGA");
|
Console.WriteLine("Obteniendo variables de entorno...");
|
||||||
ObtenerVariablesEntorno.AmbientarCredencialesDGA("DGA_CREDENCIALES");
|
ObtenerVariablesEntorno.AmbientarApiUrlNexus("NEXUS_API_URL");
|
||||||
|
ObtenerVariablesEntorno.AmbientarUrlApiSubterranea("SUBTERRANEAS_API_URL");
|
||||||
|
ObtenerVariablesEntorno.AmbientarConexionBd("CONEXION_BD_ENVIO_DGA");
|
||||||
|
ObtenerVariablesEntorno.AmbientarCredencialesDGA("DGA_CREDENCIALES");
|
||||||
|
ObtenerVariablesEntorno.ValidarVariablesEntorno();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine($"[Error] {ex.Message}");
|
||||||
|
Console.ResetColor();
|
||||||
|
FileLoggerHelper.LogInformation($"{ex.Message}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
using IHost host = Host.CreateDefaultBuilder(args)
|
using IHost host = Host.CreateDefaultBuilder(args)
|
||||||
.ConfigureServices((context, services) =>
|
.ConfigureServices((context, services) =>
|
||||||
|
@ -25,25 +39,17 @@ namespace Recuperacion_DGA
|
||||||
services.AddSingleton<IConfiguration>(configuration);
|
services.AddSingleton<IConfiguration>(configuration);
|
||||||
|
|
||||||
services.AddScoped<MedicionScadaRepository>();
|
services.AddScoped<MedicionScadaRepository>();
|
||||||
|
services.AddScoped<MedicionScadaVilosRepository>();
|
||||||
services.AddScoped<EnvioDGA>();
|
services.AddScoped<EnvioDGA>();
|
||||||
services.AddHttpClient<RegistrarMedicion>();
|
services.AddHttpClient<RegistrarMedicion>();
|
||||||
//Estos dos servicios son los que migre del otro proyecto
|
|
||||||
services.AddScoped<JobsDgaRepository>();
|
|
||||||
services.AddScoped<JobsDgaVilosRepository>();
|
|
||||||
services.AddScoped<JobsDgaSupFlujRepository>();
|
|
||||||
services.AddScoped<LogMedicionScadaRepository>();
|
services.AddScoped<LogMedicionScadaRepository>();
|
||||||
services.AddScoped<ApiService>();
|
|
||||||
services.AddScoped<BusinessLogic>();
|
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
//TODO: Controlar si las variables de ambiente existen
|
|
||||||
//TODO: Log de texto
|
|
||||||
|
|
||||||
var envioDGA = host.Services.GetRequiredService<EnvioDGA>();
|
var envioDGA = host.Services.GetRequiredService<EnvioDGA>();
|
||||||
await envioDGA.RegistrarMedicionesAsync();
|
await envioDGA.RegistrarMedicionesAsync();
|
||||||
|
|
||||||
//TODO: Log de texto
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.Envios_DGA
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Shared.DTO.Envios_DGA
|
|
||||||
{
|
{
|
||||||
public class LogMedicionScada
|
public class LogMedicionScada
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.Envios_DGA
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Shared.DTO.Envios_DGA
|
|
||||||
{
|
{
|
||||||
public class MedicionScada
|
public class MedicionScada
|
||||||
{
|
{
|
||||||
|
@ -27,6 +21,6 @@ namespace Shared.DTO.Envios_DGA
|
||||||
|
|
||||||
public decimal? Nivel { get; set; }
|
public decimal? Nivel { get; set; }
|
||||||
|
|
||||||
public string? TipoEmpresa { get; set; }
|
public string? tipo_empresa { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.Envios_DGA
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Shared.DTO.Envios_DGA
|
|
||||||
{
|
{
|
||||||
public class MedicionSubterraneaRequest
|
public class MedicionSubterraneaRequest
|
||||||
{
|
{
|
||||||
|
@ -26,5 +20,7 @@ namespace Shared.DTO.Envios_DGA
|
||||||
public string HoraMedicion { get; set; }
|
public string HoraMedicion { get; set; }
|
||||||
public string NivelFreaticoDelPozo { get; set; }
|
public string NivelFreaticoDelPozo { get; set; }
|
||||||
public string Totalizador { get; set; }
|
public string Totalizador { get; set; }
|
||||||
|
public string? TipoEmpresa { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.Integracion_DGA;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace Shared.DTO.Integracion_DGA;
|
|
||||||
|
|
||||||
public partial class DgaMacroResultado
|
public partial class DgaMacroResultado
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.Integracion_DGA;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Shared.DTO.Integracion_DGA;
|
|
||||||
|
|
||||||
public partial class DgaMacroResultadoSupFluj
|
public partial class DgaMacroResultadoSupFluj
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.Integracion_DGA;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Shared.DTO.Integracion_DGA;
|
|
||||||
|
|
||||||
public partial class DgaMacroResultadoSupFlujSuma
|
public partial class DgaMacroResultadoSupFlujSuma
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.Integracion_DGA;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Shared.DTO.Integracion_DGA;
|
|
||||||
|
|
||||||
public partial class DgaMacroResultadoVilos
|
public partial class DgaMacroResultadoVilos
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.Integracion_DGA;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Shared.DTO.Integracion_DGA;
|
|
||||||
|
|
||||||
public partial class DgaSensorResultado
|
public partial class DgaSensorResultado
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.Integracion_DGA;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Shared.DTO.Integracion_DGA;
|
|
||||||
|
|
||||||
public partial class DgaSensorResultadoVilos
|
public partial class DgaSensorResultadoVilos
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.Integracion_DGA
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Shared.DTO.Integracion_DGA
|
|
||||||
{
|
{
|
||||||
public class DocumentResponse
|
public class DocumentResponse
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.Integracion_DGA
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Shared.DTO.Integracion_DGA
|
|
||||||
{
|
{
|
||||||
public class HistoricRequest
|
public class HistoricRequest
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.Integracion_DGA
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Shared.DTO.Integracion_DGA
|
|
||||||
{
|
{
|
||||||
public class HistoricResponse
|
public class HistoricResponse
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.Integracion_DGA
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Shared.DTO.Integracion_DGA
|
|
||||||
{
|
{
|
||||||
public class TagviewsResponse
|
public class TagviewsResponse
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.VariablesEntorno
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Shared.DTO.VariablesEntorno
|
|
||||||
{
|
{
|
||||||
public static class BdConexion
|
public static class BdConexion
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
using System;
|
namespace Shared.DTO.VariablesEntorno
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Shared.DTO.VariablesEntorno
|
|
||||||
{
|
{
|
||||||
public static class CredencialDGA
|
public static class CredencialDGA
|
||||||
{
|
{
|
||||||
public static string RutEmpresa { get; set; } = string.Empty;
|
public static string RutEsval { get; set; } = string.Empty;
|
||||||
|
public static string RutAv { get; set; } = string.Empty;
|
||||||
public static string RutUsuario { get; set; } = string.Empty;
|
public static string RutUsuario { get; set; } = string.Empty;
|
||||||
public static string Password { get; set; } = string.Empty;
|
public static string Password { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.VariablesEntorno
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Shared.DTO.VariablesEntorno
|
|
||||||
{
|
{
|
||||||
public static class NexusApiUrl
|
public static class NexusApiUrl
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
using System;
|
namespace Shared.DTO.VariablesEntorno
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Shared.DTO.VariablesEntorno
|
|
||||||
{
|
{
|
||||||
public static class SubterraneaApiUrl
|
public static class SubterraneaApiUrl
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,27 +3,27 @@ using Serilog;
|
||||||
|
|
||||||
namespace Shared.Helper
|
namespace Shared.Helper
|
||||||
{
|
{
|
||||||
public class FileLoggerHelper
|
public class FileLoggerHelper
|
||||||
{
|
|
||||||
public static void ConfigureLogger(IConfiguration configuration)
|
|
||||||
{
|
{
|
||||||
var logFilePath = configuration.GetSection("Logging:LogFile:Path").Value;
|
public static void ConfigureLogger(IConfiguration configuration)
|
||||||
var logFileFullPath = Path.Combine(Directory.GetCurrentDirectory(), logFilePath);
|
{
|
||||||
|
var logFilePath = configuration.GetSection("Logging:LogFile:Path").Value;
|
||||||
|
var logFileFullPath = Path.Combine(Directory.GetCurrentDirectory(), logFilePath);
|
||||||
|
|
||||||
Log.Logger = new LoggerConfiguration()
|
Log.Logger = new LoggerConfiguration()
|
||||||
.ReadFrom.Configuration(configuration)
|
.ReadFrom.Configuration(configuration)
|
||||||
.WriteTo.File(logFileFullPath, rollingInterval: RollingInterval.Day)
|
.WriteTo.File(logFileFullPath, rollingInterval: RollingInterval.Day)
|
||||||
.CreateLogger();
|
.CreateLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LogInformation(string message)
|
public static void LogInformation(string message)
|
||||||
{
|
{
|
||||||
Log.Information($"{message}");
|
Log.Information($"{message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LogError(string message, Exception ex)
|
public static void LogError(string message, Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error(ex, message);
|
Log.Error(ex, message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
using System;
|
using Shared.DTO.VariablesEntorno;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Shared.DTO.VariablesEntorno;
|
|
||||||
|
|
||||||
namespace Shared.Utils
|
namespace Shared.Utils
|
||||||
{
|
{
|
||||||
|
@ -34,8 +29,11 @@ namespace Shared.Utils
|
||||||
{
|
{
|
||||||
var dictEnv = GetVarEnviromentDict(env);
|
var dictEnv = GetVarEnviromentDict(env);
|
||||||
|
|
||||||
dictEnv.TryGetValue("RUTEMPRESA", out string? rutEmpresa);
|
dictEnv.TryGetValue("RUTESVAL", out string? rutEsval);
|
||||||
CredencialDGA.RutEmpresa = rutEmpresa ?? string.Empty;
|
CredencialDGA.RutEsval = rutEsval ?? string.Empty;
|
||||||
|
|
||||||
|
dictEnv.TryGetValue("RUTAV", out string? rutAv);
|
||||||
|
CredencialDGA.RutAv = rutAv ?? string.Empty;
|
||||||
|
|
||||||
dictEnv.TryGetValue("RUTUSUARIO", out string? rutUsuario);
|
dictEnv.TryGetValue("RUTUSUARIO", out string? rutUsuario);
|
||||||
CredencialDGA.RutUsuario = rutUsuario ?? string.Empty;
|
CredencialDGA.RutUsuario = rutUsuario ?? string.Empty;
|
||||||
|
@ -79,5 +77,33 @@ namespace Shared.Utils
|
||||||
dictEnv.TryGetValue("ENDPOINT", out string? endpoint);
|
dictEnv.TryGetValue("ENDPOINT", out string? endpoint);
|
||||||
SubterraneaApiUrl.EndPoint = endpoint ?? string.Empty;
|
SubterraneaApiUrl.EndPoint = endpoint ?? string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ValidarVariablesEntorno()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(CredencialDGA.RutEsval))
|
||||||
|
throw new Exception("La propiedad CredencialDGA.RutEsval está vacía o nula.");
|
||||||
|
if (string.IsNullOrWhiteSpace(CredencialDGA.RutAv))
|
||||||
|
throw new Exception("La propiedad CredencialDGA.RutAv está vacía o nula.");
|
||||||
|
if (string.IsNullOrWhiteSpace(CredencialDGA.RutUsuario))
|
||||||
|
throw new Exception("La propiedad CredencialDGA.RutUsuario está vacía o nula.");
|
||||||
|
if (string.IsNullOrWhiteSpace(CredencialDGA.Password))
|
||||||
|
throw new Exception("La propiedad CredencialDGA.Password está vacía o nula.");
|
||||||
|
if (string.IsNullOrWhiteSpace(NexusApiUrl.ApiUrl))
|
||||||
|
throw new Exception("La propiedad NexusApiUrl.ApiUrl está vacía o nula.");
|
||||||
|
if (string.IsNullOrWhiteSpace(NexusApiUrl.ApiKey))
|
||||||
|
throw new Exception("La propiedad NexusApiUrl.ApiKey está vacía o nula.");
|
||||||
|
if (string.IsNullOrWhiteSpace(NexusApiUrl.Version))
|
||||||
|
throw new Exception("La propiedad NexusApiUrl.Version está vacía o nula.");
|
||||||
|
if (string.IsNullOrWhiteSpace(NexusApiUrl.DataSource))
|
||||||
|
throw new Exception("La propiedad NexusApiUrl.DataSource está vacía o nula.");
|
||||||
|
if (string.IsNullOrWhiteSpace(NexusApiUrl.Resolution))
|
||||||
|
throw new Exception("La propiedad NexusApiUrl.Resolution está vacía o nula.");
|
||||||
|
if (string.IsNullOrWhiteSpace(BdConexion.StringConnection))
|
||||||
|
throw new Exception("La propiedad BdConexion.StringConnection está vacía o nula.");
|
||||||
|
if (string.IsNullOrWhiteSpace(SubterraneaApiUrl.BaseUrl))
|
||||||
|
throw new Exception("La propiedad SubterraneaApiUrl.BaseUrl está vacía o nula.");
|
||||||
|
if (string.IsNullOrWhiteSpace(SubterraneaApiUrl.EndPoint))
|
||||||
|
throw new Exception("La propiedad SubterraneaApiUrl.EndPoint está vacía o nula.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue