82 lines
2.4 KiB
C#
82 lines
2.4 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MP.TaskMan.Models;
|
|
using MP.TaskMan.Services;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Stats.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class TaskController : ControllerBase
|
|
{
|
|
#region Public Constructors
|
|
|
|
public TaskController(IConfiguration configuration, TaskService DataService)
|
|
{
|
|
Log.Trace("Starting TaskController");
|
|
_configuration = configuration;
|
|
DService = DataService;
|
|
Log.Trace("Avviato TaskController");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Call for execution of due task and report state
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<List<TaskResultModel>> ExecuteAndReturnGet()
|
|
{
|
|
List<TaskResultModel> answ = new List<TaskResultModel>();
|
|
List<TaskListModel> listTask = await DService.TaskListAll(TaskMan.Objects.Enums.Task2ExeType.ALL, false, "");
|
|
// verifico SE ci siano task in scadenza...
|
|
DateTime adesso = DateTime.Now;
|
|
var task2exe = listTask.Where(x => x.DtNextExec <= adesso).ToList();
|
|
foreach (var taskRec in task2exe)
|
|
{
|
|
TaskResultModel result = await DService.ExecuteTask(taskRec, true);
|
|
answ.Add(result);
|
|
}
|
|
// resituisco
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// List of available task and last execution data
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("GetList")]
|
|
public async Task<List<TaskListModel>> GetList()
|
|
{
|
|
List<TaskListModel> answ = await DService.TaskListAll(TaskMan.Objects.Enums.Task2ExeType.ALL, false, "");
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
/// <summary>
|
|
/// Dataservice x accesso DB
|
|
/// </summary>
|
|
protected TaskService DService { get; set; }
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration = null!;
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |