Compare commits
4 commits
f519f3329b
...
5bd9c2a1a6
Author | SHA1 | Date | |
---|---|---|---|
5bd9c2a1a6 | |||
|
0d67a44d36 | ||
|
222d5fdc08 | ||
|
bffcdabc0a |
17 changed files with 264 additions and 156 deletions
|
@ -3,6 +3,7 @@ using DAL;
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Shared.DTO;
|
||||
using Shared.DTO.Integracion_DGA;
|
||||
using Shared.DTO.VariablesEntorno;
|
||||
using Shared.Helper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -44,11 +45,11 @@ namespace BLL.Integracion_DGA
|
|||
WriteLineAndLog($"Inicia Proceso DGA");
|
||||
try
|
||||
{
|
||||
string apiUrlBase = _configuration["ApiSettings:ApiUrl"];
|
||||
string apiUrlBase = NexusApiUrl.ApiUrl;
|
||||
Dictionary<string, string> headers = new Dictionary<string, string>
|
||||
{
|
||||
{ "nexustoken", _configuration["ApiSettings:ApiKey"] },
|
||||
{ "nexusapiversion", _configuration["ApiSettings:Version"] },
|
||||
{ "nexustoken", NexusApiUrl.ApiKey },
|
||||
{ "nexusapiversion", NexusApiUrl.Version },
|
||||
{ "accept", "application/json" }
|
||||
};
|
||||
|
||||
|
@ -73,8 +74,8 @@ namespace BLL.Integracion_DGA
|
|||
}
|
||||
|
||||
HistoricRequest historicRequest = new HistoricRequest();
|
||||
historicRequest.DataSource = _configuration["ApiSettings:DataSource"];
|
||||
historicRequest.Resolution = _configuration["ApiSettings:Resolution"];
|
||||
historicRequest.DataSource = NexusApiUrl.DataSource;
|
||||
historicRequest.Resolution = NexusApiUrl.Resolution;
|
||||
historicRequest.Uids = listTagsID;
|
||||
historicRequest.StartTs = dateStart.ToUnixTimeSeconds();
|
||||
historicRequest.EndTs = dateEnd.ToUnixTimeSeconds();
|
||||
|
|
|
@ -17,11 +17,13 @@ namespace BLL.Recuperacion_DGA
|
|||
_registrarMedicion = registrarMedicion;
|
||||
}
|
||||
|
||||
public async Task<List<MedicionScada>> ObtenerMedicionesAsync()
|
||||
public async Task<bool>RegistrarMedicionesAsync()
|
||||
{
|
||||
var mediciones = await _dGAMedicionScadaRepository.ObtenerMedicionesAsync();
|
||||
|
||||
foreach (var medicion in mediciones)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(medicion.Code))
|
||||
{
|
||||
|
@ -43,13 +45,20 @@ namespace BLL.Recuperacion_DGA
|
|||
}
|
||||
};
|
||||
|
||||
//TODO: Agregar log texto
|
||||
|
||||
await _registrarMedicion.EnviarMedicionAsync(medicion.Code, body,medicion.Id);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//TODO: Agregar log texto
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return mediciones;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,25 +9,17 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Shared.DTO.VariablesEntorno;
|
||||
|
||||
namespace DAL
|
||||
{
|
||||
public class JobsDgaRepository
|
||||
{
|
||||
private static string connectionString = string.Empty;
|
||||
private readonly IConfiguration _configuration;
|
||||
public JobsDgaRepository(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
connectionString = _configuration.GetConnectionString("DefaultConnection") ?? "";
|
||||
|
||||
}
|
||||
|
||||
public async Task<bool> InsertarDgaMacroResultado(List<DgaMacroResultado> dgaMacroResultados)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (SqlConnection connection = new SqlConnection(connectionString))
|
||||
using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
// 1. Truncar la tabla antes de insertar
|
||||
|
@ -49,7 +41,7 @@ namespace DAL
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var connection = new SqlConnection(connectionString))
|
||||
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
|
||||
|
@ -77,7 +69,7 @@ namespace DAL
|
|||
try
|
||||
{
|
||||
// Configurar la conexión a la base de datos
|
||||
using (SqlConnection connection = new SqlConnection(connectionString))
|
||||
using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
// Truncar la tabla antes de insertar
|
||||
|
@ -102,7 +94,7 @@ namespace DAL
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var connection = new SqlConnection(connectionString))
|
||||
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
// Ejecuta el stored procedure sin parámetros
|
||||
|
@ -120,7 +112,7 @@ namespace DAL
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var connection = new SqlConnection(connectionString))
|
||||
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
await connection.ExecuteAsync(
|
||||
|
@ -140,7 +132,7 @@ namespace DAL
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var connection = new SqlConnection(connectionString))
|
||||
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
await connection.ExecuteAsync(
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Shared.DTO.Integracion_DGA;
|
||||
using Shared.DTO.VariablesEntorno;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -13,21 +14,12 @@ namespace DAL
|
|||
{
|
||||
public class JobsDgaSupFlujRepository
|
||||
{
|
||||
private static string connectionString = string.Empty;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public JobsDgaSupFlujRepository(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
connectionString = _configuration.GetConnectionString("DefaultConnection") ?? "";
|
||||
}
|
||||
|
||||
public async Task<bool> InsertarDgaMacroResultadoSupFluj(List<DgaMacroResultadoSupFluj> dgaMacroResultadoSupFluj)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Configurar la conexión a la base de datos
|
||||
using (SqlConnection connection = new SqlConnection(connectionString))
|
||||
using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
await connection.ExecuteAsync("TRUNCATE TABLE DGA_MACRO_RESULTADO_SUP_FLUJ");
|
||||
|
@ -49,7 +41,7 @@ namespace DAL
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var connection = new SqlConnection(connectionString))
|
||||
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
await connection.ExecuteAsync(
|
||||
|
@ -69,7 +61,7 @@ namespace DAL
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var connection = new SqlConnection(connectionString))
|
||||
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
await connection.ExecuteAsync(
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Shared.DTO.Integracion_DGA;
|
||||
using Shared.DTO.VariablesEntorno;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -13,20 +14,12 @@ namespace DAL
|
|||
{
|
||||
public class JobsDgaVilosRepository
|
||||
{
|
||||
private IConfiguration _configuration;
|
||||
private static string connectionString = string.Empty;
|
||||
|
||||
public JobsDgaVilosRepository(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
connectionString = _configuration.GetConnectionString("DefaultConnection") ?? "";
|
||||
}
|
||||
|
||||
public async Task<bool> InsertarDgaMacroResultadoVilos(List<DgaMacroResultadoVilos> dgaMacroResultadoVilos)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var connection = new SqlConnection(connectionString))
|
||||
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
|
||||
|
@ -53,7 +46,7 @@ namespace DAL
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var connection = new SqlConnection(connectionString))
|
||||
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
|
||||
|
@ -77,7 +70,7 @@ namespace DAL
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var connection = new SqlConnection(connectionString))
|
||||
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
await connection.ExecuteAsync(
|
||||
|
@ -97,7 +90,7 @@ namespace DAL
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var connection = new SqlConnection(connectionString))
|
||||
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
await connection.ExecuteAsync(
|
||||
|
|
|
@ -7,24 +7,17 @@ using Dapper;
|
|||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Shared.DTO.Envios_DGA;
|
||||
using Shared.DTO.VariablesEntorno;
|
||||
|
||||
namespace DAL
|
||||
{
|
||||
public class LogMedicionScadaRepository
|
||||
{
|
||||
private IConfiguration _configuration;
|
||||
private static string connectionString = string.Empty;
|
||||
public LogMedicionScadaRepository(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
connectionString = _configuration.GetConnectionString("DefaultConnection") ?? "";
|
||||
}
|
||||
|
||||
public async Task<bool> InsertarLogMedicionScadaAsync(LogMedicionScada logMedicionScada)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var connection = new SqlConnection(connectionString))
|
||||
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
|
||||
|
|
|
@ -2,23 +2,16 @@
|
|||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Shared.DTO.Envios_DGA;
|
||||
using Shared.DTO.VariablesEntorno;
|
||||
using System.Data;
|
||||
|
||||
namespace DAL
|
||||
{
|
||||
public class MedicionScadaRepository
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public MedicionScadaRepository(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public async Task<List<MedicionScada>> ObtenerMedicionesAsync()
|
||||
{
|
||||
var connectionString = _configuration.GetConnectionString("DefaultConnection");
|
||||
await using var connection = new SqlConnection(connectionString);
|
||||
await using var connection = new SqlConnection(BdConexion.StringConnection);
|
||||
|
||||
var result = await connection.QueryAsync<MedicionScada>(
|
||||
"SP_OBTENER_MEDICION_SMARTSCADA_OPERACION",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using DAL;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Shared.DTO.Envios_DGA;
|
||||
using Shared.DTO.VariablesEntorno;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
|
@ -9,32 +10,19 @@ namespace DAS
|
|||
public class RegistrarMedicion
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly IConfiguration _configuration;
|
||||
private static string? password;
|
||||
private static string? rutEmpresa;
|
||||
private static string? rutUsuario;
|
||||
private readonly LogMedicionScadaRepository _logMedicionScadaRepository;
|
||||
|
||||
public RegistrarMedicion(HttpClient httpClient, IConfiguration configuration,LogMedicionScadaRepository logMedicionScadaRepository)
|
||||
public RegistrarMedicion(HttpClient httpClient, LogMedicionScadaRepository logMedicionScadaRepository)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_configuration = configuration;
|
||||
rutUsuario = _configuration["Credenciales:rutEmpresa"] ?? "";
|
||||
rutEmpresa = _configuration["Credenciales:rutUsuario"] ?? "" ?? "";
|
||||
password = _configuration["Credenciales:password"] ?? "";
|
||||
_logMedicionScadaRepository = logMedicionScadaRepository;
|
||||
}
|
||||
|
||||
public async Task<bool> EnviarMedicionAsync(string codigoObra, MedicionSubterraneaRequest request, long idMedicion)
|
||||
{
|
||||
|
||||
request.Autenticacion.Password = password;
|
||||
request.Autenticacion.RutEmpresa = rutEmpresa;
|
||||
request.Autenticacion.RutUsuario = rutUsuario;
|
||||
|
||||
var baseUrl = _configuration["ApiSubterranea:BaseUrl"];
|
||||
var endpoint = _configuration["ApiSubterranea:Endpoint"];
|
||||
var url = $"{baseUrl}{endpoint}";
|
||||
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");
|
||||
|
||||
|
@ -44,7 +32,7 @@ namespace DAS
|
|||
content.Headers.Add("codigoObra", codigoObra);
|
||||
content.Headers.Add("timeStampOrigen", timeStamp);
|
||||
|
||||
var response = await _httpClient.PostAsync(url, content);
|
||||
var response = await _httpClient.PostAsync($"{SubterraneaApiUrl.BaseUrl}{SubterraneaApiUrl.EndPoint}", content);
|
||||
string jsonRecibido = await response.Content.ReadAsStringAsync();
|
||||
string estado = response.IsSuccessStatusCode ? "OK" : "ERROR";
|
||||
string comprobante = string.Empty;
|
||||
|
@ -56,7 +44,7 @@ namespace DAS
|
|||
if (doc.RootElement.TryGetProperty("data", out var dataProp) &&
|
||||
dataProp.TryGetProperty("numeroComprobante", out var comprobanteProp))
|
||||
{
|
||||
comprobante = comprobanteProp.GetString();
|
||||
comprobante = comprobanteProp.GetString() ?? "";
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
@ -65,13 +53,15 @@ namespace DAS
|
|||
}
|
||||
}
|
||||
|
||||
var logMedicionScada = new LogMedicionScada();
|
||||
logMedicionScada.EstadoEnvio = estado;
|
||||
logMedicionScada.JsonEnviado = json;
|
||||
logMedicionScada.JsonRecibido = jsonRecibido;
|
||||
logMedicionScada.Comprobante = comprobante;
|
||||
logMedicionScada.FechaEnvio = DateTime.UtcNow;
|
||||
logMedicionScada.IdMedicionSmartscadaOperacion = idMedicion;
|
||||
var logMedicionScada = new LogMedicionScada
|
||||
{
|
||||
EstadoEnvio = estado,
|
||||
JsonEnviado = json,
|
||||
JsonRecibido = jsonRecibido,
|
||||
Comprobante = comprobante,
|
||||
FechaEnvio = DateTime.UtcNow,
|
||||
IdMedicionSmartscadaOperacion = idMedicion
|
||||
};
|
||||
|
||||
await _logMedicionScadaRepository.InsertarLogMedicionScadaAsync(logMedicionScada);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ using DAL;
|
|||
using DAS;
|
||||
using BLL.Recuperacion_DGA;
|
||||
using BLL.Integracion_DGA;
|
||||
using Shared.Utils;
|
||||
|
||||
namespace Integracion_DGA
|
||||
{
|
||||
|
@ -12,6 +13,11 @@ namespace Integracion_DGA
|
|||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
ObtenerVariablesEntorno.AmbientarApiUrlNexus("NEXUS_API_URL");
|
||||
ObtenerVariablesEntorno.AmbientarUrlApiSubterranea("SUBTERRANEAS_API_URL");
|
||||
ObtenerVariablesEntorno.AmbientarConexionBd("CONEXION_BD_ENVIO_DGA");
|
||||
ObtenerVariablesEntorno.AmbientarCredencialesDGA("DGA_CREDENCIALES");
|
||||
|
||||
using IHost host = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
|
@ -31,11 +37,13 @@ namespace Integracion_DGA
|
|||
})
|
||||
.Build();
|
||||
|
||||
//TODO: Controlar si las variables de ambiente existen
|
||||
|
||||
var envioDGA = host.Services.GetRequiredService<EnvioDGA>();
|
||||
var bussinessLogic = host.Services.GetRequiredService<BusinessLogic>();
|
||||
var apiService = host.Services.GetRequiredService<ApiService>();
|
||||
var integracion_dga = bussinessLogic.Run();
|
||||
var mediciones = await envioDGA.ObtenerMedicionesAsync();
|
||||
|
||||
await bussinessLogic.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,4 @@
|
|||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=10.224.7.53,1433;Initial Catalog=ENVIO_DGA;Persist Security Info=False;User ID=usrdga;Password=AfX8zE8F740;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=true;Connection Timeout=30;"
|
||||
},
|
||||
"ApiSettings": {
|
||||
"ApiUrl": "http://smartscada.esval.cl:56000",
|
||||
"ApiKey": "3c5fa5dd-1b19-422a-b668-10b1b6c566e2",
|
||||
"Version": "v3.0",
|
||||
"DataSource": "RAW",
|
||||
"Resolution": "RES_15_MIN"
|
||||
},
|
||||
"ApiSubterranea": {
|
||||
"BaseUrl": "https://apimee.mop.gob.cl",
|
||||
"Endpoint": "/api/v1/mediciones/subterraneas"
|
||||
},
|
||||
"Credenciales": {
|
||||
"rutEmpresa": "9A4PUqd1t4",
|
||||
"rutUsuario": "77555666-7",
|
||||
"password": "20999888-7"
|
||||
},
|
||||
"Logging": {
|
||||
"LogFile": {
|
||||
"Path": "logs/log.txt"
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using BLL.Integracion_DGA;
|
||||
using BLL.Recuperacion_DGA;
|
||||
using DAL;
|
||||
using DAS;
|
||||
using BLL.Recuperacion_DGA;
|
||||
using BLL.Integracion_DGA;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Shared.Utils;
|
||||
|
||||
namespace Recuperacion_DGA
|
||||
{
|
||||
|
@ -12,6 +13,11 @@ namespace Recuperacion_DGA
|
|||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
ObtenerVariablesEntorno.AmbientarApiUrlNexus("NEXUS_API_URL");
|
||||
ObtenerVariablesEntorno.AmbientarUrlApiSubterranea("SUBTERRANEAS_API_URL");
|
||||
ObtenerVariablesEntorno.AmbientarConexionBd("CONEXION_BD_ENVIO_DGA");
|
||||
ObtenerVariablesEntorno.AmbientarCredencialesDGA("DGA_CREDENCIALES");
|
||||
|
||||
using IHost host = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
|
@ -25,15 +31,19 @@ namespace Recuperacion_DGA
|
|||
services.AddScoped<JobsDgaRepository>();
|
||||
services.AddScoped<JobsDgaVilosRepository>();
|
||||
services.AddScoped<JobsDgaSupFlujRepository>();
|
||||
services.AddScoped<LogMedicionScadaRepository>();
|
||||
services.AddScoped<ApiService>();
|
||||
services.AddScoped<BusinessLogic>();
|
||||
})
|
||||
.Build();
|
||||
|
||||
var envioDGA = host.Services.GetRequiredService<EnvioDGA>();
|
||||
var mediciones = await envioDGA.ObtenerMedicionesAsync();
|
||||
//TODO: Controlar si las variables de ambiente existen
|
||||
//TODO: Log de texto
|
||||
|
||||
Console.WriteLine($"Se obtuvieron {mediciones.Count} registros.");
|
||||
var envioDGA = host.Services.GetRequiredService<EnvioDGA>();
|
||||
await envioDGA.RegistrarMedicionesAsync();
|
||||
|
||||
//TODO: Log de texto
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,5 +26,7 @@ namespace Shared.DTO.Envios_DGA
|
|||
public decimal? Caudalsub { get; set; }
|
||||
|
||||
public decimal? Nivel { get; set; }
|
||||
|
||||
public string? TipoEmpresa { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
13
SHARED/DTO/VariablesEntorno/BdConexion.cs
Normal file
13
SHARED/DTO/VariablesEntorno/BdConexion.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.DTO.VariablesEntorno
|
||||
{
|
||||
public static class BdConexion
|
||||
{
|
||||
public static string StringConnection { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
15
SHARED/DTO/VariablesEntorno/CredencialDGA.cs
Normal file
15
SHARED/DTO/VariablesEntorno/CredencialDGA.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.DTO.VariablesEntorno
|
||||
{
|
||||
public static class CredencialDGA
|
||||
{
|
||||
public static string RutEmpresa { get; set; } = string.Empty;
|
||||
public static string RutUsuario { get; set; } = string.Empty;
|
||||
public static string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
18
SHARED/DTO/VariablesEntorno/NexusApiUrl.cs
Normal file
18
SHARED/DTO/VariablesEntorno/NexusApiUrl.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.DTO.VariablesEntorno
|
||||
{
|
||||
public static class NexusApiUrl
|
||||
{
|
||||
public static string ApiUrl { get; set; } = string.Empty;
|
||||
public static string ApiKey { get; set; } = string.Empty;
|
||||
public static string Version { get; set; } = string.Empty;
|
||||
public static string DataSource { get; set; } = string.Empty;
|
||||
public static string Resolution { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
}
|
15
SHARED/DTO/VariablesEntorno/SubterraneaApiUrl.cs
Normal file
15
SHARED/DTO/VariablesEntorno/SubterraneaApiUrl.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.DTO.VariablesEntorno
|
||||
{
|
||||
public static class SubterraneaApiUrl
|
||||
{
|
||||
public static string BaseUrl { get; set; } = string.Empty;
|
||||
public static string EndPoint { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
}
|
83
SHARED/Utils/ObtenerVariablesEntorno.cs
Normal file
83
SHARED/Utils/ObtenerVariablesEntorno.cs
Normal file
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Shared.DTO.VariablesEntorno;
|
||||
|
||||
namespace Shared.Utils
|
||||
{
|
||||
public static class ObtenerVariablesEntorno
|
||||
{
|
||||
public static Dictionary<string, string> GetVarEnviromentDict(string key)
|
||||
{
|
||||
string? variableEnv = Environment.GetEnvironmentVariable(key);
|
||||
if (string.IsNullOrWhiteSpace(variableEnv))
|
||||
throw new ArgumentException($"La variable de entorno '{key}' no está definida.");
|
||||
|
||||
var dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var data in variableEnv.Split(';', StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
int div = data.IndexOf('=');
|
||||
if (div <= 0 || div >= data.Length - 1) continue; // Evita keys o values vacíos o sin '='
|
||||
|
||||
var keyValue = data[..div].Trim().ToUpperInvariant();
|
||||
var value = data[(div + 1)..].Trim();
|
||||
|
||||
if (!string.IsNullOrEmpty(keyValue) && !string.IsNullOrEmpty(value))
|
||||
dictionary[keyValue] = value;
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
public static void AmbientarCredencialesDGA(string env)
|
||||
{
|
||||
var dictEnv = GetVarEnviromentDict(env);
|
||||
|
||||
dictEnv.TryGetValue("RUTEMPRESA", out string? rutEmpresa);
|
||||
CredencialDGA.RutEmpresa = rutEmpresa ?? string.Empty;
|
||||
|
||||
dictEnv.TryGetValue("RUTUSUARIO", out string? rutUsuario);
|
||||
CredencialDGA.RutUsuario = rutUsuario ?? string.Empty;
|
||||
|
||||
dictEnv.TryGetValue("PASSWORD", out string? password);
|
||||
CredencialDGA.Password = password ?? string.Empty;
|
||||
}
|
||||
|
||||
public static void AmbientarConexionBd(string env)
|
||||
{
|
||||
BdConexion.StringConnection = Environment.GetEnvironmentVariable(env) ?? string.Empty;
|
||||
}
|
||||
|
||||
public static void AmbientarApiUrlNexus(string env)
|
||||
{
|
||||
var dictEnv = GetVarEnviromentDict(env);
|
||||
|
||||
dictEnv.TryGetValue("URL", out string? url);
|
||||
NexusApiUrl.ApiUrl = url ?? string.Empty;
|
||||
|
||||
dictEnv.TryGetValue("APIKEY", out string? apiKey);
|
||||
NexusApiUrl.ApiKey = apiKey ?? string.Empty;
|
||||
|
||||
dictEnv.TryGetValue("VERSION", out string? version);
|
||||
NexusApiUrl.Version = version ?? string.Empty;
|
||||
|
||||
dictEnv.TryGetValue("DATASOURCE", out string? dataSource);
|
||||
NexusApiUrl.DataSource = dataSource ?? string.Empty;
|
||||
|
||||
dictEnv.TryGetValue("RESOLUTION", out string? resolution);
|
||||
NexusApiUrl.Resolution = resolution ?? string.Empty;
|
||||
}
|
||||
|
||||
public static void AmbientarUrlApiSubterranea(string env)
|
||||
{
|
||||
var dictEnv = GetVarEnviromentDict(env);
|
||||
|
||||
dictEnv.TryGetValue("URL", out string? url);
|
||||
SubterraneaApiUrl.BaseUrl = url ?? string.Empty;
|
||||
|
||||
dictEnv.TryGetValue("ENDPOINT", out string? endpoint);
|
||||
SubterraneaApiUrl.EndPoint = endpoint ?? string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue