diff --git a/WebDoorCreator.Data/Services/WebDoorCreatorService.cs b/WebDoorCreator.Data/Services/WebDoorCreatorService.cs
index b087005..cf8e5b4 100644
--- a/WebDoorCreator.Data/Services/WebDoorCreatorService.cs
+++ b/WebDoorCreator.Data/Services/WebDoorCreatorService.cs
@@ -1,12 +1,9 @@
using EgwCoreLib.Utils;
-using MailKit.Search;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
-using Microsoft.Reporting.Map.WebForms.BingMaps;
using Newtonsoft.Json;
using NLog;
-using NLog.Fluent;
using StackExchange.Redis;
using System.Diagnostics;
using System.Security.Cryptography;
@@ -1932,12 +1929,25 @@ namespace WebDoorCreator.Data.Services
///
public async Task DoorOpUpdate(List currDoorOps)
{
- var dbResult = await dbController.DoorOpUpdate(currDoorOps);
- // elimino cache redis dati porta...
- bool answ = await DoorOpFlushCache(currDoorOps.FirstOrDefault()!.DoorId);
- answ = answ && await DoorFlushCache(currDoorOps.FirstOrDefault()!.DoorId);
- // elimino cache redis dati ordine...
- answ = answ && await OrdersFlushCache();
+ bool dbResult = false;
+ try
+ {
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ dbResult = await dbController.DoorOpUpdate(currDoorOps);
+ // elimino cache redis dati porta...
+ bool answ = await DoorOpFlushCache(currDoorOps.FirstOrDefault()!.DoorId);
+ answ = answ && await DoorFlushCache(currDoorOps.FirstOrDefault()!.DoorId);
+ // elimino cache redis dati ordine...
+ answ = answ && await OrdersFlushCache();
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"DoorOpUpdate in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during DoorOpUpdate: {exc}{Environment.NewLine}");
+ }
return dbResult;
}
@@ -1948,15 +1958,28 @@ namespace WebDoorCreator.Data.Services
///
public async Task DoorUpdateCosts(Dictionary DoorUnitCosts)
{
- var dbResult = await dbController.DoorUpdateCosts(DoorUnitCosts);
- // elimino cache redis dati porte...
- bool answ = false;
- foreach (var item in DoorUnitCosts)
+ bool dbResult = false;
+ try
{
- answ = await DoorFlushCache(item.Key);
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ dbResult = await dbController.DoorUpdateCosts(DoorUnitCosts);
+ // elimino cache redis dati porte...
+ bool answ = false;
+ foreach (var item in DoorUnitCosts)
+ {
+ answ = await DoorFlushCache(item.Key);
+ }
+ // elimino cache redis dati ordine...
+ answ = answ && await OrdersFlushCache();
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"DoorUpdateCosts in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during DoorUpdateCosts: {exc}{Environment.NewLine}");
}
- // elimino cache redis dati ordine...
- answ = answ && await OrdersFlushCache();
return dbResult;
}
@@ -1967,11 +1990,24 @@ namespace WebDoorCreator.Data.Services
///
public async Task DoorUpsert(DoorModel currRec)
{
- var dbResult = await dbController.DoorUpsert(currRec);
- // elimino cache redis dati porta...
- bool answ = await DoorFlushCache(currRec.DoorId);
- // elimino cache redis dati ordine...
- answ = answ && await OrdersFlushCache();
+ bool dbResult = false;
+ try
+ {
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ dbResult = await dbController.DoorUpsert(currRec);
+ // elimino cache redis dati porta...
+ bool answ = await DoorFlushCache(currRec.DoorId);
+ // elimino cache redis dati ordine...
+ answ = answ && await OrdersFlushCache();
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"DoorUpsert | {currRec.DoorId} in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during DoorUpsert: {exc}{Environment.NewLine}");
+ }
return dbResult;
}
@@ -2001,64 +2037,74 @@ namespace WebDoorCreator.Data.Services
await Task.Delay(1);
List listValuesTemp = new List();
ListValuesTempModel listValObj = new ListValuesTempModel();
-
- IniFile fIni = new IniFile(file);
- //cerco il contenuto delle sezioni
- var graphicParamsName = fIni.ReadSection(match.Substring(1, match.Length - 2));
- //controllo se tra numPar numeri di graphic params vi è un buco ES: Graphic parameters1 Graphic parameters3 se il buco c'è salto tutti numPar parametri che stanno dopo il buco ==> tengo conto solo di Graphic parameters1
- if (int.Parse(match.Substring(match.Length - 2, 1)) == n)
+ try
{
- int ordinal = 1;
- foreach (string param in graphicParamsName)
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ IniFile fIni = new IniFile(file);
+ //cerco il contenuto delle sezioni
+ var graphicParamsName = fIni.ReadSection(match.Substring(1, match.Length - 2));
+ //controllo se tra numPar numeri di graphic params vi è un buco ES: Graphic parameters1 Graphic parameters3 se il buco c'è salto tutti numPar parametri che stanno dopo il buco ==> tengo conto solo di Graphic parameters1
+ if (int.Parse(match.Substring(match.Length - 2, 1)) == n)
{
- string compoParams = fIni.ReadString(match.Substring(1, match.Length - 2), $"{param.Split("=")[0]}", "CONFIG"); //cerco il parametro nella sezione
- var compoParamsSplit = compoParams.Split(";");
-
- string CompoParamName = "";
- string CompoParamAlias = "";
- if (param.Split("=")[0].StartsWith("Param"))
+ int ordinal = 1;
+ foreach (string param in graphicParamsName)
{
- if (compoParamsSplit[1].Contains("/"))
- {
- CompoParamName = compoParamsSplit[1].Split("/")[0];
- CompoParamAlias = compoParamsSplit[1].Split("/")[1];
- }
- else if (compoParamsSplit[1].Contains(" "))
- {
- CompoParamName = compoParamsSplit[1].Split(" ")[1];
- //CompoParamAlias = compoParamsSplit[1].Split(" ")[1];
- }
+ string compoParams = fIni.ReadString(match.Substring(1, match.Length - 2), $"{param.Split("=")[0]}", "CONFIG"); //cerco il parametro nella sezione
+ var compoParamsSplit = compoParams.Split(";");
- //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione
-
- listValObj = new ListValuesTempModel()
+ string CompoParamName = "";
+ string CompoParamAlias = "";
+ if (param.Split("=")[0].StartsWith("Param"))
{
- TableName = $"{HwCode}".Trim(),
- FieldName = match.Substring(1, match.Length - 2),
- Value = CompoParamName,
- Label = CompoParamAlias,
- Ordinal = ordinal,
- DefaultVal = param.Split("=")[1].Split(";")[2],
- InputType = param.Split("=")[1].Split(";")[0],
- isSerializable = true
- };
+ if (compoParamsSplit[1].Contains("/"))
+ {
+ CompoParamName = compoParamsSplit[1].Split("/")[0];
+ CompoParamAlias = compoParamsSplit[1].Split("/")[1];
+ }
+ else if (compoParamsSplit[1].Contains(" "))
+ {
+ CompoParamName = compoParamsSplit[1].Split(" ")[1];
+ //CompoParamAlias = compoParamsSplit[1].Split(" ")[1];
+ }
- if (listValuesTemp.Where(x => x.TableName == listValObj.TableName && x.FieldName == listValObj.FieldName && x.Value == listValObj.Value).Count() == 0 && listValObj.TableName != null && listValObj.FieldName != null && listValObj.Value != null)
- {
- listValuesTemp.Add(listValObj);
- ordinal++;
+ //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione
+
+ listValObj = new ListValuesTempModel()
+ {
+ TableName = $"{HwCode}".Trim(),
+ FieldName = match.Substring(1, match.Length - 2),
+ Value = CompoParamName,
+ Label = CompoParamAlias,
+ Ordinal = ordinal,
+ DefaultVal = param.Split("=")[1].Split(";")[2],
+ InputType = param.Split("=")[1].Split(";")[0],
+ isSerializable = true
+ };
+
+ if (listValuesTemp.Where(x => x.TableName == listValObj.TableName && x.FieldName == listValObj.FieldName && x.Value == listValObj.Value).Count() == 0 && listValObj.TableName != null && listValObj.FieldName != null && listValObj.Value != null)
+ {
+ listValuesTemp.Add(listValObj);
+ ordinal++;
+ }
+ else
+ {
+ Log.Error($"GraphicParamsGetAll | Duplicated key: {listValObj.TableName} {listValObj.FieldName} {listValObj.Value} ");
+ }
}
else
{
- Log.Error($"GraphicParamsGetAll | Duplicated key: {listValObj.TableName} {listValObj.FieldName} {listValObj.Value} ");
}
}
- else
- {
- }
}
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"GraphicParamsGetAll | {file} in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during GraphicParamsGetAll: {exc}{Environment.NewLine}");
}
-
return listValuesTemp;
}
@@ -2071,37 +2117,44 @@ namespace WebDoorCreator.Data.Services
string source = "DB";
List? dbResult = new List();
- // cerco da cache
- string currKey = $"{Constants.rKeyLanguage}";
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- string? rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty(rawData))
+ try
{
- source = "REDIS";
- var tempResult = JsonConvert.DeserializeObject>(rawData);
- if (tempResult == null)
+ // cerco da cache
+ string currKey = $"{Constants.rKeyLanguage}";
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string? rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty(rawData))
{
- dbResult = new List();
+ source = "REDIS";
+ var tempResult = JsonConvert.DeserializeObject>(rawData);
+ if (tempResult == null)
+ {
+ dbResult = new List();
+ }
+ else
+ {
+ dbResult = tempResult;
+ }
}
else
{
- dbResult = tempResult;
+ dbResult = dbController.LanguageGetAll();
+ rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
+ await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
+ if (dbResult == null)
+ {
+ dbResult = new List();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"LanguageGetAll | {source} in: {ts.TotalMilliseconds} ms"); stopWatch.Stop();
}
- else
+ catch (Exception exc)
{
- dbResult = dbController.LanguageGetAll();
- rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
- await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
+ Log.Error($"Exception during LanguageGetAll: {exc}{Environment.NewLine}");
}
- if (dbResult == null)
- {
- dbResult = new List();
- }
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"LanguageGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
@@ -2114,38 +2167,45 @@ namespace WebDoorCreator.Data.Services
List? dbResult = new List();
string currKey = "";
- // cerco da cache
- currKey = $"{Constants.rKeyListValues}:{tableName}:{fieldName}";
-
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- string? rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty(rawData))
+ try
{
- source = "REDIS";
- var tempResult = JsonConvert.DeserializeObject>(rawData);
- if (tempResult == null)
+ // cerco da cache
+ currKey = $"{Constants.rKeyListValues}:{tableName}:{fieldName}";
+
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string? rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty(rawData))
{
- dbResult = new List();
+ source = "REDIS";
+ var tempResult = JsonConvert.DeserializeObject>(rawData);
+ if (tempResult == null)
+ {
+ dbResult = new List();
+ }
+ else
+ {
+ dbResult = tempResult;
+ }
}
else
{
- dbResult = tempResult;
+ dbResult = dbController.ListValuesGetAll(tableName, fieldName);
+ rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
+ await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
+ if (dbResult == null)
+ {
+ dbResult = new List();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"ListValuesGetAll | {source} in: {ts.TotalMilliseconds} ms"); stopWatch.Stop();
}
- else
+ catch (Exception exc)
{
- dbResult = dbController.ListValuesGetAll(tableName, fieldName);
- rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
- await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
+ Log.Error($"Exception during ListValuesGetAll: {exc}{Environment.NewLine}");
}
- if (dbResult == null)
- {
- dbResult = new List();
- }
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"ListValuesGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
@@ -2156,125 +2216,128 @@ namespace WebDoorCreator.Data.Services
List doorOpTypesList = new List();
MD5 md5 = MD5.Create();
- //ciclo nelle directories usando la colonna opcode
- //foreach (var itemOld in HwsList)
- string dir = HwTpl.OpCode;
- string compoCode = "";
- string compoTempOrShape = "";
- string[] templateDirectories = Directory.GetDirectories(dir);
-
- string[] iniFiles = Directory.GetFiles(dir, "Config.ini");
-
- int ordin = 1;
- foreach (string templateDirectory in templateDirectories)
+ try
{
- var tName = templateDirectory.Split("\\");
- var fName = templateDirectory.Split("\\");
+ //ciclo nelle directories usando la colonna opcode
+ //foreach (var itemOld in HwsList)
+ string dir = HwTpl.OpCode;
+ string compoCode = "";
+ string compoTempOrShape = "";
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string[] templateDirectories = Directory.GetDirectories(dir);
- foreach (var file in iniFiles)
+ string[] iniFiles = Directory.GetFiles(dir, "Config.ini");
+
+ int ordin = 1;
+ foreach (string templateDirectory in templateDirectories)
{
- List lines = File.ReadAllLines(file).ToList();
- IniFile fIni = new IniFile(file);
+ var tName = templateDirectory.Split("\\");
+ var fName = templateDirectory.Split("\\");
- var compoName = fIni.ReadString("Compo", "Name", "COMPONAME");
- var compoT = fIni.ReadString("Template", "Name", "TEMPSHAPE");
- compoCode = compoName.Split("/")[0].Trim();
- compoTempOrShape = compoT.Split("/")[0].Trim();
- }
-
- string[] templateFiles = Directory.GetFiles(templateDirectory);
- if (templateFiles.Length > 0)
- {
- ListValuesTempModel folderNames = new ListValuesTempModel()
+ foreach (var file in iniFiles)
{
- TableName = $"{compoCode}".Replace(" ", "_"),
- FieldName = "Folder",
- Value = @$"{tName[tName.Length - 1]}",
- Label = @$"{tName[tName.Length - 1]}",
- Ordinal = 0,
- DefaultVal = " ",
- InputType = " ",
- };
- values.Add(folderNames);
- }
+ List lines = File.ReadAllLines(file).ToList();
+ IniFile fIni = new IniFile(file);
- foreach (string templateFile in templateFiles)
- {
- FileInfo fi = new FileInfo(templateFile);
- string defGpNum = "";
- var lines = File.ReadAllLines(templateFile).ToList();
+ var compoName = fIni.ReadString("Compo", "Name", "COMPONAME");
+ var compoT = fIni.ReadString("Template", "Name", "TEMPSHAPE");
+ compoCode = compoName.Split("/")[0].Trim();
+ compoTempOrShape = compoT.Split("/")[0].Trim();
+ }
- foreach (var line in lines)
+ string[] templateFiles = Directory.GetFiles(templateDirectory);
+ if (templateFiles.Length > 0)
{
- if (line.StartsWith("--") && line.Contains("Default"))
+ ListValuesTempModel folderNames = new ListValuesTempModel()
{
- if (line.Split("=")[1] != null)
+ TableName = $"{compoCode}".Replace(" ", "_"),
+ FieldName = "Folder",
+ Value = @$"{tName[tName.Length - 1]}",
+ Label = @$"{tName[tName.Length - 1]}",
+ Ordinal = 0,
+ DefaultVal = " ",
+ InputType = " ",
+ };
+ values.Add(folderNames);
+ }
+
+ foreach (string templateFile in templateFiles)
+ {
+ FileInfo fi = new FileInfo(templateFile);
+ string defGpNum = "";
+ var lines = File.ReadAllLines(templateFile).ToList();
+
+ foreach (var line in lines)
+ {
+ if (line.StartsWith("--") && line.Contains("Default"))
{
- defGpNum = line.Split("=")[1];
- }
- else
- {
- defGpNum = " ";
+ if (line.Split("=")[1] != null)
+ {
+ defGpNum = line.Split("=")[1];
+ }
+ else
+ {
+ defGpNum = " ";
+ }
}
}
- }
- var fileName = "";
- if (Path.GetFileName(templateFile).Split(".")[1] == "lua")
- {
- fileName = Path.GetFileName(templateFile).Split(".")[0];
- }
- else
- {
- fileName = Path.GetFileName(templateFile);
- }
+ var fileName = "";
+ if (Path.GetFileName(templateFile).Split(".")[1] == "lua")
+ {
+ fileName = Path.GetFileName(templateFile).Split(".")[0];
+ }
+ else
+ {
+ fileName = Path.GetFileName(templateFile);
+ }
- ListValuesTempModel temp = new ListValuesTempModel()
- {
- TableName = $"{compoCode}".Replace(" ", "_"),
- FieldName = compoTempOrShape,
- Value = @$"{tName[tName.Length - 1]}\{fileName}",
- Label = fileName,
- Ordinal = ordin,
- DefaultVal = defGpNum,
- InputType = " ",
- };
- var fileContent = File.ReadAllBytes(templateFile);
- var hash = md5.ComputeHash(fileContent);
- var oldMD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
- DoorOpTypeModel tempType = new DoorOpTypeModel()
- {
- ParentId = HwTpl.DoorOpTypId,
- Description = $"Template for {compoCode.Replace(" ", "_")}",
- OpCode = @$"{dir}\{tName[tName.Length - 1]}\{Path.GetFileName(templateFile)}",
- HasHw = true,
- IsConcrete = true,
- HwCode = $"{compoCode}".Replace(" ", "_"),
- FileDim = fi.Length,
- FileMD5 = oldMD5,
- LastMod = fi.LastWriteTime
- };
- doorOpTypesList.Add(tempType);
- 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} ");
+ ListValuesTempModel temp = new ListValuesTempModel()
+ {
+ TableName = $"{compoCode}".Replace(" ", "_"),
+ FieldName = compoTempOrShape,
+ Value = @$"{tName[tName.Length - 1]}\{fileName}",
+ Label = fileName,
+ Ordinal = ordin,
+ DefaultVal = defGpNum,
+ InputType = " ",
+ };
+ var fileContent = File.ReadAllBytes(templateFile);
+ var hash = md5.ComputeHash(fileContent);
+ var oldMD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
+ DoorOpTypeModel tempType = new DoorOpTypeModel()
+ {
+ ParentId = HwTpl.DoorOpTypId,
+ Description = $"Template for {compoCode.Replace(" ", "_")}",
+ OpCode = @$"{dir}\{tName[tName.Length - 1]}\{Path.GetFileName(templateFile)}",
+ HasHw = true,
+ IsConcrete = true,
+ HwCode = $"{compoCode}".Replace(" ", "_"),
+ FileDim = fi.Length,
+ FileMD5 = oldMD5,
+ LastMod = fi.LastWriteTime
+ };
+ doorOpTypesList.Add(tempType);
+ 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($"ListValuesLuaNgeInsert | Duplicated key: {temp.TableName} {temp.FieldName} {temp.Value} ");
+ }
}
}
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"ListValuesLuaNgeInsert in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during ListValuesLuaNgeInsert: {exc}{Environment.NewLine}");
}
-
- //bool done = await dbController.ListValuesAdd(values);
-
- //bool fatto = false;
-
- //if (done)
- //{
- // fatto = await dbController.DoorOpTypeAddRange(doorOpTypesList);
- //}
return doorOpTypesList;
}
@@ -2286,10 +2349,23 @@ namespace WebDoorCreator.Data.Services
///
public async Task OrderAdd(OrderModel currRec)
{
- var dbResult = await dbController.OrderAdd(currRec);
- // elimino cache redis...
- RedisValue pattern = new RedisValue($"{Constants.rKeyOrderStatus}:*");
- bool answ = await ExecFlushRedisPattern(pattern);
+ int dbResult = 0;
+ try
+ {
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ dbResult = await dbController.OrderAdd(currRec);
+ // elimino cache redis...
+ RedisValue pattern = new RedisValue($"{Constants.rKeyOrderStatus}:*");
+ bool answ = await ExecFlushRedisPattern(pattern);
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"OrderAdd | {currRec.OrderExtCode} in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during OrderAdd: {exc}{Environment.NewLine}");
+ }
return dbResult;
}
@@ -2318,10 +2394,23 @@ namespace WebDoorCreator.Data.Services
///
public async Task OrderDuplicate(int OrdIdSrc, int OrdIdDest, string UsrIdMod)
{
- var dbResult = await dbController.OrderDuplicate(OrdIdSrc, OrdIdDest, UsrIdMod);
- // elimino cache redis...
- RedisValue pattern = new RedisValue($"{Constants.rKeyOrderStatus}:*");
- bool answ = await ExecFlushRedisPattern(pattern);
+ bool dbResult = false;
+ try
+ {
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ dbResult = await dbController.OrderDuplicate(OrdIdSrc, OrdIdDest, UsrIdMod);
+ // elimino cache redis...
+ RedisValue pattern = new RedisValue($"{Constants.rKeyOrderStatus}:*");
+ bool answ = await ExecFlushRedisPattern(pattern);
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"OrderDuplicate | {OrdIdSrc} in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during OrderDuplicate: {exc}{Environment.NewLine}");
+ }
return dbResult;
}
@@ -2330,37 +2419,44 @@ namespace WebDoorCreator.Data.Services
string source = "DB";
List? dbResult = new List();
- // cerco da cache
- string currKey = $"{Constants.rKeyOrderByComp}:{CompanyId}:{StatusId}"; ;
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- string? rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty(rawData))
+ try
{
- source = "REDIS";
- var tempResult = JsonConvert.DeserializeObject>(rawData);
- if (tempResult == null)
+ // cerco da cache
+ string currKey = $"{Constants.rKeyOrderByComp}:{CompanyId}:{StatusId}"; ;
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string? rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty(rawData))
{
- dbResult = new List();
+ source = "REDIS";
+ var tempResult = JsonConvert.DeserializeObject>(rawData);
+ if (tempResult == null)
+ {
+ dbResult = new List();
+ }
+ else
+ {
+ dbResult = tempResult;
+ }
}
else
{
- dbResult = tempResult;
+ dbResult = dbController.OrderGetByCompStatus(CompanyId, StatusId);
+ rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
+ await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
+ if (dbResult == null)
+ {
+ dbResult = new List();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"OrderGetByCompStatus | {source} in: {ts.TotalMilliseconds} ms");
}
- else
+ catch (Exception exc)
{
- dbResult = dbController.OrderGetByCompStatus(CompanyId, StatusId);
- rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
- await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
+ Log.Error($"Exception during OrderGetByCompStatus: {exc}{Environment.NewLine}");
}
- if (dbResult == null)
- {
- dbResult = new List();
- }
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"OrderGetByCompStatus | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
@@ -2369,60 +2465,79 @@ namespace WebDoorCreator.Data.Services
string source = "DB";
OrderModel? dbResult = new OrderModel();
- // cerco da cache
- string currKey = $"{Constants.rKeyOrderDetail}:{orderId}"; ;
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- string? rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty(rawData))
+ try
{
- source = "REDIS";
- var tempResult = JsonConvert.DeserializeObject(rawData);
- if (tempResult == null)
+ // cerco da cache
+ string currKey = $"{Constants.rKeyOrderDetail}:{orderId}"; ;
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string? rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty(rawData))
{
- dbResult = new OrderModel();
+ source = "REDIS";
+ var tempResult = JsonConvert.DeserializeObject(rawData);
+ if (tempResult == null)
+ {
+ dbResult = new OrderModel();
+ }
+ else
+ {
+ dbResult = tempResult;
+ }
}
else
{
- dbResult = tempResult;
+ dbResult = dbController.OrderGetByKey(orderId);
+ rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
+ await redisDb.StringSetAsync(currKey, rawData, LongCache);
}
+ if (dbResult == null)
+ {
+ dbResult = new OrderModel();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"OrderGetByKey | {source} in: {ts.TotalMilliseconds} ms");
}
- else
+ catch (Exception exc)
{
- dbResult = dbController.OrderGetByKey(orderId);
- rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
- await redisDb.StringSetAsync(currKey, rawData, LongCache);
+ Log.Error($"Exception during OrderGetByKey: {exc}{Environment.NewLine}");
}
- if (dbResult == null)
- {
- dbResult = new OrderModel();
- }
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"OrderGetByKey | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
///
/// Remove order
///
- ///
+ ///
///
public async Task OrderRem(int OrdId)
{
- var dbResult = await dbController.OrderRem(OrdId);
- // elimino cache redis...
- RedisValue pattern = new RedisValue($"{Constants.rKeyOrderStatus}:*");
- bool answ = await ExecFlushRedisPattern(pattern);
- pattern = new RedisValue($"{Constants.rKeyOrderByComp}:*");
- answ = await ExecFlushRedisPattern(pattern);
+ bool dbResult = false;
+ try
+ {
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ dbResult = await dbController.OrderRem(OrdId);
+ // elimino cache redis...
+ RedisValue pattern = new RedisValue($"{Constants.rKeyOrderStatus}:*");
+ bool answ = await ExecFlushRedisPattern(pattern);
+ pattern = new RedisValue($"{Constants.rKeyOrderByComp}:*");
+ answ = await ExecFlushRedisPattern(pattern);
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"OrderRem | {OrdId} in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during OrderRem: {exc}{Environment.NewLine}");
+ }
return dbResult;
}
///
/// Clean redis ORDERS cache
///
- ///
///
public async Task OrdersFlushCache()
{
@@ -2436,39 +2551,46 @@ namespace WebDoorCreator.Data.Services
string source = "DB";
List? dbResult = new List();
- // cerco da cache
- string currKey = $"{Constants.rKeyOrderStatus}:{companyId}:{orderStatus}:{dataFrom:yyyyMMdd}:{dataTo:yyyyMMdd}";
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- string? rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty(rawData))
+ try
{
- source = "REDIS";
- var tempResult = JsonConvert.DeserializeObject>(rawData);
- if (tempResult == null)
+ // cerco da cache
+ string currKey = $"{Constants.rKeyOrderStatus}:{companyId}:{orderStatus}:{dataFrom:yyyyMMdd}:{dataTo:yyyyMMdd}";
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string? rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty(rawData))
{
- dbResult = new List();
+ source = "REDIS";
+ var tempResult = JsonConvert.DeserializeObject>(rawData);
+ if (tempResult == null)
+ {
+ dbResult = new List();
+ }
+ else
+ {
+ dbResult = tempResult;
+ }
}
else
{
- dbResult = tempResult;
+ var rawResult = dbController.OrderStatusGetAll(companyId, orderStatus, dataFrom, dataTo);
+ // ordino desc in ram...
+ dbResult = rawResult.OrderByDescending(x => x.OrderId).ToList();
+ rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
+ await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
+ if (dbResult == null)
+ {
+ dbResult = new List();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"OrderStatusGetFilt | {source} in: {ts.TotalMilliseconds} ms");
}
- else
+ catch (Exception exc)
{
- var rawResult = dbController.OrderStatusGetAll(companyId, orderStatus, dataFrom, dataTo);
- // ordino desc in ram...
- dbResult = rawResult.OrderByDescending(x => x.OrderId).ToList();
- rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
- await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
+ Log.Error($"Exception during OrderStatusGetFilt: {exc}{Environment.NewLine}");
}
- if (dbResult == null)
- {
- dbResult = new List();
- }
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"OrderStatusGetFilt | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
@@ -2495,9 +2617,23 @@ namespace WebDoorCreator.Data.Services
///
public async Task OrderUpdatePromDate(int orderId, DateTime dateProm)
{
- var dbResult = await dbController.OrderUpdatePromDate(orderId, dateProm);
- // elimino cache redis dati ordine...
- bool answ = await FlushRedisCache();
+ bool dbResult = false;
+ try
+ {
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+
+ dbResult = await dbController.OrderUpdatePromDate(orderId, dateProm);
+ // elimino cache redis dati ordine...
+ bool answ = await FlushRedisCache();
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"OrderUpdatePromDate | {orderId} in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during OrderUpdatePromDate: {exc}{Environment.NewLine}");
+ }
return dbResult;
}
@@ -2509,9 +2645,23 @@ namespace WebDoorCreator.Data.Services
///
public async Task OrderUpdateStatus(int orderId, int newStatus)
{
- var dbResult = await dbController.OrderUpdateStatus(orderId, newStatus);
- // elimino cache redis dati ordine...
- bool answ = await ExecFlushRedisPattern($"{Constants.rKeyOrderStatus}:*");
+ bool dbResult = false;
+ try
+ {
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+
+ dbResult = dbResult = await dbController.OrderUpdateStatus(orderId, newStatus);
+ // elimino cache redis dati ordine...
+ bool answ = await ExecFlushRedisPattern($"{Constants.rKeyOrderStatus}:*");
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"OrderUpdateStatus | {orderId} in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during OrderUpdateStatus: {exc}{Environment.NewLine}");
+ }
return dbResult;
}
@@ -2524,78 +2674,97 @@ namespace WebDoorCreator.Data.Services
List? dbResult = new List();
// cerco da cache
- string currKey = $"{Constants.rKeyGraphicParameters}:{hwId}";
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- string? rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty(rawData))
+ try
{
- source = "REDIS";
- var tempResult = JsonConvert.DeserializeObject>(rawData);
- if (tempResult == null)
+ string currKey = $"{Constants.rKeyGraphicParameters}:{hwId}";
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string? rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty(rawData))
{
- dbResult = new List();
+ source = "REDIS";
+ var tempResult = JsonConvert.DeserializeObject>(rawData);
+ if (tempResult == null)
+ {
+ dbResult = new List();
+ }
+ else
+ {
+ dbResult = tempResult;
+ }
}
else
{
- dbResult = tempResult;
+ dbResult = dbController.ParamGetByHwId(hwId);
+ rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
+ await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
+ if (dbResult == null)
+ {
+ dbResult = new List();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"ParamGetByHwId | {source} in: {ts.TotalMilliseconds} ms");
}
- else
+ catch (Exception exc)
{
- dbResult = dbController.ParamGetByHwId(hwId);
- rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
- await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
+ Log.Error($"Exception during ParamGetByHwId: {exc}{Environment.NewLine}");
}
- if (dbResult == null)
- {
- dbResult = new List();
- }
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"ParamGetByHwId | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
public async Task populateHws()
{
bool answ = false;
- string rootPath = _configuration.GetValue("CompoBaseDirs:NewCompoDir");
- List listActiveCompo = await CompoGetAllActive(Path.Combine(rootPath, @"Default.ini"));
- string[] dirs = Directory.GetDirectories(rootPath);
- List doorOpTypesList = new List();
- foreach (string dir in dirs)
+ try
{
- string compoCode = "";
- string[] templateDirectories = Directory.GetDirectories(dir);
-
- string[] iniFiles = Directory.GetFiles(dir, "Config.ini");
-
- foreach (var file in iniFiles)
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string rootPath = _configuration.GetValue("CompoBaseDirs:NewCompoDir");
+ List listActiveCompo = await CompoGetAllActive(Path.Combine(rootPath, @"Default.ini"));
+ string[] dirs = Directory.GetDirectories(rootPath);
+ List doorOpTypesList = new List();
+ foreach (string dir in dirs)
{
- List lines = File.ReadAllLines(file).ToList();
- IniFile fIni = new IniFile(file);
+ string compoCode = "";
+ string[] templateDirectories = Directory.GetDirectories(dir);
- var compoName = fIni.ReadString("Compo", "Name", "COMPONAME");
- var compoT = fIni.ReadString("Template", "Name", "TEMPSHAPE");
- compoCode = compoName.Split("/")[0].Trim();
- }
- if (listActiveCompo.Contains(compoCode))
- {
- DoorOpTypeModel tempHwType = new DoorOpTypeModel()
+ string[] iniFiles = Directory.GetFiles(dir, "Config.ini");
+
+ foreach (var file in iniFiles)
{
- ParentId = 0,
- Description = $"Hardware Type {compoCode.Replace(" ", "_")}",
- OpCode = @$"{dir}",
- HasHw = true,
- IsConcrete = true,
- HwCode = $"{compoCode}".Replace(" ", "_")
- };
- doorOpTypesList.Add(tempHwType);
+ List lines = File.ReadAllLines(file).ToList();
+ IniFile fIni = new IniFile(file);
+
+ var compoName = fIni.ReadString("Compo", "Name", "COMPONAME");
+ var compoT = fIni.ReadString("Template", "Name", "TEMPSHAPE");
+ compoCode = compoName.Split("/")[0].Trim();
+ }
+ if (listActiveCompo.Contains(compoCode))
+ {
+ DoorOpTypeModel tempHwType = new DoorOpTypeModel()
+ {
+ ParentId = 0,
+ Description = $"Hardware Type {compoCode.Replace(" ", "_")}",
+ OpCode = @$"{dir}",
+ HasHw = true,
+ IsConcrete = true,
+ HwCode = $"{compoCode}".Replace(" ", "_")
+ };
+ doorOpTypesList.Add(tempHwType);
+ }
}
+ //scrivo su db hws
+ await dbController.DoorOpTypeAddRange(doorOpTypesList);
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"populateHws in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during populateHws: {exc}{Environment.NewLine}");
}
- //scrivo su db hws
- await dbController.DoorOpTypeAddRange(doorOpTypesList);
return answ;
}
@@ -2608,39 +2777,46 @@ namespace WebDoorCreator.Data.Services
{
string source = "DB";
List? dbResult = new List();
- // cerco da cache
- string currKey = $"{Constants.rKeyOrderStatus}:{orderId}";
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- string? rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty(rawData))
+ try
{
- source = "REDIS";
- var tempResult = JsonConvert.DeserializeObject>(rawData);
- if (tempResult == null)
+ // cerco da cache
+ string currKey = $"{Constants.rKeyOrderStatus}:{orderId}";
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string? rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty(rawData))
{
- dbResult = new List();
+ source = "REDIS";
+ var tempResult = JsonConvert.DeserializeObject>(rawData);
+ if (tempResult == null)
+ {
+ dbResult = new List();
+ }
+ else
+ {
+ dbResult = tempResult;
+ }
}
else
{
- dbResult = tempResult;
+ var rawResult = dbController.PreRepOrderGetByKey(orderId);
+ // ordino desc in ram...
+ dbResult = rawResult.OrderByDescending(x => x.OrderId).ToList();
+ rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
+ await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
}
+ if (dbResult == null)
+ {
+ dbResult = new List();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"PreRepOrderGetByKey | {source} in: {ts.TotalMilliseconds} ms");
}
- else
+ catch (Exception exc)
{
- var rawResult = dbController.PreRepOrderGetByKey(orderId);
- // ordino desc in ram...
- dbResult = rawResult.OrderByDescending(x => x.OrderId).ToList();
- rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
- await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
+ Log.Error($"Exception during populateHws: {exc}{Environment.NewLine}");
}
- if (dbResult == null)
- {
- dbResult = new List();
- }
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"PreRepOrderGetByKey | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
@@ -2667,107 +2843,124 @@ namespace WebDoorCreator.Data.Services
string source = "DB";
List? dbResult = new List();
- // cerco da cache
- string currKey = Constants.rKeyRoles;
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- string? rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty(rawData))
+ try
{
- source = "REDIS";
- var tempResult = JsonConvert.DeserializeObject>(rawData);
- if (tempResult == null)
+ // cerco da cache
+ string currKey = Constants.rKeyRoles;
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string? rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty(rawData))
{
- dbResult = new List();
+ source = "REDIS";
+ var tempResult = JsonConvert.DeserializeObject>(rawData);
+ if (tempResult == null)
+ {
+ dbResult = new List();
+ }
+ else
+ {
+ dbResult = tempResult;
+ }
}
else
{
- dbResult = tempResult;
+ dbResult = dbController.RolesGetAll();
+ rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
+ await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
+ if (dbResult == null)
+ {
+ dbResult = new List();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"RolesGetAll | {source} in: {ts.TotalMilliseconds} ms");
}
- else
+ catch (Exception exc)
{
- dbResult = dbController.RolesGetAll();
- rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
- await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
+ Log.Error($"Exception during RolesGetAll: {exc}{Environment.NewLine}");
}
- if (dbResult == null)
- {
- dbResult = new List();
- }
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"RolesGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
public async Task> scanAndCompare()
{
- string rootPathNew = _configuration.GetValue("CompoBaseDirs:NewCompoDir");
- string rootPathOld = _configuration.GetValue("CompoBaseDirs:CurrCompoDir");
-
- List tempStats = new List();
List doorOpTypesList = new List();
- System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
+ List tempStats = new List();
List archiviedFiles = new List();
- string newMD5 = "";
-
- var oldFiles = await scanSrcDestDir(rootPathOld);
- var newFiles = await scanSrcDestDir(rootPathNew);
-
- long currFileDim = 0;
- DateTime currFileLastMod = DateTime.Now;
- // ciclo sui file in area NEW x confrontare con old
- foreach (var itemNew in newFiles)
+ try
{
- currFileDim = itemNew.FileDim;
- currFileLastMod = itemNew.lastModTime;
- newMD5 = itemNew.FileMD5;
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string rootPathNew = _configuration.GetValue("CompoBaseDirs:NewCompoDir");
+ string rootPathOld = _configuration.GetValue("CompoBaseDirs:CurrCompoDir");
+ System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
+ string newMD5 = "";
- var currTpl = oldFiles.Where(t => t.FileRelPath == itemNew.FileRelPath.Replace("NewComp", "CurComp") && t.FileMD5 == itemNew.FileMD5).FirstOrDefault();
- if (currTpl != null)
+ var oldFiles = await scanSrcDestDir(rootPathOld);
+ var newFiles = await scanSrcDestDir(rootPathNew);
+
+ long currFileDim = 0;
+ DateTime currFileLastMod = DateTime.Now;
+ // ciclo sui file in area NEW x confrontare con old
+ foreach (var itemNew in newFiles)
{
+ currFileDim = itemNew.FileDim;
+ currFileLastMod = itemNew.lastModTime;
+ newMD5 = itemNew.FileMD5;
- // verifica sul DB
- archiviedFiles = dbController.DoorOpTypeGetByPath(currTpl.FileBaseDir);
- var path2Search = archiviedFiles
- .Where(x => x.OpCode == currTpl.FileAbsPath)
- .FirstOrDefault();
- tempStats.Add(0);
- if (path2Search == null)
+ var currTpl = oldFiles.Where(t => t.FileRelPath == itemNew.FileRelPath.Replace("NewComp", "CurComp") && t.FileMD5 == itemNew.FileMD5).FirstOrDefault();
+ if (currTpl != null)
{
+ // verifica sul DB
+ archiviedFiles = dbController.DoorOpTypeGetByPath(currTpl.FileBaseDir);
+ var path2Search = archiviedFiles
+ .Where(x => x.OpCode == currTpl.FileAbsPath)
+ .FirstOrDefault();
+ tempStats.Add(0);
+ if (path2Search == null)
+ {
+ }
+ else if (path2Search.FileMD5 != newMD5 || path2Search.FileDim != currFileDim || path2Search.LastMod != currFileLastMod)
+ {
+ path2Search.FileDim = currFileDim;
+ path2Search.FileMD5 = newMD5;
+ path2Search.LastMod = currFileLastMod;
+ path2Search.Description = "modded";
+ path2Search.status = 2;
+ await dbController.DoorOpTypeUpdate(path2Search);
+ }
}
- else if (path2Search.FileMD5 != newMD5 || path2Search.FileDim != currFileDim || path2Search.LastMod != currFileLastMod)
+ else
{
- path2Search.FileDim = currFileDim;
- path2Search.FileMD5 = newMD5;
- path2Search.LastMod = currFileLastMod;
- path2Search.Description = "modded";
- path2Search.status = 2;
- await dbController.DoorOpTypeUpdate(path2Search);
+ DoorOpTypeModel tempTpl = new DoorOpTypeModel()
+ {
+ ParentId = 0,
+ Description = $"Template for {itemNew.HwCode}",
+ OpCode = @$"{itemNew.FileAbsPath.Replace("NewComp", "CurComp")}",
+ HasHw = true,
+ IsConcrete = true,
+ HwCode = itemNew.HwCode,
+ FileDim = currFileDim,
+ FileMD5 = newMD5,
+ LastMod = currFileLastMod,
+ status = 1
+ };
+ doorOpTypesList.Add(tempTpl);
+ oldFiles.Add(itemNew);
}
}
- else
- {
- DoorOpTypeModel tempTpl = new DoorOpTypeModel()
- {
- ParentId = 0,
- Description = $"Template for {itemNew.HwCode}",
- OpCode = @$"{itemNew.FileAbsPath.Replace("NewComp", "CurComp")}",
- HasHw = true,
- IsConcrete = true,
- HwCode = itemNew.HwCode,
- FileDim = currFileDim,
- FileMD5 = newMD5,
- LastMod = currFileLastMod,
- status = 1
- };
- doorOpTypesList.Add(tempTpl);
- oldFiles.Add(itemNew);
- }
+ archiviedFiles.Clear();
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"scanAndCompare in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during scanAndCompare: {exc}{Environment.NewLine}");
}
- archiviedFiles.Clear();
return doorOpTypesList;
}
@@ -2782,52 +2975,65 @@ namespace WebDoorCreator.Data.Services
await Task.Delay(1);
List dirAFiles = new List();
- string[] dirs = Directory.GetDirectories(rootPath);
-
- using (MD5 md5 = MD5.Create())
+ try
{
- foreach (var dir in dirs)
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+
+ string[] dirs = Directory.GetDirectories(rootPath);
+
+ using (MD5 md5 = MD5.Create())
{
- string[] iniFiles = Directory.GetFiles(dir, "Config.ini");
- string compoCode = "";
- foreach (var file in iniFiles)
+ foreach (var dir in dirs)
{
- List lines = File.ReadAllLines(file).ToList();
- IniFile fIni = new IniFile(file);
-
- var compoName = fIni.ReadString("Compo", "Name", "COMPONAME");
- var compoT = fIni.ReadString("Template", "Name", "TEMPSHAPE");
- compoCode = compoName.Split("/")[0].Trim();
- }
- string[] templateDirectories = Directory.GetDirectories(dir);
-
- foreach (var tplDir in templateDirectories)
- {
- string[] tpls = Directory.GetFiles(tplDir, "*");
- var archiviedFiles = dbController.DoorOpTypeGetByPath(tplDir);
- foreach (var tpl in tpls)
+ string[] iniFiles = Directory.GetFiles(dir, "Config.ini");
+ string compoCode = "";
+ foreach (var file in iniFiles)
{
- FileInfo fi = new FileInfo(tpl);
- var fileName = Path.GetFileName(tpl).Split("\\")[Path.GetFileName(tpl).Split("\\").Length - 1];
- var fileContent = File.ReadAllBytes(tpl);
- var hash = md5.ComputeHash(fileContent);
- var newMD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
- FileDTO currFileInfo = new FileDTO()
+ List lines = File.ReadAllLines(file).ToList();
+ IniFile fIni = new IniFile(file);
+
+ var compoName = fIni.ReadString("Compo", "Name", "COMPONAME");
+ var compoT = fIni.ReadString("Template", "Name", "TEMPSHAPE");
+ compoCode = compoName.Split("/")[0].Trim();
+ }
+ string[] templateDirectories = Directory.GetDirectories(dir);
+
+ foreach (var tplDir in templateDirectories)
+ {
+ string[] tpls = Directory.GetFiles(tplDir, "*");
+ var archiviedFiles = dbController.DoorOpTypeGetByPath(tplDir);
+ foreach (var tpl in tpls)
{
- HwCode = compoCode.Replace(" ", "_"),
- FileBaseDir = tplDir,
- FileAbsPath = fi.FullName,
- FileRelPath = fileName,
- FileDim = fi.Length,
- FileMD5 = newMD5,
- lastModTime = fi.LastWriteTime
- };
- dirAFiles.Add(currFileInfo);
+ FileInfo fi = new FileInfo(tpl);
+ var fileName = Path.GetFileName(tpl).Split("\\")[Path.GetFileName(tpl).Split("\\").Length - 1];
+ var fileContent = File.ReadAllBytes(tpl);
+ var hash = md5.ComputeHash(fileContent);
+ var newMD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
+ FileDTO currFileInfo = new FileDTO()
+ {
+ HwCode = compoCode.Replace(" ", "_"),
+ FileBaseDir = tplDir,
+ FileAbsPath = fi.FullName,
+ FileRelPath = fileName,
+ FileDim = fi.Length,
+ FileMD5 = newMD5,
+ lastModTime = fi.LastWriteTime
+ };
+ dirAFiles.Add(currFileInfo);
+ }
}
}
}
- }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"scanAndCompare in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during scanAndCompare: {exc}{Environment.NewLine}");
+ }
return dirAFiles;
}
@@ -2854,37 +3060,44 @@ namespace WebDoorCreator.Data.Services
string source = "DB";
List? dbResult = new List();
- // cerco da cache
- string currKey = Constants.rKeyUsers;
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- string? rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty(rawData))
+ try
{
- source = "REDIS";
- var tempResult = JsonConvert.DeserializeObject>(rawData);
- if (tempResult == null)
+ // cerco da cache
+ string currKey = Constants.rKeyUsers;
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string? rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty(rawData))
{
- dbResult = new List();
+ source = "REDIS";
+ var tempResult = JsonConvert.DeserializeObject>(rawData);
+ if (tempResult == null)
+ {
+ dbResult = new List();
+ }
+ else
+ {
+ dbResult = tempResult;
+ }
}
else
{
- dbResult = tempResult;
+ dbResult = dbController.UsersGetAll();
+ rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
+ await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
+ if (dbResult == null)
+ {
+ dbResult = new List();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"UsersGetAll | {source} in: {ts.TotalMilliseconds} ms");
}
- else
+ catch (Exception exc)
{
- dbResult = dbController.UsersGetAll();
- rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
- await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
+ Log.Error($"Exception during UsersGetAll: {exc}{Environment.NewLine}");
}
- if (dbResult == null)
- {
- dbResult = new List();
- }
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"UsersGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
@@ -2896,37 +3109,44 @@ namespace WebDoorCreator.Data.Services
string source = "DB";
AspNetUsers dbResult = new AspNetUsers();
- // cerco da cache
- string currKey = $"{Constants.rKeyUsers}:{userId}";
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- string? rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty(rawData))
+ try
{
- source = "REDIS";
- var tempResult = JsonConvert.DeserializeObject(rawData);
- if (tempResult == null)
+ // cerco da cache
+ string currKey = $"{Constants.rKeyUsers}:{userId}";
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string? rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty(rawData))
{
- dbResult = new AspNetUsers();
+ source = "REDIS";
+ var tempResult = JsonConvert.DeserializeObject(rawData);
+ if (tempResult == null)
+ {
+ dbResult = new AspNetUsers();
+ }
+ else
+ {
+ dbResult = tempResult;
+ }
}
else
{
- dbResult = tempResult;
+ dbResult = dbController.UsersGetById(userId);
+ rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
+ await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
+ if (dbResult == null)
+ {
+ dbResult = new AspNetUsers();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"UsersGetById | {source} in: {ts.TotalMilliseconds} ms");
}
- else
+ catch (Exception exc)
{
- dbResult = dbController.UsersGetById(userId);
- rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
- await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
+ Log.Error($"Exception during UsersGetById: {exc}{Environment.NewLine}");
}
- if (dbResult == null)
- {
- dbResult = new AspNetUsers();
- }
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"UsersGetById | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
@@ -2938,37 +3158,44 @@ namespace WebDoorCreator.Data.Services
string source = "DB";
List? dbResult = new List();
- // cerco da cache
- string currKey = Constants.rKeyUsersView;
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- string? rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty(rawData))
+ try
{
- source = "REDIS";
- var tempResult = JsonConvert.DeserializeObject>(rawData);
- if (tempResult == null)
+ // cerco da cache
+ string currKey = Constants.rKeyUsersView;
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string? rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty(rawData))
{
- dbResult = new List();
+ source = "REDIS";
+ var tempResult = JsonConvert.DeserializeObject>(rawData);
+ if (tempResult == null)
+ {
+ dbResult = new List();
+ }
+ else
+ {
+ dbResult = tempResult;
+ }
}
else
{
- dbResult = tempResult;
+ dbResult = dbController.UserViewGetAll();
+ rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
+ await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
+ if (dbResult == null)
+ {
+ dbResult = new List();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"UserViewGetAll | {source} in: {ts.TotalMilliseconds} ms");
}
- else
+ catch (Exception exc)
{
- dbResult = dbController.UserViewGetAll();
- rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
- await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
+ Log.Error($"Exception during UserViewGetAll: {exc}{Environment.NewLine}");
}
- if (dbResult == null)
- {
- dbResult = new List();
- }
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"UserViewGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
@@ -2976,37 +3203,44 @@ namespace WebDoorCreator.Data.Services
{
string source = "DB";
VocabularyTempModel? dbResult = new VocabularyTempModel();
- // cerco da cache
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- string currKey = $"{Constants.rKeyVocLemma}:{lingua}:{lemma}";
- string? rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty(rawData))
+ try
{
- source = "REDIS";
- var tempResult = JsonConvert.DeserializeObject(rawData);
- if (tempResult == null)
+ // cerco da cache
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string currKey = $"{Constants.rKeyVocLemma}:{lingua}:{lemma}";
+ string? rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty(rawData))
{
- dbResult = new VocabularyTempModel();
+ source = "REDIS";
+ var tempResult = JsonConvert.DeserializeObject(rawData);
+ if (tempResult == null)
+ {
+ dbResult = new VocabularyTempModel();
+ }
+ else
+ {
+ dbResult = tempResult;
+ }
}
else
{
- dbResult = tempResult;
+ dbResult = await dbController.VocLemmaFindByKeys(lingua, lemma);
+ rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
+ await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
+ if (dbResult == null)
+ {
+ dbResult = new VocabularyTempModel();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"VocLemmaFindByKeys | {source} in: {ts.TotalMilliseconds} ms");
}
- else
+ catch (Exception exc)
{
- dbResult = await dbController.VocLemmaFindByKeys(lingua, lemma);
- rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
- await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
+ Log.Error($"Exception during VocLemmaFindByKeys: {exc}{Environment.NewLine}");
}
- if (dbResult == null)
- {
- dbResult = new VocabularyTempModel();
- }
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"VocLemmaFindByKeys | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
@@ -3014,37 +3248,44 @@ namespace WebDoorCreator.Data.Services
{
string source = "DB";
Dictionary>? dbResult = new Dictionary>();
- // cerco da cache
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- string currKey = $"{Constants.rKeyVocLemma}";
- string? rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty(rawData))
+ try
{
- source = "REDIS";
- var tempResult = JsonConvert.DeserializeObject>>(rawData);
- if (tempResult == null)
+ // cerco da cache
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ string currKey = $"{Constants.rKeyVocLemma}";
+ string? rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty(rawData))
{
- dbResult = new Dictionary>();
+ source = "REDIS";
+ var tempResult = JsonConvert.DeserializeObject>>(rawData);
+ if (tempResult == null)
+ {
+ dbResult = new Dictionary>();
+ }
+ else
+ {
+ dbResult = tempResult;
+ }
}
else
{
- dbResult = tempResult;
+ dbResult = dbController.VocLemmaGetAll();
+ rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
+ await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
+ if (dbResult == null)
+ {
+ dbResult = new Dictionary>();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms");
}
- else
+ catch (Exception exc)
{
- dbResult = dbController.VocLemmaGetAll();
- rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
- await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
+ Log.Error($"Exception during VocLemmaGetAll: {exc}{Environment.NewLine}");
}
- if (dbResult == null)
- {
- dbResult = new Dictionary>();
- }
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
@@ -3053,15 +3294,21 @@ namespace WebDoorCreator.Data.Services
bool fatto = false;
List VocLemmas = new List();
-
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- fatto = await dbController.VocLemmaInsert();
- RedisValue pattern = new RedisValue($"{Constants.rKeyVocLemma}");
- bool answ = await ExecFlushRedisPattern(pattern);
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"VocLemmaInsert in: {ts.TotalMilliseconds} ms");
+ try
+ {
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ fatto = await dbController.VocLemmaInsert();
+ RedisValue pattern = new RedisValue($"{Constants.rKeyVocLemma}");
+ bool answ = await ExecFlushRedisPattern(pattern);
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"VocLemmaInsert in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during VocLemmaInsert: {exc}{Environment.NewLine}");
+ }
return fatto;
}
@@ -3070,56 +3317,69 @@ namespace WebDoorCreator.Data.Services
//bool fatto = false;
await Task.Delay(1);
List VocLemmas = new List();
-
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
-
- string[] files = Directory.GetFiles(rootPath, "*");
- string lang = "";
- foreach (string file in files)
+ try
{
- var fileName = file.Split(".");
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
- lang = fileName[0].Substring(fileName[0].Length - 2, 2);
-
- //leggo tutte le linee del file
- List lines = File.ReadAllLines(file).ToList();
-
- foreach (var line in lines)
+ string[] files = Directory.GetFiles(rootPath, "*");
+ string lang = "";
+ foreach (string file in files)
{
- if (!line.StartsWith("//") && line != "")
+ var fileName = file.Split(".");
+
+ lang = fileName[0].Substring(fileName[0].Length - 2, 2);
+
+ //leggo tutte le linee del file
+ List lines = File.ReadAllLines(file).ToList();
+
+ foreach (var line in lines)
{
- string[] lineSplit = line.Split("=");
- //string trad = "";
- if (lineSplit.Length != 1)
+ if (!line.StartsWith("//") && line != "")
{
- VocabularyTempModel newVocLemma = new VocabularyTempModel()
+ string[] lineSplit = line.Split("=");
+ //string trad = "";
+ if (lineSplit.Length != 1)
{
- Lingua = lang,
- Lemma = lineSplit[0],
- Traduzione = lineSplit[1]
- };
- VocLemmas.Add(newVocLemma);
+ VocabularyTempModel newVocLemma = new VocabularyTempModel()
+ {
+ Lingua = lang,
+ Lemma = lineSplit[0],
+ Traduzione = lineSplit[1]
+ };
+ VocLemmas.Add(newVocLemma);
+ }
}
}
}
+ await dbController.VocLemmaInsertPrepare(VocLemmas);
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"VocLemmaInsertPrepare in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during VocLemmaInsertPrepare: {exc}{Environment.NewLine}");
}
- await dbController.VocLemmaInsertPrepare(VocLemmas);
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"VocLemmaInsertPrepare in: {ts.TotalMilliseconds} ms");
return VocLemmas;
}
public async Task VocLemmaSetConf(string lingua, string lemma, bool isConf)
{
bool fatto = false;
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- fatto = await dbController.VocLemmaSetConf(lingua, lemma, isConf);
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"VocLemmaSetConf in: {ts.TotalMilliseconds} ms");
+ try
+ {
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ fatto = await dbController.VocLemmaSetConf(lingua, lemma, isConf);
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"VocLemmaSetConf in: {ts.TotalMilliseconds} ms");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during VocLemmaSetConf: {exc}{Environment.NewLine}");
+ }
return fatto;
}
@@ -3128,13 +3388,20 @@ namespace WebDoorCreator.Data.Services
await Task.Delay(1);
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");
+ try
+ {
+ // 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");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Exception during VocLemmaGetAll: {exc}{Environment.NewLine}");
+ }
return dbResult;
}