This commit is contained in:
Samuele Locatelli
2023-05-29 16:21:09 +02:00
9 changed files with 223 additions and 17 deletions
+1
View File
@@ -54,6 +54,7 @@ namespace WebDoorCreator.Core
public const string rKeyUsersDataSearch = $"{rKeyUsersData}:Search";
public const string rKeyUsersView = $"{redisBaseAddr}:Cache:UsersView";
public const string rKeyVocLemma = $"{redisBaseAddr}:Cache:VocLemma";
public const string rKeyVocLemmaTEMP = $"{redisBaseAddr}:Cache:VocLemmaTEMP";
public const string rKeyLanguage = $"{redisBaseAddr}:Cache:Languages";
}
}
@@ -1241,18 +1241,46 @@ namespace WebDoorCreator.Data.Controllers
}
return DTOResult;
}
public Dictionary<string, Dictionary<string, string>> VocLemmaTEMPGetAll()
{
Dictionary<string, Dictionary<string, string>> DTOResult = new Dictionary<string, Dictionary<string, string>>();
using (WDCDataContext localDbCtx = new WDCDataContext(_configuration))
{
try
{
List<string> lingue = new List<string>()
{
"IT",
"EN"
};
/// <summary>
/// Aggiunta di un nuovo set di lemmi
/// </summary>
/// <param name="listNewTerms"></param>
/// <returns></returns>
public async Task<bool> VocLemmaInsert(List<VocabularyTempModel> listNewTerms)
// extracting entire set
var allVoc = localDbCtx
.DbSetVocabularyTemp
.AsNoTracking()
.ToList();
foreach (var lingua in lingue)
{
Dictionary<string, string> dict = new Dictionary<string, string>();
foreach (var lemma in allVoc.Where(x => x.Lingua == lingua))
{
dict.Add(lemma.Lemma, lemma.Traduzione);
}
DTOResult.Add(lingua, dict);
}
}
catch (Exception exc)
{
Log.Error($"Error in VocLemmaTEMPGetAll:{Environment.NewLine}{exc}");
}
}
return DTOResult;
}
public async Task<bool> VocLemmaInsertPrepare(List<VocabularyTempModel> listNewTerms)
{
bool fatto = false;
//var o = listNewTerms.Where(x => x.Traduzione.Length > 200).ToList();
using (WDCDataContext localDbCtx = new WDCDataContext(_configuration))
{
try
@@ -1269,8 +1297,36 @@ namespace WebDoorCreator.Data.Controllers
.AddRange(listNewTerms);
await localDbCtx.SaveChangesAsync();
fatto = true;
}
catch (Exception exc)
{
Log.Error($"Eccezione durante VocLemmaInsertPrepare: {Environment.NewLine}{exc}");
}
}
return fatto;
}
/// <summary>
/// Aggiunta di un nuovo set di lemmi
/// </summary>
/// <param name="listNewTerms"></param>
/// <returns></returns>
public async Task<bool> VocLemmaInsert()
{
await Task.Delay(1);
bool fatto = false;
//var o = listNewTerms.Where(x => x.Traduzione.Length > 200).ToList();
using (WDCDataContext localDbCtx = new WDCDataContext(_configuration))
{
try
{
//bool isOk = await VocLemmaInsertPrepare(listNewTerms);
// stored di merge dati in vocabolario
storedRes = localDbCtx
var storedRes = localDbCtx
.Database
.ExecuteSqlRaw("exec dbo.stp_Voc_Import");
@@ -2231,11 +2231,24 @@ namespace WebDoorCreator.Data.Services
Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
public async Task<bool> VocLemmaInsert(string rootPath)
public async Task<Dictionary<string, Dictionary<string, string>>?> VocLemmaTEMPGetAll()
{
bool fatto = false;
string source = "DB";
Dictionary<string, Dictionary<string, string>>? dbResult = new Dictionary<string, Dictionary<string, string>>();
// cerco da cache
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
dbResult = dbController.VocLemmaTEMPGetAll();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
public async Task<List<VocabularyTempModel>> VocLemmaInsertPrepare(string rootPath)
{
//bool fatto = false;
await Task.Delay(1);
List<VocabularyTempModel> VocLemmas = new List<VocabularyTempModel>();
Stopwatch stopWatch = new Stopwatch();
@@ -2271,7 +2284,24 @@ namespace WebDoorCreator.Data.Services
}
}
}
fatto = await dbController.VocLemmaInsert(VocLemmas);
await dbController.VocLemmaInsertPrepare(VocLemmas);
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"VocLemmaInsertPrepare in: {ts.TotalMilliseconds} ms");
return VocLemmas;
}
public async Task<bool> VocLemmaInsert()
{
bool fatto = false;
List<VocabularyTempModel> VocLemmas = new List<VocabularyTempModel>();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
fatto = await dbController.VocLemmaInsert();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"VocLemmaInsert in: {ts.TotalMilliseconds} ms");
@@ -0,0 +1,45 @@
<button class="btn btn-info" @onclick="()=>refreshVoc()">VOCABULARY REFRESH</button>
<input @bind-value="@defaultPath" />
@*@if (vocLemmas != null)
{
@foreach (var item in vocLemmas)
{
@foreach (var k in item.Value)
{
@*<div>@($"{k.Key} --> {k.Value}")</div>
@if(vocLemmasTEMP != null)
{
}
}
}
}*@
@if (showList)
{
@if (vocLemmas2Dict != null && vocLemmasTEMP2Dict != null)
{
@foreach (var item in vocLemmasTEMP2Dict)
{
@if (!vocLemmas2Dict.ContainsKey(item.Key))
{
<div class="row">
<div class="col-12 text-success">@($"{item.Key} --> {vocLemmasTEMP2Dict[item.Key]}")</div>
</div>
}
else if (item.Value != vocLemmas2Dict[item.Key])
{
<div class="row">
<div class="col-6 text-danger text-decoration-line-through">@($"{item.Key} --> {vocLemmas2Dict[item.Key]}")</div>
<div class="col-6 text-success">@($"{item.Key} --> {item.Value}")</div>
</div>
}
}
}
}
@@ -0,0 +1,71 @@
using Microsoft.AspNetCore.Components;
using Microsoft.CodeAnalysis.VisualBasic.Syntax;
using WebDoorCreator.Data.DbModels;
using WebDoorCreator.Data.Services;
namespace WebDoorCreator.UI.Components.FilesMan
{
public partial class FilesRefresh
{
[Inject]
protected WebDoorCreatorService WDCService { get; set; } = null!;
[Parameter]
public string lang { get; set; } = "";
protected Dictionary<string, Dictionary<string, string>>? vocLemmas { get; set; } = null;
protected Dictionary<string, string> vocLemmas2Dict { get; set; } = new Dictionary<string, string>();
protected Dictionary<string, Dictionary<string, string>>? vocLemmasTEMP { get; set; } = null;
protected Dictionary<string, string> vocLemmasTEMP2Dict { get; set; } = new Dictionary<string, string>();
protected bool showList { get; set; } = false;
protected async override Task OnParametersSetAsync()
{
var rawVoc = await WDCService.VocLemmaGetAll();
if (rawVoc != null)
{
vocLemmas = rawVoc.Where(x => x.Key == lang).ToDictionary(x => x.Key, x => x.Value);
if(vocLemmas != null)
{
foreach(var kvp in vocLemmas)
{
foreach(var item in kvp.Value)
{
vocLemmas2Dict.Add(item.Key, item.Value);
}
}
}
}
}
protected async Task refreshVoc()
{
vocLemmasTEMP = null;
await Task.Delay(1);
list2Mod = await WDCService.VocLemmaInsertPrepare(@$"{defaultPath}");
if (list2Mod != null)
{
//bool ok = await WDCService.VocLemmaInsert();
var k = await WDCService.VocLemmaTEMPGetAll();
if (k != null)
{
vocLemmasTEMP = k.Where(x => x.Key == lang).ToDictionary(x => x.Key, x => x.Value);
if (vocLemmasTEMP != null)
{
foreach (var kvp in vocLemmasTEMP)
{
foreach (var item in kvp.Value)
{
vocLemmasTEMP2Dict.Add(item.Key, item.Value);
}
}
}
}
}
showList = true;
}
List<VocabularyTempModel> list2Mod = new List<VocabularyTempModel>();
protected string defaultPath { get; set; } = "";
}
}
@@ -73,7 +73,7 @@
{
@if (compToShow != null)
{
<input class="form-control form-control-sm" value="@compToShow.CompanyName" disabled/>
<input class="form-control form-control-sm" value="@compToShow.CompanyName" disabled />
}
}
}
+2 -2
View File
@@ -15,7 +15,7 @@
</div>
<div>
<button class="btn btn-warning" @onclick="()=>refreshHw()">HARDWARE REFRESH</button>
<button class="btn btn-info" @onclick="()=>refreshVoc()">VOCABULARY REFRESH</button>
@*<button class="btn btn-info" @onclick="()=>refreshVoc()">VOCABULARY REFRESH</button>*@
<button class="btn btn-info" @onclick="()=>refreshFiles()">FILES REFRESH</button>
</div>
@@ -46,7 +46,7 @@
}
else
{
<UserList></UserList>
<FilesRefresh lang="EN"></FilesRefresh>
}
</div>
</div>
+3 -1
View File
@@ -312,11 +312,13 @@ namespace WebDoorCreator.UI.Pages
await Task.Delay(1);
await WDService.CompoListSetAll(@$"{defaultPath}");
}
#if false
protected async Task refreshVoc()
{
await Task.Delay(1);
await WDService.VocLemmaInsert(@$"{defaultPath}");
}
}
#endif
protected async Task refreshFiles()
{
await Task.Delay(1);
+1
View File
@@ -22,6 +22,7 @@
@using WebDoorCreator.UI.Components.SvgComp
@using WebDoorCreator.UI.Components.Filters
@using WebDoorCreator.UI.Components.Report
@using WebDoorCreator.UI.Components.FilesMan
@using WebDoorCreator.UI.Shared