primera version estable

This commit is contained in:
2026-09-07 12:17:10 +02:00
parent a644c843f4
commit 160122ce5e
22 changed files with 1333 additions and 7 deletions

View File

@@ -0,0 +1,105 @@
// <auto-generated> This file has been auto generated by EF Core Power Tools. </autogenerated>
#nullable enable
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using bdEmtusa.db;
namespace bdEmtusa.dbcontext;
public partial class EmtusaContext : DbContext
{
public EmtusaContext(DbContextOptions<EmtusaContext> options)
: base(options)
{
}
public virtual DbSet<channels> channels { get; set; }
public virtual DbSet<configuracion> configuracion { get; set; }
public virtual DbSet<historico> historico { get; set; }
public virtual DbSet<items> items { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.UseCollation("utf8mb4_0900_ai_ci")
.HasCharSet("utf8mb4");
modelBuilder.Entity<channels>(entity =>
{
entity.HasKey(e => e.id).HasName("PRIMARY");
entity.Property(e => e.creacion)
.HasDefaultValueSql("CURRENT_TIMESTAMP")
.HasColumnType("datetime");
entity.Property(e => e.description).HasMaxLength(1024);
entity.Property(e => e.generator).HasMaxLength(128);
entity.Property(e => e.language).HasMaxLength(8);
entity.Property(e => e.lastBuildDate).HasColumnType("datetime");
entity.Property(e => e.link).HasMaxLength(4096);
entity.Property(e => e.modificacion)
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("datetime");
entity.Property(e => e.title).HasMaxLength(128);
});
modelBuilder.Entity<configuracion>(entity =>
{
entity.HasKey(e => e.id).HasName("PRIMARY");
entity.HasIndex(e => e.codigo, "index_codigo").IsUnique();
entity.Property(e => e.codigo)
.HasMaxLength(128)
.HasDefaultValueSql("''");
entity.Property(e => e.grupo).HasMaxLength(128);
entity.Property(e => e.valor)
.HasMaxLength(1024)
.HasDefaultValueSql("''");
});
modelBuilder.Entity<historico>(entity =>
{
entity.HasKey(e => e.id).HasName("PRIMARY");
entity.HasIndex(e => e.id_channel, "historico_fk_id_channel");
entity.HasIndex(e => e.id_item, "historico_fk_id_item");
entity.Property(e => e.fechaHora)
.HasDefaultValueSql("CURRENT_TIMESTAMP")
.HasColumnType("datetime");
});
modelBuilder.Entity<items>(entity =>
{
entity.HasKey(e => e.id).HasName("PRIMARY");
entity.HasIndex(e => e.id_channel, "FK_id_channel");
entity.Property(e => e.category).HasMaxLength(64);
entity.Property(e => e.creacion)
.HasDefaultValueSql("CURRENT_TIMESTAMP")
.HasColumnType("datetime");
entity.Property(e => e.guid).HasMaxLength(4096);
entity.Property(e => e.link).HasMaxLength(4096);
entity.Property(e => e.modificacion)
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("datetime");
entity.Property(e => e.pubDate).HasColumnType("datetime");
entity.Property(e => e.title).HasMaxLength(1024);
entity.HasOne(d => d.id_channelNavigation).WithMany(p => p.items)
.HasForeignKey(d => d.id_channel)
.HasConstraintName("FK_id_channel");
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;
using tsUtilidades.Enumeraciones;
using System.Drawing.Imaging;
namespace bdEmtusa.dbcontext
{
public class Conexion
{
public string Nombre { get; set; }
public string Servidor { get; set; }
public int Puerto { get; set; }
public string Database { get; set; }
public string Usuario { get; set; }
public string Contraseña { get; set; }
public static List<Conexion> ListaConexiones()
{
List<Conexion> lc = new List<Conexion>();
lc.Add(new Conexion() { Nombre = "Producción", Puerto = 3306, Servidor = "192.168.41.56", Usuario = "root", Contraseña = "0êmF/e#g/*6pZÛLWqölLvPp", Database = "gestionemtusa" });
return lc;
}
internal static string ObtieneConexionDefecto(string NombreConexion="Producción")
{
try
{
// server=10.10.10.1;database=Emtusa;port=3306;uid=root;pwd=larga;persistsecurityinfo=True;TreatTinyAsBoolean=False;allowuservariables=True
string cs = @";persistsecurityinfo=True;TreatTinyAsBoolean=False;allowuservariables=True";
var lc = ListaConexiones();
var cn = lc.First(x => x.Nombre == NombreConexion);
cs = "server=" + cn.Servidor + ";pwd=" + tsUtilidades.crypt.FEncS(cn.Contraseña, @"[JO1]", @"[JD1]", -875421649) + ";port=" + cn.Puerto.ToString() + ";uid=" + cn.Usuario + ";database=" + cn.Database + cs;
return cs;
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}
}
}

View File

@@ -0,0 +1,144 @@
//using bdEmtusa.CompiledModels;
using bdEmtusa.db;
using bdEmtusa.dbcontext;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using tsEFCore8.Extensiones;
using tsUtilidades;
using tsUtilidades.Enumeraciones;
using tsUtilidades.Extensiones;
using static System.Net.Mime.MediaTypeNames;
namespace bdEmtusa
{
public class tscEmtusa : bdEmtusa.dbcontext.EmtusaContext, tsUtilidades.ItsContexto
{
public static bool Cargado = false;
private static String? _Ip = null;
public string? ip
{
get
{
return _Ip;
}
set
{
_Ip = value;
}
}
public string Aplicaciones { get; private set; }
public static readonly Microsoft.Extensions.Logging.LoggerFactory _myLoggerFactory =
new LoggerFactory(new[] {
new Microsoft.Extensions.Logging.Debug.DebugLoggerProvider()
});
private static string? ConexionPorDefecto = null;
public static tscEmtusa NuevoContexto(string NombreConexion = "", bool Lazy = true, bool SoloLectura = false, bool ConEventoSavingChanges = true, string aplicaciones = "")
{
string? cnx = null;
if (NombreConexion == "")
{
if (ConexionPorDefecto == null) ConexionPorDefecto = Conexion.ObtieneConexionDefecto();
cnx = ConexionPorDefecto;
}
else
{
cnx = Conexion.ObtieneConexionDefecto(NombreConexion);
}
var ob = new DbContextOptionsBuilder<EmtusaContext>();
// ob.UseLoggerFactory(_myLoggerFactory);
// ob.UseInternalServiceProvider(<EnumeracionesService>)
ob.UseMySql(cnx, Microsoft.EntityFrameworkCore.ServerVersion.Parse("8.0.0-mysql"));
if (Lazy) ob.UseLazyLoadingProxies();
if (SoloLectura) ob.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
var Opciones = ob.Options;
tscEmtusa bd = new tscEmtusa(Opciones);
bd.Aplicaciones = aplicaciones;
if (ConEventoSavingChanges) bd.SavingChanges += GuardandoCambios;
return bd;
}
private static void CambiosGuardados(object? sender, SavedChangesEventArgs e)
{
}
//public static Datos.BBDD ObtieneBBDD(string NombreConexion)
private static void GuardandoCambios(object? sender, SavingChangesEventArgs e)
{
}
public tscEmtusa(DbContextOptions<EmtusaContext> Opciones) : base(Opciones)
{
if (_Ip == null) { ip = tsEFCore8.bbdd.ObtieneIPMysql(this); }
else { ip = _Ip; }
}
public void AñadeObjeto(object Registro)
{
this.Add(Registro);
}
public bool CompruebaUnico(EstadosAplicacion estado, string NombreCampo, object Valor, string NombreTablaBase, object DataContext)
{
return this.CompruebaRegistroUnico(estado == EstadosAplicacion.ModificandoRegistro, "bdEmtusa.db", NombreTablaBase, NombreCampo, Valor, DataContext);
}
public void EliminaObjeto(object Registro)
{
if (this.Entry(Registro).State == Microsoft.EntityFrameworkCore.EntityState.Detached)
{
this.Entry(Registro).State = Microsoft.EntityFrameworkCore.EntityState.Unchanged;
}
else if (this.Entry(Registro).State == Microsoft.EntityFrameworkCore.EntityState.Added)
{
this.Remove(Registro);
this.Entry(Registro).State = Microsoft.EntityFrameworkCore.EntityState.Unchanged;
}
else
{
this.Remove(Registro);
}
}
public int GuardarCambios()
{
return this.SaveChanges();
}
public bool HayModificaciones()
{
return this.ChangeTracker.HasChanges();
}
public int ObtieneLongitudCampo(string NombreTablaBase, string NombreCampo)
{
return this.ObtieneMaximaLongitudCampo("bdEmtusa.db", NombreTablaBase, NombreCampo);
}
}
}