(1) MonitoringCfg.NetAdapter parameter added, (2) It's IP address used in RegisterWorkplace(), (3) AdapterInfo class moved one level up.

This commit is contained in:
Milan Hanajik
2019-07-23 11:21:44 +02:00
parent 1d31e5c4b7
commit b83ffb9e9b
7 changed files with 138 additions and 23 deletions
@@ -5,7 +5,7 @@ using System.Net.NetworkInformation;
using System.Text; using System.Text;
using System.Web; using System.Web;
namespace TBF.BenchControl.Network.Adapter namespace TBF.BenchControl.Network
{ {
/// <summary> /// <summary>
/// Class for the storing information about a network adapter. /// Class for the storing information about a network adapter.
@@ -22,13 +22,22 @@ namespace TBF.BenchControl.Network.Adapter
Description = description; Description = description;
} }
/// Member function
public IPAddress GetBroadcastAddress() public IPAddress GetBroadcastAddress()
{ {
byte[] ipAdressBytes = IPAddress.GetAddressBytes(); return AdapterInfo.GetBroadcastAddress(IPAddress, NetMask);
byte[] subnetMaskBytes = NetMask.GetAddressBytes(); }
/// Static function
static public IPAddress GetBroadcastAddress(IPAddress ipAddress, IPAddress netMask)
{
byte[] ipAdressBytes = ipAddress.GetAddressBytes();
byte[] subnetMaskBytes = netMask.GetAddressBytes();
if (ipAdressBytes.Length != subnetMaskBytes.Length) if (ipAdressBytes.Length != subnetMaskBytes.Length)
{
throw new ArgumentException("Lengths of IP address and subnet mask do not match."); throw new ArgumentException("Lengths of IP address and subnet mask do not match.");
}
byte[] broadcastAddress = new byte[ipAdressBytes.Length]; byte[] broadcastAddress = new byte[ipAdressBytes.Length];
for (int i = 0; i < broadcastAddress.Length; i++) for (int i = 0; i < broadcastAddress.Length; i++)
@@ -19,6 +19,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
public string Workplace; public string Workplace;
public string ConnStr; public string ConnStr;
public string NetAdapter;
public bool CheckPreviousRecords; public bool CheckPreviousRecords;
public bool SaveTracingRecords; public bool SaveTracingRecords;
@@ -28,6 +29,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
{ {
ParentName = string.Empty; ParentName = string.Empty;
Workplace = "WR10"; Workplace = "WR10";
NetAdapter = string.Empty;
ConnStr = "SERVER=10.42.128.16; DATABASE=sledovanie2019; UID=vyroba2019; PASSWORD=qwerty; CHARSET=utf8;"; ConnStr = "SERVER=10.42.128.16; DATABASE=sledovanie2019; UID=vyroba2019; PASSWORD=qwerty; CHARSET=utf8;";
CheckPreviousRecords = true; CheckPreviousRecords = true;
SaveTracingRecords = true; SaveTracingRecords = true;
@@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net;
using log4net; using log4net;
using NHibernate; using NHibernate;
using NHibernate.Criterion; using NHibernate.Criterion;
@@ -36,6 +37,12 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
MonitoringCfg tracingCfg; MonitoringCfg tracingCfg;
string workplace { get { return tracingCfg.Workplace; } } string workplace { get { return tracingCfg.Workplace; } }
readonly IPAddress ipAddress;
readonly IPAddress netMask;
public IPAddress IPAddress { get { return ipAddress; } }
public IPAddress NetMask { get { return netMask; } }
enum OpState enum OpState
{ {
@@ -84,6 +91,12 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
{ {
tracingCfg = cfg as MonitoringCfg; tracingCfg = cfg as MonitoringCfg;
if (tracingCfg == null) throw new ArgumentException("tracingCfg"); if (tracingCfg == null) throw new ArgumentException("tracingCfg");
Network.AdapterInfo.RefreshNetAdaptersInfo();
Network.AdapterInfo netadapter = Network.AdapterInfo.GetNetAdapter(tracingCfg.NetAdapter);
ipAddress = netadapter.IPAddress;
netMask = netadapter.NetMask;
currentOpState = OpState.None; currentOpState = OpState.None;
log.Debug(this.ToString()); log.Debug(this.ToString());
} }
@@ -95,6 +108,8 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
{ {
if (tracingCfg.DebugLevel == DebugMode.Simulate) return; if (tracingCfg.DebugLevel == DebugMode.Simulate) return;
string ipAddress = GetIPAddress();
/// ///
/// Session factory is used to create database sessions /// Session factory is used to create database sessions
/// ///
@@ -111,7 +126,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
TracingDB.DB.RegisterWorkplace(session, TracingDB.DB.RegisterWorkplace(session,
workplace, workplace,
Users.GlobalData.GetCurrentUserName(), Users.GlobalData.GetCurrentUserName(),
"1.2.3.4", GetIPAddress(),
"<multiple>", "<multiple>",
WorkstepName, WorkstepName,
DateTime.Now + new TimeSpan(15, 0, 0, 0)); DateTime.Now + new TimeSpan(15, 0, 0, 0));
@@ -123,6 +138,11 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
currentProcess = null; currentProcess = null;
} }
/// ///
string GetIPAddress()
{
return (ipAddress != null) ? ipAddress.ToString() : "1.2.3.4";
}
///
public void RunDeviceBefore() { } public void RunDeviceBefore() { }
public void RunDeviceAfter() { } public void RunDeviceAfter() { }
/// ///
@@ -5,6 +5,8 @@ using System;
using System.Windows.Forms; using System.Windows.Forms;
using Config.Entities; using Config.Entities;
using TBF.BenchControl.Generic; using TBF.BenchControl.Generic;
using System.Collections.Generic;
using System.Net;
namespace TBF.BenchControl.Output.DB.ProductionTracing namespace TBF.BenchControl.Output.DB.ProductionTracing
{ {
@@ -30,6 +32,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
private void WriterCfgCtrl_Load(object sender, EventArgs e) private void WriterCfgCtrl_Load(object sender, EventArgs e)
{ {
if (config == null) return;
Redraw(); Redraw();
} }
@@ -47,6 +50,53 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
connStrTextBox.Text = config.ConnStr; connStrTextBox.Text = config.ConnStr;
checkPreviousRecordsCheckBox.Checked = config.CheckPreviousRecords; checkPreviousRecordsCheckBox.Checked = config.CheckPreviousRecords;
saveTracingRecordsCheckBox.Checked = config.SaveTracingRecords; 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() public void Unlock()
@@ -54,6 +104,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
nameTextBox.Enabled = true; nameTextBox.Enabled = true;
workplaceTextBox.Enabled = true; workplaceTextBox.Enabled = true;
connStrTextBox.Enabled = true; connStrTextBox.Enabled = true;
netAdapterComboBox.Enabled = true;
checkPreviousRecordsCheckBox.Enabled = true; checkPreviousRecordsCheckBox.Enabled = true;
saveTracingRecordsCheckBox.Enabled = true; saveTracingRecordsCheckBox.Enabled = true;
} }
@@ -80,6 +131,16 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
flags |= UpdateDifferent(ref config.CheckPreviousRecords, checkPreviousRecordsCheckBox.Checked, 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); 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; return flags;
} }
} }
@@ -40,6 +40,8 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
this.connStrLabel = new System.Windows.Forms.Label(); this.connStrLabel = new System.Windows.Forms.Label();
this.saveTracingRecordsCheckBox = new System.Windows.Forms.CheckBox(); this.saveTracingRecordsCheckBox = new System.Windows.Forms.CheckBox();
this.checkPreviousRecordsCheckBox = new System.Windows.Forms.CheckBox(); this.checkPreviousRecordsCheckBox = new System.Windows.Forms.CheckBox();
this.netAdapterLabel = new System.Windows.Forms.Label();
this.netAdapterComboBox = new System.Windows.Forms.ComboBox();
this.SuspendLayout(); this.SuspendLayout();
// //
// nameTextBox // nameTextBox
@@ -91,7 +93,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
this.connStrTextBox.Location = new System.Drawing.Point(110, 93); this.connStrTextBox.Location = new System.Drawing.Point(110, 93);
this.connStrTextBox.Name = "connStrTextBox"; this.connStrTextBox.Name = "connStrTextBox";
this.connStrTextBox.Size = new System.Drawing.Size(327, 20); this.connStrTextBox.Size = new System.Drawing.Size(327, 20);
this.connStrTextBox.TabIndex = 22; this.connStrTextBox.TabIndex = 6;
// //
// connStrLabel // connStrLabel
// //
@@ -99,17 +101,17 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
this.connStrLabel.Location = new System.Drawing.Point(15, 96); this.connStrLabel.Location = new System.Drawing.Point(15, 96);
this.connStrLabel.Name = "connStrLabel"; this.connStrLabel.Name = "connStrLabel";
this.connStrLabel.Size = new System.Drawing.Size(89, 13); this.connStrLabel.Size = new System.Drawing.Size(89, 13);
this.connStrLabel.TabIndex = 21; this.connStrLabel.TabIndex = 5;
this.connStrLabel.Text = "Connection string"; this.connStrLabel.Text = "Connection string";
// //
// saveTracingRecordsCheckBox // saveTracingRecordsCheckBox
// //
this.saveTracingRecordsCheckBox.AutoSize = true; this.saveTracingRecordsCheckBox.AutoSize = true;
this.saveTracingRecordsCheckBox.Enabled = false; this.saveTracingRecordsCheckBox.Enabled = false;
this.saveTracingRecordsCheckBox.Location = new System.Drawing.Point(110, 154); this.saveTracingRecordsCheckBox.Location = new System.Drawing.Point(110, 177);
this.saveTracingRecordsCheckBox.Name = "saveTracingRecordsCheckBox"; this.saveTracingRecordsCheckBox.Name = "saveTracingRecordsCheckBox";
this.saveTracingRecordsCheckBox.Size = new System.Drawing.Size(177, 17); this.saveTracingRecordsCheckBox.Size = new System.Drawing.Size(177, 17);
this.saveTracingRecordsCheckBox.TabIndex = 24; this.saveTracingRecordsCheckBox.TabIndex = 10;
this.saveTracingRecordsCheckBox.Text = "Save production tracing records"; this.saveTracingRecordsCheckBox.Text = "Save production tracing records";
this.saveTracingRecordsCheckBox.UseVisualStyleBackColor = true; this.saveTracingRecordsCheckBox.UseVisualStyleBackColor = true;
// //
@@ -117,17 +119,36 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
// //
this.checkPreviousRecordsCheckBox.AutoSize = true; this.checkPreviousRecordsCheckBox.AutoSize = true;
this.checkPreviousRecordsCheckBox.Enabled = false; this.checkPreviousRecordsCheckBox.Enabled = false;
this.checkPreviousRecordsCheckBox.Location = new System.Drawing.Point(110, 131); this.checkPreviousRecordsCheckBox.Location = new System.Drawing.Point(110, 154);
this.checkPreviousRecordsCheckBox.Name = "checkPreviousRecordsCheckBox"; this.checkPreviousRecordsCheckBox.Name = "checkPreviousRecordsCheckBox";
this.checkPreviousRecordsCheckBox.Size = new System.Drawing.Size(138, 17); this.checkPreviousRecordsCheckBox.Size = new System.Drawing.Size(138, 17);
this.checkPreviousRecordsCheckBox.TabIndex = 23; this.checkPreviousRecordsCheckBox.TabIndex = 9;
this.checkPreviousRecordsCheckBox.Text = "Check previous records"; this.checkPreviousRecordsCheckBox.Text = "Check previous records";
this.checkPreviousRecordsCheckBox.UseVisualStyleBackColor = true; this.checkPreviousRecordsCheckBox.UseVisualStyleBackColor = true;
// //
// netAdapterLabel
//
this.netAdapterLabel.AutoSize = true;
this.netAdapterLabel.Location = new System.Drawing.Point(15, 122);
this.netAdapterLabel.Name = "netAdapterLabel";
this.netAdapterLabel.Size = new System.Drawing.Size(86, 13);
this.netAdapterLabel.TabIndex = 7;
this.netAdapterLabel.Text = "Network adapter";
//
// netAdapterComboBox
//
this.netAdapterComboBox.FormattingEnabled = true;
this.netAdapterComboBox.Location = new System.Drawing.Point(110, 119);
this.netAdapterComboBox.Name = "netAdapterComboBox";
this.netAdapterComboBox.Size = new System.Drawing.Size(327, 21);
this.netAdapterComboBox.TabIndex = 11;
//
// TracingCfgCtrl // TracingCfgCtrl
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.netAdapterComboBox);
this.Controls.Add(this.netAdapterLabel);
this.Controls.Add(this.saveTracingRecordsCheckBox); this.Controls.Add(this.saveTracingRecordsCheckBox);
this.Controls.Add(this.checkPreviousRecordsCheckBox); this.Controls.Add(this.checkPreviousRecordsCheckBox);
this.Controls.Add(this.connStrTextBox); this.Controls.Add(this.connStrTextBox);
@@ -156,5 +177,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing
private System.Windows.Forms.Label connStrLabel; private System.Windows.Forms.Label connStrLabel;
private System.Windows.Forms.CheckBox saveTracingRecordsCheckBox; private System.Windows.Forms.CheckBox saveTracingRecordsCheckBox;
private System.Windows.Forms.CheckBox checkPreviousRecordsCheckBox; private System.Windows.Forms.CheckBox checkPreviousRecordsCheckBox;
private System.Windows.Forms.Label netAdapterLabel;
private System.Windows.Forms.ComboBox netAdapterComboBox;
} }
} }
+1 -1
View File
@@ -1,5 +1,5 @@
/// ///
/// Copyright (c) 2013-201 Sensus Slovensko a.s. /// Copyright (c) 2013-2019 Sensus Slovensko a.s.
/// ///
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
+1 -1
View File
@@ -755,7 +755,7 @@
<Compile Include="BenchControl\Modbus\UltrasoundLevelMeter\ReadLevelOp.cs" /> <Compile Include="BenchControl\Modbus\UltrasoundLevelMeter\ReadLevelOp.cs" />
<Compile Include="BenchControl\Modbus\UltrasoundLevelMeter\ReadStableLevelOp.cs" /> <Compile Include="BenchControl\Modbus\UltrasoundLevelMeter\ReadStableLevelOp.cs" />
<Compile Include="BenchControl\Modbus\UltrasoundLevelMeter\ReadTempOp.cs" /> <Compile Include="BenchControl\Modbus\UltrasoundLevelMeter\ReadTempOp.cs" />
<Compile Include="BenchControl\Network\Adapter\AdapterInfo.cs" /> <Compile Include="BenchControl\Network\AdapterInfo.cs" />
<Compile Include="BenchControl\Network\Adapter\Netadapter.cs" /> <Compile Include="BenchControl\Network\Adapter\Netadapter.cs" />
<Compile Include="BenchControl\Network\Adapter\Factory.cs" /> <Compile Include="BenchControl\Network\Adapter\Factory.cs" />
<Compile Include="BenchControl\Network\Adapter\NetadapterCfg.cs" /> <Compile Include="BenchControl\Network\Adapter\NetadapterCfg.cs" />