Reorg codice classe accesso dati
This commit is contained in:
@@ -2,13 +2,9 @@
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NLog;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using StackExchange.Redis;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection.Emit;
|
||||
using System.Security.AccessControl;
|
||||
using System.Text;
|
||||
using WebDoorCreator.Core;
|
||||
using WebDoorCreator.Data.Controllers;
|
||||
@@ -148,9 +144,6 @@ namespace WebDoorCreator.UI.Data
|
||||
return listActiveCompo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Setting all the component list
|
||||
/// </summary>
|
||||
@@ -178,7 +171,6 @@ namespace WebDoorCreator.UI.Data
|
||||
// elenco obj da inserire
|
||||
List<DoorOpTypeModel> ListObjDOT = new List<DoorOpTypeModel>();
|
||||
|
||||
|
||||
string[] DefaultFile = Directory.GetFiles(rootPath, "Default.ini");
|
||||
|
||||
IniFile fIniDef = new IniFile(DefaultFile[0]);
|
||||
@@ -385,52 +377,6 @@ namespace WebDoorCreator.UI.Data
|
||||
return fatto;
|
||||
}
|
||||
|
||||
public async Task<bool> VocLemmaInsert(string rootPath)
|
||||
{
|
||||
bool fatto = false;
|
||||
|
||||
List<VocabularyTempModel> VocLemmas = new List<VocabularyTempModel>();
|
||||
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
|
||||
string[] files = Directory.GetFiles(rootPath, "*");
|
||||
string lang = "";
|
||||
foreach (string file in files)
|
||||
{
|
||||
var fileName = file.Split(".");
|
||||
|
||||
lang = fileName[0].Substring(fileName[0].Length - 2, 2);
|
||||
|
||||
//leggo tutte le linee del file
|
||||
List<string> lines = File.ReadAllLines(file).ToList();
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (!line.StartsWith("//") && line != "")
|
||||
{
|
||||
string[] lineSplit = line.Split("=");
|
||||
//string trad = "";
|
||||
if (lineSplit.Length != 1)
|
||||
{
|
||||
VocabularyTempModel newVocLemma = new VocabularyTempModel()
|
||||
{
|
||||
Lingua = lang,
|
||||
Lemma = lineSplit[0],
|
||||
Traduzione = lineSplit[1]
|
||||
};
|
||||
VocLemmas.Add(newVocLemma);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fatto = await dbController.VocLemmaInsert(VocLemmas);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"VocLemmaInsert in: {ts.TotalMilliseconds} ms");
|
||||
return fatto;
|
||||
}
|
||||
|
||||
public string DecriptData(string encData)
|
||||
{
|
||||
return SteamCrypto.DecryptString(encData, Constants.passPhrase);
|
||||
@@ -543,6 +489,41 @@ namespace WebDoorCreator.UI.Data
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eliminazione DoorOP
|
||||
/// </summary>
|
||||
/// <param name="currDoorOp"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DoorOpDelete(DoorOpModel currDoorOp)
|
||||
{
|
||||
var dbResult = await dbController.DoorOpDelete(currDoorOp);
|
||||
// elimino cache redis dati porta...
|
||||
bool answ = await DoorOpFlushCache(currDoorOp.DoorId);
|
||||
answ = answ && await DoorFlushCache(currDoorOp.DoorId);
|
||||
// elimino cache redis dati ordine...
|
||||
answ = answ && await OrdersFlushCache();
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eliminazione DoorOP list
|
||||
/// </summary>
|
||||
/// <param name="currDoorOpList"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DoorOpDeleteRange(List<DoorOpModel> currDoorOpList)
|
||||
{
|
||||
var dbResult = await dbController.DoorOpDeleteRange(currDoorOpList);
|
||||
// elimino cache redis dati porta...
|
||||
foreach (var item in currDoorOpList)
|
||||
{
|
||||
bool answ = await DoorOpFlushCache(item.DoorId);
|
||||
answ = answ && await DoorFlushCache(item.DoorId);
|
||||
// elimino cache redis dati ordine...
|
||||
answ = answ && await OrdersFlushCache();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean redis DOORS OP cache
|
||||
/// </summary>
|
||||
@@ -600,164 +581,6 @@ namespace WebDoorCreator.UI.Data
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, Dictionary<string, string>>?> VocLemmaGetAll()
|
||||
{
|
||||
string source = "DB";
|
||||
Dictionary<string, Dictionary<string, string>>? dbResult = new Dictionary<string, Dictionary<string, string>>();
|
||||
// cerco da cache
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string currKey = $"{Constants.rKeyVocLemma}";
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dbResult = new Dictionary<string, Dictionary<string, string>>();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = dbController.VocLemmaGetAll();
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new Dictionary<string, Dictionary<string, string>>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task<bool> ListValuesLuaNgeInsert(string rootPath)
|
||||
{
|
||||
List<ListValuesTempModel> values = new List<ListValuesTempModel>();
|
||||
string[] dirs = Directory.GetDirectories(rootPath);
|
||||
foreach (string dir in dirs)
|
||||
{
|
||||
string compoCode = "";
|
||||
string[] templateDirectories = Directory.GetDirectories(dir);
|
||||
|
||||
string[] iniFiles = Directory.GetFiles(dir, "Config.ini");
|
||||
|
||||
|
||||
int ordin = 1;
|
||||
foreach (string templateDirectory in templateDirectories)
|
||||
{
|
||||
var tName = templateDirectory.Split("\\");
|
||||
var fName = templateDirectory.Split("\\");
|
||||
|
||||
foreach (var file in iniFiles)
|
||||
{
|
||||
List<string> lines = File.ReadAllLines(file).ToList();
|
||||
IniFile fIni = new IniFile(file);
|
||||
|
||||
var compoName = fIni.ReadString("Compo", "Name", "COMPONAME");
|
||||
compoCode = compoName.Split("/")[0].Trim();
|
||||
}
|
||||
string[] templateFiles = Directory.GetFiles(templateDirectory);
|
||||
if (templateFiles.Length > 0)
|
||||
{
|
||||
|
||||
ListValuesTempModel folderNames = new ListValuesTempModel()
|
||||
{
|
||||
TableName = $"{compoCode}".Replace(" ", "_"),
|
||||
FieldName = "Folder",
|
||||
Value = @$"{tName[tName.Length - 1]}".Replace(" ", "_"),
|
||||
Label = @$"{tName[tName.Length - 1]}",
|
||||
Ordinal = 0,
|
||||
DefaultVal = " ",
|
||||
InputType = " ",
|
||||
};
|
||||
values.Add(folderNames);
|
||||
}
|
||||
|
||||
foreach (string templateFile in templateFiles)
|
||||
{
|
||||
ListValuesTempModel temp = new ListValuesTempModel()
|
||||
{
|
||||
TableName = $"{compoCode}".Replace(" ", "_"),
|
||||
FieldName = "template",
|
||||
Value = @$"{tName[tName.Length - 1]}\{Path.GetFileName(templateFile).Split(".")[0]}".Replace(" ", "_"),
|
||||
Label = Path.GetFileName(templateFile).Split(".")[0],
|
||||
Ordinal = ordin,
|
||||
DefaultVal = " ",
|
||||
InputType = " ",
|
||||
};
|
||||
|
||||
if (values.Where(x => x.TableName == temp.TableName && x.FieldName == temp.FieldName && x.Value == temp.Value).Count() == 0 && temp.TableName != null && temp.FieldName != null && temp.Value != null)
|
||||
{
|
||||
values.Add(temp);
|
||||
ordin++;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($"GraphicParamsGetAll | Duplicated key: {temp.TableName} {temp.FieldName} {temp.Value} ");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool fatto = await dbController.ListValuesAdd(values);
|
||||
|
||||
return fatto;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Doors list by orderId
|
||||
/// </summary>
|
||||
public async Task<List<DoorOpTypeModel>?> DoorOpTypeGetAll()
|
||||
{
|
||||
string source = "DB";
|
||||
List<DoorOpTypeModel>? dbResult = new List<DoorOpTypeModel>();
|
||||
// cerco da cache
|
||||
string currKey = $"{Constants.rKeyDoorOpType}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
#if false
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<DoorOpTypeModel>>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dbResult = new List<DoorOpTypeModel>();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
#endif
|
||||
dbResult = dbController.DoorOpTypeGetAll();
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new List<DoorOpTypeModel>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"DoorOpTypeGetAll | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// lista DoorOpList necessarie all'init
|
||||
/// </summary>
|
||||
@@ -821,6 +644,49 @@ namespace WebDoorCreator.UI.Data
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Doors list by orderId
|
||||
/// </summary>
|
||||
public async Task<List<DoorOpTypeModel>?> DoorOpTypeGetAll()
|
||||
{
|
||||
string source = "DB";
|
||||
List<DoorOpTypeModel>? dbResult = new List<DoorOpTypeModel>();
|
||||
// cerco da cache
|
||||
string currKey = $"{Constants.rKeyDoorOpType}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
#if false
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<DoorOpTypeModel>>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dbResult = new List<DoorOpTypeModel>();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
#endif
|
||||
dbResult = dbController.DoorOpTypeGetAll();
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new List<DoorOpTypeModel>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"DoorOpTypeGetAll | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiornamento DoorOP
|
||||
/// </summary>
|
||||
@@ -836,39 +702,6 @@ namespace WebDoorCreator.UI.Data
|
||||
answ = answ && await OrdersFlushCache();
|
||||
return dbResult;
|
||||
}
|
||||
/// <summary>
|
||||
/// Eliminazione DoorOP
|
||||
/// </summary>
|
||||
/// <param name="currDoorOp"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DoorOpDelete(DoorOpModel currDoorOp)
|
||||
{
|
||||
var dbResult = await dbController.DoorOpDelete(currDoorOp);
|
||||
// elimino cache redis dati porta...
|
||||
bool answ = await DoorOpFlushCache(currDoorOp.DoorId);
|
||||
answ = answ && await DoorFlushCache(currDoorOp.DoorId);
|
||||
// elimino cache redis dati ordine...
|
||||
answ = answ && await OrdersFlushCache();
|
||||
return dbResult;
|
||||
}
|
||||
/// <summary>
|
||||
/// Eliminazione DoorOP list
|
||||
/// </summary>
|
||||
/// <param name="currDoorOpList"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DoorOpDeleteRange(List<DoorOpModel> currDoorOpList)
|
||||
{
|
||||
var dbResult = await dbController.DoorOpDeleteRange(currDoorOpList);
|
||||
// elimino cache redis dati porta...
|
||||
foreach (var item in currDoorOpList)
|
||||
{
|
||||
bool answ = await DoorOpFlushCache(item.DoorId);
|
||||
answ = answ && await DoorFlushCache(item.DoorId);
|
||||
// elimino cache redis dati ordine...
|
||||
answ = answ && await OrdersFlushCache();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update or add door
|
||||
@@ -904,7 +737,6 @@ namespace WebDoorCreator.UI.Data
|
||||
List<ListValuesTempModel> listValuesTemp = new List<ListValuesTempModel>();
|
||||
ListValuesTempModel listValObj = new ListValuesTempModel();
|
||||
|
||||
|
||||
IniFile fIni = new IniFile(file);
|
||||
//cerco il contenuto delle sezioni
|
||||
var graphicParamsName = fIni.ReadSection(match.Substring(1, match.Length - 2));
|
||||
@@ -965,6 +797,49 @@ namespace WebDoorCreator.UI.Data
|
||||
return listValuesTemp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Estraggo tutte le lingue disponibili per questa applicazione
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<LanguageModel>?> LanguageGetAll()
|
||||
{
|
||||
string source = "DB";
|
||||
|
||||
List<LanguageModel>? dbResult = new List<LanguageModel>();
|
||||
// cerco da cache
|
||||
string currKey = $"{Constants.rKeyLanguage}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<LanguageModel>>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dbResult = new List<LanguageModel>();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = dbController.LanguageGetAll();
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new List<LanguageModel>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"LanguageGetAll | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List values
|
||||
/// </summary>
|
||||
@@ -1009,47 +884,76 @@ namespace WebDoorCreator.UI.Data
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Estraggo tutte le lingue disponibili per questa applicazione
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<LanguageModel>?> LanguageGetAll()
|
||||
public async Task<bool> ListValuesLuaNgeInsert(string rootPath)
|
||||
{
|
||||
string source = "DB";
|
||||
List<ListValuesTempModel> values = new List<ListValuesTempModel>();
|
||||
string[] dirs = Directory.GetDirectories(rootPath);
|
||||
foreach (string dir in dirs)
|
||||
{
|
||||
string compoCode = "";
|
||||
string[] templateDirectories = Directory.GetDirectories(dir);
|
||||
|
||||
List<LanguageModel>? dbResult = new List<LanguageModel>();
|
||||
// cerco da cache
|
||||
string currKey = $"{Constants.rKeyLanguage}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<LanguageModel>>(rawData);
|
||||
if (tempResult == null)
|
||||
string[] iniFiles = Directory.GetFiles(dir, "Config.ini");
|
||||
|
||||
int ordin = 1;
|
||||
foreach (string templateDirectory in templateDirectories)
|
||||
{
|
||||
dbResult = new List<LanguageModel>();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = tempResult;
|
||||
var tName = templateDirectory.Split("\\");
|
||||
var fName = templateDirectory.Split("\\");
|
||||
|
||||
foreach (var file in iniFiles)
|
||||
{
|
||||
List<string> lines = File.ReadAllLines(file).ToList();
|
||||
IniFile fIni = new IniFile(file);
|
||||
|
||||
var compoName = fIni.ReadString("Compo", "Name", "COMPONAME");
|
||||
compoCode = compoName.Split("/")[0].Trim();
|
||||
}
|
||||
string[] templateFiles = Directory.GetFiles(templateDirectory);
|
||||
if (templateFiles.Length > 0)
|
||||
{
|
||||
ListValuesTempModel folderNames = new ListValuesTempModel()
|
||||
{
|
||||
TableName = $"{compoCode}".Replace(" ", "_"),
|
||||
FieldName = "Folder",
|
||||
Value = @$"{tName[tName.Length - 1]}".Replace(" ", "_"),
|
||||
Label = @$"{tName[tName.Length - 1]}",
|
||||
Ordinal = 0,
|
||||
DefaultVal = " ",
|
||||
InputType = " ",
|
||||
};
|
||||
values.Add(folderNames);
|
||||
}
|
||||
|
||||
foreach (string templateFile in templateFiles)
|
||||
{
|
||||
ListValuesTempModel temp = new ListValuesTempModel()
|
||||
{
|
||||
TableName = $"{compoCode}".Replace(" ", "_"),
|
||||
FieldName = "template",
|
||||
Value = @$"{tName[tName.Length - 1]}\{Path.GetFileName(templateFile).Split(".")[0]}".Replace(" ", "_"),
|
||||
Label = Path.GetFileName(templateFile).Split(".")[0],
|
||||
Ordinal = ordin,
|
||||
DefaultVal = " ",
|
||||
InputType = " ",
|
||||
};
|
||||
|
||||
if (values.Where(x => x.TableName == temp.TableName && x.FieldName == temp.FieldName && x.Value == temp.Value).Count() == 0 && temp.TableName != null && temp.FieldName != null && temp.Value != null)
|
||||
{
|
||||
values.Add(temp);
|
||||
ordin++;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($"GraphicParamsGetAll | Duplicated key: {temp.TableName} {temp.FieldName} {temp.Value} ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = dbController.LanguageGetAll();
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new List<LanguageModel>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"LanguageGetAll | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
|
||||
bool fatto = await dbController.ListValuesAdd(values);
|
||||
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1357,11 +1261,94 @@ namespace WebDoorCreator.UI.Data
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, Dictionary<string, string>>?> VocLemmaGetAll()
|
||||
{
|
||||
string source = "DB";
|
||||
Dictionary<string, Dictionary<string, string>>? dbResult = new Dictionary<string, Dictionary<string, string>>();
|
||||
// cerco da cache
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string currKey = $"{Constants.rKeyVocLemma}";
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dbResult = new Dictionary<string, Dictionary<string, string>>();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = dbController.VocLemmaGetAll();
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new Dictionary<string, Dictionary<string, string>>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task<bool> VocLemmaInsert(string rootPath)
|
||||
{
|
||||
bool fatto = false;
|
||||
|
||||
List<VocabularyTempModel> VocLemmas = new List<VocabularyTempModel>();
|
||||
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
|
||||
string[] files = Directory.GetFiles(rootPath, "*");
|
||||
string lang = "";
|
||||
foreach (string file in files)
|
||||
{
|
||||
var fileName = file.Split(".");
|
||||
|
||||
lang = fileName[0].Substring(fileName[0].Length - 2, 2);
|
||||
|
||||
//leggo tutte le linee del file
|
||||
List<string> lines = File.ReadAllLines(file).ToList();
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (!line.StartsWith("//") && line != "")
|
||||
{
|
||||
string[] lineSplit = line.Split("=");
|
||||
//string trad = "";
|
||||
if (lineSplit.Length != 1)
|
||||
{
|
||||
VocabularyTempModel newVocLemma = new VocabularyTempModel()
|
||||
{
|
||||
Lingua = lang,
|
||||
Lemma = lineSplit[0],
|
||||
Traduzione = lineSplit[1]
|
||||
};
|
||||
VocLemmas.Add(newVocLemma);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fatto = await dbController.VocLemmaInsert(VocLemmas);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"VocLemmaInsert in: {ts.TotalMilliseconds} ms");
|
||||
return fatto;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
|
||||
protected Random rnd = new Random();
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
Reference in New Issue
Block a user