diff --git a/SMGen.Data/DbModels/TransizioneIngressiModel.cs b/SMGen.Data/DbModels/TransizioneIngressiModel.cs new file mode 100644 index 0000000..a2e4a04 --- /dev/null +++ b/SMGen.Data/DbModels/TransizioneIngressiModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SMGen.Data.DbModels +{ + [Table("TransizioneIngressi")] + public class TransizioneIngressiModel + { + public int IdxFamigliaIngresso { get; set; } = 0; + public int IdxMicroStato { get; set; } = 0; + public int ValoreIngresso { get; set; } = 0; + public int IdxTipoEvento { get; set; } = 0; + public int next_IdxMicroStato { get; set; } = 0; + } +} diff --git a/SMGen.Data/DbModels/TransizioneIngressiTempModel.cs b/SMGen.Data/DbModels/TransizioneIngressiTempModel.cs new file mode 100644 index 0000000..13ce3c1 --- /dev/null +++ b/SMGen.Data/DbModels/TransizioneIngressiTempModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SMGen.Data.DbModels +{ + [Table("TransizioneIngressi_Chk")] + public class TransizioneIngressiTempModel + { + public int IdxFamigliaIngresso { get; set; } = 0; + public int IdxMicroStato { get; set; } = 0; + public int ValoreIngresso { get; set; } = 0; + public int IdxTipoEvento { get; set; } = 0; + public int next_IdxMicroStato { get; set; } = 0; + } +} diff --git a/SMGen.Data/SMGDataContext.cs b/SMGen.Data/SMGDataContext.cs new file mode 100644 index 0000000..dd1bee3 --- /dev/null +++ b/SMGen.Data/SMGDataContext.cs @@ -0,0 +1,100 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.Extensions.Configuration; +using NLog; +using SMGen.Data.DbModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SMGen.Data +{ + public partial class SMGDataContext : DbContext + { + public SMGDataContext() + { } + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + private IConfiguration _configuration; + public SMGDataContext(IConfiguration configuration) + { + _configuration = configuration; + + try + { + Database.Migrate(); + } + catch (Exception exc) + { + Log.Error(exc, "Exception during context initialization 011"); + } + } + + public SMGDataContext(DbContextOptions options, IConfiguration configuration) + { + _configuration = configuration; + bool disableMigrate = _configuration.GetValue("SetupOpt:DisableMigrate"); + if (!disableMigrate) + { + try + { + // se non ci fosse... crea o migra! + Database.Migrate(); + } + catch (Exception exc) + { + Log.Error(exc, "Exception during context initialization 02"); + } + } + } + + public virtual DbSet DbSetTranIngTemp { get; set; } = null!; + + public void DbForceMigrate() + { + // verifico SE devo eseguire la migration del DB IDENT... + bool disableMigrate = _configuration.GetValue("SetupOpt:DisableMigrate"); + if (!disableMigrate) + { + try + { + // se non ci fosse... crea o migra! + Database.Migrate(); + Log.Info("DbForceMigrate: done!"); + } + catch (Exception exc) + { + Log.Error(exc, "DbForceMigrate: Exception during context initialization 01"); + } + } + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) + { + string connString = _configuration.GetConnectionString("WDC.DB"); + if (!string.IsNullOrEmpty(connString)) + { + optionsBuilder.UseSqlServer(connString); + } + else + { + optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro;Trusted_Connection=True;"); + } + } + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.UseCollation("Latin1_General_CI_AS"); + modelBuilder.Entity().HasKey(c => new { c.IdxFamigliaIngresso, c.IdxMicroStato, c.ValoreIngresso }); + + OnModelCreatingPartial(modelBuilder); + } + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); + } +} diff --git a/SMGen.Data/SMGen.Data.csproj b/SMGen.Data/SMGen.Data.csproj new file mode 100644 index 0000000..88c10e8 --- /dev/null +++ b/SMGen.Data/SMGen.Data.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + diff --git a/SMGen.Data/SMGenDataContext.cs b/SMGen.Data/SMGenDataContext.cs new file mode 100644 index 0000000..8c5fb37 --- /dev/null +++ b/SMGen.Data/SMGenDataContext.cs @@ -0,0 +1,131 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using NLog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.Emit; +using System.Text; +using System.Threading.Tasks; + +namespace SMGen.Data +{ + public partial class SMGenDataContext : DbContext + { + #region Public Constructors + + public SMGenDataContext() + { + } + + public SMGenDataContext(IConfiguration configuration) + { + _configuration = configuration; + try + { + // se non ci fosse... crea o migra! + Database.Migrate(); + } + catch (Exception exc) + { + Log.Error(exc, "Exception during context initialization 02"); + } + } + + public SMGenDataContext(DbContextOptions options, IConfiguration configuration) : base(options) + { + _configuration = configuration; + // verifico SE devo eseguire la migration del DB IDENT... + bool disableMigrate = _configuration.GetValue("SetupOpt:DisableWDCMigrate"); + if (!disableMigrate) + { + try + { + // se non ci fosse... crea o migra! + Database.Migrate(); + } + catch (Exception exc) + { + Log.Error(exc, "Exception during context initialization 02"); + } + } + } + + #endregion Public Constructors + + #region Public Properties + + //public virtual DbSet DbSetCompany { get; set; } = null!; + + #endregion Public Properties + + #region Public Methods + + public void DbForceMigrate() + { + // verifico SE devo eseguire la migration del DB IDENT... + bool disableMigrate = _configuration.GetValue("SetupOpt:DisableWDCMigrate"); + if (!disableMigrate) + { + try + { + // se non ci fosse... crea o migra! + Database.Migrate(); + Log.Info("DbForceMigrate: done!"); + } + catch (Exception exc) + { + Log.Error(exc, "DbForceMigrate: Exception during context initialization 01"); + } + } + } + + #endregion Public Methods + + #region Protected Methods + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) + { + string connString = _configuration.GetConnectionString("WDC.DB"); + if (!string.IsNullOrEmpty(connString)) + { + optionsBuilder.UseSqlServer(connString); + } + else + { + //// dev + //optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=WebDoorCreator;Trusted_Connection=True;", e => e.UseHierarchyId()); + optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=WebDoorCreator;Trusted_Connection=True;"); + } + } + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.UseCollation("Latin1_General_CI_AS"); + + + //modelBuilder.Seed(); + + OnModelCreatingPartial(modelBuilder); + } + + #endregion Protected Methods + + #region Private Fields + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + private IConfiguration _configuration; + + #endregion Private Fields + + #region Private Methods + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); + + #endregion Private Methods + } +} diff --git a/SMGen.sln b/SMGen.sln index 3c6e444..7a6f2b3 100644 --- a/SMGen.sln +++ b/SMGen.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.6.33815.320 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SMGen", "SMGen\SMGen.csproj", "{1224887B-2A4F-433C-ADB6-51683E2ADBA7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SMGen.Data", "SMGen.Data\SMGen.Data.csproj", "{CF2D0A2F-DED0-4D5D-8C31-099B3C3ED16D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {1224887B-2A4F-433C-ADB6-51683E2ADBA7}.Debug|Any CPU.Build.0 = Debug|Any CPU {1224887B-2A4F-433C-ADB6-51683E2ADBA7}.Release|Any CPU.ActiveCfg = Release|Any CPU {1224887B-2A4F-433C-ADB6-51683E2ADBA7}.Release|Any CPU.Build.0 = Release|Any CPU + {CF2D0A2F-DED0-4D5D-8C31-099B3C3ED16D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF2D0A2F-DED0-4D5D-8C31-099B3C3ED16D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF2D0A2F-DED0-4D5D-8C31-099B3C3ED16D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF2D0A2F-DED0-4D5D-8C31-099B3C3ED16D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SMGen/SMGen.csproj b/SMGen/SMGen.csproj index cc62e30..6848d57 100644 --- a/SMGen/SMGen.csproj +++ b/SMGen/SMGen.csproj @@ -23,8 +23,21 @@ - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + diff --git a/SMGen/_Imports.razor b/SMGen/_Imports.razor index 69f5b5d..887b233 100644 --- a/SMGen/_Imports.razor +++ b/SMGen/_Imports.razor @@ -11,3 +11,4 @@ @using SMGen.Components @using EgwCoreLib.Razor @using EgwCoreLib.Razor.Data +@using SMGen.Data diff --git a/SMGen/appsettings.json b/SMGen/appsettings.json index 3c885dd..6552f87 100644 --- a/SMGen/appsettings.json +++ b/SMGen/appsettings.json @@ -5,6 +5,10 @@ "Microsoft.AspNetCore": "Warning" } }, + "ConnectionStrings": { + "Redis": "nkcredis.steamware.net:6379, DefaultDatabase=11, connectTimeout=5000, syncTimeout=5000, asyncTimeout=5000, abortConnect=false, ssl=false, password=BtN9Py1wtLfLRvmzWnOPJ7RytDM+CLiVsJ/16zduNTlV8IOPGNrtzJSXPUnImA5PqmUMhKaUqo9NdHIG", + "SMGen.DB": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=SMGen.UI;" + }, "ServerConf": { "ProcCsvRootPath": "Temp\\Rules\\PROCESSED" },