Implementazione vocabolario (sync)

This commit is contained in:
Samuele Locatelli
2021-09-20 11:03:52 +02:00
parent da65188ca9
commit 3267f6a44d
18 changed files with 146 additions and 18 deletions
+17 -1
View File
@@ -59,9 +59,10 @@ namespace MP.AppAuth
#region Public Properties
//public virtual DbSet<MacchinaModel> DbSetMacchine { get; set; }
//public virtual DbSet<FileModel> DbSetProgFile { get; set; }
public virtual DbSet<UpdMan> DbSetUpdMan { get; set; }
public virtual DbSet<Vocabolario> 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<Vocabolario>(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();
@@ -81,6 +81,21 @@ namespace MP.AppAuth.Controllers
return dbResult;
}
/// <summary>
/// Elenco Record x gestione Update
/// </summary>
/// <returns></returns>
public List<Models.Vocabolario> VocabolarioGetAll()
{
List<Models.Vocabolario> dbResult = new List<Models.Vocabolario>();
dbResult = dbCtx
.DbSetVocabolario
.ToList();
return dbResult;
}
#endregion Public Methods
}
}
+21
View File
@@ -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
}
}
+17 -1
View File
@@ -43,7 +43,8 @@ namespace MP.AppAuth
public virtual DbSet<LinkMenuJqm> LinkMenuJqms { get; set; }
public virtual DbSet<ListValue> ListValues { get; set; }
public virtual DbSet<Macchine> Macchines { get; set; }
public virtual DbSet<UpdMan> UpdMen { get; set; }
public virtual DbSet<UpdMan> UpdMan { get; set; }
public virtual DbSet<Vocabolario> Vocabolario { get; set; }
#endregion Public Properties
@@ -518,6 +519,21 @@ namespace MP.AppAuth
.HasDefaultValueSql("('')");
});
modelBuilder.Entity<Vocabolario>(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);
}
+47
View File
@@ -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
/// </summary>
private int chSliExp = 5;
private Dictionary<string, string> Vocabolario = new Dictionary<string, string>();
#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<Dictionary<string, string>>(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<string> 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<List<AppAuth.Models.UpdMan>> UpdManList()
{
List<AppAuth.Models.UpdMan> dbResult = new List<AppAuth.Models.UpdMan>();
+2 -2
View File
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>MP.Land</RootNamespace>
<Version>1.1.2109.1812</Version>
<Version>1.1.2109.2011</Version>
</PropertyGroup>
<ItemGroup>
@@ -31,7 +31,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.14.0" />
+4 -1
View File
@@ -44,7 +44,10 @@
<h3>@item.AppName</h3>
</div>
<div class="card-body">
detttagli
dettagli
<ul>
@(traduci($"{item.AppName}-LIST"))
</ul>
</div>
@if (string.IsNullOrEmpty(item.LicenseKey))
{
+10
View File
@@ -71,6 +71,16 @@ namespace MP.Land.Pages
await Task.Delay(1);
}
protected MarkupString traduci(string lemma)
{
MarkupString answ;
//string rawHtml = "<li>primo</li><li>secondo</li>";
string rawHtml = DataService.Traduci(lemma, "IT").Result;
answ = new MarkupString(rawHtml);
// cerco nella cache Redis
return answ;
}
#endregion Protected Methods
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo gestione Programmi MAPO</i>
<h4>Versione: 1.1.2109.1812</h4>
<h4>Versione: 1.1.2109.2011</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
1.1.2109.1812
1.1.2109.2011
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.1.2109.1812</version>
<version>1.1.2109.2011</version>
<url>https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/MP.Land.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+2 -2
View File
@@ -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";
});
+1 -1
View File
@@ -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"
}
}
+1 -1
View File
@@ -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"
}
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>MP.Stats</RootNamespace>
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
<Version>1.1.2109.1617</Version>
<Version>1.1.2109.2010</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo statistiche MAPO</i>
<h4>Versione: 1.1.2109.1617</h4>
<h4>Versione: 1.1.2109.2010</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
1.1.2109.1617
1.1.2109.2010
+3 -3
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.1.2109.1617</version>
<url>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/0/MP.Stats.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/0/ChangeLog.html</changelog>
<version>1.1.2109.2010</version>
<url>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
</item>