diff --git a/EgwControlCenter.App/BlazorForm.Designer.cs b/EgwControlCenter.App/BlazorForm.Designer.cs index 26bd90a..44d781c 100644 --- a/EgwControlCenter.App/BlazorForm.Designer.cs +++ b/EgwControlCenter.App/BlazorForm.Designer.cs @@ -35,6 +35,8 @@ trayMenu = new ContextMenuStrip(components); timerCheck = new System.Windows.Forms.Timer(components); timerTask = new System.Windows.Forms.Timer(components); + timer1 = new System.Windows.Forms.Timer(components); + timerStats = new System.Windows.Forms.Timer(components); SuspendLayout(); // // blazorWebView1 @@ -42,7 +44,7 @@ blazorWebView1.Dock = DockStyle.Fill; blazorWebView1.Location = new Point(0, 0); blazorWebView1.Name = "blazorWebView1"; - blazorWebView1.Size = new Size(620, 370); + blazorWebView1.Size = new Size(644, 441); blazorWebView1.StartPath = "/"; blazorWebView1.TabIndex = 0; // @@ -72,11 +74,20 @@ timerTask.Interval = 1000; timerTask.Tick += timerTask_Tick; // + // timer1 + // + timer1.Interval = 1000; + // + // timerStats + // + timerStats.Interval = 600000; + timerStats.Tick += timerStats_Tick; + // // BlazorForm // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(620, 370); + ClientSize = new Size(644, 441); Controls.Add(blazorWebView1); Icon = (Icon)resources.GetObject("$this.Icon"); MaximizeBox = false; @@ -96,5 +107,7 @@ private ContextMenuStrip trayMenu; private System.Windows.Forms.Timer timerCheck; private System.Windows.Forms.Timer timerTask; + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.Timer timerStats; } } diff --git a/EgwControlCenter.App/BlazorForm.cs b/EgwControlCenter.App/BlazorForm.cs index a5a1092..3cd2698 100644 --- a/EgwControlCenter.App/BlazorForm.cs +++ b/EgwControlCenter.App/BlazorForm.cs @@ -55,7 +55,7 @@ namespace EgwControlCenter.App /// private DateTime lastMsqShown { get; set; } = DateTime.MinValue; - private Size lastSize { get; set; } = new Size(636, 409); + private Size lastSize { get; set; } = new Size(660, 480); #endregion Private Properties @@ -73,7 +73,12 @@ namespace EgwControlCenter.App Assembly assembly = Assembly.GetExecutingAssembly(); string startDir = Path.GetDirectoryName(assembly.Location)!; string extPath = Path.Combine(startDir, "libs", "EgwAccRestarter.exe"); - Process.Start(extPath); + // uso processstartInfo x nascondere finestra + ProcessStartInfo startInfo = new ProcessStartInfo(); + startInfo.WindowStyle = ProcessWindowStyle.Hidden; + startInfo.CreateNoWindow = true; + startInfo.FileName = extPath; + Process.Start(startInfo); } else { @@ -158,14 +163,36 @@ namespace EgwControlCenter.App } } + /// + /// Evento completamento caricamento app + /// + /// + /// private async void BlazorForm_Load(object sender, EventArgs e) { SetPosition(); // aspetto e poi mando a tray... await Task.Delay(500); SendToTray(); + // eseguo task preliminari tipo invio reset effettuato + elenco conf... + await Task.Delay(1000); + await ACService.SendRebooted(); + // ora invio info licenza (SE disponibili) + await Task.Delay(1000); + await ACService.SendLicInfo(); + // infine invio info conf (x editing successivo) + await Task.Delay(1000); + await ACService.SendConfTarget(); + // invio stats avvio + await Task.Delay(1000); + await ACService.SendStats(); } + /// + /// Evento post resize + /// + /// + /// private void BlazorForm_Resize(object sender, EventArgs e) { CheckFormVisibility(); @@ -229,8 +256,8 @@ namespace EgwControlCenter.App trayMenu.Items.Clear(); // aggiungo azioni con tasto DX trayMenu.Items.Add("Show EgalWare ACC"); - trayMenu.Items.Add("Reload EgalWare ACC"); - trayMenu.Items.Add("Restart EgalWare ACC"); + trayMenu.Items.Add("Reload Config"); + trayMenu.Items.Add("Restart And update"); trayMenu.Items.Add("Close EgalWare ACC"); } @@ -253,7 +280,7 @@ namespace EgwControlCenter.App { Stopwatch sw = new Stopwatch(); sw.Start(); - CurrAssembly = System.Reflection.Assembly.GetExecutingAssembly().GetName(); + CurrAssembly = Assembly.GetExecutingAssembly().GetName(); Log.Trace($"EgalWare's AppControlCenter Init, v.{CurrAssembly.Version}"); // sistemo grafica TRAY ICON SetupTrayIcon(); @@ -339,7 +366,7 @@ namespace EgwControlCenter.App notifyIcon1.BalloonTipClicked += NotifyIcon1_BalloonTipClicked; notifyIcon1.Visible = true; // mostro notifica... SE abilitata - if (ACService.EnableNotify) + if (ACService != null && ACService.EnableNotify) { notifyIcon1.ShowBalloonTip(100); } @@ -385,12 +412,24 @@ namespace EgwControlCenter.App private void StartTimer() { + // timer controlli da conf timerCheck.Interval = (ACService.RefreshPeriod * 1000); - // sistemo timer + // timer statistiche a 30 min fisso x ora + timerStats.Interval = 1000 * 60 * 5; +#if false + timerStats.Interval = 1000 * 60 * 30; +#endif + // avvio timer timerCheck.Start(); timerTask.Start(); + timerStats.Start(); } + /// + /// Esecuzione task di verifica stato app + /// + /// + /// private async void timerCheck_Tick(object sender, EventArgs e) { // fermo task... @@ -402,7 +441,24 @@ namespace EgwControlCenter.App } /// - /// Timer task (3 sec base) + /// Gestione timer statistiche + /// + /// + /// + private async void timerStats_Tick(object sender, EventArgs e) + { + // fermo task... + timerStats.Stop(); + // esegue controllo task + await ACService.SendStats(); + await ACService.SendLicInfo(); + await ACService.SendConfTarget(); + // riavvio task x evitare sovrapposizioni in debug + timerStats.Start(); + } + + /// + /// Timer task (1 sec base) /// /// /// diff --git a/EgwControlCenter.App/BlazorForm.resx b/EgwControlCenter.App/BlazorForm.resx index 0601373..8b1d2ea 100644 --- a/EgwControlCenter.App/BlazorForm.resx +++ b/EgwControlCenter.App/BlazorForm.resx @@ -296,6 +296,12 @@ 351, 17 + + 351, 17 + + + 439, 17 + AAABAAEAMDAAAAEAIACoJQAAFgAAACgAAAAwAAAAYAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA diff --git a/EgwControlCenter.App/Components/Compo/ApplicationCheck.razor.cs b/EgwControlCenter.App/Components/Compo/ApplicationCheck.razor.cs index 80a3fd9..b06a565 100644 --- a/EgwControlCenter.App/Components/Compo/ApplicationCheck.razor.cs +++ b/EgwControlCenter.App/Components/Compo/ApplicationCheck.razor.cs @@ -136,8 +136,11 @@ namespace EgwControlCenter.App.Components.Compo protected async Task ForceCheck() { + isLoading = true; + ListRecords = new List(); await ACService.DoFullCheckAsync(true); await ACService.DoTaskCheckAsync(true); + isLoading = false; } protected override void OnInitialized() diff --git a/EgwControlCenter.App/Components/Compo/TargetSetup.razor.cs b/EgwControlCenter.App/Components/Compo/TargetSetup.razor.cs index 435cdcd..92b00e2 100644 --- a/EgwControlCenter.App/Components/Compo/TargetSetup.razor.cs +++ b/EgwControlCenter.App/Components/Compo/TargetSetup.razor.cs @@ -62,10 +62,12 @@ namespace EgwControlCenter.App.Components.Compo ACService.ResetConf(); } - protected void DoSave() + protected async Task DoSave() { ACService.DoSaveConfig(); ACService.DoReloadConfig(); + // invio update in remoto + await ACService.SendConfTarget(); } protected override void OnInitialized() diff --git a/EgwControlCenter.App/ConfPatrol.json b/EgwControlCenter.App/ConfPatrol.json index 7a31831..58394de 100644 --- a/EgwControlCenter.App/ConfPatrol.json +++ b/EgwControlCenter.App/ConfPatrol.json @@ -11,32 +11,36 @@ "BasePath": "C:\\Steamware", "SearchPattern": "IOB-*.exe", "IsEnabled": true, - "UpdateEnabled": true + "UpdateEnabled": true, }, { "Idx": 2, "ApplicationType": "Machine", "BasePath": "C:\\EgtData\\Machines", - "IsEnabled": true + "IsEnabled": true, + "UpdateEnabled": false }, { "Idx": 3, "ApplicationType": "Machine", "BasePath": "C:\\TechnoEssetre7\\EgalTech\\EgtCAM5\\Machines", - "IsEnabled": true + "IsEnabled": true, + "UpdateEnabled": false }, { "Idx": 4, "ApplicationType": "Machine", "BasePath": "C:\\Testing\\Machines", - "IsEnabled": true + "IsEnabled": true, + "UpdateEnabled": false }, { "Idx": 5, "ApplicationType": "LicenceApp", "BasePath": "C:\\EgtData", "SearchPattern": "*.ini", - "IsEnabled": true + "IsEnabled": true, + "UpdateEnabled": false } ] } diff --git a/EgwControlCenter.App/EgwControlCenter.App.csproj b/EgwControlCenter.App/EgwControlCenter.App.csproj index 65044da..9449322 100644 --- a/EgwControlCenter.App/EgwControlCenter.App.csproj +++ b/EgwControlCenter.App/EgwControlCenter.App.csproj @@ -5,7 +5,7 @@ enable true enable - 1.2.2501.2016 + 1.2.2501.2111 Debug;Release;DEBUG_Local diff --git a/EgwControlCenter.App/Properties/PublishProfiles/ClickOnceProfile.pubxml b/EgwControlCenter.App/Properties/PublishProfiles/ClickOnceProfile.pubxml index bd7e09c..b673e0d 100644 --- a/EgwControlCenter.App/Properties/PublishProfiles/ClickOnceProfile.pubxml +++ b/EgwControlCenter.App/Properties/PublishProfiles/ClickOnceProfile.pubxml @@ -4,8 +4,8 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - 2016 - 1.2.2501.2016 + 2111 + 1.2.2501.2111 True Release True diff --git a/EgwControlCenter.Core/AppControlService.cs b/EgwControlCenter.Core/AppControlService.cs index 087984d..33baa1b 100644 --- a/EgwControlCenter.Core/AppControlService.cs +++ b/EgwControlCenter.Core/AppControlService.cs @@ -38,8 +38,8 @@ namespace EgwControlCenter.Core { try { - Assembly assembly = Assembly.GetExecutingAssembly(); - string startDir = Path.GetDirectoryName(assembly.Location)!; + mainAssembly = Assembly.GetCallingAssembly(); + string startDir = Path.GetDirectoryName(mainAssembly.Location)!; ConfDir = startDir; CodImpiego = SLicManager.CodImpiego(); // setup RuntimConf (da gestire anche con set remoto...) @@ -291,6 +291,7 @@ namespace EgwControlCenter.Core CloudCallActive = false; return tVal; } + /// /// Chiamata verifica attivazioni /// @@ -395,6 +396,7 @@ namespace EgwControlCenter.Core public async Task DoTaskCheckAsync(bool doForce) { Stopwatch sw = new Stopwatch(); + sw.Start(); DateTime adesso = DateTime.Now; bool sendStats = false; if (vetoTaskCheck < adesso || doForce || numFastCheck > 0) @@ -409,6 +411,7 @@ namespace EgwControlCenter.Core var task2exe = await CurrCheck.TaskGetReq(DeviceName); if (task2exe != null && task2exe.Count > 0) { + CloudCallActive = true; // 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... @@ -434,6 +437,7 @@ namespace EgwControlCenter.Core // invio risposta esito esecuzione finale await CurrCheck.TaskSetDone(DeviceName, taskResults); sendStats = true; + CloudCallActive = false; } // imposto veto controlli task vetoTaskCheck = adesso.AddSeconds(vetoSec); @@ -534,14 +538,67 @@ namespace EgwControlCenter.Core ReportConfigUpd(); } + /// + /// Invia info configurazione (directory) + /// + /// + public async Task SendConfTarget() + { + // preparo un task di conf da inviare + var task2send = new Dictionary(); + string rawConf = JsonConvert.SerializeObject(CurrCheck.CurrPatrolCont.TargetList); + task2send.Add("TargetList", rawConf); + await CurrCheck.TaskSetDone(DeviceName, task2send); + } + + /// + /// Invia info licenza (se disponibili) + /// + /// + public async Task SendLicInfo() + { + if (CurrCheck.LicenceFilesDict.Count > 0) + { + // serializzo risultato + string rawData = JsonConvert.SerializeObject(CurrCheck.LicenceFilesDict); + Dictionary licInfo = new Dictionary(); + // chiave: LicInfo + licInfo.Add("LicInfo", rawData); + // invio! + await CurrCheck.TaskSetDone(DeviceName, licInfo); + } + } + + /// + /// Invia info di reboot effettuato (spostando da req/run a done...) + /// + /// + public async Task SendRebooted() + { + // preparo un task di reboot da inviare + var task2send = new Dictionary(); + task2send.Add("ExecStart", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}"); + await CurrCheck.TaskSetRunning(DeviceName, task2send); + await Task.Delay(500); + await CurrCheck.TaskSetDone(DeviceName, task2send); + } + + /// + /// Invia info satats preliminari + /// + /// + public async Task SendStats() + { + // invio statistiche esecuzione... + await DoSendRunStats(); + } + #endregion Public Methods #region Protected Fields protected string DeviceName = ""; - protected UpdateMan updateMan = new UpdateMan(); - protected UpdateMan updateManAuth = new UpdateMan("SWDownloader", "viaD@nte16"); #endregion Protected Fields @@ -599,7 +656,7 @@ namespace EgwControlCenter.Core // serializzo risultato string rawData = JsonConvert.SerializeObject(CurrCheck.LicenceFilesDict); Dictionary licInfo = new Dictionary(); - // chiave: LicInfo + // chiave: LicInfo licInfo.Add("LicInfo", rawData); // invio! await CurrCheck.TaskSetDone(DeviceName, licInfo); @@ -613,10 +670,13 @@ namespace EgwControlCenter.Core protected async Task DoSendRunStats() { // recupero statistiche - var statsData = StatsCollector.CurrentInfo(); + Dictionary statsData = StatsCollector.CurrentInfo(); + // aggiungo versione alle statistiche + statsData.Add("Version", $"{mainAssembly.GetName().Version}"); + //serializzo string rawData = JsonConvert.SerializeObject(statsData); Dictionary statsInfo = new Dictionary(); - // chiave: RunStats + // chiave: RunStats statsInfo.Add("RunStats", rawData); // invio! await CurrCheck.TaskSetDone(DeviceName, statsInfo); @@ -641,6 +701,8 @@ namespace EgwControlCenter.Core /// private DateTime lastCheckDone = DateTime.Today.AddMonths(-1); + private Assembly mainAssembly = Assembly.GetExecutingAssembly(); + /// /// Numero di controlli fast (5 sec medi) dei task prima di tornare alla gestione lenta (2 min) /// @@ -815,25 +877,23 @@ namespace EgwControlCenter.Core case CoreEnum.EgwAccTask.DeviceInfoGet: Dictionary currDevInfo = DeviceInfoDict(); - taskVal = JsonConvert.SerializeObject(currDevInfo, Formatting.Indented); + taskVal = JsonConvert.SerializeObject(currDevInfo); break; case CoreEnum.EgwAccTask.ForceCheck: - Dictionary fcDetail = new Dictionary(); - fcDetail.Add("ExecStart", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}"); + Dictionary fcRes = new Dictionary(); + fcRes.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); + fcRes.Add("Completed", $"App Check done in {sw.Elapsed.TotalMilliseconds:N0}ms"); + taskVal = JsonConvert.SerializeObject(fcRes); break; case CoreEnum.EgwAccTask.ForceReload: - Dictionary fcReload = new Dictionary(); - fcReload.Add("ExecReload", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}"); + Dictionary frRes = new Dictionary(); + frRes.Add("ExecReload", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}"); sw.Stop(); - // mando subito conferma esecuzione... - fcReload.Add("ExecReload", $"Reload Requested..."); - taskVal = JsonConvert.SerializeObject(fcReload, Formatting.Indented); + taskVal = JsonConvert.SerializeObject(frRes); // sollevo evento if (EA_ReloadRequested != null) { @@ -842,11 +902,11 @@ namespace EgwControlCenter.Core break; case CoreEnum.EgwAccTask.ForceUpdate: - Dictionary fcUpdate = new Dictionary(); - fcUpdate.Add("ExecStart", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}"); + Dictionary fuRes = new Dictionary(); + fuRes.Add("ExecStart", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}"); sw.Stop(); // mando subito conferma esecuzione... - taskVal = JsonConvert.SerializeObject(fcUpdate, Formatting.Indented); + taskVal = JsonConvert.SerializeObject(fuRes); // sollevo evento if (EA_RestartRequested != null) { @@ -855,7 +915,12 @@ namespace EgwControlCenter.Core break; case CoreEnum.EgwAccTask.OxyLicenseGet: + Dictionary olgRes = new Dictionary(); await DoSendLicInfo(); + sw.Stop(); + // mando subito conferma esecuzione... + olgRes.Add("LicInfoCompleted", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}"); + taskVal = JsonConvert.SerializeObject(olgRes); break; //case CoreEnum.EgwAccTask.ParamDictReset: @@ -864,6 +929,32 @@ namespace EgwControlCenter.Core //case CoreEnum.EgwAccTask.ParamUpsert: // break; + case CoreEnum.EgwAccTask.TargetListUpsert: + // verifico se nel payload c'รจ la configurazione VALIDA... + if (string.IsNullOrEmpty(item.Value)) + { + taskVal = "Error: empty Payload"; + } + else + { + // provo a deserializzare oggetto + var newTargetList = JsonConvert.DeserializeObject>(item.Value); + if (newTargetList == null || newTargetList.Count == 0) + { + taskVal = "Error: empty List"; + } + else + { + // se valido sovrascrivo e salvo! + CurrCheck.CurrPatrolCont.TargetList = newTargetList; + CurrCheck.SaveConfig(); + // ... invio versione aggiornata + await Task.Delay(100); + await SendConfTarget(); + } + } + break; + case CoreEnum.EgwAccTask.ND: default: taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC"; diff --git a/EgwControlCenter.Core/CoreEnum.cs b/EgwControlCenter.Core/CoreEnum.cs index a0fb9a6..8f77e79 100644 --- a/EgwControlCenter.Core/CoreEnum.cs +++ b/EgwControlCenter.Core/CoreEnum.cs @@ -21,6 +21,7 @@ namespace EgwControlCenter.Core /// /// Elenco tipi di azioni che si possono chiedere ad EgwACC /// + [JsonConverter(typeof(StringEnumConverter))] public enum EgwAccTask { /// @@ -66,7 +67,12 @@ namespace EgwControlCenter.Core /// /// Upsert di parametri operativi (gestiti in remoto) /// - ParamUpsert + ParamUpsert, + + /// + /// Upsert valori TargetList (gestiti in remoto) + /// + TargetListUpsert } public enum TipoLicenza diff --git a/EgwControlCenter.Core/ReleaseChecker.cs b/EgwControlCenter.Core/ReleaseChecker.cs index 163468b..01b9f60 100644 --- a/EgwControlCenter.Core/ReleaseChecker.cs +++ b/EgwControlCenter.Core/ReleaseChecker.cs @@ -105,6 +105,11 @@ namespace EgwControlCenter.Core /// public PatrolSettings CurrPatrolCont { get; set; } = new PatrolSettings(); + /// + /// Dizionario files licenze trovati + /// + public Dictionary LicenceFilesDict { get; set; } = new Dictionary(); + /// /// Elenco degli oggetti stato dei programmi monitorati /// @@ -579,6 +584,18 @@ namespace EgwControlCenter.Core return taskReq; } + /// + /// Invia un dizionario di task completato (x richieste o salvataggio da EgwACC) + /// + /// + /// + public async Task TaskSetDone(string devName, Dictionary taskRes) + { + string answ = await TaskPostInfo(devName, taskRes, "done"); + return answ; + } + /// /// Invia un dizionario che dovrebbe comprendere tutte le richieste task 8da chiudere) + eventuali altri dati da salvare /// @@ -592,60 +609,108 @@ namespace EgwControlCenter.Core } /// - /// Metodo effettivo invio post info sul task + /// Aggiorna info files licenza (se configurato e se trovate) /// - /// - /// + /// /// - private async Task TaskPostInfo(string devName, Dictionary taskRes, string action) + public bool UpdateLicenceInfo() { - string answ = ""; - try + /*------------------------------------------- + * Ricerca licenze: algoritmo + * - parte da un percorso di base + * - cerca x ogni cartella la sottocartella /Config/ i files *.ini + * - prende i files che contengono "Licence=" + * - considera solo i file con valore valido x Licence + * - prende il relativo file *.lic indicato (stessa folder) + * - legge e riporta intero contenuto nel record dizionario: + * - chiave = percorso file *.lic + * - valore = contenuto file + *-------------------------------------------*/ + + bool fatto = false; + // nuovo obj licenze... + Dictionary newLicDict = new Dictionary(); + // ciclo SOLO gli oggetti licenza info + var licTgt = CurrPatrolCont + .TargetList + .Where(x => x.ApplicationType == CoreEnum.AppType.LicenceApp) + .ToList(); + int numFound = 0; + foreach (var item in licTgt) { - // preparo richiesta... - TaskResultDTO currReq = new TaskResultDTO() + try { - AppKey = CurrPatrolCont.AppKey, - CodImp = CodImpiego, - MastKey = "", - DataPayload = taskRes - }; - // client chiamate rest - var client = new RestClient(restOptStd); - // Chiamo il metodo! - 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) - { - answ = $"{currResp.Content}"; + // verifico contenuto secondo tipo + if (item != null && item.IsEnabled) + { + // processo la folder indicata e cerco tutte le macchine contenute + if (Directory.Exists(item.BasePath)) + { + // recupero elenco sottodirectory = possibili conf applicativi + var dirList = Directory.GetDirectories(item.BasePath); + // ciclo x cercare i files... + foreach (var currDir in dirList) + { + string prgName = Path.GetFileName(currDir); + // compongo ricerca della cartella Config dentro la folder target + string confPath = Path.Combine(currDir, "Config"); + // verifico se esiste directory... + if (Directory.Exists(confPath)) + { + // cerco se ci sia un file di quelli richiesti... + var fileFound = Directory.GetFiles(confPath, item.SearchPattern); + if (fileFound != null && fileFound.Count() > 0) + { + // ciclo su tutti i file candidati... + foreach (var file in fileFound) + { + // vincolo dei soli file con nome uguale alla folder ancestor... + string iniName = Path.GetFileName(file); + if (iniName.ToLower().StartsWith($"{prgName.ToLower()}.")) + { + string licName = LicSearchFileName(file); + if (!string.IsNullOrEmpty(licName)) + { + var contDir = Path.GetDirectoryName(file); + if (!string.IsNullOrEmpty(contDir)) + { + string licPath = Path.Combine(contDir, licName); + if (File.Exists(licPath)) + { + // leggo il contenuto e salvo... + var licContent = File.ReadAllText(licPath); + if (!newLicDict.ContainsKey(licPath)) + { + newLicDict.Add(licPath, licContent); + numFound++; + } + else + { + newLicDict[licPath] = licContent; + } + } + } + } + } + } + } + } + } + } + } } - else + catch (Exception exc) { - Log.Error($"Errore in ricezione REST services TaskPostInfo | action: {action} | statusCode{currResp.StatusCode} | content: {currResp.Content}"); + Log.Error($"Eccezione in UpdateLicenceInfo{Environment.NewLine}{exc}"); } } - catch (Exception exc) - { - Log.Error($"Eccezione in fase gestione REST services TaskPostInfo | action: {action}{Environment.NewLine}{exc}"); - } + // aggiorno obj... + LicenceFilesDict = newLicDict; + // salvo info licenze... + SaveLicDict(); + fatto = numFound > 0; - return answ; - } - - /// - /// Invia un dizionario di task completato (x richieste o salvataggio da EgwACC) - /// - /// - /// - public async Task TaskSetDone(string devName, Dictionary taskRes) - { - string answ = await TaskPostInfo(devName, taskRes, "done"); - return answ; + return fatto; } /// @@ -675,7 +740,6 @@ namespace EgwControlCenter.Core { switch (item.ApplicationType) { - case CoreEnum.AppType.Machine: // processo la folder indicata e cerco tutte le macchine contenute if (Directory.Exists(item.BasePath)) @@ -786,145 +850,6 @@ namespace EgwControlCenter.Core return fatto; } - /// - /// Aggiorna info files licenza (se configurato e se trovate) - /// - /// - /// - public bool UpdateLicenceInfo() - { - /*------------------------------------------- - * Ricerca licenze: algoritmo - * - parte da un percorso di base - * - cerca x ogni cartella la sottocartella /Config/ i files *.ini - * - prende i files che contengono "Licence=" - * - considera solo i file con valore valido x Licence - * - prende il relativo file *.lic indicato (stessa folder) - * - legge e riporta intero contenuto nel record dizionario: - * - chiave = percorso file *.lic - * - valore = contenuto file - *-------------------------------------------*/ - - bool fatto = false; - // nuovo obj licenze... - Dictionary newLicDict = new Dictionary(); - // ciclo SOLO gli oggetti licenza info - var licTgt = CurrPatrolCont - .TargetList - .Where(x => x.ApplicationType == CoreEnum.AppType.LicenceApp) - .ToList(); - int numFound = 0; - foreach (var item in licTgt) - { - try - { - // verifico contenuto secondo tipo - if (item != null && item.IsEnabled) - { - // processo la folder indicata e cerco tutte le macchine contenute - if (Directory.Exists(item.BasePath)) - { - // recupero elenco sottodirectory = possibili conf applicativi - var dirList = Directory.GetDirectories(item.BasePath); - // ciclo e cerco i file mlde... - foreach (var currDir in dirList) - { - // compongo ricerca della cartella Config dentro la folder target - string confPath = Path.Combine(currDir, "Config"); - // verifico se esiste directory... - if (Directory.Exists(confPath)) - { - // cerco se ci sia un file mlde... - var fileFound = Directory.GetFiles(confPath, item.SearchPattern); - if (fileFound != null && fileFound.Count() > 0) - { - // ciclo su tutti i file candidati... - foreach (var file in fileFound) - { - string licName = LicSearchFileName(file); - if (!string.IsNullOrEmpty(licName)) - { - var contDir = Path.GetDirectoryName(file); - if (!string.IsNullOrEmpty(contDir)) - { - string licPath = Path.Combine(contDir, licName); - if (File.Exists(licPath)) - { - numFound++; - // leggo il contenuto e salvo... - var licContent = File.ReadAllText(licPath); - if (!newLicDict.ContainsKey(licPath)) - { - newLicDict.Add(licPath, licContent); - } - else - { - newLicDict[licPath] = licContent; - } - } - } - } - } - } - } - } - } - } - } - catch (Exception exc) - { - Log.Error($"Eccezione in UpdateLicenceInfo{Environment.NewLine}{exc}"); - } - } - // aggiorno obj... - LicenceFilesDict = newLicDict; - // salvo info licenze... - SaveLicDict(); - fatto = numFound > 0; - - return fatto; - } - - /// - /// Processa il file ini (se esistente) cercando file licenza e se lo trova restituisce il nome del file... - /// - /// File ini da processare - /// max num di linee da verificare - /// - private string LicSearchFileName(string iniPath, int maxLines = 20) - { - string answ = ""; - string licToken = "Licence="; - if (File.Exists(iniPath)) - { - try - { - using (StreamReader reader = new StreamReader(iniPath)) - { - for (int i = 0; i < maxLines; i++) - { - if (reader.EndOfStream) - break; - - var line = reader.ReadLine(); - if (!string.IsNullOrEmpty(line)) - { - if (line.Contains(licToken)) - { - answ = line.Replace(licToken, "").Trim(); - } - } - } - } - } - catch (Exception ex) - { - Log.Error($"Error during LicSearchFileName: {Environment.NewLine}{ex}"); - } - } - return answ; - } - #endregion Public Methods #region Protected Properties @@ -940,11 +865,6 @@ namespace EgwControlCenter.Core /// protected List ListStatus { get; set; } = new List(); - /// - /// Dizionario files licenze trovati - /// - public Dictionary LicenceFilesDict { get; set; } = new Dictionary(); - #endregion Protected Properties #region Private Fields @@ -989,7 +909,9 @@ namespace EgwControlCenter.Core private string CodImpiego { get; set; } = ""; private string ConfName { get; set; } = ""; + private Dictionary CriticalRelCurrent { get; set; } = new Dictionary(); + private string DataDir { get; set; } = ""; /// @@ -1001,8 +923,20 @@ namespace EgwControlCenter.Core } private string ERName { get; set; } = "EnrollReq.json"; - private string LSName { get; set; } = "LastStatus.json"; + + /// + /// Path file salvataggio LicenceInfo + /// + private string LicInfoPath + { + get => Path.Combine(DataDir, LIName); + //get => Path.Combine(ApplicationDeployment.CurrentDeployment.DataDirectory, LSName); + } + private string LIName { get; set; } = "LicInfo.json"; + + private string LSName { get; set; } = "LastStatus.json"; + private SubLicManager SLicManager { get; set; } = new SubLicManager(); /// @@ -1012,14 +946,6 @@ namespace EgwControlCenter.Core { get => Path.Combine(DataDir, LSName); } - /// - /// Path file salvataggio LicenceInfo - /// - private string LicInfoPath - { - get => Path.Combine(DataDir, LIName); - //get => Path.Combine(ApplicationDeployment.CurrentDeployment.DataDirectory, LSName); - } #endregion Private Properties @@ -1311,6 +1237,46 @@ namespace EgwControlCenter.Core ReloadData(); } + /// + /// Processa il file ini (se esistente) cercando file licenza e se lo trova restituisce il nome del file... + /// + /// File ini da processare + /// max num di linee da verificare + /// + private string LicSearchFileName(string iniPath, int maxLines = 20) + { + string answ = ""; + string licToken = "Licence="; + if (File.Exists(iniPath)) + { + try + { + using (StreamReader reader = new StreamReader(iniPath)) + { + for (int i = 0; i < maxLines; i++) + { + if (reader.EndOfStream) + break; + + var line = reader.ReadLine(); + if (!string.IsNullOrEmpty(line)) + { + if (line.Contains(licToken)) + { + answ = line.Replace(licToken, "").Trim(); + } + } + } + } + } + catch (Exception ex) + { + Log.Error($"Error during LicSearchFileName: {Environment.NewLine}{ex}"); + } + } + return answ; + } + /// /// Recupera oggetto releaseDTO da file indicato /// @@ -1403,6 +1369,27 @@ namespace EgwControlCenter.Core ListStatus = JsonConvert.DeserializeObject>(rawData) ?? new List(); } } + // cerco se presente file licInfo e lo ricarico... + if (File.Exists(LicInfoPath)) + { + var rawData = File.ReadAllText(LicInfoPath); + if (!string.IsNullOrEmpty(rawData)) + { + LicenceFilesDict = JsonConvert.DeserializeObject>(rawData) ?? new Dictionary(); + } + } + } + + /// + /// Effettua salvataggio obj status + /// + private void SaveLicDict() + { + var rawData = JsonConvert.SerializeObject(LicenceFilesDict, Formatting.Indented); + if (rawData != null && rawData.Length > 2) + { + File.WriteAllText(LicInfoPath, rawData); + } } /// @@ -1433,15 +1420,48 @@ namespace EgwControlCenter.Core } /// - /// Effettua salvataggio obj status + /// Metodo effettivo invio post info sul task /// - private void SaveLicDict() + /// + /// + /// + private async Task TaskPostInfo(string devName, Dictionary taskRes, string action) { - var rawData = JsonConvert.SerializeObject(LicenceFilesDict, Formatting.Indented); - if (rawData != null && rawData.Length > 2) + string answ = ""; + try { - File.WriteAllText(LicInfoPath, rawData); + // preparo richiesta... + TaskResultDTO currReq = new TaskResultDTO() + { + AppKey = CurrPatrolCont.AppKey, + CodImp = CodImpiego, + MastKey = "", + DataPayload = taskRes + }; + // client chiamate rest + var client = new RestClient(restOptStd); + // Chiamo il metodo! + 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) + { + answ = $"{currResp.Content}"; + } + else + { + 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 TaskPostInfo | action: {action}{Environment.NewLine}{exc}"); + } + + return answ; } #endregion Private Methods diff --git a/EgwControlCenter.Core/StatsCollector.cs b/EgwControlCenter.Core/StatsCollector.cs index 5394770..6210844 100644 --- a/EgwControlCenter.Core/StatsCollector.cs +++ b/EgwControlCenter.Core/StatsCollector.cs @@ -47,8 +47,6 @@ namespace EgwControlCenter.Core public static Dictionary CurrentInfo() { Dictionary result = new Dictionary(); - // in primis metto uptime - result.Add("Uptime", UptimeCurr); // ciclo sugli oggetti calcolando durate e ultima call foreach (var item in Counter) { @@ -56,7 +54,9 @@ namespace EgwControlCenter.Core result.Add(item.Key, sRec); result.Add($"{item.Key}Last", $"{LastCall[item.Key]:yyyy-MM-dd HH:mm:ss}"); } - + // infine metto stata avvio e uptime + result.Add("Startup", $"{StartTime:yyyy-MM-dd HH:mm:ss}"); + result.Add("Uptime", UptimeCurr); return result; } @@ -69,13 +69,6 @@ namespace EgwControlCenter.Core Counter = new ConcurrentDictionary(); Duration = new ConcurrentDictionary(); LastCall = new ConcurrentDictionary(); -#if false - foreach (var value in Counter) - { - Duration[value.Key] = new TimeSpan(0); - Counter[value.Key] = 0; - } -#endif } /// @@ -149,15 +142,15 @@ namespace EgwControlCenter.Core // formatto secondo durata if (ts.Milliseconds < 1) { - answ = $"{ts.TotalMilliseconds:N3} ms"; + answ = $"{ts.TotalMilliseconds:N3} ns"; } - if (ts.TotalSeconds < 1) + else if (ts.TotalSeconds < 1) { - answ = $"{ts.TotalMilliseconds:N3} ms"; + answ = $"{ts.TotalMilliseconds:N1} ms"; } else if (ts.TotalSeconds < 300) { - answ = $"{ts.TotalSeconds:N3} sec"; + answ = $"{ts.TotalSeconds:N1} sec"; } else {