diff --git a/MP.MONO.UI/Components/MachStatsOverview.razor.cs b/MP.MONO.UI/Components/MachStatsOverview.razor.cs
index 8a33575..b85ae97 100644
--- a/MP.MONO.UI/Components/MachStatsOverview.razor.cs
+++ b/MP.MONO.UI/Components/MachStatsOverview.razor.cs
@@ -44,7 +44,7 @@ namespace MP.MONO.UI.Components
protected async Task ReloadData()
{
- ListRecords = await MMDataService.MachineDisplay();
+ ListRecords = await MMDataService.MachineStats();
}
#endregion Protected Methods
diff --git a/MP.MONO.UI/Components/ParamOverview.razor b/MP.MONO.UI/Components/ParamOverview.razor
index ad2284c..e8e27b4 100644
--- a/MP.MONO.UI/Components/ParamOverview.razor
+++ b/MP.MONO.UI/Components/ParamOverview.razor
@@ -4,7 +4,7 @@
@inject CurrentDataService MMDataService
-@if (ListRecords != null && ListRecords.Count>0)
+@if (ListRecords != null && ListRecords.Count > 0)
{
@foreach (var item in ListRecords)
diff --git a/MP.MONO.UI/Components/ParamOverview.razor.cs b/MP.MONO.UI/Components/ParamOverview.razor.cs
index 6fc3850..113acc9 100644
--- a/MP.MONO.UI/Components/ParamOverview.razor.cs
+++ b/MP.MONO.UI/Components/ParamOverview.razor.cs
@@ -45,7 +45,7 @@ namespace MP.MONO.UI.Components
protected async Task ReloadData()
{
await Task.Delay(1);
- ListRecords = await MMDataService.MachineDisplay();
+ ListRecords = await MMDataService.MachineParameters();
await Task.Delay(1);
}
diff --git a/MP.MONO.UI/Components/ToolsOverview.razor b/MP.MONO.UI/Components/ToolsOverview.razor
index 171a255..7a31dac 100644
--- a/MP.MONO.UI/Components/ToolsOverview.razor
+++ b/MP.MONO.UI/Components/ToolsOverview.razor
@@ -4,7 +4,7 @@
@inject CurrentDataService MMDataService
-@if (@dataLoaded && ListRecords != null)
+@if (ListRecords != null && ListRecords.Count > 0)
{
@foreach (var item in ListRecords)
@@ -24,26 +24,9 @@
else
{
- - Tool Life
- - Tool Management
-
+ - Tool Life
+ - Tool Management
+
}
-@code {
- protected bool dataLoaded = false;
- private List? ListRecords { get; set; } = null;
- protected override async Task OnInitializedAsync()
- {
- await ReloadData();
- }
-
- protected async Task ReloadData()
- {
- //await Task.Delay(10);
- //ListRecords = await MMDataService.MachineDisplay();
- await Task.Delay(500);
- dataLoaded = true;
- }
-
-}
diff --git a/MP.MONO.UI/Components/ToolsOverview.razor.cs b/MP.MONO.UI/Components/ToolsOverview.razor.cs
new file mode 100644
index 0000000..39558c6
--- /dev/null
+++ b/MP.MONO.UI/Components/ToolsOverview.razor.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Components;
+using System.Net.Http;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Components.Authorization;
+using Microsoft.AspNetCore.Components.Forms;
+using Microsoft.AspNetCore.Components.Routing;
+using Microsoft.AspNetCore.Components.Web;
+using Microsoft.AspNetCore.Components.Web.Virtualization;
+using Microsoft.JSInterop;
+using MP.MONO.UI;
+using MP.MONO.UI.Shared;
+using MP.MONO.UI.Components;
+using MP.MONO.Core.DTO;
+using MP.MONO.UI.Data;
+using Newtonsoft.Json;
+using MP.MONO.Data;
+
+namespace MP.MONO.UI.Components
+{
+ public partial class ToolsOverview
+ {
+ private List? ListRecords { get; set; } = null;
+ protected override async Task OnInitializedAsync()
+ {
+ await ReloadData();
+ MMDataService.toolsPipe.EA_NewMessage += ToolsPipe_EA_NewMessage;
+ }
+
+ private void ToolsPipe_EA_NewMessage(object? sender, EventArgs e)
+ {
+ PubSubEventArgs currArgs = (PubSubEventArgs)e;
+ if (!string.IsNullOrEmpty(currArgs.newMessage))
+ {
+ try
+ {
+ ListRecords = JsonConvert.DeserializeObject>(currArgs.newMessage);
+ }
+ catch
+ { }
+ }
+ InvokeAsync(() =>
+ {
+ StateHasChanged();
+ });
+ }
+
+ protected async Task ReloadData()
+ {
+ ListRecords = new List();
+ }
+ }
+}
\ No newline at end of file
diff --git a/MP.MONO.UI/Data/CurrentDataService.cs b/MP.MONO.UI/Data/CurrentDataService.cs
index 361e17f..1e424c9 100644
--- a/MP.MONO.UI/Data/CurrentDataService.cs
+++ b/MP.MONO.UI/Data/CurrentDataService.cs
@@ -6,9 +6,6 @@ using MP.MONO.Data.Controllers;
using Newtonsoft.Json;
using NLog;
using StackExchange.Redis;
-using System.Diagnostics;
-using System.Text;
-using StackExchange.Redis;
namespace MP.MONO.UI.Data
{
@@ -19,28 +16,18 @@ namespace MP.MONO.UI.Data
private static IConfiguration _configuration;
private static ILogger _logger;
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
- private readonly IDistributedCache distributedCache;
+
///
/// Oggetto per connessione a REDIS
///
private ConnectionMultiplexer redisConn = null!;
+
//ISubscriber sub = redis.GetSubscriber();
///
/// Oggetto DB redis da impiegare x chiamate R/W
///
private IDatabase redisDb = null!;
- ///
- /// Durata assoluta massima della cache IN SECONDI
- ///
- private int chAbsExp = 60 * 5;
-
- ///
- /// Durata della cache IN SECONDI in modalità inattiva (non acceduta) prima di venire rimossa
- /// NON estende oltre il tempo massimo di validità della cache (chAbsExp)
- ///
- private int chSliExp = 60 * 1;
-
#endregion Private Fields
#region Public Fields
@@ -52,17 +39,9 @@ namespace MP.MONO.UI.Data
#endregion Public Fields
-
- public MessagePipe alarmPipe { get; set; } = null!;
- public MessagePipe parametersPipe { get; set; } = null!;
- public MessagePipe statusPipe { get; set; } = null!;
- public MessagePipe productionPipe { get; set; } = null!;
- public MessagePipe machStatsPipe { get; set; } = null!;
- public MessagePipe maintPipe { get; set; } = null!;
-
#region Public Constructors
- public CurrentDataService(IConfiguration configuration, ILogger logger, IDistributedCache distributedCache, IConnectionMultiplexer redisConn)
+ public CurrentDataService(IConfiguration configuration, ILogger logger, IConnectionMultiplexer redisConn)
{
_logger = logger;
_configuration = configuration;
@@ -77,9 +56,7 @@ namespace MP.MONO.UI.Data
productionPipe = new MessagePipe(redisConn, "production");
machStatsPipe = new MessagePipe(redisConn, "machstats");
maintPipe = new MessagePipe(redisConn, "maintenance");
-
- // conf cache
- this.distributedCache = distributedCache;
+ toolsPipe = new MessagePipe(redisConn, "tools");
// conf DB
string connStr = _configuration.GetConnectionString("MP.MONO.Data");
@@ -96,13 +73,17 @@ namespace MP.MONO.UI.Data
#endregion Public Constructors
- #region Protected Properties
+ #region Public Properties
-#if false
- protected Dictionary? ParametersList { get; set; } = new Dictionary();
-#endif
+ public MessagePipe alarmPipe { get; set; } = null!;
+ public MessagePipe machStatsPipe { get; set; } = null!;
+ public MessagePipe maintPipe { get; set; } = null!;
+ public MessagePipe parametersPipe { get; set; } = null!;
+ public MessagePipe productionPipe { get; set; } = null!;
+ public MessagePipe statusPipe { get; set; } = null!;
+ public MessagePipe toolsPipe { get; set; } = null!;
- #endregion Protected Properties
+ #endregion Public Properties
#region Private Methods
@@ -116,13 +97,6 @@ namespace MP.MONO.UI.Data
return $"MAPO-MONO:{dataType}";
}
- private DistributedCacheEntryOptions cacheOpt(bool fastCache)
- {
- var numSecAbsExp = fastCache ? chAbsExp : chAbsExp * 10;
- var numSecSliExp = fastCache ? chSliExp : chSliExp * 10;
- return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddSeconds(numSecAbsExp)).SetSlidingExpiration(TimeSpan.FromSeconds(numSecSliExp));
- }
-
#endregion Private Methods
#region Public Methods
@@ -133,27 +107,23 @@ namespace MP.MONO.UI.Data
dbController.Dispose();
}
-#if false
- public async Task> GetCurrentParameters()
+ public async Task> MachineStats()
{
- ParametersList = new Dictionary();
- string cacheKey = mHash("Machine:Parameters:Current");
+ List? dbResult = new List();
+ string cacheKey = mHash("Machine:MachStats:Current");
string rawData = await redisDb.StringGetAsync(cacheKey);
if (!string.IsNullOrEmpty(rawData))
{
- ParametersList = JsonConvert.DeserializeObject>(rawData);
+ dbResult = JsonConvert.DeserializeObject>(rawData);
}
- else
+ if (dbResult == null)
{
- ParametersList = simGen.GetCurrentParameters();
- rawData = JsonConvert.SerializeObject(ParametersList);
- await redisDb.StringSetAsync(cacheKey, rawData);
+ dbResult = new List();
}
- return ParametersList;
- }
-#endif
+ return await Task.FromResult(dbResult);
+ }
- public async Task> MachineDisplay()
+ public async Task> MachineParameters()
{
List? dbResult = new List();
string cacheKey = mHash("Machine:Parameters:Current");
@@ -162,45 +132,10 @@ namespace MP.MONO.UI.Data
{
dbResult = JsonConvert.DeserializeObject>(rawData);
}
-#if false
- else
- {
- dbResult = simGen.MachineGetParameters();
- rawData = JsonConvert.SerializeObject(dbResult);
- await redisDb.StringSetAsync(cacheKey, rawData);
- }
-#endif
if (dbResult == null)
{
dbResult = new List();
}
-#if false
-
- 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();
- }
-#endif
return await Task.FromResult(dbResult);
}
@@ -213,29 +148,6 @@ namespace MP.MONO.UI.Data
{
dbResult = JsonConvert.DeserializeObject(rawData);
}
-
-#if false
- 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.MachineGetProd();
- 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 MachineProd: {ts.TotalMilliseconds} ms");
- }
-#endif
if (dbResult == null)
{
dbResult = new ProductionDTO();
@@ -252,14 +164,6 @@ namespace MP.MONO.UI.Data
{
dbResult = JsonConvert.DeserializeObject(rawData);
}
-#if false
- else
- {
- dbResult = simGen.MachineGetStatus();
- rawData = JsonConvert.SerializeObject(dbResult);
- redisDb.StringSetAsync(cacheKey, rawData);
- }
-#endif
if (dbResult == null)
{
dbResult = new MachineDTO();
diff --git a/MachineSim/MachineSim.csproj b/MachineSim/MachineSim.csproj
index 1f612d7..327309a 100644
--- a/MachineSim/MachineSim.csproj
+++ b/MachineSim/MachineSim.csproj
@@ -24,6 +24,9 @@
Always
+
+ Always
+
Always
diff --git a/MachineSim/Program.cs b/MachineSim/Program.cs
index 7b42843..1178c63 100644
--- a/MachineSim/Program.cs
+++ b/MachineSim/Program.cs
@@ -160,7 +160,6 @@ void simMachStat()
void simMaint()
{
- // FIXME TODO !!!
int minPeriod = 3000;
int maxPeriod = 5000;
@@ -185,7 +184,7 @@ void simTools()
do
{
// recupero uno stato simulato
- var newVal = currSimGen.getProdStats();
+ var newVal = currSimGen.getTools();
string rawData = JsonConvert.SerializeObject(newVal);
saveAndSendMessage(mHash("Machine:Tools:Current"), rawData, "tools", rawData);
diff --git a/MachineSim/SimMaint.json b/MachineSim/SimMaint.json
index 16a56cc..5c4b2e4 100644
--- a/MachineSim/SimMaint.json
+++ b/MachineSim/SimMaint.json
@@ -22,5 +22,5 @@
"SimMean": -1,
"SimStd": 1,
"DisplFormat": "N0"
- },
+ }
]
\ No newline at end of file
diff --git a/MachineSim/SimTools.json b/MachineSim/SimTools.json
new file mode 100644
index 0000000..90f4a95
--- /dev/null
+++ b/MachineSim/SimTools.json
@@ -0,0 +1,38 @@
+[
+ {
+ "Order": 0,
+ "Type": "TOOL",
+ "Title": "Tool 01 life",
+ "Value": "1000",
+ "ValueNum": 1000,
+ "MinVal": 0,
+ "MaxVal": 2000,
+ "SimMean": -1,
+ "SimStd": 1,
+ "DisplFormat": "N1"
+ },
+ {
+ "Order": 1,
+ "Type": "TOOL",
+ "Title": "Tool 02 life",
+ "Value": "800",
+ "ValueNum": 800,
+ "MinVal": 0,
+ "MaxVal": 2000,
+ "SimMean": -1,
+ "SimStd": 1,
+ "DisplFormat": "N1"
+ },
+ {
+ "Order": 2,
+ "Type": "TOOL",
+ "Title": "Tool 03 life",
+ "Value": "700",
+ "ValueNum": 700,
+ "MinVal": 0,
+ "MaxVal": 2000,
+ "SimMean": -1,
+ "SimStd": 1,
+ "DisplFormat": "N1"
+ }
+]
\ No newline at end of file
diff --git a/MachineSim/Simulator.cs b/MachineSim/Simulator.cs
index 7454617..908ee22 100644
--- a/MachineSim/Simulator.cs
+++ b/MachineSim/Simulator.cs
@@ -16,7 +16,7 @@ namespace MachineSim
protected List currSimMachStat = new List();
protected List currSimMaint = new List();
protected List currSimPar = new List();
- protected string paramFileName = "SimParams.json";
+ protected List currSimTools = new List();
protected Random rand = new Random();
@@ -55,6 +55,8 @@ namespace MachineSim
setupConf("SimMachStat.json", ref currSimMachStat);
// setup conf Maintenance
setupConf("SimMaint.json", ref currSimMaint);
+ // setup conf Tools
+ setupConf("SimTools.json", ref currSimTools);
}
#endregion Private Methods
@@ -172,6 +174,32 @@ namespace MachineSim
return answ;
}
+ public List getTools()
+ {
+ List answ = new List();
+
+ // genero a partire dall'elenco configurato da simulare...
+ answ = currSimTools.Select(i => new DisplayDataDTO()
+ {
+ IsNumeric = i.IsNumeric,
+ MaxVal = i.MaxVal,
+ MinVal = i.MinVal,
+ Order = i.Order,
+ Title = i.Title,
+ Type = i.Type,
+ ValueNum = simNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd),
+ DisplFormat = i.DisplFormat
+ //Value = $"{getNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd):N3}",
+ }).ToList();
+
+ foreach (var item in answ)
+ {
+ item.Value = $"{item.ValueNum.ToString(item.DisplFormat)}";
+ }
+
+ return answ;
+ }
+
///
/// Restituisce stato Macchina simulato come DTO
///