Add flux cache page - ForceReload
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
using EgwCoreLib.Razor.Data;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using StackExchange.Redis;
|
||||
using System.Diagnostics;
|
||||
using WebDoorCreator.Core;
|
||||
using WebDoorCreator.Data.Controllers;
|
||||
using WebDoorCreator.Data.DbModels;
|
||||
using WebDoorCreator.Core;
|
||||
using System.Security.AccessControl;
|
||||
using WebDoorCreator.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace WebDoorCreator.UI.Data
|
||||
{
|
||||
@@ -62,8 +60,20 @@ namespace WebDoorCreator.UI.Data
|
||||
|
||||
#region Public Methods
|
||||
|
||||
#region Company methods
|
||||
|
||||
/// <summary>
|
||||
/// Update company
|
||||
/// </summary>
|
||||
/// <param name="currRec"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> CompanyAddMod(CompanyModel currRec)
|
||||
{
|
||||
var dbResult = await dbController.CompanyAddMod(currRec);
|
||||
// elimino cache redis...
|
||||
RedisValue pattern = new RedisValue($"{rKeyCompany}");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
await Task.Delay(1);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Company list filtered by company id
|
||||
@@ -109,104 +119,51 @@ namespace WebDoorCreator.UI.Data
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update company
|
||||
/// </summary>
|
||||
/// <param name="currRec"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> CompanyAddMod(CompanyModel currRec)
|
||||
{
|
||||
var dbResult = await dbController.CompanyAddMod(currRec);
|
||||
// elimino cache redis...
|
||||
RedisValue pattern = new RedisValue($"{rKeyCompany}");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
await Task.Delay(1);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
#endregion Company methods
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
#region Cache methods
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria redis dato pattern
|
||||
/// </summary>
|
||||
/// <param name="pattern"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> ExecFlushRedisPattern(RedisValue pattern)
|
||||
{
|
||||
bool answ = false;
|
||||
var listEndpoints = redisConn.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
//var server = redisConnAdmin.GetServer(listEndpoints[0]);
|
||||
var server = redisConn.GetServer(endPoint);
|
||||
if (server != null)
|
||||
{
|
||||
var keyList = server.Keys(redisDb.Database, pattern);
|
||||
foreach (var item in keyList)
|
||||
{
|
||||
await redisDb.KeyDeleteAsync(item);
|
||||
}
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
public async Task<bool> FlushRedisCache()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
RedisValue pattern = new RedisValue($"{redisBaseAddr}");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Cache methods
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
#region Security Methods
|
||||
|
||||
public string DecriptData(string encData)
|
||||
{
|
||||
return SteamCrypto.DecryptString(encData, passPhrase);
|
||||
}
|
||||
|
||||
public string EncriptData(string rawData)
|
||||
/// <summary>
|
||||
/// Adding or removing a single door
|
||||
/// </summary>
|
||||
/// <param name="doorId">Record id to edit or add</param>
|
||||
/// <param name="isAdd">States if it has to be added or removing a door</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DoorModQty(int doorId, bool isAdd)
|
||||
{
|
||||
return SteamCrypto.EncryptString(rawData, passPhrase);
|
||||
var dbResult = await dbController.DoorModQty(doorId, isAdd);
|
||||
// elimino cache redis dati porta...
|
||||
RedisValue pattern = new RedisValue($"{rKeyDoor}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
// elimino cache redis dati ordine...
|
||||
pattern = new RedisValue($"{rKeyOrderStatus}:*");
|
||||
answ = await ExecFlushRedisPattern(pattern);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
#endregion Security Methods
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
#region User Methods
|
||||
|
||||
/// <summary>
|
||||
/// Users roles list
|
||||
/// Doors list by orderId
|
||||
/// </summary>
|
||||
public async Task<List<UsersViewModel>?> GetUserView()
|
||||
public async Task<List<DoorModel>?> DoorsGetByOrderId(int orderId)
|
||||
{
|
||||
string source = "DB";
|
||||
|
||||
List<UsersViewModel>? dbResult = new List<UsersViewModel>();
|
||||
List<DoorModel>? dbResult = new List<DoorModel>();
|
||||
// cerco da cache
|
||||
string currKey = rKeyUsersView;
|
||||
string currKey = $"{rKeyDoor}:{orderId}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<UsersViewModel>>(rawData);
|
||||
var tempResult = JsonConvert.DeserializeObject<List<DoorModel>>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dbResult = new List<UsersViewModel>();
|
||||
dbResult = new List<DoorModel>();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -215,17 +172,149 @@ namespace WebDoorCreator.UI.Data
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = dbController.GetUserView();
|
||||
dbResult = dbController.DoorsGetByOrderId(orderId);
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new List<UsersViewModel>();
|
||||
dbResult = new List<DoorModel>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"GetUserView | {source} in: {ts.TotalMilliseconds} ms");
|
||||
Log.Debug($"DoorsGetByOrderId | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update or add door
|
||||
/// </summary>
|
||||
/// <param name="currRec"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DoorUpsert(DoorModel currRec)
|
||||
{
|
||||
var dbResult = await dbController.DoorUpsert(currRec);
|
||||
// elimino cache redis dati porta...
|
||||
RedisValue pattern = new RedisValue($"{rKeyDoor}:{currRec.DoorId}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
// elimino cache redis dati ordine...
|
||||
answ = answ && await OrdersFlushCache();
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public string EncriptData(string rawData)
|
||||
{
|
||||
return SteamCrypto.EncryptString(rawData, passPhrase);
|
||||
}
|
||||
|
||||
public async Task<bool> FlushRedisCache()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
RedisValue pattern = new RedisValue($"{redisBaseAddr}*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Getting a list of all the active components
|
||||
/// </summary>
|
||||
/// <param name="rootPath">Path to start</param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<string>> GetAllActiveCompo(string rootPath)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
List<string> listActiveCompo = new List<string>();
|
||||
|
||||
//estraggo la lista di componenti che sono attive per il cliente
|
||||
IniFile fIni = new IniFile(rootPath);
|
||||
string compoDDF = fIni.ReadString("CompoOrder", "CompoDDFOrder", "CONFIG");
|
||||
var compoDDFList = compoDDF.Split(",");
|
||||
foreach (string compo in compoDDFList)
|
||||
{
|
||||
listActiveCompo.Add(compo.Trim());
|
||||
}
|
||||
|
||||
return listActiveCompo;
|
||||
}
|
||||
|
||||
public async Task<List<OrderStatusViewModel>?> GetOrderStatus(int companyId, int orderStatus, DateTime dataFrom, DateTime dataTo)
|
||||
{
|
||||
string source = "DB";
|
||||
|
||||
List<OrderStatusViewModel>? dbResult = new List<OrderStatusViewModel>();
|
||||
// cerco da cache
|
||||
string currKey = $"{rKeyOrderStatus}:{companyId}:{orderStatus}:{dataFrom:yyyyMMdd}:{dataTo:yyyyMMdd}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<OrderStatusViewModel>>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dbResult = new List<OrderStatusViewModel>();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = dbController.GetOrderStatus(companyId, orderStatus, dataFrom, dataTo);
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new List<OrderStatusViewModel>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"GetOrderStatus | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// roles list
|
||||
/// </summary>
|
||||
public async Task<List<AspNetRoles>?> GetRolesAll()
|
||||
{
|
||||
string source = "DB";
|
||||
|
||||
List<AspNetRoles>? dbResult = new List<AspNetRoles>();
|
||||
// cerco da cache
|
||||
string currKey = rKeyRoles;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<AspNetRoles>>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dbResult = new List<AspNetRoles>();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = dbController.GetRolesAll();
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new List<AspNetRoles>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"GetRolesAll | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
@@ -313,32 +402,26 @@ namespace WebDoorCreator.UI.Data
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
#endregion User Methods
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
#region Roles Methods
|
||||
|
||||
/// <summary>
|
||||
/// roles list
|
||||
/// Users roles list
|
||||
/// </summary>
|
||||
public async Task<List<AspNetRoles>?> GetRolesAll()
|
||||
public async Task<List<UsersViewModel>?> GetUserView()
|
||||
{
|
||||
string source = "DB";
|
||||
|
||||
List<AspNetRoles>? dbResult = new List<AspNetRoles>();
|
||||
List<UsersViewModel>? dbResult = new List<UsersViewModel>();
|
||||
// cerco da cache
|
||||
string currKey = rKeyRoles;
|
||||
string currKey = rKeyUsersView;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<AspNetRoles>>(rawData);
|
||||
var tempResult = JsonConvert.DeserializeObject<List<UsersViewModel>>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dbResult = new List<AspNetRoles>();
|
||||
dbResult = new List<UsersViewModel>();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -347,177 +430,20 @@ namespace WebDoorCreator.UI.Data
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = dbController.GetRolesAll();
|
||||
dbResult = dbController.GetUserView();
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new List<AspNetRoles>();
|
||||
dbResult = new List<UsersViewModel>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"GetRolesAll | {source} in: {ts.TotalMilliseconds} ms");
|
||||
Log.Debug($"GetUserView | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
#endregion Roles Methods
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
#region Order status Methods
|
||||
|
||||
public async Task<List<OrderStatusViewModel>?> GetOrderStatus(int companyId, int orderStatus, DateTime dataFrom, DateTime dataTo)
|
||||
{
|
||||
string source = "DB";
|
||||
|
||||
List<OrderStatusViewModel>? dbResult = new List<OrderStatusViewModel>();
|
||||
// cerco da cache
|
||||
string currKey = $"{rKeyOrderStatus}:{companyId}:{orderStatus}:{dataFrom:yyyyMMdd}:{dataTo:yyyyMMdd}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<OrderStatusViewModel>>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dbResult = new List<OrderStatusViewModel>();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = dbController.GetOrderStatus(companyId, orderStatus, dataFrom, dataTo);
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new List<OrderStatusViewModel>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"GetOrderStatus | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
#endregion Order status Methods
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
#region Order Methods
|
||||
|
||||
/// <summary>
|
||||
/// Add new order
|
||||
/// </summary>
|
||||
/// <param name="currRec"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> OrderAdd(OrderModel currRec)
|
||||
{
|
||||
var dbResult = await dbController.OrderAdd(currRec);
|
||||
// elimino cache redis...
|
||||
RedisValue pattern = new RedisValue($"{rKeyOrderStatus}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
await Task.Delay(1);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
#endregion Order Methods
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
#region Door Methods
|
||||
|
||||
/// <summary>
|
||||
/// Doors list by orderId
|
||||
/// </summary>
|
||||
public async Task<List<DoorModel>?> DoorsGetByOrderId(int orderId)
|
||||
{
|
||||
string source = "DB";
|
||||
|
||||
List<DoorModel>? dbResult = new List<DoorModel>();
|
||||
// cerco da cache
|
||||
string currKey = $"{rKeyDoor}:{orderId}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<DoorModel>>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dbResult = new List<DoorModel>();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = dbController.DoorsGetByOrderId(orderId);
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new List<DoorModel>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"DoorsGetByOrderId | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update or add door
|
||||
/// </summary>
|
||||
/// <param name="currRec"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DoorUpsert(DoorModel currRec)
|
||||
{
|
||||
var dbResult = await dbController.DoorUpsert(currRec);
|
||||
// elimino cache redis dati porta...
|
||||
RedisValue pattern = new RedisValue($"{rKeyDoor}:{currRec.DoorId}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
// elimino cache redis dati ordine...
|
||||
pattern = new RedisValue($"{rKeyOrderStatus}:*");
|
||||
answ = await ExecFlushRedisPattern(pattern);
|
||||
await Task.Delay(1);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adding or removing a single door
|
||||
/// </summary>
|
||||
/// <param name="doorId">Record id to edit or add</param>
|
||||
/// <param name="isAdd">States if it has to be added or removing a door</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DoorModQty(int doorId, bool isAdd)
|
||||
{
|
||||
var dbResult = await dbController.DoorModQty(doorId, isAdd);
|
||||
// elimino cache redis dati porta...
|
||||
RedisValue pattern = new RedisValue($"{rKeyDoor}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
// elimino cache redis dati ordine...
|
||||
pattern = new RedisValue($"{rKeyOrderStatus}:*");
|
||||
answ = await ExecFlushRedisPattern(pattern);
|
||||
await Task.Delay(1);
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
#endregion Door Methods
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
#region ListValues Methods
|
||||
|
||||
/// <summary>
|
||||
/// Company list
|
||||
/// </summary>
|
||||
@@ -560,88 +486,35 @@ namespace WebDoorCreator.UI.Data
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
#endregion ListValues Methods
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
#region IniFiles Methods
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Getting a list of all the active components
|
||||
/// Add new order
|
||||
/// </summary>
|
||||
/// <param name="rootPath">Path to start</param>
|
||||
/// <param name="currRec"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<string>> GetAllActiveCompo(string rootPath)
|
||||
public async Task<bool> OrderAdd(OrderModel currRec)
|
||||
{
|
||||
var dbResult = await dbController.OrderAdd(currRec);
|
||||
// elimino cache redis...
|
||||
RedisValue pattern = new RedisValue($"{rKeyOrderStatus}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
await Task.Delay(1);
|
||||
List<string> listActiveCompo = new List<string>();
|
||||
|
||||
//estraggo la lista di componenti che sono attive per il cliente
|
||||
IniFile fIni = new IniFile(rootPath);
|
||||
string compoDDF = fIni.ReadString("CompoOrder", "CompoDDFOrder", "CONFIG");
|
||||
var compoDDFList = compoDDF.Split(",");
|
||||
foreach (string compo in compoDDFList)
|
||||
{
|
||||
listActiveCompo.Add(compo.Trim());
|
||||
}
|
||||
|
||||
return listActiveCompo;
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setting the graphic parameters for components
|
||||
/// Clean redis ORDERS cache
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="match"></param>
|
||||
/// <param name="n"></param>
|
||||
/// <param name="i"></param>
|
||||
/// <param name="currRec"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<GraphicParamsModel>> SetGraphicParams(string file, string match, int n, int i)
|
||||
public async Task<bool> OrdersFlushCache()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
List<GraphicParamsModel> listGraphicParams = new List<GraphicParamsModel>();
|
||||
|
||||
IniFile fIni = new IniFile(file);
|
||||
//estraggo la lista di componenti che sono attive per il cliente
|
||||
var graphicParamsName = fIni.ReadSection(match.Substring(1, match.Length - 2)); //cerco il contenuto delle sezioni
|
||||
if (int.Parse(match.Substring(match.Length - 2, 1)) == n) //controllo se tra i numeri di graphic params vi è un buco ES: Graphic parameters1 Graphic parameters3 se il buco c'è salto tutti i parametri che stanno dopo il buco ==> tengo conto solo di Graphic parameters1
|
||||
{
|
||||
foreach (string param in graphicParamsName)
|
||||
{
|
||||
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"))
|
||||
{
|
||||
if (compoParamsSplit[1].Contains("/"))
|
||||
{
|
||||
CompoParamName = compoParamsSplit[1].Split("/")[0];
|
||||
CompoParamAlias = compoParamsSplit[1].Split("/")[1];
|
||||
|
||||
}
|
||||
|
||||
GraphicParamsModel graphicParams = new GraphicParamsModel() { compoId = i, graphicParamsN = match.Substring(1, match.Length - 2), graphicParamKey = param.Split("=")[0], graphicParamName = CompoParamName, graphicParamAlias = CompoParamAlias, graphicParamType = compoParamsSplit[0], graphicParamDefaultVal = compoParamsSplit[2] };
|
||||
listGraphicParams.Add(graphicParams); //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione
|
||||
await dbController.ParamAdd(graphicParams);
|
||||
}
|
||||
else
|
||||
{
|
||||
GraphicParamsModel graphicParams = new GraphicParamsModel() { compoId = i, graphicParamsN = match.Substring(1, match.Length - 2), graphicParamKey = param.Split("=")[0], graphicParamName = compoParams };
|
||||
listGraphicParams.Add(graphicParams); //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione
|
||||
await dbController.ParamAdd(graphicParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return listGraphicParams;
|
||||
RedisValue pattern = new RedisValue($"{rKeyOrderStatus}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Setting all the component list
|
||||
/// Setting all the component list
|
||||
/// </summary>
|
||||
/// <param name="rootPath">Path to start</param>
|
||||
/// <returns></returns>
|
||||
@@ -678,7 +551,7 @@ namespace WebDoorCreator.UI.Data
|
||||
{
|
||||
compoTemplateIsActive = false;
|
||||
}
|
||||
var compoNameSplit = compoName.Split("/"); // lo slash indica l'alias
|
||||
var compoNameSplit = compoName.Split("/"); // lo slash indica l'alias
|
||||
if (listActiveCompo.Contains(compoNameSplit[0].ToString()))
|
||||
{
|
||||
HardwareModel compoConfig = new HardwareModel() { compoName = compoNameSplit[0].ToString(), compoAlias = compoNameSplit[1].ToString(), compoLayerName = layerName, compoTemplateIsActive = compoTemplateIsActive }; //creo il componente (padre)
|
||||
@@ -707,7 +580,6 @@ namespace WebDoorCreator.UI.Data
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<Edges> edges = new List<Edges>();
|
||||
@@ -753,40 +625,59 @@ namespace WebDoorCreator.UI.Data
|
||||
return fatto;
|
||||
}
|
||||
|
||||
#endregion IniFiles Methods
|
||||
/// <summary>
|
||||
/// Setting the graphic parameters for components
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="match"></param>
|
||||
/// <param name="n"></param>
|
||||
/// <param name="i"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<GraphicParamsModel>> SetGraphicParams(string file, string match, int n, int i)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
List<GraphicParamsModel> listGraphicParams = new List<GraphicParamsModel>();
|
||||
|
||||
IniFile fIni = new IniFile(file);
|
||||
//estraggo la lista di componenti che sono attive per il cliente
|
||||
var graphicParamsName = fIni.ReadSection(match.Substring(1, match.Length - 2)); //cerco il contenuto delle sezioni
|
||||
if (int.Parse(match.Substring(match.Length - 2, 1)) == n) //controllo se tra i numeri di graphic params vi è un buco ES: Graphic parameters1 Graphic parameters3 se il buco c'è salto tutti i parametri che stanno dopo il buco ==> tengo conto solo di Graphic parameters1
|
||||
{
|
||||
foreach (string param in graphicParamsName)
|
||||
{
|
||||
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"))
|
||||
{
|
||||
if (compoParamsSplit[1].Contains("/"))
|
||||
{
|
||||
CompoParamName = compoParamsSplit[1].Split("/")[0];
|
||||
CompoParamAlias = compoParamsSplit[1].Split("/")[1];
|
||||
}
|
||||
|
||||
GraphicParamsModel graphicParams = new GraphicParamsModel() { compoId = i, graphicParamsN = match.Substring(1, match.Length - 2), graphicParamKey = param.Split("=")[0], graphicParamName = CompoParamName, graphicParamAlias = CompoParamAlias, graphicParamType = compoParamsSplit[0], graphicParamDefaultVal = compoParamsSplit[2] };
|
||||
listGraphicParams.Add(graphicParams); //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione
|
||||
await dbController.ParamAdd(graphicParams);
|
||||
}
|
||||
else
|
||||
{
|
||||
GraphicParamsModel graphicParams = new GraphicParamsModel() { compoId = i, graphicParamsN = match.Substring(1, match.Length - 2), graphicParamKey = param.Split("=")[0], graphicParamName = compoParams };
|
||||
listGraphicParams.Add(graphicParams); //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione
|
||||
await dbController.ParamAdd(graphicParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return listGraphicParams;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
|
||||
/// </summary>
|
||||
private TimeSpan FastCache
|
||||
{
|
||||
get => TimeSpan.FromSeconds(cacheTtlShort * rnd.Next(900, 1100) / 1000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
|
||||
/// </summary>
|
||||
private TimeSpan LongCache
|
||||
{
|
||||
get => TimeSpan.FromSeconds(cacheTtlLong * rnd.Next(900, 1100) / 1000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
|
||||
/// </summary>
|
||||
private TimeSpan UltraLongCache
|
||||
{
|
||||
get => TimeSpan.FromSeconds(cacheTtlLong * 10 * rnd.Next(900, 1100) / 1000);
|
||||
}
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
protected const string passPhrase = "9eb4660f-8753-46bc-b23b-08759ba03fe9";
|
||||
|
||||
//#region Protected Fields
|
||||
@@ -795,13 +686,18 @@ namespace WebDoorCreator.UI.Data
|
||||
//#endregion Public Methods
|
||||
protected const string rKeyCompany = $"{redisBaseAddr}:Cache:Company";
|
||||
|
||||
protected const string rKeyOrderStatus = $"{redisBaseAddr}:Cache:OrderStatus";
|
||||
protected const string rKeyUsers = $"{redisBaseAddr}:Cache:Users";
|
||||
protected const string rKeyUsersView = $"{redisBaseAddr}:Cache:UsersView";
|
||||
protected const string rKeyRoles = $"{redisBaseAddr}:Cache:Roles";
|
||||
protected const string rKeyDoor = $"{redisBaseAddr}:Cache:Doors";
|
||||
|
||||
protected const string rKeyListValues = $"{redisBaseAddr}:Cache:ListValues";
|
||||
|
||||
protected const string rKeyOrderStatus = $"{redisBaseAddr}:Cache:OrderStatus";
|
||||
|
||||
protected const string rKeyRoles = $"{redisBaseAddr}:Cache:Roles";
|
||||
|
||||
protected const string rKeyUsers = $"{redisBaseAddr}:Cache:Users";
|
||||
|
||||
protected const string rKeyUsersView = $"{redisBaseAddr}:Cache:UsersView";
|
||||
|
||||
protected Random rnd = new Random();
|
||||
|
||||
#endregion Protected Fields
|
||||
@@ -838,5 +734,73 @@ namespace WebDoorCreator.UI.Data
|
||||
private IDatabase redisDb = null!;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
|
||||
/// </summary>
|
||||
private TimeSpan FastCache
|
||||
{
|
||||
get => TimeSpan.FromSeconds(cacheTtlShort * rnd.Next(900, 1100) / 1000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
|
||||
/// </summary>
|
||||
private TimeSpan LongCache
|
||||
{
|
||||
get => TimeSpan.FromSeconds(cacheTtlLong * rnd.Next(900, 1100) / 1000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
|
||||
/// </summary>
|
||||
private TimeSpan UltraLongCache
|
||||
{
|
||||
get => TimeSpan.FromSeconds(cacheTtlLong * 10 * rnd.Next(900, 1100) / 1000);
|
||||
}
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria redis dato pattern
|
||||
/// </summary>
|
||||
/// <param name="pattern"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> ExecFlushRedisPattern(RedisValue pattern)
|
||||
{
|
||||
bool answ = false;
|
||||
var listEndpoints = redisConn.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
//var server = redisConnAdmin.GetServer(listEndpoints[0]);
|
||||
var server = redisConn.GetServer(endPoint);
|
||||
if (server != null)
|
||||
{
|
||||
var keyList = server.Keys(redisDb.Database, pattern);
|
||||
foreach (var item in keyList)
|
||||
{
|
||||
await redisDb.KeyDeleteAsync(item);
|
||||
}
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------------------------------------------------*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
@page "/ForceReload"
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using WebDoorCreator.UI.Data;
|
||||
|
||||
namespace WebDoorCreator.UI.Pages
|
||||
{
|
||||
public partial class ForceReload
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
public async Task flushCache()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
await WDService.FlushRedisCache();
|
||||
await Task.Delay(1);
|
||||
// rimando a pagina corrente
|
||||
NavManager.NavigateTo("/", true);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
[Inject]
|
||||
protected NavigationManager NavManager { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
protected WebDoorCreatorService WDService { get; set; } = null!;
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await flushCache();
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user