diff --git a/TBF/BenchControl/Operations/LoadProcedureOp.cs b/TBF/BenchControl/Operations/LoadProcedureOp.cs index 2bcdcc8bc..f21b413fe 100644 --- a/TBF/BenchControl/Operations/LoadProcedureOp.cs +++ b/TBF/BenchControl/Operations/LoadProcedureOp.cs @@ -1,6 +1,7 @@ /// /// Copyright (c) 2013-2015 Sensus Metering Systems /// +using System; using System.Threading; using log4net; using NHibernate; @@ -39,10 +40,19 @@ namespace TBF.BenchControl.Operations void Loader() { - StateMachine.LoadProcedure(false); - StateMachine.LoadProcedureParams(StateMachine.Procedure); + try + { + ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config); + StateMachine.LoadPathsAndTransitions(session); + StateMachine.LoadProcedure(session); + StateMachine.LoadProcedureParams(StateMachine.Procedure); - completed = true; + completed = true; + } + catch (Exception) + { + error = true; + } } /// Run this operation diff --git a/TBF/BenchControl/Sequences/MainSeq.cs b/TBF/BenchControl/Sequences/MainSeq.cs index 13d26539d..c5e30ff25 100644 --- a/TBF/BenchControl/Sequences/MainSeq.cs +++ b/TBF/BenchControl/Sequences/MainSeq.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using log4net; +using NHibernate; using Config; using Config.Entities; using Results.Entities; @@ -34,7 +35,7 @@ namespace TBF.BenchControl.Sequences IList simultWithEvacuationTests; IList simultWithEvacuationParams; - + IList testParamsForCurrentProcedure; System.Windows.Forms.Form modelessDlg; /// @@ -108,7 +109,8 @@ namespace TBF.BenchControl.Sequences Selection selection; 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); State.Create("MainSeq : Press OK to start the system") @@ -311,15 +313,38 @@ namespace TBF.BenchControl.Sequences 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(); + foreach (var test in StateMachine.Tests) + { + IList testParams = sesn.QueryOver() + .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 + UiBridge.Bridge.OnError(this, string.Empty); /// Clear an error message (if any) + /// /// Procedure selected at this point, a new batch was started /// - StateMachine.LoadProcedureParams(StateMachine.Procedure); StateMachine.ControlBoard.ManualUIAllowed = !StateMachine.Procedure.ManualCtrlDisabled; Bridge.Bench2UI(ButtonsEtc.StopBtnEn); /// Enable STOP button @@ -493,9 +518,9 @@ namespace TBF.BenchControl.Sequences WaterMeter newWM = BatchRslts.WaterMeters[i]; 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 watermeters = session.QueryOver().Where(x => (x.SerialNr == newWM.SerialNr)).List(); + IList watermeters = sesn.QueryOver().Where(x => (x.SerialNr == newWM.SerialNr)).List(); if (watermeters.Count > 0) { 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; if (testMethod != null && testMethod.CanTest(StateMachine.Procedure.MetersKind)) { - StateMachine.LoadTestParams(test); + StateMachine.LoadTestParams(test, testParamsForCurrentProcedure); ProcessData.RegisterReaders = sensPath.RegisterReaders; 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)) { - StateMachine.LoadTestParams(dfrrdData.Test); + StateMachine.LoadTestParams(dfrrdData.Test, testParamsForCurrentProcedure); ProcessData.RegisterReaders = sensPath.RegisterReaders; foreach (var rr in sensPath.RegisterReaders) @@ -871,7 +896,7 @@ namespace TBF.BenchControl.Sequences ITestMethod testMethod = TbfComponents.FindComponent(test.Method) as ITestMethod; if (testMethod != null && testMethod.CanTest(StateMachine.Procedure.MetersKind)) { - StateMachine.LoadTestParams(test); + StateMachine.LoadTestParams(test, testParamsForCurrentProcedure); ProcessData.RegisterReaders = sensPath.RegisterReaders; foreach (var rr in sensPath.RegisterReaders) diff --git a/TBF/BenchControl/StateMachine.cs b/TBF/BenchControl/StateMachine.cs index 7b2d36918..542b4e7fa 100644 --- a/TBF/BenchControl/StateMachine.cs +++ b/TBF/BenchControl/StateMachine.cs @@ -384,9 +384,12 @@ namespace TBF.BenchControl stateMachineRunning = true; } - public static void LoadProcedure(bool loadPathsOnly) + /// + /// Loads all paths and transitions from the DB. + /// Updates StatMachine.feedingPaths ... StatMachine.meterPaths, StatMachine.TransitionSequences + /// + public static void LoadPathsAndTransitions(ISession session) { - ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config); WtSession = session; feedingPaths = session.QueryOver().OrderBy(x => x.ItemNr).Asc.List(); @@ -397,19 +400,28 @@ namespace TBF.BenchControl #if HEAT_METERS heatMetersPaths = session.QueryOver().OrderBy(x => x.ItemNr).Asc.List(); #endif - - if (loadPathsOnly) return; + } - IList selectedProcs = session.QueryOver() + /// + /// Loads selected procedure from the DB. + /// Updates StateMachine.Procedure and StateMachine.Tests + /// + public static bool LoadProcedure(ISession session) + { + WtSession = session; + + IList selectedProcs = session.QueryOver() .Where(x => (x.ProcedureState == ProcedureState.Active)) .And(x => (x.Name == TBF.UiBridge.Bridge.SelectedProcedureName)) .List(); - if (selectedProcs.Count != 1) return; + if (selectedProcs.Count != 1) return false; - Procedure = selectedProcs[0]; - Tests = selectedProcs[0].Tests; - } + Procedure = selectedProcs[0]; + Tests = selectedProcs[0].Tests; + + return true; + } 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 bufferedTestParams) { foreach (var cmpnt in components) { diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index 0515f2d42..9be4adaa3 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.18.918.0")] -[assembly: AssemblyFileVersion("2.18.918.0")] +[assembly: AssemblyVersion("2.18.920.0")] +[assembly: AssemblyFileVersion("2.18.920.0")]