Output.DB.ProductionTracing.TracingDB : Workplace registration.

This commit is contained in:
Milan Hanajik 2018-08-28 10:48:39 +02:00
parent 6aee0a71ed
commit f675c7ada2
8 changed files with 71 additions and 38 deletions

View File

@ -175,7 +175,7 @@ namespace TBF.BenchControl
OuterLoopStart,
OuterLoopEnd,
/// Production monitoring
/// Production tracing
CheckDone,
CheckNotDone,

View File

@ -8,7 +8,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
{
public class Factory : IComponentFactory
{
public string ClassName { get { return this.GetType().Namespace.Substring(17); } }
public string ClassName { get { return "Output.DB.ProductionMonitoring"; } } /// For backward compatibility
public void ResetStaticProperties() { Tracing.ResetStaticProperties(); }
@ -16,11 +16,11 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new Tracing(cfg); }
public IComponentCfg DefaultConfig() { return new TracingCfg(this.GetType().Namespace.Substring(24), this); }
public IComponentCfg DefaultConfig() { return new MonitoringCfg(this.GetType().Namespace.Substring(24), this); }
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
{
return ComponentCfgBase.CreateFromDbEntity(TracingCfg.Serializer, component, this);
return ComponentCfgBase.CreateFromDbEntity(MonitoringCfg.Serializer, component, this);
}
}
}

View File

