diff --git a/GLS.sln b/GLS.sln index eb1225c..159c20e 100644 --- a/GLS.sln +++ b/GLS.sln @@ -7,11 +7,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SteamWare", "..\SteamWare\S EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SteamWareGestioneLicenze", "GeLiSt\SteamWareGestioneLicenze.csproj", "{4F110C8C-7C12-4D40-BDE4-A577CCEAD330}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiMan.Serv", "LiMan.Serv\LiMan.Serv.csproj", "{A89BDE27-D52A-4AB8-91B0-FB0DC36C4BCB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LiMan.Serv", "LiMan.Serv\LiMan.Serv.csproj", "{A89BDE27-D52A-4AB8-91B0-FB0DC36C4BCB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiMan.DL", "LiMan.DL\LiMan.DL.csproj", "{D9E7520A-2CB8-403A-A147-B7880FA47ED8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LiMan.DL", "LiMan.DL\LiMan.DL.csproj", "{D9E7520A-2CB8-403A-A147-B7880FA47ED8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiMan.UI", "LiMan.UI\LiMan.UI.csproj", "{34200CA2-489C-435A-A60B-34DE7B7BA04D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LiMan.UI", "LiMan.UI\LiMan.UI.csproj", "{34200CA2-489C-435A-A60B-34DE7B7BA04D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/LiMan.DL/Class1.cs b/LiMan.DL/Class1.cs deleted file mode 100644 index c0de1ba..0000000 --- a/LiMan.DL/Class1.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace LiMan.DL -{ - public class Class1 - { - } -} diff --git a/LiMan.DL/Controllers/LicManController.cs b/LiMan.DL/Controllers/LicManController.cs new file mode 100644 index 0000000..dffd89e --- /dev/null +++ b/LiMan.DL/Controllers/LicManController.cs @@ -0,0 +1,94 @@ +using LiMan.DL.DatabaseModels; +using Microsoft.Extensions.Configuration; +using NLog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LiMan.DL.Controllers +{ + public class LicManController : IDisposable + { + #region Private Fields + + private static IConfiguration _configuration; + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + #endregion Private Fields + + #region Public Constructors + + public LicManController(IConfiguration configuration) + { + _configuration = configuration; + } + + #endregion Public Constructors + + #region Public Methods + + public bool DbForceMigrate() + { + bool answ = false; + using (LicManContext localDbCtx = new LicManContext(_configuration)) + { + try + { + localDbCtx.DbForceMigrate(); + answ = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione in DbForceMigrate"); + } + } + return answ; + } + + public void Dispose() + { + // Clear database context + //Log.Info("Dispose di GWMSController"); + } + + public List GetApplicazioni() + { + List dbResult = new List(); + using (LicManContext localDbCtx = new LicManContext(_configuration)) + { + dbResult = localDbCtx + .DbSetApplicazioni + .ToList(); + } + return dbResult; + } + + public List GetInstallazioni() + { + List dbResult = new List(); + using (LicManContext localDbCtx = new LicManContext(_configuration)) + { + dbResult = localDbCtx + .DbSetInstallazioni + .ToList(); + } + return dbResult; + } + + public List GetLicenze() + { + List dbResult = new List(); + using (LicManContext localDbCtx = new LicManContext(_configuration)) + { + dbResult = localDbCtx + .DbSetLicenzeAttive + .ToList(); + } + return dbResult; + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/LiMan.DL/DatabaseModels/AnagApplicazioni.cs b/LiMan.DL/DatabaseModels/AnagApplicazioni.cs new file mode 100644 index 0000000..e8d28ef --- /dev/null +++ b/LiMan.DL/DatabaseModels/AnagApplicazioni.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; + +#nullable disable + +namespace LiMan.DL.DatabaseModels +{ + public partial class AnagApplicazioni + { + public AnagApplicazioni() + { + LicenzeAttives = new HashSet(); + } + + public string Applicativo { get; set; } + public string Descrizione { get; set; } + + public virtual ICollection LicenzeAttives { get; set; } + } +} diff --git a/LiMan.DL/DatabaseModels/AnagInstallazioni.cs b/LiMan.DL/DatabaseModels/AnagInstallazioni.cs new file mode 100644 index 0000000..e006f01 --- /dev/null +++ b/LiMan.DL/DatabaseModels/AnagInstallazioni.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; + +#nullable disable + +namespace LiMan.DL.DatabaseModels +{ + public partial class AnagInstallazioni + { + public AnagInstallazioni() + { + LicenzeAttives = new HashSet(); + } + + public string Installazione { get; set; } + public string Descrizione { get; set; } + public string Contatto { get; set; } + public string Email { get; set; } + + public virtual ICollection LicenzeAttives { get; set; } + } +} diff --git a/LiMan.DL/DatabaseModels/LicManContext.cs b/LiMan.DL/DatabaseModels/LicManContext.cs new file mode 100644 index 0000000..4254283 --- /dev/null +++ b/LiMan.DL/DatabaseModels/LicManContext.cs @@ -0,0 +1,282 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.Extensions.Configuration; +using NLog; + +#nullable disable + +namespace LiMan.DL.DatabaseModels +{ + public partial class LicManContext : DbContext + { + #region Private Fields + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + private IConfiguration _configuration; + + #endregion Private Fields + + #region Public Constructors + + public LicManContext() + { + } + + public LicManContext(IConfiguration configuration) + { + _configuration = configuration; + } + + public LicManContext(DbContextOptions options) : base(options) + { + 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 DbSetApplicazioni { get; set; } + + public virtual DbSet DbSetInstallazioni { get; set; } + + public virtual DbSet DbSetLicenzeAttive { get; set; } + + public virtual DbSet DbSetLogUpdateDb { get; set; } + + public virtual DbSet DbSetPermessi { get; set; } + + public virtual DbSet DbSetPermessi2Funzione { get; set; } + + #endregion Public Properties + + #region Private Methods + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); + + #endregion Private Methods + + #region Protected Methods + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + // default + string connString = "Server=SQLSTEAM;Database=SteamWare_Auth;Trusted_Connection=True;"; + + // tento setup da config + try + { + string srv = _configuration["DbConfig:srv"]; + string db = _configuration["DbConfig:db"]; + string usr = _configuration["DbConfig:usr"]; + string pwd = _configuration["DbConfig:pwd"]; + + //DbConfig.InitDb(server, nKey, sKey); + //DbConfig.CheckUser(nKey, sKey); + + // uso conn string calcolata + connString = $"Server={srv};Database={db};User ID={usr}Password={pwd};"; + } + catch + { } + if (!optionsBuilder.IsConfigured) + { + optionsBuilder.UseSqlServer(connString); + } + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS"); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Applicativo); + + entity.ToTable("AnagApplicazioni"); + + entity.Property(e => e.Applicativo) + .HasMaxLength(50) + .HasColumnName("applicativo"); + + entity.Property(e => e.Descrizione) + .HasMaxLength(50) + .HasColumnName("descrizione"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Installazione); + + entity.ToTable("AnagInstallazioni"); + + entity.Property(e => e.Installazione) + .HasMaxLength(50) + .HasColumnName("installazione"); + + entity.Property(e => e.Contatto) + .HasMaxLength(50) + .HasColumnName("contatto"); + + entity.Property(e => e.Descrizione) + .HasMaxLength(50) + .HasColumnName("descrizione"); + + entity.Property(e => e.Email) + .HasMaxLength(50) + .HasColumnName("email"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.IdxLic) + .HasName("PK_AnagKeyValue"); + + entity.ToTable("LicenzeAttive"); + + entity.Property(e => e.IdxLic).HasColumnName("idxLic"); + + entity.Property(e => e.Applicativo) + .HasMaxLength(50) + .HasColumnName("applicativo") + .HasDefaultValueSql("(N'-')"); + + entity.Property(e => e.Descrizione) + .HasMaxLength(250) + .HasColumnName("descrizione") + .HasDefaultValueSql("('-')"); + + entity.Property(e => e.Installazione) + .HasMaxLength(50) + .HasColumnName("installazione") + .HasDefaultValueSql("(N'SteamWare')"); + + entity.Property(e => e.Licenza) + .HasMaxLength(250) + .HasColumnName("licenza") + .HasDefaultValueSql("('')"); + + entity.Property(e => e.NumLicenze) + .HasColumnName("numLicenze") + .HasDefaultValueSql("((0))"); + + entity.Property(e => e.Scadenza) + .HasColumnType("date") + .HasColumnName("scadenza"); + + entity.HasOne(d => d.ApplicativoNavigation) + .WithMany(p => p.LicenzeAttives) + .HasForeignKey(d => d.Applicativo) + .HasConstraintName("FK_AnagKeyValue_AnagApplicazioni"); + + entity.HasOne(d => d.InstallazioneNavigation) + .WithMany(p => p.LicenzeAttives) + .HasForeignKey(d => d.Installazione) + .HasConstraintName("FK_AnagKeyValue_AnagInstallazioni"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Versione); + + entity.ToTable("LogUpdateDb"); + + entity.Property(e => e.Versione).ValueGeneratedNever(); + + entity.Property(e => e.Data).HasColumnType("datetime"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.CodPermesso); + + entity.ToTable("Permessi"); + + entity.Property(e => e.CodPermesso) + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnName("COD_PERMESSO"); + + entity.Property(e => e.Descrizione) + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnName("DESCRIZIONE"); + + entity.Property(e => e.Gruppo).HasColumnName("GRUPPO"); + + entity.Property(e => e.Nome) + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnName("NOME"); + + entity.Property(e => e.Numero).HasColumnName("NUMERO"); + + entity.Property(e => e.Url) + .IsRequired() + .HasMaxLength(250) + .IsUnicode(false) + .HasColumnName("URL"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.CodPermesso, e.CodFunzione }); + + entity.ToTable("Permessi2Funzione"); + + entity.Property(e => e.CodPermesso) + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnName("COD_PERMESSO"); + + entity.Property(e => e.CodFunzione) + .HasMaxLength(31) + .HasColumnName("COD_FUNZIONE"); + + entity.Property(e => e.Readwrite) + .HasMaxLength(1) + .IsUnicode(false) + .HasColumnName("READWRITE") + .IsFixedLength(true); + + entity.HasOne(d => d.CodPermessoNavigation) + .WithMany(p => p.Permessi2Funziones) + .HasForeignKey(d => d.CodPermesso) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("FK_Permessi2Funzione_Permessi"); + }); + + OnModelCreatingPartial(modelBuilder); + } + + #endregion Protected Methods + + #region Public Methods + + public void DbForceMigrate() + { + 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 + } +} \ No newline at end of file diff --git a/LiMan.DL/DatabaseModels/LicenzeAttive.cs b/LiMan.DL/DatabaseModels/LicenzeAttive.cs new file mode 100644 index 0000000..201e443 --- /dev/null +++ b/LiMan.DL/DatabaseModels/LicenzeAttive.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +#nullable disable + +namespace LiMan.DL.DatabaseModels +{ + public partial class LicenzeAttive + { + public int IdxLic { get; set; } + public string Installazione { get; set; } + public string Applicativo { get; set; } + public int? NumLicenze { get; set; } + public string Licenza { get; set; } + public DateTime? Scadenza { get; set; } + public string Descrizione { get; set; } + + public virtual AnagApplicazioni ApplicativoNavigation { get; set; } + public virtual AnagInstallazioni InstallazioneNavigation { get; set; } + } +} diff --git a/LiMan.DL/DatabaseModels/LogUpdateDb.cs b/LiMan.DL/DatabaseModels/LogUpdateDb.cs new file mode 100644 index 0000000..3ac0ff4 --- /dev/null +++ b/LiMan.DL/DatabaseModels/LogUpdateDb.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +#nullable disable + +namespace LiMan.DL.DatabaseModels +{ + public partial class LogUpdateDb + { + public int Versione { get; set; } + public DateTime? Data { get; set; } + } +} diff --git a/LiMan.DL/DatabaseModels/Permessi.cs b/LiMan.DL/DatabaseModels/Permessi.cs new file mode 100644 index 0000000..d60e95d --- /dev/null +++ b/LiMan.DL/DatabaseModels/Permessi.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; + +#nullable disable + +namespace LiMan.DL.DatabaseModels +{ + public partial class Permessi + { + public Permessi() + { + Permessi2Funziones = new HashSet(); + } + + public string CodPermesso { get; set; } + public string Url { get; set; } + public int? Gruppo { get; set; } + public int? Numero { get; set; } + public string Nome { get; set; } + public string Descrizione { get; set; } + + public virtual ICollection Permessi2Funziones { get; set; } + } +} diff --git a/LiMan.DL/DatabaseModels/Permessi2Funzione.cs b/LiMan.DL/DatabaseModels/Permessi2Funzione.cs new file mode 100644 index 0000000..5dda7cb --- /dev/null +++ b/LiMan.DL/DatabaseModels/Permessi2Funzione.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; + +#nullable disable + +namespace LiMan.DL.DatabaseModels +{ + public partial class Permessi2Funzione + { + public string CodPermesso { get; set; } + public string CodFunzione { get; set; } + public string Readwrite { get; set; } + + public virtual Permessi CodPermessoNavigation { get; set; } + } +} diff --git a/LiMan.DL/LiMan.DL.csproj b/LiMan.DL/LiMan.DL.csproj index f208d30..5178c83 100644 --- a/LiMan.DL/LiMan.DL.csproj +++ b/LiMan.DL/LiMan.DL.csproj @@ -1,7 +1,22 @@ - + net5.0 - + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + \ No newline at end of file diff --git a/LiMan.Serv/LiMan.Serv.csproj b/LiMan.Serv/LiMan.Serv.csproj index 2884716..c547363 100644 --- a/LiMan.Serv/LiMan.Serv.csproj +++ b/LiMan.Serv/LiMan.Serv.csproj @@ -8,4 +8,8 @@ + + + + diff --git a/LiMan.UI/Components/CmpFooter.razor b/LiMan.UI/Components/CmpFooter.razor new file mode 100644 index 0000000..e85aaf3 --- /dev/null +++ b/LiMan.UI/Components/CmpFooter.razor @@ -0,0 +1,16 @@ +
+
+ GWMS v.@version +
+
+ @adesso + Egalware +
+
+ +@code { + protected DateTime adesso = DateTime.Now; + + Version version = typeof(Program).Assembly.GetName().Version; + +} \ No newline at end of file diff --git a/LiMan.UI/Components/CmpTop.razor b/LiMan.UI/Components/CmpTop.razor new file mode 100644 index 0000000..436c6a1 --- /dev/null +++ b/LiMan.UI/Components/CmpTop.razor @@ -0,0 +1,80 @@ +@using LiMan.UI.Components +@using System.Security.Claims +@using Microsoft.AspNetCore.Components.Authorization +@using LiMan.UI.Data + +@inject MessageService AppMessages +@inject AuthenticationStateProvider AuthenticationStateProvider + +
+
+ @**@ +
+
+ @PageName +
+
+ @if (ShowSearch) + { + + } +
+
+ +@code { + + [CascadingParameter] + private Task AuthenticationStateTask { get; set; } + + [CascadingParameter(Name = "ShowSearch")] + private bool ShowSearch { get; set; } + + private string userName = ""; + + private string PageName { get; set; } + private string PageIcon { get; set; } + + protected override async Task OnInitializedAsync() + { + await forceReload(); + } + + protected override void OnInitialized() + { + AppMessages.EA_PageUpdated += OnPageUpdate; + } + public void OnPageUpdate() + { + PageName = AppMessages.PageName; + PageIcon = AppMessages.PageIcon; + InvokeAsync(() => + { + StateHasChanged(); + }); + } + + public void Dispose() + { + AppMessages.EA_PageUpdated -= OnPageUpdate; + } + + private async Task forceReload() + { + + var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + var user = authState.User; + + if (user.Identity.IsAuthenticated) + { + userName = $"{user.Identity.Name}"; + } + else + { + userName = "N.A."; + } + } +} + +@* // Vedere anche: + // https://docs.microsoft.com/en-us/aspnet/core/blazor/security/?view=aspnetcore-5.0#:~:text=Blazor%20uses%20the%20existing%20ASP.NET%20Core%20authentication%20mechanisms,all%20client-side%20code%20can%20be%20modified%20by%20users + // https://docs.microsoft.com/en-us/aspnet/core/blazor/security/?view=aspnetcore-5.0*@ \ No newline at end of file diff --git a/LiMan.UI/Components/DataPager.razor b/LiMan.UI/Components/DataPager.razor new file mode 100644 index 0000000..3d577d1 --- /dev/null +++ b/LiMan.UI/Components/DataPager.razor @@ -0,0 +1,56 @@ +
+
+
+
+ @if (totalCount > 0) + { +
    +
  • +
  • + @for (int i = @startPage; i <= endPage; ++i) + { + var pageNum = i; +
  • + } +
  • +
  • +
+ } +
+
+
+
+ @if (showLoading) + { +
+
+
+ } +
+
+
+
+
+
+ @if (!showLoading) + { + @totalCount records + } +
+
+ @if (totalCount > 0) + { +
+ +
+ } +
+
+
+
\ No newline at end of file diff --git a/LiMan.UI/Components/DataPager.razor.cs b/LiMan.UI/Components/DataPager.razor.cs new file mode 100644 index 0000000..99fe3f2 --- /dev/null +++ b/LiMan.UI/Components/DataPager.razor.cs @@ -0,0 +1,193 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; +using LiMan.UI.Components; +using LiMan.UI.Data; + +namespace LiMan.UI.Components +{ + public partial class DataPager : ComponentBase + { + #region Protected Fields + + protected bool _showLoading = false; + + #endregion Protected Fields + + #region Private Properties + + private int endPage + { + get + { + int answ = (int)(currPage / numPages) * numPages + numPages; + answ = answ < LastPage ? answ : LastPage; + return answ; + } + } + + private int LastPage + { + get + { + return Math.Max((int)Math.Ceiling(totalCount / (double)PageSize), 1); + } + } + + private int nextBlock + { + get + { + int answ = currPage + numPages; + answ = answ < LastPage ? answ : LastPage; + return answ; + } + } + + private int numPages { get; set; } = 10; + + private int prevBlock + { + get + { + int answ = currPage - numPages; + answ = answ > 0 ? answ : 1; + return answ; + } + } + + // calcola un set 1 .. numPages centrato sulla pagina corrente... + private int startPage + { + get + { + int answ = (int)(currPage / numPages) * numPages; + answ = answ > 0 ? answ : 1; + return answ; + } + } + + #endregion Private Properties + + #region Protected Properties + + protected int _numPage { get; set; } = 1; + + protected int _numRecord { get; set; } = 10; + + protected int percLoading { get; set; } = 0; + + #endregion Protected Properties + + #region Public Properties + + [Parameter] + public int currPage + { + get + { + return _numPage; + } + set + { + bool doReport = !_numPage.Equals(value); + if (doReport) + { + _numPage = value; + reportChangePage(); + } + } + } + + [Parameter] + public EventCallback numPageChanged { get; set; } + + [Parameter] + public EventCallback numRecordChanged { get; set; } + + [Parameter] + public int PageSize + { + get + { + return _numRecord; + } + set + { + bool doReport = !_numRecord.Equals(value); + if (doReport) + { + _numRecord = value; + reportChange(); + } + } + } + + [Parameter] + public bool showLoading + { + get + { + return _showLoading; + } + set + { + if (value) + { + Random random = new Random(); + percLoading = random.Next(30, 90); + } + else + { + percLoading = 5; + } + _showLoading = value; + } + } + + [Parameter] + public int totalCount { get; set; } = 0; + + #endregion Public Properties + + #region Private Methods + + private void reportChange() + { + numRecordChanged.InvokeAsync(PageSize); + } + + private void reportChangePage() + { + numPageChanged.InvokeAsync(currPage); + } + + #endregion Private Methods + + #region Protected Methods + + protected string cssActive(int numPage) + { + string answ = ""; + if (numPage == currPage) + { + answ = "active"; + } + return answ; + } + + protected override async Task OnInitializedAsync() + { + await Task.Run(() => showLoading = false); + } + + protected void PaginationItemClick(int page) + { + currPage = page; + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/LiMan.UI/Components/LoadingData.razor b/LiMan.UI/Components/LoadingData.razor new file mode 100644 index 0000000..2aa1799 --- /dev/null +++ b/LiMan.UI/Components/LoadingData.razor @@ -0,0 +1,7 @@ +@*

Working

*@ +
+
+

loading data

+ +
+
\ No newline at end of file diff --git a/LiMan.UI/Components/LoginDisplay.razor b/LiMan.UI/Components/LoginDisplay.razor new file mode 100644 index 0000000..c840f5c --- /dev/null +++ b/LiMan.UI/Components/LoginDisplay.razor @@ -0,0 +1,61 @@ +@using Microsoft.AspNetCore.Components.Authorization + +@inject AuthenticationStateProvider AuthenticationStateProvider + + + + + + +
+
+ +
+
+  @userName +
+
+
+
+ +@code{ + + private string userName = ""; + protected override async Task OnInitializedAsync() + { + await forceReload(); + } + private async Task forceReload() + { + + var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + var user = authState.User; + + if (user.Identity.IsAuthenticated) + { + userName = $"{user.Identity.Name}"; + } + else + { + userName = "Non Autenticato"; + } + } + + protected string StringLim(string original, int maxLen) + { + return original.Length <= maxLen ? original : $"{original.Substring(0, maxLen - 3)}..."; + } + +} \ No newline at end of file diff --git a/LiMan.UI/Components/SearchMod.razor b/LiMan.UI/Components/SearchMod.razor new file mode 100644 index 0000000..5250642 --- /dev/null +++ b/LiMan.UI/Components/SearchMod.razor @@ -0,0 +1,41 @@ +@using LiMan.UI.Components +@using LiMan.UI.Data +@inject MessageService MessageService + +
+ +
+ +
+
+ +@code { + + [Parameter] + public EventCallback searchUpdated { get; set; } + + [Parameter] + public string searchVal + { + get + { + return MessageService.SearchVal; + } + set + { + MessageService.SearchVal = value; + reportChange(); + } + } + + private void reportChange() + { + searchUpdated.InvokeAsync(searchVal); + } + + private void reset() + { + searchVal = ""; + } + +} \ No newline at end of file diff --git a/LiMan.UI/Data/LiManDataService.cs b/LiMan.UI/Data/LiManDataService.cs new file mode 100644 index 0000000..959fbc6 --- /dev/null +++ b/LiMan.UI/Data/LiManDataService.cs @@ -0,0 +1,213 @@ +using Microsoft.Extensions.Caching.Distributed; +using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using NLog; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LiMan.UI.Data +{ + public class LiManDataService : IDisposable + { + #region Private Fields + + private static IConfiguration _configuration; + private static ILogger _logger; + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + private readonly IDistributedCache distributedCache; + private readonly IMemoryCache memoryCache; + + /// + /// Durata assoluta massima della cache IN SECONDI + /// + private int chAbsExp = 60 * 5; + + /// + /// Durata della cache IN SECONDI in modalità inattiva (non acceduta) prima di venire rimossa + /// NON estende oltre il tempo massimo di validità della cache (chAbsExp) + /// + private int chSliExp = 60 * 1; + + #endregion Private Fields + + #region Protected Fields + + protected static string connStringBBM = ""; + + #endregion Protected Fields + + #region Public Fields + + public static LiMan.DL.Controllers.LicManController dbController; + + #endregion Public Fields + + #region Public Constructors + + public LiManDataService(IConfiguration configuration, ILogger logger, IMemoryCache memoryCache, IDistributedCache distributedCache) + { + _logger = logger; + _configuration = configuration; + // conf cache + this.memoryCache = memoryCache; + this.distributedCache = distributedCache; + // conf DB + string connStr = _configuration.GetConnectionString("GWMS.Data"); + if (string.IsNullOrEmpty(connStr)) + { + _logger.LogError("ConnString empty!"); + } + else + { + dbController = new LiMan.DL.Controllers.LicManController(configuration); + } + } + + #endregion Public Constructors + + #region Private Methods + + private DistributedCacheEntryOptions cacheOpt(bool fastCache) + { + var numSecAbsExp = fastCache ? chAbsExp : chAbsExp * 10; + var numSecSliExp = fastCache ? chSliExp : chSliExp * 10; + return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddSeconds(numSecAbsExp)).SetSlidingExpiration(TimeSpan.FromSeconds(numSecSliExp)); + } + + #endregion Private Methods + + #region Protected Methods + + protected string getCacheKey(string TableName, SelectData CurrFilter) + { + string answ = $"{TableName}:D_{CurrFilter.DateStart:yyyyMMddHHmm}_{CurrFilter.DateEnd:yyyyMMddHHmm}"; + return answ; + } + + #endregion Protected Methods + + #region Public Methods + + /// + /// Hash Redis contenente i dati MP di una specifico TYPE (es StatusMacchina, StateMachineIngressi, ...) + /// + /// + /// + public static string mHash(string dataType) + { + return $"DATA:{dataType}"; + } + + public async Task> ApplicazioniGetAll() + { + List dbResult = new List(); + string cacheKey = mHash("Applicazioni"); + string rawData; + var redisDataList = await distributedCache.GetAsync(cacheKey); + if (redisDataList != null) + { + rawData = Encoding.UTF8.GetString(redisDataList); + dbResult = JsonConvert.DeserializeObject>(rawData); + } + else + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + dbResult = dbController.GetApplicazioni(); + rawData = JsonConvert.SerializeObject(dbResult); + redisDataList = Encoding.UTF8.GetBytes(rawData); + await distributedCache.SetAsync(cacheKey, redisDataList, cacheOpt(false)); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Effettuata lettura da DB + caching per ApplicazioniGetAll: {ts.TotalMilliseconds} ms"); + } + return await Task.FromResult(dbResult); + } + + public async Task DbForceMigrate() + { + return await Task.FromResult(dbController.DbForceMigrate()); + } + + public void Dispose() + { + // Clear database controller + dbController.Dispose(); + } + + public async Task> InstallazioniGetAll() + { + List dbResult = new List(); + string cacheKey = mHash("Installazioni"); + string rawData; + var redisDataList = await distributedCache.GetAsync(cacheKey); + if (redisDataList != null) + { + rawData = Encoding.UTF8.GetString(redisDataList); + dbResult = JsonConvert.DeserializeObject>(rawData); + } + else + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + dbResult = dbController.GetInstallazioni(); + rawData = JsonConvert.SerializeObject(dbResult); + redisDataList = Encoding.UTF8.GetBytes(rawData); + await distributedCache.SetAsync(cacheKey, redisDataList, cacheOpt(false)); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Effettuata lettura da DB + caching per InstallazioniGetAll: {ts.TotalMilliseconds} ms"); + } + return await Task.FromResult(dbResult); + } + + /// + /// invalida tutta la cache in caso di update + /// + /// + public async Task InvalidateAllCache() + { + await distributedCache.RemoveAsync(mHash("Applicazioni")); + await distributedCache.RemoveAsync(mHash("Installazioni")); + await distributedCache.RemoveAsync(mHash("Licenze")); + //await distributedCache.RemoveAsync(mHash("SUPPL:List")); + //await distributedCache.RemoveAsync(mHash("TRANSP:List")); + //await distributedCache.RemoveAsync(mHash("WEEKPLAN:List")); + } + + public async Task> LicenzeGetAll() + { + List dbResult = new List(); + string cacheKey = mHash("Licenze"); + string rawData; + var redisDataList = await distributedCache.GetAsync(cacheKey); + if (redisDataList != null) + { + rawData = Encoding.UTF8.GetString(redisDataList); + dbResult = JsonConvert.DeserializeObject>(rawData); + } + else + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + dbResult = dbController.GetLicenze(); + rawData = JsonConvert.SerializeObject(dbResult); + redisDataList = Encoding.UTF8.GetBytes(rawData); + await distributedCache.SetAsync(cacheKey, redisDataList, cacheOpt(false)); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Effettuata lettura da DB + caching per LicenzeGetAll: {ts.TotalMilliseconds} ms"); + } + return await Task.FromResult(dbResult); + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/LiMan.UI/Data/MessageService.cs b/LiMan.UI/Data/MessageService.cs new file mode 100644 index 0000000..30c7a4e --- /dev/null +++ b/LiMan.UI/Data/MessageService.cs @@ -0,0 +1,147 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LiMan.UI.Data +{ + public class MessageService + { + #region Private Fields + + private SelectData _detailFilter = SelectData.Init(5, 15); + private string _pageIcon; + private string _pageName; + private string _searchVal; + private bool showSearch; + + #endregion Private Fields + + #region Public Events + + public event Action EA_FilterUpdated; + + public event Action EA_HideSearch; + + public event Action EA_PageUpdated; + + public event Action EA_SearchUpdated; + + public event Action EA_ShowSearch; + + #endregion Public Events + + #region Public Properties + + public SelectData DetailFilter + { + get => _detailFilter; + set + { + if (_detailFilter != value) + { + _detailFilter = value; + + if (EA_FilterUpdated != null) + { + EA_FilterUpdated?.Invoke(); + } + } + } + } + + public string PageIcon + { + get => _pageIcon; + set + { + if (_pageIcon != value) + { + _pageIcon = value; + ReportPageUpd(); + } + } + } + + public string PageName + { + get => _pageName; + set + { + if (_pageName != value) + { + _pageName = value; + ReportPageUpd(); + } + } + } + + public int PageNum { get; set; } = 1; + public int PageSize { get; set; } = 10; + + public string SearchVal + { + get => _searchVal; + set + { + if (_searchVal != value) + { + _searchVal = value; + + if (EA_SearchUpdated != null) + { + EA_SearchUpdated?.Invoke(); + } + } + } + } + + public bool ShowSearch + { + get => showSearch; + set + { + if (showSearch != value) + { + showSearch = value; + if (showSearch) + { + if (EA_ShowSearch != null) + { + EA_ShowSearch?.Invoke(); + } + } + else + { + if (EA_HideSearch != null) + { + EA_HideSearch?.Invoke(); + } + } + } + } + } + + #endregion Public Properties + + #region Private Methods + + private void ReportPageUpd() + { + if (EA_PageUpdated != null) + { + EA_PageUpdated?.Invoke(); + } + } + + private void ReportSearch() + { + if (EA_SearchUpdated != null) + { + EA_SearchUpdated?.Invoke(); + } + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/LiMan.UI/Data/SelectData.cs b/LiMan.UI/Data/SelectData.cs new file mode 100644 index 0000000..baf2d6e --- /dev/null +++ b/LiMan.UI/Data/SelectData.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LiMan.UI.Data +{ + public class SelectData + { + #region Public Properties + + public DateTime DateEnd { get; set; } = DateTime.Now.AddMinutes(1); + public DateTime DateStart { get; set; } = DateTime.Now.AddDays(-7); + + #endregion Public Properties + + #region Public Methods + + /// + /// Inizializzazione con periodo e arrotondamento + /// + /// + /// + /// + public static SelectData Init(int minRound, int numDayPrev) + { + DateTime endRounded = DateTime.Today.AddDays(1); + SelectData answ = new SelectData() + { + DateEnd = endRounded, + DateStart = endRounded.AddDays(-numDayPrev) + }; + return answ; + } + + public override bool Equals(object obj) + { + if (!(obj is SelectData item)) + return false; + + if (DateEnd != item.DateEnd) + return false; + if (DateStart != item.DateStart) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/LiMan.UI/Data/WeatherForecast.cs b/LiMan.UI/Data/WeatherForecast.cs deleted file mode 100644 index 2c90a40..0000000 --- a/LiMan.UI/Data/WeatherForecast.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace LiMan.UI.Data -{ - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string Summary { get; set; } - } -} diff --git a/LiMan.UI/Data/WeatherForecastService.cs b/LiMan.UI/Data/WeatherForecastService.cs deleted file mode 100644 index 6244b8f..0000000 --- a/LiMan.UI/Data/WeatherForecastService.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Linq; -using System.Threading.Tasks; - -namespace LiMan.UI.Data -{ - public class WeatherForecastService - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - public Task GetForecastAsync(DateTime startDate) - { - var rng = new Random(); - return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = startDate.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] - }).ToArray()); - } - } -} diff --git a/LiMan.UI/LiMan.UI.csproj b/LiMan.UI/LiMan.UI.csproj index 5c3a051..39a7dac 100644 --- a/LiMan.UI/LiMan.UI.csproj +++ b/LiMan.UI/LiMan.UI.csproj @@ -1,22 +1,34 @@ - + - - net5.0 - + + net5.0 + - - - + + + - - - - - - - - - - + + + + + + + + + + - + + + + + + + + + + + + + \ No newline at end of file diff --git a/LiMan.UI/Pages/Applicazioni.razor b/LiMan.UI/Pages/Applicazioni.razor new file mode 100644 index 0000000..cbe8621 --- /dev/null +++ b/LiMan.UI/Pages/Applicazioni.razor @@ -0,0 +1,170 @@ +@page "/Applicazioni" + +@using LiMan.UI.Components + +
+
+
+
+
+
+

Elenco Programmi

+
+
+
+ @**@ +
+
+
+
+ @*
+
+
+
+ +
+
+
+
+
+ + + +
+ +
+
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+ @if (!string.IsNullOrEmpty(SelFileName)) + { + @TextReduce(SelFileName, 20) + } +
+
+
+
+ + Tags +
+
+ @if (!string.IsNullOrEmpty(SelTag)) + { + @SelTag + } + else + { +   ...   + } +
+
+ +
+
+ @if (DeleteDialogOpen) + { + + } +
+
+
*@ +
+
+
+ @if (currRecord != null) + { + @**@ + } + @if (ListRecords == null) + { + + } + else if (totalCount == 0) + { +
Nessun record trovato
+ } + else + { +
+
+ + + + + + + + + + @foreach (var record in ListRecords) + { + + + + + + } + +
ApplicazioneDescrizione
+ @if (currRecord == null) + { + + } + else + { + + } + + @record.Applicativo + +
@record.Descrizione
+
+
+
+ } +
+ +
\ No newline at end of file diff --git a/LiMan.UI/Pages/Applicazioni.razor.cs b/LiMan.UI/Pages/Applicazioni.razor.cs new file mode 100644 index 0000000..0180a5d --- /dev/null +++ b/LiMan.UI/Pages/Applicazioni.razor.cs @@ -0,0 +1,149 @@ +using LiMan.DL.DatabaseModels; +using LiMan.UI.Data; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LiMan.UI.Pages +{ + public partial class Applicazioni : ComponentBase, IDisposable + { + #region Private Fields + + private AnagApplicazioni currRecord = null; + private List ListRecords; + private List SearchRecords; + + #endregion Private Fields + + #region Protected Fields + + protected int totalCount = 0; + + #endregion Protected Fields + + #region Private Properties + + private int currPage + { + get + { + return AppMService.PageNum; + } + set + { + AppMService.PageNum = value; + } + } + + private bool isLoading { get; set; } = false; + + private int numRecord + { + get + { + return AppMService.PageSize; + } + set + { + AppMService.PageSize = value; + } + } + + #endregion Private Properties + + #region Protected Properties + + [Inject] + protected MessageService AppMService { get; set; } + + [Inject] + protected LiManDataService DataService { get; set; } + + [Inject] + protected IJSRuntime JSRuntime { get; set; } + + [Inject] + protected NavigationManager NavManager { get; set; } + + protected bool showCamera { get; set; } = false; + + #endregion Protected Properties + + #region Private Methods + + private async Task ReloadAllData() + { + isLoading = true; + await Task.Delay(1); + //ListRecords = null; + SearchRecords = await DataService.ApplicazioniGetAll(); + totalCount = SearchRecords.Count(); + ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); + isLoading = false; + } + + #endregion Private Methods + + #region Protected Methods + + protected void Edit(AnagApplicazioni selRecord) + { + currRecord = selRecord; + } + + protected override async Task OnInitializedAsync() + { + AppMService.ShowSearch = false; + AppMService.PageName = "Installazioni"; + AppMService.PageIcon = "fas fa-gas-pump pr-2"; + await ReloadAllData(); + } + + protected async Task PagerReloadNum(int newNum) + { + numRecord = newNum; + await ReloadAllData(); + isLoading = false; + } + + protected async Task PagerReloadPage(int newNum) + { + currPage = newNum; + await ReloadAllData(); + isLoading = false; + } + + protected void ResetData() + { + } + + #endregion Protected Methods + + #region Public Methods + + public string checkSelect(string Applicativo) + { + string answ = ""; + if (currRecord != null) + { + try + { + answ = (currRecord.Applicativo == Applicativo) ? "table-info" : ""; + } + catch + { } + } + return answ; + } + + public void Dispose() + { + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/LiMan.UI/Pages/Counter.razor b/LiMan.UI/Pages/Counter.razor deleted file mode 100644 index 8641f78..0000000 --- a/LiMan.UI/Pages/Counter.razor +++ /dev/null @@ -1,16 +0,0 @@ -@page "/counter" - -

Counter

- -

Current count: @currentCount

- - - -@code { - private int currentCount = 0; - - private void IncrementCount() - { - currentCount++; - } -} diff --git a/LiMan.UI/Pages/FetchData.razor b/LiMan.UI/Pages/FetchData.razor deleted file mode 100644 index 8f819d9..0000000 --- a/LiMan.UI/Pages/FetchData.razor +++ /dev/null @@ -1,46 +0,0 @@ -@page "/fetchdata" - -@using LiMan.UI.Data -@inject WeatherForecastService ForecastService - -

Weather forecast

- -

This component demonstrates fetching data from a service.

- -@if (forecasts == null) -{ -

Loading...

-} -else -{ - - - - - - - - - - - @foreach (var forecast in forecasts) - { - - - - - - - } - -
DateTemp. (C)Temp. (F)Summary
@forecast.Date.ToShortDateString()@forecast.TemperatureC@forecast.TemperatureF@forecast.Summary
-} - -@code { - private WeatherForecast[] forecasts; - - protected override async Task OnInitializedAsync() - { - forecasts = await ForecastService.GetForecastAsync(DateTime.Now); - } -} diff --git a/LiMan.UI/Pages/Installazioni.razor b/LiMan.UI/Pages/Installazioni.razor new file mode 100644 index 0000000..248d255 --- /dev/null +++ b/LiMan.UI/Pages/Installazioni.razor @@ -0,0 +1,3 @@ +@page "/Installazioni" + +

Installazioni

\ No newline at end of file diff --git a/LiMan.UI/Pages/Installazioni.razor.cs b/LiMan.UI/Pages/Installazioni.razor.cs new file mode 100644 index 0000000..8a3e53f --- /dev/null +++ b/LiMan.UI/Pages/Installazioni.razor.cs @@ -0,0 +1,80 @@ +using LiMan.DL.DatabaseModels; +using LiMan.UI.Data; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LiMan.UI.Pages +{ + public partial class Installazioni : ComponentBase, IDisposable + { + #region Private Fields + + private List PlantsList; + + #endregion Private Fields + + #region Private Properties + + private bool isLoading { get; set; } = false; + + #endregion Private Properties + + #region Protected Properties + + [Inject] + protected LiManDataService DataService { get; set; } + + [Inject] + protected IJSRuntime JSRuntime { get; set; } + + [Inject] + protected MessageService MessageService { get; set; } + + [Inject] + protected NavigationManager NavManager { get; set; } + + protected bool showCamera { get; set; } = false; + + #endregion Protected Properties + + #region Private Methods + + private async Task ReloadAllData() + { + isLoading = true; + PlantsList = null; + PlantsList = await DataService.InstallazioniGetAll(); + isLoading = false; + } + + #endregion Private Methods + + #region Protected Methods + + protected override async Task OnInitializedAsync() + { + MessageService.ShowSearch = false; + MessageService.PageName = "Installazioni"; + MessageService.PageIcon = "fas fa-gas-pump pr-2"; + await ReloadAllData(); + } + + protected void ResetData() + { + } + + #endregion Protected Methods + + #region Public Methods + + public void Dispose() + { + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/LiMan.UI/Pages/LicenseManager.razor b/LiMan.UI/Pages/LicenseManager.razor new file mode 100644 index 0000000..9e47c29 --- /dev/null +++ b/LiMan.UI/Pages/LicenseManager.razor @@ -0,0 +1,5 @@ +

LicenseManager

+ +@code { + +} diff --git a/LiMan.UI/Program.cs b/LiMan.UI/Program.cs index f7275f2..72740c5 100644 --- a/LiMan.UI/Program.cs +++ b/LiMan.UI/Program.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using NLog.Web; using System; using System.Collections.Generic; using System.Linq; @@ -11,16 +12,45 @@ namespace LiMan.UI { public class Program { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } + #region Public Methods public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) + Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); - }); + }) + .ConfigureLogging(logging => + { + logging.ClearProviders(); + logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); + }) + .UseNLog(); + + public static void Main(string[] args) + { + // inclusione NLog: + // https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-5 + // https://codewithmukesh.com/blog/logging-with-nlog-in-aspnet-core/ + var logger = NLog.Web.NLogBuilder.ConfigureNLog("NLog.config").GetCurrentClassLogger(); + try + { + logger.Info("LiMan.UI Application Starting Up"); + CreateHostBuilder(args).Build().Run(); + } + catch (Exception exception) + { + logger.Error(exception, "Stopped LiMan.UI program because of exception"); + throw; + } + finally + { + NLog.LogManager.Shutdown(); + } + + //CreateHostBuilder(args).Build().Run(); + } + + #endregion Public Methods } -} +} \ No newline at end of file diff --git a/LiMan.UI/Shared/NavMenu.razor b/LiMan.UI/Shared/NavMenu.razor index 8379df0..8663815 100644 --- a/LiMan.UI/Shared/NavMenu.razor +++ b/LiMan.UI/Shared/NavMenu.razor @@ -13,13 +13,13 @@ @@ -34,4 +34,4 @@ { collapseNavMenu = !collapseNavMenu; } -} +} \ No newline at end of file diff --git a/LiMan.UI/Shared/SurveyPrompt.razor b/LiMan.UI/Shared/SurveyPrompt.razor deleted file mode 100644 index 66edfb8..0000000 --- a/LiMan.UI/Shared/SurveyPrompt.razor +++ /dev/null @@ -1,16 +0,0 @@ - - -@code { - // Demonstrates how a parent component can supply parameters - [Parameter] - public string Title { get; set; } -} diff --git a/LiMan.UI/Startup.cs b/LiMan.UI/Startup.cs index e522440..2bae00f 100644 --- a/LiMan.UI/Startup.cs +++ b/LiMan.UI/Startup.cs @@ -2,12 +2,15 @@ using LiMan.UI.Data; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Localization; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Threading.Tasks; @@ -15,21 +18,22 @@ namespace LiMan.UI { public class Startup { + #region Public Constructors + public Startup(IConfiguration configuration) { Configuration = configuration; } + #endregion Public Constructors + + #region Public Properties + public IConfiguration Configuration { get; } - // This method gets called by the runtime. Use this method to add services to the container. - // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 - public void ConfigureServices(IServiceCollection services) - { - services.AddRazorPages(); - services.AddServerSideBlazor(); - services.AddSingleton(); - } + #endregion Public Properties + + #region Public Methods // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) @@ -45,6 +49,24 @@ namespace LiMan.UI app.UseHsts(); } + // cultura IT... + var supportedCultures = new[]{ + new CultureInfo("it-IT") + }; + app.UseRequestLocalization(new RequestLocalizationOptions + { + DefaultRequestCulture = new RequestCulture("it-IT"), + SupportedCultures = supportedCultures, + FallBackToParentCultures = false + }); + CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("it-IT"); + + // fix forwarders + app.UseForwardedHeaders(new ForwardedHeadersOptions + { + ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto + }); + app.UseHttpsRedirection(); app.UseStaticFiles(); @@ -56,5 +78,35 @@ namespace LiMan.UI endpoints.MapFallbackToPage("/_Host"); }); } + + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + // cookie applicazione da 14 gg (defaul) a 30 + services.ConfigureApplicationCookie(o => + { + o.ExpireTimeSpan = TimeSpan.FromDays(30); + o.SlidingExpiration = true; + }); + + services.AddStackExchangeRedisCache(options => + { + //options.Configuration = "localhost:6379"; + options.ConfigurationOptions = new StackExchange.Redis.ConfigurationOptions() { KeepAlive = 180, DefaultDatabase = 5, EndPoints = { { "localhost", 6379 } } }; + options.InstanceName = "LiMan"; + }); + + services.AddLocalization(); + + services.AddRazorPages(); + services.AddServerSideBlazor(); + + services.AddSingleton(Configuration); + services.AddScoped(); + services.AddSingleton(); + } + + #endregion Public Methods } -} +} \ No newline at end of file