Output.DB.ProductionTracing : Alternative profuction tracing DB possible.
This commit is contained in:
parent
4bf4445672
commit
94b9f564cc
@ -98,6 +98,7 @@ namespace Results.Entities
|
||||
public virtual object CompleteTestInfos { get; set; } /// SensusTestInfo[] obtained as a best match at the beginning of the cycle, not mapped to DB !!!
|
||||
#endif
|
||||
public virtual int ProcessId { get; set; } /// Not mapped to DB !!! Tracing DB Process ID
|
||||
public virtual int SessionId { get; set; } /// Not mapped to DB !!! 1 (regular tracing DB session) or 2 (alternative tracing DB session)
|
||||
public virtual bool LastRecordIsNok { get; set; } /// Not mapped to DB !!! Previous record verification result
|
||||
|
||||
public virtual WaterMeterData WaterMeterData { get; set; }
|
||||
@ -349,6 +350,7 @@ namespace Results.Entities
|
||||
CompleteTestInfos = null;
|
||||
#endif
|
||||
ProcessId = 0;
|
||||
SessionId = 0;
|
||||
ErrorFlags = 0;
|
||||
LastRecordIsNok = false;
|
||||
}
|
||||
@ -409,6 +411,7 @@ namespace Results.Entities
|
||||
CompleteTestInfos = src.CompleteTestInfos;
|
||||
#endif
|
||||
ProcessId = src.ProcessId;
|
||||
SessionId = src.SessionId;
|
||||
LastRecordIsNok = src.LastRecordIsNok;
|
||||
|
||||
foreach (var mtr in MeterTestRslts)
|
||||
|
||||
@ -18,6 +18,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
|
||||
|
||||
public string ConnStr;
|
||||
public string ConnStr2;
|
||||
public string NetAdapter;
|
||||
public bool CheckPreviousRecords;
|
||||
public bool SaveTracingRecords;
|
||||
@ -28,7 +29,8 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
{
|
||||
ParentName = string.Empty;
|
||||
NetAdapter = string.Empty;
|
||||
ConnStr = "SERVER=10.42.128.16; DATABASE=sledovanie2019; UID=vyroba2019; PASSWORD=qwerty; CHARSET=utf8;";
|
||||
ConnStr = "server=10.42.128.16; database=sledovanie2020; uid=vyroba2020; pwd=qwerty; charset=utf8;";
|
||||
ConnStr2 = "server=10.42.128.16; database=sledovanie2019; uid=vyroba2019; pwd=qwerty; charset=utf8;";
|
||||
CheckPreviousRecords = true;
|
||||
SaveTracingRecords = true;
|
||||
}
|
||||
@ -42,11 +44,12 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
|
||||
public string ToString(int i)
|
||||
{
|
||||
return string.Format("Name={0}, CheckPreviousRecords={1}, SaveTracingRecords={2}, ConnStr={3}",
|
||||
return string.Format("Name={0}, CheckPrev.={1}, SaveRecords={2}, ConnStr={3}, , ConnStr2={4}",
|
||||
Name,
|
||||
CheckPreviousRecords,
|
||||
SaveTracingRecords,
|
||||
ConnStr);
|
||||
ConnStr,
|
||||
ConnStr2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,11 +76,16 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
Results.Entities.Batch batch;
|
||||
|
||||
|
||||
ISessionFactory sessionFactory; /// Factory to create database sessions that is initialized in the constructor
|
||||
ISessionFactory sessionFactory; /// Factory to create database sessions that is initialized in the constructor
|
||||
IList<Process> processes;
|
||||
Dictionary<int, Process> processDictionary;
|
||||
Dictionary<int, IList<Workstep>> workstepsDictionary;
|
||||
|
||||
ISessionFactory sessionFactory2; /// Factory to create database sessions that is initialized in the constructor
|
||||
IList<Process> processes2;
|
||||
Dictionary<int, Process> processDictionary2;
|
||||
Dictionary<int, IList<Workstep>> workstepsDictionary2;
|
||||
|
||||
///
|
||||
/// Previous workstep verification info
|
||||
///
|
||||
@ -125,6 +130,19 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<TracingDB.Entities.Process>())
|
||||
.ExposeConfiguration(TracingDB.DB.BuildSchema)
|
||||
.BuildSessionFactory();
|
||||
|
||||
///
|
||||
/// Session factory 2 is used to create the 2nd database sessions
|
||||
///
|
||||
if (!string.IsNullOrEmpty(tracingCfg.ConnStr2))
|
||||
{
|
||||
sessionFactory2 = FluentNHibernate.Cfg.Fluently.Configure()
|
||||
.Database(FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard.ConnectionString(tracingCfg.ConnStr2))
|
||||
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<TracingDB.Entities.Process>())
|
||||
.ExposeConfiguration(TracingDB.DB.BuildSchema)
|
||||
.BuildSessionFactory();
|
||||
}
|
||||
|
||||
///
|
||||
/// Register this test bench in the tracing DB for approx. 2 weeks
|
||||
///
|
||||
@ -290,6 +308,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
{
|
||||
Retv retVal = Retv.Error;
|
||||
|
||||
bool isAtLeastOneNOK = false;
|
||||
using (ISession session = sessionFactory.OpenSession())
|
||||
{
|
||||
for (int i = 0; i < waterMeters.Length; i++)
|
||||
@ -298,22 +317,45 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
|
||||
if ((wm != null) && !wm.Disabled)
|
||||
{
|
||||
CheckPreviousRecordOfSingleWM(session, wm);
|
||||
CheckPreviousRecordOfSingleWM(session, wm, 1);
|
||||
if (wm.LastRecordIsNok)
|
||||
{
|
||||
isAtLeastOneNOK = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
retVal = Retv.OK;
|
||||
}
|
||||
|
||||
if (isAtLeastOneNOK && (sessionFactory2 != null))
|
||||
{
|
||||
using (ISession session2 = sessionFactory2.OpenSession())
|
||||
{
|
||||
for (int i = 0; i < waterMeters.Length; i++)
|
||||
{
|
||||
Results.Entities.WaterMeter wm = waterMeters[i];
|
||||
|
||||
if ((wm != null) && !wm.Disabled && wm.LastRecordIsNok)
|
||||
{
|
||||
CheckPreviousRecordOfSingleWM(session2, wm, 2);
|
||||
}
|
||||
}
|
||||
|
||||
retVal = Retv.OK;
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
Retv CheckPreviousRecordOfSingleWM(ISession session, Results.Entities.WaterMeter wm)
|
||||
Retv CheckPreviousRecordOfSingleWM(ISession session, Results.Entities.WaterMeter wm, int sessionId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(wm.SerialNr))
|
||||
{
|
||||
/// S/N is missing
|
||||
wm.ProcessId = 0;
|
||||
wm.SessionId = 0;
|
||||
wm.LastRecordIsNok = false; /// OK, this is an RFID comm. error, not a production tracing error
|
||||
return Retv.OK;
|
||||
}
|
||||
@ -345,6 +387,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
{
|
||||
/// No records found
|
||||
wm.ProcessId = 0;
|
||||
wm.SessionId = sessionId;
|
||||
wm.LastRecordIsNok = true; /// NOK
|
||||
///
|
||||
return Retv.OK;
|
||||
@ -403,7 +446,8 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
|
||||
|
||||
wm.ProcessId = currentProcess.Id;
|
||||
wm.LastRecordIsNok = true; /// NOK (=default if no matching record found)
|
||||
wm.SessionId = sessionId;
|
||||
wm.LastRecordIsNok = true; /// NOK (=default if no matching record found)
|
||||
foreach (var rslt in results)
|
||||
{
|
||||
if ((verifiedWorkstep.Id == (int)rslt[1]) && (processId == (int)rslt[2]))
|
||||
@ -427,6 +471,10 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
{
|
||||
ITransaction transaction = null;
|
||||
ISession session = null;
|
||||
|
||||
///
|
||||
/// Save to regular tracing DB
|
||||
///
|
||||
try
|
||||
{
|
||||
session = sessionFactory.OpenSession();
|
||||
@ -435,15 +483,16 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
int writtenRecordsCount = 0;
|
||||
foreach (var wMtr in batch.WaterMeters)
|
||||
{
|
||||
writtenRecordsCount += SaveSingleWM2DB(session, wMtr);
|
||||
if (wMtr.SessionId == 1)
|
||||
{
|
||||
writtenRecordsCount += SaveSingleWM2DB(session, wMtr);
|
||||
}
|
||||
}
|
||||
transaction.Commit();
|
||||
session.Flush();
|
||||
|
||||
log.ErrorFormat("Batch {0}: {1} of {2} watermeters written to production tracing DB",
|
||||
log.ErrorFormat("Batch {0}: {1} of {2} watermeters written to the regular production tracing DB",
|
||||
batch.BatchNr, writtenRecordsCount, batch.WaterMeters.Count);
|
||||
|
||||
return Retv.OK;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
@ -462,7 +511,54 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
session.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sessionFactory2 != null)
|
||||
{
|
||||
///
|
||||
/// Save to alternative tracing DB
|
||||
///
|
||||
transaction = null;
|
||||
session = null;
|
||||
try
|
||||
{
|
||||
session = sessionFactory2.OpenSession();
|
||||
transaction = session.BeginTransaction();
|
||||
|
||||
int writtenRecordsCount = 0;
|
||||
foreach (var wMtr in batch.WaterMeters)
|
||||
{
|
||||
if (wMtr.SessionId == 2)
|
||||
{
|
||||
writtenRecordsCount += SaveSingleWM2DB(session, wMtr);
|
||||
}
|
||||
}
|
||||
transaction.Commit();
|
||||
session.Flush();
|
||||
|
||||
log.ErrorFormat("Batch {0}: {1} of {2} watermeters written to the alternative production tracing DB",
|
||||
batch.BatchNr, writtenRecordsCount, batch.WaterMeters.Count);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
if (transaction != null && !transaction.WasCommitted) transaction.Rollback();
|
||||
|
||||
log.WarnFormat("Failed to write results of batch {0} to production tracing DB: {1}",
|
||||
batch.BatchNr, exc.Message);
|
||||
|
||||
return Retv.Error;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (session != null)
|
||||
{
|
||||
session.Close();
|
||||
session.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Retv.OK;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -47,6 +47,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
classNameLabel.Text = config.Factory.ClassName;
|
||||
nameTextBox.Text = config.Name;
|
||||
connStrTextBox.Text = config.ConnStr;
|
||||
connStr2TextBox.Text = config.ConnStr2;
|
||||
checkPreviousRecordsCheckBox.Checked = config.CheckPreviousRecords;
|
||||
saveTracingRecordsCheckBox.Checked = config.SaveTracingRecords;
|
||||
|
||||
@ -102,6 +103,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
{
|
||||
nameTextBox.Enabled = true;
|
||||
connStrTextBox.Enabled = true;
|
||||
connStr2TextBox.Enabled = true;
|
||||
netAdapterComboBox.Enabled = true;
|
||||
checkPreviousRecordsCheckBox.Enabled = true;
|
||||
saveTracingRecordsCheckBox.Enabled = true;
|
||||
@ -125,6 +127,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
}
|
||||
|
||||
flags |= UpdateDifferent(ref config.ConnStr, connStrTextBox.Text, CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd);
|
||||
flags |= UpdateDifferent(ref config.ConnStr2, connStr2TextBox.Text, CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd);
|
||||
flags |= UpdateDifferent(ref config.CheckPreviousRecords, checkPreviousRecordsCheckBox.Checked, CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd);
|
||||
flags |= UpdateDifferent(ref config.SaveTracingRecords, saveTracingRecordsCheckBox.Checked, CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd);
|
||||
|
||||
|
||||
@ -40,29 +40,31 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
this.checkPreviousRecordsCheckBox = new System.Windows.Forms.CheckBox();
|
||||
this.netAdapterLabel = new System.Windows.Forms.Label();
|
||||
this.netAdapterComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.connStr2TextBox = new System.Windows.Forms.TextBox();
|
||||
this.connStr2Label = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// nameTextBox
|
||||
//
|
||||
this.nameTextBox.Enabled = false;
|
||||
this.nameTextBox.Location = new System.Drawing.Point(110, 51);
|
||||
this.nameTextBox.Location = new System.Drawing.Point(117, 32);
|
||||
this.nameTextBox.Name = "nameTextBox";
|
||||
this.nameTextBox.Size = new System.Drawing.Size(146, 20);
|
||||
this.nameTextBox.Size = new System.Drawing.Size(326, 20);
|
||||
this.nameTextBox.TabIndex = 2;
|
||||
//
|
||||
// nameLabel
|
||||
//
|
||||
this.nameLabel.AutoSize = true;
|
||||
this.nameLabel.Location = new System.Drawing.Point(15, 54);
|
||||
this.nameLabel.Location = new System.Drawing.Point(5, 35);
|
||||
this.nameLabel.Name = "nameLabel";
|
||||
this.nameLabel.Size = new System.Drawing.Size(35, 13);
|
||||
this.nameLabel.Size = new System.Drawing.Size(38, 13);
|
||||
this.nameLabel.TabIndex = 1;
|
||||
this.nameLabel.Text = "Name";
|
||||
this.nameLabel.Text = "Name:";
|
||||
//
|
||||
// classNameLabel
|
||||
//
|
||||
this.classNameLabel.AutoSize = true;
|
||||
this.classNameLabel.Location = new System.Drawing.Point(107, 26);
|
||||
this.classNameLabel.Location = new System.Drawing.Point(114, 10);
|
||||
this.classNameLabel.Name = "classNameLabel";
|
||||
this.classNameLabel.Size = new System.Drawing.Size(83, 13);
|
||||
this.classNameLabel.TabIndex = 0;
|
||||
@ -71,25 +73,25 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
// connStrTextBox
|
||||
//
|
||||
this.connStrTextBox.Enabled = false;
|
||||
this.connStrTextBox.Location = new System.Drawing.Point(110, 76);
|
||||
this.connStrTextBox.Location = new System.Drawing.Point(8, 74);
|
||||
this.connStrTextBox.Name = "connStrTextBox";
|
||||
this.connStrTextBox.Size = new System.Drawing.Size(327, 20);
|
||||
this.connStrTextBox.TabIndex = 6;
|
||||
this.connStrTextBox.Size = new System.Drawing.Size(435, 20);
|
||||
this.connStrTextBox.TabIndex = 4;
|
||||
//
|
||||
// connStrLabel
|
||||
//
|
||||
this.connStrLabel.AutoSize = true;
|
||||
this.connStrLabel.Location = new System.Drawing.Point(15, 79);
|
||||
this.connStrLabel.Location = new System.Drawing.Point(5, 58);
|
||||
this.connStrLabel.Name = "connStrLabel";
|
||||
this.connStrLabel.Size = new System.Drawing.Size(89, 13);
|
||||
this.connStrLabel.TabIndex = 5;
|
||||
this.connStrLabel.Text = "Connection string";
|
||||
this.connStrLabel.Size = new System.Drawing.Size(92, 13);
|
||||
this.connStrLabel.TabIndex = 3;
|
||||
this.connStrLabel.Text = "Connection string:";
|
||||
//
|
||||
// saveTracingRecordsCheckBox
|
||||
//
|
||||
this.saveTracingRecordsCheckBox.AutoSize = true;
|
||||
this.saveTracingRecordsCheckBox.Enabled = false;
|
||||
this.saveTracingRecordsCheckBox.Location = new System.Drawing.Point(110, 159);
|
||||
this.saveTracingRecordsCheckBox.Location = new System.Drawing.Point(117, 221);
|
||||
this.saveTracingRecordsCheckBox.Name = "saveTracingRecordsCheckBox";
|
||||
this.saveTracingRecordsCheckBox.Size = new System.Drawing.Size(177, 17);
|
||||
this.saveTracingRecordsCheckBox.TabIndex = 10;
|
||||
@ -100,7 +102,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
//
|
||||
this.checkPreviousRecordsCheckBox.AutoSize = true;
|
||||
this.checkPreviousRecordsCheckBox.Enabled = false;
|
||||
this.checkPreviousRecordsCheckBox.Location = new System.Drawing.Point(110, 136);
|
||||
this.checkPreviousRecordsCheckBox.Location = new System.Drawing.Point(117, 199);
|
||||
this.checkPreviousRecordsCheckBox.Name = "checkPreviousRecordsCheckBox";
|
||||
this.checkPreviousRecordsCheckBox.Size = new System.Drawing.Size(138, 17);
|
||||
this.checkPreviousRecordsCheckBox.TabIndex = 9;
|
||||
@ -110,24 +112,44 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
// netAdapterLabel
|
||||
//
|
||||
this.netAdapterLabel.AutoSize = true;
|
||||
this.netAdapterLabel.Location = new System.Drawing.Point(15, 104);
|
||||
this.netAdapterLabel.Location = new System.Drawing.Point(5, 147);
|
||||
this.netAdapterLabel.Name = "netAdapterLabel";
|
||||
this.netAdapterLabel.Size = new System.Drawing.Size(86, 13);
|
||||
this.netAdapterLabel.Size = new System.Drawing.Size(89, 13);
|
||||
this.netAdapterLabel.TabIndex = 7;
|
||||
this.netAdapterLabel.Text = "Network adapter";
|
||||
this.netAdapterLabel.Text = "Network adapter:";
|
||||
//
|
||||
// netAdapterComboBox
|
||||
//
|
||||
this.netAdapterComboBox.Enabled = false;
|
||||
this.netAdapterComboBox.FormattingEnabled = true;
|
||||
this.netAdapterComboBox.Location = new System.Drawing.Point(110, 101);
|
||||
this.netAdapterComboBox.Location = new System.Drawing.Point(8, 163);
|
||||
this.netAdapterComboBox.Name = "netAdapterComboBox";
|
||||
this.netAdapterComboBox.Size = new System.Drawing.Size(327, 21);
|
||||
this.netAdapterComboBox.TabIndex = 11;
|
||||
this.netAdapterComboBox.Size = new System.Drawing.Size(435, 21);
|
||||
this.netAdapterComboBox.TabIndex = 8;
|
||||
//
|
||||
// connStr2TextBox
|
||||
//
|
||||
this.connStr2TextBox.Enabled = false;
|
||||
this.connStr2TextBox.Location = new System.Drawing.Point(8, 118);
|
||||
this.connStr2TextBox.Name = "connStr2TextBox";
|
||||
this.connStr2TextBox.Size = new System.Drawing.Size(434, 20);
|
||||
this.connStr2TextBox.TabIndex = 6;
|
||||
//
|
||||
// connStr2Label
|
||||
//
|
||||
this.connStr2Label.AutoSize = true;
|
||||
this.connStr2Label.Location = new System.Drawing.Point(5, 102);
|
||||
this.connStr2Label.Name = "connStr2Label";
|
||||
this.connStr2Label.Size = new System.Drawing.Size(101, 13);
|
||||
this.connStr2Label.TabIndex = 5;
|
||||
this.connStr2Label.Text = "Connection string 2:";
|
||||
//
|
||||
// TracingCfgCtrl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.connStr2TextBox);
|
||||
this.Controls.Add(this.connStr2Label);
|
||||
this.Controls.Add(this.netAdapterComboBox);
|
||||
this.Controls.Add(this.netAdapterLabel);
|
||||
this.Controls.Add(this.saveTracingRecordsCheckBox);
|
||||
@ -138,7 +160,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
this.Controls.Add(this.nameLabel);
|
||||
this.Controls.Add(this.classNameLabel);
|
||||
this.Name = "TracingCfgCtrl";
|
||||
this.Size = new System.Drawing.Size(450, 230);
|
||||
this.Size = new System.Drawing.Size(450, 250);
|
||||
this.Load += new System.EventHandler(this.WriterCfgCtrl_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
@ -156,5 +178,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
|
||||
private System.Windows.Forms.CheckBox checkPreviousRecordsCheckBox;
|
||||
private System.Windows.Forms.Label netAdapterLabel;
|
||||
private System.Windows.Forms.ComboBox netAdapterComboBox;
|
||||
private System.Windows.Forms.TextBox connStr2TextBox;
|
||||
private System.Windows.Forms.Label connStr2Label;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user