COmpletata review log + migrazione con indice aggiunto
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.MONO.Core.DTO;
|
||||
using MP.MONO.Data.DbModels;
|
||||
using MP.MONO.Data.DTO;
|
||||
@@ -12,8 +13,11 @@ namespace MP.MONO.Data.Controllers
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public MpDbController()
|
||||
{ }
|
||||
public MpDbController(IConfiguration currAppConf)
|
||||
{
|
||||
appConf = currAppConf;
|
||||
LogDurationLimitMs = appConf.GetValue<int>("OptPar:LogDurationLimitMs");
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
@@ -39,11 +43,10 @@ namespace MP.MONO.Data.Controllers
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmListGetAll{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmListGetAll", exc);
|
||||
}
|
||||
LogDebug("AlarmListGetAll", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"AlarmListGetAll | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
@@ -82,13 +85,12 @@ namespace MP.MONO.Data.Controllers
|
||||
.DbSetAlarmList
|
||||
.FirstOrDefault(x => x.FullValue == alarmText);
|
||||
}
|
||||
LogDebug("AlarmListInsert", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"AlarmListInsert | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmListInsert{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmListInsert", exc);
|
||||
}
|
||||
}
|
||||
return foundRec;
|
||||
@@ -115,11 +117,11 @@ namespace MP.MONO.Data.Controllers
|
||||
fatto = true;
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"AlarmListInsertMany | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("AlarmListInsertMany", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmListInsertMany{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmListInsertMany", exc);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
@@ -142,21 +144,21 @@ namespace MP.MONO.Data.Controllers
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = await localDbCtx
|
||||
.DbSetAlarmLog
|
||||
.AsNoTracking()
|
||||
.Where(x => x.MachineId == MachineId)
|
||||
.Include(m => m.MachineNav)
|
||||
.OrderByDescending(x => x.AlarmLogId)
|
||||
.Skip(skipRec)
|
||||
.Take(numRec)
|
||||
.ToListAsync();
|
||||
stopWatch.Stop();
|
||||
.DbSetAlarmLog
|
||||
.AsNoTracking()
|
||||
.Where(x => x.MachineId == MachineId)
|
||||
.Include(m => m.MachineNav)
|
||||
.OrderByDescending(x => x.AlarmLogId)
|
||||
.Skip(skipRec)
|
||||
.Take(numRec)
|
||||
.ToListAsync();
|
||||
|
||||
Log.Debug($"AlarmLogGetFilt | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("AlarmLogGetFilt", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmLogGetFilt{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmLogGetFilt", exc);
|
||||
}
|
||||
}
|
||||
//await Task.Delay(1);
|
||||
@@ -176,21 +178,21 @@ namespace MP.MONO.Data.Controllers
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = localDbCtx
|
||||
.DbSetAlarmLog
|
||||
.AsNoTracking()
|
||||
.Where(x => (x.MachineId == MachineId) && (x.DtRif <= dtRif))
|
||||
.Include(m => m.MachineNav)
|
||||
.OrderByDescending(x => x.AlarmLogId)
|
||||
.Skip(skipRec)
|
||||
.Take(numRec)
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
.DbSetAlarmLog
|
||||
.AsNoTracking()
|
||||
.Where(x => (x.MachineId == MachineId) && (x.DtRif <= dtRif))
|
||||
.Include(m => m.MachineNav)
|
||||
.OrderByDescending(x => x.AlarmLogId)
|
||||
.Skip(skipRec)
|
||||
.Take(numRec)
|
||||
.ToList();
|
||||
|
||||
Log.Debug($"AlarmLogGetFilt | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("AlarmLogGetFiltByDate", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmLogGetFilt{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmLogGetFiltByDate", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -215,13 +217,13 @@ namespace MP.MONO.Data.Controllers
|
||||
.Add(newItem);
|
||||
await localDbCtx.SaveChangesAsync();
|
||||
fatto = true;
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"AlarmLogInsert | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("AlarmLogInsert", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmLogInsert{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmLogInsert", exc);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
@@ -248,14 +250,13 @@ namespace MP.MONO.Data.Controllers
|
||||
.AddRangeAsync(newItems);
|
||||
await localDbCtx.SaveChangesAsync();
|
||||
fatto = true;
|
||||
LogInfo($"AlarmLogInsertMany| DB insert | {newItems.Count} rec", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Info($"AlarmLogInsertMany| DB insert | {newItems.Count} rec | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmLogInsert{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmLogInsertMany", exc);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
@@ -295,17 +296,17 @@ namespace MP.MONO.Data.Controllers
|
||||
}
|
||||
await localDbCtx.SaveChangesAsync();
|
||||
fatto = true;
|
||||
Log.Debug($"AlarmRecCloseActive | {candList.Count} closed | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug($"AlarmRecCloseActive | {candList.Count} closed", stopWatch.Elapsed);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug($"AlarmRecCloseActive | NONE| {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug($"AlarmRecCloseActive | NONE", stopWatch.Elapsed);
|
||||
}
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmRecCloseActive{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmRecCloseActive", exc);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
@@ -337,11 +338,11 @@ namespace MP.MONO.Data.Controllers
|
||||
fatto = true;
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"AlarmRecCloseStarving | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug($"AlarmRecCloseStarving", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmRecCloseStarving{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmRecCloseStarving", exc);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
@@ -368,11 +369,11 @@ namespace MP.MONO.Data.Controllers
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"AlarmRecGetActive | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("AlarmRecGetActive", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmRecGetActive{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmRecGetActive", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -406,11 +407,11 @@ namespace MP.MONO.Data.Controllers
|
||||
.ToListAsync();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"AlarmRecGetFilt | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("AlarmRecGetFilt", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmRecGetFilt{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmRecGetFilt", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -438,13 +439,13 @@ namespace MP.MONO.Data.Controllers
|
||||
.Skip(skipRec)
|
||||
.Take(numRec)
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"AlarmRecGetFiltByDate | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("AlarmRecGetFiltByDate", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmRecGetFiltByDate{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmRecGetFiltByDate", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -496,13 +497,13 @@ namespace MP.MONO.Data.Controllers
|
||||
)
|
||||
.OrderByDescending(o => o.Duration)
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"AlarmRecGetParetoDur | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("AlarmRecGetParetoDur", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmRecGetParetoDur{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmRecGetParetoDur", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -549,13 +550,13 @@ namespace MP.MONO.Data.Controllers
|
||||
)
|
||||
.OrderByDescending(o => o.EventCount)
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"AlarmRecGetParetoFreq | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("AlarmRecGetParetoFreq", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmRecGetParetoFreq{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmRecGetParetoFreq", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -586,7 +587,7 @@ namespace MP.MONO.Data.Controllers
|
||||
// se ho trovato --> salto!
|
||||
if (stillOpenAlarms != null && stillOpenAlarms.Count > 0)
|
||||
{
|
||||
Log.Error($"Errore: trovato {stillOpenAlarms.Count} istanze già attive | Id: {newItem.AlarmId}");
|
||||
LogError($"Errore: trovato {stillOpenAlarms.Count} istanze già attive | Id: {newItem.AlarmId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -596,13 +597,12 @@ namespace MP.MONO.Data.Controllers
|
||||
await localDbCtx.SaveChangesAsync();
|
||||
fatto = true;
|
||||
}
|
||||
LogInfo($"AlarmRecInsert| DB insert 1 rec", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Info($"AlarmRecInsert| DB insert 1 rec | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmRecInsert{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmRecInsert", exc);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
@@ -624,60 +624,20 @@ namespace MP.MONO.Data.Controllers
|
||||
{
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
#if false
|
||||
// verifico eventuali items già aperti da NON dover aggiungere...
|
||||
List<int>? stillOpenAlarms = localDbCtx
|
||||
.DbSetAlarmRec
|
||||
.Where(x => x.DtStart >= x.DtEnd)
|
||||
.Select(x => x.AlarmId)
|
||||
.ToList();
|
||||
|
||||
// costruisco l'elenco degli ID allarmi da inserire
|
||||
List<int>? listNewId = newItems
|
||||
.Select(x => x.AlarmId)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
var alarm2rem = listNewId.Intersect(stillOpenAlarms).ToList();
|
||||
|
||||
// andrò ad inserire solo gli item NON già presenti...
|
||||
foreach (var item in alarm2rem)
|
||||
{
|
||||
var item2del = newItems.Where(x => x.AlarmId == item).ToList();
|
||||
if (item2del != null)
|
||||
{
|
||||
foreach (var singleItem in item2del)
|
||||
{
|
||||
newItems.Remove(singleItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (newItems.Count > 0)
|
||||
{
|
||||
// aggiungo
|
||||
localDbCtx
|
||||
.DbSetAlarmRec
|
||||
.AddRange(newItems);
|
||||
// salvo!
|
||||
localDbCtx.SaveChanges();
|
||||
fatto = true;
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Info($"AlarmRecInsertMany| DB insert | {newItems.Count} rec | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
}
|
||||
else
|
||||
{
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Info($"Allarmi già presenti non reinseriti | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
}
|
||||
// aggiungo
|
||||
localDbCtx
|
||||
.DbSetAlarmRec
|
||||
.AddRange(newItems);
|
||||
// salvo!
|
||||
localDbCtx.SaveChanges();
|
||||
fatto = true;
|
||||
LogInfo($"AlarmRecInsertMany | DB insert | {newItems.Count} rec", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmRecInsertMany{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante AlarmRecInsertMany", exc);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
@@ -700,13 +660,13 @@ namespace MP.MONO.Data.Controllers
|
||||
.DbSetCounter
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Info($"CountersGetAll| {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug($"CountersGetAll", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante CountersGetAll{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante CountersGetAll", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -751,13 +711,12 @@ namespace MP.MONO.Data.Controllers
|
||||
localDbCtx.SaveChanges();
|
||||
fatto = true;
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Info($"CountersUpsertMany| DB upsert | {newItems.Count} rec | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogInfo($"CountersUpsertMany | DB insert | {newItems.Count} rec", stopWatch.Elapsed);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante CountersUpsertMany{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante CountersUpsertMany", exc);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
@@ -789,11 +748,11 @@ namespace MP.MONO.Data.Controllers
|
||||
.ToListAsync();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"DataLogDtoGetFilt | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("DataLogDtoGetFilt", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante DataLogDtoGetFilt{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante DataLogDtoGetFilt", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -825,11 +784,11 @@ namespace MP.MONO.Data.Controllers
|
||||
.ToListAsync();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"DataLogGetFilt (5p) | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("DataLogGetFilt (5p)", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante DataLogGetFilt{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante DataLogGetFilt (5p)", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -859,11 +818,11 @@ namespace MP.MONO.Data.Controllers
|
||||
.ToListAsync();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"DataLogGetFilt (3p) | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("DataLogGetFilt (3p)", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante DataLogGetFilt{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante DataLogGetFilt (3p)", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -890,11 +849,11 @@ namespace MP.MONO.Data.Controllers
|
||||
fatto = true;
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"DataLogInsertMany | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("DataLogInsertMany", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante DataLogInsertMany{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante DataLogInsertMany", exc);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
@@ -927,11 +886,11 @@ namespace MP.MONO.Data.Controllers
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"DataStAgGetFilt | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("DataStAgGetFilt", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante DataLogGetFilt{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante DataStAgGetFilt", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -958,11 +917,11 @@ namespace MP.MONO.Data.Controllers
|
||||
fatto = true;
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"DataStAgInsert | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("DataStAgInsert", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante DataStAgInsert{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante DataStAgInsert", exc);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
@@ -971,7 +930,7 @@ namespace MP.MONO.Data.Controllers
|
||||
public void Dispose()
|
||||
{
|
||||
// Clear database context
|
||||
//Log.Info("Dispose di GWMSController");
|
||||
Log.Info("Dispose di MpDbController");
|
||||
}
|
||||
|
||||
public ProductionDTO MachineGetProd()
|
||||
@@ -1017,13 +976,13 @@ namespace MP.MONO.Data.Controllers
|
||||
.DbSetParetoStatus
|
||||
.FromSqlRaw<ParetoStatusModel>("CALL stp_paretoStatus({0},{1},{2});", MachineId, from.ToString("yyyy-MM-dd"), to.ToString("yyyy-MM-dd"))
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"ParetoStatusMach | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("ParetoStatusMach", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante ParetoStatusMach{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante ParetoStatusMach", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -1045,13 +1004,13 @@ namespace MP.MONO.Data.Controllers
|
||||
dbResult = localDbCtx
|
||||
.DbSetCounter
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"PMCounterModelGetAll | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("PMCounterModelGetAll", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante PMCounterModelGetAll{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante PMCounterModelGetAll", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -1073,13 +1032,13 @@ namespace MP.MONO.Data.Controllers
|
||||
dbResult = localDbCtx
|
||||
.DbSetPMMachGroup
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"PMMachGroupGetAll | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("PMMachGroupGetAll", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante PMMachGroupGetAll{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante PMMachGroupGetAll", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -1122,11 +1081,11 @@ namespace MP.MONO.Data.Controllers
|
||||
fatto = true;
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"PMTaskDeleteRecord | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("PMTaskDeleteRecord", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante PMTaskDeleteRecord{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante PMTaskDeleteRecord", exc);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
@@ -1160,13 +1119,13 @@ namespace MP.MONO.Data.Controllers
|
||||
await localDbCtx.SaveChangesAsync();
|
||||
}
|
||||
fatto = true;
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"PMTaskEnableRecord | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("PMTaskEnableRecord", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante PMTaskEnableRecord{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante PMTaskEnableRecord", exc);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
@@ -1188,13 +1147,13 @@ namespace MP.MONO.Data.Controllers
|
||||
dbResult = localDbCtx
|
||||
.DbSetPMTopic
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"PMTaskTopicGetAll | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("PMTaskTopicGetAll", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante PMTaskTopicGetAll{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante PMTaskTopicGetAll", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -1218,11 +1177,11 @@ namespace MP.MONO.Data.Controllers
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"PMUTeamGetAll | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("PMUTeamGetAll", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante PMUTeamGetAll{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante PMUTeamGetAll", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -1256,13 +1215,13 @@ namespace MP.MONO.Data.Controllers
|
||||
.Skip(skipRec)
|
||||
.Take(numRec)
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"PrevMaintTaskGetFilt | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("PrevMaintTaskGetFilt", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante PrevMaintTaskGetFilt{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante PrevMaintTaskGetFilt", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -1310,11 +1269,11 @@ namespace MP.MONO.Data.Controllers
|
||||
fatto = true;
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"PrevMaintTaskUpdate | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("PrevMaintTaskUpdate", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante PrevMaintTaskUpdate{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante PrevMaintTaskUpdate", exc);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
@@ -1341,11 +1300,11 @@ namespace MP.MONO.Data.Controllers
|
||||
fatto = true;
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"ProdLogInsertMany | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("ProdLogInsertMany", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante ProdLogInsertMany{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante ProdLogInsertMany", exc);
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
@@ -1371,11 +1330,11 @@ namespace MP.MONO.Data.Controllers
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"RemoveOldData | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("RemoveOldData", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante RemoveOldData{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante RemoveOldData", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -1449,13 +1408,13 @@ namespace MP.MONO.Data.Controllers
|
||||
// salvo
|
||||
localDbCtx.SaveChanges();
|
||||
answ = true;
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"SchedMaintTaskCreateMissing | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("SchedMaintTaskCreateMissing", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante SchedMaintTaskGetFilt{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante SchedMaintTaskGetFilt", exc);
|
||||
}
|
||||
}
|
||||
await Task.Delay(1);
|
||||
@@ -1492,13 +1451,13 @@ namespace MP.MONO.Data.Controllers
|
||||
.Skip(skipRec)
|
||||
.Take(numRec)
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"SchedMaintTaskGetByPMTask | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("SchedMaintTaskGetByPMTask", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante SchedMaintTaskGetByPMTask{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante SchedMaintTaskGetByPMTask", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -1535,11 +1494,11 @@ namespace MP.MONO.Data.Controllers
|
||||
.ToList();
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"SchedMaintTaskGetFilt | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("SchedMaintTaskGetFilt", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante SchedMaintTaskGetFilt{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante SchedMaintTaskGetFilt", exc);
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
@@ -1564,10 +1523,10 @@ namespace MP.MONO.Data.Controllers
|
||||
stopWatch.Start();
|
||||
// Aggiorno il task schedulato
|
||||
var dbResult = localDbCtx
|
||||
.DbSetSMTask
|
||||
.Include(i => i.CounterNav)
|
||||
.Where(x => x.PMTaskeNav.MachineId == MachineId && x.SMTaskId == SMTaskId)
|
||||
.FirstOrDefault();
|
||||
.DbSetSMTask
|
||||
.Include(i => i.CounterNav)
|
||||
.Where(x => x.PMTaskeNav.MachineId == MachineId && x.SMTaskId == SMTaskId)
|
||||
.FirstOrDefault();
|
||||
if (dbResult != null)
|
||||
{
|
||||
// aggiorno il record
|
||||
@@ -1594,13 +1553,13 @@ namespace MP.MONO.Data.Controllers
|
||||
// segno fatto!
|
||||
answ = true;
|
||||
}
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"SchedMaintTaskSetDone | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("SchedMaintTaskSetDone", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante SchedMaintTaskSetDone{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante SchedMaintTaskSetDone", exc);
|
||||
}
|
||||
}
|
||||
await Task.Delay(1);
|
||||
@@ -1665,14 +1624,14 @@ namespace MP.MONO.Data.Controllers
|
||||
|
||||
// salvo se ho NUOVO record
|
||||
localDbCtx.SaveChanges();
|
||||
LogDebug("StatusLogInsert", stopWatch.Elapsed);
|
||||
stopWatch.Stop();
|
||||
Log.Debug($"StatusLogInsert | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
}
|
||||
answ = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante StatusLogInsert{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante StatusLogInsert", exc);
|
||||
}
|
||||
}
|
||||
await Task.Delay(1);
|
||||
@@ -1700,11 +1659,11 @@ namespace MP.MONO.Data.Controllers
|
||||
answ = true;
|
||||
stopWatch.Stop();
|
||||
|
||||
Log.Debug($"TaskExecInsertLog | {stopWatch.Elapsed.TotalMilliseconds} ms");
|
||||
LogDebug("TaskExecInsertLog", stopWatch.Elapsed);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante TaskExecInsertLog{Environment.NewLine}{exc}");
|
||||
LogException("Eccezione durante TaskExecInsertLog", exc);
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
@@ -1716,6 +1675,90 @@ namespace MP.MONO.Data.Controllers
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
/// <summary>
|
||||
/// Limite durata eventi loggati x passare comunque a livello INFO...
|
||||
/// </summary>
|
||||
private int LogDurationLimitMs = 2000;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
/// <summary>
|
||||
/// Accessor configurazione
|
||||
/// </summary>
|
||||
private IConfiguration appConf { get; set; } = null!;
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Effettua Log tipo Debug
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="ts"></param>
|
||||
private void LogDebug(string message, TimeSpan ts)
|
||||
{
|
||||
// Se superato limite --> invio a INFO
|
||||
if (ts.TotalMilliseconds > LogDurationLimitMs)
|
||||
{
|
||||
LogInfo($"{message} | DurationLimit Exceeded", ts);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug($"{message} | {ts.TotalMilliseconds} ms");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua Log tipo ERROR
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="exc">Eventuale exxeczione da traccaire</param>
|
||||
private void LogError(string message)
|
||||
{
|
||||
Log.Error(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua Log tipo ERROR
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="exc">Eventuale eccezione da tracciare</param>
|
||||
private void LogException(string message, Exception exc)
|
||||
{
|
||||
Log.Error(exc, $"{message}{Environment.NewLine}{exc}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua Log tipo TRACE
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="ts"></param>
|
||||
private void LogInfo(string message, TimeSpan ts)
|
||||
{
|
||||
Log.Info($"{message} | {ts.TotalMilliseconds} ms");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua Log tipo TRACE
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="ts"></param>
|
||||
private void LogTrace(string message, TimeSpan ts)
|
||||
{
|
||||
// Se superato limite --> invio a INFO
|
||||
if (ts.TotalMilliseconds > LogDurationLimitMs)
|
||||
{
|
||||
LogInfo($"{message} | DurationLimit Exceeded", ts);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Trace($"{message} | {ts.TotalMilliseconds} ms");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -414,6 +414,11 @@ namespace MP.MONO.Data.Migrations
|
||||
table: "StatusLog",
|
||||
column: "MachineId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_StatusLog_DtRif",
|
||||
table: "StatusLog",
|
||||
column: "DtRif");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_StatusStAg_CodStatus",
|
||||
table: "StatusStAg",
|
||||
|
||||
Reference in New Issue
Block a user