diff --git a/MP-LAND.sln b/MP-LAND.sln
index 85bcdda1..2113d66c 100644
--- a/MP-LAND.sln
+++ b/MP-LAND.sln
@@ -24,8 +24,8 @@ Global
{D949AB45-9B65-4594-A97E-182BC3831707}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D949AB45-9B65-4594-A97E-182BC3831707}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D949AB45-9B65-4594-A97E-182BC3831707}.Release|Any CPU.Build.0 = Release|Any CPU
- {E8B1E617-87BC-4638-A8B6-04EEBA3B8F47}.Debug_LiManDebug|Any CPU.ActiveCfg = Debug|Any CPU
- {E8B1E617-87BC-4638-A8B6-04EEBA3B8F47}.Debug_LiManDebug|Any CPU.Build.0 = Debug|Any CPU
+ {E8B1E617-87BC-4638-A8B6-04EEBA3B8F47}.Debug_LiManDebug|Any CPU.ActiveCfg = Debug_LiManDebug|Any CPU
+ {E8B1E617-87BC-4638-A8B6-04EEBA3B8F47}.Debug_LiManDebug|Any CPU.Build.0 = Debug_LiManDebug|Any CPU
{E8B1E617-87BC-4638-A8B6-04EEBA3B8F47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E8B1E617-87BC-4638-A8B6-04EEBA3B8F47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8B1E617-87BC-4638-A8B6-04EEBA3B8F47}.Release|Any CPU.ActiveCfg = Release|Any CPU
diff --git a/MP.AppAuth/AppAuthContext.cs b/MP.AppAuth/AppAuthContext.cs
index c8c74357..35fedc43 100644
--- a/MP.AppAuth/AppAuthContext.cs
+++ b/MP.AppAuth/AppAuthContext.cs
@@ -10,7 +10,7 @@ namespace MP.AppAuth
{
#region Private Fields
- private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
+ private static Logger Log = LogManager.GetCurrentClassLogger();
private IConfiguration _configuration;
diff --git a/MP.AppAuth/MP.AppAuth.csproj b/MP.AppAuth/MP.AppAuth.csproj
index b8b2a8c4..95ecb38c 100644
--- a/MP.AppAuth/MP.AppAuth.csproj
+++ b/MP.AppAuth/MP.AppAuth.csproj
@@ -2,6 +2,7 @@
net6.0
+ Debug;Release;Debug_LiManDebug
@@ -16,7 +17,10 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
diff --git a/MP.Land/Data/SyncService.cs b/MP.AppAuth/Services/SyncService.cs
similarity index 96%
rename from MP.Land/Data/SyncService.cs
rename to MP.AppAuth/Services/SyncService.cs
index a51aa105..123b9074 100644
--- a/MP.Land/Data/SyncService.cs
+++ b/MP.AppAuth/Services/SyncService.cs
@@ -1,7 +1,4 @@
-using Egw.Core;
-using Microsoft.Extensions.Caching.Distributed;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Configuration;
using MP.AppAuth.DTO;
using MP.AppAuth.Models;
using Newtonsoft.Json;
@@ -11,12 +8,12 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Text;
using System.Threading.Tasks;
using System.Web;
-using static Egw.Core.LiManObj;
using static System.Net.Mime.MediaTypeNames;
-namespace MP.Land.Data
+namespace MP.AppAuth.Services
{
public class SyncService
{
@@ -31,15 +28,17 @@ namespace MP.Land.Data
_configuration = configuration;
// sistemo conf secondo Target compilazione
-
-
#if DEBUG_LIMANDEBUG
apiUrl = "https://localhost:5003/";
#else
apiUrl = "https://liman.egalware.com/ELM.API/";
#endif
// fix opzioni base del RestClient
- restOptStd = new RestClientOptions { Timeout = TimeSpan.FromSeconds(60), BaseUrl = new Uri(apiUrl) };
+ restOptStd = new RestClientOptions
+ {
+ Timeout = TimeSpan.FromSeconds(60),
+ BaseUrl = new Uri(apiUrl)
+ };
}
#endregion Public Constructors
@@ -82,7 +81,7 @@ namespace MP.Land.Data
answ = response.Content.Replace("\"", "");
}
}
- return await Task.FromResult(answ);
+ return answ;
}
///
@@ -241,16 +240,20 @@ namespace MP.Land.Data
private static IConfiguration? _configuration;
- ///
- /// URL dell'API x chiamate gestione licenze
- ///
- private string apiUrl { get; set; } = "https://localhost:5003/";
-
///
/// Classe logger
///
private static Logger Log = LogManager.GetCurrentClassLogger();
+ #endregion Private Fields
+
+ #region Private Properties
+
+ ///
+ /// URL dell'API x chiamate gestione licenze
+ ///
+ private string apiUrl { get; set; } = "https://localhost:5003/";
+
///
/// Conf client RestSharp standard:
/// - base URI al sito
@@ -258,6 +261,6 @@ namespace MP.Land.Data
///
private RestClientOptions restOptStd { get; set; } = new RestClientOptions();
- #endregion Private Fields
+ #endregion Private Properties
}
}
\ No newline at end of file
diff --git a/MP.Data/Controllers/MpLandController.cs b/MP.Data/Controllers/MpLandController.cs
index 10112783..e4998388 100644
--- a/MP.Data/Controllers/MpLandController.cs
+++ b/MP.Data/Controllers/MpLandController.cs
@@ -127,7 +127,7 @@ namespace MP.Data.Controllers
///
/// Se true rischedula successiva chiamata
///
- public TaskResultModel ExecuteTask(int TaskId, bool SchedNext)
+ public TaskResultModel ExecuteSqlTask(int TaskId, bool SchedNext)
{
TaskResultModel callRes = new TaskResultModel();
using (var dbCtx = new MoonPro_STATSContext(_configuration))
@@ -195,6 +195,7 @@ namespace MP.Data.Controllers
return callRes;
}
+
///
/// Annulla modifiche su una specifica entity (cancel update)
///
@@ -302,6 +303,58 @@ namespace MP.Data.Controllers
return dbResult;
}
+
+ ///
+ /// Esegue registrazione di un Task generico (NON SQL)
+ ///
+ ///
+ /// Se true rischedula successiva chiamata
+ /// Record esecuzione task esterno
+ ///
+ public TaskResultModel TaskExecSaveExecuted(int TaskId, bool SchedNext, TaskExecModel ResRec)
+ {
+ TaskResultModel callRes = new TaskResultModel();
+ using (var dbCtx = new MoonProContext(_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;
+ }
///
/// Update ordinamento task
///
@@ -374,7 +427,7 @@ namespace MP.Data.Controllers
{
var currData = dbCtx
.DbSetTaskList
- .Where(x => x.TaskId == rec2upd.TaskId)
+ .Where(x => x.TaskId == rec2upd.TaskId && rec2upd.TaskId > 0)
.FirstOrDefault();
if (currData != null)
{
diff --git a/MP.Data/Controllers/MpStatsController.cs b/MP.Data/Controllers/MpStatsController.cs
index a03ae446..8dadbbb8 100644
--- a/MP.Data/Controllers/MpStatsController.cs
+++ b/MP.Data/Controllers/MpStatsController.cs
@@ -541,7 +541,7 @@ namespace MP.Data.Controllers
}
///
- /// Ricerca task dato tipo e
+ /// Ricerca task dato tipo
///
///
///
diff --git a/MP.Data/MP.Data.csproj b/MP.Data/MP.Data.csproj
index feb3bf54..fb544465 100644
--- a/MP.Data/MP.Data.csproj
+++ b/MP.Data/MP.Data.csproj
@@ -34,6 +34,8 @@
+
+
\ No newline at end of file
diff --git a/MP.Data/Objects/Enums.cs b/MP.Data/Objects/Enums.cs
index e9b8f5ce..91506d00 100644
--- a/MP.Data/Objects/Enums.cs
+++ b/MP.Data/Objects/Enums.cs
@@ -271,7 +271,17 @@ namespace MP.Data.Objects
///
/// Chiamata a SQL Stored Procedure
///
- SqlStored
+ SqlStored,
+
+ ///
+ /// Chiamata REST tipo Get
+ ///
+ RestCallGet,
+
+ /////
+ ///// Chiamata REST tipo Post
+ /////
+ //RestCallPost
}
//[JsonConverter(typeof(StringEnumConverter))]
diff --git a/MP.Data/Services/RestCallService.cs b/MP.Data/Services/RestCallService.cs
new file mode 100644
index 00000000..48a5da3d
--- /dev/null
+++ b/MP.Data/Services/RestCallService.cs
@@ -0,0 +1,111 @@
+using Microsoft.Extensions.Configuration;
+using Newtonsoft.Json;
+using NLog;
+using RestSharp;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Web;
+using static System.Net.Mime.MediaTypeNames;
+
+namespace MP.AppAuth.Services
+{
+ public class RestCallService
+ {
+ #region Public Constructors
+
+ ///
+ /// Init classe
+ ///
+ ///
+ public RestCallService(IConfiguration configuration)
+ {
+ _configuration = configuration;
+ // verifico la url base
+ apiUrl = _configuration.GetValue("ServerConf:Prog.ApiUrl");
+ // fix opzioni base del RestClient
+ restOptStd = new RestClientOptions
+ {
+ Timeout = TimeSpan.FromSeconds(60),
+ BaseUrl = new Uri(apiUrl)
+ };
+ }
+
+ private string apiUrl = "";
+
+ #endregion Public Constructors
+
+ #region Public Methods
+
+ ///
+ /// Stato server da chiamare x verifiche preliminari stato API REST
+ ///
+ ///
+ ///
+ public async Task CheckServer()
+ {
+ string answ = "ND";
+ // cerco online
+ using (RestClient client = new RestClient(apiUrl))
+ {
+ var request = new RestRequest($"api/health", Method.Get);
+ var response = await client.GetAsync(request);
+ // controllo risposta
+ if (response.StatusCode == System.Net.HttpStatusCode.OK)
+ {
+ // verifico risposta
+ if (response.Content != null)
+ {
+ answ = response.Content.Replace("\"", "");
+ }
+ }
+ }
+ return answ;
+ }
+
+ ///
+ /// Effettua una generica chiamata ApiRest
+ ///
+ /// URL Api di base
+ /// Richiesta completa
+ ///
+ public async Task CallRestGet(string ApiUrl, string ApiRequest)
+ {
+ RestResponse response;
+ // cerco online
+ using (RestClient client = new RestClient(ApiUrl))
+ {
+ var request = new RestRequest(ApiRequest, Method.Get);
+ response = await client.GetAsync(request);
+ }
+ return response;
+ }
+
+ #endregion Public Methods
+
+ #region Private Fields
+
+ private static IConfiguration? _configuration;
+
+ ///
+ /// Classe logger
+ ///
+ private static Logger Log = LogManager.GetCurrentClassLogger();
+
+ #endregion Private Fields
+
+ #region Private Properties
+
+ ///
+ /// Conf client RestSharp standard:
+ /// - base URI al sito
+ /// - timeout 1 min
+ ///
+ private RestClientOptions restOptStd { get; set; } = new RestClientOptions();
+
+ #endregion Private Properties
+ }
+}
\ No newline at end of file
diff --git a/MP.Data/Services/TaskService.cs b/MP.Data/Services/TaskService.cs
index f11cf152..6e866e4a 100644
--- a/MP.Data/Services/TaskService.cs
+++ b/MP.Data/Services/TaskService.cs
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
+using MP.AppAuth.Services;
using MP.Data.Controllers;
using MP.Data.DatabaseModels;
using Newtonsoft.Json;
@@ -61,6 +62,9 @@ namespace MP.Data.Services
DataSource = connStrParams["Server"];
DataBase = connStrParams["Database"];
}
+
+ // conf rest call service
+ RCallService = new RestCallService(_configuration);
}
#endregion Public Constructors
@@ -88,15 +92,56 @@ namespace MP.Data.Services
///
/// Chiamata esecuzione di un singolo task programmato
///
- ///
+ /// Task richiesto
/// Se true rischedula successiva chiamata
///
- public async Task ExecuteTask(int TaskId, bool SchedNext)
+ public async Task ExecuteTask(TaskListModel TaskRec, bool SchedNext)
{
- TaskResultModel dbResult = MLController.ExecuteTask(TaskId, SchedNext);
+ TaskResultModel answ = new TaskResultModel()
+ {
+ Task = $"TaskId: {TaskRec.TaskId} | {TaskRec.TType}",
+ ExecResult = -1,
+ TextResult = "Task Not recognized"
+ };
+ // verifico tipo di task ed eseguo di conseguenza...
+ switch (TaskRec.TType)
+ {
+ //case Task2ExeType.ND:
+ // break;
+ //case Task2ExeType.Exe:
+ // break;
+ //case Task2ExeType.SqlCommand:
+ // break;
+ case Task2ExeType.SqlStored:
+ answ = MLController.ExecuteSqlTask(TaskRec.TaskId, SchedNext);
+ break;
+ case Task2ExeType.RestCallGet:
+ DateTime dtStart = DateTime.Now;
+ // in primis testo la chiamata al servizio Health
+ string rAnsw = await RCallService.CheckServer();
+ // se ok effettuo vera chiamata...
+ if (rAnsw.ToUpper() == "OK")
+ {
+ var callResp = await RCallService.CallRestGet(TaskRec.Command, TaskRec.Args);
+ DateTime dtEnd = DateTime.Now;
+ TaskExecModel tExeMod = new TaskExecModel()
+ {
+ DtEnd = dtEnd,
+ DtStart = dtStart,
+ IsError = callResp.StatusCode != System.Net.HttpStatusCode.OK,
+ TaskId = TaskRec.TaskId,
+ Result = $"{callResp.Content}".Replace("\"", ""),
+ };
+ // salvo su DB
+ answ = MLController.TaskExecSaveExecuted(TaskRec.TaskId, SchedNext, tExeMod);
+ }
+ break;
+ default:
+ break;
+ }
// svuoto cache!
await FlushCache("Task");
- return dbResult;
+ return answ;
}
///
@@ -246,7 +291,7 @@ namespace MP.Data.Services
bool dbResult = MLController.TaskListUpsert(rec2upd);
// svuoto cache!
await FlushCache("Task");
- return await Task.FromResult(dbResult);
+ return dbResult;
}
#endregion Public Methods
@@ -286,6 +331,7 @@ namespace MP.Data.Services
#region Private Properties
private static MpLandController MLController { get; set; } = null!;
+ private RestCallService RCallService { get; set; } = null!;
#endregion Private Properties
diff --git a/MP.Land/Components/TaskExeList.razor b/MP.Land/Components/TaskExeList.razor
index b74c56a3..850338fc 100644
--- a/MP.Land/Components/TaskExeList.razor
+++ b/MP.Land/Components/TaskExeList.razor
@@ -2,8 +2,17 @@