228 lines
7.6 KiB
C#
228 lines
7.6 KiB
C#
///
|
|
/// Copyright (c) 2018-2023 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using Common;
|
|
using TBF.Resources;
|
|
using TBF.Rig.Generic;
|
|
using TBF.Rig.Elde.Diverter;
|
|
using TBF.Boxes;
|
|
|
|
namespace TBF.Rig.Output.DB.ProductionTracing
|
|
{
|
|
public partial class TracingCfgCtrl : Configs.ConfigCtrlUtils, IComponentCfgCtrl
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(TracingCfgCtrl));
|
|
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
MonitoringCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as MonitoringCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public TracingCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void WriterCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
if (config == null) return;
|
|
Localize();
|
|
Redraw();
|
|
StartResponseHandler();
|
|
}
|
|
|
|
public void Closing()
|
|
{
|
|
StopResponseHandler();
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
unlockBypassButton.Text = Strings.Unlock_bypass;
|
|
setCyclesToBypassButton.Text = Strings.Set_number_of_cycles_to_bypass;
|
|
getCyclesToBypassButton.Text = Strings.Get_number_of_cycles_to_bypass;
|
|
}
|
|
|
|
void Redraw()
|
|
{
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
|
|
classNameLabel.Text = config.Factory.ClassName;
|
|
nameTextBox.Text = config.Name;
|
|
connStrTextBox.Text = config.ConnStr;
|
|
checkPreviousRecordsCheckBox.Checked = config.CheckPreviousRecords;
|
|
saveTracingRecordsCheckBox.Checked = config.SaveTracingRecords;
|
|
|
|
Network.AdapterInfo.RefreshNetAdaptersInfo();
|
|
IList<Network.AdapterInfo> adapters = Network.AdapterInfo.NetAdapters;
|
|
|
|
string cfgAdapter = string.Empty;
|
|
foreach (Network.AdapterInfo ai in adapters)
|
|
{
|
|
string record;
|
|
|
|
if (ai.IPAddress == null)
|
|
{
|
|
/// This happens with network adapters that currently have no IP address,
|
|
/// for instance not connected wireless or dial-up adapters
|
|
record = "???.???.???.???";
|
|
}
|
|
else
|
|
{
|
|
/// Do not consider IPv6 adapters as well as "Any", "Broadcast", "Loopback" or "None" addresses
|
|
if ((ai.IPAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) ||
|
|
ai.IPAddress.Equals(IPAddress.Any) ||
|
|
ai.IPAddress.Equals(IPAddress.Broadcast) ||
|
|
ai.IPAddress.Equals(IPAddress.IPv6Any) ||
|
|
ai.IPAddress.Equals(IPAddress.IPv6Loopback) ||
|
|
ai.IPAddress.Equals(IPAddress.IPv6None) ||
|
|
ai.IPAddress.Equals(IPAddress.Loopback) ||
|
|
ai.IPAddress.Equals(IPAddress.None))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
record = ai.IPAddress.ToString();
|
|
}
|
|
|
|
record += " - " + ai.Description;
|
|
int i = netAdapterComboBox.Items.Add(record);
|
|
if (ai.Description == config.NetAdapter)
|
|
{
|
|
/// Select the adapter currently in the configuration
|
|
netAdapterComboBox.SelectedIndex = i;
|
|
}
|
|
}
|
|
|
|
/// Select the first one if the adapter from the configuration does not exist on the system
|
|
if (netAdapterComboBox.SelectedIndex < 0 && netAdapterComboBox.Items.Count > 0)
|
|
{
|
|
netAdapterComboBox.SelectedIndex = 0;
|
|
}
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
connStrTextBox.Enabled = true;
|
|
netAdapterComboBox.Enabled = true;
|
|
checkPreviousRecordsCheckBox.Enabled = true;
|
|
saveTracingRecordsCheckBox.Enabled = true;
|
|
|
|
cyclesToBypassTextBox.Enabled = true;
|
|
setCyclesToBypassButton.Enabled = true;
|
|
unlockBypassButton.Enabled = false;
|
|
}
|
|
|
|
private void unlockSkipCyclesButton_Click(object sender, EventArgs e)
|
|
{
|
|
var reqrdGrpMembership = new GID[] { GID.TraceabilityManagement, GID.HeadOfLab };
|
|
if (!Users.CurrentUser.IsMemberOf(reqrdGrpMembership))
|
|
{
|
|
if (new Users.Forms.LoginDlg(TBF.DB.UserSessionFactories, reqrdGrpMembership, ParentForm).ShowDialog() != DialogResult.OK)
|
|
return;
|
|
}
|
|
|
|
cyclesToBypassTextBox.Enabled = true;
|
|
setCyclesToBypassButton.Enabled = true;
|
|
unlockBypassButton.Enabled = false;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
return CfgUpdateFlags.None;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
flags |= UpdateDifferent(ref config.ConnStr, connStrTextBox.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);
|
|
|
|
/// Network adapter
|
|
string strAdapter = netAdapterComboBox.Text;
|
|
int iDash = strAdapter.IndexOf(" - ");
|
|
string netAdapter = (iDash < 0) ? "" : strAdapter.Substring(iDash + 3);
|
|
if (config.NetAdapter != netAdapter)
|
|
{
|
|
config.NetAdapter = netAdapter;
|
|
flags |= (CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd);
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
private void setCyclesToSkipButton_Click(object sender, EventArgs e)
|
|
{
|
|
int cyclesToSkip = 0;
|
|
if (!int.TryParse(cyclesToBypassTextBox.Text, out cyclesToSkip) || cyclesToSkip < 0 || cyclesToSkip > 20)
|
|
{
|
|
MessageBox.Show(string.Format(Strings.Invalid_0, "(0..20)"));
|
|
return;
|
|
}
|
|
|
|
Tracing.OnDataChange(this, new DataChangeArgs(CfgChangeCmd.SetData, new IntBox(cyclesToSkip)));
|
|
}
|
|
|
|
private void getCyclesToSkipButton_Click(object sender, EventArgs e)
|
|
{
|
|
Tracing.OnDataChange(this, new DataChangeArgs(CfgChangeCmd.GetData, null));
|
|
}
|
|
|
|
|
|
#region Data Change Handling
|
|
|
|
public static void OnCmdResponse(object sender, CmdResponseArgs args)
|
|
{
|
|
if (CmdResponseHandler == null) return;
|
|
try { CmdResponseHandler(sender, args); }
|
|
catch (Exception e) { log.Error("CmdResponseHandler(...) failed", e); }
|
|
}
|
|
|
|
public static event EventHandler<CmdResponseArgs> CmdResponseHandler;
|
|
|
|
public void StartResponseHandler()
|
|
{
|
|
CmdResponseHandler += DoCmdResponse;
|
|
}
|
|
|
|
public void StopResponseHandler()
|
|
{
|
|
CmdResponseHandler -= DoCmdResponse;
|
|
}
|
|
|
|
void DoCmdResponse(object sender, CmdResponseArgs args)
|
|
{
|
|
if (args.Command == CfgChangeCmd.GetData)
|
|
{
|
|
cyclesToBypassTextBox2.Text = args.Response.ToString();
|
|
}
|
|
}
|
|
|
|
#endregion Configuration Change Handling
|
|
}
|
|
}
|