From ddfbe3b03237f910cbb1d732cdb2b4028a580000 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 14 Feb 2022 19:20:31 +0100 Subject: [PATCH] refresh gestione caricamento dati SIM --- MP.MONO.Data/Controllers/MpDbController.cs | 61 ++++++++++++++++++++++ MP.MONO.UI.sln | 2 +- MP.MONO.UI/Data/CurrentDataService.cs | 39 +++++++++++--- MP.MONO.UI/Pages/_Layout.cshtml | 1 + MP.MONO.UI/Shared/LoginDisplay.razor | 14 ----- MP.MONO.UI/libman.json | 33 ++++++------ 6 files changed, 113 insertions(+), 37 deletions(-) delete mode 100644 MP.MONO.UI/Shared/LoginDisplay.razor diff --git a/MP.MONO.Data/Controllers/MpDbController.cs b/MP.MONO.Data/Controllers/MpDbController.cs index d65a455..a60c9c0 100644 --- a/MP.MONO.Data/Controllers/MpDbController.cs +++ b/MP.MONO.Data/Controllers/MpDbController.cs @@ -75,5 +75,66 @@ namespace MP.MONO.Data.Controllers return currMachDto; } + + public List MachineGetDisplay() + { + List answ = new List(); + + // !!!FIXME TODO... è fake... + + Random rand = new Random(); + int stdCycle = 5; + + DisplayDataDTO displ01 = new DisplayDataDTO() + { + Order = 0, + Title = "OEE", + ValueNum = rand.NextDouble(), + IsNumeric = true, + Value = "", + Type = "OEE-75-90" + }; + answ.Add(displ01); + + DisplayDataDTO displ02 = new DisplayDataDTO() + { + Order = 0, + Title = "Avail", + ValueNum = rand.NextDouble(), + IsNumeric = true, + Value = "", + Type = "AVAIL-50-80" + }; + answ.Add(displ02); + + DisplayDataDTO displ03 = new DisplayDataDTO() + { + Order = 0, + Title = "Order fulfill", + ValueNum = rand.NextDouble(), + IsNumeric = true, + Value = "", + Type = "ORDER" + }; + answ.Add(displ03); + + double minTCiclo = stdCycle * rand.NextDouble(); + TimeSpan durTCycle = TimeSpan.FromMinutes(minTCiclo); + DisplayDataDTO displ04 = new DisplayDataDTO() + { + Order = 0, + Title = "Cycle time", + ValueNum = 0, + IsNumeric = false, + Value = $"{durTCycle.Hours:00}:{durTCycle.Minutes:00}:{durTCycle.Seconds:00}", + Type = "TCycle" + }; + answ.Add(displ03); + + + Task.Delay(200).Wait(); + + return answ; + } } } diff --git a/MP.MONO.UI.sln b/MP.MONO.UI.sln index 8c44105..dd60750 100644 --- a/MP.MONO.UI.sln +++ b/MP.MONO.UI.sln @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.MONO.UI", "MP.MONO.UI\MP EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.MONO.Data", "MP.MONO.Data\MP.MONO.Data.csproj", "{60EB575C-1E63-4A29-B233-5E661F2D2387}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.MONO.Core", "MP.MONO.Core\MP.MONO.Core.csproj", "{7DE649D8-511E-4674-A170-7E7AFDE4FD89}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.MONO.Core", "MP.MONO.Core\MP.MONO.Core.csproj", "{7DE649D8-511E-4674-A170-7E7AFDE4FD89}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/MP.MONO.UI/Data/CurrentDataService.cs b/MP.MONO.UI/Data/CurrentDataService.cs index 736c21d..6bd7703 100644 --- a/MP.MONO.UI/Data/CurrentDataService.cs +++ b/MP.MONO.UI/Data/CurrentDataService.cs @@ -1,4 +1,3 @@ -using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Memory; using MP.MONO.Core.DTO; @@ -17,9 +16,7 @@ namespace MP.MONO.UI.Data private static IConfiguration _configuration; private static ILogger _logger; private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - private readonly IEmailSender _emailSender; private readonly IDistributedCache distributedCache; - private readonly IMemoryCache memoryCache; /// /// Durata assoluta massima della cache IN SECONDI @@ -42,13 +39,11 @@ namespace MP.MONO.UI.Data #region Public Constructors - public CurrentDataService(IConfiguration configuration, ILogger logger, IMemoryCache memoryCache, IDistributedCache distributedCache, IEmailSender emailSender) + public CurrentDataService(IConfiguration configuration, ILogger logger, IDistributedCache distributedCache) { _logger = logger; _configuration = configuration; - _emailSender = emailSender; // conf cache - this.memoryCache = memoryCache; this.distributedCache = distributedCache; // conf DB string connStr = _configuration.GetConnectionString("MP.MONO.Data"); @@ -174,6 +169,38 @@ namespace MP.MONO.UI.Data } return await Task.FromResult(dbResult); } + public async Task> MachineDisplay() + { + List? dbResult = new List(); + string cacheKey = mHash("MAPO.MONO:Machine:DisplayData"); + string rawData; + var redisDataList = await distributedCache.GetAsync(cacheKey); + if (redisDataList != null) + { + rawData = Encoding.UTF8.GetString(redisDataList); + dbResult = JsonConvert.DeserializeObject>(rawData); + } + else + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + dbResult = dbController.MachineGetDisplay(); + rawData = JsonConvert.SerializeObject(dbResult); + redisDataList = Encoding.UTF8.GetBytes(rawData); + // tolgo salvataggio x sim meglio + //await distributedCache.SetAsync(cacheKey, redisDataList, cacheOpt(true)); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Effettuata lettura da DB + caching per MachineDisplay: {ts.TotalMilliseconds} ms"); + } + if (dbResult == null) + { + dbResult = new List(); + } + return await Task.FromResult(dbResult); + } + + #endregion Public Methods } diff --git a/MP.MONO.UI/Pages/_Layout.cshtml b/MP.MONO.UI/Pages/_Layout.cshtml index d21c150..08b4661 100644 --- a/MP.MONO.UI/Pages/_Layout.cshtml +++ b/MP.MONO.UI/Pages/_Layout.cshtml @@ -10,6 +10,7 @@ + diff --git a/MP.MONO.UI/Shared/LoginDisplay.razor b/MP.MONO.UI/Shared/LoginDisplay.razor deleted file mode 100644 index f4c2396..0000000 --- a/MP.MONO.UI/Shared/LoginDisplay.razor +++ /dev/null @@ -1,14 +0,0 @@ - -
-
- Machine Status: RUNNING -
-
- OEE: 77% -
-
- - @context.User.Identity?.Name! - -
-
diff --git a/MP.MONO.UI/libman.json b/MP.MONO.UI/libman.json index bd88948..4ba7756 100644 --- a/MP.MONO.UI/libman.json +++ b/MP.MONO.UI/libman.json @@ -9,21 +9,22 @@ { "library": "bootstrap-icons@1.7.2", "destination": "wwwroot/lib/bootstrap-icons/" + }, + { + "library": "Chart.js@3.7.0", + "destination": "wwwroot/lib/Chart.js/" + }, + { + "library": "luxon@2.3.0", + "destination": "wwwroot/lib/luxon/" + }, + { + "library": "chartjs-adapter-luxon@1.1.0", + "destination": "wwwroot/lib/chartjs-adapter-luxon/" + }, + { + "library": "font-awesome@6.0.0", + "destination": "wwwroot/lib/font-awesome/" } - , -{ - "library": "Chart.js@3.7.0", - "destination": "wwwroot/lib/Chart.js/" -} -, -{ - "library": "luxon@2.3.0", - "destination": "wwwroot/lib/luxon/" -} -, -{ - "library": "chartjs-adapter-luxon@1.1.0", - "destination": "wwwroot/lib/chartjs-adapter-luxon/" -} -] + ] } \ No newline at end of file