Preparation for remote sharing of procedures, ver. 2.18.920

This commit is contained in:
Milan Hanajik
2018-06-11 12:53:52 +02:00
parent f3c0da79e8
commit b5383a445e
4 changed files with 73 additions and 26 deletions
+11 -1
View File
@@ -1,6 +1,7 @@
/// ///
/// Copyright (c) 2013-2015 Sensus Metering Systems /// Copyright (c) 2013-2015 Sensus Metering Systems
/// ///
using System;
using System.Threading; using System.Threading;
using log4net; using log4net;
using NHibernate; using NHibernate;
@@ -39,11 +40,20 @@ namespace TBF.BenchControl.Operations
void Loader() void Loader()
{ {
StateMachine.LoadProcedure(false); try
{
ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
StateMachine.LoadPathsAndTransitions(session);
StateMachine.LoadProcedure(session);
StateMachine.LoadProcedureParams(StateMachine.Procedure); StateMachine.LoadProcedureParams(StateMachine.Procedure);
completed = true; completed = true;
} }
catch (Exception)
{
error = true;
}
}
/// <summary>Run this operation</summary> /// <summary>Run this operation</summary>
/// <returns> /// <returns>
+35 -10
View File
@@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using log4net; using log4net;
using NHibernate;
using Config; using Config;
using Config.Entities; using Config.Entities;
using Results.Entities; using Results.Entities;
@@ -34,7 +35,7 @@ namespace TBF.BenchControl.Sequences
IList<Config.Entities.Test> simultWithEvacuationTests; IList<Config.Entities.Test> simultWithEvacuationTests;
IList<Generic.ITestParams> simultWithEvacuationParams; IList<Generic.ITestParams> simultWithEvacuationParams;
IList<ComponentTest> testParamsForCurrentProcedure;
System.Windows.Forms.Form modelessDlg; System.Windows.Forms.Form modelessDlg;
/// ///
@@ -108,7 +109,8 @@ namespace TBF.BenchControl.Sequences
Selection selection; Selection selection;
string selectedTestName; string selectedTestName;
StateMachine.LoadProcedure(true); // TODO: Implement as an operation so that the worker thread is not blocked ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
StateMachine.LoadPathsAndTransitions(session); // TODO: Implement as an operation so that the worker thread is not blocked
Bridge.OnActivity(this, Strings.Starting_system); Bridge.OnActivity(this, Strings.Starting_system);
State.Create("MainSeq : Press OK to start the system") State.Create("MainSeq : Press OK to start the system")
@@ -311,15 +313,38 @@ namespace TBF.BenchControl.Sequences
default: selectedTestName = Bridge.SelectedTestName; break; default: selectedTestName = Bridge.SelectedTestName; break;
} }
UiBridge.Bridge.OnError(this, string.Empty); /// Clear an error message (if any) ///
StateMachine.LoadProcedure(false); /// Load all parameters for this procedure from DB
///
try
{
ISession sesn = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
StateMachine.LoadPathsAndTransitions(sesn);
StateMachine.LoadProcedure(sesn);
StateMachine.LoadProcedureParams(StateMachine.Procedure);
testParamsForCurrentProcedure = new List<ComponentTest>();
foreach (var test in StateMachine.Tests)
{
IList<ComponentTest> testParams = sesn.QueryOver<ComponentTest>()
.Where(x => (x.Test == test))
.List();
foreach (var tp in testParams) testParamsForCurrentProcedure.Add(tp);
}
}
catch (Exception)
{
StateMachine.Procedure = null;
}
} }
while (StateMachine.Procedure == null); /// Make sure a valid procedure is selected while (StateMachine.Procedure == null); /// Make sure a valid procedure is selected
UiBridge.Bridge.OnError(this, string.Empty); /// Clear an error message (if any)
/// ///
/// Procedure selected at this point, a new batch was started /// Procedure selected at this point, a new batch was started
/// ///
StateMachine.LoadProcedureParams(StateMachine.Procedure);
StateMachine.ControlBoard.ManualUIAllowed = !StateMachine.Procedure.ManualCtrlDisabled; StateMachine.ControlBoard.ManualUIAllowed = !StateMachine.Procedure.ManualCtrlDisabled;
Bridge.Bench2UI(ButtonsEtc.StopBtnEn); /// Enable STOP button Bridge.Bench2UI(ButtonsEtc.StopBtnEn); /// Enable STOP button
@@ -493,9 +518,9 @@ namespace TBF.BenchControl.Sequences
WaterMeter newWM = BatchRslts.WaterMeters[i]; WaterMeter newWM = BatchRslts.WaterMeters[i];
for (int j = 0; j < Results.DBase.Count; j++) for (int j = 0; j < Results.DBase.Count; j++)
{ {
NHibernate.ISession session = Results.DBase.Databases[j].OpenSession(); NHibernate.ISession sesn = Results.DBase.Databases[j].OpenSession();
IList<WaterMeter> watermeters = session.QueryOver<WaterMeter>().Where(x => (x.SerialNr == newWM.SerialNr)).List(); IList<WaterMeter> watermeters = sesn.QueryOver<WaterMeter>().Where(x => (x.SerialNr == newWM.SerialNr)).List();
if (watermeters.Count > 0) if (watermeters.Count > 0)
{ {
BatchRslts.WaterMeters[i].CopyContentFrom(watermeters[watermeters.Count - 1]); /// Copy results from the last occurance of the watermeter BatchRslts.WaterMeters[i].CopyContentFrom(watermeters[watermeters.Count - 1]); /// Copy results from the last occurance of the watermeter
@@ -670,7 +695,7 @@ namespace TBF.BenchControl.Sequences
ITestMethod testMethod = testMethodComp as ITestMethod; ITestMethod testMethod = testMethodComp as ITestMethod;
if (testMethod != null && testMethod.CanTest(StateMachine.Procedure.MetersKind)) if (testMethod != null && testMethod.CanTest(StateMachine.Procedure.MetersKind))
{ {
StateMachine.LoadTestParams(test); StateMachine.LoadTestParams(test, testParamsForCurrentProcedure);
ProcessData.RegisterReaders = sensPath.RegisterReaders; ProcessData.RegisterReaders = sensPath.RegisterReaders;
if (isOuterLoopMode && outerLoopRepeats != test.Repeats && !(testMethod is TestMethods.OuterLoop.End.Component)) if (isOuterLoopMode && outerLoopRepeats != test.Repeats && !(testMethod is TestMethods.OuterLoop.End.Component))
{ {
@@ -816,7 +841,7 @@ namespace TBF.BenchControl.Sequences
if (testMethod != null && testMethod.CanTest(StateMachine.Procedure.MetersKind)) if (testMethod != null && testMethod.CanTest(StateMachine.Procedure.MetersKind))
{ {
StateMachine.LoadTestParams(dfrrdData.Test); StateMachine.LoadTestParams(dfrrdData.Test, testParamsForCurrentProcedure);
ProcessData.RegisterReaders = sensPath.RegisterReaders; ProcessData.RegisterReaders = sensPath.RegisterReaders;
foreach (var rr in sensPath.RegisterReaders) foreach (var rr in sensPath.RegisterReaders)
@@ -871,7 +896,7 @@ namespace TBF.BenchControl.Sequences
ITestMethod testMethod = TbfComponents.FindComponent(test.Method) as ITestMethod; ITestMethod testMethod = TbfComponents.FindComponent(test.Method) as ITestMethod;
if (testMethod != null && testMethod.CanTest(StateMachine.Procedure.MetersKind)) if (testMethod != null && testMethod.CanTest(StateMachine.Procedure.MetersKind))
{ {
StateMachine.LoadTestParams(test); StateMachine.LoadTestParams(test, testParamsForCurrentProcedure);
ProcessData.RegisterReaders = sensPath.RegisterReaders; ProcessData.RegisterReaders = sensPath.RegisterReaders;
foreach (var rr in sensPath.RegisterReaders) foreach (var rr in sensPath.RegisterReaders)
+17 -5
View File
@@ -384,9 +384,12 @@ namespace TBF.BenchControl
stateMachineRunning = true; stateMachineRunning = true;
} }
public static void LoadProcedure(bool loadPathsOnly) /// <summary>
/// Loads all paths and transitions from the DB.
/// Updates StatMachine.feedingPaths ... StatMachine.meterPaths, StatMachine.TransitionSequences
/// </summary>
public static void LoadPathsAndTransitions(ISession session)
{ {
ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
WtSession = session; WtSession = session;
feedingPaths = session.QueryOver<Config.Entities.FeedingPath>().OrderBy(x => x.ItemNr).Asc.List(); feedingPaths = session.QueryOver<Config.Entities.FeedingPath>().OrderBy(x => x.ItemNr).Asc.List();
@@ -397,18 +400,27 @@ namespace TBF.BenchControl
#if HEAT_METERS #if HEAT_METERS
heatMetersPaths = session.QueryOver<Config.Entities.HeatMetersPath>().OrderBy(x => x.ItemNr).Asc.List(); heatMetersPaths = session.QueryOver<Config.Entities.HeatMetersPath>().OrderBy(x => x.ItemNr).Asc.List();
#endif #endif
}
if (loadPathsOnly) return; /// <summary>
/// Loads selected procedure from the DB.
/// Updates StateMachine.Procedure and StateMachine.Tests
/// </summary>
public static bool LoadProcedure(ISession session)
{
WtSession = session;
IList<Procedure> selectedProcs = session.QueryOver<Procedure>() IList<Procedure> selectedProcs = session.QueryOver<Procedure>()
.Where(x => (x.ProcedureState == ProcedureState.Active)) .Where(x => (x.ProcedureState == ProcedureState.Active))
.And(x => (x.Name == TBF.UiBridge.Bridge.SelectedProcedureName)) .And(x => (x.Name == TBF.UiBridge.Bridge.SelectedProcedureName))
.List(); .List();
if (selectedProcs.Count != 1) return; if (selectedProcs.Count != 1) return false;
Procedure = selectedProcs[0]; Procedure = selectedProcs[0];
Tests = selectedProcs[0].Tests; Tests = selectedProcs[0].Tests;
return true;
} }
public static void LoadProcedureParams(Procedure procedure) public static void LoadProcedureParams(Procedure procedure)
@@ -419,7 +431,7 @@ namespace TBF.BenchControl
} }
} }
public static void LoadTestParams(Test test) public static void LoadTestParams(Test test, IList<ComponentTest> bufferedTestParams)
{ {
foreach (var cmpnt in components) foreach (var cmpnt in components)
{ {
+2 -2
View File
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number // Build Number
// Revision // Revision
// //
[assembly: AssemblyVersion("2.18.918.0")] [assembly: AssemblyVersion("2.18.920.0")]
[assembly: AssemblyFileVersion("2.18.918.0")] [assembly: AssemblyFileVersion("2.18.920.0")]