Review AppUrl base x siti CORE
Divisione aree Redis tra app (x TaskMan in particolare) Test apertura app
This commit is contained in:
@@ -11,16 +11,20 @@ using static MP.TaskMan.Objects.Enums;
|
||||
|
||||
namespace MP.TaskMan.Controllers
|
||||
{
|
||||
public class MpTaskController: IDisposable
|
||||
public class MpTaskController : IDisposable
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public MpTaskController(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
Log.Info("Avviato MpTaskController");
|
||||
}
|
||||
private static IConfiguration _configuration;
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public DateTime CalcNextExe(TaskListModel taskRec)
|
||||
{
|
||||
DateTime dtNext = DateTime.Today;
|
||||
@@ -77,8 +81,9 @@ namespace MP.TaskMan.Controllers
|
||||
{
|
||||
_configuration = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chiamata esecuzione di un singolo task programmato
|
||||
/// Chiamata esecuzione di un singolo task programmato, SE in stato abilitato
|
||||
/// </summary>
|
||||
/// <param name="TaskId"></param>
|
||||
/// <param name="SchedNext">Se true rischedula successiva chiamata</param>
|
||||
@@ -97,7 +102,7 @@ namespace MP.TaskMan.Controllers
|
||||
// recupero i dati da richiamare...
|
||||
var currRec = dbCtx
|
||||
.DbSetTaskList
|
||||
.Where(x => x.TaskId == TaskId)
|
||||
.Where(x => x.TaskId == TaskId && x.Enabled)
|
||||
.FirstOrDefault();
|
||||
if (currRec != null)
|
||||
{
|
||||
@@ -151,7 +156,6 @@ namespace MP.TaskMan.Controllers
|
||||
return callRes;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Annulla modifiche su una specifica entity (cancel update)
|
||||
/// </summary>
|
||||
@@ -164,7 +168,7 @@ namespace MP.TaskMan.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
if (dbCtx.Entry(item).State == Microsoft.EntityFrameworkCore.EntityState.Deleted || dbCtx.Entry(item).State == Microsoft.EntityFrameworkCore.EntityState.Modified)
|
||||
if (dbCtx.Entry(item).State == EntityState.Deleted || dbCtx.Entry(item).State == EntityState.Modified)
|
||||
{
|
||||
dbCtx.Entry(item).Reload();
|
||||
}
|
||||
@@ -198,6 +202,58 @@ namespace MP.TaskMan.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue registrazione di un Task generico (NON SQL)
|
||||
/// </summary>
|
||||
/// <param name="TaskId"></param>
|
||||
/// <param name="SchedNext">Se true rischedula successiva chiamata</param>
|
||||
/// <param name="ResRec">Record esecuzione task esterno</param>
|
||||
/// <returns></returns>
|
||||
public TaskResultModel TaskExecSaveExecuted(int TaskId, bool SchedNext, TaskExecModel ResRec)
|
||||
{
|
||||
TaskResultModel callRes = new TaskResultModel();
|
||||
using (var dbCtx = new TaskContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
// recupero i dati da richiamare...
|
||||
var currRec = dbCtx
|
||||
.DbSetTaskList
|
||||
.Where(x => x.TaskId == TaskId)
|
||||
.FirstOrDefault();
|
||||
if (currRec != null)
|
||||
{
|
||||
// registro task ricevuto
|
||||
dbCtx
|
||||
.DbSetTaskExe
|
||||
.Add(ResRec);
|
||||
|
||||
// aggiorno record chiamata...
|
||||
currRec.DtLastExec = ResRec.DtStart;
|
||||
currRec.LastResult = ResRec.Result;
|
||||
currRec.LastIsError = ResRec.IsError;
|
||||
currRec.LastDuration = ResRec.DtEnd.Subtract(ResRec.DtStart).TotalSeconds;
|
||||
// solo se richiesto rischedulazione ricalcola chiamata
|
||||
if (SchedNext)
|
||||
{
|
||||
// calcolo prossima esecuzione...
|
||||
currRec.DtNextExec = CalcNextExe(currRec);
|
||||
}
|
||||
// segno modificato
|
||||
dbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
|
||||
// salvo modifiche!
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in TaskExecSaveExecuted{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return callRes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upsert record TaskExec
|
||||
/// </summary>
|
||||
@@ -259,58 +315,6 @@ namespace MP.TaskMan.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Esegue registrazione di un Task generico (NON SQL)
|
||||
/// </summary>
|
||||
/// <param name="TaskId"></param>
|
||||
/// <param name="SchedNext">Se true rischedula successiva chiamata</param>
|
||||
/// <param name="ResRec">Record esecuzione task esterno</param>
|
||||
/// <returns></returns>
|
||||
public TaskResultModel TaskExecSaveExecuted(int TaskId, bool SchedNext, TaskExecModel ResRec)
|
||||
{
|
||||
TaskResultModel callRes = new TaskResultModel();
|
||||
using (var dbCtx = new TaskContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
// recupero i dati da richiamare...
|
||||
var currRec = dbCtx
|
||||
.DbSetTaskList
|
||||
.Where(x => x.TaskId == TaskId)
|
||||
.FirstOrDefault();
|
||||
if (currRec != null)
|
||||
{
|
||||
// registro task ricevuto
|
||||
dbCtx
|
||||
.DbSetTaskExe
|
||||
.Add(ResRec);
|
||||
|
||||
// aggiorno record chiamata...
|
||||
currRec.DtLastExec = ResRec.DtStart;
|
||||
currRec.LastResult = ResRec.Result;
|
||||
currRec.LastIsError = ResRec.IsError;
|
||||
currRec.LastDuration = ResRec.DtEnd.Subtract(ResRec.DtStart).TotalSeconds;
|
||||
// solo se richiesto rischedulazione ricalcola chiamata
|
||||
if (SchedNext)
|
||||
{
|
||||
// calcolo prossima esecuzione...
|
||||
currRec.DtNextExec = CalcNextExe(currRec);
|
||||
}
|
||||
// segno modificato
|
||||
dbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
|
||||
// salvo modifiche!
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in TaskExecSaveExecuted{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return callRes;
|
||||
}
|
||||
/// <summary>
|
||||
/// Update ordinamento task
|
||||
/// </summary>
|
||||
@@ -388,6 +392,7 @@ namespace MP.TaskMan.Controllers
|
||||
if (currData != null)
|
||||
{
|
||||
currData.Ordinal = rec2upd.Ordinal;
|
||||
currData.Enabled = rec2upd.Enabled;
|
||||
currData.Name = rec2upd.Name;
|
||||
currData.Descript = rec2upd.Descript;
|
||||
currData.Command = rec2upd.Command;
|
||||
@@ -416,5 +421,19 @@ namespace MP.TaskMan.Controllers
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private static IConfiguration _configuration { get; set; } = null!;
|
||||
|
||||
#endregion Private Properties
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user