From 7a7a8c0bf86f07d01388e5c88c3533b926b0d7bb Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 18 Sep 2024 12:32:25 +0200 Subject: [PATCH 1/7] Continuo aggiunta WinFormx controllo versioni in tray --- EgwControlCenter.Core/Enum.cs | 16 --------- EgwControlCenter.Core/PatrolSettings.cs | 14 ++++++++ EgwControlCenter/AccEnum.cs | 10 ++++++ EgwControlCenter/ControlCenter.Designer.cs | 38 ++++++++++++++-------- EgwControlCenter/ControlCenter.cs | 14 ++++++++ 5 files changed, 63 insertions(+), 29 deletions(-) delete mode 100644 EgwControlCenter.Core/Enum.cs create mode 100644 EgwControlCenter.Core/PatrolSettings.cs diff --git a/EgwControlCenter.Core/Enum.cs b/EgwControlCenter.Core/Enum.cs deleted file mode 100644 index d36c109..0000000 --- a/EgwControlCenter.Core/Enum.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace EgwControlCenter.Core -{ - public class Enum - { - /// - /// Elenco tipi app ammessi - /// - public static Dictionary AppType = new Dictionary{ - { "", "---Selezionare---" }, - { "Cli", "Cli (Console)" }, - { "Machine", "Machine" }, - { "WebApp", "WebApp" }, - { "WinApp", "WinApp" } - }; - } -} diff --git a/EgwControlCenter.Core/PatrolSettings.cs b/EgwControlCenter.Core/PatrolSettings.cs new file mode 100644 index 0000000..0ce2ce3 --- /dev/null +++ b/EgwControlCenter.Core/PatrolSettings.cs @@ -0,0 +1,14 @@ +using EgwControlCenter.Core.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EgwControlCenter.Core +{ + public class PatrolSettings + { + public List TargetList { get; set; } = new List(); + } +} diff --git a/EgwControlCenter/AccEnum.cs b/EgwControlCenter/AccEnum.cs index 88a21e8..46cfc05 100644 --- a/EgwControlCenter/AccEnum.cs +++ b/EgwControlCenter/AccEnum.cs @@ -25,5 +25,15 @@ namespace EgwControlCenter /// UPD = 2 } + /// + /// Elenco tipi app ammessi + /// + public static Dictionary AppType = new Dictionary{ + { "", "---Selezionare---" }, + { "Cli", "Cli (Console)" }, + { "Machine", "Machine" }, + { "WebApp", "WebApp" }, + { "WinApp", "WinApp" } + }; } } diff --git a/EgwControlCenter/ControlCenter.Designer.cs b/EgwControlCenter/ControlCenter.Designer.cs index 28d3db6..1e1462e 100644 --- a/EgwControlCenter/ControlCenter.Designer.cs +++ b/EgwControlCenter/ControlCenter.Designer.cs @@ -32,9 +32,10 @@ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ControlCenter)); label1 = new Label(); label2 = new Label(); - label3 = new Label(); trayMenu = new ContextMenuStrip(components); notifyIcon1 = new NotifyIcon(components); + btnSetup = new Button(); + txtAuth = new TextBox(); SuspendLayout(); // // label1 @@ -56,19 +57,10 @@ label2.TabIndex = 1; label2.Text = "Elenco App (list? webview?)"; // - // label3 - // - label3.AutoSize = true; - label3.Location = new Point(484, 83); - label3.Name = "label3"; - label3.Size = new Size(156, 15); - label3.TabIndex = 2; - label3.Text = "Btn setup app da controllare"; - // // trayMenu // trayMenu.Name = "trayMenu"; - trayMenu.Size = new Size(181, 26); + trayMenu.Size = new Size(61, 4); trayMenu.ItemClicked += trayMenu_ItemClicked; // // notifyIcon1 @@ -79,12 +71,31 @@ notifyIcon1.Visible = true; notifyIcon1.DoubleClick += notifyIcon1_DoubleClick; // + // btnSetup + // + btnSetup.Location = new Point(699, 77); + btnSetup.Name = "btnSetup"; + btnSetup.Size = new Size(75, 23); + btnSetup.TabIndex = 3; + btnSetup.Text = "Setup"; + btnSetup.UseVisualStyleBackColor = true; + btnSetup.Click += btnSetup_Click; + // + // txtAuth + // + txtAuth.Location = new Point(593, 77); + txtAuth.Name = "txtAuth"; + txtAuth.PasswordChar = '*'; + txtAuth.Size = new Size(100, 23); + txtAuth.TabIndex = 4; + // // ControlCenter // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); - Controls.Add(label3); + Controls.Add(txtAuth); + Controls.Add(btnSetup); Controls.Add(label2); Controls.Add(label1); Icon = (Icon)resources.GetObject("$this.Icon"); @@ -101,8 +112,9 @@ private Label label1; private Label label2; - private Label label3; private ContextMenuStrip trayMenu; private NotifyIcon notifyIcon1; + private Button btnSetup; + private TextBox txtAuth; } } diff --git a/EgwControlCenter/ControlCenter.cs b/EgwControlCenter/ControlCenter.cs index 7c96d97..11658db 100644 --- a/EgwControlCenter/ControlCenter.cs +++ b/EgwControlCenter/ControlCenter.cs @@ -188,5 +188,19 @@ namespace EgwControlCenter } #endregion Private Methods + + private void btnSetup_Click(object sender, EventArgs e) + { + //verifico passphrase + if (txtAuth.Text == "24068Seriate") + { + TargetSetup tgtForm = new TargetSetup(); + tgtForm.Show(); + } + else + { + txtAuth.Text = ""; + } + } } } \ No newline at end of file From abf15345e4e47917851bd946907bfa818e026f91 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 18 Sep 2024 18:51:41 +0200 Subject: [PATCH 2/7] Ok fase check locale + check remoto... --- EgwControlCenter.Core/CoreEnum.cs | 21 ++ .../EgwControlCenter.Core.csproj | 6 + EgwControlCenter.Core/Models/ControlTarget.cs | 15 +- EgwControlCenter.Core/Models/ReleaseDTO.cs | 79 ++++ EgwControlCenter.Core/Models/TargetStatus.cs | 64 ++++ EgwControlCenter.Core/ReleaseChecker.cs | 350 ++++++++++++++++++ EgwControlCenter/App.config | 2 +- EgwControlCenter/Conf/.placeholder | 1 + EgwControlCenter/Conf/ConfPatrol.json | 9 + EgwControlCenter/ControlCenter.Designer.cs | 38 +- EgwControlCenter/ControlCenter.cs | 199 ++++++---- EgwControlCenter/EgwControlCenter.csproj | 9 + 12 files changed, 696 insertions(+), 97 deletions(-) create mode 100644 EgwControlCenter.Core/CoreEnum.cs create mode 100644 EgwControlCenter.Core/Models/ReleaseDTO.cs create mode 100644 EgwControlCenter.Core/Models/TargetStatus.cs create mode 100644 EgwControlCenter.Core/ReleaseChecker.cs create mode 100644 EgwControlCenter/Conf/.placeholder create mode 100644 EgwControlCenter/Conf/ConfPatrol.json diff --git a/EgwControlCenter.Core/CoreEnum.cs b/EgwControlCenter.Core/CoreEnum.cs new file mode 100644 index 0000000..9668e05 --- /dev/null +++ b/EgwControlCenter.Core/CoreEnum.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EgwControlCenter.Core +{ + public class CoreEnum + { + + public enum AppType + { + None, + Cli, + Machine, + WebApp, + WinApp + } + } +} diff --git a/EgwControlCenter.Core/EgwControlCenter.Core.csproj b/EgwControlCenter.Core/EgwControlCenter.Core.csproj index fa71b7a..8d46b1c 100644 --- a/EgwControlCenter.Core/EgwControlCenter.Core.csproj +++ b/EgwControlCenter.Core/EgwControlCenter.Core.csproj @@ -6,4 +6,10 @@ enable + + + + + + diff --git a/EgwControlCenter.Core/Models/ControlTarget.cs b/EgwControlCenter.Core/Models/ControlTarget.cs index 008e4c0..e24f0a4 100644 --- a/EgwControlCenter.Core/Models/ControlTarget.cs +++ b/EgwControlCenter.Core/Models/ControlTarget.cs @@ -1,8 +1,10 @@ -using System; +using Newtonsoft.Json.Converters; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; +using System.Text.Json.Serialization; using System.Threading.Tasks; namespace EgwControlCenter.Core.Models @@ -11,7 +13,16 @@ namespace EgwControlCenter.Core.Models { [Key] public int Idx { get; set; } = 0; - public string ObjType { get; set; } = ""; + + /// + /// Tipo applicazione da monitorare + /// + [JsonConverter(typeof(StringEnumConverter))] + public CoreEnum.AppType ApplicationType{ get; set; } = CoreEnum.AppType.None; + + /// + /// Path di base da monitorare + /// public string BasePath { get; set; } = ""; } } diff --git a/EgwControlCenter.Core/Models/ReleaseDTO.cs b/EgwControlCenter.Core/Models/ReleaseDTO.cs new file mode 100644 index 0000000..ce4ad68 --- /dev/null +++ b/EgwControlCenter.Core/Models/ReleaseDTO.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EgwControlCenter.Core.Models +{ + public class ReleaseDTO + { + /// + /// Codice/Nome applicativo + /// + public string CodApp { get; set; } = ""; + + /// + /// Versione applicativo formato semver numerico 4 blocchi + /// + public string VersNum { get; set; } = "0.0.0.0"; + + /// + /// Versione applicativo, formato testuale libero, può essere uguale a VersNum + /// + public string VersText { get; set; } = "a.b"; + + /// + /// Oggetto versione calcolato da VersNum + /// + public Version VersVal + { + get + { + Version answ = new Version(); + try + { + // solo se è una versione valida: SemVer = 2/3 punti + int numPunti = VersNum.Length - VersNum.Replace(".", "").Length; + if (numPunti >= 2 && numPunti <= 3) + { + answ = !string.IsNullOrEmpty(VersNum) ? new Version(VersNum) : new Version(); + } + } + catch { } + return answ; + } + } + + /// + /// Verifica se sia permessa la versione quando viene valutata la versione massima consentita + /// + public bool IsPermitted { get; set; } = false; + + /// + /// Data di release + /// + public DateTime ReleaseDate { get; set; } = DateTime.Today.AddYears(100); + + /// + /// Tag associati a versione, comma separated + /// + public string RelTags { get; set; } = ""; + + /// + /// Url pagina web di changelog (traduzione gestita sul sito target) - calcolato da CodApp + vers + /// + public string UrlChangelog { get; set; } = "http://releases.egalware.com"; + + /// + /// Url pagina web di changelog estesa (traduzione gestita sul sito target) - calcolato da CodApp + vers + /// + public string UrlChangelogExt { get; set; } = "http://releases.egalware.com"; + + /// + /// Attivo/Pubblico (qui calcolato, attivo se la data di release è passata, poi potrebbe essere gestito a parte da DB) + /// + public bool IsActive { get; set; } = false; + } +} diff --git a/EgwControlCenter.Core/Models/TargetStatus.cs b/EgwControlCenter.Core/Models/TargetStatus.cs new file mode 100644 index 0000000..8f90757 --- /dev/null +++ b/EgwControlCenter.Core/Models/TargetStatus.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; + +namespace EgwControlCenter.Core.Models +{ + public class TargetStatus + { + #region Public Properties + + public string CodApp { get; set; } = ""; + + /// + /// Release locale (es Macchine: come letta da file *.mlde) + /// + public ReleaseDTO CurrLocal { get; set; } = new ReleaseDTO(); + + /// + /// DataOra ultima verifica locale + /// + public DateTime LastUpdateLoc { get; set; } = DateTime.Now; + + /// + /// DataOra ultima verifica remota + /// + public DateTime LastUpdateRem { get; set; } = DateTime.Now; + + /// + /// Elenco release remote da REST service + /// + public List ListRemote { get; set; } = new List(); + + #endregion Public Properties + + #region Public Methods + + /// + /// Calcolo condizione "ci sono update": + /// - almeno 1 rel remota + /// - la rel remota "+ recente" / + alta > rel locale + /// + /// + public bool HasUpdate() + { + bool answ = false; + if (ListRemote != null && ListRemote.Count > 0) + { + // prendo max release + var lastRemote = ListRemote.OrderByDescending(x => x.VersVal).FirstOrDefault(); + //devo averla trovata... + if (lastRemote != null) + { + answ = lastRemote.VersVal > CurrLocal.VersVal; + } + } + return answ; + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/EgwControlCenter.Core/ReleaseChecker.cs b/EgwControlCenter.Core/ReleaseChecker.cs new file mode 100644 index 0000000..d3d9dba --- /dev/null +++ b/EgwControlCenter.Core/ReleaseChecker.cs @@ -0,0 +1,350 @@ +using EgwControlCenter.Core.Models; +using Newtonsoft.Json; +using NLog; +using RestSharp; +using RestSharp.Serializers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EgwControlCenter.Core +{ + public class ReleaseChecker + { + #region Public Constructors + + public ReleaseChecker(string baseDir, string currConfig) + { + AppDir = baseDir; + ConfName = currConfig; + // verifico path... + if (string.IsNullOrEmpty(AppDir)) + { + AppDir = AppDomain.CurrentDomain.BaseDirectory; + } + if (File.Exists(ConfPath)) + { + var rawData = File.ReadAllText(ConfPath); + if (!string.IsNullOrEmpty(rawData)) + { + CurrPatrolCont = JsonConvert.DeserializeObject(rawData) ?? new PatrolSettings(); + } + } + // cerco se presente file status precedente e lo ricarico... + if (File.Exists(StatusPath)) + { + var rawData = File.ReadAllText(StatusPath); + if (!string.IsNullOrEmpty(rawData)) + { + ListStatus = JsonConvert.DeserializeObject>(rawData) ?? new List(); + } + } + } + + #endregion Public Constructors + + #region Public Properties + + /// + /// Elenco degli oggetti stato dei programmi monitorati + /// + public List ListStatus { get; set; } = new List(); + + protected static string apiUrl = "https://liman.egalware.com/ELM.Api/"; + + #endregion Public Properties + + #region Public Methods + + /// + /// Esegue verifica remota versioni x i sw tracciati + /// + /// + public async Task CheckCurrReleases() + { + // ciclo x ogni item da controllare + foreach (var item in ListStatus) + { + if (item.CurrLocal != null) + { + // verifico release da remoto aggiorno obj + var ListRem = GetRemoteRel(item.CurrLocal.CodApp, item.CurrLocal.VersNum); + if (ListRem != null) + { + item.ListRemote = ListRem; + item.LastUpdateRem = DateTime.Now; + } + } + } + // salvo status... + SaveStatus(); + } + + + private static List GetRemoteRel(string CodApp, string CurrVers) + { + List answ = new List(); + try + { + // client chiamate rest + var client = new RestClient(apiUrl); + string rawData = ""; + // Chiamo il metodo! + var checkRel = new RestRequest($"/api/Release/filt/{CodApp}?VersMin={CurrVers}", Method.Get); + //var listNextRel = new RestRequest($"/api/Release/filt/TestMachine?VersMin=1.1.0.0", Method.Get); + + // effettuo vera chiamata + var pUpd = Task.Run(async () => + { + var currResp = await client.GetAsync(checkRel); + if (currResp.StatusCode == System.Net.HttpStatusCode.OK && currResp.Content != null) + { + var currList = JsonConvert.DeserializeObject>(currResp.Content); + if (currList != null) + { + answ = currList; + } + } + }); + pUpd.Wait(); + } + catch (Exception exc) + { + Log.Error($"Eccezione in fase gestione REST services{Environment.NewLine}{exc}"); + } + + return answ; + } + + /// + /// Classe logger + /// + public static Logger Log = LogManager.GetCurrentClassLogger(); + + /// + /// Aggiorna (se necessario) lo stato degli oggetti da monitorare + /// + /// + /// + public bool UpdateLocalStatus(bool doRefresh) + { + bool fatto = false; + // se non forzato verifico file dello status salvato x necessità refresh + if (!doRefresh) + { + doRefresh = checkScaduto(); + } + // verifico se procedere... + if (doRefresh) + { + // nuovo obj controlli + List newListStatus = new List(); + // ciclo x ogni item da controllare + foreach (var item in CurrPatrolCont.TargetList) + { + // verifico contenuto secondo tipo + if (item != null) + { + switch (item.ApplicationType) + { + case CoreEnum.AppType.None: + break; + + case CoreEnum.AppType.Cli: + break; + + case CoreEnum.AppType.Machine: + // processo la folder indicata e cerco tutte le macchine contenute + if (Directory.Exists(item.BasePath)) + { + // recupero elenco sottodirectory = macchine + var dirList = Directory.GetDirectories(item.BasePath); + // ciclo e cerco i file mlde... + foreach (var currDir in dirList) + { + // cerco se ci sia un file mlde... + var fileFound = Directory.GetFiles(currDir, "*.mlde"); + if (fileFound != null && fileFound.Count() > 0) + { + // prendo il primo... + var tgtFile = fileFound.FirstOrDefault() ?? ""; + var currRelDto = MldeGetRelease(tgtFile); + if (currRelDto != null) + { + newListStatus.Add(new TargetStatus() + { + CodApp = currDir, + CurrLocal = currRelDto, + LastUpdateLoc = DateTime.Now + }); + } + } + } + } + + break; + + case CoreEnum.AppType.WebApp: + break; + + case CoreEnum.AppType.WinApp: + break; + + default: + break; + } + } + + // aggiungo oggetto TargetStatus + } + // aggiorno obj... + ListStatus = newListStatus; + // salvo status... + SaveStatus(); + fatto = true; + } + return fatto; + } + + #endregion Public Methods + + #region Private Properties + + private string AppDir { get; set; } = ""; + + /// + /// Periodo minimo per autorefresh versioni default 1 gg) + /// protected TimeSpan AutoRefreshVeto { get; set; } = TimeSpan.FromDays(1); + /// + private TimeSpan AutoRefreshVeto { get; set; } = TimeSpan.FromSeconds(30); + + private string ConfName { get; set; } = ""; + + /// + /// Path file di conf check + /// + private string ConfPath + { + get => Path.Combine(AppDir, ConfName); + } + + /// + /// Configurazione degli oggetti da monitorare + /// + protected PatrolSettings CurrPatrolCont { get; set; } = new PatrolSettings(); + + private string StatusName { get; set; } = "LastStatus.json"; + + /// + /// Path file salvataggio status + /// + private string StatusPath + { + get => Path.Combine(AppDir, StatusName); + } + + #endregion Private Properties + + #region Private Methods + + /// + /// Verifica se il check sia scaduto rispetto ad AutoRefreshVeto + /// + /// + private bool checkScaduto() + { + bool answ = false; + DateTime adesso = DateTime.Now; + // ciclo per ogni oggetto della lista... + foreach (var item in ListStatus) + { + if (item.LastUpdateLoc.Add(AutoRefreshVeto) < adesso) + { + answ = true; + // esco! + break; + } + } + return answ; + } + + /// + /// Recupera oggetto releaseDTO da file indicato + /// + /// + /// + private ReleaseDTO? MldeGetRelease(string filePath) + { + ReleaseDTO? answ = null; + if (File.Exists(filePath)) + { + string versNum = ""; + string versTxt = ""; + string codApp = ""; + // leggo una riga alla volta e cerco le chaivi + using (StreamReader reader = new StreamReader(filePath)) + { + string? line; + bool stop = false; + while ((line = reader.ReadLine()) != null && !stop) + { + if (line.StartsWith("PP_VER")) + { + // splitto e prendo secondo + var splitTxt = line.Split("="); + if (splitTxt.Length > 1) + { + versTxt = splitTxt[1].Trim().Replace("'", "").Trim(); + } + } + else if (line.StartsWith("PP_NVER")) + { + // splitto e prendo secondo + var splitTxt = line.Split("="); + if (splitTxt.Length > 1) + { + versNum = splitTxt[1].Trim().Replace("'", "").Trim(); + } + } + else if (line.StartsWith("MACH_NAME")) + { + // splitto e prendo secondo + var splitTxt = line.Split("="); + if (splitTxt.Length > 1) + { + codApp = splitTxt[1].Trim().Replace("'", "").Trim(); + } + } + // se ho trovato tutto esco! + stop = !string.IsNullOrEmpty(versNum) && !string.IsNullOrEmpty(versTxt) && !string.IsNullOrEmpty(codApp); + } + } + // creo OBJ e lo restituisco... + answ = new ReleaseDTO() + { + CodApp = codApp, + ReleaseDate = DateTime.Now, + VersNum = versNum, + VersText = versTxt + }; + } + return answ; + } + + /// + /// Effettua salvataggio obj status + /// + private void SaveStatus() + { + var rawData = JsonConvert.SerializeObject(ListStatus, Formatting.Indented); + if (rawData != null && rawData.Length > 2) + { + File.WriteAllText(StatusPath, rawData); + } + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/EgwControlCenter/App.config b/EgwControlCenter/App.config index 9fb6570..246180f 100644 --- a/EgwControlCenter/App.config +++ b/EgwControlCenter/App.config @@ -56,7 +56,7 @@ - + diff --git a/EgwControlCenter/Conf/.placeholder b/EgwControlCenter/Conf/.placeholder new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/EgwControlCenter/Conf/.placeholder @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/EgwControlCenter/Conf/ConfPatrol.json b/EgwControlCenter/Conf/ConfPatrol.json new file mode 100644 index 0000000..c150129 --- /dev/null +++ b/EgwControlCenter/Conf/ConfPatrol.json @@ -0,0 +1,9 @@ +{ + "TargetList": [ + { + "Idx": 1, + "ApplicationType": "Machine", + "BasePath": "C:\\Testing\\Machine" + } + ] +} diff --git a/EgwControlCenter/ControlCenter.Designer.cs b/EgwControlCenter/ControlCenter.Designer.cs index 1e1462e..043fbf9 100644 --- a/EgwControlCenter/ControlCenter.Designer.cs +++ b/EgwControlCenter/ControlCenter.Designer.cs @@ -35,7 +35,8 @@ trayMenu = new ContextMenuStrip(components); notifyIcon1 = new NotifyIcon(components); btnSetup = new Button(); - txtAuth = new TextBox(); + btnUpdate = new Button(); + lblOut = new Label(); SuspendLayout(); // // label1 @@ -73,28 +74,40 @@ // // btnSetup // - btnSetup.Location = new Point(699, 77); + btnSetup.Location = new Point(761, 23); btnSetup.Name = "btnSetup"; - btnSetup.Size = new Size(75, 23); + btnSetup.Size = new Size(27, 23); btnSetup.TabIndex = 3; - btnSetup.Text = "Setup"; + btnSetup.Text = "..."; btnSetup.UseVisualStyleBackColor = true; btnSetup.Click += btnSetup_Click; // - // txtAuth + // btnUpdate // - txtAuth.Location = new Point(593, 77); - txtAuth.Name = "txtAuth"; - txtAuth.PasswordChar = '*'; - txtAuth.Size = new Size(100, 23); - txtAuth.TabIndex = 4; + btnUpdate.Location = new Point(577, 77); + btnUpdate.Name = "btnUpdate"; + btnUpdate.Size = new Size(75, 23); + btnUpdate.TabIndex = 4; + btnUpdate.Text = "Update"; + btnUpdate.UseVisualStyleBackColor = true; + btnUpdate.Click += btnUpdate_Click; + // + // lblOut + // + lblOut.AutoSize = true; + lblOut.Location = new Point(44, 117); + lblOut.Name = "lblOut"; + lblOut.Size = new Size(12, 15); + lblOut.TabIndex = 5; + lblOut.Text = "-"; // // ControlCenter // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); - Controls.Add(txtAuth); + Controls.Add(lblOut); + Controls.Add(btnUpdate); Controls.Add(btnSetup); Controls.Add(label2); Controls.Add(label1); @@ -115,6 +128,7 @@ private ContextMenuStrip trayMenu; private NotifyIcon notifyIcon1; private Button btnSetup; - private TextBox txtAuth; + private Button btnUpdate; + private Label lblOut; } } diff --git a/EgwControlCenter/ControlCenter.cs b/EgwControlCenter/ControlCenter.cs index 11658db..da238be 100644 --- a/EgwControlCenter/ControlCenter.cs +++ b/EgwControlCenter/ControlCenter.cs @@ -1,5 +1,9 @@ using System.Windows.Forms; using static EgwControlCenter.AccEnum; +using Microsoft.VisualBasic; +using EgwControlCenter.Core; +using System.Diagnostics; +using Newtonsoft.Json; namespace EgwControlCenter { @@ -10,8 +14,9 @@ namespace EgwControlCenter public ControlCenter() { InitializeComponent(); - setupTrayIcon(); - createTrayMenu(); + SetupTrayIcon(); + CreateTrayMenu(); + InitObjects(); } #endregion Public Constructors @@ -25,12 +30,51 @@ namespace EgwControlCenter #endregion Protected Fields + #region Private Properties + + private ReleaseChecker CurrCheck { get; set; } = new ReleaseChecker("", ""); + + #endregion Private Properties + #region Private Methods + private void btnSetup_Click(object sender, EventArgs e) + { + string authPwd = Interaction.InputBox("Prego inserire pwd per abilitare lo sblocco", "Verifica Utente", "", 10, 10); + //verifico passphrase + if (authPwd == "24068Seriate") + { + TargetSetup tgtForm = new TargetSetup(); + tgtForm.Show(); + } + else + { + string message = "La passphrase inserita non è corretta. Impossibile procedere"; + string caption = "Auth Error"; + MessageBoxButtons buttons = MessageBoxButtons.OK; + DialogResult result; + result = MessageBox.Show(message, caption, buttons); + } + } + + private async void btnUpdate_Click(object sender, EventArgs e) + { + Stopwatch sw = new Stopwatch(); + sw.Start(); + // effettua un refresh del controllo status... + bool localOk = CurrCheck.UpdateLocalStatus(true); + await CurrCheck.CheckCurrReleases(); + sw.Stop(); + string rawConf = JsonConvert.SerializeObject(CurrCheck, Formatting.Indented); + lblOut.Text = rawConf; + lblOut.Text += $"{Environment.NewLine}---------------------{Environment.NewLine}"; + lblOut.Text += $"Eseguito refresh in {sw.ElapsedMilliseconds:N0} ms"; + } + /// /// Verifica stato windows (minimized/normal) e visibilità con tray... /// - private void checkFormVisibility() + private void CheckFormVisibility() { // se non può massimizzare imposto COMUNQUE a minimized... if (!AccUtils.CRB("windowCanMax")) @@ -61,43 +105,6 @@ namespace EgwControlCenter #endif } - /// - /// crea menù tray x applicazione - /// - private void createTrayMenu() - { - // Fix testi menù tray... - trayMenu.Items.Clear(); - // SE permessa massimizzazione... - trayMenu.Items.Add("Show EgalWare ACC"); - // se è permesso chiudere - trayMenu.Items.Add("Close EgalWare ACC"); - } - - /// - /// Gestisce "andata nel tray" della form - /// - private void sendToTray() - { - if (!notifyIcon1.Visible) - { - notifyIcon1.BalloonTipTitle = AccUtils.CRS("appName"); - notifyIcon1.BalloonTipText = $"{AccUtils.CRS("appName")} running on tray"; - notifyIcon1.Visible = true; - notifyIcon1.ShowBalloonTip(100); - } - Hide(); - } - - private void setupTrayIcon() - { - // fix icon! - var currObj = System.Reflection.Assembly.GetExecutingAssembly().GetName(); - notifyIcon1.Text = $"EgalWare's AppControlCenter | {currObj.Version}"; - //Icon = Icon.ExtractAssociatedIcon(AccUtils.defIconFilePath); - //notifyIcon1.Icon = Icon.ExtractAssociatedIcon(AccUtils.defIconFilePath); - } - /// /// evento chiusura /// @@ -106,40 +113,10 @@ namespace EgwControlCenter private void ControlCenter_FormClosing(object sender, FormClosingEventArgs e) { #if false - closeAllChild(); + closeAllChild(); #endif } - - /// - /// click su menù contestuale in tray - /// - /// - /// - private void trayMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) - { - if (e != null && e.ClickedItem != null && !string.IsNullOrEmpty(e.ClickedItem.Text)) - { - if (e.ClickedItem.Text.StartsWith("Close")) - { -#if false - // stop child adapters... - closeAllChild(); -#endif - // chiudo! - Close(); - } - else if (e.ClickedItem.Text.StartsWith("Show")) - { - if (AccUtils.CRB("windowCanMax")) - { - Show(); - WindowState = FormWindowState.Normal; - } - } - } - } - /// /// evento resize /// @@ -147,7 +124,7 @@ namespace EgwControlCenter /// private void ControlCenter_Resize(object sender, EventArgs e) { - checkFormVisibility(); + CheckFormVisibility(); } /// @@ -168,10 +145,29 @@ namespace EgwControlCenter } } #if false - displayTaskAndLog("Main Form SHOWN (MDI)"); + displayTaskAndLog("Main Form SHOWN (MDI)"); #endif } + /// + /// crea menù tray x applicazione + /// + private void CreateTrayMenu() + { + // Fix testi menù tray... + trayMenu.Items.Clear(); + // SE permessa massimizzazione... + trayMenu.Items.Add("Show EgalWare ACC"); + // se è permesso chiudere + trayMenu.Items.Add("Close EgalWare ACC"); + } + + private void InitObjects() + { + // init obj gestione check... + CurrCheck = new ReleaseChecker(AccUtils.confDir, "ConfPatrol.json"); + } + /// /// doppio click su tray icon /// @@ -187,20 +183,59 @@ namespace EgwControlCenter } } - #endregion Private Methods - - private void btnSetup_Click(object sender, EventArgs e) + /// + /// Gestisce "andata nel tray" della form + /// + private void sendToTray() { - //verifico passphrase - if (txtAuth.Text == "24068Seriate") + if (!notifyIcon1.Visible) { - TargetSetup tgtForm = new TargetSetup(); - tgtForm.Show(); + notifyIcon1.BalloonTipTitle = AccUtils.CRS("appName"); + notifyIcon1.BalloonTipText = $"{AccUtils.CRS("appName")} running on tray"; + notifyIcon1.Visible = true; + notifyIcon1.ShowBalloonTip(100); } - else + Hide(); + } + + private void SetupTrayIcon() + { + // fix icon! + var currObj = System.Reflection.Assembly.GetExecutingAssembly().GetName(); + notifyIcon1.Text = $"EgalWare's AppControlCenter | {currObj.Version}"; + //Icon = Icon.ExtractAssociatedIcon(AccUtils.defIconFilePath); + //notifyIcon1.Icon = Icon.ExtractAssociatedIcon(AccUtils.defIconFilePath); + } + + /// + /// click su menù contestuale in tray + /// + /// + /// + private void trayMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) + { + if (e != null && e.ClickedItem != null && !string.IsNullOrEmpty(e.ClickedItem.Text)) { - txtAuth.Text = ""; + if (e.ClickedItem.Text.StartsWith("Close")) + { +#if false + // stop child adapters... + closeAllChild(); +#endif + // chiudo! + Close(); + } + else if (e.ClickedItem.Text.StartsWith("Show")) + { + if (AccUtils.CRB("windowCanMax")) + { + Show(); + WindowState = FormWindowState.Normal; + } + } } } + + #endregion Private Methods } } \ No newline at end of file diff --git a/EgwControlCenter/EgwControlCenter.csproj b/EgwControlCenter/EgwControlCenter.csproj index 17672c4..c538ad8 100644 --- a/EgwControlCenter/EgwControlCenter.csproj +++ b/EgwControlCenter/EgwControlCenter.csproj @@ -12,4 +12,13 @@ + + + Always + + + PreserveNewest + + + \ No newline at end of file From 1d395022250852278dee39fdb3184027ffa61c36 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 18 Sep 2024 19:04:14 +0200 Subject: [PATCH 3/7] Completata parte gestione recupero info locali/remote raw --- EgwControlCenter.Core/ReleaseChecker.cs | 135 ++++++++++++++---------- EgwControlCenter/ControlCenter.cs | 6 +- 2 files changed, 81 insertions(+), 60 deletions(-) diff --git a/EgwControlCenter.Core/ReleaseChecker.cs b/EgwControlCenter.Core/ReleaseChecker.cs index d3d9dba..77fbe34 100644 --- a/EgwControlCenter.Core/ReleaseChecker.cs +++ b/EgwControlCenter.Core/ReleaseChecker.cs @@ -5,6 +5,7 @@ using RestSharp; using RestSharp.Serializers; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -13,6 +14,15 @@ namespace EgwControlCenter.Core { public class ReleaseChecker { + #region Public Fields + + /// + /// Classe logger + /// + public static Logger Log = LogManager.GetCurrentClassLogger(); + + #endregion Public Fields + #region Public Constructors public ReleaseChecker(string baseDir, string currConfig) @@ -52,8 +62,6 @@ namespace EgwControlCenter.Core /// public List ListStatus { get; set; } = new List(); - protected static string apiUrl = "https://liman.egalware.com/ELM.Api/"; - #endregion Public Properties #region Public Methods @@ -62,67 +70,36 @@ namespace EgwControlCenter.Core /// Esegue verifica remota versioni x i sw tracciati /// /// - public async Task CheckCurrReleases() + public bool CheckCurrReleases() { - // ciclo x ogni item da controllare - foreach (var item in ListStatus) - { - if (item.CurrLocal != null) - { - // verifico release da remoto aggiorno obj - var ListRem = GetRemoteRel(item.CurrLocal.CodApp, item.CurrLocal.VersNum); - if (ListRem != null) - { - item.ListRemote = ListRem; - item.LastUpdateRem = DateTime.Now; - } - } - } - // salvo status... - SaveStatus(); - } - - - private static List GetRemoteRel(string CodApp, string CurrVers) - { - List answ = new List(); + bool fatto = false; try { - // client chiamate rest - var client = new RestClient(apiUrl); - string rawData = ""; - // Chiamo il metodo! - var checkRel = new RestRequest($"/api/Release/filt/{CodApp}?VersMin={CurrVers}", Method.Get); - //var listNextRel = new RestRequest($"/api/Release/filt/TestMachine?VersMin=1.1.0.0", Method.Get); - - // effettuo vera chiamata - var pUpd = Task.Run(async () => + // ciclo x ogni item da controllare + foreach (var item in ListStatus) { - var currResp = await client.GetAsync(checkRel); - if (currResp.StatusCode == System.Net.HttpStatusCode.OK && currResp.Content != null) + if (item.CurrLocal != null) { - var currList = JsonConvert.DeserializeObject>(currResp.Content); - if (currList != null) + // verifico release da remoto aggiorno obj + var ListRem = GetRemoteRel(item.CodApp, item.CurrLocal.VersNum); + if (ListRem != null) { - answ = currList; + item.ListRemote = ListRem; + item.LastUpdateRem = DateTime.Now; } } - }); - pUpd.Wait(); + } + // salvo status... + SaveStatus(); + fatto = true; } catch (Exception exc) { - Log.Error($"Eccezione in fase gestione REST services{Environment.NewLine}{exc}"); + Log.Error($"Errore in CheckCurrReleases{Environment.NewLine}{exc}"); } - - return answ; + return fatto; } - /// - /// Classe logger - /// - public static Logger Log = LogManager.GetCurrentClassLogger(); - /// /// Aggiorna (se necessario) lo stato degli oggetti da monitorare /// @@ -173,9 +150,10 @@ namespace EgwControlCenter.Core var currRelDto = MldeGetRelease(tgtFile); if (currRelDto != null) { + string codApp = Path.GetFileName(currDir); newListStatus.Add(new TargetStatus() { - CodApp = currDir, + CodApp = codApp, CurrLocal = currRelDto, LastUpdateLoc = DateTime.Now }); @@ -210,13 +188,28 @@ namespace EgwControlCenter.Core #endregion Public Methods + #region Protected Fields + + protected static string apiUrl = "https://liman.egalware.com/ELM.Api/"; + + #endregion Protected Fields + + #region Protected Properties + + /// + /// Configurazione degli oggetti da monitorare + /// + protected PatrolSettings CurrPatrolCont { get; set; } = new PatrolSettings(); + + #endregion Protected Properties + #region Private Properties private string AppDir { get; set; } = ""; /// - /// Periodo minimo per autorefresh versioni default 1 gg) - /// protected TimeSpan AutoRefreshVeto { get; set; } = TimeSpan.FromDays(1); + /// Periodo minimo per autorefresh versioni default 1 gg) protected TimeSpan AutoRefreshVeto + /// { get; set; } = TimeSpan.FromDays(1); /// private TimeSpan AutoRefreshVeto { get; set; } = TimeSpan.FromSeconds(30); @@ -230,11 +223,6 @@ namespace EgwControlCenter.Core get => Path.Combine(AppDir, ConfName); } - /// - /// Configurazione degli oggetti da monitorare - /// - protected PatrolSettings CurrPatrolCont { get; set; } = new PatrolSettings(); - private string StatusName { get; set; } = "LastStatus.json"; /// @@ -249,6 +237,39 @@ namespace EgwControlCenter.Core #region Private Methods + private static List GetRemoteRel(string CodApp, string CurrVers) + { + List answ = new List(); + try + { + // client chiamate rest + var client = new RestClient(apiUrl); + string rawData = ""; + // Chiamo il metodo! + var checkRel = new RestRequest($"/api/Release/filt/{CodApp}?VersMin={CurrVers}", Method.Get); + // effettuo vera chiamata + var pUpd = Task.Run(async () => + { + var currResp = await client.GetAsync(checkRel); + if (currResp.StatusCode == System.Net.HttpStatusCode.OK && currResp.Content != null) + { + var currList = JsonConvert.DeserializeObject>(currResp.Content); + if (currList != null) + { + answ = currList; + } + } + }); + pUpd.Wait(); + } + catch (Exception exc) + { + Log.Error($"Eccezione in fase gestione REST services{Environment.NewLine}{exc}"); + } + + return answ; + } + /// /// Verifica se il check sia scaduto rispetto ad AutoRefreshVeto /// diff --git a/EgwControlCenter/ControlCenter.cs b/EgwControlCenter/ControlCenter.cs index da238be..2a33b15 100644 --- a/EgwControlCenter/ControlCenter.cs +++ b/EgwControlCenter/ControlCenter.cs @@ -57,13 +57,13 @@ namespace EgwControlCenter } } - private async void btnUpdate_Click(object sender, EventArgs e) + private void btnUpdate_Click(object sender, EventArgs e) { Stopwatch sw = new Stopwatch(); sw.Start(); // effettua un refresh del controllo status... - bool localOk = CurrCheck.UpdateLocalStatus(true); - await CurrCheck.CheckCurrReleases(); + bool locOk = CurrCheck.UpdateLocalStatus(true); + bool remOk = CurrCheck.CheckCurrReleases(); sw.Stop(); string rawConf = JsonConvert.SerializeObject(CurrCheck, Formatting.Indented); lblOut.Text = rawConf; From 530ded0ff1cad8b9189fab80fab80aa62d116f44 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 18 Sep 2024 19:22:04 +0200 Subject: [PATCH 4/7] Aggiunto timer + auto-update (rapido 1 sec x ora...) --- EgwControlCenter/ControlCenter.Designer.cs | 7 +++ EgwControlCenter/ControlCenter.cs | 66 ++++++++++++++++------ EgwControlCenter/ControlCenter.resx | 3 + 3 files changed, 60 insertions(+), 16 deletions(-) diff --git a/EgwControlCenter/ControlCenter.Designer.cs b/EgwControlCenter/ControlCenter.Designer.cs index 043fbf9..eb9c876 100644 --- a/EgwControlCenter/ControlCenter.Designer.cs +++ b/EgwControlCenter/ControlCenter.Designer.cs @@ -37,6 +37,7 @@ btnSetup = new Button(); btnUpdate = new Button(); lblOut = new Label(); + timerCheck = new System.Windows.Forms.Timer(components); SuspendLayout(); // // label1 @@ -101,6 +102,11 @@ lblOut.TabIndex = 5; lblOut.Text = "-"; // + // timerCheck + // + timerCheck.Interval = 1000; + timerCheck.Tick += timerCheck_Tick; + // // ControlCenter // AutoScaleDimensions = new SizeF(7F, 15F); @@ -130,5 +136,6 @@ private Button btnSetup; private Button btnUpdate; private Label lblOut; + private System.Windows.Forms.Timer timerCheck; } } diff --git a/EgwControlCenter/ControlCenter.cs b/EgwControlCenter/ControlCenter.cs index 2a33b15..2b4b44c 100644 --- a/EgwControlCenter/ControlCenter.cs +++ b/EgwControlCenter/ControlCenter.cs @@ -4,6 +4,7 @@ using Microsoft.VisualBasic; using EgwControlCenter.Core; using System.Diagnostics; using Newtonsoft.Json; +using System.Text; namespace EgwControlCenter { @@ -34,6 +35,10 @@ namespace EgwControlCenter private ReleaseChecker CurrCheck { get; set; } = new ReleaseChecker("", ""); + private bool locCheckOk { get; set; } = false; + + private bool remCheckOk { get; set; } = false; + #endregion Private Properties #region Private Methods @@ -62,13 +67,13 @@ namespace EgwControlCenter Stopwatch sw = new Stopwatch(); sw.Start(); // effettua un refresh del controllo status... - bool locOk = CurrCheck.UpdateLocalStatus(true); - bool remOk = CurrCheck.CheckCurrReleases(); + locCheckOk = CurrCheck.UpdateLocalStatus(true); + if (locCheckOk) + { + remCheckOk = CurrCheck.CheckCurrReleases(); + } sw.Stop(); - string rawConf = JsonConvert.SerializeObject(CurrCheck, Formatting.Indented); - lblOut.Text = rawConf; - lblOut.Text += $"{Environment.NewLine}---------------------{Environment.NewLine}"; - lblOut.Text += $"Eseguito refresh in {sw.ElapsedMilliseconds:N0} ms"; + DisplayCheckResult(sw.Elapsed); } /// @@ -99,10 +104,6 @@ namespace EgwControlCenter { notifyIcon1.Visible = false; } -#if false - // fix child! - this.LayoutMdi(MdiLayout.TileHorizontal); -#endif } /// @@ -112,9 +113,8 @@ namespace EgwControlCenter /// private void ControlCenter_FormClosing(object sender, FormClosingEventArgs e) { -#if false - closeAllChild(); -#endif + timerCheck.Stop(); + timerCheck.Dispose(); } /// @@ -144,9 +144,6 @@ namespace EgwControlCenter sendToTray(); } } -#if false - displayTaskAndLog("Main Form SHOWN (MDI)"); -#endif } /// @@ -162,10 +159,33 @@ namespace EgwControlCenter trayMenu.Items.Add("Close EgalWare ACC"); } + /// + /// Mostra i risultati dell'esito del controllo release + /// + /// + private void DisplayCheckResult(TimeSpan elapsed) + { + StringBuilder sb = new StringBuilder(); + sb.AppendLine("---------------------"); + sb.AppendLine($"{DateTime.Now:HH:mm:ss}"); + sb.AppendLine("---------------------"); + sb.AppendLine(); + if (locCheckOk && remCheckOk) + { + string rawConf = JsonConvert.SerializeObject(CurrCheck, Formatting.Indented); + sb.Append(rawConf); + } + sb.AppendLine(); + sb.AppendLine("---------------------"); + sb.AppendLine($"Eseguito refresh | Loc: {locCheckOk} | Rem: {remCheckOk} | {elapsed.TotalMilliseconds:N0} ms"); + lblOut.Text = sb.ToString(); + } + private void InitObjects() { // init obj gestione check... CurrCheck = new ReleaseChecker(AccUtils.confDir, "ConfPatrol.json"); + timerCheck.Start(); } /// @@ -207,6 +227,20 @@ namespace EgwControlCenter //notifyIcon1.Icon = Icon.ExtractAssociatedIcon(AccUtils.defIconFilePath); } + private void timerCheck_Tick(object sender, EventArgs e) + { + Stopwatch sw = new Stopwatch(); + sw.Start(); + // esegue controllo locale ed eventualmente remoto se scaduto... + locCheckOk = CurrCheck.UpdateLocalStatus(false); + if (locCheckOk) + { + remCheckOk = CurrCheck.CheckCurrReleases(); + } + sw.Stop(); + DisplayCheckResult(sw.Elapsed); + } + /// /// click su menù contestuale in tray /// diff --git a/EgwControlCenter/ControlCenter.resx b/EgwControlCenter/ControlCenter.resx index 4f36b58..fdb3f2b 100644 --- a/EgwControlCenter/ControlCenter.resx +++ b/EgwControlCenter/ControlCenter.resx @@ -290,6 +290,9 @@ AAA= + + 236, 17 + AAABAAEAMDAAAAEAIACoJQAAFgAAACgAAAAwAAAAYAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA From 46345e3393eaa4e7c9edc91361d4f78686e43fce Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 19 Sep 2024 08:10:46 +0200 Subject: [PATCH 5/7] Update AppControlCenter - aggiunto tooltip su update trovato - posizionato form in basso a sx --- EgwControlCenter.Core/ReleaseChecker.cs | 39 +++++++++++++ EgwControlCenter/App.config | 2 +- EgwControlCenter/ControlCenter.Designer.cs | 66 +++++++++++++++------- EgwControlCenter/ControlCenter.cs | 31 ++++++++-- EgwControlCenter/ControlCenter.resx | 3 + 5 files changed, 116 insertions(+), 25 deletions(-) diff --git a/EgwControlCenter.Core/ReleaseChecker.cs b/EgwControlCenter.Core/ReleaseChecker.cs index 77fbe34..4b395db 100644 --- a/EgwControlCenter.Core/ReleaseChecker.cs +++ b/EgwControlCenter.Core/ReleaseChecker.cs @@ -57,6 +57,45 @@ namespace EgwControlCenter.Core #region Public Properties + + /// + /// DataOra ultimo check locale + /// + public DateTime LastChecked() + { + DateTime answ = new DateTime(DateTime.Today.Year, 1, 1); + //se ho record locali cerco il + recente + if (ListStatus != null && ListStatus.Count > 0) + { + var primo = ListStatus + .OrderByDescending(x => x.LastUpdateLoc) + .FirstOrDefault(); + if (primo != null) + { + answ = primo.LastUpdateLoc; + } + } + return answ; + } + + public bool HasUpdate() + { + bool answ = false; + //se ho record locali cerco il + recente + if (ListStatus != null && ListStatus.Count > 0) + { + foreach (var item in ListStatus) + { + answ = item.HasUpdate(); + if(answ) + { + break; + } + } + } + return answ; + } + /// /// Elenco degli oggetti stato dei programmi monitorati /// diff --git a/EgwControlCenter/App.config b/EgwControlCenter/App.config index 246180f..9e682e6 100644 --- a/EgwControlCenter/App.config +++ b/EgwControlCenter/App.config @@ -46,7 +46,7 @@ - + diff --git a/EgwControlCenter/ControlCenter.Designer.cs b/EgwControlCenter/ControlCenter.Designer.cs index eb9c876..14b07da 100644 --- a/EgwControlCenter/ControlCenter.Designer.cs +++ b/EgwControlCenter/ControlCenter.Designer.cs @@ -31,34 +31,29 @@ components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ControlCenter)); label1 = new Label(); - label2 = new Label(); trayMenu = new ContextMenuStrip(components); notifyIcon1 = new NotifyIcon(components); btnSetup = new Button(); btnUpdate = new Button(); lblOut = new Label(); timerCheck = new System.Windows.Forms.Timer(components); + statusStrip1 = new StatusStrip(); + tsLabelOut = new ToolStripStatusLabel(); + dgView = new DataGridView(); + statusStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dgView).BeginInit(); SuspendLayout(); // // label1 // label1.AutoSize = true; - label1.Font = new Font("Roboto", 24F, FontStyle.Regular, GraphicsUnit.Point, 0); - label1.Location = new Point(193, 9); + label1.Font = new Font("Roboto", 16F, FontStyle.Regular, GraphicsUnit.Point, 0); + label1.Location = new Point(34, 9); label1.Name = "label1"; - label1.Size = new Size(429, 38); + label1.Size = new Size(293, 27); label1.TabIndex = 0; label1.Text = "EgalWare App Control Center"; // - // label2 - // - label2.AutoSize = true; - label2.Location = new Point(53, 83); - label2.Name = "label2"; - label2.Size = new Size(152, 15); - label2.TabIndex = 1; - label2.Text = "Elenco App (list? webview?)"; - // // trayMenu // trayMenu.Name = "trayMenu"; @@ -75,7 +70,7 @@ // // btnSetup // - btnSetup.Location = new Point(761, 23); + btnSetup.Location = new Point(352, 13); btnSetup.Name = "btnSetup"; btnSetup.Size = new Size(27, 23); btnSetup.TabIndex = 3; @@ -85,11 +80,11 @@ // // btnUpdate // - btnUpdate.Location = new Point(577, 77); + btnUpdate.Location = new Point(281, 267); btnUpdate.Name = "btnUpdate"; - btnUpdate.Size = new Size(75, 23); + btnUpdate.Size = new Size(98, 23); btnUpdate.TabIndex = 4; - btnUpdate.Text = "Update"; + btnUpdate.Text = "Check Now"; btnUpdate.UseVisualStyleBackColor = true; btnUpdate.Click += btnUpdate_Click; // @@ -107,22 +102,51 @@ timerCheck.Interval = 1000; timerCheck.Tick += timerCheck_Tick; // + // statusStrip1 + // + statusStrip1.Items.AddRange(new ToolStripItem[] { tsLabelOut }); + statusStrip1.Location = new Point(0, 293); + statusStrip1.Name = "statusStrip1"; + statusStrip1.Size = new Size(388, 22); + statusStrip1.TabIndex = 6; + statusStrip1.Text = "statusStrip1"; + // + // tsLabelOut + // + tsLabelOut.Name = "tsLabelOut"; + tsLabelOut.Size = new Size(49, 17); + tsLabelOut.Text = "v.0.0.0.0"; + tsLabelOut.TextImageRelation = TextImageRelation.Overlay; + // + // dgView + // + dgView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dgView.Location = new Point(12, 56); + dgView.Name = "dgView"; + dgView.Size = new Size(364, 205); + dgView.TabIndex = 7; + // // ControlCenter // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(388, 315); + Controls.Add(dgView); + Controls.Add(statusStrip1); Controls.Add(lblOut); Controls.Add(btnUpdate); Controls.Add(btnSetup); - Controls.Add(label2); Controls.Add(label1); Icon = (Icon)resources.GetObject("$this.Icon"); Name = "ControlCenter"; Text = "Egalware Control Center"; FormClosing += ControlCenter_FormClosing; + Load += ControlCenter_Load; Shown += ControlCenter_Shown; Resize += ControlCenter_Resize; + statusStrip1.ResumeLayout(false); + statusStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dgView).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -130,12 +154,14 @@ #endregion private Label label1; - private Label label2; private ContextMenuStrip trayMenu; private NotifyIcon notifyIcon1; private Button btnSetup; private Button btnUpdate; private Label lblOut; private System.Windows.Forms.Timer timerCheck; + private StatusStrip statusStrip1; + private ToolStripStatusLabel tsLabelOut; + private DataGridView dgView; } } diff --git a/EgwControlCenter/ControlCenter.cs b/EgwControlCenter/ControlCenter.cs index 2b4b44c..00c50d9 100644 --- a/EgwControlCenter/ControlCenter.cs +++ b/EgwControlCenter/ControlCenter.cs @@ -15,8 +15,6 @@ namespace EgwControlCenter public ControlCenter() { InitializeComponent(); - SetupTrayIcon(); - CreateTrayMenu(); InitObjects(); } @@ -117,6 +115,13 @@ namespace EgwControlCenter timerCheck.Dispose(); } + private void ControlCenter_Load(object sender, EventArgs e) + { + // posiziono in basso a sx... + Rectangle workArea = Screen.GetWorkingArea(this); + this.Location = new Point(workArea.Right - Size.Width, workArea.Bottom - Size.Height); + } + /// /// evento resize /// @@ -165,6 +170,7 @@ namespace EgwControlCenter /// private void DisplayCheckResult(TimeSpan elapsed) { +#if false StringBuilder sb = new StringBuilder(); sb.AppendLine("---------------------"); sb.AppendLine($"{DateTime.Now:HH:mm:ss}"); @@ -178,13 +184,27 @@ namespace EgwControlCenter sb.AppendLine(); sb.AppendLine("---------------------"); sb.AppendLine($"Eseguito refresh | Loc: {locCheckOk} | Rem: {remCheckOk} | {elapsed.TotalMilliseconds:N0} ms"); - lblOut.Text = sb.ToString(); + lblOut.Text = sb.ToString(); +#endif + tsLabelOut.Text = $"Last Check: {CurrCheck.LastChecked():yyyy-MM-dd HH:mm:ss}"; + // notifica ballontip se ho aggiornamenti... + if(CurrCheck.HasUpdate()) + { + + notifyIcon1.BalloonTipTitle = "EgalWare's App Control Center"; + notifyIcon1.BalloonTipText = "Update found!"; + notifyIcon1.BalloonTipIcon = ToolTipIcon.Warning; + notifyIcon1.ShowBalloonTip(1000); + } } private void InitObjects() { + SetupTrayIcon(); + CreateTrayMenu(); // init obj gestione check... CurrCheck = new ReleaseChecker(AccUtils.confDir, "ConfPatrol.json"); + tsLabelOut.Text = $"Last Check: {CurrCheck.LastChecked():yyyy-MM-dd HH:mm:ss}"; timerCheck.Start(); } @@ -238,7 +258,10 @@ namespace EgwControlCenter remCheckOk = CurrCheck.CheckCurrReleases(); } sw.Stop(); - DisplayCheckResult(sw.Elapsed); + if (locCheckOk) + { + DisplayCheckResult(sw.Elapsed); + } } /// diff --git a/EgwControlCenter/ControlCenter.resx b/EgwControlCenter/ControlCenter.resx index fdb3f2b..7072d7c 100644 --- a/EgwControlCenter/ControlCenter.resx +++ b/EgwControlCenter/ControlCenter.resx @@ -293,6 +293,9 @@ 236, 17 + + 351, 17 + AAABAAEAMDAAAAEAIACoJQAAFgAAACgAAAAwAAAAYAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA From 97a2b3fc654a44ed71ceab29f90c326de96c4722 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 19 Sep 2024 10:07:57 +0200 Subject: [PATCH 6/7] Update controlCenter --- EgwControlCenter.Core/Models/TargetStatus.cs | 19 +++++++++ EgwControlCenter.Core/Models/VersStatusDTO.cs | 39 +++++++++++++++++++ EgwControlCenter.Core/ReleaseChecker.cs | 24 ++++++++++-- EgwControlCenter/ControlCenter.Designer.cs | 35 +++++++++++------ EgwControlCenter/ControlCenter.cs | 30 ++++++++++---- 5 files changed, 124 insertions(+), 23 deletions(-) create mode 100644 EgwControlCenter.Core/Models/VersStatusDTO.cs diff --git a/EgwControlCenter.Core/Models/TargetStatus.cs b/EgwControlCenter.Core/Models/TargetStatus.cs index 8f90757..caca4cd 100644 --- a/EgwControlCenter.Core/Models/TargetStatus.cs +++ b/EgwControlCenter.Core/Models/TargetStatus.cs @@ -11,6 +11,9 @@ namespace EgwControlCenter.Core.Models { #region Public Properties + /// + /// Nome applicazione + /// public string CodApp { get; set; } = ""; /// @@ -37,6 +40,22 @@ namespace EgwControlCenter.Core.Models #region Public Methods + public ReleaseDTO CurrRemote + { + get + { + ReleaseDTO answ = new ReleaseDTO(); + if (ListRemote != null && ListRemote.Count() > 0) + { + answ = ListRemote + .OrderByDescending(x => x.VersVal) + .ThenByDescending(x => x.ReleaseDate) + .FirstOrDefault() ?? new ReleaseDTO(); + } + return answ; + } + } + /// /// Calcolo condizione "ci sono update": /// - almeno 1 rel remota diff --git a/EgwControlCenter.Core/Models/VersStatusDTO.cs b/EgwControlCenter.Core/Models/VersStatusDTO.cs new file mode 100644 index 0000000..324272f --- /dev/null +++ b/EgwControlCenter.Core/Models/VersStatusDTO.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; + +namespace EgwControlCenter.Core.Models +{ + public class VersStatusDTO + { + #region Public Properties + + /// + /// Nome applicazione + /// + public string CodApp { get; set; } = ""; + + + /// + /// Versione applicativo corrente + /// + public string VersNumCurr { get; set; } = "0.0.0.0"; + + + /// + /// Versione applicativo LAST disponibile + /// + public string VersNumLast { get; set; } = "0.0.0.0"; + + /// + /// Tag associati a ultima versione disponibile, comma separated + /// + public string RelTagsLast { get; set; } = ""; + + #endregion Public Properties + + } +} \ No newline at end of file diff --git a/EgwControlCenter.Core/ReleaseChecker.cs b/EgwControlCenter.Core/ReleaseChecker.cs index 4b395db..7d76e72 100644 --- a/EgwControlCenter.Core/ReleaseChecker.cs +++ b/EgwControlCenter.Core/ReleaseChecker.cs @@ -87,7 +87,7 @@ namespace EgwControlCenter.Core foreach (var item in ListStatus) { answ = item.HasUpdate(); - if(answ) + if (answ) { break; } @@ -99,7 +99,12 @@ namespace EgwControlCenter.Core /// /// Elenco degli oggetti stato dei programmi monitorati /// - public List ListStatus { get; set; } = new List(); + protected List ListStatus { get; set; } = new List(); + + /// + /// Elenco degli oggetti stato dei programmi monitorati + /// + public List ListAppStatus { get; set; } = new List(); #endregion Public Properties @@ -109,7 +114,7 @@ namespace EgwControlCenter.Core /// Esegue verifica remota versioni x i sw tracciati /// /// - public bool CheckCurrReleases() + public bool CheckRemoteReleases() { bool fatto = false; try @@ -134,7 +139,7 @@ namespace EgwControlCenter.Core } catch (Exception exc) { - Log.Error($"Errore in CheckCurrReleases{Environment.NewLine}{exc}"); + Log.Error($"Errore in CheckRemoteReleases{Environment.NewLine}{exc}"); } return fatto; } @@ -403,6 +408,17 @@ namespace EgwControlCenter.Core { File.WriteAllText(StatusPath, rawData); } + // aggiorno obj calcolato versioni... + ListAppStatus = ListStatus + .Where(x => x.HasUpdate()) + .Select(x => new VersStatusDTO + { + CodApp = x.CodApp, + VersNumCurr = x.CurrLocal.VersNum, + VersNumLast = x.CurrRemote.VersNum, + RelTagsLast = x.CurrRemote.RelTags + }) + .ToList(); } #endregion Private Methods diff --git a/EgwControlCenter/ControlCenter.Designer.cs b/EgwControlCenter/ControlCenter.Designer.cs index 14b07da..20ad6bd 100644 --- a/EgwControlCenter/ControlCenter.Designer.cs +++ b/EgwControlCenter/ControlCenter.Designer.cs @@ -38,6 +38,7 @@ lblOut = new Label(); timerCheck = new System.Windows.Forms.Timer(components); statusStrip1 = new StatusStrip(); + tsLabelVers = new ToolStripStatusLabel(); tsLabelOut = new ToolStripStatusLabel(); dgView = new DataGridView(); statusStrip1.SuspendLayout(); @@ -48,7 +49,7 @@ // label1.AutoSize = true; label1.Font = new Font("Roboto", 16F, FontStyle.Regular, GraphicsUnit.Point, 0); - label1.Location = new Point(34, 9); + label1.Location = new Point(70, 9); label1.Name = "label1"; label1.Size = new Size(293, 27); label1.TabIndex = 0; @@ -70,7 +71,8 @@ // // btnSetup // - btnSetup.Location = new Point(352, 13); + btnSetup.Anchor = AnchorStyles.Top | AnchorStyles.Right; + btnSetup.Location = new Point(385, 13); btnSetup.Name = "btnSetup"; btnSetup.Size = new Size(27, 23); btnSetup.TabIndex = 3; @@ -80,7 +82,8 @@ // // btnUpdate // - btnUpdate.Location = new Point(281, 267); + btnUpdate.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + btnUpdate.Location = new Point(314, 223); btnUpdate.Name = "btnUpdate"; btnUpdate.Size = new Size(98, 23); btnUpdate.TabIndex = 4; @@ -104,33 +107,40 @@ // // statusStrip1 // - statusStrip1.Items.AddRange(new ToolStripItem[] { tsLabelOut }); - statusStrip1.Location = new Point(0, 293); + statusStrip1.Items.AddRange(new ToolStripItem[] { tsLabelVers, tsLabelOut }); + statusStrip1.Location = new Point(0, 249); statusStrip1.Name = "statusStrip1"; - statusStrip1.Size = new Size(388, 22); + statusStrip1.Size = new Size(421, 22); statusStrip1.TabIndex = 6; statusStrip1.Text = "statusStrip1"; // + // tsLabelVers + // + tsLabelVers.Name = "tsLabelVers"; + tsLabelVers.Size = new Size(49, 17); + tsLabelVers.Text = "v.0.0.0.0"; + tsLabelVers.TextImageRelation = TextImageRelation.Overlay; + // // tsLabelOut // tsLabelOut.Name = "tsLabelOut"; - tsLabelOut.Size = new Size(49, 17); - tsLabelOut.Text = "v.0.0.0.0"; - tsLabelOut.TextImageRelation = TextImageRelation.Overlay; + tsLabelOut.Size = new Size(16, 17); + tsLabelOut.Text = "..."; // // dgView // + dgView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; dgView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dgView.Location = new Point(12, 56); dgView.Name = "dgView"; - dgView.Size = new Size(364, 205); + dgView.Size = new Size(397, 161); dgView.TabIndex = 7; // // ControlCenter // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(388, 315); + ClientSize = new Size(421, 271); Controls.Add(dgView); Controls.Add(statusStrip1); Controls.Add(lblOut); @@ -161,7 +171,8 @@ private Label lblOut; private System.Windows.Forms.Timer timerCheck; private StatusStrip statusStrip1; - private ToolStripStatusLabel tsLabelOut; + private ToolStripStatusLabel tsLabelVers; private DataGridView dgView; + private ToolStripStatusLabel tsLabelOut; } } diff --git a/EgwControlCenter/ControlCenter.cs b/EgwControlCenter/ControlCenter.cs index 00c50d9..16f759d 100644 --- a/EgwControlCenter/ControlCenter.cs +++ b/EgwControlCenter/ControlCenter.cs @@ -5,6 +5,8 @@ using EgwControlCenter.Core; using System.Diagnostics; using Newtonsoft.Json; using System.Text; +using System.ComponentModel; +using EgwControlCenter.Core.Models; namespace EgwControlCenter { @@ -68,7 +70,7 @@ namespace EgwControlCenter locCheckOk = CurrCheck.UpdateLocalStatus(true); if (locCheckOk) { - remCheckOk = CurrCheck.CheckCurrReleases(); + remCheckOk = CurrCheck.CheckRemoteReleases(); } sw.Stop(); DisplayCheckResult(sw.Elapsed); @@ -170,6 +172,8 @@ namespace EgwControlCenter /// private void DisplayCheckResult(TimeSpan elapsed) { + var list = new BindingList(CurrCheck.ListAppStatus); + dgView.DataSource = list; #if false StringBuilder sb = new StringBuilder(); sb.AppendLine("---------------------"); @@ -184,16 +188,16 @@ namespace EgwControlCenter sb.AppendLine(); sb.AppendLine("---------------------"); sb.AppendLine($"Eseguito refresh | Loc: {locCheckOk} | Rem: {remCheckOk} | {elapsed.TotalMilliseconds:N0} ms"); - lblOut.Text = sb.ToString(); + lblOut.Text = sb.ToString(); #endif tsLabelOut.Text = $"Last Check: {CurrCheck.LastChecked():yyyy-MM-dd HH:mm:ss}"; // notifica ballontip se ho aggiornamenti... - if(CurrCheck.HasUpdate()) + if (CurrCheck.HasUpdate() && WindowState != FormWindowState.Normal) { - notifyIcon1.BalloonTipTitle = "EgalWare's App Control Center"; notifyIcon1.BalloonTipText = "Update found!"; notifyIcon1.BalloonTipIcon = ToolTipIcon.Warning; + notifyIcon1.BalloonTipClicked += NotifyIcon1_BalloonTipClicked; notifyIcon1.ShowBalloonTip(1000); } } @@ -204,10 +208,17 @@ namespace EgwControlCenter CreateTrayMenu(); // init obj gestione check... CurrCheck = new ReleaseChecker(AccUtils.confDir, "ConfPatrol.json"); + tsLabelVers.Text = $"EACC v.{CurrAssembly.Version}"; tsLabelOut.Text = $"Last Check: {CurrCheck.LastChecked():yyyy-MM-dd HH:mm:ss}"; timerCheck.Start(); } + private void NotifyIcon1_BalloonTipClicked(object? sender, EventArgs e) + { + Show(); + WindowState = FormWindowState.Normal; + } + /// /// doppio click su tray icon /// @@ -232,17 +243,22 @@ namespace EgwControlCenter { notifyIcon1.BalloonTipTitle = AccUtils.CRS("appName"); notifyIcon1.BalloonTipText = $"{AccUtils.CRS("appName")} running on tray"; + notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; + notifyIcon1.BalloonTipClicked += NotifyIcon1_BalloonTipClicked; notifyIcon1.Visible = true; notifyIcon1.ShowBalloonTip(100); } + WindowState = FormWindowState.Minimized; Hide(); } + private System.Reflection.AssemblyName CurrAssembly { get; set; } = new System.Reflection.AssemblyName(); + private void SetupTrayIcon() { // fix icon! - var currObj = System.Reflection.Assembly.GetExecutingAssembly().GetName(); - notifyIcon1.Text = $"EgalWare's AppControlCenter | {currObj.Version}"; + CurrAssembly = System.Reflection.Assembly.GetExecutingAssembly().GetName(); + notifyIcon1.Text = $"EgalWare's AppControlCenter | {CurrAssembly.Version}"; //Icon = Icon.ExtractAssociatedIcon(AccUtils.defIconFilePath); //notifyIcon1.Icon = Icon.ExtractAssociatedIcon(AccUtils.defIconFilePath); } @@ -255,7 +271,7 @@ namespace EgwControlCenter locCheckOk = CurrCheck.UpdateLocalStatus(false); if (locCheckOk) { - remCheckOk = CurrCheck.CheckCurrReleases(); + remCheckOk = CurrCheck.CheckRemoteReleases(); } sw.Stop(); if (locCheckOk) From c0afb1a9bb6890f05e153ea6a442cc5d176581f3 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 19 Sep 2024 10:47:38 +0200 Subject: [PATCH 7/7] Update x display num vers --- Core/Const.cs | 2 +- LiMan.Transfer/Resources/ChangeLog.html | 2 +- LiMan.Transfer/Resources/VersNum.txt | 2 +- LiMan.Transfer/Resources/manifest.xml | 2 +- LiMan.UI/Components/ListApplicazioni.razor | 9 +- LiMan.UI/Components/ListApplicazioni.razor.cs | 11 +++ LiMan.UI/Data/LiManDataService.cs | 84 ++++++++++++++++++- LiMan.UI/LiMan.UI.csproj | 2 +- LiMan.UI/Resources/ChangeLog.html | 2 +- LiMan.UI/Resources/VersNum.txt | 2 +- LiMan.UI/Resources/manifest.xml | 2 +- 11 files changed, 109 insertions(+), 11 deletions(-) diff --git a/Core/Const.cs b/Core/Const.cs index a58b0b1..37fbd8d 100644 --- a/Core/Const.cs +++ b/Core/Const.cs @@ -10,7 +10,7 @@ namespace Core { // classi utilità x cache REDIS dati DB - public const string redisBaseAddr = "MagManUi"; + public const string redisBaseAddr = "LiMan:Ui"; public const string rKeyConfig = $"{redisBaseAddr}:Cache"; } } diff --git a/LiMan.Transfer/Resources/ChangeLog.html b/LiMan.Transfer/Resources/ChangeLog.html index 10ff335..1ced187 100644 --- a/LiMan.Transfer/Resources/ChangeLog.html +++ b/LiMan.Transfer/Resources/ChangeLog.html @@ -1,6 +1,6 @@ License Manager -

Versione: 1.1.2409.1807

+

Versione: 1.1.2409.1910


Note di rilascio:
    diff --git a/LiMan.Transfer/Resources/VersNum.txt b/LiMan.Transfer/Resources/VersNum.txt index e130097..2c7f5a0 100644 --- a/LiMan.Transfer/Resources/VersNum.txt +++ b/LiMan.Transfer/Resources/VersNum.txt @@ -1 +1 @@ -1.1.2409.1807 +1.1.2409.1910 diff --git a/LiMan.Transfer/Resources/manifest.xml b/LiMan.Transfer/Resources/manifest.xml index 878febb..258093c 100644 --- a/LiMan.Transfer/Resources/manifest.xml +++ b/LiMan.Transfer/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.1.2409.1807 + 1.1.2409.1910 https://nexus.steamware.net/repository/SWS/LiMan/stable/LAST/LiMan.Transfer.zip https://nexus.steamware.net/repository/SWS/LiMan/stable/LAST/ChangeLog.html false diff --git a/LiMan.UI/Components/ListApplicazioni.razor b/LiMan.UI/Components/ListApplicazioni.razor index ce74132..7e9da4f 100644 --- a/LiMan.UI/Components/ListApplicazioni.razor +++ b/LiMan.UI/Components/ListApplicazioni.razor @@ -62,6 +62,7 @@ { Tipo Descrizione + Rel. Db ConnString } @@ -100,7 +101,13 @@
    @record.Descrizione
    - + + @if (CurrVersNum(record.CodApp) != "0.0.0.0") + { + @CurrVersNum(record.CodApp) + } + + @if (UserHasClaim("Admin")) {
    @record.TplConnString
    diff --git a/LiMan.UI/Components/ListApplicazioni.razor.cs b/LiMan.UI/Components/ListApplicazioni.razor.cs index 62bf62b..af4ed2a 100644 --- a/LiMan.UI/Components/ListApplicazioni.razor.cs +++ b/LiMan.UI/Components/ListApplicazioni.razor.cs @@ -182,6 +182,17 @@ namespace LiMan.UI.Components #region Private Fields + private string CurrVersNum(string CodApp) + { + string answ = ""; + var pUpd = Task.Run(async () => + { + answ = await DataService.ReleaseLastGetByApp(CodApp); + }); + pUpd.Wait(); + return answ; + } + private string gridKey = "ListApplicazioni"; private List ListRecords; diff --git a/LiMan.UI/Data/LiManDataService.cs b/LiMan.UI/Data/LiManDataService.cs index ec5aa22..4857752 100644 --- a/LiMan.UI/Data/LiManDataService.cs +++ b/LiMan.UI/Data/LiManDataService.cs @@ -12,6 +12,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using NLog; +using Org.BouncyCastle.Asn1.Pkcs; using StackExchange.Redis; using System; using System.Collections.Generic; @@ -287,7 +288,6 @@ namespace LiMan.UI.Data { Log.Error($"Error during AuthClaimByUserID:{Environment.NewLine}{exc}"); } - //return await Task.FromResult(dbResult); return dbResult; } @@ -934,6 +934,54 @@ namespace LiMan.UI.Data /// public async Task> ReleaseGetByApp(string CodApp) { + string source = "DB"; + List? dbResult = new List(); + try + { + string currKey = $"{Const.rKeyConfig}:App:AllRel:{CodApp}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbControllerNext.ReleaseGetByApp(CodApp); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + // per evitare loopback uso deserialize... + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult != null) + { + dbResult = tempResult; + } + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ReleaseGetByApp | {source} in: {ts.TotalMilliseconds} ms"); + } + catch (Exception exc) + { + Log.Error($"Error during ReleaseGetByApp:{Environment.NewLine}{exc}"); + } + return dbResult; + +#if false await Task.Delay(1); List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); @@ -942,7 +990,39 @@ namespace LiMan.UI.Data stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per ReleaseGetByApp | {CodApp} | {ts.TotalMilliseconds} ms"); - return dbResult; + return dbResult; +#endif + } + + /// + /// Ultima Release dato Applicativo + /// + /// Codice Applicazione + /// + public async Task ReleaseLastGetByApp(string CodApp) + { + string answ = ""; + RedisKey currKey = $"{Const.rKeyConfig}:App:CurrRel"; + var rawVal = await redisDb.HashGetAsync(currKey, CodApp); + if (rawVal.HasValue) + { + answ = $"{rawVal}"; + } + else + { + var rawList = await ReleaseGetByApp(CodApp); + if (rawList != null) + { + var lastRel = rawList + .OrderByDescending(x => x.VersVal) + .ThenByDescending(x => x.ReleaseDate) + .FirstOrDefault() ?? new ReleaseModel() { CodApp = CodApp }; + answ = lastRel.VersNum; + // salvo su redis tab... + await redisDb.HashSetAsync(currKey, CodApp, answ); + } + } + return answ; } /// diff --git a/LiMan.UI/LiMan.UI.csproj b/LiMan.UI/LiMan.UI.csproj index fb648ba..f48cf8f 100644 --- a/LiMan.UI/LiMan.UI.csproj +++ b/LiMan.UI/LiMan.UI.csproj @@ -2,7 +2,7 @@ net6.0 - 1.1.2409.1807 + 1.1.2409.1910 LiMan.UI LiMan.UI diff --git a/LiMan.UI/Resources/ChangeLog.html b/LiMan.UI/Resources/ChangeLog.html index d997f84..21bb0bd 100644 --- a/LiMan.UI/Resources/ChangeLog.html +++ b/LiMan.UI/Resources/ChangeLog.html @@ -1,6 +1,6 @@ License Manager -

    Versione: 1.1.2409.1807

    +

    Versione: 1.1.2409.1910


    Note di rilascio:
    • diff --git a/LiMan.UI/Resources/VersNum.txt b/LiMan.UI/Resources/VersNum.txt index e130097..2c7f5a0 100644 --- a/LiMan.UI/Resources/VersNum.txt +++ b/LiMan.UI/Resources/VersNum.txt @@ -1 +1 @@ -1.1.2409.1807 +1.1.2409.1910 diff --git a/LiMan.UI/Resources/manifest.xml b/LiMan.UI/Resources/manifest.xml index 7ed87fd..5f8f799 100644 --- a/LiMan.UI/Resources/manifest.xml +++ b/LiMan.UI/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.1.2409.1807 + 1.1.2409.1910 https://nexus.steamware.net/repository/SWS/LiMan/stable/LAST/LiMan.UI.zip https://nexus.steamware.net/repository/SWS/LiMan/stable/LAST/ChangeLog.html false