diff --git a/WebDoorCreator.Core/Constants.cs b/WebDoorCreator.Core/Constants.cs index 634c6ca..06c7dde 100644 --- a/WebDoorCreator.Core/Constants.cs +++ b/WebDoorCreator.Core/Constants.cs @@ -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"; } } diff --git a/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs b/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs index a87ddfd..ca63d49 100644 --- a/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs +++ b/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs @@ -1241,18 +1241,46 @@ namespace WebDoorCreator.Data.Controllers } return DTOResult; } + public Dictionary> VocLemmaTEMPGetAll() + { + Dictionary> DTOResult = new Dictionary>(); + using (WDCDataContext localDbCtx = new WDCDataContext(_configuration)) + { + try + { + List lingue = new List() + { + "IT", + "EN" + }; - /// - /// Aggiunta di un nuovo set di lemmi - /// - /// - /// - public async Task VocLemmaInsert(List listNewTerms) + // extracting entire set + var allVoc = localDbCtx + .DbSetVocabularyTemp + .AsNoTracking() + .ToList(); + + foreach (var lingua in lingue) + { + Dictionary dict = new Dictionary(); + 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 VocLemmaInsertPrepare(List 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; + } + + /// + /// Aggiunta di un nuovo set di lemmi + /// + /// + /// + public async Task 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"); diff --git a/WebDoorCreator.Data/Services/WebDoorCreatorService.cs b/WebDoorCreator.Data/Services/WebDoorCreatorService.cs index 147ef49..dea0196 100644 --- a/WebDoorCreator.Data/Services/WebDoorCreatorService.cs +++ b/WebDoorCreator.Data/Services/WebDoorCreatorService.cs @@ -2231,11 +2231,24 @@ namespace WebDoorCreator.Data.Services Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms"); return dbResult; } - - public async Task VocLemmaInsert(string rootPath) + public async Task>?> VocLemmaTEMPGetAll() { - bool fatto = false; + string source = "DB"; + Dictionary>? dbResult = new Dictionary>(); + // 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> VocLemmaInsertPrepare(string rootPath) + { + //bool fatto = false; + await Task.Delay(1); List VocLemmas = new List(); 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 VocLemmaInsert() + { + bool fatto = false; + + List VocLemmas = new List(); + + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + fatto = await dbController.VocLemmaInsert(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Debug($"VocLemmaInsert in: {ts.TotalMilliseconds} ms"); diff --git a/WebDoorCreator.UI/Components/FilesMan/FilesRefresh.razor b/WebDoorCreator.UI/Components/FilesMan/FilesRefresh.razor new file mode 100644 index 0000000..2d6baf1 --- /dev/null +++ b/WebDoorCreator.UI/Components/FilesMan/FilesRefresh.razor @@ -0,0 +1,45 @@ + + + + + +@*@if (vocLemmas != null) +{ + @foreach (var item in vocLemmas) + { + @foreach (var k in item.Value) + { + @*
@($"{k.Key} --> {k.Value}")
+ @if(vocLemmasTEMP != null) + { + + } + } + } +}*@ + +@if (showList) +{ + + + @if (vocLemmas2Dict != null && vocLemmasTEMP2Dict != null) + { + @foreach (var item in vocLemmasTEMP2Dict) + { + @if (!vocLemmas2Dict.ContainsKey(item.Key)) + { +
+
@($"{item.Key} --> {vocLemmasTEMP2Dict[item.Key]}")
+
+ } + else if (item.Value != vocLemmas2Dict[item.Key]) + { +
+
@($"{item.Key} --> {vocLemmas2Dict[item.Key]}")
+
@($"{item.Key} --> {item.Value}")
+
+ } + } + } +} + diff --git a/WebDoorCreator.UI/Components/FilesMan/FilesRefresh.razor.cs b/WebDoorCreator.UI/Components/FilesMan/FilesRefresh.razor.cs new file mode 100644 index 0000000..98eee93 --- /dev/null +++ b/WebDoorCreator.UI/Components/FilesMan/FilesRefresh.razor.cs @@ -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>? vocLemmas { get; set; } = null; + protected Dictionary vocLemmas2Dict { get; set; } = new Dictionary(); + protected Dictionary>? vocLemmasTEMP { get; set; } = null; + protected Dictionary vocLemmasTEMP2Dict { get; set; } = new Dictionary(); + + 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 list2Mod = new List(); + + protected string defaultPath { get; set; } = ""; + } +} \ No newline at end of file diff --git a/WebDoorCreator.UI/Components/Gen/NavMenuHorizontal.razor b/WebDoorCreator.UI/Components/Gen/NavMenuHorizontal.razor index d05cb93..72bd844 100644 --- a/WebDoorCreator.UI/Components/Gen/NavMenuHorizontal.razor +++ b/WebDoorCreator.UI/Components/Gen/NavMenuHorizontal.razor @@ -73,7 +73,7 @@ { @if (compToShow != null) { - + } } } diff --git a/WebDoorCreator.UI/Pages/SuperAdmin.razor b/WebDoorCreator.UI/Pages/SuperAdmin.razor index 71f015b..d8d739f 100644 --- a/WebDoorCreator.UI/Pages/SuperAdmin.razor +++ b/WebDoorCreator.UI/Pages/SuperAdmin.razor @@ -15,7 +15,7 @@
- + @**@
@@ -46,7 +46,7 @@ } else { - + } diff --git a/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs b/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs index 671c6d6..e4d2e1a 100644 --- a/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs +++ b/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs @@ -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); diff --git a/WebDoorCreator.UI/_Imports.razor b/WebDoorCreator.UI/_Imports.razor index 50fc7e5..3172152 100644 --- a/WebDoorCreator.UI/_Imports.razor +++ b/WebDoorCreator.UI/_Imports.razor @@ -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