(1) power users obtain nr.6 on startup, (2) maxBatchNr from DB detected and used, (3) more logging, ver. 2.4.258.

This commit is contained in:
Milan Hanajik 2016-04-07 13:52:57 +02:00
parent a275a911f6
commit 2d20ea1196
5 changed files with 160 additions and 90 deletions

View File

@ -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
{

View File

@ -182,6 +182,23 @@ namespace Results
WaterMeterDataList = session.CreateQuery("FROM WaterMeterData").List<Entities.WaterMeterData>();
}
/// <summary>
/// Loads shared data from the database
/// </summary>
/// <exception>Throws NHibernate exceptions</exception>
public static int GetMaxSavedBatchNr()
{
ISession session = DB.CreateSession();
IList<Entities.Batch> batches = session.CreateQuery("FROM Batch").List<Entities.Batch>();
int maxBatchNr = 0;
foreach (var b in batches)
{
if (b.BatchNr > maxBatchNr) maxBatchNr = b.BatchNr;
}
return maxBatchNr;
}
/// <summary>
/// Update TestData, Components and WaterMeterData fo tests and water meters in batch results

View File

@ -21,6 +21,17 @@ namespace TBF.BenchControl.Sequences
public override string ToString() { return "Sequences.MainSeq"; }
int simultWithPurgingCount;
Generic.IComponentCfg simultWithPurgingCfg;
IList<Config.Entities.Test> simultWithPurgingTests;
IList<Generic.ITestParams> simultWithPurgingParams;
int simultWithEvacuationCount;
Generic.IComponentCfg simultWithEvacuationCfg;
IList<Config.Entities.Test> simultWithEvacuationTests;
IList<Generic.ITestParams> simultWithEvacuationParams;
System.Windows.Forms.Form modelessDlg;
///
delegate void iPerlCommFormDlgt(MainSeq myRef, Generic.IComponentCfg cfg, IList<Test> tests, IList<Generic.ITestParams> multiTestParams);
@ -65,7 +76,11 @@ namespace TBF.BenchControl.Sequences
/// <summary> Constructor </summary>
public MainSeq()
{
}
simultWithPurgingTests = new List<Config.Entities.Test>();
simultWithPurgingParams = new List<Generic.ITestParams>();
simultWithEvacuationTests = new List<Config.Entities.Test>();
simultWithEvacuationParams = new List<Generic.ITestParams>();
}
/// <summary>
@ -82,15 +97,15 @@ namespace TBF.BenchControl.Sequences
Selection selection;
bool benchFilled = false;
int simultWithPurgingCount = 0;
Generic.IComponentCfg simultWithPurgingCfg = null;
IList<Config.Entities.Test> simultWithPurgingTests = new List<Config.Entities.Test>();
IList<Generic.ITestParams> simultWithPurgingParams = new List<Generic.ITestParams>();
simultWithPurgingCount = 0;
simultWithPurgingCfg = null;
simultWithPurgingTests.Clear();
simultWithPurgingParams.Clear();
int simultWithEvacuationCount = 0;
Generic.IComponentCfg simultWithEvacuationCfg = null;
IList<Config.Entities.Test> simultWithEvacuationTests = new List<Config.Entities.Test>();
IList<Generic.ITestParams> simultWithEvacuationParams = new List<Generic.ITestParams>();
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++;
}
}
}
}

View File

@ -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;

View File

@ -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")]