(1) Save process data after each completed test, (2) Restore process data of an interrupted session via 'Abort' button.

This commit is contained in:
Milan Hanajik
2020-02-05 13:04:00 +01:00
parent 12c9e72d0c
commit c73f6a857a
9 changed files with 179 additions and 37 deletions
+1
View File
@@ -123,6 +123,7 @@ namespace TBF.BenchControl
UiCmdStopDrainingTank2,
UiCmdStopDrainingTank3,
UiCmdBreak,
UiCmdRestoreSession,
UiCmdResetResults,
UiCmdAcceptResults,
UiCmdShutdown,
+1
View File
@@ -101,6 +101,7 @@ namespace TBF.BenchControl.Operations
case UI2BenchCmd.StopDrainingTank2: return Event.UiCmdStopDrainingTank2;
case UI2BenchCmd.StopDrainingTank3: return Event.UiCmdStopDrainingTank3;
case UI2BenchCmd.Break: return Event.UiCmdBreak;
case UI2BenchCmd.RestoreSession: return Event.UiCmdRestoreSession;
case UI2BenchCmd.ResetResults: return Event.UiCmdResetResults;
case UI2BenchCmd.AcceptResults: return Event.UiCmdAcceptResults;
case UI2BenchCmd.Shutdown: return Event.UiCmdShutdown;
+84 -26
View File
@@ -15,6 +15,7 @@ using TBF.BenchControl.GenericDevices;
using TBF.Boxes;
using TBF.Resources;
using System.Threading;
using System.IO;
namespace TBF.BenchControl.Sequences
{
@@ -505,9 +506,26 @@ namespace TBF.BenchControl.Sequences
int newBatchNr = Program.LocalSettings.BatchNr;
log.FatalFormat("New measurement session started: batch = {0}, procedure = {1}", newBatchNr, StateMachine.Procedure.Name);
ClearSessionData();
if (selection == Selection.RestoreBatch)
if (selection == Selection.RestoreInterruptedSession)
{
if (!LoadProcessData(Program.Version))
{
/// Program version does not match the one stored in process data
UiBridge.Bridge.OnError(this, Strings.Program_version_does_not_match);
goto stop;
}
else if (BatchRslts.Batch.BatchNr != newBatchNr)
{
/// Program version does not match the one stored in process data
UiBridge.Bridge.OnError(this, Strings.Invalid_batch_number);
goto stop;
}
else
{
/// Everythign is OK
}
}
else if (selection == Selection.RestoreBatch)
{
BatchRslts = CreateNewBatchResults(newBatchNr, StateMachine.Procedure);
RestoreBatchResults(TBF.UiBridge.Bridge.BatchNr, ref BatchRslts); /// pass the original batch number of the batch to be restored
@@ -562,15 +580,18 @@ namespace TBF.BenchControl.Sequences
StateMachine.CycleStartTimeStamp = BatchRslts.Batch.StartTime;
Bridge.OnProcedureSelected(this, new ProcedureSelectedEventArgs(StateMachine.Procedure));
Bridge.OnProcedureSelected(this, new ProcedureSelectedEventArgs(StateMachine.Procedure)); /// Select procedure in case of interrupted session
///
/// Display 'Cycle Begin Form' in case of a normal batch (not a restored batch)
///
if ((selection != Selection.RestoreBatch) && (selection != Selection.RestoreAndFixBatch) && !OpenCycleBeginForm())
if (selection != Selection.RestoreBatch && selection != Selection.RestoreAndFixBatch && selection != Selection.RestoreInterruptedSession)
{
goto stop;
///
/// This is a normal batch (not a restored one) => Display 'Cycle Begin Form'
///
if (!OpenCycleBeginForm())
{
goto stop;
}
}
///
@@ -608,12 +629,15 @@ namespace TBF.BenchControl.Sequences
}
if (selection == Selection.Q1 || selection == Selection.Q2 ||
selection == Selection.Q3 || selection == Selection.Test)
if (selection == Selection.Q1 ||
selection == Selection.Q2 ||
selection == Selection.Q3 ||
selection == Selection.Test ||
selection == Selection.RestoreInterruptedSession)
{
goto assume_bench_filled;
}
else if ((selection == Selection.Cycle && benchFilled) || (selection == Selection.RestoreBatch) || (selection == Selection.RestoreAndFixBatch))
else if ((selection == Selection.Cycle && benchFilled) || (selection == Selection.RestoreBatch) || (selection == Selection.RestoreAndFixBatch) || (selection == Selection.RestoreInterruptedSession))
{
///
/// Always ask a question in case of a restored batch
@@ -770,10 +794,32 @@ namespace TBF.BenchControl.Sequences
}
}
if ((selection != Selection.PurgeBegin) && (selection != Selection.RestoreBatch) && (selection != Selection.RestoreAndFixBatch))
if (selection == Selection.Cycle || selection == Selection.RestOfCycle ||
selection == Selection.Test || selection == Selection.Q1 || selection == Selection.Q2 || selection == Selection.Q3)
{
goto cycle_or_test_selected;
}
else if (selection == Selection.RestoreInterruptedSession)
{
///
/// Make progress bars of completed test green
///
foreach (var testRslt in BatchRslts.Batch.TestRslts)
{
if (testRslt.TestDone)
{
TestProgressEventArgs testProgress = new TestProgressEventArgs(testRslt.Name(), Progress.Completed);
testProgress.Progress = 100;
Bridge.OnTestProgress(this, testProgress);
}
}
/// TODO: Try to find out where the cycle stopped
}
else
{
/// Do nothing
}
select_cycle_or_test:
@@ -1423,6 +1469,11 @@ namespace TBF.BenchControl.Sequences
summaryResults.Info(TestResult2CsvLine(tr));
}
///
/// Clear a file with interim test results
///
ClearProcessData();
Program.LocalSettings.BatchNr++;
Program.LocalSettings.Save();
@@ -1551,6 +1602,7 @@ namespace TBF.BenchControl.Sequences
RestoreBatch,
RestoreAndFixBatch,
Shutdown,
RestoreInterruptedSession,
}
@@ -1565,7 +1617,9 @@ namespace TBF.BenchControl.Sequences
Selection MakeSelection(MKSelContext context)
{
log.WarnFormat("MakeSelection({0})", context);
bool restoreIntrptdSessionEnabled = (context == MKSelContext.ProcedureNotSelected) && File.Exists(ProcessData.PDataFileName);
/// Tank emptying valves states
bool draining1 = false;
bool draining2 = false;
@@ -1597,6 +1651,7 @@ namespace TBF.BenchControl.Sequences
Bridge.Bench2UI(((context == MKSelContext.ProcedureNotSelected) ? ButtonsEtc.ProcedureCmbBoxEn : 0) |
ButtonsEtc.TestCmbBoxEn |
((context == MKSelContext.InsideProcedure) ? ButtonsEtc.Break : 0) |
(restoreIntrptdSessionEnabled ? ButtonsEtc.RestoreSession : 0) |
(saveResultsActive ? ButtonsEtc.AcceptResultsBtnEn : 0) |
(draining ? 0 : ButtonsEtc.StartCycleBtnEn) |
(draining ? 0 : ButtonsEtc.StartTestBtnsEn) |
@@ -1631,18 +1686,21 @@ namespace TBF.BenchControl.Sequences
if (draining3 && StateMachine.Tank3.IsEmpty()) break;
/// Quit the selection loop and leave MakeSelection()
if (e.Contains(Event.UiCmdShutdown)) return Selection.Shutdown;
if (e.Contains(Event.UiCmdBreak) && (context == MKSelContext.InsideProcedure)) return Selection.Break;
if (e.Contains(Event.UiCmdPurgeBegin)) return Selection.PurgeBegin;
if (e.Contains(Event.UiCmdPurgeEnd)) return Selection.PurgeEnd;
if (e.Contains(Event.UiCmdStartCycle)) return Selection.Cycle;
if (e.Contains(Event.UiCmdStartTest)) return Selection.Test;
if (e.Contains(Event.UiCmdStartQ1)) return Selection.Q1;
if (e.Contains(Event.UiCmdStartQ2)) return Selection.Q2;
if (e.Contains(Event.UiCmdStartQ3)) return Selection.Q3;
if (e.Contains(Event.UiCmdAcceptResults)) return Selection.SaveResults;
if (e.Contains(Event.UiCmdReloadBatch)) return Selection.RestoreBatch;
if (e.Contains(Event.UiCmdReloadAndFixBatch)) return Selection.RestoreAndFixBatch;
if (e.Contains(Event.UiCmdShutdown)) return Selection.Shutdown;
if (context == MKSelContext.InsideProcedure
&& e.Contains(Event.UiCmdBreak)) return Selection.Break;
if (e.Contains(Event.UiCmdPurgeBegin)) return Selection.PurgeBegin;
if (e.Contains(Event.UiCmdPurgeEnd)) return Selection.PurgeEnd;
if (e.Contains(Event.UiCmdStartCycle)) return Selection.Cycle;
if (e.Contains(Event.UiCmdStartTest)) return Selection.Test;
if (e.Contains(Event.UiCmdStartQ1)) return Selection.Q1;
if (e.Contains(Event.UiCmdStartQ2)) return Selection.Q2;
if (e.Contains(Event.UiCmdStartQ3)) return Selection.Q3;
if (e.Contains(Event.UiCmdAcceptResults)) return Selection.SaveResults;
if (e.Contains(Event.UiCmdReloadBatch)) return Selection.RestoreBatch;
if (e.Contains(Event.UiCmdReloadAndFixBatch)) return Selection.RestoreAndFixBatch;
if (restoreIntrptdSessionEnabled
&& e.Contains(Event.UiCmdRestoreSession)) return Selection.RestoreInterruptedSession;
}
while (true);
+36
View File
@@ -1266,6 +1266,15 @@ namespace TBF.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Do you really want to restore uncompleted session?.
/// </summary>
internal static string Do_you_really_want_to_restore_uncompleted_session {
get {
return ResourceManager.GetString("Do_you_really_want_to_restore_uncompleted_session", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Do you want to back up configuration?.
/// </summary>
@@ -2193,6 +2202,15 @@ namespace TBF.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Invalid batch number.
/// </summary>
internal static string Invalid_batch_number {
get {
return ResourceManager.GetString("Invalid_batch_number", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Buoyancy is invalid, correct it please..
/// </summary>
@@ -3651,6 +3669,15 @@ namespace TBF.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Program version does not match.
/// </summary>
internal static string Program_version_does_not_match {
get {
return ResourceManager.GetString("Program_version_does_not_match", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Progress.
/// </summary>
@@ -4281,6 +4308,15 @@ namespace TBF.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Restore session.
/// </summary>
internal static string Restore_session {
get {
return ResourceManager.GetString("Restore_session", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Result.
/// </summary>
+12
View File
@@ -1530,4 +1530,16 @@
<data name="Start_cycle" xml:space="preserve">
<value>Spustit postup</value>
</data>
<data name="Do_you_really_want_to_restore_uncompleted_session" xml:space="preserve">
<value>Skutečně chcete pokračovat v nedokončeném cyklu?</value>
</data>
<data name="Restore_session" xml:space="preserve">
<value>Obnovit nedokončený cyklus</value>
</data>
<data name="Invalid_batch_number" xml:space="preserve">
<value>Číslo dávky nesedí</value>
</data>
<data name="Program_version_does_not_match" xml:space="preserve">
<value>Verze programu nesedí</value>
</data>
</root>
+12
View File
@@ -2137,4 +2137,16 @@
<data name="any" xml:space="preserve">
<value>any</value>
</data>
<data name="Restore_session" xml:space="preserve">
<value>Restore session</value>
</data>
<data name="Do_you_really_want_to_restore_uncompleted_session" xml:space="preserve">
<value>Do you really want to restore uncompleted session?</value>
</data>
<data name="Invalid_batch_number" xml:space="preserve">
<value>Invalid batch number</value>
</data>
<data name="Program_version_does_not_match" xml:space="preserve">
<value>Program version does not match</value>
</data>
</root>
+24 -6
View File
@@ -46,6 +46,7 @@ namespace TBF.UI.Shared
bool drain2Highlighted;
bool drain3Highlighted;
bool isRestoreSessionEnabled;
public int BalancesCount
{
@@ -248,12 +249,27 @@ namespace TBF.UI.Shared
private void breakBtn_Click(object sender, EventArgs e)
{
if (MessageBox.Show(Strings.Do_you_really_want_to_abort_this_session + Environment.NewLine + Strings.Test_results_will_be_lost,
Strings.Warning,
MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation) == DialogResult.Yes)
if (isRestoreSessionEnabled)
{
Bridge.Ui2Bench(UI2BenchCmd.Break);
/// Restore session button is enabled
if (MessageBox.Show(Strings.Do_you_really_want_to_restore_uncompleted_session,
Strings.Warning,
MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation) == DialogResult.Yes)
{
Bridge.Ui2Bench(UI2BenchCmd.RestoreSession);
}
}
else
{
/// Break button is enabled
if (MessageBox.Show(Strings.Do_you_really_want_to_abort_this_session + Environment.NewLine + Strings.Test_results_will_be_lost,
Strings.Warning,
MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation) == DialogResult.Yes)
{
Bridge.Ui2Bench(UI2BenchCmd.Break);
}
}
}
@@ -416,7 +432,9 @@ namespace TBF.UI.Shared
acceptResultsBtn.Enabled = ((args.Flags & ButtonsEtc.AcceptResultsBtnEn) != 0);
acceptResultsBtn.BackColor = acceptResultsBtn.Enabled ? colorAcceptEn : colorAcceptDis;
breakBtn.Enabled = ((args.Flags & ButtonsEtc.Break) != 0);
isRestoreSessionEnabled = (args.Flags & ButtonsEtc.RestoreSession) != 0;
breakBtn.Enabled = isRestoreSessionEnabled || (args.Flags & ButtonsEtc.Break) != 0;
breakBtn.Text = isRestoreSessionEnabled ? Strings.Restore_session : Strings.Abort_session;
breakBtn.BackColor = breakBtn.Enabled ? colorOtherEn : colorOtherDis;
cameraTestBtn.Enabled = ((args.Flags & ButtonsEtc.CalibrationBtnEn) != 0);
+2
View File
@@ -130,6 +130,8 @@ namespace TBF.UiBridge
/// </summary>
public static void OnTestCompleted(object sender, TestCompletedEventArgs data)
{
TBF.BenchControl.Sequences.ProcessData.SaveProcessData();
if (TestCompletedHandler == null) return;
try { TestCompletedHandler(sender, data); }
catch (Exception e) { log.Error("TestCompletedHandler(...) failed", e); }
+7 -5
View File
@@ -24,6 +24,7 @@ namespace TBF.UiBridge
StopDrainingTank2,
StopDrainingTank3,
Break,
RestoreSession,
ResetResults,
AcceptResults,
Shutdown,
@@ -53,11 +54,12 @@ namespace TBF.UiBridge
DrainTankBtn3En = (1 << 11),
DrainTankBtn3Hi = (1 << 12),
Break = (1 << 13),
ResetResultsBtnEn = (1 << 14),
AcceptResultsBtnEn = (1 << 15),
CalibrationBtnEn = (1 << 16),
SensitivityTestBtnEn = (1 << 17),
CustomBtnEn = (1 << 18),
RestoreSession = (1 << 14),
ResetResultsBtnEn = (1 << 15),
AcceptResultsBtnEn = (1 << 16),
CalibrationBtnEn = (1 << 17),
SensitivityTestBtnEn = (1 << 18),
CustomBtnEn = (1 << 19),
/// If one of the following flags is set, flags (1 << 0) through (1 << 18) are ignored
ShowBenchEmpty = (1 << 24),