Refactorization : BenchControl -> Rig

This commit is contained in:
Milan Hanajik
2021-03-05 16:12:24 +01:00
parent 84c8ec26b6
commit 6cf3bd6160
1461 changed files with 6330 additions and 6330 deletions
@@ -0,0 +1,28 @@
///
/// Copyright (c) 2018 Sensus Slovensko a.s.
///
using System.Collections.Generic;
using TBF.Rig.Generic;
using TBF.Rig.Configs.NameOnly;
namespace TBF.Rig.Various.ManualLevelMsrmnt
{
public class Factory : IComponentFactory
{
public string ClassName { get { return this.GetType().Namespace.Substring(8); } }
public override string ToString() { return ClassName; }
public void ResetStaticProperties() { ManualLevelMsrmnt.ResetStaticProperties(); }
public IComponent DummyComponent() { return new ManualLevelMsrmnt(); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new ManualLevelMsrmnt(cfg); }
public IComponentCfg DefaultConfig() { return new TestMethodCfg(this.GetType().Namespace.Substring(16), this); }
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
{
return ComponentCfgBase.CreateFromDbEntity(TestMethodCfg.Serializer, component, this);
}
}
}
@@ -0,0 +1,128 @@
///
/// Copyright (c) 2018 Sensus Slovensko a.s.
///
using System;
using log4net;
using TBF.Rig.GenericDevices;
using TBF.Rig.Configs.NameOnly;
using TBF.Boxes;
namespace TBF.Rig.Various.ManualLevelMsrmnt
{
public class ManualLevelMsrmnt : ComponentBase, ILevelMeter, IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(ManualLevelMsrmnt));
public override string ToString() { return string.Format("ManualLevelMsrmnt({0})", Cfg.ToString(1)); }
readonly TestMethodCfg myCfg;
public double Level { get { return level_mm; } }
double level_mm;
DoubleBox levelBox;
WaterLevelForm waterLevelForm;
bool resultSaved; /// Set in Run() when results are saved
public enum CurrentOp
{
None,
EnterLevel,
}
CurrentOp currentOp;
public ManualLevelMsrmnt()
{
currentOp = CurrentOp.None;
}
public ManualLevelMsrmnt(Generic.IComponentCfg cfg)
: base(cfg)
{
myCfg = cfg as TestMethodCfg;
currentOp = CurrentOp.None;
log.Warn(this.ToString());
}
/// <returns>Reference to the operation</returns>
public IOperation ReadLevelOp(ref DoubleBox levelBox)
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
this.levelBox = levelBox;
currentOp = CurrentOp.EnterLevel;
return this;
}
/// <returns>Reference to the operation</returns>
public IOperation ReadStableLevelOp(ref DoubleBox levelBox, double sdev)
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
this.levelBox = levelBox;
currentOp = CurrentOp.EnterLevel;
return this;
}
/// <returns>Reference to the operation</returns>
public IOperation ManualReadLevelOp(ref DoubleBox levelBox)
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
this.levelBox = levelBox;
currentOp = CurrentOp.EnterLevel;
return this;
}
delegate void EntryFormDlgt(ManualLevelMsrmnt myRef);
///
void OpenWaterLevelForm(ManualLevelMsrmnt myRef)
{
myRef.waterLevelForm = new WaterLevelForm();
waterLevelForm.Show();
}
/// <summary>Start this operation</summary>
public void Start()
{
resultSaved = false;
if (currentOp == CurrentOp.EnterLevel)
{
Program.MainWnd.Invoke(new EntryFormDlgt(OpenWaterLevelForm), this);
}
}
/// <summary>Run this operation</summary>
/// <returns>Event.ResultsPrinted</returns>
public Event Run()
{
if ((waterLevelForm != null) && !waterLevelForm.Completed)
{
return Event.Busy; /// = Form open
}
if (!resultSaved && (currentOp == CurrentOp.EnterLevel) && (waterLevelForm != null))
{
/// Save the result (only once)
level_mm = waterLevelForm.Level_mm;
if (levelBox != null) levelBox.Val = level_mm;
resultSaved = true;
}
return Event.LevelDone; /// = Form closed
}
/// <summary>Stop this operation</summary>
public void Stop()
{
if (waterLevelForm != null)
{
waterLevelForm.OnCloseThisForm(this, null);
waterLevelForm = null;
}
currentOp = CurrentOp.None;
}
}
}
@@ -0,0 +1,111 @@
///
/// Copyright (c) 2018 Sensus Slovensko a.s.
///
using System;
using System.Windows.Forms;
using log4net;
using TBF.Resources;
namespace TBF.Rig.Various.ManualLevelMsrmnt
{
public partial class WaterLevelForm : Form
{
private static readonly ILog log = LogManager.GetLogger(typeof(WaterLevelForm));
// Set to 'true' when the form closes
public bool Completed { get { return completed; } }
bool completed;
/// <summary> Water level in mm entered by the user </summary>
public double Level_mm;
/// <summary>
/// Constructor to fill in start states
/// </summary>
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
public WaterLevelForm()
{
InitializeComponent();
ControlBox = false;
Level_mm = 0;
completed = false;
StartForceCloseHandler();
}
private void WaterLevelForm_Load(object sender, EventArgs e)
{
Localize();
}
void Localize()
{
Text = Strings.Water_level_in_mm;
waterLevelGroupBox.Text = Strings.Water_level_in_mm;
okButton.Text = Strings.OkBtnText;
}
private void waterLevelTextBox_TextChanged(object sender, EventArgs e)
{
double dummy;
okButton.Enabled = Utils.TryParseUDouble(waterLevelTextBox.Text, out dummy);
}
private void okButton_Click(object sender, EventArgs eArgs)
{
log.Debug("okButton_Click(..)");
try
{
Level_mm = Utils.ParseUDouble(waterLevelTextBox.Text);
}
catch (Exception e)
{
log.ErrorFormat("Exception: {0}", e.Message);
return;
}
completed = true;
Close();
}
#region Forced close handling
/// <summary>
/// Used by CoverTest, AskYesNoOp and MessageBoxOp.
/// </summary>
public void OnCloseThisForm(object sender, EventArgs args)
{
if (CloseThisFormHandler == null) return;
try
{
CloseThisFormHandler(sender, null);
}
catch (Exception e)
{
log.Error("CloseThisFormHandler(...) failed", e);
}
}
public event EventHandler<EventArgs> CloseThisFormHandler;
public void StartForceCloseHandler()
{
CloseThisFormHandler += delegate(object sender, EventArgs args)
{
if (InvokeRequired)
Invoke(new EventHandler<EventArgs>(OnForceClose), sender, args);
else
OnForceClose(sender, args);
};
}
private void OnForceClose(object sender, EventArgs args)
{
DialogResult = DialogResult.Cancel;
Close();
}
#endregion
}
}
@@ -0,0 +1,99 @@
///
/// Copyright (c) 2018 Sensus Slovensko a.s.
///
namespace TBF.Rig.Various.ManualLevelMsrmnt
{
partial class WaterLevelForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.waterLevelGroupBox = new System.Windows.Forms.GroupBox();
this.waterLevelTextBox = new System.Windows.Forms.TextBox();
this.okButton = new System.Windows.Forms.Button();
this.waterLevelGroupBox.SuspendLayout();
this.SuspendLayout();
//
// waterLevelGroupBox
//
this.waterLevelGroupBox.Controls.Add(this.waterLevelTextBox);
this.waterLevelGroupBox.Font = new System.Drawing.Font("Verdana", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.waterLevelGroupBox.ForeColor = System.Drawing.Color.Black;
this.waterLevelGroupBox.Location = new System.Drawing.Point(25, 16);
this.waterLevelGroupBox.Name = "waterLevelGroupBox";
this.waterLevelGroupBox.Size = new System.Drawing.Size(377, 81);
this.waterLevelGroupBox.TabIndex = 1;
this.waterLevelGroupBox.TabStop = false;
this.waterLevelGroupBox.Text = "Water level in mm";
//
// waterLevelTextBox
//
this.waterLevelTextBox.Location = new System.Drawing.Point(191, 31);
this.waterLevelTextBox.Name = "waterLevelTextBox";
this.waterLevelTextBox.Size = new System.Drawing.Size(163, 31);
this.waterLevelTextBox.TabIndex = 1;
this.waterLevelTextBox.TextChanged += new System.EventHandler(this.waterLevelTextBox_TextChanged);
//
// okButton
//
this.okButton.Font = new System.Drawing.Font("Verdana", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.okButton.ForeColor = System.Drawing.Color.Black;
this.okButton.Location = new System.Drawing.Point(437, 30);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(98, 63);
this.okButton.TabIndex = 7;
this.okButton.Text = "OK";
this.okButton.UseVisualStyleBackColor = true;
this.okButton.Click += new System.EventHandler(this.okButton_Click);
//
// WaterLevelForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.DarkGoldenrod;
this.ClientSize = new System.Drawing.Size(571, 123);
this.Controls.Add(this.okButton);
this.Controls.Add(this.waterLevelGroupBox);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "WaterLevelForm";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.Text = "Water level in mm";
this.TopMost = true;
this.Load += new System.EventHandler(this.WaterLevelForm_Load);
this.waterLevelGroupBox.ResumeLayout(false);
this.waterLevelGroupBox.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox waterLevelGroupBox;
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.TextBox waterLevelTextBox;
}
}
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>