bd61e76529
- aggiunta API chiamate web
69 lines
2.2 KiB
C#
69 lines
2.2 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MP.Data.DatabaseModels;
|
|
using MP.Stats.Data;
|
|
using NLog;
|
|
using NLog.Fluent;
|
|
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
|
|
{
|
|
public TaskController(IConfiguration configuration, MpStatsService DataService)
|
|
{
|
|
Log.Trace("Starting TaskController");
|
|
_configuration = configuration;
|
|
DService = DataService;
|
|
Log.Trace("Avviato TaskController");
|
|
}
|
|
|
|
/// <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(MP.Data.Objects.Enums.Task2ExeType.ND, "");
|
|
return answ;
|
|
}
|
|
|
|
/// <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(MP.Data.Objects.Enums.Task2ExeType.ND, "");
|
|
// 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.TaskId);
|
|
answ.Add(result);
|
|
}
|
|
// resituisco
|
|
return answ;
|
|
}
|
|
|
|
|
|
private static IConfiguration _configuration = null!;
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
/// <summary>
|
|
/// Dataservice x accesso DB
|
|
/// </summary>
|
|
protected MpStatsService DService { get; set; }
|
|
}
|
|
}
|