diff --git a/IOB-UT-NEXT/Iob/BaseObj.cs b/IOB-UT-NEXT/Iob/BaseObj.cs
index f2785b3a..6eba73dc 100644
--- a/IOB-UT-NEXT/Iob/BaseObj.cs
+++ b/IOB-UT-NEXT/Iob/BaseObj.cs
@@ -127,7 +127,31 @@ namespace IOB_UT_NEXT.Iob
///
/// Configurazione gerarchica completa (v 4.x.x.x)
///
- public IobConfTree IOBConfFull;
+ public IobConfTree IOBConfFull
+ {
+ get => _IOBConfFull;
+ set
+ {
+ _IOBConfFull = value;
+ SetIOB(value.General.FilenameIOB);
+ }
+ }
+
+ private IobConfTree _IOBConfFull;
+
+
+ private IDisposable _scopeIOB;
+
+ ///
+ /// Salvo IOB e scope x NLog management
+ ///
+ ///
+ private void SetIOB(string newIOB)
+ {
+ _scopeIOB?.Dispose(); // rimuove il vecchio valore
+
+ _scopeIOB = ScopeContext.PushProperty("codIOB", newIOB);
+ }
///
/// ULtimo valore inviato (in caso di disconnessione lo reinvia x garantire watchdog...)
diff --git a/IOB-WIN-BECKHOFF/NLog.config b/IOB-WIN-BECKHOFF/NLog.config
index cd1bcc98..0ecdf272 100644
--- a/IOB-WIN-BECKHOFF/NLog.config
+++ b/IOB-WIN-BECKHOFF/NLog.config
@@ -10,9 +10,9 @@
@@ -42,7 +55,7 @@ namespace IOB_WIN_FORM
///
public AdapterForm(string codIOB)
{
- CurrIOB = codIOB;
+ SetIOB(codIOB);
// continuo avvio...
InitializeComponent();
myGraphInitForm();
@@ -67,6 +80,24 @@ namespace IOB_WIN_FORM
#region Public Properties
+ ///
+ /// Button start encapsulato x gestione da classi derivate
+ ///
+ public Button btnStart
+ {
+ get => start;
+ set => start = value;
+ }
+
+ ///
+ /// Button stop encapsulato x gestione da classi derivate
+ ///
+ public Button btnStop
+ {
+ get => stop;
+ set => stop = value;
+ }
+
///
/// Visualizzazione stato di comunicazione attiva con PLC
///
@@ -89,7 +120,6 @@ namespace IOB_WIN_FORM
this.UIThread(delegate
{
lblCNC.ForeColor = value ? Color.SeaGreen : Color.Black;
- //statusStrip1.Invalidate();
});
}
}
@@ -129,7 +159,6 @@ namespace IOB_WIN_FORM
default:
break;
}
- //statusStrip1.Invalidate();
});
}
}
@@ -195,17 +224,15 @@ namespace IOB_WIN_FORM
get
{
int answ = 5;
- try
- {
- Int32.TryParse(nLines.Text, out answ);
- }
- catch
- { }
+ Int32.TryParse(nLines.Text, out answ);
return answ;
}
set
{
- nLines.Text = value.ToString();
+ this.UIThread(delegate
+ {
+ nLines.Text = value.ToString();
+ });
}
}
@@ -221,14 +248,13 @@ namespace IOB_WIN_FORM
set
{
_sIN = value;
+ if (!ShouldUpdateUI()) return;
var newColor = decSemaforo(value);
if (newColor != bIN.BackColor)
{
- if (!ShouldUpdateUI()) return;
this.UIThread(delegate
{
bIN.BackColor = newColor;
- //bIN.Invalidate();
});
}
}
@@ -246,53 +272,55 @@ namespace IOB_WIN_FORM
set
{
_sOUT = value;
+ if (!ShouldUpdateUI()) return;
var newColor = decSemaforo(value);
if (newColor != bOUT.BackColor)
{
- if (!ShouldUpdateUI()) return;
this.UIThread(delegate
{
bOUT.BackColor = newColor;
- //bOUT.Invalidate();
});
}
}
}
+ ///
+ /// Coda messaggi task
+ ///
+ private readonly Queue logTaskQueue = new Queue();
///
/// Task watcher (in modalità "accodamento in testa" ultimi messaggi...)
///
- public string taskWatcher
+ public void AddTaskLog(string value)
{
- get
+ try
{
- return lblTaskLog.Text;
+ // FIFO buffer
+ if (logTaskQueue.Count >= nLine2show)
+ logTaskQueue.Dequeue();
+
+ logTaskQueue.Enqueue(value);
+
+ if (!ShouldUpdateUI())
+ return;
+
+ // snapshot + reverse per mostrare latest in alto
+ var text = string.Join(
+ Environment.NewLine,
+ logTaskQueue.Reverse()
+ );
+
+ this.UIThread(() =>
+ {
+ if (lblTaskLog.Text != text)
+ lblTaskLog.Text = text;
+ });
}
- set
+ catch (Exception exc)
{
- try
- {
- logTaskString.Insert(0, value);
- // se supero limite --> trim!
- if (logTaskString.Count > nLine2show)
- {
- logTaskString = logTaskString.Take(nLine2show).ToList();
- }
- if (!ShouldUpdateUI()) return;
- this.UIThread(delegate
- {
- lblTaskLog.Text = string.Join(Environment.NewLine, logTaskString);
- //lblTaskLog.Invalidate();
- });
- }
- catch (Exception exc)
- {
- lgError($"Errore in esecuzione taskWatcher{Environment.NewLine}--> {value}");
- if (isVerboseLog)
- {
- lgError($"{exc}");
- }
- }
+ lgError($"Errore in taskWatcher --> {value}");
+ if (isVerboseLog)
+ lgError($"{exc}");
}
}
@@ -414,7 +442,6 @@ namespace IOB_WIN_FORM
if (logCounterVeto < adesso || lblCounter.Text != $"{currDispData.counter}")
{
lblCounter.Text = $"{currDispData.counter}";
- //lblCounter.Invalidate();
logCounterVeto = adesso.AddMilliseconds(delayShowLogMs);
}
}
@@ -422,7 +449,6 @@ namespace IOB_WIN_FORM
if (!string.IsNullOrWhiteSpace(currDispData.currBitmap))
{
lblBitmap.Text = currDispData.currBitmap;
- //lblBitmap.Invalidate();
}
// LiveLog
if (!string.IsNullOrWhiteSpace(currDispData.newLiveLogData))
@@ -568,25 +594,6 @@ namespace IOB_WIN_FORM
get => restart;
}
- ///
- /// Button start encapsulato x gestione da classi derivate
- ///
- public Button btnStart
- {
- get => start;
- set => start = value;
- }
-
- ///
- /// Button stop encapsulato x gestione da classi derivate
- ///
- public Button btnStop
- {
- get => stop;
- set => stop = value;
- }
-
-
///
/// Modello macchina
///
@@ -625,11 +632,6 @@ namespace IOB_WIN_FORM
///
protected DateTime logCounterVeto { get; set; } = DateTime.Now;
- ///
- /// Lista String da mostrare quale TaskLog corrente...
- ///
- protected List logTaskString { get; set; } = new List();
-
///
/// Lista String da mostrare quale WatchLog corrente...
///
@@ -738,13 +740,28 @@ namespace IOB_WIN_FORM
});
}
+
+ private IDisposable _scopeIOB;
+
+ ///
+ /// Salvo IOB e scope x NLog management
+ ///
+ ///
+ private void SetIOB(string newIOB)
+ {
+ CurrIOB = newIOB;
+ _scopeIOB?.Dispose(); // rimuove il vecchio valore
+
+ _scopeIOB = ScopeContext.PushProperty("codIOB", newIOB);
+ }
+
+
///
/// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere...
///
///
protected void lgDebug(string txt2log)
{
- lg.Factory.Configuration.Variables["codIOB"] = this.CurrIOB;//IOBConfFull.General.FilenameIOB ??this.CurrIOB;
lg.Debug(txt2log);
// salvo anche in logwatcher...
newDisplayData currDispData = new newDisplayData();
@@ -760,7 +777,6 @@ namespace IOB_WIN_FORM
{
if (!string.IsNullOrEmpty(txt2log))
{
- lg.Factory.Configuration.Variables["codIOB"] = this.CurrIOB;//IOBConfFull.General.FilenameIOB ??this.CurrIOB;
lg.Error(txt2log);
// salvo anche in logwatcher... SE non si dimostra ricorsivo...
if (!txt2log.Contains("logWatcher"))
@@ -778,7 +794,6 @@ namespace IOB_WIN_FORM
///
protected void lgInfo(string txt2log)
{
- lg.Factory.Configuration.Variables["codIOB"] = this.CurrIOB;//IOBConfFull.General.FilenameIOB ??this.CurrIOB;
lg.Info(txt2log);
// salvo anche in logwatcher...
newDisplayData currDispData = new newDisplayData();
@@ -792,7 +807,6 @@ namespace IOB_WIN_FORM
///
protected void lgTrace(string txt2log)
{
- lg.Factory.Configuration.Variables["codIOB"] = this.CurrIOB;//IOBConfFull.General.FilenameIOB ??this.CurrIOB;
lg.Trace(txt2log);
// salvo anche in logwatcher...
newDisplayData currDispData = new newDisplayData();
@@ -1317,15 +1331,19 @@ namespace IOB_WIN_FORM
case 0:
lblRawData.Text = newText;
break;
+
case 1:
lblOutMessage.Text = newText;
break;
+
case 2:
lblOutMessage2.Text = newText;
break;
+
case 3:
lblOutMessage3.Text = newText;
break;
+
default:
break;
}
@@ -1826,46 +1844,49 @@ namespace IOB_WIN_FORM
/// indica se si debba aggiornare la form (no se si sta chiudendo...)
private void fermaTutto(bool stopTimer, bool tryRestart, bool forceDequeue, bool updateForm)
{
- if (iobObj != null)
- {
- try
- {
- try
- {
- // PONTE SYNC/ASYNC: Ora sw.Stop() aspetterà la fine reale dell'operazione
- Task.Run(async () =>
- {
- await iobObj.stopAdapter(tryRestart, forceDequeue);
- btnStop.Enabled = false;
- btnStart.Enabled = true;
- restart.Enabled = false;
- _isSuspended = true;
- if (stopTimer)
- {
- gather.Enabled = false;
- await StopWorker();
- }
- })
- .GetAwaiter()
- .GetResult();
- }
- catch (Exception ex)
- {
- lgError($"Errore in fermaTutto |stopTimer: {stopTimer} | tryRestart: {tryRestart} | forceDequeue: {forceDequeue} | updateForm: {updateForm}{Environment.NewLine}{ex.Message}");
- }
- newDisplayData currDispData = new newDisplayData();
- currDispData.semIn = Semaforo.SS;
- currDispData.semOut = Semaforo.SS;
- if (updateForm)
- {
- updateFormDisplay(currDispData);
- }
- }
- catch (Exception exc)
+ if (iobObj == null)
+ return;
+
+ try
+ {
+ // PONTE SYNC/ASYNC: Ora sw.Stop() aspetterà la fine reale dell'operazione
+ Task.Run(async () =>
{
- lgError($"Errore in chiusura:{Environment.NewLine}{exc}");
- }
+ await iobObj.stopAdapter(tryRestart, forceDequeue);
+ })
+ .GetAwaiter()
+ .GetResult();
+
+ this.UIThread(() =>
+ {
+ btnStop.Enabled = false;
+ btnStart.Enabled = true;
+ restart.Enabled = false;
+ });
+ _isSuspended = true;
+ Task.Run(async () =>
+ {
+ if (stopTimer)
+ {
+ gather.Enabled = false;
+ await StopWorker();
+ }
+ })
+ .GetAwaiter()
+ .GetResult();
+ }
+ catch (Exception ex)
+ {
+ lgError($"Errore in fermaTutto |stopTimer: {stopTimer} | tryRestart: {tryRestart} | forceDequeue: {forceDequeue} | updateForm: {updateForm}{Environment.NewLine}{ex.Message}");
+ }
+
+ newDisplayData currDispData = new newDisplayData();
+ currDispData.semIn = Semaforo.SS;
+ currDispData.semOut = Semaforo.SS;
+ if (updateForm)
+ {
+ updateFormDisplay(currDispData);
}
}
@@ -2428,9 +2449,9 @@ namespace IOB_WIN_FORM
// Metodo per fermare tutto (es. nel Form_Closing o Dispose)
private async Task StopWorker()
{
- if (_ctsMachine == null) return;
+ if (_ctsServer == null) return;
- _ctsMachine.Cancel();
+ _ctsServer.Cancel();
try
{
@@ -2443,10 +2464,10 @@ namespace IOB_WIN_FORM
catch (OperationCanceledException) { /* Normale amministrazione */ }
finally
{
- if (_ctsMachine != null)
+ if (_ctsServer != null)
{
- _ctsMachine.Dispose();
- _ctsMachine = null;
+ _ctsServer.Dispose();
+ _ctsServer = null;
}
if (_workerTask != null)
{
diff --git a/IOB-WIN-FORM/IForceUpdateUI.cs b/IOB-WIN-FORM/IForceUpdateUI.cs
new file mode 100644
index 00000000..4f4f6c86
--- /dev/null
+++ b/IOB-WIN-FORM/IForceUpdateUI.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace IOB_WIN_FORM
+{
+ public interface IForceUpdateUI
+ {
+ void ForceUpdateUI();
+ }
+}
diff --git a/IOB-WIN-FORM/IOB-WIN-FORM.csproj b/IOB-WIN-FORM/IOB-WIN-FORM.csproj
index 288b827c..a6e6399b 100644
--- a/IOB-WIN-FORM/IOB-WIN-FORM.csproj
+++ b/IOB-WIN-FORM/IOB-WIN-FORM.csproj
@@ -134,6 +134,7 @@
AdapterForm.cs
+
diff --git a/IOB-WIN-FORM/Iob/BaseObj.cs b/IOB-WIN-FORM/Iob/BaseObj.cs
index a0fb40f8..02a5c600 100644
--- a/IOB-WIN-FORM/Iob/BaseObj.cs
+++ b/IOB-WIN-FORM/Iob/BaseObj.cs
@@ -46,6 +46,8 @@ namespace IOB_WIN_FORM.Iob
#region Protected Methods
+
+
///
/// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere...
///
@@ -56,7 +58,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
lg.Debug(message);
if (sendToForm)
{
@@ -76,7 +77,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
lg.Debug(message, args);
sendToLogWatch("DEBUG", message, args);
}
@@ -93,7 +93,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
lg.Error(message, args);
sendToLogWatch("ERROR", message, args);
}
@@ -109,7 +108,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
lg.Error(message);
if (sendToForm)
{
@@ -130,7 +128,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
lg.Error(exception, message, args);
sendToLogWatch("ERROR", message, exception, args);
}
@@ -146,7 +143,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
lg.Fatal(message);
if (sendToForm)
{
@@ -166,7 +162,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
lg.Fatal(message, args);
sendToLogWatch("FATAL", message, args);
}
@@ -184,7 +179,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
lg.Fatal(exception, message, args);
sendToLogWatch("FATAL", message, exception, args);
}
@@ -200,7 +194,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
lg.Info(message);
if (sendToForm)
{
@@ -220,7 +213,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
lg.Info(message, args);
sendToLogWatch("INFO", message, args);
}
@@ -237,7 +229,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
DateTime adesso = DateTime.Now;
if (adesso.Subtract(DtHelp.lastLogStartup).TotalMinutes > vetoLogStartupDuration)
{
@@ -266,7 +257,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
DateTime adesso = DateTime.Now;
if (adesso.Subtract(DtHelp.lastLogStartup).TotalMinutes > vetoLogStartupDuration)
{
@@ -291,7 +281,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
lg.Trace(message);
if (sendToForm)
{
@@ -311,7 +300,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
lg.Trace(message, args);
sendToLogWatch("TRACE", message, args);
}
@@ -327,7 +315,6 @@ namespace IOB_WIN_FORM.Iob
// se non ho veto --> loggo
if (!doVeto)
{
- lg.Factory.Configuration.Variables["codIOB"] = IOBConfFull.General.FilenameIOB;
lg.Warn(message);
if (sendToForm)
{
diff --git a/IOB-WIN-FORM/Iob/Generic.cs b/IOB-WIN-FORM/Iob/Generic.cs
index deab2327..87360dd7 100644
--- a/IOB-WIN-FORM/Iob/Generic.cs
+++ b/IOB-WIN-FORM/Iob/Generic.cs
@@ -6933,7 +6933,7 @@ namespace IOB_WIN_FORM.Iob
{
logMsg += $" | {codTav} | {messType} | {message}";
}
- parentForm.taskWatcher = logMsg;
+ parentForm.AddTaskLog(logMsg);
}
///
@@ -9114,7 +9114,7 @@ namespace IOB_WIN_FORM.Iob
{
string codIob = IOBConfFull.General.FilenameIOB;
bool useRedis = IOBConfFull.General.EnabRedisQue;
- if(QHelp.QueueIN!=null) QHelp.QueueIN.Dispose();
+ if (QHelp.QueueIN != null) QHelp.QueueIN.Dispose();
QHelp.QueueIN = new DataQueue(codIob, "QueueIN", useRedis, redisMan);
if (QHelp.QueueSrvResp != null) QHelp.QueueSrvResp.Dispose();
QHelp.QueueSrvResp = new DataQueue(codIob, "QueueServResp", useRedis, redisMan);
diff --git a/IOB-WIN-FORM/MainForm.Designer.cs b/IOB-WIN-FORM/MainForm.Designer.cs
index 2e46304c..7d9ebef5 100644
--- a/IOB-WIN-FORM/MainForm.Designer.cs
+++ b/IOB-WIN-FORM/MainForm.Designer.cs
@@ -233,7 +233,7 @@
// MainTimer
//
this.MainTimer.Enabled = true;
- this.MainTimer.Interval = 20;
+ this.MainTimer.Interval = 50;
this.MainTimer.Tick += new System.EventHandler(this.MainTimer_Tick);
//
// notifyIcon1
diff --git a/IOB-WIN-FORM/MainForm.cs b/IOB-WIN-FORM/MainForm.cs
index 83f799cb..021549d7 100644
--- a/IOB-WIN-FORM/MainForm.cs
+++ b/IOB-WIN-FORM/MainForm.cs
@@ -11,13 +11,11 @@ using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Drawing;
+using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
-using System.Text;
-using System.Threading;
using System.Threading.Tasks;
-using System.Timers;
using System.Windows.Forms;
namespace IOB_WIN_FORM
@@ -26,11 +24,6 @@ namespace IOB_WIN_FORM
{
#region Public Fields
- ///
- /// oggetto logging
- ///
- protected static Logger lg = LogManager.GetCurrentClassLogger();
-
///
/// Configurazione gerarchica completa (v 4.x.x.x)
///
@@ -50,6 +43,7 @@ namespace IOB_WIN_FORM
///
public MainForm(string[] args)
{
+ SetIOB("MAIN");
// salvo parametri avvio...
saveArgs(args);
// continuo iNIT!!!
@@ -96,7 +90,6 @@ namespace IOB_WIN_FORM
// se true --> comunica/verde, altrimenti grigio
lblApp.ForeColor = value ? Color.SeaGreen : Color.Black;
lblVers.ForeColor = value ? Color.SeaGreen : Color.DarkSlateGray;
- //statusStrip1.Invalidate();
});
}
}
@@ -219,10 +212,6 @@ namespace IOB_WIN_FORM
{
resetProgBar++;
}
-#if false
- // invalido x ridisegnare...
- MainProgrBar.Invalidate();
-#endif
}
}
catch (Exception exc)
@@ -242,7 +231,6 @@ namespace IOB_WIN_FORM
// mostro solo se non minimizzata
if (!ShouldUpdateUI()) return;
lblStatus.Text = txt2show;
- //lblStatus.Invalidate();
}
///
@@ -254,8 +242,8 @@ namespace IOB_WIN_FORM
///
public void updateComStats(int numPLC, int numAttivi, bool serverOk)
{
- // testo
- lblComStats.Text = $"{numAttivi}/{numPLC} PLC --> {MPIP} (MP/IO)";
+ if (!ShouldUpdateUI()) return;
+
// colore secondo valori... server !="ND" è ok, PLC > 0 è OK
int score = 0;
if (serverOk)
@@ -268,7 +256,8 @@ namespace IOB_WIN_FORM
score++;
}
- if (!ShouldUpdateUI()) return;
+ // testo
+ lblComStats.Text = $"{numAttivi}/{numPLC} PLC --> {MPIP} (MP/IO)";
switch (score)
{
case 0:
@@ -464,7 +453,6 @@ namespace IOB_WIN_FORM
///
protected static void lgError(string txt2log)
{
- lg.Factory.Configuration.Variables["codIOB"] = "MAIN";
lg.Error(txt2log);
}
@@ -474,7 +462,6 @@ namespace IOB_WIN_FORM
///
protected static void lgInfo(string txt2log)
{
- lg.Factory.Configuration.Variables["codIOB"] = "MAIN";
lg.Info(txt2log);
}
@@ -484,7 +471,6 @@ namespace IOB_WIN_FORM
///
protected static void lgWarn(string txt2log)
{
- lg.Factory.Configuration.Variables["codIOB"] = "MAIN";
lg.Warn(txt2log);
}
@@ -625,6 +611,23 @@ namespace IOB_WIN_FORM
base.OnFormClosing(e);
}
+ protected override void OnVisibleChanged(EventArgs e)
+ {
+ base.OnVisibleChanged(e);
+
+ if (!Visible)
+ {
+ wasHidden = true;
+ return;
+ }
+
+ if (wasHidden)
+ {
+ wasHidden = false;
+ OnAppBecameVisible();
+ }
+ }
+
///
/// Apre la finestra child con conf
///
@@ -684,13 +687,21 @@ namespace IOB_WIN_FORM
///
private static bool closed = false;
+ ///
+ /// oggetto logging
+ ///
+ private static Logger lg = LogManager.GetCurrentClassLogger();
+
private FormWindowState _lastState = FormWindowState.Minimized;
+ private IDisposable _scopeIOB;
///
/// Nome applicazione (da app.config)
///
private string nomeApp = "";
+ private bool wasHidden = false;
+
#endregion Private Fields
#region Private Methods
@@ -716,6 +727,8 @@ namespace IOB_WIN_FORM
///
private void checkCom()
{
+ if (!ShouldUpdateUI()) return;
+
// eseguo update se è passato almeno comCheckTOut secondi da ultimo check...
if (DateTime.Now.Subtract(lastComCheck).TotalSeconds > utils.CRI("comCheckTOut"))
{
@@ -1074,7 +1087,7 @@ namespace IOB_WIN_FORM
{
try
{
- string logPath = $"{System.AppDomain.CurrentDomain.BaseDirectory}logs\\MAIN\\{DateTime.Today:yyyy-MM-dd}.log";
+ string logPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "logs", "MAIN", $"{DateTime.Today:yyyy-MM-dd}.log");
Process.Start(logPath);
}
catch (Exception exc)
@@ -1095,6 +1108,19 @@ namespace IOB_WIN_FORM
{
Show();
WindowState = FormWindowState.Normal;
+ Activate();
+ }
+ }
+
+ private void OnAppBecameVisible()
+ {
+ // refresh completo per tutti i child form...
+ foreach (var ChildForm in this.MdiChildren)
+ {
+ if (ChildForm is IForceUpdateUI updatable)
+ {
+ updatable.ForceUpdateUI();
+ }
}
}
@@ -1127,6 +1153,17 @@ namespace IOB_WIN_FORM
Hide();
}
+ ///
+ /// Salvo IOB e scope x NLog management
+ ///
+ ///
+ private void SetIOB(string newIOB)
+ {
+ _scopeIOB?.Dispose(); // rimuove il vecchio valore
+
+ _scopeIOB = ScopeContext.PushProperty("codIOB", newIOB);
+ }
+
private bool ShouldUpdateUI()
{
// 1. Controlla se la form stessa è minimizzata
diff --git a/IOB-WIN-FTP/NLog.config b/IOB-WIN-FTP/NLog.config
index cd1bcc98..0ecdf272 100644
--- a/IOB-WIN-FTP/NLog.config
+++ b/IOB-WIN-FTP/NLog.config
@@ -10,9 +10,9 @@