Update x gestione remote call e ritorni vari

This commit is contained in:
Samuele Locatelli
2025-01-18 10:45:40 +01:00
parent 2af4e5a7a5
commit 05b46a629c
12 changed files with 367 additions and 114 deletions
+7
View File
@@ -34,6 +34,7 @@
notifyIcon1 = new NotifyIcon(components);
trayMenu = new ContextMenuStrip(components);
timerCheck = new System.Windows.Forms.Timer(components);
timerTask = new System.Windows.Forms.Timer(components);
SuspendLayout();
//
// blazorWebView1
@@ -66,6 +67,11 @@
timerCheck.Interval = 1000;
timerCheck.Tick += timerCheck_Tick;
//
// timerTask
//
timerTask.Interval = 1000;
timerTask.Tick += timerTask_Tick;
//
// BlazorForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
@@ -89,5 +95,6 @@
private NotifyIcon notifyIcon1;
private ContextMenuStrip trayMenu;
private System.Windows.Forms.Timer timerCheck;
private System.Windows.Forms.Timer timerTask;
}
}
+60 -16
View File
@@ -26,13 +26,13 @@ namespace EgwControlCenter.App
#region Private Fields
private static bool forceClose = false;
/// <summary>
/// Classe logger
/// </summary>
private static Logger Log = LogManager.GetCurrentClassLogger();
private bool forceClose = false;
private Size minSize = new Size(676, 409);
/// <summary>
@@ -61,14 +61,37 @@ namespace EgwControlCenter.App
#region Private Methods
/// <summary>
/// Esecuzione del processo di restart
/// </summary>
private static void DoRestart()
{
// verifico se sono in debug o meno...
#if DEBUG
// NON eseguo...
forceClose = true;
Application.Restart();
Environment.Exit(0);
#else
// uso restarter esterno...
Assembly assembly = Assembly.GetExecutingAssembly();
string startDir = Path.GetDirectoryName(assembly.Location)!;
string extPath = Path.Combine(startDir, "libs", "EgwAccRestarter.exe");
Process.Start(extPath);
#endif
}
private void BlazorForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (forceClose)
{
MainAppControlService.EA_StatusUpdated -= MainAppControlService_EA_StatusUpdated;
MainAppControlService.EA_ConfigUpdated -= MainAppControlService_EA_ConfigUpdated;
MainAppControlService.EA_RestartRequested -= MainAppControlService_EA_RestartRequested;
timerCheck.Stop();
timerCheck.Dispose();
timerTask.Stop();
timerTask.Dispose();
}
else
{
@@ -167,6 +190,7 @@ namespace EgwControlCenter.App
private async Task ForceReload()
{
await MainAppControlService.DoFullCheckAsync(true);
await MainAppControlService.DoTaskCheckAsync(true);
}
private void InitBlazorView()
@@ -205,9 +229,19 @@ namespace EgwControlCenter.App
private void MainAppControlService_EA_ConfigUpdated()
{
timerCheck.Stop();
timerTask.Stop();
StartTimer();
}
/// <summary>
/// Gestione evento restart applicazione
/// </summary>
private void MainAppControlService_EA_RestartRequested()
{
// effettua chiamata restart
DoRestart();
}
/// <summary>
/// Verifica se ci siano update da mostrare come notifica in tray
/// </summary>
@@ -277,7 +311,7 @@ namespace EgwControlCenter.App
{
// notifica ballontip se ho aggiornamenti...
DateTime adesso = DateTime.Now;
if ( adesso > lastMsqShown.AddSeconds(VetoNewNotifySec))
if (adesso > lastMsqShown.AddSeconds(VetoNewNotifySec))
{
// salvo che ho mostrato msg
lastMsqShown = adesso;
@@ -302,6 +336,7 @@ namespace EgwControlCenter.App
MainAppControlService = new AppControlService();
MainAppControlService.EA_StatusUpdated += MainAppControlService_EA_StatusUpdated;
MainAppControlService.EA_ConfigUpdated += MainAppControlService_EA_ConfigUpdated;
MainAppControlService.EA_RestartRequested += MainAppControlService_EA_RestartRequested;
}
private void SetPosition()
@@ -334,12 +369,32 @@ namespace EgwControlCenter.App
timerCheck.Interval = (MainAppControlService.RefreshPeriod * 1000);
// sistemo timer
timerCheck.Start();
timerTask.Start();
}
private async void timerCheck_Tick(object sender, EventArgs e)
{
// fermo task...
timerCheck.Stop();
// esegue controllo locale ed eventualmente remoto se scaduto...
await MainAppControlService.DoFullCheckAsync(false);
// riavvio task x evitare sovrapposizioni in debug
timerCheck.Start();
}
/// <summary>
/// Timer task (3 sec base)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void timerTask_Tick(object sender, EventArgs e)
{
// fermo task...
timerTask.Stop();
// esegue controllo task
await MainAppControlService.DoTaskCheckAsync(false);
// riavvio task x evitare sovrapposizioni in debug
timerTask.Start();
}
/// <summary>
@@ -359,18 +414,7 @@ namespace EgwControlCenter.App
}
else if (e.ClickedItem.Text.StartsWith("Restart"))
{
// verifico se sono in debug o meno...
#if DEBUG
forceClose = true;
Application.Restart();
Environment.Exit(0);
#else
// uso restarter esterno...
Assembly assembly = Assembly.GetExecutingAssembly();
string startDir = Path.GetDirectoryName(assembly.Location)!;
string extPath = Path.Combine(startDir, "libs", "EgwAccRestarter.exe");
Process.Start(extPath);
#endif
DoRestart();
}
else if (e.ClickedItem.Text.StartsWith("Show"))
{
@@ -380,6 +424,6 @@ namespace EgwControlCenter.App
}
}
#endregion Private Methods
#endregion Private Methods
}
}
+3
View File
@@ -293,6 +293,9 @@
<metadata name="timerCheck.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>236, 17</value>
</metadata>
<metadata name="timerTask.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>351, 17</value>
</metadata>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAEAMDAAAAEAIACoJQAAFgAAACgAAAAwAAAAYAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
@@ -129,6 +129,7 @@ namespace EgwControlCenter.App.Components.Compo
await InvokeAsync(StateHasChanged);
// check finale
await ACService.DoFullCheckAsync(true);
await ACService.DoTaskCheckAsync(true);
ForceReload();
await InvokeAsync(StateHasChanged);
}
@@ -136,6 +137,7 @@ namespace EgwControlCenter.App.Components.Compo
protected async Task ForceCheck()
{
await ACService.DoFullCheckAsync(true);
await ACService.DoTaskCheckAsync(true);
}
protected override void OnInitialized()
@@ -145,6 +147,8 @@ namespace EgwControlCenter.App.Components.Compo
currStats = new TaskRunStats(ACService.DataDir, "Stats.json");
}
protected override void OnParametersSet()
{
ForceReload();
@@ -199,7 +199,7 @@ namespace EgwControlCenter.App.Components.Compo
{
// controllo stato chiamata...
string mainKey = await ACService.CheckAssignIdxLic();
vetoRemCheck = DateTime.Now.AddMilliseconds(rnd.Next(1500, 2500));
vetoRemCheck = DateTime.Now.AddMilliseconds(rnd.Next(800, 1200));
// se la auth key fosse valida ritorno evento x uscire da fase validazione...
if (!string.IsNullOrEmpty(mainKey))
{
@@ -42,6 +42,7 @@ namespace EgwControlCenter.App.Components.Pages
protected async Task ForceCheck()
{
await ACService.DoFullCheckAsync(true);
await ACService.DoTaskCheckAsync(true);
}
protected override async Task OnInitializedAsync()
@@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.2.2501.1616</Version>
<Version>1.2.2501.1810</Version>
<Configurations>Debug;Release;DEBUG_Local</Configurations>
</PropertyGroup>
<ItemGroup>
@@ -17,8 +17,8 @@
<None Include="wwwroot\favicon.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="EgwCoreLib.Razor" Version="1.5.2412.2718" />
<PackageReference Include="EgwCoreLib.Utils" Version="1.5.2412.2718" />
<PackageReference Include="EgwCoreLib.Razor" Version="1.5.2501.1716" />
<PackageReference Include="EgwCoreLib.Utils" Version="1.5.2501.1716" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.Analyzers" Version="8.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.WindowsForms" Version="8.0.100" />
@@ -4,8 +4,8 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<ApplicationRevision>1616</ApplicationRevision>
<ApplicationVersion>1.2.2501.1616</ApplicationVersion>
<ApplicationRevision>1810</ApplicationRevision>
<ApplicationVersion>1.2.2501.1810</ApplicationVersion>
<BootstrapperEnabled>True</BootstrapperEnabled>
<Configuration>Release</Configuration>
<CreateWebPageOnPublish>True</CreateWebPageOnPublish>
+235 -67
View File
@@ -13,6 +13,25 @@ namespace EgwControlCenter.Core
{
public class AppControlService : IAppControlService
{
#region Public Fields
/// <summary>
/// Dizionario completo info macchina
/// </summary>
public static Dictionary<string, string> DictMachineInfo = new Dictionary<string, string>();
/// <summary>
/// Dizionario completo info networking
/// </summary>
public static Dictionary<string, string> DictNetInfo = new Dictionary<string, string>();
/// <summary>
/// Dizionario completo info utente
/// </summary>
public static Dictionary<string, string> DictUserInfo = new Dictionary<string, string>();
#endregion Public Fields
#region Public Constructors
public AppControlService()
@@ -23,6 +42,11 @@ namespace EgwControlCenter.Core
string startDir = Path.GetDirectoryName(assembly.Location)!;
ConfDir = startDir;
CodImpiego = SLicManager.CodImpiego();
// setup RuntimConf (da gestire anche con set remoto...)
RuntimeConfDict.Add("CountNumFastCheck", "30");
// chiedo info x fare setup DeviceName...
var allInfo = DeviceInfoDict();
DeviceName = DictUserInfo != null && DictUserInfo.ContainsKey("MachineName") ? DictUserInfo["MachineName"] : "UnkDevice";
//DataDir = Environment.GetEnvironmentVariable("ClickOnce_DataDirectory") ?? startDir;
string appData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
if (string.IsNullOrEmpty(appData))
@@ -57,7 +81,12 @@ namespace EgwControlCenter.Core
public event Action EA_RemoteCalling = null!;
/// <summary>
/// Evento udpate status controlli
/// Evento richiesta update applicazione
/// </summary>
public event Action EA_RestartRequested = null!;
/// <summary>
/// Evento update status controlli
/// </summary>
public event Action EA_StatusUpdated = null!;
@@ -265,17 +294,22 @@ namespace EgwControlCenter.Core
}
/// <summary>
/// Effettua un controllo completo (loacele remoto)
/// Effettua un controllo completo (locale e remoto)
/// </summary>
/// <param name="doForce">se true esegue anche prima della scadenza veto</param>
public async Task DoFullCheckAsync(bool doForce)
{
DateTime adesso = DateTime.Now;
Stopwatch sw = new Stopwatch();
sw.Start();
// dizionario risultati controllo...
Dictionary<string, string> taskResults = new Dictionary<string, string>();
Dictionary<string, string> jobDetail = new Dictionary<string, string>();
if (lastCheckDone.AddMinutes(VetoRefresh) < adesso || doForce)
{
CloudCallActive = true;
lastCheckDone = adesso;
//se non è forzato controllo ultimo check
// se non è forzato controllo ultimo check
// in primis controllo se il remote è ok sennò mi fermo...
bool remoteOk = await CurrCheck.CheckRemote();
if (remoteOk)
@@ -297,41 +331,19 @@ namespace EgwControlCenter.Core
}
}
CloudCallActive = false;
// predispongo x check task successivo...
vetoTaskCheck = adesso.AddSeconds(-1);
}
else if (vetoTaskCheck < adesso)
{
// veto random prossimo controllo...
int vetoSec = rnd.Next(60, 180);
// verifica se ci siano task da eseguire...
var task2exe = await CurrCheck.Task2ExeGet();
if (task2exe != null && task2exe.Count > 0)
{
// imposto veto prox controllo breve: circa 30 sec....
vetoSec = rnd.Next(5, 15);
Dictionary<string, string> taskResults = new Dictionary<string, string>();
// eseguo 1:1 ...
foreach (var currTask in task2exe)
{
var cResp = await ExecuteTask(currTask);
// provo ad accodare risposte...
foreach (var resp in cResp)
{
if (taskResults.ContainsKey(resp.Key))
{
taskResults[resp.Key] = resp.Value;
}
else
{
taskResults.Add(resp.Key, resp.Value);
}
}
}
// invio risposta esito esecuzione finale
await CurrCheck.Task2ExeSend(taskResults);
}
// imposto veto controlli task
vetoTaskCheck = adesso.AddSeconds(vetoSec);
}
// aggiungo dataora esecuzone e tempo complessivo
sw.Stop();
jobDetail.Add("ExecutionTime", $"{sw.Elapsed.TotalSeconds:N3} sec");
jobDetail.Add("Completed", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
// impacchetto la risposta complessiva
string payload = JsonConvert.SerializeObject(jobDetail);
string checkType = doForce ? "Forced" : "Standard";
taskResults.Add($"AppCheck{checkType}", payload);
// invio risposta esito esecuzione finale
await CurrCheck.TaskSetDone(DeviceName, taskResults);
}
/// <summary> Effettua rilettura configurazione e setup controlli... </summary
@@ -370,6 +382,55 @@ namespace EgwControlCenter.Core
ReportConfigUpd();
}
/// <summary>
/// Effettua un controllo dei task da eseguire
/// </summary>
/// <param name="doForce">se true esegue anche prima della scadenza veto</param>
public async Task DoTaskCheckAsync(bool doForce)
{
DateTime adesso = DateTime.Now;
if (vetoTaskCheck < adesso || doForce || numFastCheck > 0)
{
// veto random prossimo controllo default 2 min (media)...
double vetoSec = (double)rnd.Next(10000, 14000) / 100;
if (numFastCheck > 0)
{
numFastCheck--;
}
// verifica se ci siano task da eseguire...
var task2exe = await CurrCheck.TaskGetReq(DeviceName);
if (task2exe != null && task2exe.Count > 0)
{
// in primis li segnala in running...
await CurrCheck.TaskSetRunning(DeviceName, task2exe);
// imposto limite a scalare x i prox fast check avendo trovato task da eseguire...
numFastCheck = RuntimeConfInt("CountNumFastCheck");
Dictionary<string, string> taskResults = new Dictionary<string, string>();
// eseguo 1:1 ...
foreach (var currTask in task2exe)
{
var cResp = await ExecuteTask(currTask);
// provo ad accodare risposte...
foreach (var resp in cResp)
{
if (taskResults.ContainsKey(resp.Key))
{
taskResults[resp.Key] = resp.Value;
}
else
{
taskResults.Add(resp.Key, resp.Value);
}
}
}
// invio risposta esito esecuzione finale
await CurrCheck.TaskSetDone(DeviceName, taskResults);
}
// imposto veto controlli task
vetoTaskCheck = adesso.AddSeconds(vetoSec);
}
}
/// <summary>
/// Restituisce un codice di auth temporaneo INT da impiegare x autorizzare
/// </summary>
@@ -380,30 +441,7 @@ namespace EgwControlCenter.Core
//verifico che NON ci sia una richiesta già in corso...
if (CurrEnrollData.IdReq == 0)
{
// in primis preparo dizionario dei dati da allegare alla richiesta
Dictionary<string, string> reqInfo = new Dictionary<string, string>();
// preparo dati DeviceId da allegare in coda
string deviceId = new DeviceIdBuilder()
.AddMachineName()
.AddUserName()
.AddOsVersion()
.OnWindows(windows => windows
.AddMacAddressFromWmi(excludeWireless: true, excludeNonPhysical: true)
.AddProcessorId()
.AddMotherboardSerialNumber()
.AddSystemDriveSerialNumber())
.ToString();
// aggiungo dati MachineInfo...
reqInfo = MachineDataValidator.userInfo;
foreach (var item in MachineDataValidator.netInfo)
{
if (!reqInfo.ContainsKey(item.Key))
{
reqInfo.Add(item.Key, item.Value);
}
}
// raggiungo DevideID
reqInfo.Add("DeviceID", deviceId);
Dictionary<string, string> reqInfo = DeviceInfoDict();
CloudCallActive = true;
// faccio la chiamata rest e salvo risposta...
@@ -478,6 +516,8 @@ namespace EgwControlCenter.Core
#region Protected Fields
protected string DeviceName = "";
protected UpdateMan updateMan = new UpdateMan();
protected UpdateMan updateManAuth = new UpdateMan("SWDownloader", "viaD@nte16");
@@ -543,6 +583,11 @@ namespace EgwControlCenter.Core
/// </summary>
private DateTime lastCheckDone = DateTime.Today.AddMonths(-1);
/// <summary>
/// Numero di controlli fast (5 sec medi) dei task prima di tornare alla gestione lenta (2 min)
/// </summary>
private int numFastCheck = 0;
/// <summary>
/// Valore massimo ammesso refresh sec
/// </summary>
@@ -555,6 +600,11 @@ namespace EgwControlCenter.Core
private Random rnd = new Random();
/// <summary>
/// Configurazione parametri speciali a runtime (con override da remoto...)
/// </summary>
private Dictionary<string, string> RuntimeConfDict = new Dictionary<string, string>();
/// <summary>
/// Directory temp di appoggio
/// </summary>
@@ -612,6 +662,59 @@ namespace EgwControlCenter.Core
#region Private Methods
/// <summary>
/// Predispone un dizionario delle info del device + ID x inviare
/// </summary>
/// <returns></returns>
private static Dictionary<string, string> DeviceInfoDict()
{
// in primis preparo dizionario dei dati da allegare alla richiesta
Dictionary<string, string> reqInfo = new Dictionary<string, string>();
// in primis setup dati dizionario conf...
if (DictUserInfo == null || DictUserInfo.Count == 0)
{
DictUserInfo = new Dictionary<string, string>(MachineDataValidator.userInfo);
}
if (DictNetInfo == null || DictNetInfo.Count == 0)
{
DictNetInfo = new Dictionary<string, string>(MachineDataValidator.netInfo);
}
if (DictMachineInfo == null || DictMachineInfo.Count == 0)
{
DictMachineInfo = new Dictionary<string, string>(DictUserInfo);
foreach (var item in DictNetInfo)
{
if (!DictMachineInfo.ContainsKey(item.Key))
{
DictMachineInfo.Add(item.Key, item.Value);
}
}
}
// Iniziallizzo con dati MachineInfo...
reqInfo = new Dictionary<string, string>(DictMachineInfo);
foreach (var item in new Dictionary<string, string>(MachineDataValidator.netInfo))
{
if (!reqInfo.ContainsKey(item.Key))
{
reqInfo.Add(item.Key, item.Value);
}
}
// ora i dati DeviceId da allegare in coda
string deviceId = new DeviceIdBuilder()
.AddMachineName()
.AddUserName()
.AddOsVersion()
.OnWindows(windows => windows
.AddMacAddressFromWmi(excludeWireless: true, excludeNonPhysical: true)
.AddProcessorId()
.AddMotherboardSerialNumber()
.AddSystemDriveSerialNumber())
.ToString();
// raggiungo DevideID
reqInfo.Add("DeviceID", deviceId);
return reqInfo;
}
/// <summary>
/// Elimina contenuto directory
/// </summary>
@@ -642,24 +745,53 @@ namespace EgwControlCenter.Core
Dictionary<string, string> taskDone = new Dictionary<string, string>();
bool taskOk = false;
string taskVal = "";
Stopwatch sw = Stopwatch.StartNew();
// converto richiesta in enum...
CoreEnum.EgwAccTask tName = CoreEnum.EgwAccTask.ND;
Enum.TryParse(item.Key, out tName);
// switch sui vari casi x eseguire...
switch (tName)
{
//case CoreEnum.EgwAccTask.AppSearch:
// break;
case CoreEnum.EgwAccTask.DeviceInfoGet:
Dictionary<string, string> currDevInfo = DeviceInfoDict();
taskVal = JsonConvert.SerializeObject(currDevInfo, Formatting.Indented);
break;
case CoreEnum.EgwAccTask.ForceCheck:
Dictionary<string, string> fcDetail = new Dictionary<string, string>();
fcDetail.Add("ExecStart", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
await DoFullCheckAsync(true);
sw.Stop();
fcDetail.Add("Completed", $"App Check done in {sw.Elapsed.TotalMilliseconds:N0}ms");
taskVal = JsonConvert.SerializeObject(fcDetail, Formatting.Indented);
break;
case CoreEnum.EgwAccTask.ForceUpdate:
Dictionary<string, string> fcUpdate = new Dictionary<string, string>();
fcUpdate.Add("ExecStart", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
sw.Stop();
// mando subito conferma esecuzione...
fcUpdate.Add("ExecStart", $"Full Restart Requested...");
taskVal = JsonConvert.SerializeObject(fcUpdate, Formatting.Indented);
// sollevo evento
if (EA_RestartRequested != null)
{
EA_RestartRequested?.Invoke();
}
break;
case CoreEnum.EgwAccTask.OxyLicenseGet:
break;
case CoreEnum.EgwAccTask.ParamDictReset:
break;
case CoreEnum.EgwAccTask.ParamUpsert:
break;
//case CoreEnum.EgwAccTask.OxyLicenseGet:
// break;
//case CoreEnum.EgwAccTask.ParamDictReset:
// break;
//case CoreEnum.EgwAccTask.ParamUpsert:
// break;
case CoreEnum.EgwAccTask.ND:
default:
taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC";
@@ -668,6 +800,11 @@ namespace EgwControlCenter.Core
}
// aggiungo task!
taskDone.Add(item.Key, taskVal);
// aggiungo task ultima esecuzione...
Dictionary<string, string> finDet = new Dictionary<string, string>();
finDet.Add("Completed", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
taskVal = JsonConvert.SerializeObject(finDet, Formatting.Indented);
taskDone.Add("LastTaskExec", taskVal);
return taskDone;
}
@@ -887,6 +1024,37 @@ namespace EgwControlCenter.Core
}
}
/// <summary>
/// Recupera parametro conf in Runtime di tipo Int
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
private int RuntimeConfInt(string param)
{
int answ = 0;
if (RuntimeConfDict.ContainsKey(param))
{
string retVal = RuntimeConfDict[param];
int.TryParse(retVal, out answ);
}
return answ;
}
/// <summary>
/// Recupera parametro conf in Runtime di tipo Int
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
private string RuntimeConfString(string param)
{
string answ = "";
if (RuntimeConfDict.ContainsKey(param))
{
answ = RuntimeConfDict[param];
}
return answ;
}
#endregion Private Methods
}
}
+5 -1
View File
@@ -59,11 +59,15 @@ namespace EgwControlCenter.Core
/// </summary>
ND = 0,
/// <summary>
/// Richiesta ricerca generica app da sorgenti mappate (registro, path...) ricevute in input
/// </summary>
AppSearch,
/// <summary>
/// Richiesta info device (analoghe a quelle del setup iniziale in Enroll)
/// </summary>
DeviceInfoGet,
/// <summary>
/// Richiesta verifica forzata da remoto
/// Richiesta verifica forzata da remoto delle versioni app gestite ed installate
/// </summary>
ForceCheck,
/// <summary>
@@ -8,8 +8,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EgwCoreLib.Razor" Version="1.5.2412.2718" />
<PackageReference Include="EgwCoreLib.Utils" Version="1.5.2412.2718" />
<PackageReference Include="EgwCoreLib.Razor" Version="1.5.2501.1716" />
<PackageReference Include="EgwCoreLib.Utils" Version="1.5.2501.1716" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.Analyzers" Version="8.0.11" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
+44 -22
View File
@@ -188,7 +188,7 @@ namespace EgwControlCenter.Core
// aggiorna set rel current
CriticalRelCurrent = listRemote;
// se ho fatto aggiornamenti locali salvo!
// se ho answ aggiornamenti locali salvo!
if (setUpdated)
{
SaveStatus();
@@ -541,27 +541,22 @@ namespace EgwControlCenter.Core
/// <summary>
/// Richiede dizionario dei task da eseguire localmente
/// </summary>
/// <param name="devName">Nome device</param>
/// <returns></returns>
public async Task<Dictionary<string, string>> Task2ExeGet()
public async Task<Dictionary<string, string>> TaskGetReq(string devName)
{
Dictionary<string, string> taskReq = new Dictionary<string, string>();
try
{
// preparo richiesta...
AuthDataDTO currReq = new AuthDataDTO()
{
AppKey = CurrPatrolCont.AppKey,
CodImp = CodImpiego,
MastKey = ""
};
// client chiamate rest
var client = new RestClient(restOptStd);
// Chiamo il metodo!
var actReq = new RestRequest($"/api/enroller/task-pending", Method.Post);
string payload = JsonConvert.SerializeObject(currReq);
actReq.AddJsonBody(payload);
var actReq = new RestRequest($"/api/apptask/pend/{devName}", Method.Get);
actReq.AddHeader("AppKey", CurrPatrolCont.AppKey);
actReq.AddHeader("CodImp", CodImpiego);
//actReq.AddHeader
// effettuo vera chiamata
var currResp = await client.PostAsync(actReq);
var currResp = await client.GetAsync(actReq);
if (currResp.StatusCode == System.Net.HttpStatusCode.OK && currResp.Content != null)
{
// mi aspetto un dizionario...
@@ -573,12 +568,12 @@ namespace EgwControlCenter.Core
}
else
{
Log.Error($"Errore in ricezione REST services Task2ExeGet | statusCode{currResp.StatusCode} | content: {currResp.Content}");
Log.Error($"Errore in ricezione REST services TaskGetReq | statusCode{currResp.StatusCode} | content: {currResp.Content}");
}
}
catch (Exception exc)
{
Log.Error($"Eccezione in fase gestione REST services Task2ExeGet{Environment.NewLine}{exc}");
Log.Error($"Eccezione in fase gestione REST services TaskGetReq{Environment.NewLine}{exc}");
}
return taskReq;
}
@@ -586,11 +581,25 @@ namespace EgwControlCenter.Core
/// <summary>
/// Invia un dizionario che dovrebbe comprendere tutte le richieste task 8da chiudere) + eventuali altri dati da salvare
/// </summary>
/// <param name="devName"></param>
/// <param name="taskRes"></param>
/// <returns></returns>
public async Task<string> Task2ExeSend(Dictionary<string, string> taskRes)
public async Task<string> TaskSetRunning(string devName, Dictionary<string, string> taskRes)
{
string fatto = "";
string answ = await TaskPostInfo(devName, taskRes, "running");
return answ;
}
/// <summary>
/// Metodo effettivo invio post info sul task
/// </summary>
/// <param name="devName"></param>
/// <param name="taskRes"></param
/// <param name="action"></param>
/// <returns></returns>
private async Task<string> TaskPostInfo(string devName, Dictionary<string, string> taskRes, string action)
{
string answ = "";
try
{
// preparo richiesta...
@@ -604,25 +613,38 @@ namespace EgwControlCenter.Core
// client chiamate rest
var client = new RestClient(restOptStd);
// Chiamo il metodo!
var actReq = new RestRequest($"/api/enroller/task-done", Method.Post);
var actReq = new RestRequest($"/api/apptask/{action}/{devName}", Method.Post);
string payload = JsonConvert.SerializeObject(currReq);
actReq.AddJsonBody(payload);
// effettuo vera chiamata
var currResp = await client.PostAsync(actReq);
if (currResp.StatusCode == System.Net.HttpStatusCode.OK && currResp.Content != null)
{
fatto = $"{currResp.Content}";
answ = $"{currResp.Content}";
}
else
{
Log.Error($"Errore in ricezione REST services Task2ExeGet | statusCode{currResp.StatusCode} | content: {currResp.Content}");
Log.Error($"Errore in ricezione REST services TaskPostInfo | action: {action} | statusCode{currResp.StatusCode} | content: {currResp.Content}");
}
}
catch (Exception exc)
{
Log.Error($"Eccezione in fase gestione REST services Task2ExeSend{Environment.NewLine}{exc}");
Log.Error($"Eccezione in fase gestione REST services TaskPostInfo | action: {action}{Environment.NewLine}{exc}");
}
return fatto;
return answ;
}
/// <summary>
/// Invia un dizionario che dovrebbe comprendere tutte le richieste task 8da chiudere) + eventuali altri dati da salvare
/// </summary>
/// <param name="devName"></param>
/// <param name="taskRes"></param
/// <returns></returns>
public async Task<string> TaskSetDone(string devName, Dictionary<string, string> taskRes)
{
string answ = await TaskPostInfo(devName, taskRes, "done");
return answ;
}
/// <summary>