@ -6,9 +6,12 @@ using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Output.DB.ProductionTracing
{
public class TracingCfg : ComponentCfgBase, Generic.IComponentCfg
///
/// Class and file name is preserved for backward compatibility
///
public class MonitoringCfg : ComponentCfgBase, Generic.IComponentCfg
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(TracingCfg) })[0];
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(MonitoringCfg) })[0];
public override XmlSerializer GetSerializer() { return Serializer; }
public IComponentCfgCtrl GetControl() { return new TracingCfgCtrl(); }
@ -19,14 +22,14 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
/// Private parameterless constructor invoked by all other (public) constructors
TracingCfg()
MonitoringCfg()
{
ParentName = string.Empty;
Workplace = "WR10";
ConnStr = "SERVER=10.42.128.16; DATABASE=st_wr_shared_config; UID=u9305784; PASSWORD=p89344390; CHARSET=utf8;";
}
public TracingCfg(string name, IComponentFactory factory)
public MonitoringCfg(string name, IComponentFactory factory)
: this()
{
this.Name = name;

View File

@ -19,19 +19,19 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
public class Tracing : ComponentBase, IOperation, GenericDevices.IResultsWriter, Generic.IDevice
{
private static readonly ILog log = LogManager.GetLogger(typeof(Tracing));
public override string ToString() { return string.Format("Monitoring({0})", Cfg.ToString(1)); }
public override string ToString() { return string.Format("Tracing({0})", Cfg.ToString(1)); }
public const string WorkstepName = "Test_bench";
TracingCfg monitoringCfg;
string workplace { get { return monitoringCfg.Workplace; } }
MonitoringCfg tracingCfg;
string workplace { get { return tracingCfg.Workplace; } }
enum CurrentOp
{
None,
SaveMonitoringRecords,
SaveRecords,
}
CurrentOp currentOp;
@ -54,7 +54,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
public Tracing(Generic.IComponentCfg cfg)
: base(cfg)
{
monitoringCfg = cfg as TracingCfg;
tracingCfg = cfg as MonitoringCfg;
currentOp = CurrentOp.None;
log.Debug(this.ToString());
@ -62,30 +62,55 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
public void Initialize()
{
if (monitoringCfg.DebugLevel == DebugMode.Simulate) return;
if (tracingCfg.DebugLevel == DebugMode.Simulate) return;
///
/// Session factory is used to create database sessions
///
sessionFactory = FluentNHibernate.Cfg.Fluently
.Configure()
.Database(FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard.ConnectionString(monitoringCfg.ConnStr))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<TracingDB.Entities.Process>())
.ExposeConfiguration(TracingDB.DB.BuildSchema)
.BuildSessionFactory();
///
/// Read processes and worksteps from the database (this verifies DB connection as well)
///
log.WarnFormat("Reading processes/worksteps from production monitoring DB started");
ReadProcessesFromDB(sessionFactory.OpenSession());
log.WarnFormat("Reading processes/worksteps from production monitoring DB completed");
.Configure()
.Database(FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard.ConnectionString(tracingCfg.ConnStr))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<TracingDB.Entities.Process>())
.ExposeConfiguration(TracingDB.DB.BuildSchema)
.BuildSessionFactory();
using (ISession session = sessionFactory.OpenSession())
{
///
/// Read processes and worksteps from the database (this verifies DB connection as well)
///
log.WarnFormat("Reading processes/worksteps from production tracing DB started");
ReadProcessesFromDB(session);
log.WarnFormat("Reading processes/worksteps from production tracing DB completed");
///
/// Register the test bench workplace
///
TracingDB.DB.RegisterWorkplace(session,
workplace,
Users.GlobalData.GetCurrentUserName(),
"1.2.3.4",
"<multiple>",
WorkstepName,
DateTime.Now + new TimeSpan(8, 0, 0));
session.Flush();
}
}
public void StopDevice()
{
using (ISession session = sessionFactory.OpenSession())
{
TracingDB.DB.UnregisterWorkplace(session, workplace);
session.Flush();
}
}
public void RunDeviceBefore() { }
public void StopDevice2() {}
public void RunDeviceBefore() {}
public void RunDeviceAfter() {}
public void StopDevice() {}
public void StopDevice2() {}
/// <summary>
@ -99,7 +124,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
if (currentOp != CurrentOp.None)
throw new Exception("Sequence error");
else
currentOp = CurrentOp.SaveMonitoringRecords;
currentOp = CurrentOp.SaveRecords;
this.batch = batch;
@ -117,13 +142,13 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
/// <returns>Event.ResultsWritten or Event.Error</returns>
public Event Run()
{
if (monitoringCfg.DebugLevel == DebugMode.Simulate || batch.WaterMeters.Count == 0)
if (tracingCfg.DebugLevel == DebugMode.Simulate || batch.WaterMeters.Count == 0)
{
opCompleted = true;
return Event.ResultsWritten;
}
if (currentOp == CurrentOp.SaveMonitoringRecords)
if (currentOp == CurrentOp.SaveRecords)
{
if (!opCompleted)
{
@ -138,7 +163,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
session.Flush();
opCompleted = true;
log.ErrorFormat("Batch {0}: {1} of {2} watermeters written to production monitoring DB",
log.ErrorFormat("Batch {0}: {1} of {2} watermeters written to production tracing DB",
batch.BatchNr, wrCount, batch.WaterMeters.Count);
}
catch (Exception exc)
@ -146,7 +171,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
if (transaction != null && !transaction.WasCommitted) transaction.Rollback();
anyError = true;
log.WarnFormat("Failed to write batch {0} results to production monitoring DB: {1}",
log.WarnFormat("Failed to write results of batch {0} to production tracing DB: {1}",
batch.BatchNr, exc.Message);
}
}

View File

@ -12,13 +12,13 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
{
public bool ShowMore { get { return false; } }
TracingCfg config;
MonitoringCfg config;
public IComponentCfg Config
{
get { return config as IComponentCfg; }
set
{
config = value as TracingCfg;
config = value as MonitoringCfg;
Redraw();
}
}

View File

@ -100,7 +100,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
this.connStrLabel.TabIndex = 21;
this.connStrLabel.Text = "Connection string";
//
// MonitoringCfgCtrl
// TracingCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
@ -111,7 +111,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Name = "MonitoringCfgCtrl";
this.Name = "TracingCfgCtrl";
this.Size = new System.Drawing.Size(450, 230);
this.Load += new System.EventHandler(this.WriterCfgCtrl_Load);
this.ResumeLayout(false);

View File

@ -743,7 +743,7 @@
<Compile Include="BenchControl\Operations\ReturnGivenEventOp.cs" />
<Compile Include="BenchControl\Output\DB\ProductionTracing\Enums.cs" />
<Compile Include="BenchControl\Output\DB\ProductionTracing\Tracing.cs" />
<Compile Include="BenchControl\Output\DB\ProductionTracing\TracingCfg.cs" />
<Compile Include="BenchControl\Output\DB\ProductionTracing\MonitoringCfg.cs" />
<Compile Include="BenchControl\Output\DB\ProductionTracing\TracingCfgCtrl.cs">
<SubType>UserControl</SubType>
</Compile>

View File

@ -10,5 +10,10 @@ namespace Users
public static Entities.User CurrentUser;
public static Entities.AuthorizedAs AuthorizedAs;
public static DateTime LastAuthorization = DateTime.Now;
public static string GetCurrentUserName()
{
return (CurrentUser != null) ? CurrentUser.UserName : string.Empty;
}
}
}