149 lines
5.0 KiB
C#
149 lines
5.0 KiB
C#
///
|
|
/// Copyright (c) 2018-2019 Sensus Slovensko a.s.
|
|
///
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net;
|
|
using Common;
|
|
using TBF.Rig.Generic;
|
|
|
|
|
|
namespace TBF.Rig.Output.DB.DatabaseWriter
|
|
{
|
|
public partial class WriteDbCfgCtrl : Configs.ConfigCtrlUtils, IComponentCfgCtrl
|
|
{
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
WriterCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as WriterCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public WriteDbCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void WriterCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
if (config == null) return;
|
|
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;
|
|
connStrTextBox.Text = config.ConnStr;
|
|
connStr2TextBox.Text = config.ConnStr2;
|
|
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;
|
|
connStr2TextBox.Enabled = true;
|
|
netAdapterComboBox.Enabled = true;
|
|
checkPreviousRecordsCheckBox.Enabled = true;
|
|
saveTracingRecordsCheckBox.Enabled = true;
|
|
}
|
|
|
|
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.ConnStr2, connStr2TextBox.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;
|
|
}
|
|
}
|
|
}
|