ProductionTracing : 1. No alternative tracing DB, 2. SaveTracingRecords( ) is public
This commit is contained in:
parent
3da6fcfe73
commit
426bb0cce9
@ -99,7 +99,6 @@ namespace Results.Entities
|
||||
public virtual int HydrPruefung { get; set; }
|
||||
#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; }
|
||||
@ -458,7 +457,6 @@ namespace Results.Entities
|
||||
HydrPruefung = 0;
|
||||
#endif
|
||||
ProcessId = 0;
|
||||
SessionId = 0;
|
||||
LastRecordIsNok = false;
|
||||
}
|
||||
|
||||
@ -520,7 +518,6 @@ namespace Results.Entities
|
||||
HydrPruefung = src.HydrPruefung;
|
||||
#endif
|
||||
ProcessId = src.ProcessId; /// Not mapped to DB
|
||||
SessionId = src.SessionId; /// Not mapped to DB
|
||||
LastRecordIsNok = src.LastRecordIsNok; /// Not mapped to DB
|
||||
|
||||
foreach (var mtr in MeterTestRslts)
|
||||
@ -700,7 +697,6 @@ namespace Results.Entities
|
||||
writer.Write(HydrPruefung);
|
||||
#endif
|
||||
writer.Write(ProcessId);
|
||||
writer.Write(SessionId);
|
||||
writer.Write(LastRecordIsNok);
|
||||
|
||||
/// Save WaterMeterData or WaterMeterData.Id
|
||||
@ -780,7 +776,6 @@ namespace Results.Entities
|
||||
HydrPruefung = reader.ReadInt32();
|
||||
#endif
|
||||
ProcessId = reader.ReadInt32();
|
||||
SessionId = reader.ReadInt32();
|
||||
LastRecordIsNok = reader.ReadBoolean();
|
||||
|
||||
/// Retrieve TestData
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2018 Sensus Slovensko a.s.
|
||||
/// Copyright (c) 2018-2023 Sensus Slovensko a.s.
|
||||
///
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
@ -19,7 +19,6 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
|
||||
|
||||
public string ConnStr;
|
||||
public string ConnStr2;
|
||||
public string NetAdapter;
|
||||
public bool CheckPreviousRecords;
|
||||
public bool SaveTracingRecords;
|
||||
@ -30,8 +29,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
{
|
||||
ParentName = string.Empty;
|
||||
NetAdapter = string.Empty;
|
||||
ConnStr = "server=10.42.128.24; database=sledovanie2020; uid=vyroba2020; pwd=qwerty; charset=utf8;";
|
||||
ConnStr2 = "server=10.42.128.24; database=sledovanie2019; uid=vyroba2019; pwd=qwerty; charset=utf8;";
|
||||
ConnStr = "server=10.42.128.35; database=sledovanie2019; uid=sledovanie2019; pwd=velka-javorina-970; charset=utf8;";
|
||||
CheckPreviousRecords = true;
|
||||
SaveTracingRecords = true;
|
||||
}
|
||||
@ -45,12 +43,11 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
|
||||
public string ToString(int i)
|
||||
{
|
||||
return string.Format("Name={0}, CheckPrev.={1}, SaveRecords={2}, ConnStr={3}, , ConnStr2={4}",
|
||||
return string.Format("Name={0}, CheckPrev={1}, SaveRecords={2}, ConnStr={3}",
|
||||
Name,
|
||||
CheckPreviousRecords,
|
||||
SaveTracingRecords,
|
||||
ConnStr,
|
||||
ConnStr2);
|
||||
ConnStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,17 +78,11 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
/// </summary>
|
||||
Results.Entities.Batch batch;
|
||||
|
||||
|
||||
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
|
||||
///
|
||||
@ -127,18 +121,6 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
.SetProperty("hibernate.connection.connect_timeout", Const.MySqlConnectTimeoutSec)
|
||||
.BuildSessionFactory();
|
||||
|
||||
/// Session factory 2 is used to create the 2nd database sessions
|
||||
if (!string.IsNullOrEmpty(tracingCfg.ConnStr2))
|
||||
{
|
||||
sessionFactory2 = Fluently.Configure()
|
||||
.Database(FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard.ConnectionString(tracingCfg.ConnStr2))
|
||||
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<TracingDB.Entities.Process>())
|
||||
.ExposeConfiguration(TracingDB.DB.BuildSchema)
|
||||
.BuildConfiguration()
|
||||
.SetProperty("hibernate.connection.connect_timeout", Const.MySqlConnectTimeoutSec)
|
||||
.BuildSessionFactory();
|
||||
}
|
||||
|
||||
/// Register this test bench in the tracing DB for approx. 2 weeks
|
||||
var session = sessionFactory.OpenSession();
|
||||
#if !DEBUG
|
||||
@ -359,7 +341,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
|
||||
if ((wm != null) && !wm.Disabled)
|
||||
{
|
||||
CheckPreviousRecordOfSingleWM(session, wm, 1);
|
||||
CheckPreviousRecordOfSingleWM(session, wm);
|
||||
if (wm.LastRecordIsNok)
|
||||
{
|
||||
isAtLeastOneNOK = true;
|
||||
@ -370,34 +352,15 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
retVal = Retv.OK;
|
||||
}
|
||||
|
||||
if (isAtLeastOneNOK && (sessionFactory2 != null))
|
||||
{
|
||||
using (ISession session2 = sessionFactory2.OpenSession())
|
||||
{
|
||||
for (int i = 0; i < waterMeters.Count; 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, int sessionId)
|
||||
Retv CheckPreviousRecordOfSingleWM(ISession session, Results.Entities.WaterMeter wm)
|
||||
{
|
||||
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;
|
||||
}
|
||||
@ -431,7 +394,6 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
{
|
||||
/// No records found
|
||||
wm.ProcessId = 0;
|
||||
wm.SessionId = sessionId;
|
||||
wm.LastRecordIsNok = true; /// NOK
|
||||
///
|
||||
return Retv.OK;
|
||||
@ -479,7 +441,6 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
|
||||
|
||||
wm.ProcessId = currentProcess.Id;
|
||||
wm.SessionId = sessionId;
|
||||
wm.LastRecordIsNok = true; /// NOK (=default if no matching record found)
|
||||
foreach (var rcrd in records)
|
||||
{
|
||||
@ -500,7 +461,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
/// </summary>
|
||||
/// <param name="session">DB session</param>
|
||||
/// <param name="batch">Batch entity</param>
|
||||
Retv SaveTracingRecords(Results.Entities.Batch batch)
|
||||
public Retv SaveTracingRecords(Results.Entities.Batch batch)
|
||||
{
|
||||
ITransaction transaction = null;
|
||||
ISession session = null;
|
||||
@ -515,12 +476,9 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
|
||||
int writtenRecordsCount = 0;
|
||||
foreach (var wMtr in batch.WaterMeters)
|
||||
{
|
||||
if (wMtr.SessionId == 1)
|
||||
{
|
||||
writtenRecordsCount += SaveSingleWM2DB(session, wMtr);
|
||||
}
|
||||
}
|
||||
transaction.Commit();
|
||||
session.Flush();
|
||||
|
||||
@ -545,51 +503,6 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -602,12 +515,12 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
/// <returns>Number of written reference record</returns>
|
||||
int SaveSingleWM2DB(ISession session, Results.Entities.WaterMeter wm)
|
||||
{
|
||||
if (string.IsNullOrEmpty(wm.SerialNr) || (wm.ProcessId == 0))
|
||||
if (string.IsNullOrEmpty(wm.SerialNr))
|
||||
{
|
||||
/// Without PCB number there is no DB activity
|
||||
return 0;
|
||||
}
|
||||
else if ((currentProcess != null) && (wm.ProcessId == currentProcess.Id))
|
||||
else if (wm.ProcessId != 0 && currentProcess != null && wm.ProcessId == currentProcess.Id)
|
||||
{
|
||||
/// Process is already loaded => save a reference record for this WM
|
||||
session.SaveOrUpdate(new ReferenceRecord(currentProcess, currentWorkstep, wm.SerialNr, Users.CurrentUser.UserName(), workplace, wm.Passed ? 0 : 1));
|
||||
@ -639,23 +552,19 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
///
|
||||
|
||||
/// Get all already existing reference records with Code == wm.SerialNr, refRecords[0] will be the most recent one
|
||||
IList<ReferenceRecord> refRecords;
|
||||
int trialsCount = 0;
|
||||
do
|
||||
{
|
||||
if (trialsCount > 0) ReadProcessesFromDB(session);
|
||||
ReadProcessesFromDB(session);
|
||||
|
||||
refRecords = session.QueryOver<ReferenceRecord>()
|
||||
var refRecords = session.QueryOver<ReferenceRecord>()
|
||||
.Where(rr => (rr.Code == wm.SerialNr))
|
||||
.OrderBy(rr => rr.TimeStamp).Desc
|
||||
.List();
|
||||
trialsCount++;
|
||||
}
|
||||
while (refRecords.Count == 0 && trialsCount <= 2);
|
||||
|
||||
/// Save a new reference record from this test bench if workstep "Test_bench" is defined in the obtained WM process
|
||||
IList<Workstep> worksteps;
|
||||
if ((refRecords.Count > 0) && workstepsDictionary.TryGetValue(refRecords[0].Process.Id, out worksteps) && (worksteps.Count == 1))
|
||||
if (refRecords.Count > 0 &&
|
||||
workstepsDictionary.TryGetValue(refRecords[0].Process.Id, out worksteps) &&
|
||||
worksteps != null &&
|
||||
worksteps.Count == 1)
|
||||
{
|
||||
session.SaveOrUpdate(new ReferenceRecord(refRecords[0].Process, worksteps[0], wm.SerialNr, Users.CurrentUser.UserName(), workplace, wm.Passed ? 0 : 1));
|
||||
return 1;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2018-2019 Sensus Slovensko a.s.
|
||||
/// Copyright (c) 2018-2023 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
@ -48,7 +48,6 @@ namespace TBF.Rig.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;
|
||||
|
||||
@ -104,7 +103,6 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
{
|
||||
nameTextBox.Enabled = true;
|
||||
connStrTextBox.Enabled = true;
|
||||
connStr2TextBox.Enabled = true;
|
||||
netAdapterComboBox.Enabled = true;
|
||||
checkPreviousRecordsCheckBox.Enabled = true;
|
||||
saveTracingRecordsCheckBox.Enabled = true;
|
||||
@ -128,7 +126,6 @@ namespace TBF.Rig.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,8 +40,6 @@ namespace TBF.Rig.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
|
||||
@ -73,7 +71,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
// connStrTextBox
|
||||
//
|
||||
this.connStrTextBox.Enabled = false;
|
||||
this.connStrTextBox.Location = new System.Drawing.Point(8, 74);
|
||||
this.connStrTextBox.Location = new System.Drawing.Point(8, 79);
|
||||
this.connStrTextBox.Name = "connStrTextBox";
|
||||
this.connStrTextBox.Size = new System.Drawing.Size(435, 20);
|
||||
this.connStrTextBox.TabIndex = 4;
|
||||
@ -81,7 +79,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
// connStrLabel
|
||||
//
|
||||
this.connStrLabel.AutoSize = true;
|
||||
this.connStrLabel.Location = new System.Drawing.Point(5, 58);
|
||||
this.connStrLabel.Location = new System.Drawing.Point(5, 63);
|
||||
this.connStrLabel.Name = "connStrLabel";
|
||||
this.connStrLabel.Size = new System.Drawing.Size(92, 13);
|
||||
this.connStrLabel.TabIndex = 3;
|
||||
@ -91,7 +89,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
//
|
||||
this.saveTracingRecordsCheckBox.AutoSize = true;
|
||||
this.saveTracingRecordsCheckBox.Enabled = false;
|
||||
this.saveTracingRecordsCheckBox.Location = new System.Drawing.Point(117, 221);
|
||||
this.saveTracingRecordsCheckBox.Location = new System.Drawing.Point(117, 181);
|
||||
this.saveTracingRecordsCheckBox.Name = "saveTracingRecordsCheckBox";
|
||||
this.saveTracingRecordsCheckBox.Size = new System.Drawing.Size(177, 17);
|
||||
this.saveTracingRecordsCheckBox.TabIndex = 10;
|
||||
@ -102,7 +100,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
//
|
||||
this.checkPreviousRecordsCheckBox.AutoSize = true;
|
||||
this.checkPreviousRecordsCheckBox.Enabled = false;
|
||||
this.checkPreviousRecordsCheckBox.Location = new System.Drawing.Point(117, 199);
|
||||
this.checkPreviousRecordsCheckBox.Location = new System.Drawing.Point(117, 159);
|
||||
this.checkPreviousRecordsCheckBox.Name = "checkPreviousRecordsCheckBox";
|
||||
this.checkPreviousRecordsCheckBox.Size = new System.Drawing.Size(138, 17);
|
||||
this.checkPreviousRecordsCheckBox.TabIndex = 9;
|
||||
@ -112,7 +110,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
// netAdapterLabel
|
||||
//
|
||||
this.netAdapterLabel.AutoSize = true;
|
||||
this.netAdapterLabel.Location = new System.Drawing.Point(5, 147);
|
||||
this.netAdapterLabel.Location = new System.Drawing.Point(5, 107);
|
||||
this.netAdapterLabel.Name = "netAdapterLabel";
|
||||
this.netAdapterLabel.Size = new System.Drawing.Size(89, 13);
|
||||
this.netAdapterLabel.TabIndex = 7;
|
||||
@ -122,34 +120,15 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
//
|
||||
this.netAdapterComboBox.Enabled = false;
|
||||
this.netAdapterComboBox.FormattingEnabled = true;
|
||||
this.netAdapterComboBox.Location = new System.Drawing.Point(8, 163);
|
||||
this.netAdapterComboBox.Location = new System.Drawing.Point(8, 123);
|
||||
this.netAdapterComboBox.Name = "netAdapterComboBox";
|
||||
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);
|
||||
@ -178,7 +157,5 @@ namespace TBF.Rig.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