diff --git a/Config/Entities/User.cs b/Config/Entities/User.cs index 1c38bf0b7..c92beab73 100644 --- a/Config/Entities/User.cs +++ b/Config/Entities/User.cs @@ -7,12 +7,15 @@ using System.Security.Cryptography; using System.Text; using System.Diagnostics; using Config.Resources; +using log4net; namespace Config.Entities { public class User { - public virtual int Id { get; protected set; } + static readonly ILog log = LogManager.GetLogger(typeof(User)); + + public virtual int Id { get; protected set; } public virtual string Name { get; set; } public virtual int Number { get; set; } public virtual string Password { get; set; } @@ -140,6 +143,7 @@ namespace Config.Entities { currentUser = this; lastAuthorization = DateTime.Now; + log.FatalFormat("Power user '{0}' authorized @level '{1}'", userName, requiredGroupMembership); return true; } @@ -149,7 +153,8 @@ namespace Config.Entities { currentUser = this; lastAuthorization = DateTime.Now; - return true; + log.FatalFormat("User '{0}' authorized @level '{1}'", userName, requiredGroupMembership); + return true; } else { diff --git a/Results/DB.cs b/Results/DB.cs index 19acb6349..38146e143 100644 --- a/Results/DB.cs +++ b/Results/DB.cs @@ -182,6 +182,23 @@ namespace Results WaterMeterDataList = session.CreateQuery("FROM WaterMeterData").List(); } + /// + /// Loads shared data from the database + /// + /// Throws NHibernate exceptions + public static int GetMaxSavedBatchNr() + { + ISession session = DB.CreateSession(); + IList batches = session.CreateQuery("FROM Batch").List(); + + int maxBatchNr = 0; + foreach (var b in batches) + { + if (b.BatchNr > maxBatchNr) maxBatchNr = b.BatchNr; + } + return maxBatchNr; + } + /// /// Update TestData, Components and WaterMeterData fo tests and water meters in batch results diff --git a/TestBenchFramework/BenchControl/Sequences/MainSeq.cs b/TestBenchFramework/BenchControl/Sequences/MainSeq.cs index 498e30588..1f29e60db 100644 --- a/TestBenchFramework/BenchControl/Sequences/MainSeq.cs +++ b/TestBenchFramework/BenchControl/Sequences/MainSeq.cs @@ -21,6 +21,17 @@ namespace TBF.BenchControl.Sequences public override string ToString() { return "Sequences.MainSeq"; } + int simultWithPurgingCount; + Generic.IComponentCfg simultWithPurgingCfg; + IList simultWithPurgingTests; + IList simultWithPurgingParams; + + int simultWithEvacuationCount; + Generic.IComponentCfg simultWithEvacuationCfg; + IList simultWithEvacuationTests; + IList simultWithEvacuationParams; + + System.Windows.Forms.Form modelessDlg; /// delegate void iPerlCommFormDlgt(MainSeq myRef, Generic.IComponentCfg cfg, IList tests, IList multiTestParams); @@ -65,7 +76,11 @@ namespace TBF.BenchControl.Sequences /// Constructor public MainSeq() { - } + simultWithPurgingTests = new List(); + simultWithPurgingParams = new List(); + simultWithEvacuationTests = new List(); + simultWithEvacuationParams = new List(); + } /// @@ -82,15 +97,15 @@ namespace TBF.BenchControl.Sequences Selection selection; bool benchFilled = false; - int simultWithPurgingCount = 0; - Generic.IComponentCfg simultWithPurgingCfg = null; - IList simultWithPurgingTests = new List(); - IList simultWithPurgingParams = new List(); + simultWithPurgingCount = 0; + simultWithPurgingCfg = null; + simultWithPurgingTests.Clear(); + simultWithPurgingParams.Clear(); - int simultWithEvacuationCount = 0; - Generic.IComponentCfg simultWithEvacuationCfg = null; - IList simultWithEvacuationTests = new List(); - IList simultWithEvacuationParams = new List(); + simultWithEvacuationCount = 0; + simultWithEvacuationCfg = null; + simultWithEvacuationTests.Clear(); + simultWithEvacuationParams.Clear(); StateMachine.LoadProcedure(true); // TODO: Implement as an operation so that the worker thread is not blocked @@ -213,7 +228,7 @@ namespace TBF.BenchControl.Sequences //-------------------------------------------------------------------------------------------- select_procedure: - /// Make sure the CycleBeginForm is closed (aftrer an abnormal procedure/test end, etc.) + /// Make sure the CycleBeginForm is closed (after an abnormal procedure/test end, etc.) CloseBeginForm(); selection = MakeSelection(MKSelContext.ProcedureNotSelected); @@ -228,7 +243,9 @@ namespace TBF.BenchControl.Sequences /// StateMachine.LoadProcedureParams(StateMachine.Procedure); + /// /// Prepare new water meters + /// foreach (var wm in WaterMeters) wm.ClearData(); /// Clean water meter data bool compound = (StateMachine.Procedure.MetersKind == MetersKind.Combined); @@ -259,14 +276,16 @@ namespace TBF.BenchControl.Sequences #endif } + /// /// Prepare empty results + /// BatchRslts = Results.BatchResults.NewFromProcedure(Program.LocalSettings.BatchNr, (BenchInfo != null) ? BenchInfo.TestBenchId : 1, User.CurrentUser.Name, User.CurrentUser.Number, Program.Version, StateMachine.Procedure, waterMeterData, waterMeterParts); - StateMachine.CycleStartTimeStamp = BatchRslts.Batch.StartTime; + Bridge.OnProcedureSelected(this, new ProcedureSelectedEventArgs(StateMachine.Procedure)); /// Display 'Cycle Begin Form' @@ -305,76 +324,7 @@ namespace TBF.BenchControl.Sequences fill_the_bench: - /// - /// Collect steps (e.g. iPerl communication) to be done simultaneously with purging - /// - simultWithPurgingCount = 0; - simultWithPurgingCfg = null; - simultWithPurgingTests.Clear(); - simultWithPurgingParams.Clear(); - /// - foreach (var test in StateMachine.Tests) - { - Generic.IComponent testMethodComp = TbfComponents.FindComponent(test.Method); - if (testMethodComp == null) break; - - testMethodComp.Cfg.UpdateTestParams(test); - - ISimultTestMethod simultTest = testMethodComp as ISimultTestMethod; - MetersPath sensPath = StateMachine.GetMetersPath(test); - - if (simultTest == null || !simultTest.SimultWithPrevious || sensPath == null) break; - - if (simultWithPurgingCount == 0) - { - simultWithPurgingCfg = simultTest.Cfg; - } - else if (simultTest.Cfg != simultWithPurgingCfg) - { - break; - } - - simultWithPurgingTests.Add(test); - simultWithPurgingParams.Add(testMethodComp.Cfg.GetTestParams().Clone() as Generic.ITestParams); - simultWithPurgingCount++; - } - - /// - /// Collect steps (e.g. iPerl communication) to be done simultaneously with evacuation - /// - simultWithEvacuationCount = 0; - simultWithEvacuationCfg = null; - simultWithEvacuationTests.Clear(); - simultWithEvacuationParams.Clear(); - /// - for (int i = StateMachine.Tests.Count - 1; i >= simultWithPurgingCount; i--) - { - var test = StateMachine.Tests[i]; - - Generic.IComponent testMethodComp = TbfComponents.FindComponent(test.Method); - if (testMethodComp == null) break; - - testMethodComp.Cfg.UpdateTestParams(test); - - ISimultTestMethod simultTest = testMethodComp as ISimultTestMethod; - MetersPath sensPath = StateMachine.GetMetersPath(test); - - if (simultTest == null || !simultTest.SimultWithNext || sensPath == null) break; - - if (simultWithEvacuationCount == 0) - { - simultWithEvacuationCfg = simultTest.Cfg; - } - else if (simultTest.Cfg != simultWithEvacuationCfg) - { - break; - } - - simultWithEvacuationTests.Insert(0, test); - simultWithEvacuationParams.Insert(0, testMethodComp.Cfg.GetTestParams().Clone() as Generic.ITestParams); - simultWithEvacuationCount++; - } - + CollectSimultSteps(); /// if (simultWithPurgingCount > 0) { @@ -465,6 +415,10 @@ namespace TBF.BenchControl.Sequences Bridge.Bench2UI(ButtonsEtc.StopBtnEn); /// Hide buttons + if (selection != Selection.Cycle) + { + } + if (selection == Selection.Cycle) { float TimeEstimateTotal; /// Time estimate of the selected cycle or test @@ -703,6 +657,7 @@ namespace TBF.BenchControl.Sequences Program.LocalSettings.BatchNr++; Program.LocalSettings.Save(); + log.FatalFormat("BatchNr = {0} (incremented)", Program.LocalSettings.BatchNr); if (simultWithEvacuationCount > 0) @@ -1145,5 +1100,79 @@ namespace TBF.BenchControl.Sequences .EnterState(); while (true) StateMachine.WaitRunDevsRunOps(); } - } + + + void CollectSimultSteps() + { + /// + /// Collect steps (e.g. iPerl communication) to be done simultaneously with purging + /// + simultWithPurgingCount = 0; + simultWithPurgingCfg = null; + simultWithPurgingTests.Clear(); + simultWithPurgingParams.Clear(); + /// + foreach (var test in StateMachine.Tests) + { + Generic.IComponent testMethodComp = TbfComponents.FindComponent(test.Method); + if (testMethodComp == null) break; + + testMethodComp.Cfg.UpdateTestParams(test); + + ISimultTestMethod simultTest = testMethodComp as ISimultTestMethod; + MetersPath sensPath = StateMachine.GetMetersPath(test); + + if (simultTest == null || !simultTest.SimultWithPrevious || sensPath == null) break; + + if (simultWithPurgingCount == 0) + { + simultWithPurgingCfg = simultTest.Cfg; + } + else if (simultTest.Cfg != simultWithPurgingCfg) + { + break; + } + + simultWithPurgingTests.Add(test); + simultWithPurgingParams.Add(testMethodComp.Cfg.GetTestParams().Clone() as Generic.ITestParams); + simultWithPurgingCount++; + } + + /// + /// Collect steps (e.g. iPerl communication) to be done simultaneously with evacuation + /// + simultWithEvacuationCount = 0; + simultWithEvacuationCfg = null; + simultWithEvacuationTests.Clear(); + simultWithEvacuationParams.Clear(); + /// + for (int i = StateMachine.Tests.Count - 1; i >= simultWithPurgingCount; i--) + { + var test = StateMachine.Tests[i]; + + Generic.IComponent testMethodComp = TbfComponents.FindComponent(test.Method); + if (testMethodComp == null) break; + + testMethodComp.Cfg.UpdateTestParams(test); + + ISimultTestMethod simultTest = testMethodComp as ISimultTestMethod; + MetersPath sensPath = StateMachine.GetMetersPath(test); + + if (simultTest == null || !simultTest.SimultWithNext || sensPath == null) break; + + if (simultWithEvacuationCount == 0) + { + simultWithEvacuationCfg = simultTest.Cfg; + } + else if (simultTest.Cfg != simultWithEvacuationCfg) + { + break; + } + + simultWithEvacuationTests.Insert(0, test); + simultWithEvacuationParams.Insert(0, testMethodComp.Cfg.GetTestParams().Clone() as Generic.ITestParams); + simultWithEvacuationCount++; + } + } + } } diff --git a/TestBenchFramework/Program.cs b/TestBenchFramework/Program.cs index af57f7a7a..3fcb2a9a3 100644 --- a/TestBenchFramework/Program.cs +++ b/TestBenchFramework/Program.cs @@ -116,19 +116,26 @@ namespace TBF Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsBackupName); if (Program.LocalSettings == null || Program.LocalSettings.TestBenches == null) { + log.FatalFormat("Local settings: Could not load file {0}, nor {1}.", Program.LocalSettingsFileName, Program.LocalSettingsBackupName); + log.Fatal("Application terminated."); return; /// Fatal error } else { LocalSettings.Save(); /// Save the settings to overwrite the wrong file + log.FatalFormat("Local settings: Could not load file {0}, successfully loaded {1}", Program.LocalSettingsFileName, Program.LocalSettingsBackupName); + log.FatalFormat("BatchNr = {0}", LocalSettings.BatchNr); } } else { /// Loading local seetings from the regular config file was successful. Update the backup File.Copy(Program.LocalSettingsFileName, Program.LocalSettingsBackupName, true); + log.FatalFormat("Local settings: Successfully loaded from {0}", Program.LocalSettingsFileName); + log.FatalFormat("BatchNr = {0}", LocalSettings.BatchNr); } + try { string culture = LocalSettings.Language.Replace('_', '-'); @@ -145,11 +152,13 @@ namespace TBF //AltCulture = null; AltCulture = new System.Globalization.CultureInfo("SK"); + /// This belongs to Application.Run(new MainWnd()) ... /// and should be executed before opening 'loginDlg' Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); + /// Ensure that there is at least one bench in the configuration while (Program.LocalSettings.BenchesCount == 0) { @@ -170,7 +179,8 @@ namespace TBF /// User login bool retryLogin = true; /// true = stay in a login loop - do { + do + { LoginDlgWithBenchSelection loginDlgBench; if (LocalSettings.LastBenchName != null) { @@ -188,11 +198,12 @@ namespace TBF } else { - for (int i = 0; i < LocalSettings.BenchesCount; i++) { if (LocalSettings.TestBenches[i].BenchName == loginDlgBench.BenchName) - { + { + log.FatalFormat("Test bench name: {0}", loginDlgBench.BenchName); + User loadedUser = null; try { @@ -200,7 +211,7 @@ namespace TBF if (User.IsPowerUser(loginDlgBench.User, loginDlgBench.Password)) { - loadedUser = new User(loginDlgBench.User); + loadedUser = new User(loginDlgBench.User, 6); authorized = loadedUser.Authorize(loginDlgBench.User, loginDlgBench.Password); } @@ -231,6 +242,14 @@ namespace TBF Results.DB.DbType = Config.Data.CurrentBench.WaterMetersDBSettings.DbType; Results.DB.ConnectionString = Config.Data.CurrentBench.WaterMetersDBSettings.ConnectionString; Results.DB.LoadSharedData(); + int maxBatchNr = Results.DB.GetMaxSavedBatchNr(); + if (Program.LocalSettings.BatchNr <= maxBatchNr) + { + log.FatalFormat("Max. BatchNr in DB = {0}, LocalSettings.BatchNr = {1}", maxBatchNr, Program.LocalSettings.BatchNr); + Program.LocalSettings.BatchNr = maxBatchNr + 1; + Program.LocalSettings.Save(); + log.FatalFormat("LocalSettings.BatchNr updated to {0}", Program.LocalSettings.BatchNr); + } retryLogin = false; break; diff --git a/TestBenchFramework/Properties/AssemblyInfo.cs b/TestBenchFramework/Properties/AssemblyInfo.cs index 33db230e4..efe465020 100644 --- a/TestBenchFramework/Properties/AssemblyInfo.cs +++ b/TestBenchFramework/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.5.257.1")] -[assembly: AssemblyFileVersion("2.5.257.1")] +[assembly: AssemblyVersion("2.5.258.1")] +[assembly: AssemblyFileVersion("2.5.258.1")]