Compare commits
3 Commits
155c97ccf6
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| c795be9cd5 | |||
| e55dd0ef68 | |||
| 4ac7cb716b |
28
ApiDatosSanchoToro/ApiDatosSanchoToro.csproj
Normal file
28
ApiDatosSanchoToro/ApiDatosSanchoToro.csproj
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<SccProjectName>SAK</SccProjectName>
|
||||||
|
<SccProvider>SAK</SccProvider>
|
||||||
|
<SccAuxPath>SAK</SccAuxPath>
|
||||||
|
<SccLocalPath>SAK</SccLocalPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="EPPlus" Version="7.5.2" />
|
||||||
|
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.14.28" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.14" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||||
|
<PackageReference Include="tsUtilidades" Version="1.1.5" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\SanchoToro\bdGrupoSanchoToro\bdGrupoSanchoToro.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
6
ApiDatosSanchoToro/ApiDatosSanchoToro.http
Normal file
6
ApiDatosSanchoToro/ApiDatosSanchoToro.http
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
@ApiExcelGuadex_HostAddress = http://localhost:5188
|
||||||
|
|
||||||
|
GET {{ApiExcelGuadex_HostAddress}}/weatherforecast/
|
||||||
|
Accept: application/json
|
||||||
|
|
||||||
|
###
|
||||||
88
ApiDatosSanchoToro/Controllers/HomeController.cs
Normal file
88
ApiDatosSanchoToro/Controllers/HomeController.cs
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
using ApiDatosGuadex.Models;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Data.Common;
|
||||||
|
using bdGrupoSanchoToro.dbcontext;
|
||||||
|
using bdGrupoSanchoToro;
|
||||||
|
|
||||||
|
namespace ApiDatosGuadex.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class HomeController : Controller
|
||||||
|
{
|
||||||
|
//metodo
|
||||||
|
[HttpGet("lee")]
|
||||||
|
public IActionResult LeeSQL(string bd, string sqlh)
|
||||||
|
{
|
||||||
|
// bdGestionGuadex.Utilidades.AñadeLog(tsUtilidades.Enumeraciones.TipoLog.Otros, "Inicio Log",null);
|
||||||
|
Response.ContentType = "text/plain";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
DbConnection? db = null;
|
||||||
|
|
||||||
|
switch (bd.ToLower())
|
||||||
|
{
|
||||||
|
case "sanchotoro":
|
||||||
|
{
|
||||||
|
db = tscGrupoSanchoToro.NuevoContexto().Database.GetDbConnection();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//case "guadex":
|
||||||
|
// {
|
||||||
|
// db = tscGrupoSanchoToro.NuevoContexto().Database.GetDbConnection();
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
// string res = tsUtilidades.bbdd.LeeMysql(db, sqlh);
|
||||||
|
string res = tsUtilidades.bbdd.LeeMysql(db, sqlh);
|
||||||
|
|
||||||
|
|
||||||
|
// termiancion en CRLF
|
||||||
|
res = res.Replace("\n", "\r\n");
|
||||||
|
|
||||||
|
return Content(res, "text/plain", System.Text.Encoding.UTF8);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
bdGrupoSanchoToro.db.Utilidades.AñadeLog(tsUtilidades.Enumeraciones.TipoLog.Fallo, "Error en LeeSQL", ex.Message, ex);
|
||||||
|
return Content($"Error: {ex.Message}\r\n", "text/plain", System.Text.Encoding.UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public IActionResult EjeSQL(string bd, string sqlh)
|
||||||
|
{
|
||||||
|
Response.ContentType = "text/plain";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DbConnection? db = null;
|
||||||
|
switch (bd.ToLower())
|
||||||
|
{
|
||||||
|
case "sanchotoro":
|
||||||
|
{
|
||||||
|
db = tscGrupoSanchoToro.NuevoContexto().Database.GetDbConnection();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//case "guadex":
|
||||||
|
// {
|
||||||
|
// db = bdGuadex.tscGuadex.NuevoContexto().Database.GetDbConnection();
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
string res = tsUtilidades.bbdd.EjeMySqlHex(db, sqlh);
|
||||||
|
|
||||||
|
// terminacion en CRLF
|
||||||
|
res = res.Replace("\n", "\r\n");
|
||||||
|
|
||||||
|
return Content(res, "text/plain", System.Text.Encoding.UTF8);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
bdGrupoSanchoToro.db.Utilidades.AñadeLog(tsUtilidades.Enumeraciones.TipoLog.Fallo, "Error en EjeSQL", ex.Message, ex);
|
||||||
|
return Content($"Error: {ex.Message}\r\n", "text/plain", System.Text.Encoding.UTF8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
39
ApiDatosSanchoToro/Filtros/FiltroAutenticacionBasica.cs
Normal file
39
ApiDatosSanchoToro/Filtros/FiltroAutenticacionBasica.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
namespace ApiDatosGuadex.Filtros
|
||||||
|
{
|
||||||
|
public class FiltroAutenticacionBasica : Attribute, IAuthorizationFilter
|
||||||
|
{
|
||||||
|
private readonly string _usuarioPermitido;
|
||||||
|
private readonly string _contrasenaPermitida;
|
||||||
|
|
||||||
|
public FiltroAutenticacionBasica(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
var authSettings = configuration.GetSection("Authentication");
|
||||||
|
_usuarioPermitido = authSettings["Username"];
|
||||||
|
_contrasenaPermitida = authSettings["Password"];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnAuthorization(AuthorizationFilterContext contexto)
|
||||||
|
{
|
||||||
|
var encabezadoAutorizacion = contexto.HttpContext.Request.Headers["Authorization"].ToString();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(encabezadoAutorizacion) || !encabezadoAutorizacion.StartsWith("Basic "))
|
||||||
|
{
|
||||||
|
contexto.Result = new UnauthorizedResult();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var credencialesCodificadas = encabezadoAutorizacion.Substring("Basic ".Length).Trim();
|
||||||
|
var credencialesDecodificadas = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(credencialesCodificadas));
|
||||||
|
|
||||||
|
var partes = credencialesDecodificadas.Split(':');
|
||||||
|
if (partes.Length != 2 || partes[0] != _usuarioPermitido || partes[1] != _contrasenaPermitida)
|
||||||
|
{
|
||||||
|
contexto.Result = new UnauthorizedResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
ApiDatosSanchoToro/Models/MensajeViewModel.cs
Normal file
7
ApiDatosSanchoToro/Models/MensajeViewModel.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace ApiDatosGuadex.Models
|
||||||
|
{
|
||||||
|
public class MensajeViewModel
|
||||||
|
{
|
||||||
|
public string Mensaje { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
38
ApiDatosSanchoToro/Program.cs
Normal file
38
ApiDatosSanchoToro/Program.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using ApiDatosGuadex.Filtros;
|
||||||
|
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
// Agregar servicios al contenedor
|
||||||
|
builder.Services.AddControllersWithViews();
|
||||||
|
|
||||||
|
// Registrar el filtro de autenticaci<63>n como servicio
|
||||||
|
builder.Services.AddScoped<FiltroAutenticacionBasica>();
|
||||||
|
|
||||||
|
// Agregar Swagger
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
builder.Services.AddSwaggerGen();
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
// Configuraci<63>n del pipeline de solicitudes HTTP
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
app.UseStaticFiles();
|
||||||
|
|
||||||
|
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
|
app.MapControllerRoute(
|
||||||
|
name: "default",
|
||||||
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||||
|
|
||||||
|
|
||||||
|
app.Run();
|
||||||
41
ApiDatosSanchoToro/Properties/launchSettings.json
Normal file
41
ApiDatosSanchoToro/Properties/launchSettings.json
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:12379",
|
||||||
|
"sslPort": 44309
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "http://localhost:5188",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"https": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "https://localhost:7029;http://localhost:5188",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"IIS Express": {
|
||||||
|
"commandName": "IISExpress",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
ApiDatosSanchoToro/Views/Home/EjeSQL.cshtml
Normal file
3
ApiDatosSanchoToro/Views/Home/EjeSQL.cshtml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
@ViewData["Mensaje"]
|
||||||
|
|
||||||
|
|
||||||
4
ApiDatosSanchoToro/Views/Home/LeeSQL.cshtml
Normal file
4
ApiDatosSanchoToro/Views/Home/LeeSQL.cshtml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
@ViewData["Mensaje"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
8
ApiDatosSanchoToro/appsettings.Development.json
Normal file
8
ApiDatosSanchoToro/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
ApiDatosSanchoToro/appsettings.json
Normal file
13
ApiDatosSanchoToro/appsettings.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*",
|
||||||
|
"Authentication": {
|
||||||
|
"Username": "guadex",
|
||||||
|
"Password": "tsguadex..-"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 18
|
# Visual Studio Version 18
|
||||||
VisualStudioVersion = 18.2.11415.280 d18.0
|
VisualStudioVersion = 18.2.11415.280
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bdGrupoSanchoToro", "bdGrupoSanchoToro\bdGrupoSanchoToro.csproj", "{747EDA0C-CF88-4F3A-88C2-9CE2F23B5D56}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bdGrupoSanchoToro", "bdGrupoSanchoToro\bdGrupoSanchoToro.csproj", "{747EDA0C-CF88-4F3A-88C2-9CE2F23B5D56}"
|
||||||
EndProject
|
EndProject
|
||||||
@@ -9,6 +9,10 @@ Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "GestionGrupoSanchoToro", "G
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServicioGrupoSanchoToro", "ServicioGrupoSanchoToro\ServicioGrupoSanchoToro.csproj", "{B5C14166-BE3A-4F61-BD9A-11894BC45C1F}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServicioGrupoSanchoToro", "ServicioGrupoSanchoToro\ServicioGrupoSanchoToro.csproj", "{B5C14166-BE3A-4F61-BD9A-11894BC45C1F}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InterconexionHP", "..\Guadex\InterconexionHP\InterconexionHP.csproj", "{43932962-58FE-A2E7-8695-ADFDB60EC1E2}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiDatosSanchoToro", "..\Guadex\ApiDatosGuadex\ApiDatosSanchoToro.csproj", "{B399F33C-87E1-6AA2-D9E0-6044133F45F8}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
All|Any CPU = All|Any CPU
|
All|Any CPU = All|Any CPU
|
||||||
@@ -34,6 +38,18 @@ Global
|
|||||||
{B5C14166-BE3A-4F61-BD9A-11894BC45C1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{B5C14166-BE3A-4F61-BD9A-11894BC45C1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{B5C14166-BE3A-4F61-BD9A-11894BC45C1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{B5C14166-BE3A-4F61-BD9A-11894BC45C1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{B5C14166-BE3A-4F61-BD9A-11894BC45C1F}.Release|Any CPU.Build.0 = Release|Any CPU
|
{B5C14166-BE3A-4F61-BD9A-11894BC45C1F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{43932962-58FE-A2E7-8695-ADFDB60EC1E2}.All|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{43932962-58FE-A2E7-8695-ADFDB60EC1E2}.All|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{43932962-58FE-A2E7-8695-ADFDB60EC1E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{43932962-58FE-A2E7-8695-ADFDB60EC1E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{43932962-58FE-A2E7-8695-ADFDB60EC1E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{43932962-58FE-A2E7-8695-ADFDB60EC1E2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B399F33C-87E1-6AA2-D9E0-6044133F45F8}.All|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B399F33C-87E1-6AA2-D9E0-6044133F45F8}.All|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B399F33C-87E1-6AA2-D9E0-6044133F45F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B399F33C-87E1-6AA2-D9E0-6044133F45F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B399F33C-87E1-6AA2-D9E0-6044133F45F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B399F33C-87E1-6AA2-D9E0-6044133F45F8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
Reference in New Issue
Block a user