Fix traduzione scheda tecnica
This commit is contained in:
@@ -45,6 +45,11 @@ namespace MP.Data.Services
|
||||
/// </summary>
|
||||
public Dictionary<int, AnagStatiModel> DictStati { get; set; } = new Dictionary<int, AnagStatiModel>();
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario globale (key: lingua_lemma, lowercase)
|
||||
/// </summary>
|
||||
public Dictionary<string, string> DictVocab { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
/// <summary>
|
||||
/// Lista completa eventi
|
||||
/// </summary>
|
||||
@@ -60,6 +65,11 @@ namespace MP.Data.Services
|
||||
/// </summary>
|
||||
public List<AnagStatiModel> ListStati { get; set; } = new List<AnagStatiModel>();
|
||||
|
||||
/// <summary>
|
||||
/// Lista completa stati
|
||||
/// </summary>
|
||||
public List<VocabolarioModel> ListVocab { get; set; } = new List<VocabolarioModel>();
|
||||
|
||||
public bool MenuOk
|
||||
{
|
||||
get => AllMenuData.Count > 0;
|
||||
@@ -81,6 +91,7 @@ namespace MP.Data.Services
|
||||
DictConfig = new Dictionary<string, string>();
|
||||
DictEventi = new Dictionary<int, AnagEventiModel>();
|
||||
DictStati = new Dictionary<int, AnagStatiModel>();
|
||||
DictVocab = new Dictionary<string, string>();
|
||||
Log.Info("SharedMemService | Cache resetted!");
|
||||
}
|
||||
|
||||
@@ -224,12 +235,49 @@ namespace MP.Data.Services
|
||||
Log.Info("SharedMemService | SetupMenu executed!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua setup vocabolario
|
||||
/// </summary>
|
||||
/// <param name="allVoc"></param>
|
||||
public void SetVocab(List<VocabolarioModel> allVoc)
|
||||
{
|
||||
ListVocab = allVoc ?? new List<VocabolarioModel>();
|
||||
// salvo dizionario
|
||||
DictVocab = ListVocab.ToDictionary(x => $"{x.Lingua}_{x.Lemma.ToUpper()}", x => x.Traduzione);
|
||||
Log.Info("SharedMemService | SetVocab executed!");
|
||||
}
|
||||
|
||||
public string Traduci(string lingua, string lemma)
|
||||
{
|
||||
return Traduci($"{lingua}_{lemma}".ToUpper());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Traduzione diretta vocabolario
|
||||
/// </summary>
|
||||
/// <param name="lingua_lemma">Formato {lingua}_{lemma}, lowercase</param>
|
||||
/// <returns></returns>
|
||||
public string Traduci(string lingua_lemma)
|
||||
{
|
||||
string answ = $"[{lingua_lemma}]";
|
||||
if (DictVocab.ContainsKey(lingua_lemma))
|
||||
{
|
||||
answ = DictVocab[lingua_lemma];
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto vocabolario x uso continuo traduzione
|
||||
/// </summary>
|
||||
private List<VocabolarioModel> ObjVocabolario = new List<VocabolarioModel>();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
@@ -1078,6 +1078,36 @@ namespace MP.Data.Services
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<VocabolarioModel> VocabolarioGetAll()
|
||||
{
|
||||
// setup parametri costanti
|
||||
string source = "DB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
List<VocabolarioModel>? result = new List<VocabolarioModel>();
|
||||
// cerco in redis...
|
||||
string currKey = $"{redisBaseKey}:Vocab";
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<VocabolarioModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbTabController.VocabolarioGetAll();
|
||||
// serializzp e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<VocabolarioModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"VocabolarioGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta record RegistroScarti
|
||||
|
||||
Reference in New Issue
Block a user