feat: migracion y ajustes de configuracion, servicios y el sistema de logueo a la nueva app

This commit is contained in:
Leonel Toro 2025-06-25 13:01:32 -04:00
parent 45f5ec5f84
commit 3348272225
92 changed files with 2676 additions and 19 deletions

58
DAL/Encriptador.cs Normal file
View file

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace DAL
{
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)
{
using Aes aesAlg = Aes.Create();
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());
}
}
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))
{
return srDecrypt.ReadToEnd();
}
}
}
}
}
}

159
DAL/JobsDgaRepository.cs Normal file
View file

@ -0,0 +1,159 @@
using Microsoft.Data.SqlClient;
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 Microsoft.Extensions.Configuration;
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))
{
await connection.OpenAsync();
// 1. Truncar la tabla antes de insertar
await connection.ExecuteAsync("TRUNCATE TABLE DGA_MACRO_RESULTADO");
// 2. Insertar la lista de registros
string sql = "INSERT INTO DGA_MACRO_RESULTADO (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)";
// Esto inserta todos los elementos de la lista en la tabla
await connection.ExecuteAsync(sql, dgaMacroResultados);
return true;
}
}
catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
}
}
public async Task<bool> InsertarDgaSensorResultado(List<DgaSensorResultado> dgaSensorResultado)
{
try
{
using (var connection = new SqlConnection(connectionString))
{
await connection.OpenAsync();
// 1. Truncar la tabla DGA_SENSOR_RESULTADO
await connection.ExecuteAsync("TRUNCATE TABLE DGA_SENSOR_RESULTADO");
// 2. Llamar al stored procedure SP_CALCULO_DGA
await connection.ExecuteAsync("SP_CALCULO_DGA", commandType: System.Data.CommandType.StoredProcedure);
// 3. Insertar todos los registros de la lista con Dapper
string sql = "INSERT INTO DGA_SENSOR_RESULTADO (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)";
await connection.ExecuteAsync(sql, dgaSensorResultado);
return true;
}
}
catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
}
}
public async Task<bool> InsertarDgaMacroResultadoSupFlujSuma(List<DgaMacroResultadoSupFlujSuma> dgaMacroResultadoSupFlujSuma)
{
try
{
// Configurar la conexión a la base de datos
using (SqlConnection connection = new SqlConnection(connectionString))
{
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
SqlDataAdapter adapter = new SqlDataAdapter();
// 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)";
await connection.ExecuteAsync(sql, dgaMacroResultadoSupFlujSuma);
return true; // Éxito
}
}catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
}
}
public async Task<bool> SpCalculoDga()
{
try
{
using (var connection = new SqlConnection(connectionString))
{
await connection.OpenAsync();
// Ejecuta el stored procedure sin parámetros
await connection.ExecuteAsync("SP_CALCULO_DGA", commandType: CommandType.StoredProcedure);
}
return true; // Éxito
}
catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
}
}
public async Task<bool> SpCalculoDgaSupFlujSumaSnreversibilidad()
{
try
{
using (var connection = new SqlConnection(connectionString))
{
await connection.OpenAsync();
await connection.ExecuteAsync(
"SP_CALCULO_DGA_SUP_FLUJ_SUMA_SNREVERSIBILIDAD",
commandType: CommandType.StoredProcedure
);
}
return true; // Éxito
}
catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
}
}
public async Task<bool> SpTraspasoDatosAchird()
{
try
{
using (var connection = new SqlConnection(connectionString))
{
await connection.OpenAsync();
await connection.ExecuteAsync(
"SP_TRASPASO_DATOS_ACHIRD",
commandType: CommandType.StoredProcedure
);
}
return true; // Éxito
}
catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
}
}
}
}

View file

@ -0,0 +1,88 @@
using Dapper;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;
using Shared.DTO.Integracion_DGA;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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))
{
await connection.OpenAsync();
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(connectionString))
{
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(connectionString))
{
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}");
}
}
}
}

View file

@ -0,0 +1,116 @@
using Dapper;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;
using Shared.DTO.Integracion_DGA;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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))
{
await connection.OpenAsync();
// 1. Truncar la tabla antes de insertar
await connection.ExecuteAsync("TRUNCATE TABLE DGA_MACRO_RESULTADO_VILOS");
// 2. Llamar al stored procedure
await connection.ExecuteAsync("SP_CALCULO_DGA_VILOS", commandType: System.Data.CommandType.StoredProcedure);
// 3. Insertar todos los datos de la lista usando Dapper
string sql = "INSERT INTO DGA_MACRO_RESULTADO_VILOS (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)";
await connection.ExecuteAsync(sql, dgaMacroResultadoVilos);
return true; // Éxito
}
}
catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
}
}
public async Task<bool> InsertarDgaSensorResultadoVilos(List<DgaSensorResultadoVilos> dgaSensorResultadoVilos)
{
try
{
using (var connection = new SqlConnection(connectionString))
{
await connection.OpenAsync();
// 1. Truncar la tabla antes de insertar
await connection.ExecuteAsync("TRUNCATE TABLE DGA_SENSOR_RESULTADO_VILOS");
// 2. Insertar todos los datos de la lista usando Dapper
string sql = "INSERT INTO DGA_SENSOR_RESULTADO_VILOS (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)";
await connection.ExecuteAsync(sql, dgaSensorResultadoVilos);
return true; // Éxito
}
}
catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
}
}
public async Task<bool> SpCalculoDgaVilos()
{
try
{
using (var connection = new SqlConnection(connectionString))
{
await connection.OpenAsync();
await connection.ExecuteAsync(
"SP_CALCULO_DGA_VILOS",
commandType: CommandType.StoredProcedure
);
}
return true; // Éxito
}
catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
}
}
public async Task<bool> SpTraspasoDatosAchirdVilos()
{
try
{
using (var connection = new SqlConnection(connectionString))
{
await connection.OpenAsync();
await connection.ExecuteAsync(
"SP_TRASPASO_DATOS_ACHIRD_VILOS",
commandType: CommandType.StoredProcedure
);
}
return true; // Éxito
}
catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
}
}
}
}

View file

@ -1,7 +1,7 @@
using Dapper;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;
using Shared.DTO;
using Shared.DTO.Envios_DGA;
using System.Data;
namespace DAL