diff --git a/TBF/BenchControl/Events.cs b/TBF/BenchControl/Events.cs index c7d13083b..316deba1b 100644 --- a/TBF/BenchControl/Events.cs +++ b/TBF/BenchControl/Events.cs @@ -175,7 +175,7 @@ namespace TBF.BenchControl OuterLoopStart, OuterLoopEnd, - /// Production monitoring + /// Production tracing CheckDone, CheckNotDone, diff --git a/TBF/BenchControl/Output/DB/ProductionTracing/Factory.cs b/TBF/BenchControl/Output/DB/ProductionTracing/Factory.cs index 1fbdef872..7369758d3 100644 --- a/TBF/BenchControl/Output/DB/ProductionTracing/Factory.cs +++ b/TBF/BenchControl/Output/DB/ProductionTracing/Factory.cs @@ -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 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); } } } diff --git a/TBF/BenchControl/Output/DB/ProductionTracing/TracingCfg.cs b/TBF/BenchControl/Output/DB/ProductionTracing/MonitoringCfg.cs similarity index 77% rename from TBF/BenchControl/Output/DB/ProductionTracing/TracingCfg.cs rename to TBF/BenchControl/Output/DB/ProductionTracing/MonitoringCfg.cs index 825e0b36d..09d12242d 100644 --- a/TBF/BenchControl/Output/DB/ProductionTracing/TracingCfg.cs +++ b/TBF/BenchControl/Output/DB/ProductionTracing/MonitoringCfg.cs @@ -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; diff --git a/TBF/BenchControl/Output/DB/ProductionTracing/Tracing.cs b/TBF/BenchControl/Output/DB/ProductionTracing/Tracing.cs index 829263354..013fcfc36 100644 --- a/TBF/BenchControl/Output/DB/ProductionTracing/Tracing.cs +++ b/TBF/BenchControl/Output/DB/ProductionTracing/Tracing.cs @@ -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()) - .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()) + .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", + "", + 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() {} /// @@ -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 /// Event.ResultsWritten or Event.Error 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); } } diff --git a/TBF/BenchControl/Output/DB/ProductionTracing/TracingCfgCtrl.cs b/TBF/BenchControl/Output/DB/ProductionTracing/TracingCfgCtrl.cs index c79621a29..38b573ac2 100644 --- a/TBF/BenchControl/Output/DB/ProductionTracing/TracingCfgCtrl.cs +++ b/TBF/BenchControl/Output/DB/ProductionTracing/TracingCfgCtrl.cs @@ -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(); } } diff --git a/TBF/BenchControl/Output/DB/ProductionTracing/TracingCfgCtrl.designer.cs b/TBF/BenchControl/Output/DB/ProductionTracing/TracingCfgCtrl.designer.cs index 9fe104030..e0901c6a2 100644 --- a/TBF/BenchControl/Output/DB/ProductionTracing/TracingCfgCtrl.designer.cs +++ b/TBF/BenchControl/Output/DB/ProductionTracing/TracingCfgCtrl.designer.cs @@ -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); diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj index 7cf171a7d..ea28a0212 100644 --- a/TBF/TBF.csproj +++ b/TBF/TBF.csproj @@ -743,7 +743,7 @@ - + UserControl diff --git a/Users/GlobalData.cs b/Users/GlobalData.cs index 5be249748..a6458f69b 100644 --- a/Users/GlobalData.cs +++ b/Users/GlobalData.cs @@ -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; + } } }