From 3267f6a44db5dbc01eb2034d641291d5ee805e36 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 20 Sep 2021 11:03:52 +0200 Subject: [PATCH] Implementazione vocabolario (sync) --- MP.AppAuth/AppAuthContext.cs | 18 +++++++- MP.AppAuth/Controllers/AppAuthController.cs | 15 +++++++ MP.AppAuth/Models/Vocabolario.cs | 21 +++++++++ MP.AppAuth/MoonProContext.cs | 18 +++++++- MP.Land/Data/AppAuthService.cs | 47 +++++++++++++++++++++ MP.Land/MP.Land.csproj | 4 +- MP.Land/Pages/Index.razor | 5 ++- MP.Land/Pages/Index.razor.cs | 10 +++++ MP.Land/Resources/ChangeLog.html | 2 +- MP.Land/Resources/VersNum.txt | 2 +- MP.Land/Resources/manifest.xml | 2 +- MP.Land/Startup.cs | 4 +- MP.Land/appsettings.json | 2 +- MP.Prog/appsettings.json | 2 +- MP.Stats/MP.Stats.csproj | 2 +- MP.Stats/Resources/ChangeLog.html | 2 +- MP.Stats/Resources/VersNum.txt | 2 +- MP.Stats/Resources/manifest.xml | 6 +-- 18 files changed, 146 insertions(+), 18 deletions(-) create mode 100644 MP.AppAuth/Models/Vocabolario.cs diff --git a/MP.AppAuth/AppAuthContext.cs b/MP.AppAuth/AppAuthContext.cs index fad88874..29066c68 100644 --- a/MP.AppAuth/AppAuthContext.cs +++ b/MP.AppAuth/AppAuthContext.cs @@ -59,9 +59,10 @@ namespace MP.AppAuth #region Public Properties //public virtual DbSet DbSetMacchine { get; set; } - //public virtual DbSet DbSetProgFile { get; set; } public virtual DbSet DbSetUpdMan { get; set; } + public virtual DbSet DbSetVocabolario { get; set; } + #endregion Public Properties #region Private Methods @@ -92,6 +93,21 @@ namespace MP.AppAuth { modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS"); + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.Lingua, e.Lemma }); + + entity.ToTable("Vocabolario"); + + entity.Property(e => e.Lingua).HasMaxLength(3); + + entity.Property(e => e.Lemma).HasMaxLength(50); + + entity.Property(e => e.Traduzione) + .IsRequired() + .HasMaxLength(500); + }); + // modelBuilder.Seed(); diff --git a/MP.AppAuth/Controllers/AppAuthController.cs b/MP.AppAuth/Controllers/AppAuthController.cs index ef16df17..08b1a064 100644 --- a/MP.AppAuth/Controllers/AppAuthController.cs +++ b/MP.AppAuth/Controllers/AppAuthController.cs @@ -81,6 +81,21 @@ namespace MP.AppAuth.Controllers return dbResult; } + /// + /// Elenco Record x gestione Update + /// + /// + public List VocabolarioGetAll() + { + List dbResult = new List(); + + dbResult = dbCtx + .DbSetVocabolario + .ToList(); + + return dbResult; + } + #endregion Public Methods } } \ No newline at end of file diff --git a/MP.AppAuth/Models/Vocabolario.cs b/MP.AppAuth/Models/Vocabolario.cs new file mode 100644 index 00000000..15b6f1c6 --- /dev/null +++ b/MP.AppAuth/Models/Vocabolario.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MP.AppAuth.Models +{ + [Table("Vocabolario")] + public partial class Vocabolario + { + #region Public Properties + + public string Lemma { get; set; } + public string Lingua { get; set; } + public string Traduzione { get; set; } + + #endregion Public Properties + } +} \ No newline at end of file diff --git a/MP.AppAuth/MoonProContext.cs b/MP.AppAuth/MoonProContext.cs index ef7a9291..33453f34 100644 --- a/MP.AppAuth/MoonProContext.cs +++ b/MP.AppAuth/MoonProContext.cs @@ -43,7 +43,8 @@ namespace MP.AppAuth public virtual DbSet LinkMenuJqms { get; set; } public virtual DbSet ListValues { get; set; } public virtual DbSet Macchines { get; set; } - public virtual DbSet UpdMen { get; set; } + public virtual DbSet UpdMan { get; set; } + public virtual DbSet Vocabolario { get; set; } #endregion Public Properties @@ -518,6 +519,21 @@ namespace MP.AppAuth .HasDefaultValueSql("('')"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.Lingua, e.Lemma }); + + entity.ToTable("Vocabolario"); + + entity.Property(e => e.Lingua).HasMaxLength(3); + + entity.Property(e => e.Lemma).HasMaxLength(50); + + entity.Property(e => e.Traduzione) + .IsRequired() + .HasMaxLength(500); + }); + OnModelCreatingPartial(modelBuilder); } diff --git a/MP.Land/Data/AppAuthService.cs b/MP.Land/Data/AppAuthService.cs index 5a17d488..ed3b396d 100644 --- a/MP.Land/Data/AppAuthService.cs +++ b/MP.Land/Data/AppAuthService.cs @@ -8,6 +8,8 @@ using NLog; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Memory; using System.Diagnostics; +using System.Text; +using Newtonsoft.Json; namespace MP.Land.Data { @@ -38,6 +40,8 @@ namespace MP.Land.Data /// private int chSliExp = 5; + private Dictionary Vocabolario = new Dictionary(); + #endregion Private Fields #region Public Fields @@ -90,6 +94,36 @@ namespace MP.Land.Data #endregion Private Properties + #region Protected Methods + + protected async Task CheckVoc() + { + string cacheKey = "MP:VOCAB"; + string rawData; + //var redisDataList = await distributedCache.GetAsync(cacheKey); + var redisDataList = distributedCache.Get(cacheKey); + if (redisDataList != null) + { + rawData = Encoding.UTF8.GetString(redisDataList); + Vocabolario = JsonConvert.DeserializeObject>(rawData); + } + if (Vocabolario.Count == 0) + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + Vocabolario = dbController.VocabolarioGetAll().ToDictionary(x => $"{x.Lingua}#{x.Lemma}", x => x.Traduzione); + rawData = JsonConvert.SerializeObject(Vocabolario); + redisDataList = Encoding.UTF8.GetBytes(rawData); + distributedCache.Set(cacheKey, redisDataList, cacheOptLong); + //await distributedCache.SetAsync(cacheKey, redisDataList, cacheOptLong); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Effettuato rilettura da DB + caching per Vocabolario: {ts.TotalMilliseconds} ms"); + } + } + + #endregion Protected Methods + #region Public Methods public void Dispose() @@ -97,6 +131,19 @@ namespace MP.Land.Data throw new NotImplementedException(); } + public async Task Traduci(string lemma, string lingua = "IT") + { + string answ = $"__{lemma}__"; + string keyReq = $"{lingua}#{lemma}"; + await CheckVoc(); + // cerco in vocabolario... + if (Vocabolario.ContainsKey(keyReq)) + { + answ = Vocabolario[keyReq]; + } + return answ; + } + public async Task> UpdManList() { List dbResult = new List(); diff --git a/MP.Land/MP.Land.csproj b/MP.Land/MP.Land.csproj index e9b03c72..105a6265 100644 --- a/MP.Land/MP.Land.csproj +++ b/MP.Land/MP.Land.csproj @@ -3,7 +3,7 @@ net5.0 MP.Land - 1.1.2109.1812 + 1.1.2109.2011 @@ -31,7 +31,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/MP.Land/Pages/Index.razor b/MP.Land/Pages/Index.razor index 59e3ac5a..1006c710 100644 --- a/MP.Land/Pages/Index.razor +++ b/MP.Land/Pages/Index.razor @@ -44,7 +44,10 @@

