Network.Comet.Ambient component added, ver. 2.18.821

This commit is contained in:
Milan Hanajik
2018-02-20 19:30:05 +01:00
parent 1155cae130
commit 95a3d7def6
12 changed files with 810 additions and 16 deletions
@@ -0,0 +1,144 @@
///
/// Copyright (c) 2018 Sensus Slovensko a.s.
///
using System;
using System.Net;
using System.Windows.Forms;
using log4net;
using TBF.BenchControl.Generic;
using TBF.Resources;
namespace TBF.BenchControl.Network.Comet.Ambient
{
public partial class AmbientCfgCtrl : UserControl, IComponentCfgCtrl
{
static readonly ILog log = LogManager.GetLogger(typeof(AmbientCfgCtrl));
ComponentParametersDlg parent;
public bool ShowMore { get { return false; } }
AmbientCfg config;
public IComponentCfg Config
{
get { return config as IComponentCfg; }
set
{
config = value as AmbientCfg;
Redraw();
}
}
public AmbientCfgCtrl()
{
InitializeComponent();
}
private void AbbientCfgCtrl_Load(object sender, EventArgs e)
{
Localize();
parent = ParentForm as ComponentParametersDlg;
if (parent == null) return;
if (parent.TbfComponents != null)
{
parentNameComboBox.Items.Add("---");
foreach (var cmpnt in parent.TbfComponents)
{
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is TBF.BenchControl.Network.Adapter.Factory)
{
parentNameComboBox.Items.Add(cmpnt.Name);
}
}
}
Redraw();
}
void Localize()
{
nameLabel.Text = Strings.Name;
parentNameLabel.Text = Strings.Parent_name;
serialNrLabel.Text = Strings.Serial_Number;
}
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;
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
ipAddressTextBox.Text = config.IPAddress != null ? config.IPAddress.ToString() : "192.168.0.123";
tcpPortTextBox.Text = config.TcpPort.ToString();
serialNrTextBox.Text = config.SerialNr.ToString();
}
public void Unlock()
{
nameTextBox.Enabled = true;
parentNameComboBox.Enabled = true;
ipAddressTextBox.Enabled = true;
tcpPortTextBox.Enabled = true;
serialNrTextBox.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
{
CfgUpdateFlags flags = CfgUpdateFlags.None;
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + string.Format(Strings.Invalid_0, parentNameLabel.Text);
}
IPAddress ip;
if (!IPAddress.TryParse(ipAddressTextBox.Text, out ip))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + string.Format(Strings.Invalid_0, ipAddressLabel.Text);
}
int port;
if (!int.TryParse(tcpPortTextBox.Text, out port) || port < 0 || port > 65535)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + string.Format(Strings.Invalid_0, tcpPortLabel.Text);
}
return flags;
}
public CfgUpdateFlags UpdateCfg()
{
CfgUpdateFlags flags = CfgUpdateFlags.None;
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
string newParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
if (config.Name != nameTextBox.Text ||
config.ParentName != newParentName ||
config.IPAddress != ipAddressTextBox.Text ||
config.TcpPort.ToString() != tcpPortTextBox.Text ||
config.SerialNr != serialNrTextBox.Text)
{
config.Name = nameTextBox.Text;
config.ParentName = newParentName;
config.IPAddress = ipAddressTextBox.Text;
config.TcpPort = int.Parse(tcpPortTextBox.Text);
config.SerialNr = serialNrTextBox.Text;
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
}
return flags;
}
}
}