Merge branch 'release/AdapterFormUpdate_06'

This commit is contained in:
Samuele Locatelli
2026-05-26 14:52:59 +02:00
8 changed files with 130 additions and 184 deletions
-1
View File
@@ -34,4 +34,3 @@ CLI_INST=SteamWareSim
STARTLIST=SIMUL_02
MAXCNC=10
+130 -177
View File
@@ -35,18 +35,6 @@ namespace IOB_WIN_FORM
#endregion Public Fields
public void ForceUpdateUI()
{
// aggiorna UI (log, grid, label…)
this.UIThread(delegate
{
bIN.BackColor = decSemaforo(_sIN);
bOUT.BackColor = decSemaforo(_sOUT);
});
}
#region Public Constructors
/// <summary>
@@ -165,10 +153,6 @@ namespace IOB_WIN_FORM
public string counterIob
{
get
{
return lblPzCountIob.Text;
}
set
{
this.UIThread(delegate
@@ -180,10 +164,6 @@ namespace IOB_WIN_FORM
public string counterMac
{
get
{
return lblPzCountMac.Text;
}
set
{
this.UIThread(delegate
@@ -198,12 +178,9 @@ namespace IOB_WIN_FORM
/// </summary>
public string dataProcLabel
{
get
{
return lblDataProc.Text;
}
set
{
if (!ShouldUpdateUI()) return;
this.UIThread(delegate
{
lblDataProc.Text = value;
@@ -221,18 +198,18 @@ namespace IOB_WIN_FORM
/// </summary>
public int nLine2show
{
get
{
int answ = 5;
Int32.TryParse(nLines.Text, out answ);
return answ;
}
get => _nLine2show = 5;
set
{
this.UIThread(delegate
if (_nLine2show != value)
{
nLines.Text = value.ToString();
});
_nLine2show = value;
if (!ShouldUpdateUI()) return;
this.UIThread(delegate
{
nLines.Text = value.ToString();
});
}
}
}
@@ -283,10 +260,18 @@ namespace IOB_WIN_FORM
}
}
}
/// <summary>
/// Coda messaggi task
/// tipo di adapter prescelto...
/// </summary>
private readonly Queue<string> logTaskQueue = new Queue<string>();
public tipoAdapter tipoScelto
{
get => IOBConfFull != null ? IOBConfFull.General.IobType : tipoAdapter.ND;
}
#endregion Public Properties
#region Public Methods
/// <summary>
/// Task watcher (in modalità "accodamento in testa" ultimi messaggi...)
@@ -301,8 +286,7 @@ namespace IOB_WIN_FORM
logTaskQueue.Enqueue(value);
if (!ShouldUpdateUI())
return;
if (!ShouldUpdateUI()) return;
// snapshot + reverse per mostrare latest in alto
var text = string.Join(
@@ -324,18 +308,6 @@ namespace IOB_WIN_FORM
}
}
/// <summary>
/// tipo di adapter prescelto...
/// </summary>
public tipoAdapter tipoScelto
{
get => IOBConfFull != null ? IOBConfFull.General.IobType : tipoAdapter.ND;
}
#endregion Public Properties
#region Public Methods
/// <summary>
/// Registra variazione error delay in caso di errori o successi
/// </summary>
@@ -395,6 +367,17 @@ namespace IOB_WIN_FORM
fermaTutto(false, tryRestart, forceDequeue, updateForm);
}
public void ForceUpdateUI()
{
// aggiorna UI (log, grid, label…)
this.UIThread(delegate
{
bIN.BackColor = decSemaforo(_sIN);
bOUT.BackColor = decSemaforo(_sOUT);
refreshFormData();
});
}
/// <summary>
/// Mostra update delle statistiche di comunicazione (numero chiamate, tempo medio...)
/// </summary>
@@ -517,6 +500,19 @@ namespace IOB_WIN_FORM
/// </summary>
protected DateTime lastStartTry;
protected long maxAlQueue = 0;
protected long maxEvQueue = 0;
protected long maxFlQueue = 0;
protected long maxMsQueue = 0;
protected long maxRwTrQueue = 0;
protected long maxUlQueue = 0;
protected long qAlLen = 0;
protected long qEvLen = 0;
protected long qFlLen = 0;
protected long qMsLen = 0;
protected long qRTrLen = 0;
protected long qUlLen = 0;
/// <summary>
/// Generatore numeri random
/// </summary>
@@ -566,8 +562,6 @@ namespace IOB_WIN_FORM
set
{
qAlLen = value;
lblQueueAlarmLen.Text = qAlLen.ToString();
showQueueData();
// se supero max precedente, ed è > 10... loggo!
if (qAlLen > maxAlQueue && qAlLen > 10)
{
@@ -579,6 +573,9 @@ namespace IOB_WIN_FORM
maxAlQueue--;
maxAlQueue = maxAlQueue < qAlLen ? qAlLen : maxAlQueue;
}
if (!ShouldUpdateUI()) return;
lblQueueAlarmLen.Text = qAlLen.ToString();
showQueueData();
}
get
{
@@ -642,53 +639,17 @@ namespace IOB_WIN_FORM
/// </summary>
protected DateTime logWatchWriteVeto { get; set; } = DateTime.Now;
protected long maxAlQueue { get; set; }
protected long maxEvQueue { get; set; }
protected long maxFlQueue { get; set; }
protected long maxMsQueue { get; set; }
protected long maxRwTrQueue { get; set; }
protected long maxUlQueue { get; set; }
protected long qAlLen { get; set; }
protected long qEvLen { get; set; }
protected long qFlLen { get; set; }
protected long qMsLen { get; set; }
protected long qRTrLen { get; set; }
protected long qUlLen { get; set; }
protected long totQueue
{
get
{
return qEvLen + qFlLen + qAlLen + qMsLen + qUlLen;
}
}
protected long totQueue => qEvLen + qFlLen + qAlLen + qMsLen + qUlLen;
/// <summary>
/// URL per salvare i file dell'IOB (SENZA IOB)
/// </summary>
protected string urlUploadFile
{
get => $"http://{IOBConfFull.MapoMes.IpAddr}{IOBConfFull.MapoMes.BaseAppUrl}IOB/uploadFile/";
}
protected string urlUploadFile => $"http://{IOBConfFull.MapoMes.IpAddr}{IOBConfFull.MapoMes.BaseAppUrl}IOB/uploadFile/";
/// <summary>
/// URL per salvare i file dell'IOB su CLOUD (SENZA IOB)
/// </summary>
protected string urlUploadFileCloud
{
get => $"{baseUrl}IOB/uploadFile/";
}
protected string urlUploadFileCloud => $"{baseUrl}IOB/uploadFile/";
#endregion Protected Properties
@@ -740,22 +701,6 @@ namespace IOB_WIN_FORM
});
}
private IDisposable _scopeIOB;
/// <summary>
/// Salvo IOB e scope x NLog management
/// </summary>
/// <param name="newIOB"></param>
private void SetIOB(string newIOB)
{
CurrIOB = newIOB;
_scopeIOB?.Dispose(); // rimuove il vecchio valore
_scopeIOB = ScopeContext.PushProperty("codIOB", newIOB);
}
/// <summary>
/// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere...
/// </summary>
@@ -885,6 +830,7 @@ namespace IOB_WIN_FORM
/// </summary>
protected void showQueueData()
{
if (!ShouldUpdateUI()) return;
lblQueueLenTop.Text = totQueue == 0 ? "realtime" : $"ev: {qEvLen} | flog: {qFlLen} | tot: {totQueue}";
}
@@ -893,9 +839,6 @@ namespace IOB_WIN_FORM
/// </summary>
protected void UpdateDisplTypeIobSel()
{
lblCNC.Text = $"CNC: {IOBConfFull.General.IobType} [{IOBConfFull.Device.Connect.IpAddr}:{IOBConfFull.Device.Connect.Port}]";
lblSrvUrlText = $"SRV: {IOBConfFull.MapoMes.IpAddr} | BaseURL: {IOBConfFull.MapoMes.ApiUrl("")}";
// aggancio evento refresh
iobObj.eh_refreshed -= IobObj_eh_refreshed;
iobObj.eh_refreshed += IobObj_eh_refreshed;
@@ -904,6 +847,10 @@ namespace IOB_WIN_FORM
setDefaults();
displayTaskAndLog($"Caricata conf per adapter {tipoScelto}");
if (!ShouldUpdateUI()) return;
lblCNC.Text = $"CNC: {IOBConfFull.General.IobType} [{IOBConfFull.Device.Connect.IpAddr}:{IOBConfFull.Device.Connect.Port}]";
lblSrvUrl.Text = $"SRV: {IOBConfFull.MapoMes.IpAddr} | BaseURL: {IOBConfFull.MapoMes.ApiUrl("")}";
}
#endregion Protected Methods
@@ -934,6 +881,11 @@ namespace IOB_WIN_FORM
private readonly object _threadLock = new object();
/// <summary>
/// Coda messaggi task
/// </summary>
private readonly Queue<string> logTaskQueue = new Queue<string>();
/// <summary>
/// Cancellation token x processi verso macchina
/// </summary>
@@ -958,10 +910,10 @@ namespace IOB_WIN_FORM
private bool _isSuspended = false;
private FormWindowState _lastState = FormWindowState.Minimized;
private Thread _machineThread;
private int _nLine2show = 5;
private Task _redisTask;
private IDisposable _scopeIOB;
private Task _workerTask;
@@ -1012,35 +964,17 @@ namespace IOB_WIN_FORM
/// <summary>
/// File configurazione default
/// </summary>
private string defConfFilePath
{
get
{
return Path.Combine(utils.confDir, $"{CurrIOB}.ini");
}
}
private string defConfFilePath => Path.Combine(utils.confDir, $"{CurrIOB}.ini");
/// <summary>
/// File configurazione json (completo) se presente
/// </summary>
private string defConfFilePathJson
{
get
{
return Path.Combine(utils.confDir, $"{CurrIOB}.json");
}
}
private string defConfFilePathJson => Path.Combine(utils.confDir, $"{CurrIOB}.json");
/// <summary>
/// File configurazione yaml (completo) se presente
/// </summary>
private string defConfFilePathYaml
{
get
{
return Path.Combine(utils.confDir, $"{CurrIOB}.yaml");
}
}
private string defConfFilePathYaml => Path.Combine(utils.confDir, $"{CurrIOB}.yaml");
private bool enableEditMes2Plc { get; set; }
@@ -1049,8 +983,6 @@ namespace IOB_WIN_FORM
set
{
qEvLen = value;
lblQueueLen.Text = qEvLen.ToString();
showQueueData();
// se supero max precedente, ed è > 10... loggo!
if (qEvLen > maxEvQueue && qEvLen > 10)
{
@@ -1062,6 +994,10 @@ namespace IOB_WIN_FORM
maxEvQueue--;
maxEvQueue = maxEvQueue < qEvLen ? qEvLen : maxEvQueue;
}
if (!ShouldUpdateUI()) return;
lblQueueLen.Text = qEvLen.ToString();
showQueueData();
}
get
{
@@ -1074,8 +1010,6 @@ namespace IOB_WIN_FORM
set
{
qFlLen = value;
lblQueueFLogLen.Text = qFlLen.ToString();
showQueueData();
// se supero max precedente, ed è > 10... loggo!
if (qFlLen > maxFlQueue && qFlLen > 10)
{
@@ -1087,6 +1021,10 @@ namespace IOB_WIN_FORM
maxFlQueue--;
maxFlQueue = maxFlQueue < qFlLen ? qFlLen : maxFlQueue;
}
if (!ShouldUpdateUI()) return;
lblQueueFLogLen.Text = qFlLen.ToString();
showQueueData();
}
get
{
@@ -1094,18 +1032,6 @@ namespace IOB_WIN_FORM
}
}
private string lblCncText
{
get => lblCNC.Text;
set => lblCNC.Text = value;
}
private string lblSrvUrlText
{
get => lblSrvUrl.Text;
set => lblSrvUrl.Text = value;
}
private long msQueueLen
{
set
@@ -1373,8 +1299,7 @@ namespace IOB_WIN_FORM
if (logWatchWriteVeto >= now)
return;
if (!ShouldUpdateUI())
return;
if (!ShouldUpdateUI()) return;
logWatchWriteVeto = now.AddMilliseconds(delayShowLogMs);
@@ -1844,7 +1769,6 @@ namespace IOB_WIN_FORM
/// <param name="updateForm">indica se si debba aggiornare la form (no se si sta chiudendo...)</param>
private void fermaTutto(bool stopTimer, bool tryRestart, bool forceDequeue, bool updateForm)
{
if (iobObj == null)
return;
@@ -1864,7 +1788,7 @@ namespace IOB_WIN_FORM
btnStart.Enabled = true;
restart.Enabled = false;
});
_isSuspended = true;
_isSuspended = true;
Task.Run(async () =>
{
if (stopTimer)
@@ -2115,8 +2039,7 @@ namespace IOB_WIN_FORM
OpenFileDialog openFileDial = new OpenFileDialog();
// directory iniziale
openFileDial.InitialDirectory = utils.confDir; // string.Format(@"{0}\{1}", Application.StartupPath, utils.CRS("dataConfPath"));
// Set filter options and filter index.
openFileDial.InitialDirectory = utils.confDir;
openFileDial.Filter = "INI Files (.ini)|*.ini|All Files (*.*)|*.*";
openFileDial.FilterIndex = 1;
// altre opzioni
@@ -2147,41 +2070,31 @@ namespace IOB_WIN_FORM
{
if (iobObj != null)
{
// 1. Estrazione dati dalle code (operazione logica)
long alQueueLen = iobObj.QHelp.QueueAlarm.Count;
long evQueueLen = iobObj.QHelp.QueueIN.Count;
long flQueueLen = iobObj.QHelp.QueueFLog.Count;
long msQueueLen = iobObj.QHelp.QueueMessages.Count;
long rtrQueueLen = iobObj.QHelp.QueueRawTransf.Count;
long ulQueueLen = iobObj.QHelp.QueueULog.Count;
var setPar = new Dictionary<string, string>
{
{ "IP", iobObj.IOBConfFull.Device.Connect.IpAddr },
{ "PORT", iobObj.IOBConfFull.Device.Connect.Port }
};
IobWinStatus currIobStatus = new IobWinStatus()
{
CodIob = iobObj.IOBConfFull.General.FilenameIOB,
IobType = $"{iobObj.IOBConfFull.General.IobType}",
queueAlLen = alQueueLen,
queueEvLen = evQueueLen,
queueFlLen = flQueueLen,
queueMsLen = msQueueLen,
queueRawTransfLen = rtrQueueLen,
queueUlLen = ulQueueLen,
queueAlLen = iobObj.QHelp.QueueAlarm.Count,
queueEvLen = iobObj.QHelp.QueueIN.Count,
queueFlLen = iobObj.QHelp.QueueFLog.Count,
queueMsLen = iobObj.QHelp.QueueMessages.Count,
queueRawTransfLen = iobObj.QHelp.QueueRawTransf.Count,
queueUlLen = iobObj.QHelp.QueueULog.Count,
counterIOB = iobObj.contapezziIOB,
counterMAC = iobObj.contapezziPLC,
lastUpdate = lastIobStatus.lastUpdate > iobObj.DtHelp.lastWatchDog ? lastIobStatus.lastUpdate : iobObj.DtHelp.lastWatchDog,
online = utils.IOB_Online,
lastDataIn = iobObj.DtHelp.lastReadPLC,
lastDataOut = iobObj.DtHelp.lastIobOnline,
setupParams = setPar,
setupParams = new Dictionary<string, string>
{
{ "IP", iobObj.IOBConfFull.Device.Connect.IpAddr },
{ "PORT", iobObj.IOBConfFull.Device.Connect.Port }
},
freeNotes = $"{iobObj.IOBConfFull.General.FilenameIOB} | DT ultimo avvio: {iobObj.DtHelp.AvvioAdp}"
};
// 2. Logica di salvataggio su REDIS (Rete -> Thread di background!)
// Logica di salvataggio su REDIS (Rete -> Thread di background!)
if (!currIobStatus.Equals(lastIobStatus))
{
currIobStatus.lastUpdate = DateTime.Now;
@@ -2332,6 +2245,18 @@ namespace IOB_WIN_FORM
}
}
/// <summary>
/// Salvo IOB e scope x NLog management
/// </summary>
/// <param name="newIOB"></param>
private void SetIOB(string newIOB)
{
CurrIOB = newIOB;
_scopeIOB?.Dispose(); // rimuove il vecchio valore
_scopeIOB = ScopeContext.PushProperty("codIOB", newIOB);
}
/// <summary>
/// Indica se debba aggiornare o meno la UI perché minimizzata o meno
/// </summary>
@@ -2446,15 +2371,25 @@ namespace IOB_WIN_FORM
lgInfo("UNLOAD Adapter");
}
// Metodo per fermare tutto (es. nel Form_Closing o Dispose)
/// <summary>
/// Metodo per fermare tutto (es. nel Form_Closing o Dispose)
/// </summary>
/// <returns></returns>
private async Task StopWorker()
{
if (_ctsServer == null) return;
_ctsMachine.Cancel();
_ctsRedis.Cancel();
_ctsServer.Cancel();
try
{
if (_redisTask != null)
{
await _redisTask;
}
// Opzionale: attendi che il task finisca davvero prima di fare il dispose
if (_workerTask != null)
{
@@ -2464,11 +2399,29 @@ namespace IOB_WIN_FORM
catch (OperationCanceledException) { /* Normale amministrazione */ }
finally
{
if (_ctsMachine != null)
{
_ctsMachine.Dispose();
_ctsMachine = null;
}
if (_ctsRedis != null)
{
_ctsRedis.Dispose();
_ctsRedis = null;
}
if (_ctsServer != null)
{
_ctsServer.Dispose();
_ctsServer = null;
}
if (_machineThread != null)
{
_machineThread = null;
}
if (_redisTask != null)
{
_redisTask = null;
}
if (_workerTask != null)
{
_workerTask = null;
-1
View File
@@ -20,4 +20,3 @@ CLI_INST=SteamWareSim
STARTLIST=FTP_SONATEST
MAXCNC=10
-1
View File
@@ -27,4 +27,3 @@ CLI_INST=SteamWareSim
STARTLIST=SIMUL_01
MAXCNC=10
-1
View File
@@ -34,4 +34,3 @@ STARTLIST=SIMUL_01
;STARTLIST=3026
MAXCNC=10
-1
View File
@@ -20,4 +20,3 @@ STARTLIST=SIMUL_01
;STARTLIST=3023-PING
MAXCNC=10
-1
View File
@@ -42,4 +42,3 @@ CLI_INST=SteamWareSim
STARTLIST=3010
MAXCNC=10
-1
View File
@@ -24,4 +24,3 @@ STARTLIST=3018
;STARTLIST=SIMUL_06
MAXCNC=10