refresh gestione caricamento dati SIM

This commit is contained in:
Samuele Locatelli
2022-02-14 19:20:31 +01:00
parent 635041014c
commit ddfbe3b032
6 changed files with 113 additions and 37 deletions
@@ -75,5 +75,66 @@ namespace MP.MONO.Data.Controllers
return currMachDto;
}
public List<DisplayDataDTO> MachineGetDisplay()
{
List<DisplayDataDTO> answ = new List<DisplayDataDTO>();
// !!!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;
}
}
}
+1 -1
View File
@@ -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
+33 -6
View File
@@ -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<CurrentDataService> _logger;
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
private readonly IEmailSender _emailSender;
private readonly IDistributedCache distributedCache;
private readonly IMemoryCache memoryCache;
/// <summary>
/// Durata assoluta massima della cache IN SECONDI
@@ -42,13 +39,11 @@ namespace MP.MONO.UI.Data
#region Public Constructors
public CurrentDataService(IConfiguration configuration, ILogger<CurrentDataService> logger, IMemoryCache memoryCache, IDistributedCache distributedCache, IEmailSender emailSender)
public CurrentDataService(IConfiguration configuration, ILogger<CurrentDataService> 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<List<DisplayDataDTO>> MachineDisplay()
{
List<DisplayDataDTO>? dbResult = new List<DisplayDataDTO>();
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<List<DisplayDataDTO>>(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<DisplayDataDTO>();
}
return await Task.FromResult(dbResult);
}
#endregion Public Methods
}
+1
View File
@@ -10,6 +10,7 @@
<base href="~/" />
<link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="css/site.min.css" />
<link rel="stylesheet"href="lib/font-awesome/css/all.css" />
<link rel="stylesheet" href="lib/bootstrap-icons/font/bootstrap-icons.min.css" />
<link rel="stylesheet"href="MP.MONO.UI.styles.css" />
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
-14
View File
@@ -1,14 +0,0 @@
<div class="d-flex justify-content-between w-100">
<div class="px-2">
Machine Status: <b>RUNNING</b>
</div>
<div class="px-2">
<b>OEE: 77%</b>
</div>
<div class="px-2">
<AuthorizeView>
<i class="bi bi-person-badge"></i> @context.User.Identity?.Name!
</AuthorizeView>
</div>
</div>
+17 -16
View File
@@ -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/"
}
]
]
}