@item.AppName

- detttagli + dettagli +
    + @(traduci($"{item.AppName}-LIST")) +
@if (string.IsNullOrEmpty(item.LicenseKey)) { diff --git a/MP.Land/Pages/Index.razor.cs b/MP.Land/Pages/Index.razor.cs index 1f8023fb..f4903b86 100644 --- a/MP.Land/Pages/Index.razor.cs +++ b/MP.Land/Pages/Index.razor.cs @@ -71,6 +71,16 @@ namespace MP.Land.Pages await Task.Delay(1); } + protected MarkupString traduci(string lemma) + { + MarkupString answ; + //string rawHtml = "
  • primo
  • secondo
  • "; + string rawHtml = DataService.Traduci(lemma, "IT").Result; + answ = new MarkupString(rawHtml); + // cerco nella cache Redis + return answ; + } + #endregion Protected Methods } } \ No newline at end of file diff --git a/MP.Land/Resources/ChangeLog.html b/MP.Land/Resources/ChangeLog.html index e2cfb611..342c67d8 100644 --- a/MP.Land/Resources/ChangeLog.html +++ b/MP.Land/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo gestione Programmi MAPO -

    Versione: 1.1.2109.1812

    +

    Versione: 1.1.2109.2011


    Note di rilascio:
      diff --git a/MP.Land/Resources/VersNum.txt b/MP.Land/Resources/VersNum.txt index ec7dc9b4..440efd98 100644 --- a/MP.Land/Resources/VersNum.txt +++ b/MP.Land/Resources/VersNum.txt @@ -1 +1 @@ -1.1.2109.1812 +1.1.2109.2011 diff --git a/MP.Land/Resources/manifest.xml b/MP.Land/Resources/manifest.xml index 31ade05b..1a60e419 100644 --- a/MP.Land/Resources/manifest.xml +++ b/MP.Land/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.1.2109.1812 + 1.1.2109.2011 https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/MP.Land.zip https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/ChangeLog.html false diff --git a/MP.Land/Startup.cs b/MP.Land/Startup.cs index 665b2123..c6dd8202 100644 --- a/MP.Land/Startup.cs +++ b/MP.Land/Startup.cs @@ -105,8 +105,8 @@ namespace MP.Land services.AddStackExchangeRedisCache(options => { - //options.Configuration = "localhost:6379"; - options.ConfigurationOptions = new StackExchange.Redis.ConfigurationOptions() { KeepAlive = 180, DefaultDatabase = 5, EndPoints = { { "localhost", 6379 } } }; + options.Configuration = Configuration["ConnectionStrings:Redis"]; + //options.ConfigurationOptions = new StackExchange.Redis.ConfigurationOptions() { KeepAlive = 180, DefaultDatabase = 1, EndPoints = { { "localhost", 6379 } } }; options.InstanceName = "MP:Land"; }); diff --git a/MP.Land/appsettings.json b/MP.Land/appsettings.json index 28740eea..d7fa4540 100644 --- a/MP.Land/appsettings.json +++ b/MP.Land/appsettings.json @@ -17,6 +17,6 @@ "ConnectionStrings": { "DefaultConnection": "Server=SQL2016DEV;Database=MoonPro;Trusted_Connection=True;MultipleActiveResultSets=true", "MP.Land": "Server=SQL2016DEV;Database=MoonPro;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.Land;", - "Redis": "localhost:6379" + "Redis": "localhost:6379,defaultDatabase=1,keepAlive=180,asyncTimeout=5000" } } \ No newline at end of file diff --git a/MP.Prog/appsettings.json b/MP.Prog/appsettings.json index 1336c695..0ffa0a63 100644 --- a/MP.Prog/appsettings.json +++ b/MP.Prog/appsettings.json @@ -15,7 +15,7 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "DefaultConnection": "Server=SQL2016DEV;Database=MoonPro_PROG;Trusted_Connection=True;MultipleActiveResultSets=true", + "DefaultConnection": "Server=SQL2016DEV;Database=MoonPro_PROG;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.Prog;", "Mp.Prog": "Server=SQL2016DEV;Database=MoonPro_PROG;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.Prog;", "Redis": "localhost:6379" } diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index 184464c3..ae779454 100644 --- a/MP.Stats/MP.Stats.csproj +++ b/MP.Stats/MP.Stats.csproj @@ -4,7 +4,7 @@ net5.0 MP.Stats 826e877c-ba70-4253-84cb-d0b1cafd4440 - 1.1.2109.1617 + 1.1.2109.2010 diff --git a/MP.Stats/Resources/ChangeLog.html b/MP.Stats/Resources/ChangeLog.html index e2c7ddbd..bc59a157 100644 --- a/MP.Stats/Resources/ChangeLog.html +++ b/MP.Stats/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

      Versione: 1.1.2109.1617

      +

      Versione: 1.1.2109.2010


      Note di rilascio:
        diff --git a/MP.Stats/Resources/VersNum.txt b/MP.Stats/Resources/VersNum.txt index 5bac5ea4..8aec05e9 100644 --- a/MP.Stats/Resources/VersNum.txt +++ b/MP.Stats/Resources/VersNum.txt @@ -1 +1 @@ -1.1.2109.1617 +1.1.2109.2010 diff --git a/MP.Stats/Resources/manifest.xml b/MP.Stats/Resources/manifest.xml index bf837864..fade9946 100644 --- a/MP.Stats/Resources/manifest.xml +++ b/MP.Stats/Resources/manifest.xml @@ -1,7 +1,7 @@ - 1.1.2109.1617 - https://nexus.steamware.net/repository/SWS/MP-STATS/stable/0/MP.Stats.zip - https://nexus.steamware.net/repository/SWS/MP-STATS/stable/0/ChangeLog.html + 1.1.2109.2010 + https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip + https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html false