aggiunti metodi per inserire nuova scansione
This commit is contained in:
@@ -47,15 +47,10 @@ namespace MP.Data.Controllers
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
}
|
||||
#endregion gestione config
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#region gestione scansioni
|
||||
/// <summary>
|
||||
/// Elenco Scansioni dato Id sessione inventario
|
||||
/// </summary>
|
||||
@@ -76,6 +71,41 @@ namespace MP.Data.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserisco nuova scansione
|
||||
/// </summary>
|
||||
/// <param name="InveSessId"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
/// <summary>
|
||||
/// insert di un record sessione
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> InsertNewScansione(ScanDataModel newRec)
|
||||
{
|
||||
bool fatto = false;
|
||||
using (var dbCtx = new MoonPro_InveContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
dbCtx
|
||||
.DbScanData
|
||||
.Add(newRec);
|
||||
await dbCtx.SaveChangesAsync();
|
||||
fatto = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante InsertNewScansione{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
|
||||
#endregion gestione scansioni
|
||||
|
||||
|
||||
#region gestione operatori
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -69,6 +69,84 @@ namespace MP.INVE.Data
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<ConfigModel>> ConfigGetAll()
|
||||
{
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
List<ConfigModel>? result = new List<ConfigModel>();
|
||||
string source = "DB";
|
||||
// cerco in redis...
|
||||
RedisValue rawData = await redisDb.StringGetAsync(redisConfigBaseAddr);
|
||||
if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<ConfigModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbController.ConfigGetAll());
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(redisConfigBaseAddr, rawData, getRandTOut(redisLongTimeCache));
|
||||
source = "DB";
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<ConfigModel>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"ConfigGetAll Read from {source}: {ts.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce valore della stringa (SE disponibile)
|
||||
/// </summary>
|
||||
/// <param name="keyName"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> tryGetConfig(string keyName)
|
||||
{
|
||||
string answ = "";
|
||||
// preselezione valori
|
||||
var configData = await ConfigGetAll();
|
||||
var currRec = configData.FirstOrDefault(x => x.Chiave == keyName);
|
||||
if (currRec != null)
|
||||
{
|
||||
answ = currRec.Valore;
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset dati cache config
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task ConfigResetCache()
|
||||
{
|
||||
await redisDb.StringSetAsync(redisConfigBaseAddr, "");
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> InsertNewScansione(ScanDataModel newScan)
|
||||
{
|
||||
bool result = false;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
result = await dbController.InsertNewScansione(newScan);
|
||||
// elimino cache redis...
|
||||
RedisValue pattern = new RedisValue(redisScanBaseAddr);
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"InsertNewScansione | Id scansione: {newScan.ScanID} | Id sessione: {newScan.InveSessID} | {ts.TotalMilliseconds}ms");
|
||||
return result;
|
||||
// aggiungo record al DB
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> InsertNewSessione(InventorySessionModel newSess)
|
||||
{
|
||||
bool result = false;
|
||||
@@ -80,7 +158,7 @@ namespace MP.INVE.Data
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"InsertNewSessione | Id sessione: {newSess.InveSessID} | Id sessione: {newSess.Description} | {ts.TotalMilliseconds}ms");
|
||||
Log.Debug($"InsertNewSessione | Id sessione: {newSess.InveSessID} | Descrizione sessione: {newSess.Description} | {ts.TotalMilliseconds}ms");
|
||||
return result;
|
||||
// aggiungo record al DB
|
||||
}
|
||||
@@ -406,16 +484,6 @@ namespace MP.INVE.Data
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
return answ;
|
||||
}
|
||||
#if false
|
||||
|
||||
public async Task<bool> FlushRedisCache(string keyPattern)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
RedisValue pattern = new RedisValue($"{keyPattern}*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
return answ;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria redis dato pattern
|
||||
@@ -455,6 +523,8 @@ namespace MP.INVE.Data
|
||||
private const string redisOperatoriBaseAddr = ":Operatore";
|
||||
private const string redisUdcBaseAddr = ":UDC";
|
||||
private const string redisLottiBaseAddr = ":Lotti";
|
||||
private const string redisConfigBaseAddr = ":Config";
|
||||
private const string redisScanBaseAddr = ":Config";
|
||||
private const string redisElencoOperatori = redisBaseAddr + redisOperatoriBaseAddr + ":ListOperatori";
|
||||
private const string redisOperatoreLogged = redisBaseAddr + redisOperatoriBaseAddr + ":OperatoreLogged";
|
||||
private const string redisSessionCurrList = redisBaseAddr + redisSessionBaseAddr + ":ListSessHist";
|
||||
|
||||
Reference in New Issue
Block a user