tbf/TBF/Rig/TestMethods/GenesisCommunication/TestMethodCfgCtrl.cs

307 lines
16 KiB
C#

///
/// Copyright (c) 2015-2020 Sensus Slovensko a.s.
///
using System;
using System.Windows.Forms;
using Common;
using TBF.Resources;
using TBF.Rig.Generic;
namespace TBF.Rig.TestMethods.GenesisCommunication
{
public partial class TestMethodCfgCtrl : Configs.ConfigCtrlUtils, IComponentCfgCtrl
{
public bool ShowMore { get { return false; } }
TestMethodCfg config;
public IComponentCfg Config
{
get { return config as IComponentCfg; }
set
{
config = value as TestMethodCfg;
Redraw();
}
}
public TestMethodCfgCtrl()
{
InitializeComponent();
}
private void EntryFormCfgCtrl_Load(object sender, EventArgs e)
{
Redraw();
}
public void Closing()
{
}
void Redraw()
{
if (config == null) return; /// Control was not loaded, settings were not changed
classNameLabel.Text = config.Factory.ClassName;
nameTextBox.Text = config.Name;
commTimeoutTextBox.Text = config.CommTimeout.ToString();
maxCommRetriesTextBox.Text = config.MaxCommRetries.ToString();
delayBetweenRetriesTextBox.Text = config.DelayBetweenRetries.ToString();
nrThreadsTextBox.Text = config.NrThreads.ToString();
iperlCheckErrorsToStopTextBox.Text = config.IperlCheckErrorsToStop.ToString();
textBoxCh1_15inch.Text = config.CalibFactor1InchCh1.ToString();
textBoxCh2_15inch.Text = config.CalibFactor1InchCh2.ToString();
textBoxCh3_15inch.Text = config.CalibFactor1InchCh3.ToString();
textBoxCh1_2inch.Text = config.CalibFactor2InchCh1.ToString();
textBoxCh2_2inch.Text = config.CalibFactor2InchCh2.ToString();
textBoxCh3_2inch.Text = config.CalibFactor2InchCh3.ToString();
textBoxCh1_3inch.Text = config.CalibFactor3InchCh1.ToString();
textBoxCh2_3inch.Text = config.CalibFactor3InchCh2.ToString();
textBoxCh3_3inch.Text = config.CalibFactor3InchCh3.ToString();
textBoxCh1_4inch.Text = config.CalibFactor4InchCh1.ToString();
textBoxCh2_4inch.Text = config.CalibFactor4InchCh2.ToString();
textBoxCh3_4inch.Text = config.CalibFactor4InchCh3.ToString();
textBoxCh1_6inch.Text = config.CalibFactor6InchCh1.ToString();
textBoxCh2_6inch.Text = config.CalibFactor6InchCh2.ToString();
textBoxCh3_6inch.Text = config.CalibFactor6InchCh3.ToString();
textBoxCh1_6MoreInch.Text = config.CalibFactor6MoreInchCh1.ToString();
textBoxCh2_6MoreInch.Text = config.CalibFactor6MoreInchCh2.ToString();
textBoxCh3_6MoreInch.Text = config.CalibFactor6MoreInchCh3.ToString();
useWebServiceCheckBox.Checked = config.UseWebService;
baseUrlTextBox.Text = config.BaseUrl;
relativeUrlTextBox.Text = config.RelativeUrl;
}
public void Unlock()
{
nameTextBox.Enabled = true;
commTimeoutTextBox.Enabled = true;
maxCommRetriesTextBox.Enabled = true;
delayBetweenRetriesTextBox.Enabled = true;
nrThreadsTextBox.Enabled = true;
iperlCheckErrorsToStopTextBox.Enabled = true;
textBoxCh1_15inch.Enabled = true;
textBoxCh2_15inch.Enabled = true;
textBoxCh3_15inch.Enabled = true;
textBoxCh1_2inch.Enabled = true;
textBoxCh2_2inch.Enabled = true;
textBoxCh3_2inch.Enabled = true;
textBoxCh1_3inch.Enabled = true;
textBoxCh2_3inch.Enabled = true;
textBoxCh3_3inch.Enabled = true;
textBoxCh1_4inch.Enabled = true;
textBoxCh2_4inch.Enabled = true;
textBoxCh3_4inch.Enabled = true;
textBoxCh1_6inch.Enabled = true;
textBoxCh2_6inch.Enabled = true;
textBoxCh3_6inch.Enabled = true;
textBoxCh1_6MoreInch.Enabled = true;
textBoxCh2_6MoreInch.Enabled = true;
textBoxCh3_6MoreInch.Enabled = true;
useWebServiceCheckBox.Enabled = true;
ManageCheckGroupBox(useWebServiceCheckBox, useWebServiceGroupBox);
baseUrlTextBox.Enabled = useWebServiceCheckBox.Enabled;
relativeUrlTextBox.Enabled = useWebServiceCheckBox.Enabled;
}
public CfgUpdateFlags VerifyCfg(ref string message)
{
CfgUpdateFlags flags = CfgUpdateFlags.None;
int dummy;
if (!int.TryParse(commTimeoutTextBox.Text, out dummy) || dummy < 500 || dummy > 5000)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Comm. timeout' should be in range 500 .. 5000";
}
if (!int.TryParse(maxCommRetriesTextBox.Text, out dummy) || dummy < 1 || dummy > 10)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Max. retries' should be in range 1 .. 10";
}
if (!int.TryParse(delayBetweenRetriesTextBox.Text, out dummy) || dummy < 0 || dummy > 5000)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Comm. timeout' should be in range 0 .. 5000";
}
if (!int.TryParse(nrThreadsTextBox.Text, out dummy) || (dummy != 1 && dummy != 2 && dummy != 4 && dummy != 8 && dummy != 10))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Nr. threads' should be 1, 2, 4, 8, 10";
}
if (!int.TryParse(iperlCheckErrorsToStopTextBox.Text, out dummy) || ((dummy < 1) && (dummy > 40)))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + string.Format(Strings.Invalid_0, iperlCheckErrorsToStopLabel.Text);
}
flags = CfgUpdateFlagsQ3(textBoxCh1_15inch.Text,"1.5 inch", ref message, flags, 1);
flags = CfgUpdateFlagsQ3(textBoxCh2_15inch.Text,"1.5 inch", ref message, flags, 2);
flags = CfgUpdateFlagsQ3(textBoxCh3_15inch.Text,"1.5 inch", ref message, flags, 3);
flags = CfgUpdateFlagsQ3(textBoxCh1_2inch.Text,"2 inch", ref message, flags, 1);
flags = CfgUpdateFlagsQ3(textBoxCh2_2inch.Text,"2 inch", ref message, flags, 2);
flags = CfgUpdateFlagsQ3(textBoxCh3_2inch.Text,"2 inch", ref message, flags, 3);
flags = CfgUpdateFlagsQ3(textBoxCh1_3inch.Text,"3 inch", ref message, flags, 1);
flags = CfgUpdateFlagsQ3(textBoxCh2_3inch.Text,"3 inch", ref message, flags, 2);
flags = CfgUpdateFlagsQ3(textBoxCh3_3inch.Text,"3 inch", ref message, flags, 3);
flags = CfgUpdateFlagsQ3(textBoxCh1_4inch.Text,"4 inch", ref message, flags, 1);
flags = CfgUpdateFlagsQ3(textBoxCh2_4inch.Text,"4 inch", ref message, flags, 2);
flags = CfgUpdateFlagsQ3(textBoxCh3_4inch.Text,"4 inch", ref message, flags, 3);
flags = CfgUpdateFlagsQ3(textBoxCh1_6inch.Text,"6 inch", ref message, flags, 1);
flags = CfgUpdateFlagsQ3(textBoxCh2_6inch.Text,"6 inch", ref message, flags, 2);
flags = CfgUpdateFlagsQ3(textBoxCh3_6inch.Text,"6 inch", ref message, flags, 3);
flags = CfgUpdateFlagsQ3(textBoxCh1_6MoreInch.Text,">6 inch", ref message, flags, 1);
flags = CfgUpdateFlagsQ3(textBoxCh1_6MoreInch.Text,">6 inch", ref message, flags, 2);
flags = CfgUpdateFlagsQ3(textBoxCh1_6MoreInch.Text,">6 inch", ref message, flags, 3);
return flags;
}
private CfgUpdateFlags CfgUpdateFlagsQ3(string ValueText, string DN, ref string message, CfgUpdateFlags flags, int ch, int minRange = 0, int maxRange = 25000)
{
int dummy;
if (!int.TryParse(ValueText, out dummy) || dummy < minRange || dummy > maxRange)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + $"Default Q3 correction factor DN({DN}) CH{ch} should be in range {minRange} .. {maxRange}";
}
return flags;
}
public CfgUpdateFlags UpdateCfg()
{
CfgUpdateFlags flags = CfgUpdateFlags.None;
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
if (config.Name != nameTextBox.Text)
{
config.Name = nameTextBox.Text;
flags |= (CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd);
}
var CommTimeout = config.CommTimeout;;
var MaxCommRetries = config.MaxCommRetries;
var DelayBetweenRetries = config.DelayBetweenRetries;
var NrThreads = config.NrThreads;
var IperlCheckErrorsToStop = config.IperlCheckErrorsToStop;
var calFactor1Ch1 = config.CalibFactor1InchCh1;
var calFactor1Ch2 = config.CalibFactor1InchCh2;
var calFactor1Ch3 = config.CalibFactor1InchCh3;
var calFactor2Ch1 = config.CalibFactor2InchCh1;
var calFactor2Ch2 = config.CalibFactor2InchCh2;
var calFactor2Ch3 = config.CalibFactor2InchCh3;
var calFactor3Ch1 = config.CalibFactor3InchCh1;
var calFactor3Ch2 = config.CalibFactor3InchCh2;
var calFactor3Ch3 = config.CalibFactor3InchCh3;
var calFactor4Ch1 = config.CalibFactor4InchCh1;
var calFactor4Ch2 = config.CalibFactor4InchCh2;
var calFactor4Ch3 = config.CalibFactor4InchCh3;
var calFactor6Ch1 = config.CalibFactor6InchCh1;
var calFactor6Ch2 = config.CalibFactor6InchCh2;
var calFactor6Ch3 = config.CalibFactor6InchCh3;
var calFactor6MCh1 = config.CalibFactor6MoreInchCh1;
var calFactor6MCh2 = config.CalibFactor6MoreInchCh2;
var calFactor6MCh3 = config.CalibFactor6MoreInchCh3;
var UseWebService = config.UseWebService;
var BaseUrl = config.BaseUrl;
var RelativeUrl = config.RelativeUrl;
flags |= UpdateDifferent(ref CommTimeout, commTimeoutTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref MaxCommRetries, maxCommRetriesTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref DelayBetweenRetries, delayBetweenRetriesTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref NrThreads, nrThreadsTextBox.Text, CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref IperlCheckErrorsToStop, iperlCheckErrorsToStopTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor1Ch1, textBoxCh1_15inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor1Ch2, textBoxCh2_15inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor1Ch3, textBoxCh3_15inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor2Ch1, textBoxCh1_2inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor2Ch2, textBoxCh2_2inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor2Ch3, textBoxCh3_2inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor3Ch1, textBoxCh1_3inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor3Ch2, textBoxCh2_3inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor3Ch3, textBoxCh3_3inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor4Ch1, textBoxCh1_4inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor4Ch2, textBoxCh2_4inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor4Ch3, textBoxCh3_4inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor6Ch1, textBoxCh1_6inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor6Ch2, textBoxCh2_6inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor6Ch3, textBoxCh3_6inch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor6MCh1, textBoxCh1_6MoreInch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor6MCh2, textBoxCh2_6MoreInch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref calFactor6MCh3, textBoxCh3_6MoreInch.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref UseWebService, useWebServiceCheckBox.Checked, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref BaseUrl, baseUrlTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
flags |= UpdateDifferent(ref RelativeUrl, relativeUrlTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
config.CommTimeout = CommTimeout;
config.MaxCommRetries = MaxCommRetries;
config.DelayBetweenRetries = DelayBetweenRetries;
config.NrThreads = NrThreads;
config.IperlCheckErrorsToStop = IperlCheckErrorsToStop;
config.CalibFactor1InchCh1 = calFactor1Ch1;
config.CalibFactor1InchCh2 = calFactor1Ch2;
config.CalibFactor1InchCh3 = calFactor1Ch3;
config.CalibFactor2InchCh1 = calFactor2Ch1;
config.CalibFactor2InchCh2 = calFactor2Ch2;
config.CalibFactor2InchCh3 = calFactor2Ch3;
config.CalibFactor3InchCh1 = calFactor3Ch1;
config.CalibFactor3InchCh2 = calFactor3Ch2;
config.CalibFactor3InchCh3 = calFactor3Ch3;
config.CalibFactor4InchCh1 = calFactor4Ch1;
config.CalibFactor4InchCh2 = calFactor4Ch2;
config.CalibFactor4InchCh3 = calFactor4Ch3;
config.CalibFactor6InchCh1 = calFactor6Ch1;
config.CalibFactor6InchCh2 = calFactor6Ch2;
config.CalibFactor6InchCh3 = calFactor6Ch3;
config.CalibFactor6MoreInchCh1 = calFactor6MCh1;
config.CalibFactor6MoreInchCh2 = calFactor6MCh2;
config.CalibFactor6MoreInchCh3 = calFactor6MCh3;
config.UseWebService = UseWebService;
config.BaseUrl = BaseUrl;
config.RelativeUrl = RelativeUrl;
if ((flags & CfgUpdateFlags.InvokeCfgChange) != 0)
{
TestMethod.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config));
}
return flags;
}
private void ManageCheckGroupBox(CheckBox chk, GroupBox grp)
{
/// Make sure the CheckBox isn't in the GroupBox. This will only happen the first time.
if (chk.Parent == grp)
{
grp.Parent.Controls.Add(chk); /// Reparent the CheckBox so it's not in the GroupBox.
chk.Location = new System.Drawing.Point(chk.Left + grp.Left, chk.Top + grp.Top); /// Adjust the CheckBox's location.
chk.BringToFront(); /// Move the CheckBox to the top of the stacking order.
}
/// Enable or disable the GroupBox.
grp.Enabled = chk.Checked;
}
private void useWebServiceCheckBox_CheckedChanged(object sender, EventArgs e)
{
useWebServiceGroupBox.Enabled = useWebServiceCheckBox.Checked;
}
}
}