/// Displays the dialog.
diff --git a/Samples/ClientControls.Net4/ExceptionDlg.cs b/Samples/ClientControls.Net4/ExceptionDlg.cs
index fb0e416da..281c4ef56 100644
--- a/Samples/ClientControls.Net4/ExceptionDlg.cs
+++ b/Samples/ClientControls.Net4/ExceptionDlg.cs
@@ -91,7 +91,7 @@ private void AddBlock(StringBuilder buffer, string text, int level)
}
buffer.Append("color:#FFFFFF;font-weight:bold;font-size:10pt;font-family:Verdana'>| ");
- buffer.Append(" ");
+ buffer.Append(" ");
}
else
{
@@ -183,7 +183,7 @@ public static void Show(string caption, Exception e)
Utils.Trace(e, "Unexpected error in '{0}'.", caption);
return;
}
-
+
new ExceptionDlg().ShowDialog(caption, e);
}
@@ -198,12 +198,12 @@ public void ShowDialog(string caption, Exception e)
}
m_exception = e;
-
- #if _DEBUG
+
+#if _DEBUG
ShowStackTracesCK.Checked = true;
- #else
+#else
ShowStackTracesCK.Checked = false;
- #endif
+#endif
Show(ShowStackTracesCK.Checked);
ShowDialog();
diff --git a/Samples/ClientControls.Net4/MessageDlg.cs b/Samples/ClientControls.Net4/MessageDlg.cs
index 1b967b7ea..7e8ef5738 100644
--- a/Samples/ClientControls.Net4/MessageDlg.cs
+++ b/Samples/ClientControls.Net4/MessageDlg.cs
@@ -1,8 +1,8 @@
-/* ========================================================================
+/* ========================================================================
* Copyright (c) 2005-2020 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -27,9 +27,10 @@
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/
+using System.Threading;
using System.Threading.Tasks;
-using Opc.Ua.Configuration;
using System.Windows.Forms;
+using Opc.Ua.Configuration;
namespace Opc.Ua.Client.Controls
{
@@ -52,10 +53,10 @@ public override void Message(string text, bool ask)
}
}
- public override async Task ShowAsync()
+ public override Task ShowAsync()
{
DialogResult result = MessageBox.Show(message, "OPC UA", buttons);
- return await Task.FromResult((result == DialogResult.OK) || (result == DialogResult.Yes));
+ return Task.FromResult((result == DialogResult.OK) || (result == DialogResult.Yes));
}
}
}
diff --git a/Samples/ClientControls.Net4/UA Client Controls.csproj b/Samples/ClientControls.Net4/UA Client Controls.csproj
index 1e64f12a6..e087ea8ed 100644
--- a/Samples/ClientControls.Net4/UA Client Controls.csproj
+++ b/Samples/ClientControls.Net4/UA Client Controls.csproj
@@ -48,6 +48,7 @@
false
+ AllRules.ruleset
pdbonly
@@ -60,6 +61,7 @@
false
+ AllRules.ruleset
@@ -1015,16 +1017,16 @@
- 1.5.376.244
+ 1.5.377.11-preview
- 1.5.376.244
+ 1.5.377.11-preview
- 1.5.376.244
+ 1.5.377.11-preview
- 1.5.376.244
+ 1.5.377.11-preview
diff --git a/Samples/Controls.Net4/ClientForm.Designer.cs b/Samples/Controls.Net4/ClientForm.Designer.cs
index 3fa5207bd..8fead5147 100644
--- a/Samples/Controls.Net4/ClientForm.Designer.cs
+++ b/Samples/Controls.Net4/ClientForm.Designer.cs
@@ -175,7 +175,7 @@ private void InitializeComponent()
this.PerformanceTestMI.Name = "PerformanceTestMI";
this.PerformanceTestMI.Size = new System.Drawing.Size(154, 22);
this.PerformanceTestMI.Text = "Stack Test...";
- this.PerformanceTestMI.Click += new System.EventHandler(this.PerformanceTestMI_Click);
+ this.PerformanceTestMI.Click += new System.EventHandler(this.PerformanceTestMI_ClickAsync);
//
// toolStripSeparator1
//
@@ -333,7 +333,7 @@ private void InitializeComponent()
this.EndpointSelectorCTRL.SelectedEndpoint = null;
this.EndpointSelectorCTRL.Size = new System.Drawing.Size(553, 27);
this.EndpointSelectorCTRL.TabIndex = 2;
- this.EndpointSelectorCTRL.ConnectEndpoint += new Opc.Ua.Client.Controls.ConnectEndpointEventHandler(this.EndpointSelectorCTRL_ConnectEndpoint);
+ this.EndpointSelectorCTRL.ConnectEndpoint += new Opc.Ua.Client.Controls.ConnectEndpointEventHandler(this.EndpointSelectorCTRL_ConnectEndpointAsync);
this.EndpointSelectorCTRL.EndpointsChanged += new System.EventHandler(this.EndpointSelectorCTRL_OnChange);
//
// serverHeaderBranding1
@@ -369,7 +369,7 @@ private void InitializeComponent()
this.MainMenuStrip = this.MainMenu;
this.Name = "ClientForm";
this.Text = "UA Sample Client";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
+ this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosingAsync);
this.MainMenu.ResumeLayout(false);
this.MainMenu.PerformLayout();
this.StatusStrip.ResumeLayout(false);
diff --git a/Samples/Controls.Net4/ClientForm.cs b/Samples/Controls.Net4/ClientForm.cs
index e13b334e1..4e652cb24 100644
--- a/Samples/Controls.Net4/ClientForm.cs
+++ b/Samples/Controls.Net4/ClientForm.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -33,10 +33,13 @@
using System.Drawing;
using System.IO;
using System.Reflection;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
using Opc.Ua.Configuration;
+using static System.Net.Mime.MediaTypeNames;
namespace Opc.Ua.Sample.Controls
{
@@ -89,7 +92,7 @@ public ClientForm(
EndpointSelectorCTRL.Initialize(m_endpoints, m_configuration);
// initialize control state.
- Disconnect();
+ DisconnectAsync().GetAwaiter().GetResult();
}
///
@@ -130,7 +133,7 @@ void Window_FormClosing(object sender, FormClosingEventArgs e)
///
/// Disconnect from the server if ths form is closing.
///
- protected override void OnClosing(CancelEventArgs e)
+ protected override async void OnClosing(CancelEventArgs e)
{
if (m_masterForm == null && m_forms.Count > 0)
{
@@ -147,14 +150,20 @@ protected override void OnClosing(CancelEventArgs e)
form.Close();
}
}
-
- Disconnect();
+ try
+ {
+ await DisconnectAsync();
+ }
+ catch (Exception exception)
+ {
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ }
}
///
/// Disconnects from a server.
///
- public void Disconnect()
+ public async Task DisconnectAsync(CancellationToken ct = default)
{
if (m_session != null)
{
@@ -167,7 +176,7 @@ public void Disconnect()
m_session.KeepAlive -= StandardClient_KeepAlive;
- m_session.Close();
+ await m_session.CloseAsync(ct);
m_session = null;
}
@@ -182,11 +191,11 @@ protected virtual void DoTest(Session session)
MessageBox.Show("A handy place to put test code.");
}
- void EndpointSelectorCTRL_ConnectEndpoint(object sender, ConnectEndpointEventArgs e)
+ private async void EndpointSelectorCTRL_ConnectEndpointAsync(object sender, ConnectEndpointEventArgs e)
{
try
{
- Connect(e.Endpoint);
+ await ConnectAsync(e.Endpoint);
}
catch (Exception exception)
{
@@ -201,7 +210,7 @@ private void EndpointSelectorCTRL_OnChange(object sender, EventArgs e)
{
m_endpoints.Save();
}
- catch (Exception)
+ catch
{
// GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
@@ -210,14 +219,14 @@ private void EndpointSelectorCTRL_OnChange(object sender, EventArgs e)
///
/// Connects to a server.
///
- public async void Connect(ConfiguredEndpoint endpoint)
+ public async Task ConnectAsync(ConfiguredEndpoint endpoint, CancellationToken ct = default)
{
if (endpoint == null)
{
return;
}
- Session session = await SessionsCTRL.Connect(endpoint);
+ Session session = await SessionsCTRL.ConnectAsync(endpoint, ct);
if (session != null)
{
@@ -230,7 +239,7 @@ public async void Connect(ConfiguredEndpoint endpoint)
m_session = session;
m_session.KeepAlive += new KeepAliveEventHandler(StandardClient_KeepAlive);
- BrowseCTRL.SetView(m_session, BrowseViewType.Objects, null);
+ await BrowseCTRL.SetViewAsync(m_session, BrowseViewType.Objects, null, ct);
StandardClient_KeepAlive(m_session, null);
}
}
@@ -327,7 +336,7 @@ private void StandardClient_Server_ReconnectComplete(object sender, EventArgs e)
}
}
- BrowseCTRL.SetView(m_session, BrowseViewType.Objects, null);
+ BrowseCTRL.SetViewAsync(m_session, BrowseViewType.Objects, null);
SessionsCTRL.Reload(m_session);
@@ -339,11 +348,11 @@ private void StandardClient_Server_ReconnectComplete(object sender, EventArgs e)
}
}
- private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
+ private async void MainForm_FormClosingAsync(object sender, FormClosingEventArgs e)
{
try
{
- SessionsCTRL.Close();
+ await SessionsCTRL.CloseAsync();
if (m_masterForm == null)
{
@@ -361,14 +370,14 @@ private void FileExit_Click(object sender, EventArgs e)
this.Close();
}
- private async void PerformanceTestMI_Click(object sender, EventArgs e)
+ private async void PerformanceTestMI_ClickAsync(object sender, EventArgs e)
{
try
{
- new PerformanceTestDlg().ShowDialog(
+ _ = new PerformanceTestDlg().ShowDialog(
m_configuration,
m_endpoints,
- await m_configuration.SecurityConfiguration.ApplicationCertificate.Find(true));
+ await m_configuration.SecurityConfiguration.ApplicationCertificate.FindAsync(true));
}
catch (Exception exception)
{
@@ -480,7 +489,7 @@ private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
- System.Diagnostics.Process.Start(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "WebHelp" + Path.DirectorySeparatorChar + "index.htm");
+ System.Diagnostics.Process.Start(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + Path.DirectorySeparatorChar + "WebHelp" + Path.DirectorySeparatorChar + "index.htm");
}
catch (Exception ex)
{
diff --git a/Samples/Controls.Net4/Common/ArgumentListCtrl.Designer.cs b/Samples/Controls.Net4/Common/ArgumentListCtrl.Designer.cs
index c458ce66e..07ba7f3ca 100644
--- a/Samples/Controls.Net4/Common/ArgumentListCtrl.Designer.cs
+++ b/Samples/Controls.Net4/Common/ArgumentListCtrl.Designer.cs
@@ -81,14 +81,14 @@ private void InitializeComponent()
this.EditMI.Name = "EditMI";
this.EditMI.Size = new System.Drawing.Size(152, 22);
this.EditMI.Text = "Edit...";
- this.EditMI.Click += new System.EventHandler(this.EditMI_Click);
+ this.EditMI.Click += new System.EventHandler(this.EditMI_ClickAsync);
//
// ClearValueMI
//
this.ClearValueMI.Name = "ClearValueMI";
this.ClearValueMI.Size = new System.Drawing.Size(152, 22);
this.ClearValueMI.Text = "Clear Value";
- this.ClearValueMI.Click += new System.EventHandler(this.ClearValueMI_Click);
+ this.ClearValueMI.Click += new System.EventHandler(this.ClearValueMI_ClickAsync);
//
// ArgumentListCtrl
//
diff --git a/Samples/Controls.Net4/Common/ArgumentListCtrl.cs b/Samples/Controls.Net4/Common/ArgumentListCtrl.cs
index b084f25a0..4923e5dda 100644
--- a/Samples/Controls.Net4/Common/ArgumentListCtrl.cs
+++ b/Samples/Controls.Net4/Common/ArgumentListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,10 +32,11 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
@@ -45,8 +46,8 @@ public partial class ArgumentListCtrl : Opc.Ua.Client.Controls.BaseListCtrl
{
public ArgumentListCtrl()
{
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
}
#region Private Fields
@@ -56,13 +57,13 @@ public ArgumentListCtrl()
/// The columns to display in the control.
///
private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Name", HorizontalAlignment.Left, null },
- new object[] { "DataType", HorizontalAlignment.Left, null },
- new object[] { "Value", HorizontalAlignment.Left, null },
- new object[] { "Description", HorizontalAlignment.Left, null },
- };
- #endregion
+ {
+ new object[] { "Name", HorizontalAlignment.Left, null },
+ new object[] { "DataType", HorizontalAlignment.Left, null },
+ new object[] { "Value", HorizontalAlignment.Left, null },
+ new object[] { "Description", HorizontalAlignment.Left, null },
+ };
+ #endregion
#region Public Interface
///
@@ -77,17 +78,17 @@ public void Clear()
///
/// Sets the nodes in the control.
///
- public bool Update(Session session, NodeId methodId, bool inputArgs)
+ public async Task UpdateAsync(Session session, NodeId methodId, bool inputArgs, CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
- if (methodId == null) throw new ArgumentNullException("methodId");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+ if (methodId == null) throw new ArgumentNullException(nameof(methodId));
+
Clear();
-
+
m_session = session;
// find the method.
- MethodNode method = session.NodeCache.Find(methodId) as MethodNode;
+ MethodNode method = await session.NodeCache.FindAsync(methodId, ct) as MethodNode;
if (method == null)
{
@@ -96,7 +97,7 @@ public bool Update(Session session, NodeId methodId, bool inputArgs)
// select the property to find.
QualifiedName browseName = null;
-
+
if (inputArgs)
{
browseName = Opc.Ua.BrowseNames.InputArguments;
@@ -107,7 +108,7 @@ public bool Update(Session session, NodeId methodId, bool inputArgs)
}
// fetch the argument list.
- VariableNode argumentsNode = session.NodeCache.Find(methodId, ReferenceTypeIds.HasProperty, false, true, browseName) as VariableNode;
+ VariableNode argumentsNode = await session.NodeCache.FindAsync(methodId, ReferenceTypeIds.HasProperty, false, true, browseName, ct) as VariableNode;
if (argumentsNode == null)
{
@@ -115,7 +116,7 @@ public bool Update(Session session, NodeId methodId, bool inputArgs)
}
// read the value from the server.
- DataValue value = m_session.ReadValue(argumentsNode.NodeId);
+ DataValue value = await m_session.ReadValueAsync(argumentsNode.NodeId, ct);
ExtensionObject[] argumentsList = value.Value as ExtensionObject[];
@@ -130,7 +131,7 @@ public bool Update(Session session, NodeId methodId, bool inputArgs)
AdjustColumns();
return ItemsLV.Items.Count > 0;
- }
+ }
///
/// Returns the argument values
@@ -155,7 +156,7 @@ public VariantCollection GetValues()
///
/// Updates the argument values.
///
- public void SetValues(VariantCollection values)
+ public async Task SetValuesAsync(VariantCollection values, CancellationToken ct = default)
{
int ii = 0;
@@ -166,88 +167,95 @@ public void SetValues(VariantCollection values)
if (argument != null)
{
argument.Value = values[ii++].Value;
- UpdateItem(item, argument);
+ await UpdateItemAsync(item, argument, ct);
}
}
AdjustColumns();
}
- #endregion
-
+ #endregion
+
#region Overridden Methods
///
protected override void PickItems()
{
base.PickItems();
- EditMI_Click(this, null);
+ EditMI_ClickAsync(this, null);
}
///
protected override void EnableMenuItems(ListViewItem clickedItem)
- {
- EditMI.Enabled = ItemsLV.SelectedItems.Count == 1;
- ClearValueMI.Enabled = EditMI.Enabled;
- }
-
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
{
- Argument argument = item as Argument;
+ EditMI.Enabled = ItemsLV.SelectedItems.Count == 1;
+ ClearValueMI.Enabled = EditMI.Enabled;
+ }
- if (argument == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
+ {
+ try
+ {
+ Argument argument = item as Argument;
- listItem.SubItems[0].Text = String.Format("{0}", argument.Name);
+ if (argument == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
- INode datatype = m_session.NodeCache.Find(argument.DataType);
+ listItem.SubItems[0].Text = String.Format("{0}", argument.Name);
- if (datatype != null)
- {
- listItem.SubItems[1].Text = String.Format("{0}", datatype);
- }
- else
- {
- listItem.SubItems[1].Text = String.Format("{0}", argument.DataType);
- }
+ INode datatype = await m_session.NodeCache.FindAsync(argument.DataType, ct);
- if (argument.ValueRank >= ValueRanks.OneOrMoreDimensions)
- {
- listItem.SubItems[1].Text += "[]";
- }
+ if (datatype != null)
+ {
+ listItem.SubItems[1].Text = String.Format("{0}", datatype);
+ }
+ else
+ {
+ listItem.SubItems[1].Text = String.Format("{0}", argument.DataType);
+ }
- if (argument.Value == null)
- {
- argument.Value = TypeInfo.GetDefaultValue(argument.DataType, argument.ValueRank, m_session.TypeTree);
+ if (argument.ValueRank >= ValueRanks.OneOrMoreDimensions)
+ {
+ listItem.SubItems[1].Text += "[]";
+ }
if (argument.Value == null)
{
- Type type = m_session.MessageContext.Factory.GetSystemType(argument.DataType);
+ argument.Value = TypeInfo.GetDefaultValue(argument.DataType, argument.ValueRank, m_session.TypeTree);
- if (type != null)
+ if (argument.Value == null)
{
- if (argument.ValueRank == ValueRanks.Scalar)
- {
- argument.Value = new ExtensionObject(Activator.CreateInstance(type));
- }
- else
+ Type type = m_session.MessageContext.Factory.GetSystemType(argument.DataType);
+
+ if (type != null)
{
- argument.Value = new ExtensionObject[0];
+ if (argument.ValueRank == ValueRanks.Scalar)
+ {
+ argument.Value = new ExtensionObject(Activator.CreateInstance(type));
+ }
+ else
+ {
+ argument.Value = Array.Empty();
+ }
}
}
}
- }
- listItem.SubItems[2].Text = String.Format("{0}", argument.Value);
- listItem.SubItems[3].Text = String.Format("{0}", argument.Description.Text);
+ listItem.SubItems[2].Text = String.Format("{0}", argument.Value);
+ listItem.SubItems[3].Text = String.Format("{0}", argument.Description.Text);
- listItem.Tag = item;
+ listItem.Tag = item;
+ }
+ catch (Exception exception)
+ {
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ }
}
#endregion
- private void EditMI_Click(object sender, EventArgs e)
+ private async void EditMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -265,15 +273,15 @@ private void EditMI_Click(object sender, EventArgs e)
arguments[0].Value = value;
}
- UpdateItem(ItemsLV.SelectedItems[0], arguments[0]);
+ await UpdateItemAsync(ItemsLV.SelectedItems[0], arguments[0]);
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void ClearValueMI_Click(object sender, EventArgs e)
+ private async void ClearValueMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -286,11 +294,11 @@ private void ClearValueMI_Click(object sender, EventArgs e)
arguments[0].Value = null;
- UpdateItem(ItemsLV.SelectedItems[0], arguments[0]);
+ await UpdateItemAsync(ItemsLV.SelectedItems[0], arguments[0]);
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
}
diff --git a/Samples/Controls.Net4/Common/AttributeListCtrl.Designer.cs b/Samples/Controls.Net4/Common/AttributeListCtrl.Designer.cs
index 81e7e06cc..d9ecacea7 100644
--- a/Samples/Controls.Net4/Common/AttributeListCtrl.Designer.cs
+++ b/Samples/Controls.Net4/Common/AttributeListCtrl.Designer.cs
@@ -83,7 +83,7 @@ private void InitializeComponent()
this.ViewMI.Name = "ViewMI";
this.ViewMI.Size = new System.Drawing.Size(152, 22);
this.ViewMI.Text = "View...";
- this.ViewMI.Click += new System.EventHandler(this.EditMI_Click);
+ this.ViewMI.Click += new System.EventHandler(this.EditMI_ClickAsync);
//
// Separator01
//
diff --git a/Samples/Controls.Net4/Common/AttributeListCtrl.cs b/Samples/Controls.Net4/Common/AttributeListCtrl.cs
index b2cc39400..5315e9dcb 100644
--- a/Samples/Controls.Net4/Common/AttributeListCtrl.cs
+++ b/Samples/Controls.Net4/Common/AttributeListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,12 +32,13 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -45,8 +46,8 @@ public partial class AttributeListCtrl : Opc.Ua.Client.Controls.BaseListCtrl
{
public AttributeListCtrl()
{
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
}
#region Private Fields
@@ -58,20 +59,20 @@ public AttributeListCtrl()
/// The columns to display in the control.
///
private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Field", HorizontalAlignment.Left, null },
- new object[] { "Value", HorizontalAlignment.Left, null },
- new object[] { "Status", HorizontalAlignment.Left, "Good" }
- };
- #endregion
+ {
+ new object[] { "Field", HorizontalAlignment.Left, null },
+ new object[] { "Value", HorizontalAlignment.Left, null },
+ new object[] { "Status", HorizontalAlignment.Left, "Good" }
+ };
+ #endregion
#region Public Interface
///
- ///
+ ///
///
public bool ReadOnly
{
- get { return m_readOnly; }
+ get { return m_readOnly; }
set { m_readOnly = value; }
}
@@ -87,81 +88,80 @@ public void Clear()
///
/// Sets the nodes in the control.
///
- public void Initialize(Session session, ExpandedNodeId nodeId)
+ public async Task InitializeAsync(Session session, ExpandedNodeId nodeId, CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
Clear();
if (nodeId == null)
{
- return;
+ return;
}
-
+
m_session = session;
- m_nodeId = (NodeId)nodeId;
+ m_nodeId = (NodeId)nodeId;
- INode node = m_session.NodeCache.Find(m_nodeId);
+ INode node = await m_session.NodeCache.FindAsync(m_nodeId, ct);
if (node != null && (node.NodeClass & (NodeClass.Variable | NodeClass.Object)) != 0)
{
- AddReferences(ReferenceTypeIds.HasTypeDefinition, BrowseDirection.Forward);
- AddReferences(ReferenceTypeIds.HasModellingRule, BrowseDirection.Forward);
+ await AddReferencesAsync(ReferenceTypeIds.HasTypeDefinition, BrowseDirection.Forward, ct);
+ await AddReferencesAsync(ReferenceTypeIds.HasModellingRule, BrowseDirection.Forward, ct);
}
- AddAttributes();
- AddProperties();
+ await AddAttributesAsync(ct);
+ await AddPropertiesAsync(ct);
AdjustColumns();
}
- #endregion
-
+ #endregion
+
#region NodeField Class
///
/// A field associated with a node.
///
- private class NodeField
- {
- public string Name;
- public object Value;
- public StatusCode StatusCode;
+ private sealed class NodeField
+ {
+ public string Name;
+ public object Value;
+ public StatusCode StatusCode;
public DiagnosticInfo DiagnosticInfo;
- public ReadValueId ValueId;
+ public ReadValueId ValueId;
}
- #endregion
+ #endregion
#region Private Methods
///
/// Adds the attributes to the control.
///
- private void AddAttributes()
+ private async Task AddAttributesAsync(CancellationToken ct = default)
{
// build list of attributes to read.
ReadValueIdCollection nodesToRead = new ReadValueIdCollection();
- foreach (uint attributeId in Attributes.GetIdentifiers())
+ foreach (uint attributeId in Attributes.Identifiers)
{
ReadValueId valueId = new ReadValueId();
- valueId.NodeId = m_nodeId;
- valueId.AttributeId = attributeId;
- valueId.IndexRange = null;
+ valueId.NodeId = m_nodeId;
+ valueId.AttributeId = attributeId;
+ valueId.IndexRange = null;
valueId.DataEncoding = null;
nodesToRead.Add(valueId);
}
// read attributes.
- DataValueCollection values;
- DiagnosticInfoCollection diagnosticInfos;
-
- m_session.Read(
+ ReadResponse response = await m_session.ReadAsync(
null,
0,
TimestampsToReturn.Neither,
nodesToRead,
- out values,
- out diagnosticInfos);
+ ct);
+
+ DataValueCollection values = response.Results;
+ DiagnosticInfoCollection diagnosticInfos = response.DiagnosticInfos;
ClientBase.ValidateResponse(values, nodesToRead);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
@@ -177,10 +177,10 @@ private void AddAttributes()
NodeField field = new NodeField();
- field.ValueId = nodesToRead[ii];
- field.Name = Attributes.GetBrowseName(nodesToRead[ii].AttributeId);
- field.Value = values[ii].Value;
- field.StatusCode = values[ii].StatusCode;
+ field.ValueId = nodesToRead[ii];
+ field.Name = Attributes.GetBrowseName(nodesToRead[ii].AttributeId);
+ field.Value = values[ii].Value;
+ field.StatusCode = values[ii].StatusCode;
if (diagnosticInfos != null && diagnosticInfos.Count > ii)
{
@@ -190,32 +190,32 @@ private void AddAttributes()
AddItem(field, "SimpleItem", -1);
}
}
-
+
///
/// Adds the properties to the control.
///
- private void AddProperties()
+ private async Task AddPropertiesAsync(CancellationToken ct = default)
{
// build list of properties to read.
ReadValueIdCollection nodesToRead = new ReadValueIdCollection();
Browser browser = new Browser(m_session);
-
- browser.BrowseDirection = BrowseDirection.Forward;
- browser.ReferenceTypeId = ReferenceTypeIds.HasProperty;
- browser.IncludeSubtypes = true;
- browser.NodeClassMask = (int)NodeClass.Variable;
+
+ browser.BrowseDirection = BrowseDirection.Forward;
+ browser.ReferenceTypeId = ReferenceTypeIds.HasProperty;
+ browser.IncludeSubtypes = true;
+ browser.NodeClassMask = (int)NodeClass.Variable;
browser.ContinueUntilDone = true;
- ReferenceDescriptionCollection references = browser.Browse(m_nodeId);
+ ReferenceDescriptionCollection references = await browser.BrowseAsync(m_nodeId, ct);
foreach (ReferenceDescription reference in references)
{
ReadValueId valueId = new ReadValueId();
- valueId.NodeId = (NodeId)reference.NodeId;
- valueId.AttributeId = Attributes.Value;
- valueId.IndexRange = null;
+ valueId.NodeId = (NodeId)reference.NodeId;
+ valueId.AttributeId = Attributes.Value;
+ valueId.IndexRange = null;
valueId.DataEncoding = null;
nodesToRead.Add(valueId);
@@ -228,28 +228,27 @@ private void AddProperties()
}
// read values.
- DataValueCollection values;
- DiagnosticInfoCollection diagnosticInfos;
-
- m_session.Read(
+ ReadResponse response = await m_session.ReadAsync(
null,
0,
TimestampsToReturn.Neither,
nodesToRead,
- out values,
- out diagnosticInfos);
+ ct);
+
+ DataValueCollection values = response.Results;
+ DiagnosticInfoCollection diagnosticInfos = response.DiagnosticInfos;
ClientBase.ValidateResponse(values, nodesToRead);
- ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
+ ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
// update control.
for (int ii = 0; ii < nodesToRead.Count; ii++)
{
NodeField field = new NodeField();
- field.ValueId = nodesToRead[ii];
- field.Name = references[ii].ToString();
- field.Value = values[ii].Value;
+ field.ValueId = nodesToRead[ii];
+ field.Name = references[ii].ToString();
+ field.Value = values[ii].Value;
field.StatusCode = values[ii].StatusCode;
if (diagnosticInfos != null && diagnosticInfos.Count > ii)
@@ -264,34 +263,34 @@ private void AddProperties()
///
/// Adds the targets of references to the control.
///
- private void AddReferences(NodeId referenceTypeId, BrowseDirection browseDirection)
+ private async Task AddReferencesAsync(NodeId referenceTypeId, BrowseDirection browseDirection, CancellationToken ct = default)
{
// fetch the attributes for the reference type.
- INode referenceType = m_session.NodeCache.Find(referenceTypeId);
+ INode referenceType = await m_session.NodeCache.FindAsync(referenceTypeId, ct);
if (referenceType == null)
{
return;
}
-
+
// browse for the references.
Browser browser = new Browser(m_session);
-
- browser.BrowseDirection = browseDirection;
- browser.ReferenceTypeId = referenceTypeId;
- browser.IncludeSubtypes = true;
- browser.NodeClassMask = 0;
+
+ browser.BrowseDirection = browseDirection;
+ browser.ReferenceTypeId = referenceTypeId;
+ browser.IncludeSubtypes = true;
+ browser.NodeClassMask = 0;
browser.ContinueUntilDone = true;
- ReferenceDescriptionCollection references = browser.Browse(m_nodeId);
+ ReferenceDescriptionCollection references = await browser.BrowseAsync(m_nodeId, ct);
// add results to list.
foreach (ReferenceDescription reference in references)
{
NodeField field = new NodeField();
- field.Name = referenceType.ToString();
- field.Value = reference.ToString();
+ field.Name = referenceType.ToString();
+ field.Value = reference.ToString();
field.StatusCode = StatusCodes.Good;
AddItem(field, "ReferenceType", -1);
@@ -301,7 +300,7 @@ private void AddReferences(NodeId referenceTypeId, BrowseDirection browseDirecti
///
/// Formats the value of an attribute.
///
- private string FormatAttributeValue(uint attributeId, object value)
+ private async Task FormatAttributeValueAsync(uint attributeId, object value, CancellationToken ct = default)
{
switch (attributeId)
{
@@ -314,14 +313,14 @@ private string FormatAttributeValue(uint attributeId, object value)
return "(null)";
}
-
+
case Attributes.DataType:
{
NodeId datatypeId = value as NodeId;
if (datatypeId != null)
{
- INode datatype = m_session.NodeCache.Find(datatypeId);
+ INode datatype = await m_session.NodeCache.FindAsync(datatypeId, ct);
if (datatype != null)
{
@@ -332,10 +331,10 @@ private string FormatAttributeValue(uint attributeId, object value)
return String.Format("{0}", datatypeId);
}
}
-
+
return String.Format("{0}", value);
}
-
+
case Attributes.ValueRank:
{
int? valueRank = value as int?;
@@ -344,21 +343,21 @@ private string FormatAttributeValue(uint attributeId, object value)
{
switch (valueRank.Value)
{
- case ValueRanks.Scalar: return "Scalar";
- case ValueRanks.OneDimension: return "OneDimension";
+ case ValueRanks.Scalar: return "Scalar";
+ case ValueRanks.OneDimension: return "OneDimension";
case ValueRanks.OneOrMoreDimensions: return "OneOrMoreDimensions";
- case ValueRanks.Any: return "Any";
+ case ValueRanks.Any: return "Any";
default:
{
return String.Format("{0}", valueRank.Value);
}
- }
+ }
}
return String.Format("{0}", value);
}
-
+
case Attributes.MinimumSamplingInterval:
{
double? minimumSamplingInterval = value as double?;
@@ -375,7 +374,7 @@ private string FormatAttributeValue(uint attributeId, object value)
return "Continuous";
}
- return String.Format("{0}", minimumSamplingInterval.Value);
+ return String.Format("{0}", minimumSamplingInterval.Value);
}
return String.Format("{0}", value);
@@ -392,37 +391,37 @@ private string FormatAttributeValue(uint attributeId, object value)
{
bits.Append("Readable");
}
-
+
if ((accessLevel & AccessLevels.CurrentWrite) != 0)
{
if (bits.Length > 0)
{
bits.Append(" | ");
}
-
+
bits.Append("Writeable");
}
-
+
if ((accessLevel & AccessLevels.HistoryRead) != 0)
{
if (bits.Length > 0)
{
bits.Append(" | ");
}
-
+
bits.Append("History");
}
-
+
if ((accessLevel & AccessLevels.HistoryWrite) != 0)
{
if (bits.Length > 0)
{
bits.Append(" | ");
}
-
+
bits.Append("History Update");
}
-
+
if (bits.Length == 0)
{
bits.Append("No Access");
@@ -430,7 +429,7 @@ private string FormatAttributeValue(uint attributeId, object value)
return String.Format("{0}", bits);
}
-
+
case Attributes.EventNotifier:
{
byte notifier = Convert.ToByte(value);
@@ -441,27 +440,27 @@ private string FormatAttributeValue(uint attributeId, object value)
{
bits.Append("Subscribe");
}
-
+
if ((notifier & EventNotifiers.HistoryRead) != 0)
{
if (bits.Length > 0)
{
bits.Append(" | ");
}
-
+
bits.Append("History");
}
-
+
if ((notifier & EventNotifiers.HistoryWrite) != 0)
{
if (bits.Length > 0)
{
bits.Append(" | ");
}
-
+
bits.Append("History Update");
}
-
+
if (bits.Length == 0)
{
bits.Append("No Access");
@@ -476,8 +475,8 @@ private string FormatAttributeValue(uint attributeId, object value)
}
}
}
- #endregion
-
+ #endregion
+
#region Overridden Methods
///
protected override object GetDataToDrag()
@@ -501,42 +500,42 @@ protected override object GetDataToDrag()
protected override void PickItems()
{
base.PickItems();
- EditMI_Click(this, null);
+ EditMI_ClickAsync(this, null);
}
///
protected override void EnableMenuItems(ListViewItem clickedItem)
- {
+ {
RefreshMI.Enabled = true;
-
+
NodeField[] items = GetSelectedItems(typeof(NodeField)) as NodeField[];
if (items != null && items.Length > 0)
{
ViewMI.Enabled = items.Length == 1;
}
- }
-
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
+ }
+
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
{
- NodeField field = item as NodeField;
+ NodeField field = item as NodeField;
- if (field == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
+ if (field == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
Array array = field.Value as Array;
- listItem.SubItems[0].Text = String.Format("{0}", field.Name);
+ listItem.SubItems[0].Text = String.Format("{0}", field.Name);
if (array == null)
{
if (field.ValueId != null)
{
- listItem.SubItems[1].Text = FormatAttributeValue(field.ValueId.AttributeId, field.Value);
+ listItem.SubItems[1].Text = await FormatAttributeValueAsync(field.ValueId.AttributeId, field.Value, ct);
}
else
{
@@ -550,18 +549,18 @@ protected override void UpdateItem(ListViewItem listItem, object item)
listItem.SubItems[2].Text = String.Format("{0}", field.StatusCode);
- listItem.Tag = item;
+ listItem.Tag = item;
}
#endregion
- private void EditMI_Click(object sender, EventArgs e)
+ private async void EditMI_ClickAsync(object sender, EventArgs e)
{
try
{
NodeField[] items = GetSelectedItems(typeof(NodeField)) as NodeField[];
if (items != null && items.Length == 1)
- {
+ {
object value = GuiUtils.EditValue(m_session, items[0].Value);
if (!m_readOnly)
@@ -569,14 +568,14 @@ private void EditMI_Click(object sender, EventArgs e)
if (value != null)
{
items[0].Value = value;
- UpdateItem(ItemsLV.SelectedItems[0], items[0]);
+ await UpdateItemAsync(ItemsLV.SelectedItems[0], items[0]);
}
}
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
}
diff --git a/Samples/Controls.Net4/Common/BackgroundTaskDlg.cs b/Samples/Controls.Net4/Common/BackgroundTaskDlg.cs
index 1fad72d19..cf597bc00 100644
--- a/Samples/Controls.Net4/Common/BackgroundTaskDlg.cs
+++ b/Samples/Controls.Net4/Common/BackgroundTaskDlg.cs
@@ -48,10 +48,10 @@ public BackgroundTaskDlg()
public int Progress
{
- get { return ProgressCTRL.Value; }
-
- set
- {
+ get { return ProgressCTRL.Value; }
+
+ set
+ {
ProgressCTRL.Value = value;
if (value == ProgressCTRL.Maximum)
diff --git a/Samples/Controls.Net4/Common/CallMethodDlg.Designer.cs b/Samples/Controls.Net4/Common/CallMethodDlg.Designer.cs
index 01cd49388..621038150 100644
--- a/Samples/Controls.Net4/Common/CallMethodDlg.Designer.cs
+++ b/Samples/Controls.Net4/Common/CallMethodDlg.Designer.cs
@@ -89,7 +89,7 @@ private void InitializeComponent()
this.OkBTN.TabIndex = 0;
this.OkBTN.Text = "Call";
this.OkBTN.UseVisualStyleBackColor = true;
- this.OkBTN.Click += new System.EventHandler(this.OkBTN_Click);
+ this.OkBTN.Click += new System.EventHandler(this.OkBTN_ClickAsync);
//
// CancelBTN
//
diff --git a/Samples/Controls.Net4/Common/CallMethodDlg.cs b/Samples/Controls.Net4/Common/CallMethodDlg.cs
index 0fb89a54e..1028bfda4 100644
--- a/Samples/Controls.Net4/Common/CallMethodDlg.cs
+++ b/Samples/Controls.Net4/Common/CallMethodDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,10 +32,11 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
@@ -58,16 +59,16 @@ public CallMethodDlg()
private NodeId m_objectId;
private NodeId m_methodId;
#endregion
-
+
#region Public Interface
///
/// Displays the dialog.
///
- public void Show(Session session, NodeId objectId, NodeId methodId)
+ public async Task ShowAsync(Session session, NodeId objectId, NodeId methodId, CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
- if (methodId == null) throw new ArgumentNullException("methodId");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+ if (methodId == null) throw new ArgumentNullException(nameof(methodId));
+
if (m_session != null)
{
m_session.SessionClosing -= m_SessionClosing;
@@ -75,15 +76,15 @@ public void Show(Session session, NodeId objectId, NodeId methodId)
m_session = session;
m_session.SessionClosing += m_SessionClosing;
-
- m_objectId = objectId;
+
+ m_objectId = objectId;
m_methodId = methodId;
- InputArgumentsCTRL.Update(session, methodId, true);
- OutputArgumentsCTRL.Update(session, methodId, false);
-
- Node target = session.NodeCache.Find(objectId) as Node;
- Node method = session.NodeCache.Find(methodId) as Node;
+ await InputArgumentsCTRL.UpdateAsync(session, methodId, true, ct);
+ await OutputArgumentsCTRL.UpdateAsync(session, methodId, false, ct);
+
+ Node target = await session.NodeCache.FindAsync(objectId, ct) as Node;
+ Node method = await session.NodeCache.FindAsync(methodId, ct) as Node;
if (target != null && method != null)
{
@@ -94,7 +95,7 @@ public void Show(Session session, NodeId objectId, NodeId methodId)
BringToFront();
}
#endregion
-
+
private void Session_Closing(object sender, EventArgs e)
{
if (Object.ReferenceEquals(sender, m_session))
@@ -105,36 +106,36 @@ private void Session_Closing(object sender, EventArgs e)
}
}
- private void OkBTN_Click(object sender, EventArgs e)
+ private async void OkBTN_ClickAsync(object sender, EventArgs e)
{
try
{
VariantCollection inputArguments = InputArgumentsCTRL.GetValues();
-
+
CallMethodRequest request = new CallMethodRequest();
- request.ObjectId = m_objectId;
- request.MethodId = m_methodId;
+ request.ObjectId = m_objectId;
+ request.MethodId = m_methodId;
request.InputArguments = inputArguments;
CallMethodRequestCollection requests = new CallMethodRequestCollection();
requests.Add(request);
- CallMethodResultCollection results;
- DiagnosticInfoCollection diagnosticInfos;
-
- ResponseHeader responseHeader = m_session.Call(
+ CallResponse response = await m_session.CallAsync(
null,
requests,
- out results,
- out diagnosticInfos);
+ default);
+
+ ResponseHeader responseHeader = response.ResponseHeader;
+ CallMethodResultCollection results = response.Results;
+ DiagnosticInfoCollection diagnosticInfos = response.DiagnosticInfos;
if (StatusCode.IsBad(results[0].StatusCode))
{
throw new ServiceResultException(new ServiceResult(results[0].StatusCode, 0, diagnosticInfos, responseHeader.StringTable));
}
- OutputArgumentsCTRL.SetValues(results[0].OutputArguments);
+ await OutputArgumentsCTRL.SetValuesAsync(results[0].OutputArguments);
if (results[0].OutputArguments.Count == 0)
{
diff --git a/Samples/Controls.Net4/Common/DataEncodingDlg.Designer.cs b/Samples/Controls.Net4/Common/DataEncodingDlg.Designer.cs
deleted file mode 100644
index c828c7f6b..000000000
--- a/Samples/Controls.Net4/Common/DataEncodingDlg.Designer.cs
+++ /dev/null
@@ -1,299 +0,0 @@
-/* ========================================================================
- * Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
- *
- * OPC Foundation MIT License 1.00
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * The complete license agreement can be found here:
- * http://opcfoundation.org/License/MIT/1.00/
- * ======================================================================*/
-
-namespace Opc.Ua.Sample.Controls
-{
- partial class DataEncodingDlg
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- this.ButtonsPN = new System.Windows.Forms.Panel();
- this.OkBTN = new System.Windows.Forms.Button();
- this.CancelBTN = new System.Windows.Forms.Button();
- this.MainPN = new System.Windows.Forms.Panel();
- this.TypeNameTB = new System.Windows.Forms.TextBox();
- this.ShowEntireDictionaryLN = new System.Windows.Forms.Label();
- this.ShowEntireDictionaryCHK = new System.Windows.Forms.CheckBox();
- this.TypeSystemNameTB = new System.Windows.Forms.TextBox();
- this.DictionaryNameTB = new System.Windows.Forms.TextBox();
- this.DescriptionPN = new System.Windows.Forms.Panel();
- this.DescriptionTB = new System.Windows.Forms.RichTextBox();
- this.TypeSystemNameLB = new System.Windows.Forms.Label();
- this.EncodingCB = new System.Windows.Forms.ComboBox();
- this.DictionaryNameLB = new System.Windows.Forms.Label();
- this.TypeNameLB = new System.Windows.Forms.Label();
- this.EncodingLB = new System.Windows.Forms.Label();
- this.ButtonsPN.SuspendLayout();
- this.MainPN.SuspendLayout();
- this.DescriptionPN.SuspendLayout();
- this.SuspendLayout();
- //
- // ButtonsPN
- //
- this.ButtonsPN.Controls.Add(this.OkBTN);
- this.ButtonsPN.Controls.Add(this.CancelBTN);
- this.ButtonsPN.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.ButtonsPN.Location = new System.Drawing.Point(0, 335);
- this.ButtonsPN.Name = "ButtonsPN";
- this.ButtonsPN.Size = new System.Drawing.Size(492, 31);
- this.ButtonsPN.TabIndex = 0;
- //
- // OkBTN
- //
- this.OkBTN.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.OkBTN.Location = new System.Drawing.Point(4, 4);
- this.OkBTN.Name = "OkBTN";
- this.OkBTN.Size = new System.Drawing.Size(75, 23);
- this.OkBTN.TabIndex = 1;
- this.OkBTN.Text = "OK";
- this.OkBTN.UseVisualStyleBackColor = true;
- this.OkBTN.Click += new System.EventHandler(this.OkBTN_Click);
- //
- // CancelBTN
- //
- this.CancelBTN.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.CancelBTN.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- this.CancelBTN.Location = new System.Drawing.Point(413, 4);
- this.CancelBTN.Name = "CancelBTN";
- this.CancelBTN.Size = new System.Drawing.Size(75, 23);
- this.CancelBTN.TabIndex = 0;
- this.CancelBTN.Text = "Cancel";
- this.CancelBTN.UseVisualStyleBackColor = true;
- //
- // MainPN
- //
- this.MainPN.Controls.Add(this.TypeNameTB);
- this.MainPN.Controls.Add(this.ShowEntireDictionaryLN);
- this.MainPN.Controls.Add(this.ShowEntireDictionaryCHK);
- this.MainPN.Controls.Add(this.TypeSystemNameTB);
- this.MainPN.Controls.Add(this.DictionaryNameTB);
- this.MainPN.Controls.Add(this.DescriptionPN);
- this.MainPN.Controls.Add(this.TypeSystemNameLB);
- this.MainPN.Controls.Add(this.EncodingCB);
- this.MainPN.Controls.Add(this.DictionaryNameLB);
- this.MainPN.Controls.Add(this.TypeNameLB);
- this.MainPN.Controls.Add(this.EncodingLB);
- this.MainPN.Dock = System.Windows.Forms.DockStyle.Fill;
- this.MainPN.Location = new System.Drawing.Point(0, 0);
- this.MainPN.Name = "MainPN";
- this.MainPN.Size = new System.Drawing.Size(492, 335);
- this.MainPN.TabIndex = 1;
- //
- // TypeNameTB
- //
- this.TypeNameTB.Location = new System.Drawing.Point(105, 76);
- this.TypeNameTB.Name = "TypeNameTB";
- this.TypeNameTB.Size = new System.Drawing.Size(202, 20);
- this.TypeNameTB.TabIndex = 23;
- //
- // ShowEntireDictionaryLN
- //
- this.ShowEntireDictionaryLN.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.ShowEntireDictionaryLN.AutoSize = true;
- this.ShowEntireDictionaryLN.Location = new System.Drawing.Point(353, 80);
- this.ShowEntireDictionaryLN.Name = "ShowEntireDictionaryLN";
- this.ShowEntireDictionaryLN.Size = new System.Drawing.Size(114, 13);
- this.ShowEntireDictionaryLN.TabIndex = 18;
- this.ShowEntireDictionaryLN.Text = "Show Entire Dictionary";
- this.ShowEntireDictionaryLN.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
- //
- // ShowEntireDictionaryCHK
- //
- this.ShowEntireDictionaryCHK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.ShowEntireDictionaryCHK.AutoSize = true;
- this.ShowEntireDictionaryCHK.Location = new System.Drawing.Point(472, 81);
- this.ShowEntireDictionaryCHK.Name = "ShowEntireDictionaryCHK";
- this.ShowEntireDictionaryCHK.Size = new System.Drawing.Size(15, 14);
- this.ShowEntireDictionaryCHK.TabIndex = 19;
- this.ShowEntireDictionaryCHK.UseVisualStyleBackColor = true;
- this.ShowEntireDictionaryCHK.CheckStateChanged += new System.EventHandler(this.EncodingCB_SelectedIndexChanged);
- //
- // TypeSystemNameTB
- //
- this.TypeSystemNameTB.Location = new System.Drawing.Point(105, 28);
- this.TypeSystemNameTB.Name = "TypeSystemNameTB";
- this.TypeSystemNameTB.Size = new System.Drawing.Size(202, 20);
- this.TypeSystemNameTB.TabIndex = 22;
- //
- // DictionaryNameTB
- //
- this.DictionaryNameTB.Location = new System.Drawing.Point(105, 52);
- this.DictionaryNameTB.Name = "DictionaryNameTB";
- this.DictionaryNameTB.Size = new System.Drawing.Size(202, 20);
- this.DictionaryNameTB.TabIndex = 21;
- //
- // DescriptionPN
- //
- this.DescriptionPN.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.DescriptionPN.Controls.Add(this.DescriptionTB);
- this.DescriptionPN.Location = new System.Drawing.Point(0, 100);
- this.DescriptionPN.Name = "DescriptionPN";
- this.DescriptionPN.Size = new System.Drawing.Size(493, 235);
- this.DescriptionPN.TabIndex = 20;
- //
- // DescriptionTB
- //
- this.DescriptionTB.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.DescriptionTB.Location = new System.Drawing.Point(3, 2);
- this.DescriptionTB.Name = "DescriptionTB";
- this.DescriptionTB.Size = new System.Drawing.Size(486, 233);
- this.DescriptionTB.TabIndex = 17;
- this.DescriptionTB.Text = "";
- this.DescriptionTB.WordWrap = false;
- //
- // TypeSystemNameLB
- //
- this.TypeSystemNameLB.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.TypeSystemNameLB.AutoSize = true;
- this.TypeSystemNameLB.Location = new System.Drawing.Point(4, 32);
- this.TypeSystemNameLB.Name = "TypeSystemNameLB";
- this.TypeSystemNameLB.Size = new System.Drawing.Size(99, 13);
- this.TypeSystemNameLB.TabIndex = 15;
- this.TypeSystemNameLB.Text = "Type System Name";
- this.TypeSystemNameLB.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
- //
- // EncodingCB
- //
- this.EncodingCB.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.EncodingCB.FormattingEnabled = true;
- this.EncodingCB.Location = new System.Drawing.Point(105, 4);
- this.EncodingCB.Name = "EncodingCB";
- this.EncodingCB.Size = new System.Drawing.Size(202, 21);
- this.EncodingCB.TabIndex = 11;
- this.EncodingCB.SelectedIndexChanged += new System.EventHandler(this.EncodingCB_SelectedIndexChanged);
- //
- // DictionaryNameLB
- //
- this.DictionaryNameLB.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.DictionaryNameLB.AutoSize = true;
- this.DictionaryNameLB.Location = new System.Drawing.Point(4, 56);
- this.DictionaryNameLB.Name = "DictionaryNameLB";
- this.DictionaryNameLB.Size = new System.Drawing.Size(85, 13);
- this.DictionaryNameLB.TabIndex = 14;
- this.DictionaryNameLB.Text = "Dictionary Name";
- this.DictionaryNameLB.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
- //
- // TypeNameLB
- //
- this.TypeNameLB.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.TypeNameLB.AutoSize = true;
- this.TypeNameLB.Location = new System.Drawing.Point(4, 80);
- this.TypeNameLB.Name = "TypeNameLB";
- this.TypeNameLB.Size = new System.Drawing.Size(62, 13);
- this.TypeNameLB.TabIndex = 12;
- this.TypeNameLB.Text = "Type Name";
- this.TypeNameLB.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
- //
- // EncodingLB
- //
- this.EncodingLB.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.EncodingLB.AutoSize = true;
- this.EncodingLB.Location = new System.Drawing.Point(4, 8);
- this.EncodingLB.Name = "EncodingLB";
- this.EncodingLB.Size = new System.Drawing.Size(52, 13);
- this.EncodingLB.TabIndex = 10;
- this.EncodingLB.Text = "Encoding";
- this.EncodingLB.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
- //
- // DataEncodingDlg
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(492, 366);
- this.Controls.Add(this.MainPN);
- this.Controls.Add(this.ButtonsPN);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.MaximizeBox = false;
- this.Name = "DataEncodingDlg";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
- this.Text = "Data Encoding";
- this.ButtonsPN.ResumeLayout(false);
- this.MainPN.ResumeLayout(false);
- this.MainPN.PerformLayout();
- this.DescriptionPN.ResumeLayout(false);
- this.ResumeLayout(false);
-
- }
-
- #endregion
-
- private System.Windows.Forms.Panel ButtonsPN;
- private System.Windows.Forms.Button OkBTN;
- private System.Windows.Forms.Button CancelBTN;
- private System.Windows.Forms.Panel MainPN;
- private System.Windows.Forms.Label EncodingLB;
- private System.Windows.Forms.Label DictionaryNameLB;
- private System.Windows.Forms.Label TypeNameLB;
- private System.Windows.Forms.ComboBox EncodingCB;
- private System.Windows.Forms.Label TypeSystemNameLB;
- private System.Windows.Forms.Label ShowEntireDictionaryLN;
- private System.Windows.Forms.Panel DescriptionPN;
- private System.Windows.Forms.CheckBox ShowEntireDictionaryCHK;
- private System.Windows.Forms.TextBox TypeNameTB;
- private System.Windows.Forms.TextBox TypeSystemNameTB;
- private System.Windows.Forms.TextBox DictionaryNameTB;
- private System.Windows.Forms.RichTextBox DescriptionTB;
- }
-}
diff --git a/Samples/Controls.Net4/Common/DataEncodingDlg.cs b/Samples/Controls.Net4/Common/DataEncodingDlg.cs
deleted file mode 100644
index 8a8dd1179..000000000
--- a/Samples/Controls.Net4/Common/DataEncodingDlg.cs
+++ /dev/null
@@ -1,295 +0,0 @@
-/* ========================================================================
- * Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
- *
- * OPC Foundation MIT License 1.00
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * The complete license agreement can be found here:
- * http://opcfoundation.org/License/MIT/1.00/
- * ======================================================================*/
-
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Text;
-using System.Windows.Forms;
-using System.Reflection;
-
-using Opc.Ua.Client;
-using Opc.Ua.Client.Controls;
-
-namespace Opc.Ua.Sample.Controls
-{
- public partial class DataEncodingDlg : Form
- {
- #region Constructors
- public DataEncodingDlg()
- {
- InitializeComponent();
- this.Icon = ClientUtils.GetAppIcon();
- }
- #endregion
-
- #region Private Fields
- private Session m_session;
- private ReferenceDescriptionCollection m_encodings;
- #endregion
-
- #region Private Methods
- ///
- /// Formats the description.
- ///
- private void FormatDescription()
- {
- string text = DescriptionTB.Text;
-
- int state = 0;
- int start = 0;
- int offset = 0;
-
- for (int ii = 0; ii < 4096 && ii < text.Length; ii++)
- {
- if (text[ii] == '\r')
- {
- offset--;
- }
-
- if (state == 0)
- {
- if (text[ii] == '<')
- {
- start = ii;
- state = 1;
- continue;
- }
- }
-
- if (state == 1)
- {
- if (Char.IsLetter(text[ii]))
- {
- DescriptionTB.SelectionStart = start + offset;
- DescriptionTB.SelectionLength = ii - start;
- DescriptionTB.SelectionColor = Color.Blue;
-
- string selection = DescriptionTB.SelectedText;
-
- start = ii;
- state = 2;
- continue;
- }
- }
-
- if (state == 2)
- {
- if (Char.IsWhiteSpace(text[ii]) || text[ii] == '>' || text[ii] == '/')
- {
- DescriptionTB.SelectionStart = start + offset;
- DescriptionTB.SelectionLength = ii - start;
- DescriptionTB.SelectionColor = Color.Maroon;
-
- string selection = DescriptionTB.SelectedText;
-
- start = ii;
-
- if (text[ii] == '>' || text[ii] == '/')
- {
- state = 0;
- }
- else
- {
- state = 3;
- }
-
- continue;
- }
- }
-
- if (state == 3)
- {
- if (text[ii] == '>')
- {
- DescriptionTB.SelectionStart = start + offset;
- DescriptionTB.SelectionLength = ii - start + 1;
- DescriptionTB.SelectionColor = Color.Blue;
-
- string selection = DescriptionTB.SelectedText;
-
- start = ii+1;
- state = 0;
- continue;
- }
-
- if (Char.IsLetter(text[ii]))
- {
- start = ii;
- state = 4;
- continue;
- }
- }
-
- if (state == 4)
- {
- if (text[ii] == '=')
- {
- DescriptionTB.SelectionStart = start + offset;
- DescriptionTB.SelectionLength = ii - start;
- DescriptionTB.SelectionColor = Color.Red;
-
- string selection = DescriptionTB.SelectedText;
-
- start = ii;
- state = 5;
- continue;
- }
- }
-
- if (state == 5)
- {
- if (text[ii] == '"' || text[ii] == '\'')
- {
- state = 6;
- continue;
- }
- }
-
- if (state == 6)
- {
- if (text[ii] == '"' || text[ii] == '\'')
- {
- DescriptionTB.SelectionStart = start + offset;
- DescriptionTB.SelectionLength = ii - start + 1;
- DescriptionTB.SelectionColor = Color.Blue;
-
- string selection = DescriptionTB.SelectedText;
-
- start = ii+1;
- state = 3;
- continue;
- }
- }
- }
- }
- #endregion
-
- #region Event Handlers
- ///
- /// Prompts the user to specify the browse options.
- ///
- public bool ShowDialog(Session session, NodeId variableId)
- {
- if (session == null) throw new ArgumentNullException("session");
- if (variableId == null) throw new ArgumentNullException("variableId");
-
- m_session = session;
- m_encodings = session.ReadAvailableEncodings(variableId);
-
- foreach (ReferenceDescription encoding in m_encodings)
- {
- EncodingCB.Items.Add(encoding.ToString());
- }
-
- if (EncodingCB.Items.Count > 0)
- {
- EncodingCB.SelectedIndex = 0;
- }
-
- if (ShowDialog() != DialogResult.OK)
- {
- return false;
- }
-
- return true;
- }
-
- private void OkBTN_Click(object sender, EventArgs e)
- {
- DialogResult = DialogResult.OK;
- }
-
- private async void EncodingCB_SelectedIndexChanged(object sender, EventArgs e)
- {
- try
- {
- DescriptionTB.Text = null;
- TypeNameTB.Text = null;
- DictionaryNameTB.Text = null;
- TypeSystemNameTB.Text = null;
-
- if (EncodingCB.SelectedIndex < 0 || EncodingCB.SelectedIndex > m_encodings.Count)
- {
- return;
- }
-
- // get the current encoding.
- ReferenceDescription encoding = m_encodings[EncodingCB.SelectedIndex];
-
- // find the desctiption.
- ReferenceDescription description = m_session.FindDataDescription((NodeId)encoding.NodeId);
-
- if (description == null)
- {
- return;
- }
-
- TypeNameTB.Text = description.ToString();
-
- // find the dictionary.
- DataDictionary dictionary = await m_session.FindDataDictionary((NodeId)description.NodeId);
-
- if (dictionary == null)
- {
- return;
- }
-
- NodeId descriptionId = null;
-
- if (!ShowEntireDictionaryCHK.Checked)
- {
- descriptionId = (NodeId)description.NodeId;
- }
-
- DictionaryNameTB.Text = dictionary.Name;
- TypeSystemNameTB.Text = dictionary.TypeSystemName;
- DescriptionTB.Text = dictionary.GetSchema(descriptionId);
-
- Cursor = Cursors.WaitCursor;
-
- try
- {
- FormatDescription();
- }
- finally
- {
- Cursor = Cursors.Default;
- }
- }
- catch (Exception exception)
- {
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
- }
- }
- #endregion
- }
-}
diff --git a/Samples/Controls.Net4/Common/DataEncodingDlg.resx b/Samples/Controls.Net4/Common/DataEncodingDlg.resx
deleted file mode 100644
index d58980a38..000000000
--- a/Samples/Controls.Net4/Common/DataEncodingDlg.resx
+++ /dev/null
@@ -1,120 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
\ No newline at end of file
diff --git a/Samples/Controls.Net4/Common/DataValueListCtrl.cs b/Samples/Controls.Net4/Common/DataValueListCtrl.cs
index 6413e6a9c..8873a4fb3 100644
--- a/Samples/Controls.Net4/Common/DataValueListCtrl.cs
+++ b/Samples/Controls.Net4/Common/DataValueListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,10 +32,11 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
@@ -46,8 +47,8 @@ public partial class DataValueListCtrl : Opc.Ua.Client.Controls.BaseListCtrl
#region Constructors
public DataValueListCtrl()
{
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
}
#endregion
@@ -59,15 +60,15 @@ public DataValueListCtrl()
/// The columns to display in the control.
///
private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Node", HorizontalAlignment.Left, null },
- new object[] { "Attribute", HorizontalAlignment.Left, "Value", },
- new object[] { "Value", HorizontalAlignment.Left, "", 200 },
- new object[] { "Status", HorizontalAlignment.Left, "" },
- new object[] { "Source Time", HorizontalAlignment.Left, "" },
- new object[] { "Server Time", HorizontalAlignment.Left, "" },
- };
- #endregion
+ {
+ new object[] { "Node", HorizontalAlignment.Left, null },
+ new object[] { "Attribute", HorizontalAlignment.Left, "Value", },
+ new object[] { "Value", HorizontalAlignment.Left, "", 200 },
+ new object[] { "Status", HorizontalAlignment.Left, "" },
+ new object[] { "Source Time", HorizontalAlignment.Left, "" },
+ new object[] { "Server Time", HorizontalAlignment.Left, "" },
+ };
+ #endregion
#region Public Interface
///
@@ -75,8 +76,8 @@ public DataValueListCtrl()
///
public DataListCtrl DataListCtrl
{
- get { return m_DataListCtrl; }
- set { m_DataListCtrl = value; }
+ get { return m_DataListCtrl; }
+ set { m_DataListCtrl = value; }
}
///
@@ -91,17 +92,18 @@ public void Clear()
///
/// Sets the nodes in the control.
///
- public void Initialize(
- Session session,
- ReadValueIdCollection valueIds,
- DataValueCollection values,
- List results)
+ public async Task InitializeAsync(
+ Session session,
+ ReadValueIdCollection valueIds,
+ DataValueCollection values,
+ List results,
+ CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
Clear();
-
- m_session = session;
+
+ m_session = session;
if (valueIds != null)
{
@@ -109,7 +111,7 @@ public void Initialize(
{
ValueItem item = new ValueItem();
- item.Node = m_session.NodeCache.Find(valueIds[ii].NodeId) as Node;
+ item.Node = await m_session.NodeCache.FindAsync(valueIds[ii].NodeId, ct) as Node;
item.AttributeId = valueIds[ii].AttributeId;
if (values != null && ii < values.Count)
@@ -132,26 +134,27 @@ public void Initialize(
///
/// Sets the nodes in the control.
///
- public void Initialize(
- Session session,
- WriteValueCollection values,
- List results)
+ public async Task InitializeAsync(
+ Session session,
+ WriteValueCollection values,
+ List results,
+ CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
Clear();
-
+
m_session = session;
-
+
if (values != null)
{
for (int ii = 0; ii < values.Count; ii++)
{
ValueItem item = new ValueItem();
- item.Node = m_session.NodeCache.Find(values[ii].NodeId) as Node;
+ item.Node = await m_session.NodeCache.FindAsync(values[ii].NodeId, ct) as Node;
item.AttributeId = values[ii].AttributeId;
- item.Value = values[ii].Value;
+ item.Value = values[ii].Value;
if (results != null && ii < results.Count)
{
@@ -164,35 +167,35 @@ public void Initialize(
AdjustColumns();
}
- #endregion
-
+ #endregion
+
#region NodeField Class
///
/// A field associated with a node.
///
- private class ValueItem
- {
+ private sealed class ValueItem
+ {
public Node Node;
public uint AttributeId;
public DataValue Value;
public ServiceResult Result;
}
- #endregion
+ #endregion
#region Private Methods
- #endregion
-
+ #endregion
+
#region Overridden Methods
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
{
- ValueItem dataValue = item as ValueItem;
+ ValueItem dataValue = item as ValueItem;
- if (dataValue == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
+ if (dataValue == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
listItem.SubItems[0].Text = String.Format("{0}", dataValue.Node);
listItem.SubItems[1].Text = Attributes.GetBrowseName(dataValue.AttributeId);
@@ -218,12 +221,12 @@ protected override void UpdateItem(ListViewItem listItem, object item)
if (dataValue.Result != null)
{
- listItem.SubItems[3].Text =String.Format("{0}", dataValue.Result);
+ listItem.SubItems[3].Text = String.Format("{0}", dataValue.Result);
}
- listItem.Tag = item;
+ listItem.Tag = item;
}
-
+
///
protected override void SelectItems()
{
@@ -235,11 +238,11 @@ protected override void SelectItems()
if (values != null && values.Length > 0)
{
- m_DataListCtrl.ShowValue(values[0].Value);
+ m_DataListCtrl.ShowValueAsync(values[0].Value);
}
else
{
- m_DataListCtrl.ShowValue(null);
+ m_DataListCtrl.ShowValueAsync(null);
}
}
}
diff --git a/Samples/Controls.Net4/Common/FindNodeDlg.Designer.cs b/Samples/Controls.Net4/Common/FindNodeDlg.Designer.cs
index 090a459a5..b79239465 100644
--- a/Samples/Controls.Net4/Common/FindNodeDlg.Designer.cs
+++ b/Samples/Controls.Net4/Common/FindNodeDlg.Designer.cs
@@ -104,7 +104,7 @@ private void InitializeComponent()
this.FindBTN.TabIndex = 2;
this.FindBTN.Text = "Find";
this.FindBTN.UseVisualStyleBackColor = true;
- this.FindBTN.Click += new System.EventHandler(this.OkBTN_Click);
+ this.FindBTN.Click += new System.EventHandler(this.OkBTN_ClickAsync);
//
// OkBTN
//
@@ -116,7 +116,7 @@ private void InitializeComponent()
this.OkBTN.TabIndex = 0;
this.OkBTN.Text = "OK";
this.OkBTN.UseVisualStyleBackColor = true;
- this.OkBTN.Click += new System.EventHandler(this.OkBTN_Click);
+ this.OkBTN.Click += new System.EventHandler(this.OkBTN_ClickAsync);
//
// CancelBTN
//
diff --git a/Samples/Controls.Net4/Common/FindNodeDlg.cs b/Samples/Controls.Net4/Common/FindNodeDlg.cs
index ef2b50cd9..74e49577d 100644
--- a/Samples/Controls.Net4/Common/FindNodeDlg.cs
+++ b/Samples/Controls.Net4/Common/FindNodeDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -58,7 +58,7 @@ public NodeIdCollection ShowDialog(Session session, NodeId startNodeId)
{
m_session = session;
- StartNode.Text = String.Format("{0}", startNodeId);
+ StartNode.Text = String.Format("{0}", startNodeId);
RelativePath.Text = null;
if (ShowDialog() != DialogResult.OK)
@@ -69,36 +69,35 @@ public NodeIdCollection ShowDialog(Session session, NodeId startNodeId)
return null;
}
- private void OkBTN_Click(object sender, EventArgs e)
+ private async void OkBTN_ClickAsync(object sender, EventArgs e)
{
try
- {
+ {
BrowsePathCollection browsePaths = new BrowsePathCollection();
-
+
BrowsePath browsePath = new BrowsePath();
browsePath.StartingNode = NodeId.Parse(StartNode.Text);
browsePath.RelativePath = Opc.Ua.RelativePath.Parse(RelativePath.Text, m_session.TypeTree);
-
- browsePaths.Add(browsePath);
- BrowsePathResultCollection results = null;
- DiagnosticInfoCollection diagnosticInfos = null;
+ browsePaths.Add(browsePath);
- m_session.TranslateBrowsePathsToNodeIds(
+ TranslateBrowsePathsToNodeIdsResponse response = await m_session.TranslateBrowsePathsToNodeIdsAsync(
null,
browsePaths,
- out results,
- out diagnosticInfos);
+ default);
+
+ BrowsePathResultCollection results = response.Results;
+ DiagnosticInfoCollection diagnosticInfos = response.DiagnosticInfos;
if (results != null && results.Count == 1)
{
// NodesCTRL.SetNodeList(results[0].MatchingNodeIds);
- }
+ }
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
}
diff --git a/Samples/Controls.Net4/Common/NodeListCtrl.Designer.cs b/Samples/Controls.Net4/Common/NodeListCtrl.Designer.cs
index 4d41311cd..7c28f201f 100644
--- a/Samples/Controls.Net4/Common/NodeListCtrl.Designer.cs
+++ b/Samples/Controls.Net4/Common/NodeListCtrl.Designer.cs
@@ -81,7 +81,7 @@ private void InitializeComponent()
this.ViewMI.Name = "ViewMI";
this.ViewMI.Size = new System.Drawing.Size(166, 22);
this.ViewMI.Text = "View...";
- this.ViewMI.Click += new System.EventHandler(this.ViewMI_Click);
+ this.ViewMI.Click += new System.EventHandler(this.ViewMI_ClickAsync);
//
// DeleteMI
//
diff --git a/Samples/Controls.Net4/Common/NodeListCtrl.cs b/Samples/Controls.Net4/Common/NodeListCtrl.cs
index b2e91f3c5..55f51f7b4 100644
--- a/Samples/Controls.Net4/Common/NodeListCtrl.cs
+++ b/Samples/Controls.Net4/Common/NodeListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -38,6 +38,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -45,8 +47,8 @@ public partial class NodeListCtrl : Opc.Ua.Client.Controls.BaseListCtrl
{
public NodeListCtrl()
{
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
}
#region Private Fields
@@ -58,12 +60,12 @@ public NodeListCtrl()
/// The columns to display in the control.
///
private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Name", HorizontalAlignment.Left, null },
- new object[] { "NodeId", HorizontalAlignment.Left, null },
- new object[] { "Class", HorizontalAlignment.Left, null }
- };
- #endregion
+ {
+ new object[] { "Name", HorizontalAlignment.Left, null },
+ new object[] { "NodeId", HorizontalAlignment.Left, null },
+ new object[] { "Class", HorizontalAlignment.Left, null }
+ };
+ #endregion
#region Public Interface
///
@@ -78,24 +80,24 @@ public void Clear()
///
/// Sets the nodes in the control.
///
- public void Initialize(Session session, NodeIdCollection nodeIds, NodeClass nodeClassMask)
+ public async Task InitializeAsync(Session session, NodeIdCollection nodeIds, NodeClass nodeClassMask, CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
Clear();
-
- m_session = session;
- m_nodeIds = nodeIds;
- m_nodeClassMask = (nodeClassMask == 0)?(NodeClass)Byte.MaxValue:nodeClassMask;
+
+ m_session = session;
+ m_nodeIds = nodeIds;
+ m_nodeClassMask = (nodeClassMask == 0) ? (NodeClass)Byte.MaxValue : nodeClassMask;
if (nodeIds == null)
{
- return;
+ return;
}
foreach (NodeId nodeId in nodeIds)
{
- INode node = m_session.NodeCache.Find(nodeId);
+ INode node = await m_session.NodeCache.FindAsync(nodeId, ct);
if (node != null && (m_nodeClassMask & node.NodeClass) != 0)
{
@@ -105,15 +107,15 @@ public void Initialize(Session session, NodeIdCollection nodeIds, NodeClass node
AdjustColumns();
}
-
+
///
/// Adds a node to the list.
///
- public void AddNodeId(ReferenceDescription reference)
+ public async Task AddNodeIdAsync(ReferenceDescription reference, CancellationToken ct = default)
{
if (reference != null)
{
- AddNodeId(reference.NodeId);
+ await AddNodeIdAsync(reference.NodeId, ct);
AdjustColumns();
}
}
@@ -121,9 +123,9 @@ public void AddNodeId(ReferenceDescription reference)
///
/// Adds a node to the list.
///
- public void AddNodeId(ExpandedNodeId nodeId)
+ public async Task AddNodeIdAsync(ExpandedNodeId nodeId, CancellationToken ct = default)
{
- Node node = m_session.NodeCache.Find(nodeId) as Node;
+ Node node = await m_session.NodeCache.FindAsync(nodeId, ct) as Node;
if (node == null)
{
@@ -140,12 +142,12 @@ public void AddNodeId(ExpandedNodeId nodeId)
{
if (target.NodeId == node.NodeId)
{
- UpdateItem(listItem, node);
+ await UpdateItemAsync(listItem, node, ct);
return;
}
}
}
-
+
AddItem(node, "Property", -1);
return;
}
@@ -156,15 +158,15 @@ public void AddNodeId(ExpandedNodeId nodeId)
if (supertypeId != null)
{
- AddNodeId(supertypeId);
+ await AddNodeIdAsync(supertypeId, ct);
}
}
-
+
IList properties = node.ReferenceTable.Find(ReferenceTypeIds.HasProperty, false, true, m_session.TypeTree);
for (int ii = 0; ii < properties.Count; ii++)
{
- AddNodeId(properties[ii].TargetId);
+ await AddNodeIdAsync(properties[ii].TargetId, ct);
}
}
@@ -187,40 +189,40 @@ public NodeIdCollection GetNodeIds()
return nodeIds;
}
- #endregion
-
+ #endregion
+
#region Private Methods
- #endregion
-
+ #endregion
+
#region Overridden Methods
///
- protected override void EnableMenuItems(ListViewItem clickedItem)
- {
- ViewMI.Enabled = ItemsLV.SelectedItems.Count == 1;
+ protected override void EnableMenuItems(ListViewItem clickedItem)
+ {
+ ViewMI.Enabled = ItemsLV.SelectedItems.Count == 1;
DeleteMI.Enabled = ItemsLV.SelectedItems.Count > 0;
- }
-
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
+ }
+
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
{
- Node node = item as Node;
+ Node node = item as Node;
- if (node == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
+ if (node == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
listItem.SubItems[0].Text = String.Format("{0}", node);
- listItem.SubItems[1].Text = String.Format("{0}", node.NodeId);
- listItem.SubItems[2].Text = String.Format("{0}", (NodeClass)node.NodeClass);
+ listItem.SubItems[1].Text = String.Format("{0}", node.NodeId);
+ listItem.SubItems[2].Text = String.Format("{0}", (NodeClass)node.NodeClass);
- listItem.Tag = item;
+ listItem.Tag = item;
}
#endregion
-
+
#region Event Handlers
- private void ViewMI_Click(object sender, EventArgs e)
+ private async void ViewMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -228,24 +230,24 @@ private void ViewMI_Click(object sender, EventArgs e)
if (nodes == null || nodes.Length == 1)
{
- new NodeAttributesDlg().ShowDialog(m_session, nodes[0].NodeId);
+ await new NodeAttributesDlg().ShowDialogAsync(m_session, nodes[0].NodeId);
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- protected override void ItemsLV_DragDrop(object sender, DragEventArgs e)
- {
+ protected override async Task OnDragDropAsync(object sender, DragEventArgs e, CancellationToken ct = default)
+ {
try
{
ReferenceDescription reference = e.Data.GetData(typeof(ReferenceDescription)) as ReferenceDescription;
if (reference != null)
{
- AddNodeId(reference);
+ await AddNodeIdAsync(reference, ct);
}
ReferenceDescriptionCollection references = e.Data.GetData(typeof(ReferenceDescriptionCollection)) as ReferenceDescriptionCollection;
@@ -254,7 +256,7 @@ protected override void ItemsLV_DragDrop(object sender, DragEventArgs e)
{
foreach (ReferenceDescription current in references)
{
- AddNodeId(current);
+ await AddNodeIdAsync(current, ct);
}
}
@@ -270,7 +272,7 @@ protected override void ItemsLV_DragDrop(object sender, DragEventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -292,7 +294,7 @@ private void DeleteMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Common/PerformanceResultsListCtrl.cs b/Samples/Controls.Net4/Common/PerformanceResultsListCtrl.cs
index e012ea178..b6b2cef38 100644
--- a/Samples/Controls.Net4/Common/PerformanceResultsListCtrl.cs
+++ b/Samples/Controls.Net4/Common/PerformanceResultsListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,10 +32,11 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client.Controls;
namespace Opc.Ua.Sample.Controls
@@ -44,8 +45,8 @@ public partial class PerformanceResultsListCtrl : Opc.Ua.Client.Controls.BaseLis
{
public PerformanceResultsListCtrl()
{
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
}
#region Private Fields
@@ -53,19 +54,19 @@ public PerformanceResultsListCtrl()
/// The columns to display in the control.
///
private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Server", HorizontalAlignment.Left, null },
- new object[] { "1", HorizontalAlignment.Left, "-1" },
- new object[] { "10", HorizontalAlignment.Left, "-1" },
- new object[] { "50", HorizontalAlignment.Left, "-1" },
- new object[] { "100", HorizontalAlignment.Left, "-1" },
- new object[] { "250", HorizontalAlignment.Left, "-1" },
- new object[] { "500", HorizontalAlignment.Left, "-1" },
- new object[] { "1000", HorizontalAlignment.Left, "-1" },
+ {
+ new object[] { "Server", HorizontalAlignment.Left, null },
+ new object[] { "1", HorizontalAlignment.Left, "-1" },
+ new object[] { "10", HorizontalAlignment.Left, "-1" },
+ new object[] { "50", HorizontalAlignment.Left, "-1" },
+ new object[] { "100", HorizontalAlignment.Left, "-1" },
+ new object[] { "250", HorizontalAlignment.Left, "-1" },
+ new object[] { "500", HorizontalAlignment.Left, "-1" },
+ new object[] { "1000", HorizontalAlignment.Left, "-1" },
//new object[] { "2500", HorizontalAlignment.Left, "-1" },
- //new object[] { "5000", HorizontalAlignment.Left, "-1" },
+ //new object[] { "5000", HorizontalAlignment.Left, "-1" },
};
- #endregion
+ #endregion
#region Public Interface
///
@@ -73,7 +74,7 @@ public PerformanceResultsListCtrl()
///
public void Add(PerformanceTestResult result)
{
- if (result == null) throw new ArgumentNullException("result");
+ if (result == null) throw new ArgumentNullException(nameof(result));
AddItem(result);
AdjustColumns();
@@ -95,8 +96,8 @@ public PerformanceTestResult[] GetResults()
{
return (PerformanceTestResult[])GetItems(typeof(PerformanceTestResult));
}
- #endregion
-
+ #endregion
+
#region Overridden Methods
///
protected override void PickItems()
@@ -106,22 +107,22 @@ protected override void PickItems()
///
protected override void EnableMenuItems(ListViewItem clickedItem)
- {
- DeleteMI.Enabled = ItemsLV.SelectedItems.Count > 0;
+ {
+ DeleteMI.Enabled = ItemsLV.SelectedItems.Count > 0;
ClearAllMI.Enabled = ItemsLV.Items.Count > 0;
- }
-
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
+ }
+
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
{
- PerformanceTestResult result = item as PerformanceTestResult;
-
- if (result == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
-
+ PerformanceTestResult result = item as PerformanceTestResult;
+
+ if (result == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
+
listItem.SubItems[0].Text = String.Format("{0}", result.Endpoint);
listItem.SubItems[1].Text = String.Format("{0:0.##}", result.Results[1]);
listItem.SubItems[2].Text = String.Format("{0:0.##}", result.Results[10]);
@@ -132,8 +133,8 @@ protected override void UpdateItem(ListViewItem listItem, object item)
//listItem.SubItems[7].Text = String.Format("{0:0.##}", result.Results[1000]);
//listItem.SubItems[7].Text = String.Format("{0:0.##}", result.Results[2500]);
//listItem.SubItems[8].Text = String.Format("{0:0.##}", result.Results[5000]);
-
- listItem.Tag = item;
+
+ listItem.Tag = item;
listItem.ImageKey = "DataType";
}
#endregion
@@ -158,7 +159,7 @@ private void DeleteMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -170,7 +171,7 @@ private void ClearAllMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
}
diff --git a/Samples/Controls.Net4/Common/PerformanceTestDlg.cs b/Samples/Controls.Net4/Common/PerformanceTestDlg.cs
index 49156757c..64cfda812 100644
--- a/Samples/Controls.Net4/Common/PerformanceTestDlg.cs
+++ b/Samples/Controls.Net4/Common/PerformanceTestDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -43,6 +43,7 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
namespace Opc.Ua.Sample.Controls
{
@@ -64,24 +65,24 @@ public PerformanceTestDlg()
private ServiceMessageContext m_messageContext;
private X509Certificate2 m_clientCertificate;
private string m_filePath;
-
+
///
/// Displays the dialog.
///
public EndpointDescription ShowDialog(
- ApplicationConfiguration configuration,
+ ApplicationConfiguration configuration,
ConfiguredEndpointCollection endpoints,
- X509Certificate2 clientCertificate)
+ X509Certificate2 clientCertificate)
{
- m_configuration = configuration;
- m_endpoints = endpoints;
- m_messageContext = configuration.CreateMessageContext();
+ m_configuration = configuration;
+ m_endpoints = endpoints;
+ m_messageContext = configuration.CreateMessageContext();
m_clientCertificate = clientCertificate;
- m_running = false;
- m_filePath = @".\perftest.csv";
-
+ m_running = false;
+ m_filePath = @".\perftest.csv";
+
EndpointSelectorCTRL.Initialize(m_endpoints, configuration);
-
+
lock (m_lock)
{
OkBTN.Enabled = m_running = false;
@@ -105,7 +106,7 @@ private void LoadResults(string filePath)
DataContractSerializer serializer = new DataContractSerializer(typeof(PerformanceTestResult[]));
PerformanceTestResult[] results = (PerformanceTestResult[])serializer.ReadObject(istrm);
istrm.Close();
-
+
ResultsCTRL.Clear();
foreach (PerformanceTestResult result in results)
@@ -127,7 +128,7 @@ private void SaveResults(string filePath)
{
return;
}
-
+
Stream ostrm = File.Open(filePath, FileMode.Create);
StreamWriter writer = new StreamWriter(ostrm);
@@ -137,8 +138,8 @@ private void SaveResults(string filePath)
writer.Write(",Algorithms");
writer.Write(",Encoding");
- foreach (KeyValuePair result in results[0].Results)
- {
+ foreach (KeyValuePair result in results[0].Results)
+ {
writer.Write(",{0} Values", result.Key);
}
@@ -154,17 +155,17 @@ private void SaveResults(string filePath)
writer.Write(",{0}", uri.Scheme);
writer.Write(",{0}", endpoint.SecurityMode);
writer.Write(",{0}", SecurityPolicies.GetDisplayName(endpoint.SecurityPolicyUri));
- writer.Write(",{0}", (results[ii].Endpoint.Configuration.UseBinaryEncoding)?"Binary":"XML");
+ writer.Write(",{0}", (results[ii].Endpoint.Configuration.UseBinaryEncoding) ? "Binary" : "XML");
- foreach (KeyValuePair result in results[ii].Results)
- {
+ foreach (KeyValuePair result in results[ii].Results)
+ {
writer.Write(",{0}", result.Value);
}
writer.Write("\r\n");
}
- writer.Close();
+ writer.Close();
m_filePath = filePath;
}
@@ -180,13 +181,13 @@ public void TestComplete(object state)
}
try
- {
+ {
ProgressCTRL.Value = ProgressCTRL.Maximum;
ResultsCTRL.Add((PerformanceTestResult)state);
- }
+ }
catch (Exception e)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), e);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), e);
}
}
@@ -204,15 +205,15 @@ private void TestProgress(object state)
try
{
ProgressCTRL.Value = (int)state;
- }
+ }
catch (Exception e)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), e);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), e);
}
}
///
- /// Called when the the test fails with an exception.
+ /// Called when the test fails with an exception.
///
private void TestException(object state)
{
@@ -225,26 +226,26 @@ private void TestException(object state)
try
{
OkBTN.Enabled = m_running = false;
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), (Exception)state);
- }
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), (Exception)state);
+ }
catch (Exception e)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), e);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), e);
}
}
-
+
///
/// Runs all tests in a background thread.
///
- private void DoAllTests(object state)
+ private async Task DoAllTestsAsync(CancellationToken ct = default)
{
for (int ii = 0; ii < m_endpoints.Count; ii++)
{
try
{
- DoTest(m_endpoints[ii]);
+ await DoTestAsync(m_endpoints[ii], ct);
}
- catch
+ catch
{
// ignore.
}
@@ -256,24 +257,7 @@ private void DoAllTests(object state)
///
/// Runs the test in a background thread.
///
- private void DoTest(object state)
- {
- try
- {
- DoTest((ConfiguredEndpoint)state);
- }
- catch (Exception e)
- {
- TestException(e);
- }
-
- m_running = false;
- }
-
- ///
- /// Runs the test in a background thread.
- ///
- private void DoTest(ConfiguredEndpoint endpoint)
+ private async Task DoTestAsync(ConfiguredEndpoint endpoint, CancellationToken ct = default)
{
PerformanceTestResult result = new PerformanceTestResult(endpoint, 100);
@@ -289,7 +273,7 @@ private void DoTest(ConfiguredEndpoint endpoint)
// update the endpoint.
if (endpoint.UpdateBeforeConnect)
{
- endpoint.UpdateFromServer();
+ await endpoint.UpdateFromServerAsync(ct);
}
SessionClient client = null;
@@ -339,16 +323,15 @@ private void DoTest(ConfiguredEndpoint endpoint)
}
// ensure valid connection.
- DataValueCollection results = null;
- DiagnosticInfoCollection diagnosticInfos = null;
-
- client.Read(
+ ReadResponse response = await client.ReadAsync(
requestHeader,
0,
TimestampsToReturn.Both,
nodesToRead,
- out results,
- out diagnosticInfos);
+ ct);
+
+ DataValueCollection results = response.Results;
+ DiagnosticInfoCollection diagnosticInfos = response.DiagnosticInfos;
if (results.Count != count)
{
@@ -360,13 +343,15 @@ private void DoTest(ConfiguredEndpoint endpoint)
for (int jj = 0; jj < result.Iterations; jj++)
{
- client.Read(
+ response = await client.ReadAsync(
requestHeader,
0,
TimestampsToReturn.Both,
nodesToRead,
- out results,
- out diagnosticInfos);
+ ct);
+
+ results = response.Results;
+ diagnosticInfos = response.DiagnosticInfos;
if (results.Count != count)
{
@@ -404,11 +389,11 @@ private void EndpointSelectorCTRL_ConnectEndpoint(object sender, ConnectEndpoint
// start processing.
OkBTN.Enabled = m_running = true;
- ThreadPool.QueueUserWorkItem(new WaitCallback(DoTest), endpoint);
+ Task.Run(() => DoTestAsync(endpoint));
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
e.UpdateControl = false;
}
}
@@ -424,70 +409,70 @@ private void OkBTN_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
private void SaveBTN_Click(object sender, EventArgs e)
{
- try
- {
+ try
+ {
FileInfo fileInfo = new FileInfo(m_filePath);
- SaveFileDialog dialog = new SaveFileDialog();
+ SaveFileDialog dialog = new SaveFileDialog();
- dialog.CheckFileExists = false;
- dialog.CheckPathExists = true;
- dialog.DefaultExt = ".csv";
- dialog.Filter = "Result Files (*.csv)|*.csv|All Files (*.*)|*.*";
- dialog.ValidateNames = true;
- dialog.Title = "Save Performance Test Result File";
- dialog.FileName = m_filePath;
+ dialog.CheckFileExists = false;
+ dialog.CheckPathExists = true;
+ dialog.DefaultExt = ".csv";
+ dialog.Filter = "Result Files (*.csv)|*.csv|All Files (*.*)|*.*";
+ dialog.ValidateNames = true;
+ dialog.Title = "Save Performance Test Result File";
+ dialog.FileName = m_filePath;
dialog.InitialDirectory = fileInfo.DirectoryName;
dialog.RestoreDirectory = true;
- if (dialog.ShowDialog() != DialogResult.OK)
- {
- return;
- }
+ if (dialog.ShowDialog() != DialogResult.OK)
+ {
+ return;
+ }
SaveResults(dialog.FileName);
- }
+ }
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
private void LoadBTN_Click(object sender, EventArgs e)
- {
- try
- {
+ {
+ try
+ {
FileInfo fileInfo = new FileInfo(m_filePath);
- OpenFileDialog dialog = new OpenFileDialog();
+ OpenFileDialog dialog = new OpenFileDialog();
- dialog.CheckFileExists = true;
- dialog.CheckPathExists = true;
- dialog.DefaultExt = ".csv";
- dialog.Filter = "Result Files (*.csv)|*.csv|All Files (*.*)|*.*";
- dialog.Multiselect = false;
- dialog.ValidateNames = true;
- dialog.Title = "Open Performance Test Result File";
- dialog.FileName = m_filePath;
+ dialog.CheckFileExists = true;
+ dialog.CheckPathExists = true;
+ dialog.DefaultExt = ".csv";
+ dialog.Filter = "Result Files (*.csv)|*.csv|All Files (*.*)|*.*";
+ dialog.Multiselect = false;
+ dialog.ValidateNames = true;
+ dialog.Title = "Open Performance Test Result File";
+ dialog.FileName = m_filePath;
dialog.InitialDirectory = fileInfo.DirectoryName;
dialog.RestoreDirectory = true;
- if (dialog.ShowDialog() != DialogResult.OK)
- {
- return;
- }
+ if (dialog.ShowDialog() != DialogResult.OK)
+ {
+ return;
+ }
LoadResults(dialog.FileName);
- }
+ }
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -502,7 +487,7 @@ private void TestAllBTN_Click(object sender, EventArgs e)
ResultsCTRL.Clear();
OkBTN.Enabled = m_running = true;
- ThreadPool.QueueUserWorkItem(new WaitCallback(DoAllTests), null);
+ Task.Run(() => DoAllTestsAsync());
}
catch (Exception exception)
{
@@ -525,19 +510,19 @@ public PerformanceTestResult(ConfiguredEndpoint endpoint, int iterations)
{
Initialize();
- m_endpoint = endpoint;
+ m_endpoint = endpoint;
m_iterations = iterations;
}
- ///
- /// Sets private members to default values.
- ///
- private void Initialize()
- {
- m_endpoint = null;
+ ///
+ /// Sets private members to default values.
+ ///
+ private void Initialize()
+ {
+ m_endpoint = null;
m_iterations = 0;
- m_results = new Dictionary();
- }
+ m_results = new Dictionary();
+ }
///
/// Initializes the object during deserialization.
@@ -577,14 +562,14 @@ public int Iterations
private List TestCaseResults
{
get
- {
+ {
List results = new List();
- foreach (KeyValuePair entry in m_results)
+ foreach (KeyValuePair entry in m_results)
{
PerformanceTestResultItem item = new PerformanceTestResultItem();
- item.Count = entry.Key;
+ item.Count = entry.Key;
item.Average = entry.Value;
results.Add(item);
@@ -592,8 +577,8 @@ private List TestCaseResults
return results;
}
- set
- {
+ set
+ {
m_results.Clear();
if (value != null)
@@ -607,18 +592,18 @@ private List TestCaseResults
}
///
- /// The average roundtrip time in milliseconds indexed by the payload size in bytes.
+ /// The average roundtrip time in milliseconds indexed by the payload size in bytes.
///
- public IDictionary Results
+ public IDictionary Results
{
get { return m_results; }
}
#endregion
-
+
#region Private Fields
private ConfiguredEndpoint m_endpoint;
private int m_iterations;
- private Dictionary m_results;
+ private Dictionary m_results;
#endregion
}
@@ -637,14 +622,14 @@ public PerformanceTestResultItem()
Initialize();
}
- ///
- /// Sets private members to default values.
- ///
- private void Initialize()
- {
- m_count = 0;
+ ///
+ /// Sets private members to default values.
+ ///
+ private void Initialize()
+ {
+ m_count = 0;
m_average = 0;
- }
+ }
///
/// Initializes the object during deserialization.
@@ -663,7 +648,7 @@ private void Initialize(StreamingContext context)
[DataMember(Order = 1)]
public int Count
{
- get { return m_count; }
+ get { return m_count; }
set { m_count = value; }
}
@@ -673,11 +658,11 @@ public int Count
[DataMember(Order = 2)]
public double Average
{
- get { return m_average; }
+ get { return m_average; }
set { m_average = value; }
}
#endregion
-
+
#region Private Fields
private int m_count;
private double m_average;
diff --git a/Samples/Controls.Net4/Common/PropertyListCtrl.cs b/Samples/Controls.Net4/Common/PropertyListCtrl.cs
index 8ad8dc835..dde321b9a 100644
--- a/Samples/Controls.Net4/Common/PropertyListCtrl.cs
+++ b/Samples/Controls.Net4/Common/PropertyListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,10 +32,11 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
@@ -45,8 +46,8 @@ public partial class PropertyListCtrl : Opc.Ua.Client.Controls.BaseListCtrl
{
public PropertyListCtrl()
{
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
}
#region Private Fields
@@ -57,13 +58,13 @@ public PropertyListCtrl()
/// The columns to display in the control.
///
private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Property", HorizontalAlignment.Left, null },
- new object[] { "Value", HorizontalAlignment.Left, "" },
- new object[] { "DataType", HorizontalAlignment.Left, null },
- new object[] { "Description", HorizontalAlignment.Left, null }
- };
- #endregion
+ {
+ new object[] { "Property", HorizontalAlignment.Left, null },
+ new object[] { "Value", HorizontalAlignment.Left, "" },
+ new object[] { "DataType", HorizontalAlignment.Left, null },
+ new object[] { "Description", HorizontalAlignment.Left, null }
+ };
+ #endregion
#region Public Interface
///
@@ -71,10 +72,10 @@ public PropertyListCtrl()
///
public bool ShowValues
{
- get { return m_showValues; }
+ get { return m_showValues; }
set { m_showValues = value; }
}
-
+
///
/// Clears the contents of the control,
///
@@ -87,44 +88,44 @@ public void Clear()
///
/// Sets the nodes in the control.
///
- public void Update(Session session, ReferenceDescription reference)
+ public async Task UpdateAsync(Session session, ReferenceDescription reference, CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
Clear();
if (reference == null)
{
- return;
+ return;
}
-
+
m_session = session;
- AddProperties(reference.NodeId);
+ await AddPropertiesAsync(reference.NodeId, ct);
AdjustColumns();
}
- #endregion
-
+ #endregion
+
#region NodeField Class
///
/// A field associated with a node.
///
- private class PropertyItem
- {
+ private sealed class PropertyItem
+ {
public ReferenceDescription Reference;
- public VariableNode Property;
+ public VariableNode Property;
}
- #endregion
+ #endregion
#region Private Methods
///
/// Adds the properties to the control.
///
- private void AddProperties(ExpandedNodeId nodeId)
+ private async Task AddPropertiesAsync(ExpandedNodeId nodeId, CancellationToken ct = default)
{
// get node.
- Node node = m_session.NodeCache.Find(nodeId) as Node;
+ Node node = await m_session.NodeCache.FindAsync(nodeId, ct) as Node;
if (node == null)
{
@@ -136,21 +137,21 @@ private void AddProperties(ExpandedNodeId nodeId)
if (supertypeId != null)
{
- AddProperties(supertypeId);
+ await AddPropertiesAsync(supertypeId, ct);
}
// build list of properties to read.
ReadValueIdCollection nodesToRead = new ReadValueIdCollection();
Browser browser = new Browser(m_session);
-
- browser.BrowseDirection = BrowseDirection.Forward;
- browser.ReferenceTypeId = ReferenceTypeIds.HasProperty;
- browser.IncludeSubtypes = true;
- browser.NodeClassMask = (int)NodeClass.Variable;
+
+ browser.BrowseDirection = BrowseDirection.Forward;
+ browser.ReferenceTypeId = ReferenceTypeIds.HasProperty;
+ browser.IncludeSubtypes = true;
+ browser.NodeClassMask = (int)NodeClass.Variable;
browser.ContinueUntilDone = true;
- ReferenceDescriptionCollection references = browser.Browse(node.NodeId);
+ ReferenceDescriptionCollection references = await browser.BrowseAsync(node.NodeId, ct);
// add propertoes to view.
foreach (ReferenceDescription reference in references)
@@ -158,13 +159,13 @@ private void AddProperties(ExpandedNodeId nodeId)
PropertyItem field = new PropertyItem();
field.Reference = reference;
- field.Property = m_session.NodeCache.Find(reference.NodeId) as VariableNode;
+ field.Property = await m_session.NodeCache.FindAsync(reference.NodeId, ct) as VariableNode;
AddItem(field, "Property", -1);
}
}
- #endregion
-
+ #endregion
+
#region Overridden Methods
///
protected override object GetDataToDrag()
@@ -186,25 +187,25 @@ protected override object GetDataToDrag()
///
protected override void EnableMenuItems(ListViewItem clickedItem)
- {
+ {
PropertyItem[] items = GetSelectedItems(typeof(PropertyItem)) as PropertyItem[];
if (items != null && items.Length > 0)
{
SelectMI.Enabled = true;
}
- }
-
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
+ }
+
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
{
- PropertyItem property = item as PropertyItem;
+ PropertyItem property = item as PropertyItem;
- if (property == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
+ if (property == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
listItem.SubItems[0].Text = String.Format("{0}", property.Reference);
listItem.SubItems[1].Text = "";
@@ -224,7 +225,7 @@ protected override void UpdateItem(ListViewItem listItem, object item)
}
}
- INode node = m_session.NodeCache.Find(property.Property.DataType);
+ INode node = await m_session.NodeCache.FindAsync(property.Property.DataType, ct);
if (node != null)
{
@@ -239,10 +240,10 @@ protected override void UpdateItem(ListViewItem listItem, object item)
{
listItem.SubItems[2].Text += "[]";
}
-
+
listItem.SubItems[3].Text = String.Format("{0}", property.Property.Description);
- listItem.Tag = item;
+ listItem.Tag = item;
}
#endregion
@@ -254,7 +255,7 @@ private void SelectMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
}
diff --git a/Samples/Controls.Net4/Common/SelectNodesDlg.Designer.cs b/Samples/Controls.Net4/Common/SelectNodesDlg.Designer.cs
index 10e804dac..3df22f483 100644
--- a/Samples/Controls.Net4/Common/SelectNodesDlg.Designer.cs
+++ b/Samples/Controls.Net4/Common/SelectNodesDlg.Designer.cs
@@ -136,7 +136,7 @@ private void InitializeComponent()
this.BrowseCTRL.SessionTreeCtrl = null;
this.BrowseCTRL.Size = new System.Drawing.Size(375, 285);
this.BrowseCTRL.TabIndex = 1;
- this.BrowseCTRL.ItemsSelected += new Opc.Ua.Sample.Controls.NodesSelectedEventHandler(this.BrowseCTRL_NodesSelected);
+ this.BrowseCTRL.ItemsSelected += new Opc.Ua.Sample.Controls.NodesSelectedEventHandler(this.BrowseCTRL_NodesSelectedAsync);
//
// AttributesCTRL
//
diff --git a/Samples/Controls.Net4/Common/SelectNodesDlg.cs b/Samples/Controls.Net4/Common/SelectNodesDlg.cs
index e538e95a5..ed4369e2a 100644
--- a/Samples/Controls.Net4/Common/SelectNodesDlg.cs
+++ b/Samples/Controls.Net4/Common/SelectNodesDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -38,6 +38,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading;
+using System.Threading.Tasks;
namespace Opc.Ua.Sample.Controls
{
@@ -54,45 +56,46 @@ public SelectNodesDlg()
#region Private Fields
private Session m_session;
#endregion
-
+
#region Public Interface
///
/// Displays the dialog.
///
- public NodeIdCollection ShowDialog(
- Session session,
- BrowseViewType browseView,
+ public async Task ShowDialogAsync(
+ Session session,
+ BrowseViewType browseView,
NodeIdCollection nodesIds,
- NodeClass nodeClassMask)
+ NodeClass nodeClassMask,
+ CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
+ if (session == null) throw new ArgumentNullException(nameof(session));
m_session = session;
- BrowseCTRL.SetView(session, browseView, null);
- NodeListCTRL.Initialize(session, nodesIds, nodeClassMask);
-
+ await BrowseCTRL.SetViewAsync(session, browseView, null, ct);
+ await NodeListCTRL.InitializeAsync(session, nodesIds, nodeClassMask, ct);
+
if (ShowDialog() != DialogResult.OK)
{
return null;
}
-
+
return NodeListCTRL.GetNodeIds();
}
#endregion
-
+
#region Private Methods
#endregion
-
+
#region Event Handler
- private void BrowseCTRL_NodesSelected(object sender, NodesSelectedEventArgs e)
+ private async void BrowseCTRL_NodesSelectedAsync(object sender, NodesSelectedEventArgs e)
{
try
{
foreach (ReferenceDescription reference in e.References)
{
- NodeListCTRL.AddNodeId(reference);
- }
+ await NodeListCTRL.AddNodeIdAsync(reference);
+ }
}
catch (Exception exception)
{
diff --git a/Samples/Controls.Net4/SelectLocaleDlg.cs b/Samples/Controls.Net4/SelectLocaleDlg.cs
index a647bc8ff..75a2296df 100644
--- a/Samples/Controls.Net4/SelectLocaleDlg.cs
+++ b/Samples/Controls.Net4/SelectLocaleDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -33,6 +33,8 @@
using System.Text;
using Opc.Ua;
using Opc.Ua.Client;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -50,25 +52,25 @@ public SelectLocaleDlg()
InitializeComponent();
}
#endregion
-
+
#region Private Fields
private Session m_session;
#endregion
-
+
#region Public Interface
///
/// Displays the available areas in a tree view.
///
/// The session.
///
- public string ShowDialog(Session session)
+ public async Task ShowDialogAsync(Session session, CancellationToken ct = default)
{
m_session = session;
LocaleCB.Items.Clear();
// get the locales from the server.
- DataValue value = m_session.ReadValue(VariableIds.Server_ServerCapabilities_LocaleIdArray);
+ DataValue value = await m_session.ReadValueAsync(VariableIds.Server_ServerCapabilities_LocaleIdArray, ct);
if (value != null)
{
@@ -98,7 +100,7 @@ public string ShowDialog(Session session)
return LocaleCB.SelectedItem as string;
}
#endregion
-
+
#region Private Methods
#endregion
diff --git a/Samples/Controls.Net4/ServerForm.cs b/Samples/Controls.Net4/ServerForm.cs
index b6bc593f8..1e32aac94 100644
--- a/Samples/Controls.Net4/ServerForm.cs
+++ b/Samples/Controls.Net4/ServerForm.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -48,7 +48,7 @@ public ServerForm(StandardServer server, ApplicationConfiguration configuration)
{
InitializeComponent();
this.Icon = this.TrayIcon.Icon = ClientUtils.GetAppIcon();
-
+
GuiUtils.DisplayUaTcpImplementation(this, configuration);
m_server = server;
@@ -59,46 +59,46 @@ public ServerForm(StandardServer server, ApplicationConfiguration configuration)
}
}
#endregion
-
+
#region Private Fields
private bool m_exit;
private StandardServer m_server;
#endregion
-
+
#region Private Methods
///
/// Shows the diagnostics window and starts the update timer.
///
private void ShowStatus()
- {
+ {
this.WindowState = FormWindowState.Normal;
this.BringToFront();
Timer.Enabled = true;
}
-
+
///
/// Hides the diagnostics window and starts the update timer.
///
private void HideStatus()
- {
+ {
this.WindowState = FormWindowState.Minimized;
Timer.Enabled = false;
}
-
- ///
- /// Displays an unhandled exception.
- ///
- public static void HandleException(string caption, MethodBase method, Exception e)
- {
+
+ ///
+ /// Displays an unhandled exception.
+ ///
+ public static void HandleException(string caption, MethodBase method, Exception e)
+ {
if (String.IsNullOrEmpty(caption))
{
caption = method.Name;
}
- MessageBox.Show(e.Message, caption);
- }
+ MessageBox.Show(e.Message, caption);
+ }
#endregion
-
+
#region Event Handlers
///
/// Handles a certificate validation error.
@@ -111,7 +111,7 @@ void CertificateValidator_CertificateValidation(CertificateValidator validator,
}
catch (Exception exception)
{
- Opc.Ua.Client.Controls.GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ Opc.Ua.Client.Controls.GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -125,11 +125,11 @@ private void TrayIcon_DoubleClick(object sender, EventArgs e)
{
try
{
- ShowStatus();
+ ShowStatus();
}
catch (Exception exception)
{
- HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -141,11 +141,11 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
HideStatus();
- }
+ }
}
catch (Exception exception)
{
- HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -153,11 +153,11 @@ private void ShowMI_Click(object sender, EventArgs e)
{
try
{
- ShowStatus();
+ ShowStatus();
}
catch (Exception exception)
{
- HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -165,15 +165,17 @@ private void Timer_Tick(object sender, EventArgs e)
{
try
{
+#pragma warning disable CS0618 // Type or member is obsolete
ServerStatusDataType status = m_server.GetStatus();
+#pragma warning restore CS0618 // Type or member is obsolete
- StartTimeTB.Text = Utils.Format("{0:HH:mm:ss.ff}", status.StartTime.ToLocalTime());
+ StartTimeTB.Text = Utils.Format("{0:HH:mm:ss.ff}", status.StartTime.ToLocalTime());
CurrentTimeTB.Text = Utils.Format("{0:HH:mm:ss.ff}", status.CurrentTime.ToLocalTime());
ServerStateTB.Text = Utils.Format("{0}", status.State);
}
catch (Exception exception)
{
- HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Sessions/AddressSpaceDlg.cs b/Samples/Controls.Net4/Sessions/AddressSpaceDlg.cs
index 20c3cf450..38c963360 100644
--- a/Samples/Controls.Net4/Sessions/AddressSpaceDlg.cs
+++ b/Samples/Controls.Net4/Sessions/AddressSpaceDlg.cs
@@ -33,6 +33,7 @@
using System.Data;
using System.Drawing;
using System.Text;
+using System.Threading.Tasks;
using System.Windows.Forms;
using Opc.Ua.Client;
@@ -50,9 +51,9 @@ public AddressSpaceDlg()
m_SessionClosing = new EventHandler(Session_Closing);
}
#endregion
-
+
#region Private Fields
- private Session m_session;
+ private ISession m_session;
private EventHandler m_SessionClosing;
#endregion
@@ -61,23 +62,23 @@ public AddressSpaceDlg()
/// Displays the address space with the specified view
///
public void Show(Session session, BrowseViewType viewType, NodeId viewId)
- {
- if (session == null) throw new ArgumentNullException("session");
-
+ {
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
if (m_session != null)
{
m_session.SessionClosing -= m_SessionClosing;
}
- m_session = session;
+ m_session = session;
m_session.SessionClosing += m_SessionClosing;
-
- BrowseCTRL.SetView(session, viewType, viewId);
+
+ BrowseCTRL.SetViewAsync(session, viewType, viewId);
Show();
BringToFront();
}
#endregion
-
+
private void Session_Closing(object sender, EventArgs e)
{
if (Object.ReferenceEquals(sender, m_session))
diff --git a/Samples/Controls.Net4/Sessions/BrowseDlg.Designer.cs b/Samples/Controls.Net4/Sessions/BrowseDlg.Designer.cs
index 3412c0335..f84049abe 100644
--- a/Samples/Controls.Net4/Sessions/BrowseDlg.Designer.cs
+++ b/Samples/Controls.Net4/Sessions/BrowseDlg.Designer.cs
@@ -87,7 +87,7 @@ private void InitializeComponent()
this.BrowseCTRL.Size = new System.Drawing.Size(696, 372);
this.BrowseCTRL.TabIndex = 0;
this.BrowseCTRL.PositionChanged += new System.EventHandler(this.BrowseCTRL_PositionChanged);
- this.BrowseCTRL.PositionAdded += new System.EventHandler(this.BrowseCTRL_PositionAdded);
+ this.BrowseCTRL.PositionAdded += new System.EventHandler(this.BrowseCTRL_PositionAddedAsync);
//
// TopPN
//
@@ -111,7 +111,7 @@ private void InitializeComponent()
this.NodeCTRL.Name = "NodeCTRL";
this.NodeCTRL.Size = new System.Drawing.Size(642, 21);
this.NodeCTRL.TabIndex = 2;
- this.NodeCTRL.SelectedIndexChanged += new System.EventHandler(this.NodeCTRL_SelectedIndexChanged);
+ this.NodeCTRL.SelectedIndexChanged += new System.EventHandler(this.NodeCTRL_SelectedIndexChangedAsync);
//
// ForwardBTN
//
@@ -122,7 +122,7 @@ private void InitializeComponent()
this.ForwardBTN.TabIndex = 1;
this.ForwardBTN.Text = ">";
this.ForwardBTN.UseVisualStyleBackColor = true;
- this.ForwardBTN.Click += new System.EventHandler(this.ForwardBTN_Click);
+ this.ForwardBTN.Click += new System.EventHandler(this.ForwardBTN_ClickAsync);
//
// BackBTN
//
@@ -132,7 +132,7 @@ private void InitializeComponent()
this.BackBTN.TabIndex = 0;
this.BackBTN.Text = "<";
this.BackBTN.UseVisualStyleBackColor = true;
- this.BackBTN.Click += new System.EventHandler(this.BackBTN_Click);
+ this.BackBTN.Click += new System.EventHandler(this.BackBTN_ClickAsync);
//
// BrowseDlg
//
diff --git a/Samples/Controls.Net4/Sessions/BrowseDlg.cs b/Samples/Controls.Net4/Sessions/BrowseDlg.cs
index 4464c8f25..8ef105354 100644
--- a/Samples/Controls.Net4/Sessions/BrowseDlg.cs
+++ b/Samples/Controls.Net4/Sessions/BrowseDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -38,6 +38,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -51,7 +53,7 @@ public BrowseDlg()
m_SessionClosing = new EventHandler(Session_Closing);
}
#endregion
-
+
#region Private Fields
private Session m_session;
private EventHandler m_SessionClosing;
@@ -61,27 +63,27 @@ public BrowseDlg()
///
/// Displays the address space with the specified view
///
- public void Show(Session session, NodeId startId)
- {
- if (session == null) throw new ArgumentNullException("session");
-
+ public async Task ShowAsync(Session session, NodeId startId, CancellationToken ct = default)
+ {
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
if (m_session != null)
{
m_session.SessionClosing -= m_SessionClosing;
}
- m_session = session;
+ m_session = session;
m_session.SessionClosing += m_SessionClosing;
-
- Browser browser = new Browser(session);
+
+ Browser browser = new Browser(session);
browser.BrowseDirection = BrowseDirection.Both;
browser.ContinueUntilDone = true;
browser.ReferenceTypeId = ReferenceTypeIds.References;
- BrowseCTRL.Initialize(browser, startId);
-
- UpdateNavigationBar();
+ await BrowseCTRL.InitializeAsync(browser, startId, ct);
+
+ await UpdateNavigationBarAsync(ct);
Show();
BringToFront();
@@ -91,15 +93,15 @@ public void Show(Session session, NodeId startId)
///
/// Updates the navigation bar with the current positions in the browse control.
///
- private void UpdateNavigationBar()
+ private async Task UpdateNavigationBarAsync(CancellationToken ct = default)
{
int index = 0;
foreach (NodeId nodeId in BrowseCTRL.Positions)
{
- Node node = m_session.NodeCache.Find(nodeId) as Node;
+ Node node = await m_session.NodeCache.FindAsync(nodeId, ct) as Node;
- string displayText = m_session.NodeCache.GetDisplayText(node);
+ string displayText = await m_session.NodeCache.GetDisplayTextAsync(node, ct);
if (index < NodeCTRL.Items.Count)
{
@@ -114,16 +116,16 @@ private void UpdateNavigationBar()
}
index++;
- }
-
+ }
+
while (index < NodeCTRL.Items.Count)
{
- NodeCTRL.Items.RemoveAt(NodeCTRL.Items.Count-1);
+ NodeCTRL.Items.RemoveAt(NodeCTRL.Items.Count - 1);
}
-
+
NodeCTRL.SelectedIndex = BrowseCTRL.Position;
}
-
+
private void Session_Closing(object sender, EventArgs e)
{
if (Object.ReferenceEquals(sender, m_session))
@@ -143,44 +145,44 @@ private void AddressSpaceDlg_FormClosing(object sender, FormClosingEventArgs e)
}
}
- private void BackBTN_Click(object sender, EventArgs e)
+ private async void BackBTN_ClickAsync(object sender, EventArgs e)
{
try
- {
- BrowseCTRL.Back();
+ {
+ await BrowseCTRL.BackAsync();
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void ForwardBTN_Click(object sender, EventArgs e)
+ private async void ForwardBTN_ClickAsync(object sender, EventArgs e)
{
try
- {
- BrowseCTRL.Forward();
+ {
+ await BrowseCTRL.ForwardAsync();
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void NodeCTRL_SelectedIndexChanged(object sender, EventArgs e)
- {
+ private async void NodeCTRL_SelectedIndexChangedAsync(object sender, EventArgs e)
+ {
try
- {
- BrowseCTRL.SetPosition(NodeCTRL.SelectedIndex);
+ {
+ await BrowseCTRL.SetPositionAsync(NodeCTRL.SelectedIndex);
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
private void BrowseCTRL_PositionChanged(object sender, EventArgs e)
- {
+ {
try
{
if (BrowseCTRL.Position < NodeCTRL.Items.Count)
@@ -190,23 +192,23 @@ private void BrowseCTRL_PositionChanged(object sender, EventArgs e)
else
{
NodeCTRL.SelectedIndex = -1;
- }
+ }
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void BrowseCTRL_PositionAdded(object sender, EventArgs e)
+ private async void BrowseCTRL_PositionAddedAsync(object sender, EventArgs e)
{
try
{
- UpdateNavigationBar();
+ await UpdateNavigationBarAsync();
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
}
diff --git a/Samples/Controls.Net4/Sessions/BrowseListCtrl.cs b/Samples/Controls.Net4/Sessions/BrowseListCtrl.cs
index c1b879625..d8a600b6b 100644
--- a/Samples/Controls.Net4/Sessions/BrowseListCtrl.cs
+++ b/Samples/Controls.Net4/Sessions/BrowseListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -38,6 +38,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -49,18 +51,18 @@ public partial class BrowseListCtrl : Opc.Ua.Client.Controls.BaseListCtrl
///
public BrowseListCtrl()
{
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
ItemsLV.Sorting = SortOrder.Ascending;
m_stack = new List();
m_position = -1;
}
- #endregion
+ #endregion
#region Private Fields
- private Session m_session;
+ private ISession m_session;
private Browser m_browser;
private NodeId m_startId;
private List m_stack;
@@ -72,13 +74,13 @@ public BrowseListCtrl()
/// The columns to display in the control.
///
private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "ReferenceType", HorizontalAlignment.Left, null },
- new object[] { "Node", HorizontalAlignment.Left, null },
- new object[] { "Type", HorizontalAlignment.Left, null },
- new object[] { "Value", HorizontalAlignment.Left, null }
- };
- #endregion
+ {
+ new object[] { "ReferenceType", HorizontalAlignment.Left, null },
+ new object[] { "Node", HorizontalAlignment.Left, null },
+ new object[] { "Type", HorizontalAlignment.Left, null },
+ new object[] { "Value", HorizontalAlignment.Left, null }
+ };
+ #endregion
#region Public Interface
///
@@ -105,8 +107,8 @@ public event EventHandler PositionAdded
[DefaultValue(-1)]
public int Position
{
- get { return m_position+1; }
- set { SetPosition(value-1); }
+ get { return m_position + 1; }
+ set { SetPositionAsync(value - 1).GetAwaiter().GetResult(); }
}
///
@@ -115,7 +117,7 @@ public int Position
public ICollection Positions
{
get
- {
+ {
List positions = new List();
positions.Add(m_startId);
@@ -141,49 +143,49 @@ public void Clear()
///
/// Initializes the control with the session/subscription indicated.
///
- public void Initialize(Browser browser, NodeId startId)
+ public async Task InitializeAsync(Browser browser, NodeId startId, CancellationToken ct = default)
{
m_browser = null;
m_session = null;
-
+
Clear();
// nothing to do if no browser provided.
if (browser == null)
{
return;
- }
-
- m_browser = browser;
- m_session = browser.Session as Session;
- m_startId = startId;
+ }
+
+ m_browser = browser;
+ m_session = browser.Session as Session;
+ m_startId = startId;
m_position = -1;
-
+
m_stack.Clear();
- Browse(startId);
+ await BrowseAsync(startId, ct);
}
///
/// Moves to the previous position.
///
- public void Back()
+ public async Task BackAsync(CancellationToken ct = default)
{
- SetPosition(m_position);
+ await SetPositionAsync(m_position, ct);
}
///
/// Moves to the next position.
///
- public void Forward()
+ public async Task ForwardAsync(CancellationToken ct = default)
{
- SetPosition(m_position+2);
+ await SetPositionAsync(m_position + 2, ct);
}
///
/// Sets the current position.
///
- public void SetPosition(int position)
+ public async Task SetPositionAsync(int position, CancellationToken ct = default)
{
position--;
@@ -194,23 +196,23 @@ public void SetPosition(int position)
if (position >= m_stack.Count)
{
- position = m_stack.Count-1;
+ position = m_stack.Count - 1;
}
if (m_position == position)
{
return;
}
-
+
m_position = position;
-
+
if (m_position == -1)
{
- Browse(m_startId);
- }
+ await BrowseAsync(m_startId, ct);
+ }
else
{
- Browse(m_stack[m_position].Target.NodeId);
+ await BrowseAsync(m_stack[m_position].Target.NodeId, ct);
}
if (m_PositionChanged != null)
@@ -222,44 +224,44 @@ public void SetPosition(int position)
///
/// Displays the target of a browse operation in the control.
///
- private void Browse(NodeId startId)
+ private async Task BrowseAsync(NodeId startId, CancellationToken ct = default)
{
if (m_browser == null || NodeId.IsNull(startId))
- {
+ {
Clear();
return;
}
-
+
List variables = new List();
-
+
// browse the references from the node and build list of variables.
BeginUpdate();
- foreach (ReferenceDescription reference in m_browser.Browse(startId))
+ foreach (ReferenceDescription reference in await m_browser.BrowseAsync(startId, ct))
{
- Node target = m_session.NodeCache.Find(reference.NodeId) as Node;
+ Node target = await m_session.NodeCache.FindAsync(reference.NodeId, ct) as Node;
if (target == null)
{
continue;
}
- ReferenceTypeNode referenceType = m_session.NodeCache.Find(reference.ReferenceTypeId) as ReferenceTypeNode;
+ ReferenceTypeNode referenceType = await m_session.NodeCache.FindAsync(reference.ReferenceTypeId, ct) as ReferenceTypeNode;
Node typeDefinition = null;
if ((target.NodeClass & (NodeClass.Variable | NodeClass.Object)) != 0)
{
- typeDefinition = m_session.NodeCache.Find(reference.TypeDefinition) as Node;
+ typeDefinition = await m_session.NodeCache.FindAsync(reference.TypeDefinition, ct) as Node;
}
else
{
- typeDefinition = m_session.NodeCache.Find(m_session.NodeCache.TypeTree.FindSuperType(target.NodeId)) as Node;
+ typeDefinition = await m_session.NodeCache.FindAsync(await m_session.NodeCache.TypeTree.FindSuperTypeAsync(target.NodeId, ct), ct) as Node;
}
ItemData item = new ItemData(referenceType, !reference.IsForward, target, typeDefinition);
- AddItem(item, GuiUtils.GetTargetIcon(m_browser.Session as Session, reference), -1);
-
+ AddItem(item, await GuiUtils.GetTargetIconAsync(m_browser.Session as Session, reference, ct), -1);
+
if ((target.NodeClass & (NodeClass.Variable | NodeClass.VariableType)) != 0)
{
variables.Add(item);
@@ -272,42 +274,41 @@ private void Browse(NodeId startId)
if (variables.Count > 0)
{
ReadValueIdCollection nodesToRead = new ReadValueIdCollection();
-
+
foreach (ItemData item in variables)
{
ReadValueId valueId = new ReadValueId();
- valueId.NodeId = item.Target.NodeId;
- valueId.AttributeId = Attributes.Value;
- valueId.IndexRange = null;
+ valueId.NodeId = item.Target.NodeId;
+ valueId.AttributeId = Attributes.Value;
+ valueId.IndexRange = null;
valueId.DataEncoding = null;
nodesToRead.Add(valueId);
}
-
- DataValueCollection values;
- DiagnosticInfoCollection diagnosticInfos;
- m_session.Read(
+ ReadResponse response = await m_session.ReadAsync(
null,
0,
TimestampsToReturn.Neither,
nodesToRead,
- out values,
- out diagnosticInfos);
+ ct);
+
+ DataValueCollection values = response.Results;
+ DiagnosticInfoCollection diagnosticInfos = response.DiagnosticInfos;
ClientBase.ValidateResponse(values, nodesToRead);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
-
+
for (int ii = 0; ii < variables.Count; ii++)
{
variables[ii].Value = values[ii];
-
+
foreach (ListViewItem item in ItemsLV.Items)
{
if (Object.ReferenceEquals(item.Tag, variables[ii]))
{
- UpdateItem(item, variables[ii]);
+ await UpdateItemAsync(item, variables[ii], ct);
break;
}
}
@@ -317,12 +318,12 @@ private void Browse(NodeId startId)
AdjustColumns();
}
#endregion
-
+
#region ItemData Class
///
/// Stores the data associated with a list view item.
///
- private class ItemData : IComparable
+ private sealed class ItemData : IComparable
{
public ReferenceTypeNode ReferenceType;
public bool IsInverse;
@@ -330,12 +331,12 @@ private class ItemData : IComparable
public Node TypeDefinition;
public DataValue Value;
public string SortKey;
-
+
public ItemData(ReferenceTypeNode referenceType, bool isInverse, Node target, Node typeDefinition)
{
- ReferenceType = referenceType;
- IsInverse = isInverse;
- Target = target;
+ ReferenceType = referenceType;
+ IsInverse = isInverse;
+ Target = target;
TypeDefinition = typeDefinition;
}
@@ -366,92 +367,99 @@ public int CompareTo(object obj)
#region Overridden Methods
///
protected override void EnableMenuItems(ListViewItem clickedItem)
- {
+ {
// TBD
- }
+ }
///
/// Handles a double click.
///
- protected override void PickItems()
+ protected override async void PickItems()
{
- if (ItemsLV.SelectedItems.Count <= 0)
+ try
{
- return;
- }
+ if (ItemsLV.SelectedItems.Count <= 0)
+ {
+ return;
+ }
- ItemData itemData = ItemsLV.SelectedItems[0].Tag as ItemData;
-
- if (itemData == null)
- {
- return;
- }
+ ItemData itemData = ItemsLV.SelectedItems[0].Tag as ItemData;
- base.PickItems();
-
- if (m_position >= 0 && m_position < m_stack.Count-1)
- {
- m_stack.RemoveRange(m_position, m_stack.Count-m_position);
- }
- else if (m_position == -1)
- {
- m_stack.Clear();
- }
-
- m_position++;
- m_stack.Add(itemData);
+ if (itemData == null)
+ {
+ return;
+ }
+
+ base.PickItems();
+
+ if (m_position >= 0 && m_position < m_stack.Count - 1)
+ {
+ m_stack.RemoveRange(m_position, m_stack.Count - m_position);
+ }
+ else if (m_position == -1)
+ {
+ m_stack.Clear();
+ }
+
+ m_position++;
+ m_stack.Add(itemData);
- if (m_PositionAdded != null)
+ if (m_PositionAdded != null)
+ {
+ m_PositionAdded(this, null);
+ }
+
+ await BrowseAsync(itemData.Target.NodeId);
+ }
+ catch (Exception exception)
{
- m_PositionAdded(this, null);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
-
- Browse(itemData.Target.NodeId);
}
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
{
ItemData itemData = item as ItemData;
- if (itemData == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
+ if (itemData == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
if (itemData.ReferenceType != null)
{
if (itemData.IsInverse)
{
- listItem.SubItems[0].Text = String.Format("{0}", itemData.ReferenceType.InverseName);
+ listItem.SubItems[0].Text = String.Format("{0}", itemData.ReferenceType.InverseName);
}
else
{
- listItem.SubItems[0].Text = String.Format("{0}", itemData.ReferenceType.DisplayName);
+ listItem.SubItems[0].Text = String.Format("{0}", itemData.ReferenceType.DisplayName);
}
}
else
{
listItem.SubItems[0].Text = "(unknown)";
}
-
- listItem.SubItems[1].Text = String.Format("{0}", itemData.Target);
- listItem.SubItems[2].Text = String.Format("{0}", itemData.TypeDefinition);
+
+ listItem.SubItems[1].Text = String.Format("{0}", itemData.Target);
+ listItem.SubItems[2].Text = String.Format("{0}", itemData.TypeDefinition);
if (itemData.Value != null)
{
- listItem.SubItems[3].Text = String.Format("{0}", itemData.Value);
+ listItem.SubItems[3].Text = String.Format("{0}", itemData.Value);
}
else
{
- listItem.SubItems[3].Text = String.Empty;
+ listItem.SubItems[3].Text = String.Empty;
}
-
+
itemData.SortKey = String.Format("{0}{1}", listItem.SubItems[0].Text, listItem.SubItems[1].Text);
- listItem.Tag = item;
+ listItem.Tag = item;
}
- #endregion
+ #endregion
}
}
diff --git a/Samples/Controls.Net4/Sessions/BrowseOptionsDlg.Designer.cs b/Samples/Controls.Net4/Sessions/BrowseOptionsDlg.Designer.cs
index f43a25348..5d380aca1 100644
--- a/Samples/Controls.Net4/Sessions/BrowseOptionsDlg.Designer.cs
+++ b/Samples/Controls.Net4/Sessions/BrowseOptionsDlg.Designer.cs
@@ -223,7 +223,7 @@ private void InitializeComponent()
this.BrowseBTN.TabIndex = 17;
this.BrowseBTN.Text = "...";
this.BrowseBTN.UseVisualStyleBackColor = true;
- this.BrowseBTN.Click += new System.EventHandler(this.BrowseBTN_Click);
+ this.BrowseBTN.Click += new System.EventHandler(this.BrowseBTN_ClickAsync);
//
// ViewIdTB
//
diff --git a/Samples/Controls.Net4/Sessions/BrowseOptionsDlg.cs b/Samples/Controls.Net4/Sessions/BrowseOptionsDlg.cs
index 0c09b46cd..e8ce9b04c 100644
--- a/Samples/Controls.Net4/Sessions/BrowseOptionsDlg.cs
+++ b/Samples/Controls.Net4/Sessions/BrowseOptionsDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -38,6 +38,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -57,44 +59,44 @@ public BrowseOptionsDlg()
BrowseDirectionCB.SelectedIndex = 0;
}
#endregion
-
+
#region Private Fields
private Browser m_browser;
#endregion
-
+
#region Public Interface
///
/// Prompts the user to specify the browse options.
///
- public bool ShowDialog(Browser browser)
+ public async Task ShowDialogAsync(Browser browser, CancellationToken ct = default)
{
- if (browser == null) throw new ArgumentNullException("browser");
+ if (browser == null) throw new ArgumentNullException(nameof(browser));
m_browser = browser;
- ReferenceTypeCTRL.Initialize(m_browser.Session as Session, null);
+ await ReferenceTypeCTRL.InitializeAsync(m_browser.Session as Session, null, ct);
- ViewIdTB.Text = null;
+ ViewIdTB.Text = null;
ViewTimestampDP.Value = ViewTimestampDP.MinDate;
- ViewVersionNC.Value = 0;
+ ViewVersionNC.Value = 0;
if (browser.View != null)
{
- ViewIdTB.Text = String.Format("{0}", browser.View.ViewId);
- ViewVersionNC.Value = browser.View.ViewVersion;
+ ViewIdTB.Text = String.Format("{0}", browser.View.ViewId);
+ ViewVersionNC.Value = browser.View.ViewVersion;
ViewVersionCK.Checked = browser.View.ViewVersion != 0;
if (browser.View.Timestamp > ViewTimestampDP.MinDate)
- {
- ViewTimestampDP.Value = browser.View.Timestamp ;
+ {
+ ViewTimestampDP.Value = browser.View.Timestamp;
ViewTimestampCK.Checked = true;
}
}
- MaxReferencesReturnedNC.Value = browser.MaxReferencesReturned;
- BrowseDirectionCB.SelectedItem = browser.BrowseDirection;
+ MaxReferencesReturnedNC.Value = browser.MaxReferencesReturned;
+ BrowseDirectionCB.SelectedItem = browser.BrowseDirection;
ReferenceTypeCTRL.SelectedTypeId = browser.ReferenceTypeId;
- IncludeSubtypesCK.Checked = browser.IncludeSubtypes;
- NodeClassMaskCK.Checked = browser.NodeClassMask != 0;
+ IncludeSubtypesCK.Checked = browser.IncludeSubtypes;
+ NodeClassMaskCK.Checked = browser.NodeClassMask != 0;
NodeClassList.Items.Clear();
@@ -117,7 +119,7 @@ public bool ShowDialog(Browser browser)
return true;
}
#endregion
-
+
#region Event Handlers
private void ViewIdTB_TextChanged(object sender, EventArgs e)
{
@@ -125,8 +127,8 @@ private void ViewIdTB_TextChanged(object sender, EventArgs e)
}
private void NodeClassMask_CheckedChanged(object sender, EventArgs e)
- {
- NodeClassList.Enabled = NodeClassMaskCK.Checked;
+ {
+ NodeClassList.Enabled = NodeClassMaskCK.Checked;
}
private void ViewVersionCK_CheckedChanged(object sender, EventArgs e)
@@ -139,24 +141,24 @@ private void ViewTimestampCK_CheckedChanged(object sender, EventArgs e)
ViewTimestampDP.Enabled = ViewTimestampCK.Checked;
}
- private void BrowseBTN_Click(object sender, EventArgs e)
+ private async void BrowseBTN_ClickAsync(object sender, EventArgs e)
{
try
{
Browser browser = new Browser(m_browser.Session);
browser.BrowseDirection = BrowseDirection.Forward;
- browser.NodeClassMask = (int)NodeClass.View | (int)NodeClass.Object;
+ browser.NodeClassMask = (int)NodeClass.View | (int)NodeClass.Object;
browser.ReferenceTypeId = ReferenceTypeIds.Organizes;
browser.IncludeSubtypes = true;
- ReferenceDescription reference = new SelectNodeDlg().ShowDialog(browser, Objects.ViewsFolder);
+ ReferenceDescription reference = await new SelectNodeDlg().ShowDialogAsync(browser, Objects.ViewsFolder);
if (reference != null)
{
if (reference.NodeClass != NodeClass.View)
{
- MessageBox.Show("Please select a valid view node id.", this.Text);
+ MessageBox.Show("Please select a valid view node id.", this.Text);
return;
}
@@ -165,7 +167,7 @@ private void BrowseBTN_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -179,9 +181,9 @@ private void OkBTN_Click(object sender, EventArgs e)
}
catch (Exception)
{
- MessageBox.Show("Please enter a valid node id for the view id.", this.Text);
+ MessageBox.Show("Please enter a valid node id for the view id.", this.Text);
}
-
+
try
{
ViewDescription view = null;
@@ -190,28 +192,28 @@ private void OkBTN_Click(object sender, EventArgs e)
{
view = new ViewDescription();
- view.ViewId = viewId;
- view.Timestamp = DateTime.MinValue;
+ view.ViewId = viewId;
+ view.Timestamp = DateTime.MinValue;
view.ViewVersion = 0;
if (ViewTimestampCK.Checked && ViewTimestampDP.Value > ViewTimestampDP.MinDate)
{
view.Timestamp = ViewTimestampDP.Value;
}
-
+
if (ViewVersionCK.Checked)
{
view.ViewVersion = (uint)ViewVersionNC.Value;
}
}
- m_browser.View = view;
+ m_browser.View = view;
m_browser.MaxReferencesReturned = (uint)MaxReferencesReturnedNC.Value;
- m_browser.BrowseDirection = (BrowseDirection)BrowseDirectionCB.SelectedItem;
- m_browser.NodeClassMask = (int)NodeClass.View | (int)NodeClass.Object;
- m_browser.ReferenceTypeId = ReferenceTypeCTRL.SelectedTypeId;
- m_browser.IncludeSubtypes = IncludeSubtypesCK.Checked;
- m_browser.NodeClassMask = 0;
+ m_browser.BrowseDirection = (BrowseDirection)BrowseDirectionCB.SelectedItem;
+ m_browser.NodeClassMask = (int)NodeClass.View | (int)NodeClass.Object;
+ m_browser.ReferenceTypeId = ReferenceTypeCTRL.SelectedTypeId;
+ m_browser.IncludeSubtypes = IncludeSubtypesCK.Checked;
+ m_browser.NodeClassMask = 0;
int nodeClassMask = 0;
@@ -221,12 +223,12 @@ private void OkBTN_Click(object sender, EventArgs e)
}
m_browser.NodeClassMask = nodeClassMask;
-
+
DialogResult = DialogResult.OK;
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Sessions/BrowseTreeCtrl.Designer.cs b/Samples/Controls.Net4/Sessions/BrowseTreeCtrl.Designer.cs
index d73d929a0..182efa590 100644
--- a/Samples/Controls.Net4/Sessions/BrowseTreeCtrl.Designer.cs
+++ b/Samples/Controls.Net4/Sessions/BrowseTreeCtrl.Designer.cs
@@ -68,7 +68,6 @@ private void InitializeComponent()
this.HistoryReadMI = new System.Windows.Forms.ToolStripMenuItem();
this.WriteMI = new System.Windows.Forms.ToolStripMenuItem();
this.HistoryUpdateMI = new System.Windows.Forms.ToolStripMenuItem();
- this.EncodingsMI = new System.Windows.Forms.ToolStripMenuItem();
this.SubscribeMI = new System.Windows.Forms.ToolStripMenuItem();
this.SubscribeNewMI = new System.Windows.Forms.ToolStripMenuItem();
this.CallMI = new System.Windows.Forms.ToolStripMenuItem();
@@ -85,9 +84,11 @@ private void InitializeComponent()
//
this.NodesTV.ContextMenuStrip = this.PopupMenu;
this.NodesTV.LineColor = System.Drawing.Color.Black;
+ this.NodesTV.Size = new System.Drawing.Size(896, 733);
//
// PopupMenu
//
+ this.PopupMenu.ImageScalingSize = new System.Drawing.Size(28, 28);
this.PopupMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.BrowseOptionsMI,
this.ShowReferencesMI,
@@ -98,7 +99,6 @@ private void InitializeComponent()
this.HistoryReadMI,
this.WriteMI,
this.HistoryUpdateMI,
- this.EncodingsMI,
this.SubscribeMI,
this.CallMI,
this.Separator02,
@@ -106,14 +106,14 @@ private void InitializeComponent()
this.SelectSeparatorMI,
this.BrowseRefreshMI});
this.PopupMenu.Name = "PopupMenu";
- this.PopupMenu.Size = new System.Drawing.Size(162, 330);
+ this.PopupMenu.Size = new System.Drawing.Size(271, 492);
//
// BrowseOptionsMI
//
this.BrowseOptionsMI.Name = "BrowseOptionsMI";
- this.BrowseOptionsMI.Size = new System.Drawing.Size(161, 22);
+ this.BrowseOptionsMI.Size = new System.Drawing.Size(270, 36);
this.BrowseOptionsMI.Text = "Browse Options...";
- this.BrowseOptionsMI.Click += new System.EventHandler(this.BrowseOptionsMI_Click);
+ this.BrowseOptionsMI.Click += new System.EventHandler(this.BrowseOptionsMI_ClickAsync);
//
// ShowReferencesMI
//
@@ -121,89 +121,82 @@ private void InitializeComponent()
this.ShowReferencesMI.CheckOnClick = true;
this.ShowReferencesMI.CheckState = System.Windows.Forms.CheckState.Checked;
this.ShowReferencesMI.Name = "ShowReferencesMI";
- this.ShowReferencesMI.Size = new System.Drawing.Size(161, 22);
+ this.ShowReferencesMI.Size = new System.Drawing.Size(270, 36);
this.ShowReferencesMI.Text = "Show References";
- this.ShowReferencesMI.CheckedChanged += new System.EventHandler(this.ShowReferencesMI_CheckedChanged);
+ this.ShowReferencesMI.CheckedChanged += new System.EventHandler(this.ShowReferencesMI_CheckedChangedAsync);
//
// Separator01
//
this.Separator01.Name = "Separator01";
- this.Separator01.Size = new System.Drawing.Size(158, 6);
+ this.Separator01.Size = new System.Drawing.Size(267, 6);
//
// BrowseMI
//
this.BrowseMI.Name = "BrowseMI";
- this.BrowseMI.Size = new System.Drawing.Size(161, 22);
+ this.BrowseMI.Size = new System.Drawing.Size(270, 36);
this.BrowseMI.Text = "Browse...";
- this.BrowseMI.Click += new System.EventHandler(this.BrowseMI_Click);
+ this.BrowseMI.Click += new System.EventHandler(this.BrowseMI_ClickAsync);
//
// ViewAttributesMI
//
this.ViewAttributesMI.Name = "ViewAttributesMI";
- this.ViewAttributesMI.Size = new System.Drawing.Size(161, 22);
+ this.ViewAttributesMI.Size = new System.Drawing.Size(270, 36);
this.ViewAttributesMI.Text = "View Attributes...";
- this.ViewAttributesMI.Click += new System.EventHandler(this.ViewAttributesMI_Click);
+ this.ViewAttributesMI.Click += new System.EventHandler(this.ViewAttributesMI_ClickAsync);
//
// ReadMI
//
this.ReadMI.Name = "ReadMI";
- this.ReadMI.Size = new System.Drawing.Size(161, 22);
+ this.ReadMI.Size = new System.Drawing.Size(270, 36);
this.ReadMI.Text = "Read..";
- this.ReadMI.Click += new System.EventHandler(this.ReadMI_Click);
+ this.ReadMI.Click += new System.EventHandler(this.ReadMI_ClickAsync);
//
// HistoryReadMI
//
this.HistoryReadMI.Name = "HistoryReadMI";
- this.HistoryReadMI.Size = new System.Drawing.Size(161, 22);
+ this.HistoryReadMI.Size = new System.Drawing.Size(270, 36);
this.HistoryReadMI.Text = "History Read...";
- this.HistoryReadMI.Click += new System.EventHandler(this.HistoryReadMI_Click);
+ this.HistoryReadMI.Click += new System.EventHandler(this.HistoryReadMI_ClickAsync);
//
// WriteMI
//
this.WriteMI.Name = "WriteMI";
- this.WriteMI.Size = new System.Drawing.Size(161, 22);
+ this.WriteMI.Size = new System.Drawing.Size(270, 36);
this.WriteMI.Text = "Write...";
- this.WriteMI.Click += new System.EventHandler(this.WriteMI_Click);
+ this.WriteMI.Click += new System.EventHandler(this.WriteMI_ClickAsync);
//
// HistoryUpdateMI
//
this.HistoryUpdateMI.Name = "HistoryUpdateMI";
- this.HistoryUpdateMI.Size = new System.Drawing.Size(161, 22);
+ this.HistoryUpdateMI.Size = new System.Drawing.Size(270, 36);
this.HistoryUpdateMI.Text = "History Update...";
//
- // EncodingsMI
- //
- this.EncodingsMI.Name = "EncodingsMI";
- this.EncodingsMI.Size = new System.Drawing.Size(161, 22);
- this.EncodingsMI.Text = "View Encodings...";
- this.EncodingsMI.Click += new System.EventHandler(this.EncodingsMI_Click);
- //
// SubscribeMI
//
this.SubscribeMI.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SubscribeNewMI});
this.SubscribeMI.Name = "SubscribeMI";
- this.SubscribeMI.Size = new System.Drawing.Size(161, 22);
+ this.SubscribeMI.Size = new System.Drawing.Size(270, 36);
this.SubscribeMI.Text = "Subscribe";
//
// SubscribeNewMI
//
this.SubscribeNewMI.Name = "SubscribeNewMI";
- this.SubscribeNewMI.Size = new System.Drawing.Size(152, 22);
+ this.SubscribeNewMI.Size = new System.Drawing.Size(315, 40);
this.SubscribeNewMI.Text = "New...";
- this.SubscribeNewMI.Click += new System.EventHandler(this.SubscribeNewMI_Click);
+ this.SubscribeNewMI.Click += new System.EventHandler(this.SubscribeNewMI_ClickAsync);
//
// CallMI
//
this.CallMI.Name = "CallMI";
- this.CallMI.Size = new System.Drawing.Size(161, 22);
+ this.CallMI.Size = new System.Drawing.Size(270, 36);
this.CallMI.Text = "Call...";
- this.CallMI.Click += new System.EventHandler(this.CallMI_Click);
+ this.CallMI.Click += new System.EventHandler(this.CallMI_ClickAsync);
//
// Separator02
//
this.Separator02.Name = "Separator02";
- this.Separator02.Size = new System.Drawing.Size(158, 6);
+ this.Separator02.Size = new System.Drawing.Size(267, 6);
//
// SelectMI
//
@@ -211,38 +204,39 @@ private void InitializeComponent()
this.SelectItemMI,
this.SelectChildrenMI});
this.SelectMI.Name = "SelectMI";
- this.SelectMI.Size = new System.Drawing.Size(161, 22);
+ this.SelectMI.Size = new System.Drawing.Size(270, 36);
this.SelectMI.Text = "Select";
//
// SelectItemMI
//
this.SelectItemMI.Name = "SelectItemMI";
- this.SelectItemMI.Size = new System.Drawing.Size(145, 22);
+ this.SelectItemMI.Size = new System.Drawing.Size(269, 40);
this.SelectItemMI.Text = "Select Item";
this.SelectItemMI.Click += new System.EventHandler(this.SelectItemMI_Click);
//
// SelectChildrenMI
//
this.SelectChildrenMI.Name = "SelectChildrenMI";
- this.SelectChildrenMI.Size = new System.Drawing.Size(145, 22);
+ this.SelectChildrenMI.Size = new System.Drawing.Size(269, 40);
this.SelectChildrenMI.Text = "Select Children";
this.SelectChildrenMI.Click += new System.EventHandler(this.SelectChildrenMI_Click);
//
// SelectSeparatorMI
//
this.SelectSeparatorMI.Name = "SelectSeparatorMI";
- this.SelectSeparatorMI.Size = new System.Drawing.Size(158, 6);
+ this.SelectSeparatorMI.Size = new System.Drawing.Size(267, 6);
//
// BrowseRefreshMI
//
this.BrowseRefreshMI.Name = "BrowseRefreshMI";
- this.BrowseRefreshMI.Size = new System.Drawing.Size(161, 22);
+ this.BrowseRefreshMI.Size = new System.Drawing.Size(270, 36);
this.BrowseRefreshMI.Text = "Refresh";
- this.BrowseRefreshMI.Click += new System.EventHandler(this.BrowseRefreshMI_Click);
+ this.BrowseRefreshMI.Click += new System.EventHandler(this.BrowseRefreshMI_ClickAsync);
//
// BrowseTreeCtrl
//
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F);
+ this.Margin = new System.Windows.Forms.Padding(11, 11, 11, 11);
this.Name = "BrowseTreeCtrl";
this.Controls.SetChildIndex(this.NodesTV, 0);
this.PopupMenu.ResumeLayout(false);
@@ -268,7 +262,6 @@ private void InitializeComponent()
private System.Windows.Forms.ToolStripMenuItem WriteMI;
private System.Windows.Forms.ToolStripMenuItem ReadMI;
private System.Windows.Forms.ToolStripMenuItem SubscribeNewMI;
- private System.Windows.Forms.ToolStripMenuItem EncodingsMI;
private System.Windows.Forms.ToolStripMenuItem HistoryReadMI;
private System.Windows.Forms.ToolStripMenuItem HistoryUpdateMI;
private System.Windows.Forms.ToolStripMenuItem BrowseMI;
diff --git a/Samples/Controls.Net4/Sessions/BrowseTreeCtrl.cs b/Samples/Controls.Net4/Sessions/BrowseTreeCtrl.cs
index b6a0ddabd..a67db1246 100644
--- a/Samples/Controls.Net4/Sessions/BrowseTreeCtrl.cs
+++ b/Samples/Controls.Net4/Sessions/BrowseTreeCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -38,6 +38,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -48,7 +50,7 @@ public BrowseTreeCtrl()
{
InitializeComponent();
m_references = new ReferenceDescriptionCollection();
- m_BrowserMoreReferences = new BrowserEventHandler(Browser_MoreReferences);
+ m_BrowserMoreReferences = new BrowserEventHandler(Browser_MoreReferencesAsync);
}
#endregion
@@ -66,14 +68,14 @@ public BrowseTreeCtrl()
private BrowserEventHandler m_BrowserMoreReferences;
private SessionTreeCtrl m_SessionTreeCtrl;
#endregion
-
+
#region Public Interface
///
/// The control used to display the address space for a session.
///
public SessionTreeCtrl SessionTreeCtrl
{
- get { return m_SessionTreeCtrl; }
+ get { return m_SessionTreeCtrl; }
set { m_SessionTreeCtrl = value; }
}
@@ -83,32 +85,32 @@ public SessionTreeCtrl SessionTreeCtrl
[DefaultValue(false)]
public bool AllowPick
{
- get { return m_allowPick; }
+ get { return m_allowPick; }
set { m_allowPick = value; }
}
-
+
///
/// Whether references should be displayed in the control.
///
[DefaultValue(false)]
public bool ShowReferences
{
- get { return m_showReferences; }
+ get { return m_showReferences; }
set { m_showReferences = value; }
}
-
+
///
/// Whether references should be displayed in the control.
///
public ReferenceDescriptionCollection SelectedReferences
{
- get
- {
+ get
+ {
return m_references;
}
- set
- {
+ set
+ {
m_references = value;
if (m_references == null)
@@ -123,16 +125,16 @@ public ReferenceDescriptionCollection SelectedReferences
///
public AttributeListCtrl AttributesCtrl
{
- get { return m_AttributesCtrl; }
+ get { return m_AttributesCtrl; }
set { m_AttributesCtrl = value; }
}
-
+
///
/// Raised when nodes are selected in the control.
///
public event NodesSelectedEventHandler ItemsSelected
{
- add { m_ItemsSelected += value; }
+ add { m_ItemsSelected += value; }
remove { m_ItemsSelected -= value; }
}
@@ -141,7 +143,7 @@ public event NodesSelectedEventHandler ItemsSelected
///
public event MethodCalledEventHandler MethodCalled
{
- add { m_MethodCalled += value; }
+ add { m_MethodCalled += value; }
remove { m_MethodCalled -= value; }
}
@@ -161,13 +163,13 @@ public void Clear()
///
/// Sets the root node for the control.
///
- public void SetRoot(Browser browser, NodeId rootId)
- {
+ public async Task SetRootAsync(Browser browser, NodeId rootId, CancellationToken ct = default)
+ {
Clear();
-
+
ShowReferencesMI.Checked = m_showReferences;
-
- m_rootId = rootId;
+
+ m_rootId = rootId;
m_browser = browser;
if (m_browser != null)
@@ -188,7 +190,7 @@ public void SetRoot(Browser browser, NodeId rootId)
if (m_browser != null)
{
- INode node = m_browser.Session.NodeCache.Find(m_rootId);
+ INode node = await m_browser.Session.NodeCache.FindAsync(m_rootId, ct);
if (node == null)
{
@@ -196,53 +198,53 @@ public void SetRoot(Browser browser, NodeId rootId)
}
ReferenceDescription reference = new ReferenceDescription();
-
+
reference.ReferenceTypeId = ReferenceTypeIds.References;
- reference.IsForward = true;
- reference.NodeId = node.NodeId;
- reference.NodeClass = (NodeClass)node.NodeClass;
- reference.BrowseName = node.BrowseName;
- reference.DisplayName = node.DisplayName;
- reference.TypeDefinition = null;
-
+ reference.IsForward = true;
+ reference.NodeId = node.NodeId;
+ reference.NodeClass = (NodeClass)node.NodeClass;
+ reference.BrowseName = node.BrowseName;
+ reference.DisplayName = node.DisplayName;
+ reference.TypeDefinition = null;
+
string text = GetTargetText(reference);
- string icon = GuiUtils.GetTargetIcon(m_browser.Session as Session, reference);
+ string icon = await GuiUtils.GetTargetIconAsync(m_browser.Session as Session, reference, ct);
TreeNode root = AddNode(null, reference, text, icon);
root.Nodes.Add(new TreeNode());
root.Expand();
}
}
-
+
///
/// Sets the root node for the control.
///
- public void SetRoot(Session session, NodeId rootId)
+ public Task SetRootAsync(Session session, NodeId rootId, CancellationToken ct = default)
{
- SetRoot(new Browser(session), rootId);
+ return SetRootAsync(new Browser(session), rootId, ct);
}
///
/// Sets the view for the control.
///
- public void SetView(Session session, BrowseViewType viewType, NodeId viewId)
- {
+ public Task SetViewAsync(Session session, BrowseViewType viewType, NodeId viewId, CancellationToken ct = default)
+ {
Clear();
// check if session is connected.
if (session == null || !session.Connected)
{
- return;
+ return Task.CompletedTask;
}
Browser browser = new Browser(session);
- browser.BrowseDirection = BrowseDirection.Forward;
- browser.ReferenceTypeId = null;
- browser.IncludeSubtypes = true;
- browser.NodeClassMask = 0;
+ browser.BrowseDirection = BrowseDirection.Forward;
+ browser.ReferenceTypeId = null;
+ browser.IncludeSubtypes = true;
+ browser.NodeClassMask = 0;
browser.ContinueUntilDone = false;
-
+
NodeId rootId = Objects.RootFolder;
ShowReferences = false;
@@ -305,8 +307,8 @@ public void SetView(Session session, BrowseViewType viewType, NodeId viewId)
break;
}
}
-
- SetRoot(browser, rootId);
+
+ return SetRootAsync(browser, rootId, ct);
}
///
@@ -317,249 +319,249 @@ public NodeId RootId
get { return m_rootId; }
}
#endregion
-
+
#region Overridden Members
- ///
- protected override bool BeforeExpand(TreeNode clickedNode)
+ ///
+ protected override Task BeforeExpandAsync(TreeNode clickedNode, CancellationToken ct = default)
{
// check if a placeholder child is present.
if (clickedNode.Nodes.Count == 1 && clickedNode.Nodes[0].Text == String.Empty)
{
// clear dummy children.
clickedNode.Nodes.Clear();
-
+
// do nothing if an error is detected.
if (m_browser.Session.KeepAliveStopped)
{
- return false;
+ return Task.FromResult(false);
}
// browse.
- return Browse(clickedNode);
+ return BrowseAsync(clickedNode, ct);
}
// do not cancel expand.
- return false;
+ return Task.FromResult(false);
}
///
- protected override void EnableMenuItems(TreeNode clickedNode)
+ protected override async void EnableMenuItems(TreeNode clickedNode)
{
- BrowseOptionsMI.Enabled = true;
- ShowReferencesMI.Enabled = true;
- SelectMI.Visible = m_allowPick;
- SelectSeparatorMI.Visible = m_allowPick;
-
- if (clickedNode != null)
+ try
{
- // do nothing if an error is detected.
- if (m_browser.Session.KeepAliveStopped)
- {
- return;
- }
+ BrowseOptionsMI.Enabled = true;
+ ShowReferencesMI.Enabled = true;
+ SelectMI.Visible = m_allowPick;
+ SelectSeparatorMI.Visible = m_allowPick;
- SelectMI.Enabled = true;
- SelectItemMI.Enabled = true;
- SelectChildrenMI.Enabled = clickedNode.Nodes.Count > 0;
- BrowseRefreshMI.Enabled = true;
-
- ReferenceDescription reference = clickedNode.Tag as ReferenceDescription;
-
- if (reference != null)
+ if (clickedNode != null)
{
- BrowseMI.Enabled = (reference.NodeId != null && !reference.NodeId.IsAbsolute);
- ViewAttributesMI.Enabled = true;
-
- NodeId nodeId = ExpandedNodeId.ToNodeId(reference.NodeId, m_browser.Session.NamespaceUris);
+ // do nothing if an error is detected.
+ if (m_browser.Session.KeepAliveStopped)
+ {
+ return;
+ }
- INode node = m_browser.Session.ReadNode(nodeId);
-
- byte accessLevel = 0;
- byte eventNotifier = 0;
- bool executable = false;
+ SelectMI.Enabled = true;
+ SelectItemMI.Enabled = true;
+ SelectChildrenMI.Enabled = clickedNode.Nodes.Count > 0;
+ BrowseRefreshMI.Enabled = true;
- VariableNode variableNode = node as VariableNode;
+ ReferenceDescription reference = clickedNode.Tag as ReferenceDescription;
- if (variableNode != null)
+ if (reference != null)
{
- accessLevel = variableNode.UserAccessLevel;
- }
-
- ObjectNode objectNode = node as ObjectNode;
+ BrowseMI.Enabled = (reference.NodeId != null && !reference.NodeId.IsAbsolute);
+ ViewAttributesMI.Enabled = true;
- if (objectNode != null)
- {
- eventNotifier = objectNode.EventNotifier;
- }
-
- ViewNode viewNode = node as ViewNode;
+ NodeId nodeId = ExpandedNodeId.ToNodeId(reference.NodeId, m_browser.Session.NamespaceUris);
- if (viewNode != null)
- {
- eventNotifier = viewNode.EventNotifier;
- }
-
- MethodNode methodNode = node as MethodNode;
+ INode node = await m_browser.Session.ReadNodeAsync(nodeId);
- if (methodNode != null)
- {
- executable = methodNode.UserExecutable;
- }
-
- ReadMI.Visible = false;
- HistoryReadMI.Visible = false;
- WriteMI.Visible = false;
- HistoryUpdateMI.Visible = false;
- EncodingsMI.Visible = false;
- SubscribeMI.Visible = false;
- CallMI.Visible = false;
-
- if (accessLevel != 0)
- {
- ReadMI.Visible = true;
- HistoryReadMI.Visible = true;
- WriteMI.Visible = true;
- HistoryUpdateMI.Visible = true;
- EncodingsMI.Visible = true;
- SubscribeMI.Visible = m_SessionTreeCtrl != null;
-
- if ((accessLevel & (byte)AccessLevels.CurrentRead) != 0)
+ byte accessLevel = 0;
+ byte eventNotifier = 0;
+ bool executable = false;
+
+ VariableNode variableNode = node as VariableNode;
+
+ if (variableNode != null)
{
- ReadMI.Enabled = true;
- EncodingsMI.Enabled = true;
- SubscribeMI.Enabled = true;
- SubscribeNewMI.Enabled = true;
+ accessLevel = variableNode.UserAccessLevel;
}
- if ((accessLevel & (byte)AccessLevels.CurrentWrite) != 0)
+ ObjectNode objectNode = node as ObjectNode;
+
+ if (objectNode != null)
{
- WriteMI.Enabled = true;
- EncodingsMI.Enabled = true;
+ eventNotifier = objectNode.EventNotifier;
}
- if ((accessLevel & (byte)AccessLevels.HistoryRead) != 0)
+ ViewNode viewNode = node as ViewNode;
+
+ if (viewNode != null)
{
- HistoryReadMI.Enabled = true;
+ eventNotifier = viewNode.EventNotifier;
}
- if ((accessLevel & (byte)AccessLevels.HistoryWrite) != 0)
+ MethodNode methodNode = node as MethodNode;
+
+ if (methodNode != null)
{
- HistoryUpdateMI.Enabled = true;
+ executable = methodNode.UserExecutable;
}
- }
-
- if (eventNotifier != 0)
- {
- HistoryReadMI.Visible = true;
- HistoryUpdateMI.Visible = true;
- SubscribeMI.Visible = true;
-
- if ((eventNotifier & (byte)EventNotifiers.HistoryRead) != 0)
+
+ ReadMI.Visible = false;
+ HistoryReadMI.Visible = false;
+ WriteMI.Visible = false;
+ HistoryUpdateMI.Visible = false;
+ SubscribeMI.Visible = false;
+ CallMI.Visible = false;
+
+ if (accessLevel != 0)
{
- HistoryReadMI.Enabled = true;
+ ReadMI.Visible = true;
+ HistoryReadMI.Visible = true;
+ WriteMI.Visible = true;
+ HistoryUpdateMI.Visible = true;
+ SubscribeMI.Visible = m_SessionTreeCtrl != null;
+
+ if ((accessLevel & (byte)AccessLevels.CurrentRead) != 0)
+ {
+ ReadMI.Enabled = true;
+ SubscribeMI.Enabled = true;
+ SubscribeNewMI.Enabled = true;
+ }
+
+ if ((accessLevel & (byte)AccessLevels.CurrentWrite) != 0)
+ {
+ WriteMI.Enabled = true;
+ }
+
+ if ((accessLevel & (byte)AccessLevels.HistoryRead) != 0)
+ {
+ HistoryReadMI.Enabled = true;
+ }
+
+ if ((accessLevel & (byte)AccessLevels.HistoryWrite) != 0)
+ {
+ HistoryUpdateMI.Enabled = true;
+ }
}
- if ((eventNotifier & (byte)EventNotifiers.HistoryWrite) != 0)
+ if (eventNotifier != 0)
{
- HistoryUpdateMI.Enabled = true;
- }
+ HistoryReadMI.Visible = true;
+ HistoryUpdateMI.Visible = true;
+ SubscribeMI.Visible = true;
- SubscribeMI.Enabled = (eventNotifier & (byte)EventNotifiers.SubscribeToEvents) != 0;
- SubscribeNewMI.Enabled = SubscribeMI.Enabled;
- }
-
- if (methodNode != null)
- {
- CallMI.Visible = true;
- CallMI.Enabled = executable;
- }
-
- if (variableNode != null && EncodingsMI.Enabled)
- {
- ReferenceDescriptionCollection encodings = m_browser.Session.ReadAvailableEncodings(variableNode.NodeId);
+ if ((eventNotifier & (byte)EventNotifiers.HistoryRead) != 0)
+ {
+ HistoryReadMI.Enabled = true;
+ }
- if (encodings.Count == 0)
- {
- EncodingsMI.Visible = false;
+ if ((eventNotifier & (byte)EventNotifiers.HistoryWrite) != 0)
+ {
+ HistoryUpdateMI.Enabled = true;
+ }
+
+ SubscribeMI.Enabled = (eventNotifier & (byte)EventNotifiers.SubscribeToEvents) != 0;
+ SubscribeNewMI.Enabled = SubscribeMI.Enabled;
}
- }
- if (SubscribeMI.Enabled)
- {
- while (SubscribeMI.DropDown.Items.Count > 1)
+ if (methodNode != null)
{
- SubscribeMI.DropDown.Items.RemoveAt(SubscribeMI.DropDown.Items.Count - 1);
+ CallMI.Visible = true;
+ CallMI.Enabled = executable;
}
- foreach (Subscription subscription in m_browser.Session.Subscriptions)
+ if (SubscribeMI.Enabled)
{
- if (subscription.Created)
+ while (SubscribeMI.DropDown.Items.Count > 1)
+ {
+ SubscribeMI.DropDown.Items.RemoveAt(SubscribeMI.DropDown.Items.Count - 1);
+ }
+
+ foreach (Subscription subscription in m_browser.Session.Subscriptions)
{
- ToolStripItem item = SubscribeMI.DropDown.Items.Add(subscription.DisplayName);
- item.Click += new EventHandler(Subscription_Click);
- item.Tag = subscription;
+ if (subscription.Created)
+ {
+ ToolStripItem item = SubscribeMI.DropDown.Items.Add(subscription.DisplayName);
+ item.Click += new EventHandler(Subscription_ClickAsync);
+ item.Tag = subscription;
+ }
}
}
}
}
}
+ catch (Exception exception)
+ {
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ }
}
///
- protected override void SelectNode()
+ protected override async void SelectNode()
{
- base.SelectNode();
-
- // check if node is selected.
- if (NodesTV.SelectedNode == null)
+ try
{
- return;
- }
-
- m_parent = GetParentOfSelected();
+ base.SelectNode();
- ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;
+ // check if node is selected.
+ if (NodesTV.SelectedNode == null)
+ {
+ return;
+ }
- // update the attributes control.
- if (m_AttributesCtrl != null)
- {
- if (reference != null)
+ m_parent = GetParentOfSelected();
+
+ ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;
+
+ // update the attributes control.
+ if (m_AttributesCtrl != null)
{
- m_AttributesCtrl.Initialize(m_browser.Session as Session, reference.NodeId);
+ if (reference != null)
+ {
+ await m_AttributesCtrl.InitializeAsync(m_browser.Session as Session, reference.NodeId);
+ }
+ else
+ {
+ m_AttributesCtrl.Clear();
+ }
}
- else
+
+ // check for single reference.
+ if (reference != null)
{
- m_AttributesCtrl.Clear();
+ m_references = new ReferenceDescription[] { reference };
+ return;
}
- }
-
- // check for single reference.
- if (reference != null)
- {
- m_references = new ReferenceDescription[] { reference };
- return;
- }
-
- // check if reference type folder is selected.
- NodeId referenceTypeId = NodesTV.SelectedNode.Tag as NodeId;
- if (referenceTypeId != null)
- {
- m_references = new ReferenceDescriptionCollection();
+ // check if reference type folder is selected.
+ NodeId referenceTypeId = NodesTV.SelectedNode.Tag as NodeId;
- foreach (TreeNode child in NodesTV.SelectedNode.Nodes)
- {
- reference = child.Tag as ReferenceDescription;
+ if (referenceTypeId != null)
+ {
+ m_references = new ReferenceDescriptionCollection();
- if (reference != null)
+ foreach (TreeNode child in NodesTV.SelectedNode.Nodes)
{
- m_references.Add(reference);
+ reference = child.Tag as ReferenceDescription;
+
+ if (reference != null)
+ {
+ m_references.Add(reference);
+ }
}
}
- }
+ }
+ catch (Exception exception)
+ {
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ }
}
#endregion
-
+
#region Private Members
///
/// Returns the parent node of the selected reference.
@@ -587,16 +589,16 @@ private ReferenceDescription GetParentOfSelected()
///
/// Adds a item to a subscription.
///
- private void Subscribe(Subscription subscription, ReferenceDescription reference)
- {
+ private async Task SubscribeAsync(Subscription subscription, ReferenceDescription reference, CancellationToken ct = default)
+ {
MonitoredItem monitoredItem = new MonitoredItem(subscription.DefaultItem);
- monitoredItem.DisplayName = subscription.Session.NodeCache.GetDisplayText(reference);
- monitoredItem.StartNodeId = (NodeId)reference.NodeId;
- monitoredItem.NodeClass = (NodeClass)reference.NodeClass;
- monitoredItem.AttributeId = Attributes.Value;
+ monitoredItem.DisplayName = await subscription.Session.NodeCache.GetDisplayTextAsync(reference, ct);
+ monitoredItem.StartNodeId = (NodeId)reference.NodeId;
+ monitoredItem.NodeClass = (NodeClass)reference.NodeClass;
+ monitoredItem.AttributeId = Attributes.Value;
monitoredItem.SamplingInterval = 0;
- monitoredItem.QueueSize = 1;
+ monitoredItem.QueueSize = 1;
// add condition fields to any event filter.
EventFilter filter = monitoredItem.Filter as EventFilter;
@@ -604,18 +606,18 @@ private void Subscribe(Subscription subscription, ReferenceDescription reference
if (filter != null)
{
monitoredItem.AttributeId = Attributes.EventNotifier;
- monitoredItem.QueueSize = 0;
+ monitoredItem.QueueSize = 0;
}
-
+
subscription.AddItem(monitoredItem);
- subscription.ApplyChanges();
+ await subscription.ApplyChangesAsync(ct);
}
///
/// Browses the server address space and adds the targets to the tree.
///
- private bool Browse(TreeNode node)
- {
+ private async Task BrowseAsync(TreeNode node, CancellationToken ct = default)
+ {
// save node being browsed.
m_nodeToBrowse = node;
@@ -626,21 +628,21 @@ private bool Browse(TreeNode node)
{
return false;
}
-
+
// fetch references.
ReferenceDescriptionCollection references = null;
if (reference != null)
{
- references = m_browser.Browse((NodeId)reference.NodeId);
+ references = await m_browser.BrowseAsync((NodeId)reference.NodeId, ct);
}
else
{
- references = m_browser.Browse(m_rootId);
+ references = await m_browser.BrowseAsync(m_rootId, ct);
}
-
+
// add nodes to tree.
- AddReferences(m_nodeToBrowse, references);
+ await AddReferencesAsync(m_nodeToBrowse, references, ct);
return false;
}
@@ -648,7 +650,7 @@ private bool Browse(TreeNode node)
///
/// Adds a target to the tree control.
///
- private void AddReferences(TreeNode parent, ReferenceDescriptionCollection references)
+ private async Task AddReferencesAsync(TreeNode parent, ReferenceDescriptionCollection references, CancellationToken ct = default)
{
foreach (ReferenceDescription reference in references)
{
@@ -658,7 +660,7 @@ private void AddReferences(TreeNode parent, ReferenceDescriptionCollection refer
continue;
}
- ReferenceTypeNode typeNode = m_browser.Session.NodeCache.Find(reference.ReferenceTypeId) as ReferenceTypeNode;
+ ReferenceTypeNode typeNode = await m_browser.Session.NodeCache.FindAsync(reference.ReferenceTypeId, ct) as ReferenceTypeNode;
if (typeNode == null)
{
Utils.Trace("Reference {0} has invalid reference type id.", reference.DisplayName);
@@ -689,7 +691,7 @@ private void AddReferences(TreeNode parent, ReferenceDescriptionCollection refer
Utils.Trace("Node class is an unknown or unspecified value, for reference {0}", reference.DisplayName);
continue;
}
-
+
if (m_browser.NodeClassMask != 0 && m_browser.NodeClassMask != 255)
{
if (reference.TypeDefinition == null || reference.TypeDefinition.IsNull)
@@ -725,13 +727,13 @@ private void AddReferences(TreeNode parent, ReferenceDescriptionCollection refer
}
string text = GetTargetText(reference);
- string icon = GuiUtils.GetTargetIcon(m_browser.Session as Session, reference);
+ string icon = await GuiUtils.GetTargetIconAsync(m_browser.Session as Session, reference, ct);
TreeNode container = parent;
if (m_showReferences)
{
- container = FindReferenceTypeContainer(parent, reference);
+ container = await FindReferenceTypeContainerAsync(parent, reference, ct);
}
if (container != null)
@@ -741,11 +743,11 @@ private void AddReferences(TreeNode parent, ReferenceDescriptionCollection refer
}
}
}
-
+
///
/// Adds a container for the reference type to the tree control.
///
- private TreeNode FindReferenceTypeContainer(TreeNode parent, ReferenceDescription reference)
+ private async Task FindReferenceTypeContainerAsync(TreeNode parent, ReferenceDescription reference, CancellationToken ct = default)
{
if (parent == null)
{
@@ -758,7 +760,7 @@ private TreeNode FindReferenceTypeContainer(TreeNode parent, ReferenceDescriptio
return null;
}
- ReferenceTypeNode typeNode = m_browser.Session.NodeCache.Find(reference.ReferenceTypeId) as ReferenceTypeNode;
+ ReferenceTypeNode typeNode = await m_browser.Session.NodeCache.FindAsync(reference.ReferenceTypeId, ct) as ReferenceTypeNode;
foreach (TreeNode child in parent.Nodes)
{
@@ -805,7 +807,7 @@ private TreeNode FindReferenceTypeContainer(TreeNode parent, ReferenceDescriptio
return null;
}
-
+
///
/// Returns to display text for the target of a reference.
///
@@ -824,52 +826,52 @@ public string GetTargetText(ReferenceDescription reference)
}
}
- return null;
+ return null;
}
#endregion
-
- private void BrowseOptionsMI_Click(object sender, EventArgs e)
+
+ private async void BrowseOptionsMI_ClickAsync(object sender, EventArgs e)
{
try
{
- if (new BrowseOptionsDlg().ShowDialog(m_browser))
- {
+ if (await new BrowseOptionsDlg().ShowDialogAsync(m_browser))
+ {
if (NodesTV.SelectedNode != null)
{
NodesTV.SelectedNode.Nodes.Clear();
- Browse(NodesTV.SelectedNode);
+ await BrowseAsync(NodesTV.SelectedNode);
}
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void BrowseRefreshMI_Click(object sender, EventArgs e)
+ private async void BrowseRefreshMI_ClickAsync(object sender, EventArgs e)
{
try
{
if (NodesTV.SelectedNode != null)
{
NodesTV.SelectedNode.Nodes.Clear();
- Browse(NodesTV.SelectedNode);
+ await BrowseAsync(NodesTV.SelectedNode);
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void Browser_MoreReferences(Browser sender, BrowserEventArgs e)
+ private async void Browser_MoreReferencesAsync(Browser sender, BrowserEventArgs e)
{
try
{
- AddReferences(m_nodeToBrowse, e.References);
+ await AddReferencesAsync(m_nodeToBrowse, e.References);
e.References.Clear();
-
+
if (MessageBox.Show("More references exist. Continue?", "Browse", MessageBoxButtons.YesNo) == DialogResult.No)
{
e.Cancel = true;
@@ -877,7 +879,7 @@ private void Browser_MoreReferences(Browser sender, BrowserEventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -897,10 +899,10 @@ private void SelectItemMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
-
+
private void SelectChildrenMI_Click(object sender, EventArgs e)
{
try
@@ -920,7 +922,7 @@ private void SelectChildrenMI_Click(object sender, EventArgs e)
if (reference != null)
{
m_references.Add(reference);
- }
+ }
}
if (m_references.Count > 0)
@@ -930,17 +932,24 @@ private void SelectChildrenMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void ShowReferencesMI_CheckedChanged(object sender, EventArgs e)
+ private async void ShowReferencesMI_CheckedChangedAsync(object sender, EventArgs e)
{
m_showReferences = ShowReferencesMI.Checked;
- SetRoot(m_browser, m_rootId);
+ try
+ {
+ await SetRootAsync(m_browser, m_rootId);
+ }
+ catch (Exception exception)
+ {
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ }
}
- private void ViewAttributesMI_Click(object sender, EventArgs e)
+ private async void ViewAttributesMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -948,23 +957,23 @@ private void ViewAttributesMI_Click(object sender, EventArgs e)
{
return;
}
-
+
ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;
-
+
if (reference == null)
{
return;
}
-
- new NodeAttributesDlg().ShowDialog(m_browser.Session as Session, reference.NodeId);
+
+ await new NodeAttributesDlg().ShowDialogAsync(m_browser.Session as Session, reference.NodeId);
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void CallMI_Click(object sender, EventArgs e)
+ private async void CallMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -974,18 +983,18 @@ private void CallMI_Click(object sender, EventArgs e)
}
Session session = m_browser.Session as Session;
-
+
ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;
-
+
if (reference == null || reference.NodeClass != NodeClass.Method)
{
return;
}
NodeId methodId = (NodeId)reference.NodeId;
-
+
reference = NodesTV.SelectedNode.Parent.Tag as ReferenceDescription;
-
+
if (reference == null)
{
reference = NodesTV.SelectedNode.Parent.Parent.Tag as ReferenceDescription;
@@ -995,7 +1004,7 @@ private void CallMI_Click(object sender, EventArgs e)
return;
}
}
-
+
NodeId objectId = (NodeId)reference.NodeId;
if (m_MethodCalled != null)
@@ -1009,15 +1018,15 @@ private void CallMI_Click(object sender, EventArgs e)
}
}
- new CallMethodDlg().Show(m_browser.Session as Session, objectId, methodId);
+ await new CallMethodDlg().ShowAsync(m_browser.Session as Session, objectId, methodId);
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void ReadMI_Click(object sender, EventArgs e)
+ private async void ReadMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -1025,9 +1034,9 @@ private void ReadMI_Click(object sender, EventArgs e)
{
return;
}
-
+
ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;
-
+
if (reference == null || (reference.NodeClass & (NodeClass.Variable | NodeClass.VariableType)) == 0)
{
return;
@@ -1040,23 +1049,23 @@ private void ReadMI_Click(object sender, EventArgs e)
ReadValueId valueId = new ReadValueId();
- valueId.NodeId = (NodeId)reference.NodeId;
- valueId.AttributeId = Attributes.Value;
- valueId.IndexRange = null;
+ valueId.NodeId = (NodeId)reference.NodeId;
+ valueId.AttributeId = Attributes.Value;
+ valueId.IndexRange = null;
valueId.DataEncoding = null;
valueIds.Add(valueId);
// show form.
- new ReadDlg().Show(session, valueIds);
+ await new ReadDlg().ShowAsync(session, valueIds);
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void WriteMI_Click(object sender, EventArgs e)
+ private async void WriteMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -1064,9 +1073,9 @@ private void WriteMI_Click(object sender, EventArgs e)
{
return;
}
-
+
ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;
-
+
if (reference == null || (reference.NodeClass & (NodeClass.Variable | NodeClass.VariableType)) == 0)
{
return;
@@ -1079,23 +1088,23 @@ private void WriteMI_Click(object sender, EventArgs e)
WriteValue value = new WriteValue();
- value.NodeId = (NodeId)reference.NodeId;
+ value.NodeId = (NodeId)reference.NodeId;
value.AttributeId = Attributes.Value;
- value.IndexRange = null;
- value.Value = null;
+ value.IndexRange = null;
+ value.Value = null;
values.Add(value);
// show form.
- new WriteDlg().Show(session, values);
+ await new WriteDlg().ShowAsync(session, values);
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void SubscribeNewMI_Click(object sender, EventArgs e)
+ private async void SubscribeNewMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -1112,22 +1121,22 @@ private void SubscribeNewMI_Click(object sender, EventArgs e)
}
if (m_SessionTreeCtrl != null)
- {
- Subscription subscription = m_SessionTreeCtrl.CreateSubscription(m_browser.Session as Session);
+ {
+ Subscription subscription = await m_SessionTreeCtrl.CreateSubscriptionAsync(m_browser.Session as Session);
if (subscription != null)
{
- Subscribe(subscription, reference);
+ await SubscribeAsync(subscription, reference);
}
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- void Subscription_Click(object sender, EventArgs e)
+ private async void Subscription_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -1142,45 +1151,21 @@ void Subscription_Click(object sender, EventArgs e)
{
return;
}
-
+
Subscription subscription = ((ToolStripItem)sender).Tag as Subscription;
if (subscription != null)
{
- Subscribe(subscription, reference);
- }
- }
- catch (Exception exception)
- {
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
- }
- }
-
- private void EncodingsMI_Click(object sender, EventArgs e)
- {
- try
- {
- if (NodesTV.SelectedNode == null)
- {
- return;
- }
-
- ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;
-
- if (reference == null || (reference.NodeClass & NodeClass.Variable) == 0)
- {
- return;
+ await SubscribeAsync(subscription, reference);
}
-
- new DataEncodingDlg().ShowDialog(m_browser.Session as Session, (NodeId)reference.NodeId);
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void HistoryReadMI_Click(object sender, EventArgs e)
+ private async void HistoryReadMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -1196,7 +1181,7 @@ private void HistoryReadMI_Click(object sender, EventArgs e)
return;
}
- new ReadHistoryDlg().ShowDialog(m_browser.Session as Session, (NodeId)reference.NodeId);
+ await new ReadHistoryDlg().ShowDialogAsync(m_browser.Session as Session, (NodeId)reference.NodeId);
}
catch (Exception exception)
{
@@ -1204,7 +1189,7 @@ private void HistoryReadMI_Click(object sender, EventArgs e)
}
}
- private void BrowseMI_Click(object sender, EventArgs e)
+ private async void BrowseMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -1220,15 +1205,15 @@ private void BrowseMI_Click(object sender, EventArgs e)
return;
}
- new BrowseDlg().Show(m_browser.Session as Session, (NodeId)reference.NodeId);
+ await new BrowseDlg().ShowAsync(m_browser.Session as Session, (NodeId)reference.NodeId);
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
}
-
+
#region NodesSelectedEventArgs Class
///
/// The event arguments provided nodes are picked in the dialog.
@@ -1241,7 +1226,7 @@ public class NodesSelectedEventArgs : EventArgs
///
internal NodesSelectedEventArgs(ExpandedNodeId sourceId, ReferenceDescriptionCollection references)
{
- m_sourceId = sourceId;
+ m_sourceId = sourceId;
m_references = references;
}
#endregion
@@ -1263,7 +1248,7 @@ public IEnumerable References
get { return m_references; }
}
#endregion
-
+
#region Private Fields
private ExpandedNodeId m_sourceId;
private ReferenceDescriptionCollection m_references;
@@ -1274,11 +1259,11 @@ public IEnumerable References
/// The delegate used to receive notifications when nodes are picked in the dialog.
///
public delegate void NodesSelectedEventHandler(object sender, NodesSelectedEventArgs e);
- #endregion
-
+ #endregion
+
#region BrowseViewType Enumeration
///
- /// The type views that can be used when browsing the address space.
+ /// The type views that can be used when browsing the address space.
///
public enum BrowseViewType
{
@@ -1322,9 +1307,9 @@ public enum BrowseViewType
///
ServerDefinedView
}
- #endregion
+ #endregion
+
-
#region MethodCalledEventArgs Class
///
/// The event arguments provided nodes are picked in the dialog.
@@ -1337,7 +1322,7 @@ public class MethodCalledEventArgs : EventArgs
///
internal MethodCalledEventArgs(Session session, NodeId objectId, NodeId methodId)
{
- m_session = session;
+ m_session = session;
m_objectId = objectId;
m_methodId = methodId;
}
@@ -1345,7 +1330,7 @@ internal MethodCalledEventArgs(Session session, NodeId objectId, NodeId methodId
#region Public Properties
///
- /// The session
+ /// The session
///
public Session Session
{
@@ -1373,11 +1358,11 @@ public NodeId MethodId
///
public bool Handled
{
- get { return m_handled; }
+ get { return m_handled; }
set { m_handled = value; }
}
#endregion
-
+
#region Private Fields
private Session m_session;
private NodeId m_objectId;
@@ -1390,5 +1375,5 @@ public bool Handled
/// The delegate used to receive notifications when nodes are picked in the dialog.
///
public delegate void MethodCalledEventHandler(object sender, MethodCalledEventArgs e);
- #endregion
+ #endregion
}
diff --git a/Samples/Controls.Net4/Sessions/BrowseTreeCtrl.resx b/Samples/Controls.Net4/Sessions/BrowseTreeCtrl.resx
index edd3be8a4..664168a02 100644
--- a/Samples/Controls.Net4/Sessions/BrowseTreeCtrl.resx
+++ b/Samples/Controls.Net4/Sessions/BrowseTreeCtrl.resx
@@ -112,12 +112,12 @@
2.0
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
+
17, 17
\ No newline at end of file
diff --git a/Samples/Controls.Net4/Sessions/BrowseTypesDlg.Designer.cs b/Samples/Controls.Net4/Sessions/BrowseTypesDlg.Designer.cs
index 433d0db9b..e95189d0f 100644
--- a/Samples/Controls.Net4/Sessions/BrowseTypesDlg.Designer.cs
+++ b/Samples/Controls.Net4/Sessions/BrowseTypesDlg.Designer.cs
@@ -128,7 +128,7 @@ private void InitializeComponent()
this.TypeNavigatorCTRL.Name = "TypeNavigatorCTRL";
this.TypeNavigatorCTRL.Size = new System.Drawing.Size(788, 24);
this.TypeNavigatorCTRL.TabIndex = 1;
- this.TypeNavigatorCTRL.TypeSelected += new Opc.Ua.Sample.TypeNavigatorEventHandler(this.TypeNavigatorCTRL_TypeSelected);
+ this.TypeNavigatorCTRL.TypeSelected += new Opc.Ua.Sample.TypeNavigatorEventHandler(this.TypeNavigatorCTRL_TypeSelectedAsync);
//
// BrowseTypesDlg
//
diff --git a/Samples/Controls.Net4/Sessions/BrowseTypesDlg.cs b/Samples/Controls.Net4/Sessions/BrowseTypesDlg.cs
index dc12aec1d..1fe09bc3d 100644
--- a/Samples/Controls.Net4/Sessions/BrowseTypesDlg.cs
+++ b/Samples/Controls.Net4/Sessions/BrowseTypesDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -38,6 +38,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -55,32 +57,33 @@ public BrowseTypesDlg()
private Session m_session;
private ILocalNode m_selectedType;
#endregion
-
+
#region Public Interface
///
/// Displays the dialog.
///
- public void Show(
+ public async Task ShowAsync(
Session session,
- NodeId typeId)
+ NodeId typeId,
+ CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
+ if (session == null) throw new ArgumentNullException(nameof(session));
- m_session = session;
-
- TypeNavigatorCTRL.Initialize(m_session, typeId);
- TypeHierarchyCTRL.Initialize(m_session, typeId);
+ m_session = session;
+
+ await TypeNavigatorCTRL.InitializeAsync(m_session, typeId, ct);
+ await TypeHierarchyCTRL.InitializeAsync(m_session, typeId, ct);
Show();
BringToFront();
}
#endregion
-
+
#region Private Methods
#endregion
-
+
#region Event Handler
- private void TypeNavigatorCTRL_TypeSelected(object sender, TypeNavigatorEventArgs e)
+ private async void TypeNavigatorCTRL_TypeSelectedAsync(object sender, TypeNavigatorEventArgs e)
{
try
{
@@ -88,11 +91,11 @@ private void TypeNavigatorCTRL_TypeSelected(object sender, TypeNavigatorEventArg
if (m_selectedType != null)
{
- TypeHierarchyCTRL.Initialize(m_session, m_selectedType.NodeId);
+ await TypeHierarchyCTRL.InitializeAsync(m_session, m_selectedType.NodeId);
}
else
{
- TypeHierarchyCTRL.Initialize(m_session, null);
+ await TypeHierarchyCTRL.InitializeAsync(m_session, null);
}
}
catch (Exception exception)
diff --git a/Samples/Controls.Net4/Sessions/CreateSecureChannelDlg.Designer.cs b/Samples/Controls.Net4/Sessions/CreateSecureChannelDlg.Designer.cs
index b09959186..8bd7c2f21 100644
--- a/Samples/Controls.Net4/Sessions/CreateSecureChannelDlg.Designer.cs
+++ b/Samples/Controls.Net4/Sessions/CreateSecureChannelDlg.Designer.cs
@@ -146,7 +146,7 @@ private void InitializeComponent()
this.OkBTN.TabIndex = 1;
this.OkBTN.Text = "OK";
this.OkBTN.UseVisualStyleBackColor = true;
- this.OkBTN.Click += new System.EventHandler(this.OkBTN_Click);
+ this.OkBTN.Click += new System.EventHandler(this.OkBTN_ClickAsync);
//
// CancelBTN
//
diff --git a/Samples/Controls.Net4/Sessions/CreateSecureChannelDlg.cs b/Samples/Controls.Net4/Sessions/CreateSecureChannelDlg.cs
index 4084cfa5a..d59982f39 100644
--- a/Samples/Controls.Net4/Sessions/CreateSecureChannelDlg.cs
+++ b/Samples/Controls.Net4/Sessions/CreateSecureChannelDlg.cs
@@ -63,19 +63,19 @@ public CreateSecureChannelDlg()
private ApplicationConfiguration m_configuration;
private EndpointDescriptionCollection m_endpoints;
private ServiceMessageContext m_messageContext;
-
+
///
/// Displays the dialog.
///
public ITransportChannel ShowDialog(
- ApplicationConfiguration configuration,
+ ApplicationConfiguration configuration,
EndpointDescriptionCollection endpoints)
{
- if (endpoints == null) throw new ArgumentNullException("endpoints");
- if (configuration == null) throw new ArgumentNullException("configuration");
+ if (endpoints == null) throw new ArgumentNullException(nameof(endpoints));
+ if (configuration == null) throw new ArgumentNullException(nameof(configuration));
- m_endpoints = endpoints;
- m_configuration = configuration;
+ m_endpoints = endpoints;
+ m_configuration = configuration;
m_messageContext = configuration.CreateMessageContext();
EndpointCB.Items.Clear();
@@ -89,23 +89,23 @@ public ITransportChannel ShowDialog(
{
EndpointCB.SelectedIndex = 0;
}
-
- OperationTimeoutNC.Value = configuration.TransportQuotas.OperationTimeout;
- MaxMessageSizeNC.Value = configuration.TransportQuotas.MaxMessageSize;
- MaxArrayLengthNC.Value = configuration.TransportQuotas.MaxArrayLength;
- MaxStringLengthNC.Value = configuration.TransportQuotas.MaxStringLength;
+
+ OperationTimeoutNC.Value = configuration.TransportQuotas.OperationTimeout;
+ MaxMessageSizeNC.Value = configuration.TransportQuotas.MaxMessageSize;
+ MaxArrayLengthNC.Value = configuration.TransportQuotas.MaxArrayLength;
+ MaxStringLengthNC.Value = configuration.TransportQuotas.MaxStringLength;
MaxByteStringLengthNC.Value = configuration.TransportQuotas.MaxByteStringLength;
if (ShowDialog() != DialogResult.OK)
{
return null;
}
-
+
// return the channel.
return m_channel;
}
- private async void OkBTN_Click(object sender, EventArgs e)
+ private async void OkBTN_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -122,7 +122,7 @@ private async void OkBTN_Click(object sender, EventArgs e)
m_configuration,
m_endpoints[EndpointCB.SelectedIndex],
configuration,
- await m_configuration.SecurityConfiguration.ApplicationCertificate.Find(true),
+ await m_configuration.SecurityConfiguration.ApplicationCertificate.FindAsync(true),
m_messageContext);
// create the channel.
@@ -189,7 +189,7 @@ private void EndpointCB_SelectedIndexChanged(object sender, EventArgs e)
}
private void DetailsBTN_Click(object sender, EventArgs e)
- {
+ {
try
{
int index = EndpointCB.SelectedIndex;
diff --git a/Samples/Controls.Net4/Sessions/EndpointViewDlg.cs b/Samples/Controls.Net4/Sessions/EndpointViewDlg.cs
index 3749f46e4..7a750e99e 100644
--- a/Samples/Controls.Net4/Sessions/EndpointViewDlg.cs
+++ b/Samples/Controls.Net4/Sessions/EndpointViewDlg.cs
@@ -54,17 +54,17 @@ public EndpointViewDlg()
{
InitializeComponent();
}
-
+
///
/// Displays the dialog.
///
public bool ShowDialog(EndpointDescription endpoint)
{
- if (endpoint == null) throw new ArgumentNullException("endpoint");
-
- EndpointTB.Text = endpoint.EndpointUrl;
+ if (endpoint == null) throw new ArgumentNullException(nameof(endpoint));
+
+ EndpointTB.Text = endpoint.EndpointUrl;
ServerNameTB.Text = endpoint.Server.ApplicationName.Text;
- ServerUriTB.Text = endpoint.Server.ApplicationUri;
+ ServerUriTB.Text = endpoint.Server.ApplicationUri;
try
{
@@ -75,11 +75,11 @@ public bool ShowDialog(EndpointDescription endpoint)
{
ServerCertificateTB.Text = "";
}
-
-
- SecurityModeTB.Text = String.Format("{0}", endpoint.SecurityMode);;
+
+
+ SecurityModeTB.Text = String.Format("{0}", endpoint.SecurityMode); ;
SecurityPolicyUriTB.Text = String.Format("{0}", endpoint.SecurityPolicyUri);
-
+
UserIdentityTypeTB.Text = "";
foreach (UserTokenPolicy policy in endpoint.UserIdentityTokens)
@@ -91,7 +91,7 @@ public bool ShowDialog(EndpointDescription endpoint)
{
return false;
}
-
+
return true;
}
}
diff --git a/Samples/Controls.Net4/Sessions/NodeAttributesDlg.Designer.cs b/Samples/Controls.Net4/Sessions/NodeAttributesDlg.Designer.cs
index 97df8dd30..998bd2c8f 100644
--- a/Samples/Controls.Net4/Sessions/NodeAttributesDlg.Designer.cs
+++ b/Samples/Controls.Net4/Sessions/NodeAttributesDlg.Designer.cs
@@ -85,7 +85,7 @@ private void InitializeComponent()
this.OkBTN.TabIndex = 0;
this.OkBTN.Text = "Refresh";
this.OkBTN.UseVisualStyleBackColor = true;
- this.OkBTN.Click += new System.EventHandler(this.OkBTN_Click);
+ this.OkBTN.Click += new System.EventHandler(this.OkBTN_ClickAsync);
//
// CancelBTN
//
diff --git a/Samples/Controls.Net4/Sessions/NodeAttributesDlg.cs b/Samples/Controls.Net4/Sessions/NodeAttributesDlg.cs
index 8de810284..c4d13212f 100644
--- a/Samples/Controls.Net4/Sessions/NodeAttributesDlg.cs
+++ b/Samples/Controls.Net4/Sessions/NodeAttributesDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -39,6 +39,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -56,20 +58,20 @@ public NodeAttributesDlg()
private Session m_session;
private ExpandedNodeId m_nodeId;
#endregion
-
+
#region Public Interface
///
/// Displays the dialog.
///
- public void ShowDialog(Session session, ExpandedNodeId nodeId)
+ public async Task ShowDialogAsync(Session session, ExpandedNodeId nodeId, CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
- if (nodeId == null) throw new ArgumentNullException("nodeId");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+ if (nodeId == null) throw new ArgumentNullException(nameof(nodeId));
+
m_session = session;
- m_nodeId = nodeId;
+ m_nodeId = nodeId;
- AttributesCTRL.Initialize(session, nodeId);
+ await AttributesCTRL.InitializeAsync(session, nodeId, ct);
if (ShowDialog() != DialogResult.OK)
{
@@ -78,11 +80,11 @@ public void ShowDialog(Session session, ExpandedNodeId nodeId)
}
#endregion
- private void OkBTN_Click(object sender, EventArgs e)
+ private async void OkBTN_ClickAsync(object sender, EventArgs e)
{
try
{
- AttributesCTRL.Initialize(m_session, m_nodeId);
+ await AttributesCTRL.InitializeAsync(m_session, m_nodeId);
}
catch (Exception exception)
{
diff --git a/Samples/Controls.Net4/Sessions/ReadHistoryDlg.Designer.cs b/Samples/Controls.Net4/Sessions/ReadHistoryDlg.Designer.cs
index 87fda8871..ed55eb6da 100644
--- a/Samples/Controls.Net4/Sessions/ReadHistoryDlg.Designer.cs
+++ b/Samples/Controls.Net4/Sessions/ReadHistoryDlg.Designer.cs
@@ -173,7 +173,7 @@ private void InitializeComponent()
this.StopBTN.TabIndex = 19;
this.StopBTN.Text = "Stop";
this.StopBTN.UseVisualStyleBackColor = true;
- this.StopBTN.Click += new System.EventHandler(this.StopBTN_Click);
+ this.StopBTN.Click += new System.EventHandler(this.StopBTN_ClickAsync);
//
// NextBTN
//
@@ -357,7 +357,7 @@ private void InitializeComponent()
this.ReadTypeCB.Name = "ReadTypeCB";
this.ReadTypeCB.Size = new System.Drawing.Size(138, 21);
this.ReadTypeCB.TabIndex = 1;
- this.ReadTypeCB.SelectedIndexChanged += new System.EventHandler(this.ReadTypeCB_SelectedIndexChanged);
+ this.ReadTypeCB.SelectedIndexChanged += new System.EventHandler(this.ReadTypeCB_SelectedIndexChangedAsync);
//
// ReadTypeLB
//
diff --git a/Samples/Controls.Net4/Sessions/ReadHistoryDlg.cs b/Samples/Controls.Net4/Sessions/ReadHistoryDlg.cs
index a48f59349..64a1169af 100644
--- a/Samples/Controls.Net4/Sessions/ReadHistoryDlg.cs
+++ b/Samples/Controls.Net4/Sessions/ReadHistoryDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -43,6 +43,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -67,7 +69,7 @@ public ReadHistoryDlg()
AggregateCB.Items.Add(BrowseNames.AggregateFunction_Count);
AggregateCB.Items.Add(BrowseNames.AggregateFunction_Maximum);
AggregateCB.Items.Add(BrowseNames.AggregateFunction_Minimum);
- AggregateCB.Items.Add(BrowseNames.AggregateFunction_Total);
+ AggregateCB.Items.Add(BrowseNames.AggregateFunction_Total);
}
private enum ReadType
@@ -82,17 +84,17 @@ private enum ReadType
private NodeId m_nodeId;
private HistoryReadResult m_result;
private int m_index;
-
+
///
/// Displays the dialog.
///
- public bool ShowDialog(Session session, NodeId nodeId)
+ public async Task ShowDialogAsync(Session session, NodeId nodeId, CancellationToken ct = default)
{
m_session = session;
m_nodeId = nodeId;
// update the title.
- string displayText = session.NodeCache.GetDisplayText(nodeId);
+ string displayText = await session.NodeCache.GetDisplayTextAsync(nodeId, ct);
if (!String.IsNullOrEmpty(displayText))
{
@@ -104,7 +106,7 @@ public bool ShowDialog(Session session, NodeId nodeId)
try
{
- startTime = ReadFirstDate().ToLocalTime();
+ startTime = (await ReadFirstDateAsync(ct)).ToLocalTime();
}
catch (Exception)
{
@@ -115,7 +117,7 @@ public bool ShowDialog(Session session, NodeId nodeId)
{
startTime = StartTimeDP.MinDate;
}
-
+
ReadTypeCB.SelectedItem = ReadType.Raw;
StartTimeDP.Value = startTime;
StartTimeCK.Checked = true;
@@ -134,7 +136,7 @@ public bool ShowDialog(Session session, NodeId nodeId)
{
return false;
}
-
+
return true;
}
@@ -182,8 +184,8 @@ private void ShowResults()
ResultsLV.Columns[ii].Width = -2;
}
}
-
- private void ReleaseContinuationPoints()
+
+ private async Task ReleaseContinuationPointsAsync(CancellationToken ct = default)
{
ReadRawModifiedDetails details = new ReadRawModifiedDetails();
@@ -198,17 +200,16 @@ private void ReleaseContinuationPoints()
HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();
nodesToRead.Add(nodeToRead);
- HistoryReadResultCollection results = null;
- DiagnosticInfoCollection diagnosticInfos = null;
-
- m_session.HistoryRead(
+ HistoryReadResponse response = await m_session.HistoryReadAsync(
null,
new ExtensionObject(details),
TimestampsToReturn.Source,
true,
nodesToRead,
- out results,
- out diagnosticInfos);
+ ct);
+
+ HistoryReadResultCollection results = response.Results;
+ DiagnosticInfoCollection diagnosticInfos = response.DiagnosticInfos;
Session.ValidateResponse(results, nodesToRead);
Session.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
@@ -218,7 +219,7 @@ private void ReleaseContinuationPoints()
ShowResults();
}
- private DateTime ReadFirstDate()
+ private async Task ReadFirstDateAsync(CancellationToken ct = default)
{
ReadRawModifiedDetails details = new ReadRawModifiedDetails();
details.StartTime = new DateTime(1970, 1, 1);
@@ -233,17 +234,16 @@ private DateTime ReadFirstDate()
HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();
nodesToRead.Add(nodeToRead);
- HistoryReadResultCollection results = null;
- DiagnosticInfoCollection diagnosticInfos = null;
-
- m_session.HistoryRead(
+ HistoryReadResponse response = await m_session.HistoryReadAsync(
null,
new ExtensionObject(details),
TimestampsToReturn.Source,
false,
nodesToRead,
- out results,
- out diagnosticInfos);
+ ct);
+
+ HistoryReadResultCollection results = response.Results;
+ DiagnosticInfoCollection diagnosticInfos = response.DiagnosticInfos;
Session.ValidateResponse(results, nodesToRead);
Session.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
@@ -266,14 +266,16 @@ private DateTime ReadFirstDate()
{
nodeToRead.ContinuationPoint = results[0].ContinuationPoint;
- m_session.HistoryRead(
+ response = await m_session.HistoryReadAsync(
null,
new ExtensionObject(details),
TimestampsToReturn.Source,
true,
nodesToRead,
- out results,
- out diagnosticInfos);
+ ct);
+
+ results = response.Results;
+ diagnosticInfos = response.DiagnosticInfos;
Session.ValidateResponse(results, nodesToRead);
Session.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
@@ -282,7 +284,7 @@ private DateTime ReadFirstDate()
return startTime;
}
- private void ReadRaw(bool isReadModified)
+ private async Task ReadRawAsync(bool isReadModified, CancellationToken ct = default)
{
ReadRawModifiedDetails details = new ReadRawModifiedDetails();
details.StartTime = DateTime.MinValue;
@@ -317,36 +319,36 @@ private void ReadRaw(bool isReadModified)
HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();
nodesToRead.Add(nodeToRead);
- HistoryReadResultCollection results = null;
- DiagnosticInfoCollection diagnosticInfos = null;
-
- m_session.HistoryRead(
+ HistoryReadResponse response = await m_session.HistoryReadAsync(
null,
new ExtensionObject(details),
TimestampsToReturn.Source,
false,
nodesToRead,
- out results,
- out diagnosticInfos);
+ ct);
+
+ HistoryReadResultCollection results = response.Results;
+ DiagnosticInfoCollection diagnosticInfos = response.DiagnosticInfos;
Session.ValidateResponse(results, nodesToRead);
Session.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
-
+
if (StatusCode.IsBad(results[0].StatusCode))
{
throw new ServiceResultException(results[0].StatusCode);
}
m_result = results[0];
-
+
ShowResults();
}
- private void ReadAtTime()
+ private Task ReadAtTimeAsync(CancellationToken ct = default)
{
+ return Task.CompletedTask;
}
- private void ReadProcessed()
+ private async Task ReadProcessedAsync(CancellationToken ct = default)
{
ReadProcessedDetails details = new ReadProcessedDetails();
details.StartTime = StartTimeDP.Value.ToUniversalTime();
@@ -379,17 +381,16 @@ private void ReadProcessed()
HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();
nodesToRead.Add(nodeToRead);
- HistoryReadResultCollection results = null;
- DiagnosticInfoCollection diagnosticInfos = null;
-
- m_session.HistoryRead(
+ HistoryReadResponse response = await m_session.HistoryReadAsync(
null,
new ExtensionObject(details),
TimestampsToReturn.Source,
false,
nodesToRead,
- out results,
- out diagnosticInfos);
+ ct);
+
+ HistoryReadResultCollection results = response.Results;
+ DiagnosticInfoCollection diagnosticInfos = response.DiagnosticInfos;
Session.ValidateResponse(results, nodesToRead);
Session.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
@@ -404,34 +405,31 @@ private void ReadProcessed()
ShowResults();
}
- private void Read()
+ private Task ReadAsync(CancellationToken ct = default)
{
switch ((ReadType)ReadTypeCB.SelectedItem)
{
case ReadType.Raw:
{
- ReadRaw(false);
- break;
+ return ReadRawAsync(false, ct);
}
case ReadType.Modified:
{
- ReadRaw(true);
- break;
+ return ReadRawAsync(true, ct);
}
case ReadType.AtTime:
{
- ReadAtTime();
- break;
+ return ReadAtTimeAsync(ct);
}
case ReadType.Processed:
{
- ReadProcessed();
- break;
+ return ReadProcessedAsync(ct);
}
}
+ return Task.CompletedTask;
}
private void GoBTN_Click(object sender, EventArgs e)
@@ -442,7 +440,7 @@ private void GoBTN_Click(object sender, EventArgs e)
ResultsLV.Items.Clear();
m_result = null;
- Read();
+ ReadAsync();
}
catch (Exception exception)
{
@@ -454,7 +452,7 @@ private void NextBTN_Click(object sender, EventArgs e)
{
try
{
- Read();
+ ReadAsync();
}
catch (Exception exception)
{
@@ -462,11 +460,11 @@ private void NextBTN_Click(object sender, EventArgs e)
}
}
- private void StopBTN_Click(object sender, EventArgs e)
+ private async void StopBTN_ClickAsync(object sender, EventArgs e)
{
try
{
- ReleaseContinuationPoints();
+ await ReleaseContinuationPointsAsync();
}
catch (Exception exception)
{
@@ -474,13 +472,13 @@ private void StopBTN_Click(object sender, EventArgs e)
}
}
- private void ReadTypeCB_SelectedIndexChanged(object sender, EventArgs e)
+ private async void ReadTypeCB_SelectedIndexChangedAsync(object sender, EventArgs e)
{
try
{
- ReleaseContinuationPoints();
+ await ReleaseContinuationPointsAsync();
}
- catch (Exception)
+ catch
{
// ignore is ok.
}
diff --git a/Samples/Controls.Net4/Sessions/SecuritySettingsDlg.cs b/Samples/Controls.Net4/Sessions/SecuritySettingsDlg.cs
index 508387747..8d4bd6651 100644
--- a/Samples/Controls.Net4/Sessions/SecuritySettingsDlg.cs
+++ b/Samples/Controls.Net4/Sessions/SecuritySettingsDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -61,10 +61,7 @@ public SecuritySettingsDlg()
SecurityModeCB.Items.Add(value);
}
- foreach (string value in SecurityPolicies.GetDisplayNames())
- {
- SecurityPolicyUriCB.Items.Add(value);
- }
+ SecurityPolicyUriCB.Items.AddRange(SecurityPolicies.GetDisplayNames());
}
///
@@ -74,7 +71,7 @@ public bool ShowDialog(ref MessageSecurityMode securityMode, ref string security
{
// set security mode.
SecurityModeCB.SelectedItem = securityMode;
-
+
// set security policy uri
SecurityPolicyUriCB.SelectedIndex = -1;
@@ -91,11 +88,11 @@ public bool ShowDialog(ref MessageSecurityMode securityMode, ref string security
{
return false;
}
-
- securityMode = (MessageSecurityMode)SecurityModeCB.SelectedItem;
+
+ securityMode = (MessageSecurityMode)SecurityModeCB.SelectedItem;
securityPolicyUri = SecurityPolicies.GetUri((string)SecurityPolicyUriCB.SelectedItem);
- useNativeStack = UseNativeStackCK.Checked;
-
+ useNativeStack = UseNativeStackCK.Checked;
+
return true;
}
diff --git a/Samples/Controls.Net4/Sessions/SelectNodeDlg.cs b/Samples/Controls.Net4/Sessions/SelectNodeDlg.cs
index 0546838b3..356490049 100644
--- a/Samples/Controls.Net4/Sessions/SelectNodeDlg.cs
+++ b/Samples/Controls.Net4/Sessions/SelectNodeDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -39,6 +39,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -65,27 +67,27 @@ public SelectNodeDlg()
#region Private Fields
private ReferenceDescription m_reference;
#endregion
-
+
#region Public Interface
///
/// Displays the dialog.
///
- public ReferenceDescription ShowDialog(Browser browser, NodeId rootId)
+ public async Task ShowDialogAsync(Browser browser, NodeId rootId, CancellationToken ct = default)
{
- if (browser == null) throw new ArgumentNullException("browser");
+ if (browser == null) throw new ArgumentNullException(nameof(browser));
- BrowseCTRL.SetRoot(browser, rootId);
+ await BrowseCTRL.SetRootAsync(browser, rootId, ct);
NamespaceUriCB.Items.Clear();
NamespaceUriCB.Items.AddRange(browser.Session.NamespaceUris.ToArray());
-
+
OkBTN.Enabled = false;
if (ShowDialog() != DialogResult.OK)
{
return null;
}
-
+
return m_reference;
}
#endregion
@@ -134,7 +136,7 @@ private void BrowseCTRL_NodeSelected(object sender, TreeNodeActionEventArgs e)
OkBTN.Enabled = false;
ReferenceDescription reference = e.Node as ReferenceDescription;
-
+
if (reference == null)
{
return;
@@ -146,9 +148,9 @@ private void BrowseCTRL_NodeSelected(object sender, TreeNodeActionEventArgs e)
}
// set the display name.
- DisplayNameTB.Text = reference.ToString();
+ DisplayNameTB.Text = reference.ToString();
NodeClassCB.SelectedItem = (NodeClass)reference.NodeClass;
-
+
// set identifier type.
IdentifierTypeCB.SelectedItem = reference.NodeId.IdType;
@@ -170,7 +172,7 @@ private void BrowseCTRL_NodeSelected(object sender, TreeNodeActionEventArgs e)
NamespaceUriCB.Text = null;
}
}
-
+
// set identifier.
switch (reference.NodeId.IdType)
{
diff --git a/Samples/Controls.Net4/Sessions/SessionOpenDlg.cs b/Samples/Controls.Net4/Sessions/SessionOpenDlg.cs
index 6d73780af..d4d88b23d 100644
--- a/Samples/Controls.Net4/Sessions/SessionOpenDlg.cs
+++ b/Samples/Controls.Net4/Sessions/SessionOpenDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -35,6 +35,7 @@
using System.Reflection;
using System.Text;
using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
namespace Opc.Ua.Sample.Controls
@@ -56,18 +57,18 @@ public SessionOpenDlg()
private IList m_preferredLocales;
private bool m_checkDomain = true;
#endregion
-
+
#region Public Interface
///
/// Displays the dialog.
///
public bool ShowDialog(Session session, IList preferredLocales)
{
- if (session == null) throw new ArgumentNullException("session");
+ if (session == null) throw new ArgumentNullException(nameof(session));
m_session = session;
m_preferredLocales = preferredLocales;
-
+
UserIdentityTypeCB.Items.Clear();
foreach (UserTokenPolicy policy in session.Endpoint.UserIdentityTokens)
@@ -88,7 +89,7 @@ public bool ShowDialog(Session session, IList preferredLocales)
{
SessionNameTB.Text = Utils.Format("MySession {0}", Utils.IncrementIdentifier(ref m_Counter));
}
-
+
if (session.Identity != null)
{
UserIdentityTypeCB.SelectedItem = session.Identity.TokenType;
@@ -98,19 +99,19 @@ public bool ShowDialog(Session session, IList preferredLocales)
{
return false;
}
-
+
return true;
}
#endregion
private void UserIdentityTypeCB_SelectedIndexChanged(object sender, EventArgs e)
- {
+ {
try
{
UserTokenType tokenType = (UserTokenType)UserIdentityTypeCB.SelectedItem;
UserNameCB.Items.Clear();
-
+
UserNameCB.Enabled = true;
PasswordTB.Enabled = true;
@@ -132,7 +133,7 @@ private void UserIdentityTypeCB_SelectedIndexChanged(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -151,7 +152,7 @@ private void OkBTN_Click(object sender, EventArgs e)
{
username = UserNameCB.Text;
}
-
+
if (!String.IsNullOrEmpty(username) || !String.IsNullOrEmpty(PasswordTB.Text))
{
identity = new UserIdentity(username, PasswordTB.Text);
@@ -160,8 +161,8 @@ private void OkBTN_Click(object sender, EventArgs e)
Cursor = Cursors.WaitCursor;
- ThreadPool.QueueUserWorkItem(Open, new object[] { m_session, SessionNameTB.Text, identity, m_preferredLocales, m_checkDomain });
-
+ Task.Run(() => OpenAsync(m_session, SessionNameTB.Text, identity, m_preferredLocales, m_checkDomain));
+
CancelBTN.Enabled = false;
OkBTN.Enabled = false;
}
@@ -169,7 +170,7 @@ private void OkBTN_Click(object sender, EventArgs e)
{
GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
- }
+ }
///
/// Reports the results of the open session operation.
@@ -246,21 +247,15 @@ private void OpenComplete(object e)
///
/// Asynchronously open the session.
///
- private void Open(object state)
+ private async Task OpenAsync(Session session, string sessionName, IUserIdentity identity, IList preferredLocales, bool? checkDomain, CancellationToken ct = default)
{
try
{
- Session session = ((object[])state)[0] as Session;
- string sessionName = ((object[])state)[1] as string;
- IUserIdentity identity = ((object[])state)[2] as IUserIdentity;
- IList preferredLocales = ((object[])state)[3] as IList;
- bool? checkDomain = ((object[])state)[4] as bool?;
-
// open the session.
- session.Open(sessionName, (uint)session.SessionTimeout, identity, preferredLocales, checkDomain ?? true);
+ await session.OpenAsync(sessionName, (uint)session.SessionTimeout, identity, preferredLocales, checkDomain ?? true, ct);
var typeSystemLoader = new ComplexTypeSystem(session);
- typeSystemLoader.Load().Wait();
+ _ = await typeSystemLoader.LoadAsync(ct: ct);
OpenComplete(null);
}
diff --git a/Samples/Controls.Net4/Sessions/SessionTreeCtrl.Designer.cs b/Samples/Controls.Net4/Sessions/SessionTreeCtrl.Designer.cs
index 9389e3811..072b215cc 100644
--- a/Samples/Controls.Net4/Sessions/SessionTreeCtrl.Designer.cs
+++ b/Samples/Controls.Net4/Sessions/SessionTreeCtrl.Designer.cs
@@ -111,7 +111,7 @@ private void InitializeComponent()
this.NewSessionMI.Name = "NewSessionMI";
this.NewSessionMI.Size = new System.Drawing.Size(183, 22);
this.NewSessionMI.Text = "New Session...";
- this.NewSessionMI.Click += new System.EventHandler(this.NewSessionMI_Click);
+ this.NewSessionMI.Click += new System.EventHandler(this.NewSessionMI_ClickAsync);
//
// NewWindowMI
//
@@ -132,14 +132,14 @@ private void InitializeComponent()
this.SessionLoadMI.Name = "SessionLoadMI";
this.SessionLoadMI.Size = new System.Drawing.Size(183, 22);
this.SessionLoadMI.Text = "Load Subscriptions...";
- this.SessionLoadMI.Click += new System.EventHandler(this.SessionLoadMI_Click);
+ this.SessionLoadMI.Click += new System.EventHandler(this.SessionLoadMI_ClickAsync);
//
// DeleteMI
//
this.DeleteMI.Name = "DeleteMI";
this.DeleteMI.Size = new System.Drawing.Size(183, 22);
this.DeleteMI.Text = "Delete";
- this.DeleteMI.Click += new System.EventHandler(this.DeleteMI_Click);
+ this.DeleteMI.Click += new System.EventHandler(this.DeleteMI_ClickAsync);
//
// Separator01
//
@@ -180,28 +180,28 @@ private void InitializeComponent()
this.BrowseServerViewsMI.Name = "BrowseServerViewsMI";
this.BrowseServerViewsMI.Size = new System.Drawing.Size(178, 22);
this.BrowseServerViewsMI.Text = "Server Defined View";
- this.BrowseServerViewsMI.DropDownOpening += new System.EventHandler(this.BrowseServerViewsMI_DropDownOpening);
+ this.BrowseServerViewsMI.DropDownOpening += new System.EventHandler(this.BrowseServerViewsMI_DropDownOpeningAsync);
//
// BrowseObjectTypesMI
//
this.BrowseObjectTypesMI.Name = "BrowseObjectTypesMI";
this.BrowseObjectTypesMI.Size = new System.Drawing.Size(178, 22);
this.BrowseObjectTypesMI.Text = "Object Types...";
- this.BrowseObjectTypesMI.Click += new System.EventHandler(this.BrowseObjectTypesMI_Click);
+ this.BrowseObjectTypesMI.Click += new System.EventHandler(this.BrowseObjectTypesMI_ClickAsync);
//
// BrowseEventTypesMI
//
this.BrowseEventTypesMI.Name = "BrowseEventTypesMI";
this.BrowseEventTypesMI.Size = new System.Drawing.Size(178, 22);
this.BrowseEventTypesMI.Text = "Event Types...";
- this.BrowseEventTypesMI.Click += new System.EventHandler(this.BrowseEventTypesMI_Click);
+ this.BrowseEventTypesMI.Click += new System.EventHandler(this.BrowseEventTypesMI_ClickAsync);
//
// BrowseVariableTypesMI
//
this.BrowseVariableTypesMI.Name = "BrowseVariableTypesMI";
this.BrowseVariableTypesMI.Size = new System.Drawing.Size(178, 22);
this.BrowseVariableTypesMI.Text = "Variable Types...";
- this.BrowseVariableTypesMI.Click += new System.EventHandler(this.BrowseVariableTypesMI_Click);
+ this.BrowseVariableTypesMI.Click += new System.EventHandler(this.BrowseVariableTypesMI_ClickAsync);
//
// BrowseDataTypesMI
//
@@ -232,7 +232,7 @@ private void InitializeComponent()
this.SubscriptionCreateMI.Name = "SubscriptionCreateMI";
this.SubscriptionCreateMI.Size = new System.Drawing.Size(168, 22);
this.SubscriptionCreateMI.Text = "New...";
- this.SubscriptionCreateMI.Click += new System.EventHandler(this.SubscriptionCreateMI_Click);
+ this.SubscriptionCreateMI.Click += new System.EventHandler(this.SubscriptionCreateMI_ClickAsync);
//
// SubscriptionMonitorMI
//
@@ -247,28 +247,28 @@ private void InitializeComponent()
this.SubscriptionEnabledPublishingMI.Name = "SubscriptionEnabledPublishingMI";
this.SubscriptionEnabledPublishingMI.Size = new System.Drawing.Size(168, 22);
this.SubscriptionEnabledPublishingMI.Text = "Enable Publishing";
- this.SubscriptionEnabledPublishingMI.Click += new System.EventHandler(this.SubscriptionEnabledPublishingMI_Click);
+ this.SubscriptionEnabledPublishingMI.Click += new System.EventHandler(this.SubscriptionEnabledPublishingMI_ClickAsync);
//
// ReadMI
//
this.ReadMI.Name = "ReadMI";
this.ReadMI.Size = new System.Drawing.Size(183, 22);
this.ReadMI.Text = "Read...";
- this.ReadMI.Click += new System.EventHandler(this.ReadMI_Click);
+ this.ReadMI.Click += new System.EventHandler(this.ReadMI_ClickAsync);
//
// WriteMI
//
this.WriteMI.Name = "WriteMI";
this.WriteMI.Size = new System.Drawing.Size(183, 22);
this.WriteMI.Text = "Write...";
- this.WriteMI.Click += new System.EventHandler(this.WriteMI_Click);
+ this.WriteMI.Click += new System.EventHandler(this.WriteMI_ClickAsync);
//
// SetLocaleMI
//
this.SetLocaleMI.Name = "SetLocaleMI";
this.SetLocaleMI.Size = new System.Drawing.Size(183, 22);
this.SetLocaleMI.Text = "Set Locale...";
- this.SetLocaleMI.Click += new System.EventHandler(this.SetLocaleMI_Click);
+ this.SetLocaleMI.Click += new System.EventHandler(this.SetLocaleMI_ClickAsync);
//
// SessionTreeCtrl
//
diff --git a/Samples/Controls.Net4/Sessions/SessionTreeCtrl.cs b/Samples/Controls.Net4/Sessions/SessionTreeCtrl.cs
index 0b9cb6dbe..4aa6a48db 100644
--- a/Samples/Controls.Net4/Sessions/SessionTreeCtrl.cs
+++ b/Samples/Controls.Net4/Sessions/SessionTreeCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -37,6 +37,7 @@
using Opc.Ua.Client.Controls;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -98,7 +99,7 @@ public ServiceMessageContext MessageContext
///
/// Closes all open sessions within the control.
///
- public void Close()
+ public async Task CloseAsync(CancellationToken ct = default)
{
// close any dialogs.
foreach (SubscriptionDlg dialog in new List(m_dialogs.Values))
@@ -113,17 +114,17 @@ public void Close()
if (session != null)
{
- session.Close();
+ await session.CloseAsync(ct);
}
}
- Clear();
+ await ClearAsync(ct);
}
///
/// Clears the contents of the control,
///
- public void Clear()
+ public async Task ClearAsync(CancellationToken ct = default)
{
// close all active sessions.
foreach (TreeNode root in NodesTV.Nodes)
@@ -132,7 +133,7 @@ public void Clear()
if (session != null)
{
- session.Close();
+ await session.CloseAsync(ct);
}
}
@@ -169,9 +170,9 @@ public ToolStripStatusLabel ServerStatusCtrl
///
/// Creates a session with the endpoint.
///
- public async Task Connect(ConfiguredEndpoint endpoint)
+ public async Task ConnectAsync(ConfiguredEndpoint endpoint, CancellationToken ct = default)
{
- if (endpoint == null) throw new ArgumentNullException("endpoint");
+ if (endpoint == null) throw new ArgumentNullException(nameof(endpoint));
EndpointDescriptionCollection availableEndpoints = null;
@@ -204,7 +205,7 @@ public async Task Connect(ConfiguredEndpoint endpoint)
throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ApplicationCertificate must be specified.");
}
- clientCertificate = await m_configuration.SecurityConfiguration.ApplicationCertificate.Find(true);
+ clientCertificate = await m_configuration.SecurityConfiguration.ApplicationCertificate.FindAsync(true, ct: ct);
if (clientCertificate == null)
{
@@ -214,7 +215,7 @@ public async Task Connect(ConfiguredEndpoint endpoint)
// load certificate chain
clientCertificateChain = new X509Certificate2Collection(clientCertificate);
List issuers = new List();
- await m_configuration.CertificateValidator.GetIssuers(clientCertificate, issuers);
+ await m_configuration.CertificateValidator.GetIssuersAsync(clientCertificate, issuers);
for (int i = 0; i < issuers.Count; i++)
{
clientCertificateChain.Add(issuers[i].Certificate);
@@ -231,15 +232,15 @@ public async Task Connect(ConfiguredEndpoint endpoint)
m_messageContext);
// create the session.
- return Connect(endpoint, channel, availableEndpoints);
+ return await ConnectAsync(endpoint, channel, availableEndpoints, ct);
}
///
/// Opens a new session.
///
- public Session Connect(ConfiguredEndpoint endpoint, ITransportChannel channel, EndpointDescriptionCollection availableEndpoints)
+ public async Task ConnectAsync(ConfiguredEndpoint endpoint, ITransportChannel channel, EndpointDescriptionCollection availableEndpoints, CancellationToken ct = default)
{
- if (channel == null) throw new ArgumentNullException("channel");
+ if (channel == null) throw new ArgumentNullException(nameof(channel));
try
{
@@ -256,7 +257,7 @@ public Session Connect(ConfiguredEndpoint endpoint, ITransportChannel channel, E
channel = null;
// delete the existing session.
- Close();
+ await CloseAsync(ct);
// add session to tree.
AddNode(session);
@@ -277,9 +278,9 @@ public Session Connect(ConfiguredEndpoint endpoint, ITransportChannel channel, E
///
/// Deletes a session.
///
- public void Delete(Session session)
+ public async Task DeleteAsync(Session session, CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
+ if (session == null) throw new ArgumentNullException(nameof(session));
TreeNode node = FindNode(NodesTV.Nodes, session);
@@ -295,7 +296,7 @@ public void Delete(Session session)
dialog.Close();
}
- session.Close();
+ await session.CloseAsync(ct);
NodesTV.SelectedNode = null;
SelectNode();
}
@@ -303,9 +304,9 @@ public void Delete(Session session)
///
/// Deletes a subscription.
///
- public void Delete(Subscription subscription)
+ public async Task DeleteAsync(Subscription subscription, CancellationToken ct = default)
{
- if (subscription == null) throw new ArgumentNullException("subscription");
+ if (subscription == null) throw new ArgumentNullException(nameof(subscription));
// close any dialog.
SubscriptionDlg dialog = null;
@@ -316,7 +317,7 @@ public void Delete(Subscription subscription)
}
Session session = subscription.Session as Session;
- session.RemoveSubscription(subscription);
+ await session.RemoveSubscriptionAsync(subscription, ct);
TreeNode node = FindNode(NodesTV.Nodes, subscription);
@@ -332,9 +333,9 @@ public void Delete(Subscription subscription)
///
/// Deletes a monitored item.
///
- public void Delete(MonitoredItem monitoredItem)
+ public async Task DeleteAsync(MonitoredItem monitoredItem, CancellationToken ct = default)
{
- if (monitoredItem == null) throw new ArgumentNullException("monitoredItem");
+ if (monitoredItem == null) throw new ArgumentNullException(nameof(monitoredItem));
TreeNode node = FindNode(NodesTV.Nodes, monitoredItem);
@@ -346,21 +347,21 @@ public void Delete(MonitoredItem monitoredItem)
Subscription subscription = monitoredItem.Subscription;
subscription.RemoveItem(monitoredItem);
- subscription.ApplyChanges();
+ await subscription.ApplyChangesAsync(ct);
NodesTV.SelectedNode = FindNode(NodesTV.Nodes, subscription);
}
///
/// Creates a new subscription.
///
- public Subscription CreateSubscription(Session session)
+ public async Task CreateSubscriptionAsync(Session session, CancellationToken ct = default)
{
// create form.
SubscriptionDlg dialog = new SubscriptionDlg();
dialog.FormClosing += new FormClosingEventHandler(Subscription_FormClosing);
// create subscription.
- Subscription subscription = dialog.New(session);
+ Subscription subscription = await dialog.NewAsync(session, ct);
if (subscription != null)
{
@@ -480,7 +481,7 @@ protected override void SelectNode()
// update address space control.
if (m_AddressSpaceCtrl != null)
{
- m_AddressSpaceCtrl.SetView(session, BrowseViewType.Objects, null);
+ m_AddressSpaceCtrl.SetViewAsync(session, BrowseViewType.Objects, null);
}
// update notification messages control.
@@ -613,7 +614,7 @@ private TreeNode FindChild(TreeNodeCollection collection, object tag, object chi
///
private void AddNode(Session session)
{
- if (session == null) throw new ArgumentNullException("session");
+ if (session == null) throw new ArgumentNullException(nameof(session));
TreeNode node = AddNode(null, session, session.SessionName, "Server");
UpdateNode(node, session);
@@ -672,7 +673,7 @@ private void UpdateNode(TreeNode parent, Subscription subscription)
AddNode(parent, monitoredItem, monitoredItem.DisplayName, "Property");
}
}
- #endregion
+ #endregion
private void BrowseAllMI_Click(object sender, EventArgs e)
{
@@ -726,7 +727,7 @@ private void BrowseObjectsMI_Click(object sender, EventArgs e)
}
}
- private void BrowseObjectTypesMI_Click(object sender, EventArgs e)
+ private async void BrowseObjectTypesMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -743,7 +744,7 @@ private void BrowseObjectTypesMI_Click(object sender, EventArgs e)
if (session != null)
{
- new BrowseTypesDlg().Show(session, ObjectTypeIds.BaseObjectType);
+ await new BrowseTypesDlg().ShowAsync(session, ObjectTypeIds.BaseObjectType);
}
}
catch (Exception exception)
@@ -752,7 +753,7 @@ private void BrowseObjectTypesMI_Click(object sender, EventArgs e)
}
}
- private void BrowseVariableTypesMI_Click(object sender, EventArgs e)
+ private async void BrowseVariableTypesMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -769,7 +770,7 @@ private void BrowseVariableTypesMI_Click(object sender, EventArgs e)
if (session != null)
{
- new BrowseTypesDlg().Show(session, VariableTypeIds.BaseDataVariableType);
+ await new BrowseTypesDlg().ShowAsync(session, VariableTypeIds.BaseDataVariableType);
}
}
catch (Exception exception)
@@ -830,7 +831,7 @@ private void BrowseReferenceTypesMI_Click(object sender, EventArgs e)
}
}
- private void BrowseEventTypesMI_Click(object sender, EventArgs e)
+ private async void BrowseEventTypesMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -847,7 +848,7 @@ private void BrowseEventTypesMI_Click(object sender, EventArgs e)
if (session != null)
{
- new BrowseTypesDlg().Show(session, ObjectTypeIds.BaseEventType);
+ await new BrowseTypesDlg().ShowAsync(session, ObjectTypeIds.BaseEventType);
}
}
catch (Exception exception)
@@ -856,7 +857,7 @@ private void BrowseEventTypesMI_Click(object sender, EventArgs e)
}
}
- private void BrowseServerViewsMI_DropDownOpening(object sender, EventArgs e)
+ private async void BrowseServerViewsMI_DropDownOpeningAsync(object sender, EventArgs e)
{
try
{
@@ -883,7 +884,7 @@ private void BrowseServerViewsMI_DropDownOpening(object sender, EventArgs e)
browser.NodeClassMask = (int)NodeClass.View;
browser.ContinueUntilDone = true;
- ReferenceDescriptionCollection references = browser.Browse(Objects.ViewsFolder);
+ ReferenceDescriptionCollection references = await browser.BrowseAsync(Objects.ViewsFolder);
foreach (ReferenceDescription reference in references)
{
@@ -935,7 +936,7 @@ void BrowseServerViewsMI_Click(object sender, EventArgs e)
}
}
- private void SubscriptionCreateMI_Click(object sender, EventArgs e)
+ private async void SubscriptionCreateMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -956,7 +957,7 @@ private void SubscriptionCreateMI_Click(object sender, EventArgs e)
}
// create the subscription.
- CreateSubscription(session);
+ await CreateSubscriptionAsync(session);
}
catch (Exception exception)
{
@@ -964,7 +965,7 @@ private void SubscriptionCreateMI_Click(object sender, EventArgs e)
}
}
- void Subscription_FormClosing(object sender, FormClosingEventArgs e)
+ private void Subscription_FormClosing(object sender, FormClosingEventArgs e)
{
foreach (KeyValuePair current in m_dialogs)
{
@@ -976,11 +977,11 @@ void Subscription_FormClosing(object sender, FormClosingEventArgs e)
}
}
- private async void NewSessionMI_Click(object sender, EventArgs e)
+ private async void NewSessionMI_ClickAsync(object sender, EventArgs e)
{
try
{
- await Connect(m_endpoint);
+ await ConnectAsync(m_endpoint);
}
catch (Exception exception)
{
@@ -988,7 +989,7 @@ private async void NewSessionMI_Click(object sender, EventArgs e)
}
}
- private void DeleteMI_Click(object sender, EventArgs e)
+ private async void DeleteMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -1005,7 +1006,7 @@ private void DeleteMI_Click(object sender, EventArgs e)
if (session != null)
{
- Delete(session);
+ await DeleteAsync(session);
}
// delete subscription
@@ -1013,7 +1014,7 @@ private void DeleteMI_Click(object sender, EventArgs e)
if (subscription != null)
{
- Delete(subscription);
+ await DeleteAsync(subscription);
}
// delete monitored item
@@ -1021,7 +1022,7 @@ private void DeleteMI_Click(object sender, EventArgs e)
if (monitoredItem != null)
{
- Delete(monitoredItem);
+ await DeleteAsync(monitoredItem);
}
}
catch (Exception exception)
@@ -1030,7 +1031,7 @@ private void DeleteMI_Click(object sender, EventArgs e)
}
}
- private void ReadMI_Click(object sender, EventArgs e)
+ private async void ReadMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -1079,7 +1080,7 @@ private void ReadMI_Click(object sender, EventArgs e)
}
// show form.
- new ReadDlg().Show(session, valueIds);
+ await new ReadDlg().ShowAsync(session, valueIds);
}
catch (Exception exception)
{
@@ -1087,7 +1088,7 @@ private void ReadMI_Click(object sender, EventArgs e)
}
}
- private void WriteMI_Click(object sender, EventArgs e)
+ private async void WriteMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -1148,7 +1149,7 @@ private void WriteMI_Click(object sender, EventArgs e)
}
// show form.
- new WriteDlg().Show(session, values);
+ await new WriteDlg().ShowAsync(session, values);
}
catch (Exception exception)
{
@@ -1156,7 +1157,7 @@ private void WriteMI_Click(object sender, EventArgs e)
}
}
- private void SubscriptionEnabledPublishingMI_Click(object sender, EventArgs e)
+ private async void SubscriptionEnabledPublishingMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -1173,7 +1174,7 @@ private void SubscriptionEnabledPublishingMI_Click(object sender, EventArgs e)
if (subscription != null)
{
- subscription.SetPublishingMode(SubscriptionEnabledPublishingMI.Checked);
+ await subscription.SetPublishingModeAsync(SubscriptionEnabledPublishingMI.Checked);
}
}
catch (Exception exception)
@@ -1268,7 +1269,7 @@ private void SessionSaveMI_Click(object sender, EventArgs e)
}
}
- private void SessionLoadMI_Click(object sender, EventArgs e)
+ private async void SessionLoadMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -1322,7 +1323,7 @@ private void SessionLoadMI_Click(object sender, EventArgs e)
{
foreach (Subscription subscription in subscriptions)
{
- subscription.Create();
+ await subscription.CreateAsync();
}
}
}
@@ -1349,7 +1350,7 @@ private void NewWindowMI_Click(object sender, EventArgs e)
}
}
- private void SetLocaleMI_Click(object sender, EventArgs e)
+ private async void SetLocaleMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -1361,7 +1362,7 @@ private void SetLocaleMI_Click(object sender, EventArgs e)
return;
}
- string locale = new SelectLocaleDlg().ShowDialog(session);
+ string locale = await new SelectLocaleDlg().ShowDialogAsync(session);
if (locale == null)
{
@@ -1369,7 +1370,7 @@ private void SetLocaleMI_Click(object sender, EventArgs e)
}
PreferredLocales = new string[] { locale };
- session.ChangePreferredLocales(new StringCollection(PreferredLocales));
+ await session.ChangePreferredLocalesAsync(new StringCollection(PreferredLocales), CancellationToken.None);
}
catch (Exception exception)
{
diff --git a/Samples/Controls.Net4/Sessions/TypeHierarchyListCtrl.cs b/Samples/Controls.Net4/Sessions/TypeHierarchyListCtrl.cs
index b9c72d4fa..c1badc6bc 100644
--- a/Samples/Controls.Net4/Sessions/TypeHierarchyListCtrl.cs
+++ b/Samples/Controls.Net4/Sessions/TypeHierarchyListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -38,6 +38,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample
{
@@ -47,35 +49,35 @@ public partial class TypeHierarchyListCtrl : Opc.Ua.Client.Controls.BaseListCtrl
public TypeHierarchyListCtrl()
{
InitializeComponent();
- SetColumns(m_ColumnNames);
+ SetColumns(m_ColumnNames);
}
- #endregion
+ #endregion
#region Private Fields
private Session m_session;
- // The columns to display in the control.
- private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Name", HorizontalAlignment.Left, null },
- new object[] { "Type", HorizontalAlignment.Left, null },
- new object[] { "Description", HorizontalAlignment.Left, null }
- };
+ // The columns to display in the control.
+ private readonly object[][] m_ColumnNames = new object[][]
+ {
+ new object[] { "Name", HorizontalAlignment.Left, null },
+ new object[] { "Type", HorizontalAlignment.Left, null },
+ new object[] { "Description", HorizontalAlignment.Left, null }
+ };
- private class InstanceDeclaration
+ private sealed class InstanceDeclaration
{
public ILocalNode Instance;
public string DisplayPath;
public string DataType;
public string Description;
}
- #endregion
+ #endregion
#region Public Interface
///
/// Initializes the control.
///
- public void Initialize(Session session, NodeId typeId)
+ public async Task InitializeAsync(Session session, NodeId typeId, CancellationToken ct = default)
{
ItemsLV.Items.Clear();
AdjustColumns();
@@ -85,29 +87,29 @@ public void Initialize(Session session, NodeId typeId)
return;
}
- ILocalNode root = session.NodeCache.Find(typeId) as ILocalNode;
+ ILocalNode root = await session.NodeCache.FindAsync(typeId, ct) as ILocalNode;
if (root == null)
{
return;
}
-
+
m_session = session;
- SortedDictionary instances = new SortedDictionary();
-
+ SortedDictionary instances = new SortedDictionary();
+
InstanceDeclaration declaration = new InstanceDeclaration();
declaration.Instance = root;
declaration.DisplayPath = Utils.Format("({0})", root.NodeClass);
declaration.Description = Utils.Format("{0}", root.Description);
declaration.DataType = "NodeId";
-
+
IVariableBase variable = root as IVariableBase;
if (variable != null)
{
- INode dataType = m_session.NodeCache.Find(variable.DataType);
+ INode dataType = await m_session.NodeCache.FindAsync(variable.DataType, ct);
if (dataType != null)
{
@@ -118,39 +120,39 @@ public void Initialize(Session session, NodeId typeId)
{
declaration.DataType += "[]";
}
- }
+ }
instances.Add(declaration.DisplayPath, declaration);
- CollectInstances(root, String.Empty, instances);
+ await CollectInstancesAsync(root, String.Empty, instances, ct);
foreach (InstanceDeclaration instance in instances.Values)
{
AddItem(instance);
}
-
+
AdjustColumns();
}
#endregion
-
+
#region Overridden Methods
///
- protected override void UpdateItem(ListViewItem listItem, object item)
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
{
InstanceDeclaration instance = item as InstanceDeclaration;
- if (instance == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
-
- listItem.SubItems[0].Text = instance.DisplayPath;
- listItem.SubItems[1].Text = instance.DataType;
- listItem.SubItems[2].Text = instance.Description;
-
- listItem.ImageKey = GuiUtils.GetTargetIcon(m_session, instance.Instance.NodeClass, instance.Instance.TypeDefinitionId);
- listItem.Tag = item;
+ if (instance == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
+
+ listItem.SubItems[0].Text = instance.DisplayPath;
+ listItem.SubItems[1].Text = instance.DataType;
+ listItem.SubItems[2].Text = instance.Description;
+
+ listItem.ImageKey = await GuiUtils.GetTargetIconAsync(m_session, instance.Instance.NodeClass, instance.Instance.TypeDefinitionId, ct);
+ listItem.Tag = item;
}
#endregion
@@ -158,8 +160,8 @@ protected override void UpdateItem(ListViewItem listItem, object item)
///
/// Collects the instance declarations to display in the control.
///
- private void CollectInstances(ILocalNode parent, string basePath, SortedDictionary instances)
- {
+ private async Task CollectInstancesAsync(ILocalNode parent, string basePath, SortedDictionary instances, CancellationToken ct = default)
+ {
if (parent == null)
{
return;
@@ -173,14 +175,14 @@ private void CollectInstances(ILocalNode parent, string basePath, SortedDictiona
for (int ii = 0; ii < supertypes.Count; ii++)
{
- ILocalNode supertype = m_session.NodeCache.Find(supertypes[ii].TargetId) as ILocalNode;
+ ILocalNode supertype = await m_session.NodeCache.FindAsync(supertypes[ii].TargetId, ct) as ILocalNode;
if (supertype == null)
{
continue;
}
- CollectInstances(supertype, basePath, instances);
+ await CollectInstancesAsync(supertype, basePath, instances, ct);
}
IList children = parent.References.Find(
@@ -191,7 +193,7 @@ private void CollectInstances(ILocalNode parent, string basePath, SortedDictiona
for (int ii = 0; ii < children.Count; ii++)
{
- ILocalNode child = m_session.NodeCache.Find(children[ii].TargetId) as ILocalNode;
+ ILocalNode child = await m_session.NodeCache.FindAsync(children[ii].TargetId, ct) as ILocalNode;
if (child == null)
{
@@ -209,12 +211,12 @@ private void CollectInstances(ILocalNode parent, string basePath, SortedDictiona
}
string displayPath = Utils.Format("{0}", child);
-
+
if (!String.IsNullOrEmpty(basePath))
{
displayPath = Utils.Format("{0}/{1}", basePath, displayPath);
}
-
+
InstanceDeclaration declaration = new InstanceDeclaration();
declaration.Instance = child;
@@ -226,7 +228,7 @@ private void CollectInstances(ILocalNode parent, string basePath, SortedDictiona
if (variable != null)
{
- INode dataType = m_session.NodeCache.Find(variable.DataType);
+ INode dataType = await m_session.NodeCache.FindAsync(variable.DataType, ct);
if (dataType != null)
{
@@ -238,16 +240,16 @@ private void CollectInstances(ILocalNode parent, string basePath, SortedDictiona
declaration.DataType += "[]";
}
}
-
+
IObject objectn = child as IObject;
if (objectn != null)
- {
+ {
declaration.DataType = "NodeId";
}
instances[displayPath] = declaration;
- CollectInstances(child, displayPath, instances);
+ await CollectInstancesAsync(child, displayPath, instances, ct);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Sessions/TypeNavigatorCtrl.Designer.cs b/Samples/Controls.Net4/Sessions/TypeNavigatorCtrl.Designer.cs
index be9cfffed..8f18cbb8d 100644
--- a/Samples/Controls.Net4/Sessions/TypeNavigatorCtrl.Designer.cs
+++ b/Samples/Controls.Net4/Sessions/TypeNavigatorCtrl.Designer.cs
@@ -87,7 +87,7 @@ private void InitializeComponent()
this.RootBTN.Size = new System.Drawing.Size(45, 21);
this.RootBTN.Text = "Root";
this.RootBTN.ToolTipText = "Root";
- this.RootBTN.DropDownOpening += new System.EventHandler(this.RootBTN_DropDownOpening);
+ this.RootBTN.DropDownOpening += new System.EventHandler(this.RootBTN_DropDownOpeningAsync);
this.RootBTN.Click += new System.EventHandler(this.RootBTN_Click);
//
// childToolStripMenuItem
diff --git a/Samples/Controls.Net4/Sessions/TypeNavigatorCtrl.cs b/Samples/Controls.Net4/Sessions/TypeNavigatorCtrl.cs
index 32e432c32..9058f0e4f 100644
--- a/Samples/Controls.Net4/Sessions/TypeNavigatorCtrl.cs
+++ b/Samples/Controls.Net4/Sessions/TypeNavigatorCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -38,6 +38,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample
{
@@ -49,12 +51,12 @@ public TypeNavigatorCtrl()
InitializeComponent();
}
#endregion
-
+
#region Private Fields
private Session m_session;
private event TypeNavigatorEventHandler m_TypeSelected;
#endregion
-
+
#region Public Interface
///
/// Raised when a type is selected in the control.
@@ -68,7 +70,7 @@ public event TypeNavigatorEventHandler TypeSelected
///
/// Initializes the control.
///
- public void Initialize(Session session, NodeId typeId)
+ public async Task InitializeAsync(Session session, NodeId typeId, CancellationToken ct = default)
{
if (session == null)
{
@@ -76,7 +78,7 @@ public void Initialize(Session session, NodeId typeId)
return;
}
- ILocalNode root = session.NodeCache.Find(typeId) as ILocalNode;
+ ILocalNode root = await session.NodeCache.FindAsync(typeId, ct) as ILocalNode;
if (root == null)
{
@@ -103,7 +105,7 @@ private void RootBTN_Click(object sender, EventArgs e)
{
return;
}
-
+
ILocalNode node = button.Tag as ILocalNode;
if (node == null)
@@ -129,11 +131,11 @@ private void RootBTN_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void RootBTN_DropDownOpening(object sender, EventArgs e)
+ private async void RootBTN_DropDownOpeningAsync(object sender, EventArgs e)
{
try
{
@@ -152,7 +154,7 @@ private void RootBTN_DropDownOpening(object sender, EventArgs e)
{
return;
}
-
+
IList subtypes = node.References.Find(
ReferenceTypeIds.HasSubtype,
false,
@@ -161,7 +163,7 @@ private void RootBTN_DropDownOpening(object sender, EventArgs e)
for (int ii = 0; ii < subtypes.Count; ii++)
{
- ILocalNode subtype = m_session.NodeCache.Find(subtypes[ii].TargetId) as ILocalNode;
+ ILocalNode subtype = await m_session.NodeCache.FindAsync(subtypes[ii].TargetId) as ILocalNode;
if (subtype == null)
{
@@ -185,11 +187,11 @@ private void RootBTN_DropDownOpening(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- void ChildBTN_Click(object sender, EventArgs e)
+ private void ChildBTN_Click(object sender, EventArgs e)
{
try
{
@@ -199,13 +201,13 @@ void ChildBTN_Click(object sender, EventArgs e)
{
return;
}
-
+
ILocalNode node = menuItem.Tag as ILocalNode;
if (node == null)
{
return;
- }
+ }
bool found = false;
@@ -222,21 +224,21 @@ void ChildBTN_Click(object sender, EventArgs e)
TypePathCTRL.Items.Remove(TypePathCTRL.Items[ii]);
}
}
-
+
if (!found)
{
return;
}
string text = Utils.Format("{0}", node.DisplayName);
-
+
ToolStripDropDownButton button = new ToolStripDropDownButton(text);
button.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
button.Name = Utils.Format("Type{0}BTN", TypePathCTRL.Items.Count);
button.Size = new System.Drawing.Size(48, 21);
button.Text = Utils.Format("{0}", node.DisplayName);
- button.DropDownOpening += RootBTN_DropDownOpening;
+ button.DropDownOpening += RootBTN_DropDownOpeningAsync;
button.Click += RootBTN_Click;
button.Tag = node;
@@ -249,7 +251,7 @@ void ChildBTN_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Subscriptions/ContentFilterElementListCtrl.Designer.cs b/Samples/Controls.Net4/Subscriptions/ContentFilterElementListCtrl.Designer.cs
index d9d231b6b..a348c096e 100644
--- a/Samples/Controls.Net4/Subscriptions/ContentFilterElementListCtrl.Designer.cs
+++ b/Samples/Controls.Net4/Subscriptions/ContentFilterElementListCtrl.Designer.cs
@@ -97,7 +97,7 @@ private void InitializeComponent()
this.SelectNodeMI.Name = "SelectEventTypeMI";
this.SelectNodeMI.Size = new System.Drawing.Size(161, 22);
this.SelectNodeMI.Text = "Select Node...";
- this.SelectNodeMI.Click += new System.EventHandler(this.SelectNodeMI_Click);
+ this.SelectNodeMI.Click += new System.EventHandler(this.SelectNodeMI_ClickAsync);
//
// CreateElementMI
//
diff --git a/Samples/Controls.Net4/Subscriptions/ContentFilterElementListCtrl.cs b/Samples/Controls.Net4/Subscriptions/ContentFilterElementListCtrl.cs
index 9aff0da3a..9eeb0f63f 100644
--- a/Samples/Controls.Net4/Subscriptions/ContentFilterElementListCtrl.cs
+++ b/Samples/Controls.Net4/Subscriptions/ContentFilterElementListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -38,6 +38,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading;
+using System.Threading.Tasks;
namespace Opc.Ua.Sample.Controls
{
@@ -45,8 +47,8 @@ public partial class ContentFilterElementListCtrl : Opc.Ua.Client.Controls.BaseL
{
public ContentFilterElementListCtrl()
{
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
}
#region Private Fields
@@ -58,11 +60,11 @@ public ContentFilterElementListCtrl()
/// The columns to display in the control.
///
private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Index", HorizontalAlignment.Left, null },
- new object[] { "Expression", HorizontalAlignment.Left, null }
- };
- #endregion
+ {
+ new object[] { "Index", HorizontalAlignment.Left, null },
+ new object[] { "Expression", HorizontalAlignment.Left, null }
+ };
+ #endregion
#region Public Interface
///
@@ -79,17 +81,17 @@ public void Clear()
///
public void Initialize(Session session, ContentFilter filter)
{
- if (session == null) throw new ArgumentNullException("session");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
Clear();
-
+
m_session = session;
m_browser = new Browser(session);
- m_filter = filter;
+ m_filter = filter;
if (m_filter == null)
{
- return;
+ return;
}
foreach (ContentFilterElement element in filter.Elements)
@@ -106,7 +108,7 @@ public void Initialize(Session session, ContentFilter filter)
public ContentFilter GetFilter()
{
ContentFilter filter = new ContentFilter();
-
+
for (int ii = 0; ii < ItemsLV.Items.Count; ii++)
{
ContentFilterElement element = ItemsLV.Items[ii].Tag as ContentFilterElement;
@@ -126,7 +128,7 @@ public ContentFilter GetFilter()
public List GetElements()
{
List elements = new List();
-
+
for (int ii = 0; ii < ItemsLV.Items.Count; ii++)
{
ContentFilterElement element = ItemsLV.Items[ii].Tag as ContentFilterElement;
@@ -144,41 +146,41 @@ public List GetElements()
#region Overridden Methods
///
protected override void EnableMenuItems(ListViewItem clickedItem)
- {
- SetOperatorMI.Enabled = ItemsLV.SelectedItems.Count == 1;
- SelectNodeMI.Enabled = true;
- EditValueMI.Enabled = ItemsLV.SelectedItems.Count == 1;
- DeleteMI.Enabled = ItemsLV.SelectedItems.Count > 0;
- CreateElementMI.Enabled = ItemsLV.SelectedItems.Count > 0;
+ {
+ SetOperatorMI.Enabled = ItemsLV.SelectedItems.Count == 1;
+ SelectNodeMI.Enabled = true;
+ EditValueMI.Enabled = ItemsLV.SelectedItems.Count == 1;
+ DeleteMI.Enabled = ItemsLV.SelectedItems.Count > 0;
+ CreateElementMI.Enabled = ItemsLV.SelectedItems.Count > 0;
CreateElementAndMI.Enabled = ItemsLV.SelectedItems.Count == 2;
- CreateElementOrMI.Enabled = ItemsLV.SelectedItems.Count == 2;
+ CreateElementOrMI.Enabled = ItemsLV.SelectedItems.Count == 2;
CreateElementNotMI.Enabled = ItemsLV.SelectedItems.Count == 1;
- }
-
- ///
- protected override void UpdateItem(ListViewItem listItem, object item, int index)
+ }
+
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, int index, CancellationToken ct = default)
{
- ContentFilterElement element = item as ContentFilterElement;
-
- if (element == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
-
+ ContentFilterElement element = item as ContentFilterElement;
+
+ if (element == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
+
listItem.SubItems[0].Text = String.Format("[{0}]", index);
- listItem.SubItems[1].Text = String.Format("{0}", element.ToString(m_session.NodeCache));
-
+ listItem.SubItems[1].Text = String.Format("{0}", element.ToString(m_session.NodeCache.AsNodeTable()));
+
listItem.Tag = element;
}
#endregion
-
+
#region Event Handlers
///
/// Updates the control with a new filter.
///
private void Update(ContentFilter filter)
- {
+ {
BeginUpdate();
int index = 0;
@@ -187,7 +189,7 @@ private void Update(ContentFilter filter)
{
AddItem(element, "Property", index++);
}
-
+
EndUpdate();
AdjustColumns();
@@ -209,15 +211,15 @@ private void SetOperatorMI_Click(object sender, EventArgs e)
if (!new FilterOperatorEditDlg().ShowDialog(ref op))
{
return;
- }
+ }
element.FilterOperator = op;
- UpdateItem(ItemsLV.SelectedItems[0], element);
+ UpdateItemAsync(ItemsLV.SelectedItems[0], element);
AdjustColumns();
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -230,25 +232,25 @@ private void DeleteMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void SelectNodeMI_Click(object sender, EventArgs e)
+ private async void SelectNodeMI_ClickAsync(object sender, EventArgs e)
{
try
{
- ReferenceDescription reference = new SelectNodeDlg().ShowDialog(m_browser, ObjectTypes.BaseEventType);
+ ReferenceDescription reference = await new SelectNodeDlg().ShowDialogAsync(m_browser, ObjectTypes.BaseEventType);
if (reference != null)
{
- Node node = m_session.NodeCache.Find(reference.NodeId) as Node;
+ Node node = await m_session.NodeCache.FindAsync(reference.NodeId) as Node;
if (node == null)
{
return;
}
-
+
ContentFilterElement element = null;
// build the relative path.
@@ -268,7 +270,7 @@ private void SelectNodeMI_Click(object sender, EventArgs e)
// create attribute operand.
SimpleAttributeOperand attribute = new SimpleAttributeOperand(
- m_session.FilterContext,
+ m_session.FilterContext,
typeId,
browsePath);
@@ -284,7 +286,7 @@ private void SelectNodeMI_Click(object sender, EventArgs e)
{
// create attribute operand.
SimpleAttributeOperand attribute = new SimpleAttributeOperand(
- m_session.FilterContext,
+ m_session.FilterContext,
typeId,
browsePath);
@@ -317,7 +319,7 @@ private void SelectNodeMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -329,10 +331,10 @@ private void CreateElementAndMI_Click(object sender, EventArgs e)
{
return;
}
-
+
ContentFilterElement element1 = ItemsLV.SelectedItems[0].Tag as ContentFilterElement;
ContentFilterElement element2 = ItemsLV.SelectedItems[1].Tag as ContentFilterElement;
-
+
ContentFilter filter = GetFilter();
filter.Push(FilterOperator.And, element1, element2);
@@ -340,7 +342,7 @@ private void CreateElementAndMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -352,10 +354,10 @@ private void CreateElementOrMI_Click(object sender, EventArgs e)
{
return;
}
-
+
ContentFilterElement element1 = ItemsLV.SelectedItems[0].Tag as ContentFilterElement;
ContentFilterElement element2 = ItemsLV.SelectedItems[1].Tag as ContentFilterElement;
-
+
ContentFilter filter = GetFilter();
filter.Push(FilterOperator.Or, element1, element2);
@@ -363,7 +365,7 @@ private void CreateElementOrMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -375,7 +377,7 @@ private void CreateElementNotMI_Click(object sender, EventArgs e)
{
return;
}
-
+
ContentFilterElement element1 = ItemsLV.SelectedItems[0].Tag as ContentFilterElement;
ContentFilter filter = GetFilter();
@@ -385,10 +387,10 @@ private void CreateElementNotMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
-
+
private void EditValueMI_Click(object sender, EventArgs e)
{
try
@@ -404,7 +406,7 @@ private void EditValueMI_Click(object sender, EventArgs e)
if (operands.Count != 2)
{
- return;
+ return;
}
LiteralOperand literal = operands[1] as LiteralOperand;
@@ -437,7 +439,7 @@ private void EditValueMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Subscriptions/CreateMonitoredItemsDlg.Designer.cs b/Samples/Controls.Net4/Subscriptions/CreateMonitoredItemsDlg.Designer.cs
index a434e38ee..b56cdc51e 100644
--- a/Samples/Controls.Net4/Subscriptions/CreateMonitoredItemsDlg.Designer.cs
+++ b/Samples/Controls.Net4/Subscriptions/CreateMonitoredItemsDlg.Designer.cs
@@ -103,7 +103,7 @@ private void InitializeComponent()
this.ApplyBTN.TabIndex = 4;
this.ApplyBTN.Text = "Apply";
this.ApplyBTN.UseVisualStyleBackColor = true;
- this.ApplyBTN.Click += new System.EventHandler(this.ApplyBTN_Click);
+ this.ApplyBTN.Click += new System.EventHandler(this.ApplyBTN_ClickAsync);
//
// SplitterPN
//
@@ -133,7 +133,7 @@ private void InitializeComponent()
this.BrowseCTRL.SessionTreeCtrl = null;
this.BrowseCTRL.Size = new System.Drawing.Size(276, 392);
this.BrowseCTRL.TabIndex = 1;
- this.BrowseCTRL.ItemsSelected += new Opc.Ua.Sample.Controls.NodesSelectedEventHandler(this.BrowseCTRL_ItemsSelected);
+ this.BrowseCTRL.ItemsSelected += new Opc.Ua.Sample.Controls.NodesSelectedEventHandler(this.BrowseCTRL_ItemsSelectedAsync);
//
// MonitoredItemsCTRL
//
diff --git a/Samples/Controls.Net4/Subscriptions/CreateMonitoredItemsDlg.cs b/Samples/Controls.Net4/Subscriptions/CreateMonitoredItemsDlg.cs
index 59a5372dd..0d5db1e3b 100644
--- a/Samples/Controls.Net4/Subscriptions/CreateMonitoredItemsDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/CreateMonitoredItemsDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -56,15 +56,15 @@ public CreateMonitoredItemsDlg()
private Subscription m_subscription;
private SubscriptionStateChangedEventHandler m_SubscriptionStateChanged;
#endregion
-
+
#region Public Interface
///
/// Displays the dialog.
///
public void Show(Subscription subscription, bool useTypeModel)
{
- if (subscription == null) throw new ArgumentNullException("subscription");
-
+ if (subscription == null) throw new ArgumentNullException(nameof(subscription));
+
Show();
BringToFront();
@@ -73,24 +73,24 @@ public void Show(Subscription subscription, bool useTypeModel)
{
m_subscription.StateChanged -= m_SubscriptionStateChanged;
}
-
+
// start receiving notifications from the new subscription.
m_subscription = subscription;
-
+
if (subscription != null)
{
m_subscription.StateChanged += m_SubscriptionStateChanged;
- }
+ }
m_subscription = subscription;
-
+
BrowseCTRL.AllowPick = true;
- BrowseCTRL.SetView(subscription.Session as Session, (useTypeModel)?BrowseViewType.ObjectTypes:BrowseViewType.Objects, null);
+ BrowseCTRL.SetViewAsync(subscription.Session as Session, (useTypeModel) ? BrowseViewType.ObjectTypes : BrowseViewType.Objects, null);
MonitoredItemsCTRL.Initialize(subscription);
}
#endregion
-
+
#region Event Handlers
///
/// Handles a change to the state of the subscription.
@@ -110,7 +110,7 @@ void Subscription_StateChanged(Subscription subscription, SubscriptionStateChang
try
{
// ignore notifications for other subscriptions.
- if (!Object.ReferenceEquals(m_subscription, subscription))
+ if (!Object.ReferenceEquals(m_subscription, subscription))
{
return;
}
@@ -120,11 +120,11 @@ void Subscription_StateChanged(Subscription subscription, SubscriptionStateChang
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void BrowseCTRL_ItemsSelected(object sender, NodesSelectedEventArgs e)
+ private async void BrowseCTRL_ItemsSelectedAsync(object sender, NodesSelectedEventArgs e)
{
try
{
@@ -132,25 +132,25 @@ private void BrowseCTRL_ItemsSelected(object sender, NodesSelectedEventArgs e)
{
if (reference.ReferenceTypeId == ReferenceTypeIds.HasProperty || reference.IsForward)
{
- MonitoredItemsCTRL.AddItem(reference);
+ await MonitoredItemsCTRL.AddItemAsync(reference);
}
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void ApplyBTN_Click(object sender, EventArgs e)
+ private async void ApplyBTN_ClickAsync(object sender, EventArgs e)
{
try
{
- MonitoredItemsCTRL.ApplyChanges(true);
+ await MonitoredItemsCTRL.ApplyChangesAsync(true);
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -162,7 +162,7 @@ private void CancelBTN_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Subscriptions/DataChangeFilterEditDlg.cs b/Samples/Controls.Net4/Subscriptions/DataChangeFilterEditDlg.cs
index 6d929a092..9db70682c 100644
--- a/Samples/Controls.Net4/Subscriptions/DataChangeFilterEditDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/DataChangeFilterEditDlg.cs
@@ -47,14 +47,14 @@ public DataChangeFilterEditDlg()
{
InitializeComponent();
this.Icon = ClientUtils.GetAppIcon();
-
+
Array values = Enum.GetValues(typeof(DataChangeTrigger));
foreach (object value in values)
{
TriggerCB.Items.Add(value);
}
-
+
values = Enum.GetValues(typeof(DeadbandType));
foreach (object value in values)
@@ -68,7 +68,7 @@ public DataChangeFilterEditDlg()
///
public bool ShowDialog(Session session, MonitoredItem monitoredItem)
{
- if (monitoredItem == null) throw new ArgumentNullException("monitoredItem");
+ if (monitoredItem == null) throw new ArgumentNullException(nameof(monitoredItem));
DataChangeFilter filter = monitoredItem.Filter as DataChangeFilter;
@@ -76,22 +76,22 @@ public bool ShowDialog(Session session, MonitoredItem monitoredItem)
{
filter = new DataChangeFilter();
- filter.Trigger = DataChangeTrigger.StatusValue;
+ filter.Trigger = DataChangeTrigger.StatusValue;
filter.DeadbandValue = 0;
- filter.DeadbandType = (uint)(int)DeadbandType.None;
+ filter.DeadbandType = (uint)(int)DeadbandType.None;
}
- TriggerCB.SelectedItem = filter.Trigger;
+ TriggerCB.SelectedItem = filter.Trigger;
DeadbandTypeCB.SelectedItem = (DeadbandType)(int)filter.DeadbandType;
- DeadbandNC.Value = (decimal)filter.DeadbandValue;
-
+ DeadbandNC.Value = (decimal)filter.DeadbandValue;
+
if (ShowDialog() != DialogResult.OK)
{
return false;
}
- filter.Trigger = (DataChangeTrigger)TriggerCB.SelectedItem;
- filter.DeadbandType = Convert.ToUInt32(DeadbandTypeCB.SelectedItem);
+ filter.Trigger = (DataChangeTrigger)TriggerCB.SelectedItem;
+ filter.DeadbandType = Convert.ToUInt32(DeadbandTypeCB.SelectedItem);
filter.DeadbandValue = (double)DeadbandNC.Value;
monitoredItem.Filter = filter;
@@ -100,7 +100,7 @@ public bool ShowDialog(Session session, MonitoredItem monitoredItem)
}
private void OkBTN_Click(object sender, EventArgs e)
- {
+ {
DialogResult = DialogResult.OK;
}
diff --git a/Samples/Controls.Net4/Subscriptions/DataChangeNotificationListCtrl.cs b/Samples/Controls.Net4/Subscriptions/DataChangeNotificationListCtrl.cs
index 0fc99e990..677a9966c 100644
--- a/Samples/Controls.Net4/Subscriptions/DataChangeNotificationListCtrl.cs
+++ b/Samples/Controls.Net4/Subscriptions/DataChangeNotificationListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,10 +32,11 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
@@ -45,8 +46,8 @@ public partial class DataChangeNotificationListCtrl : Opc.Ua.Client.Controls.Bas
{
public DataChangeNotificationListCtrl()
{
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
}
#region Private Fields
@@ -59,15 +60,15 @@ public DataChangeNotificationListCtrl()
/// The columns to display in the control.
///
private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Item", HorizontalAlignment.Left, null },
- new object[] { "Variable", HorizontalAlignment.Left, null },
- new object[] { "Value", HorizontalAlignment.Left, String.Empty, 250 },
- new object[] { "Status", HorizontalAlignment.Left, String.Empty },
- new object[] { "Source Time", HorizontalAlignment.Center, String.Empty },
- new object[] { "Server Time", HorizontalAlignment.Center, String.Empty }
- };
- #endregion
+ {
+ new object[] { "Item", HorizontalAlignment.Left, null },
+ new object[] { "Variable", HorizontalAlignment.Left, null },
+ new object[] { "Value", HorizontalAlignment.Left, String.Empty, 250 },
+ new object[] { "Status", HorizontalAlignment.Left, String.Empty },
+ new object[] { "Source Time", HorizontalAlignment.Center, String.Empty },
+ new object[] { "Server Time", HorizontalAlignment.Center, String.Empty }
+ };
+ #endregion
#region Public Interface
///
@@ -76,17 +77,17 @@ public DataChangeNotificationListCtrl()
[DefaultValue(20)]
public int MaxChangeCount
{
- get { return m_maxChangeCount; }
+ get { return m_maxChangeCount; }
set { m_maxChangeCount = value; }
}
-
+
///
/// Whether to show previous values in the control after an update.
///
[DefaultValue(false)]
public bool ShowHistory
{
- get { return m_showHistory; }
+ get { return m_showHistory; }
set { m_showHistory = value; }
}
@@ -102,14 +103,14 @@ public void Clear()
///
/// Sets the nodes in the control.
///
- public void Initialize(Subscription subscription, MonitoredItem monitoredItem)
+ public async void InitializeAsync(Subscription subscription, MonitoredItem monitoredItem, CancellationToken ct = default)
{
- if (subscription == null) throw new ArgumentNullException("subscription");
-
+ if (subscription == null) throw new ArgumentNullException(nameof(subscription));
+
Clear();
-
+
// start receiving notifications from the new subscription.
- m_subscription = subscription;
+ m_subscription = subscription;
m_monitoredItem = monitoredItem;
// get the events.
@@ -148,14 +149,14 @@ public void Initialize(Subscription subscription, MonitoredItem monitoredItem)
}
}
- UpdateChanges(changes, 0);
+ await UpdateChangesAsync(changes, 0, ct);
AdjustColumns();
}
-
+
///
/// Processes a new notification.
///
- public void NotificationReceived(NotificationEventArgs e)
+ public async Task NotificationReceivedAsync(NotificationEventArgs e, CancellationToken ct = default)
{
// get the changes.
List changes = new List();
@@ -194,7 +195,7 @@ public void NotificationReceived(NotificationEventArgs e)
foreach (ListViewItem listItem in ItemsLV.Items)
{
MonitoredItemNotification change = listItem.Tag as MonitoredItemNotification;
-
+
if (change == null)
{
continue;
@@ -220,22 +221,22 @@ public void NotificationReceived(NotificationEventArgs e)
changes.Reverse();
}
- UpdateChanges(changes, offset);
+ await UpdateChangesAsync(changes, offset, ct);
AdjustColumns();
}
-
+
///
/// Processes a new notification.
///
- public void NotificationReceived(MonitoredItemNotificationEventArgs e)
+ public async Task NotificationReceivedAsync(MonitoredItemNotificationEventArgs e, CancellationToken ct = default)
{
MonitoredItemNotification change = e.NotificationValue as MonitoredItemNotification;
-
+
if (change == null)
{
return;
}
-
+
if (m_monitoredItem != null)
{
if (m_monitoredItem.ClientHandle != change.ClientHandle)
@@ -248,13 +249,13 @@ public void NotificationReceived(MonitoredItemNotificationEventArgs e)
List changes = new List();
changes.Add(change);
- // fill in earlier changes.
+ // fill in earlier changes.
if (m_showHistory)
{
foreach (ListViewItem listItem in ItemsLV.Items)
{
change = listItem.Tag as MonitoredItemNotification;
-
+
if (change == null)
{
continue;
@@ -276,11 +277,11 @@ public void NotificationReceived(MonitoredItemNotificationEventArgs e)
}
}
}
-
- UpdateChanges(changes, 1);
+
+ await UpdateChangesAsync(changes, 1, ct);
AdjustColumns();
}
-
+
///
/// Processes a change to the subscription.
///
@@ -303,19 +304,19 @@ public void SubscriptionChanged(SubscriptionStateChangedEventArgs e)
}
}
}
-
+
// remove events for items that have been deleted.
foreach (ListViewItem listItem in itemsToRemove)
{
listItem.Remove();
- }
+ }
}
}
///
/// Updates the display after the publish status for the subscription changes.
///
- public void PublishStatusChanged()
+ public async Task PublishStatusChangedAsync(CancellationToken ct = default)
{
foreach (ListViewItem listItem in ItemsLV.Items)
{
@@ -323,10 +324,10 @@ public void PublishStatusChanged()
if (change != null)
{
- UpdateItem(listItem, change);
+ await UpdateItemAsync(listItem, change, ct);
}
}
-
+
AdjustColumns();
}
#endregion
@@ -334,22 +335,22 @@ public void PublishStatusChanged()
#region Overridden Methods
///
protected override void EnableMenuItems(ListViewItem clickedItem)
- {
- ViewMI.Enabled = ItemsLV.SelectedItems.Count == 1;
+ {
+ ViewMI.Enabled = ItemsLV.SelectedItems.Count == 1;
DeleteMI.Enabled = ItemsLV.SelectedItems.Count > 0;
- }
-
+ }
+
///
protected override void PickItems()
{
base.PickItems();
ViewMI_Click(this, null);
}
-
+
///
/// Updates the events displayed in the control.
///
- private void UpdateChanges(IList changes, int offset)
+ private async Task UpdateChangesAsync(IList changes, int offset, CancellationToken ct = default)
{
// save selected indexes.
List indexes = new List(ItemsLV.SelectedIndices.Count);
@@ -358,7 +359,7 @@ private void UpdateChanges(IList changes, int offset)
{
indexes.Add(index);
}
-
+
// add all new values.
if (m_showHistory)
{
@@ -374,13 +375,13 @@ private void UpdateChanges(IList changes, int offset)
// only update changed values.
else
- {
+ {
foreach (ListViewItem listItem in ItemsLV.Items)
{
listItem.ForeColor = Color.Gray;
}
- for (int ii = changes.Count-1; ii >= 0; ii--)
+ for (int ii = changes.Count - 1; ii >= 0; ii--)
{
bool found = false;
@@ -390,7 +391,7 @@ private void UpdateChanges(IList changes, int offset)
if (change != null && change.ClientHandle == changes[ii].ClientHandle)
{
- UpdateItem(listItem, changes[ii]);
+ await UpdateItemAsync(listItem, changes[ii], ct);
found = true;
listItem.ForeColor = Color.Empty;
break;
@@ -398,7 +399,7 @@ private void UpdateChanges(IList changes, int offset)
}
if (!found)
- {
+ {
AddItem(changes[ii]);
}
}
@@ -409,29 +410,29 @@ private void UpdateChanges(IList changes, int offset)
{
ItemsLV.Items[index].Selected = false;
- if (index+offset < ItemsLV.Items.Count)
+ if (index + offset < ItemsLV.Items.Count)
{
- ItemsLV.Items[index+offset].Selected = true;
+ ItemsLV.Items[index + offset].Selected = true;
}
}
}
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
{
- MonitoredItemNotification change = item as MonitoredItemNotification;
-
- if (change == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
-
+ MonitoredItemNotification change = item as MonitoredItemNotification;
+
+ if (change == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
+
// fill in the columns.
listItem.SubItems[0].Text = String.Format("[{0}]", change.ClientHandle);
MonitoredItem monitoredItem = null;
-
+
if (m_subscription != null)
{
monitoredItem = m_subscription.FindItemByClientHandle(change.ClientHandle);
@@ -445,7 +446,7 @@ protected override void UpdateItem(ListViewItem listItem, object item)
{
listItem.SubItems[1].Text = "(unknown)";
}
-
+
listItem.SubItems[2].Text = String.Format("{0}", change.Value.WrappedValue);
// check of publishing has stopped for some reason.
@@ -468,7 +469,7 @@ protected override void UpdateItem(ListViewItem listItem, object item)
{
listItem.SubItems[4].Text = String.Empty;
}
-
+
time = change.Value.ServerTimestamp;
if (time != null && time != DateTime.MinValue)
@@ -479,12 +480,12 @@ protected override void UpdateItem(ListViewItem listItem, object item)
{
listItem.SubItems[5].Text = String.Empty;
}
-
+
listItem.Tag = change;
- listItem.ForeColor = (m_subscription.PublishingStopped)?Color.Red:Color.Empty;
+ listItem.ForeColor = (m_subscription.PublishingStopped) ? Color.Red : Color.Empty;
}
#endregion
-
+
#region Event Handlers
private void ViewMI_Click(object sender, EventArgs e)
{
@@ -501,7 +502,7 @@ private void ViewMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Subscriptions/EventFilterDlg.Designer.cs b/Samples/Controls.Net4/Subscriptions/EventFilterDlg.Designer.cs
index 111df91bb..9797902d6 100644
--- a/Samples/Controls.Net4/Subscriptions/EventFilterDlg.Designer.cs
+++ b/Samples/Controls.Net4/Subscriptions/EventFilterDlg.Designer.cs
@@ -172,7 +172,7 @@ private void InitializeComponent()
this.BrowseCTRL.SessionTreeCtrl = null;
this.BrowseCTRL.Size = new System.Drawing.Size(340, 395);
this.BrowseCTRL.TabIndex = 1;
- this.BrowseCTRL.ItemsSelected += new Opc.Ua.Sample.Controls.NodesSelectedEventHandler(this.BrowseCTRL_ItemsSelected);
+ this.BrowseCTRL.ItemsSelected += new Opc.Ua.Sample.Controls.NodesSelectedEventHandler(this.BrowseCTRL_ItemsSelectedAsync);
//
// FilterOperandsCTRL
//
diff --git a/Samples/Controls.Net4/Subscriptions/EventFilterDlg.cs b/Samples/Controls.Net4/Subscriptions/EventFilterDlg.cs
index 248729a9f..6af6d7e67 100644
--- a/Samples/Controls.Net4/Subscriptions/EventFilterDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/EventFilterDlg.cs
@@ -55,25 +55,25 @@ public EventFilterDlg()
private Session m_session;
private EventFilter m_filter;
#endregion
-
+
#region Public Interface
///
/// Displays the dialog.
///
public EventFilter ShowDialog(Session session, EventFilter filter, bool editWhereClause)
{
- if (session == null) throw new ArgumentNullException("session");
- if (filter == null) throw new ArgumentNullException("filter");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+ if (filter == null) throw new ArgumentNullException(nameof(filter));
+
m_session = session;
- m_filter = filter;
+ m_filter = filter;
- BrowseCTRL.SetView(m_session, BrowseViewType.EventTypes, null);
+ BrowseCTRL.SetViewAsync(m_session, BrowseViewType.EventTypes, null);
SelectClauseCTRL.Initialize(session, filter.SelectClauses);
ContentFilterCTRL.Initialize(session, filter.WhereClause);
FilterOperandsCTRL.Initialize(session, null, -1);
- MoveBTN_Click((editWhereClause)?NextBTN:BackBTN, null);
+ MoveBTN_Click((editWhereClause) ? NextBTN : BackBTN, null);
if (ShowDialog() != DialogResult.OK)
{
@@ -83,9 +83,9 @@ public EventFilter ShowDialog(Session session, EventFilter filter, bool editWher
return m_filter;
}
#endregion
-
+
#region Event Handlers
- private void BrowseCTRL_ItemsSelected(object sender, NodesSelectedEventArgs e)
+ private async void BrowseCTRL_ItemsSelectedAsync(object sender, NodesSelectedEventArgs e)
{
try
{
@@ -93,13 +93,13 @@ private void BrowseCTRL_ItemsSelected(object sender, NodesSelectedEventArgs e)
{
if (reference.ReferenceTypeId == ReferenceTypeIds.HasProperty || reference.IsForward)
{
- SelectClauseCTRL.AddSelectClause(reference);
+ await SelectClauseCTRL.AddSelectClauseAsync(reference);
}
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -126,12 +126,12 @@ private void ContentFilterCTRL_ItemsSelected(object sender, ListItemActionEventA
}
else
{
- FilterOperandsCTRL.Initialize(m_session, null, -1);
+ FilterOperandsCTRL.Initialize(m_session, null, -1);
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -140,30 +140,30 @@ private void MoveBTN_Click(object sender, EventArgs e)
try
{
if (sender == NextBTN)
- {
- BackBTN.Visible = true;
- NextBTN.Visible = false;
- OkBTN.Visible = true;
- ContentFilterCTRL.Visible = true;
+ {
+ BackBTN.Visible = true;
+ NextBTN.Visible = false;
+ OkBTN.Visible = true;
+ ContentFilterCTRL.Visible = true;
FilterOperandsCTRL.Visible = true;
- BrowseCTRL.Visible = false;
- SelectClauseCTRL.Visible = false;
+ BrowseCTRL.Visible = false;
+ SelectClauseCTRL.Visible = false;
}
else if (sender == BackBTN)
- {
- BackBTN.Visible = false;
- NextBTN.Visible = true;
- OkBTN.Visible = false;
- ContentFilterCTRL.Visible = false;
+ {
+ BackBTN.Visible = false;
+ NextBTN.Visible = true;
+ OkBTN.Visible = false;
+ ContentFilterCTRL.Visible = false;
FilterOperandsCTRL.Visible = false;
- BrowseCTRL.Visible = true;
- SelectClauseCTRL.Visible = true;
+ BrowseCTRL.Visible = true;
+ SelectClauseCTRL.Visible = true;
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -175,7 +175,7 @@ private void OkBTN_Click(object sender, EventArgs e)
filter.SelectClauses.AddRange(SelectClauseCTRL.GetSelectClauses());
filter.WhereClause = ContentFilterCTRL.GetFilter();
-
+
EventFilter.Result result = filter.Validate(new FilterContext(m_session.NamespaceUris, m_session.TypeTree));
if (ServiceResult.IsBad(result.Status))
@@ -189,7 +189,7 @@ private void OkBTN_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
diff --git a/Samples/Controls.Net4/Subscriptions/EventNotificationListCtrl.cs b/Samples/Controls.Net4/Subscriptions/EventNotificationListCtrl.cs
index d05992c1c..cde08bca8 100644
--- a/Samples/Controls.Net4/Subscriptions/EventNotificationListCtrl.cs
+++ b/Samples/Controls.Net4/Subscriptions/EventNotificationListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,10 +32,11 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
@@ -45,8 +46,8 @@ public partial class EventNotificationListListCtrl : Opc.Ua.Client.Controls.Base
{
public EventNotificationListListCtrl()
{
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
}
#region Private Fields
@@ -58,15 +59,15 @@ public EventNotificationListListCtrl()
/// The columns to display in the control.
///
private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Item", HorizontalAlignment.Left, null },
- new object[] { "Type", HorizontalAlignment.Left, null },
- new object[] { "Source", HorizontalAlignment.Left, String.Empty },
- new object[] { "Time", HorizontalAlignment.Center, String.Empty },
- new object[] { "Severity", HorizontalAlignment.Center, String.Empty },
- new object[] { "Message", HorizontalAlignment.Left, String.Empty }
- };
- #endregion
+ {
+ new object[] { "Item", HorizontalAlignment.Left, null },
+ new object[] { "Type", HorizontalAlignment.Left, null },
+ new object[] { "Source", HorizontalAlignment.Left, String.Empty },
+ new object[] { "Time", HorizontalAlignment.Center, String.Empty },
+ new object[] { "Severity", HorizontalAlignment.Center, String.Empty },
+ new object[] { "Message", HorizontalAlignment.Left, String.Empty }
+ };
+ #endregion
#region Public Interface
///
@@ -75,7 +76,7 @@ public EventNotificationListListCtrl()
[DefaultValue(20)]
public int MaxEventCount
{
- get { return m_maxEventCount; }
+ get { return m_maxEventCount; }
set { m_maxEventCount = value; }
}
@@ -93,12 +94,12 @@ public void Clear()
///
public void Initialize(Subscription subscription, MonitoredItem monitoredItem)
{
- if (subscription == null) throw new ArgumentNullException("subscription");
-
+ if (subscription == null) throw new ArgumentNullException(nameof(subscription));
+
Clear();
-
+
// start receiving notifications from the new subscription.
- m_subscription = subscription;
+ m_subscription = subscription;
m_monitoredItem = monitoredItem;
// get the events.
@@ -122,7 +123,7 @@ public void Initialize(Subscription subscription, MonitoredItem monitoredItem)
continue;
}
}
-
+
events.Add(eventFields);
if (events.Count >= MaxEventCount)
@@ -140,7 +141,7 @@ public void Initialize(Subscription subscription, MonitoredItem monitoredItem)
UpdateEvents(events, 0);
AdjustColumns();
}
-
+
///
/// Processes a new notification.
///
@@ -164,7 +165,7 @@ public void NotificationReceived(NotificationEventArgs e)
{
continue;
}
- }
+ }
events.Add(eventFields);
@@ -199,15 +200,15 @@ public void NotificationReceived(NotificationEventArgs e)
continue;
}
}
-
- events.Add(eventFields);
+
+ events.Add(eventFields);
if (events.Count >= MaxEventCount)
{
break;
}
}
-
+
UpdateEvents(events, offset);
AdjustColumns();
}
@@ -218,12 +219,12 @@ public void NotificationReceived(NotificationEventArgs e)
public void NotificationReceived(MonitoredItemNotificationEventArgs e)
{
EventFieldList eventFields = e.NotificationValue as EventFieldList;
-
+
if (eventFields == null)
{
return;
}
-
+
if (m_monitoredItem != null)
{
if (m_monitoredItem.ClientHandle != eventFields.ClientHandle)
@@ -240,7 +241,7 @@ public void NotificationReceived(MonitoredItemNotificationEventArgs e)
foreach (ListViewItem listItem in ItemsLV.Items)
{
eventFields = listItem.Tag as EventFieldList;
-
+
if (m_monitoredItem != null)
{
if (m_monitoredItem.ClientHandle != eventFields.ClientHandle)
@@ -259,11 +260,11 @@ public void NotificationReceived(MonitoredItemNotificationEventArgs e)
break;
}
}
-
+
UpdateEvents(events, 1);
AdjustColumns();
}
-
+
///
/// Processes a change to the subscription.
///
@@ -286,12 +287,12 @@ public void SubscriptionChanged(SubscriptionStateChangedEventArgs e)
}
}
}
-
+
// remove events for items that have been deleted.
foreach (ListViewItem listItem in itemsToRemove)
{
listItem.Remove();
- }
+ }
}
}
#endregion
@@ -299,18 +300,18 @@ public void SubscriptionChanged(SubscriptionStateChangedEventArgs e)
#region Overridden Methods
///
protected override void EnableMenuItems(ListViewItem clickedItem)
- {
- ViewMI.Enabled = ItemsLV.SelectedItems.Count == 1;
+ {
+ ViewMI.Enabled = ItemsLV.SelectedItems.Count == 1;
DeleteMI.Enabled = ItemsLV.SelectedItems.Count > 0;
- }
+ }
///
protected override void PickItems()
{
base.PickItems();
ViewMI_Click(this, null);
- }
-
+ }
+
///
/// Updates the events displayed in the control.
///
@@ -326,7 +327,7 @@ private void UpdateEvents(IList events, int offset)
// update items.
BeginUpdate();
-
+
foreach (EventFieldList eventFields in events)
{
AddItem(eventFields);
@@ -339,23 +340,23 @@ private void UpdateEvents(IList events, int offset)
{
ItemsLV.Items[index].Selected = false;
- if (index+offset < ItemsLV.Items.Count)
+ if (index + offset < ItemsLV.Items.Count)
{
- ItemsLV.Items[index+offset].Selected = true;
+ ItemsLV.Items[index + offset].Selected = true;
}
}
}
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
{
- EventFieldList eventFields = item as EventFieldList;
+ EventFieldList eventFields = item as EventFieldList;
- if (eventFields == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
+ if (eventFields == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
MonitoredItem monitoredItem = m_subscription.FindItemByClientHandle(eventFields.ClientHandle);
@@ -367,22 +368,22 @@ protected override void UpdateItem(ListViewItem listItem, object item)
listItem.SubItems[3].Text = null;
listItem.SubItems[4].Text = null;
listItem.SubItems[5].Text = null;
-
+
listItem.Tag = eventFields;
return;
- }
-
+ }
+
// get the event fields.
- NodeId eventType = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, Opc.Ua.BrowseNames.EventType) as NodeId;
- string sourceName = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, Opc.Ua.BrowseNames.SourceName) as string;
- DateTime? time = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, Opc.Ua.BrowseNames.Time) as DateTime?;
- ushort? severity = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, Opc.Ua.BrowseNames.Severity) as ushort?;
+ NodeId eventType = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, Opc.Ua.BrowseNames.EventType) as NodeId;
+ string sourceName = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, Opc.Ua.BrowseNames.SourceName) as string;
+ DateTime? time = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, Opc.Ua.BrowseNames.Time) as DateTime?;
+ ushort? severity = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, Opc.Ua.BrowseNames.Severity) as ushort?;
LocalizedText message = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, Opc.Ua.BrowseNames.Message) as LocalizedText;
-
+
// fill in the columns.
listItem.SubItems[0].Text = String.Format("[{0}]", eventFields.ClientHandle);
- INode typeNode = m_subscription.Session.NodeCache.Find(eventType);
+ INode typeNode = await m_subscription.Session.NodeCache.FindAsync(eventType, ct);
if (typeNode == null)
{
@@ -405,7 +406,7 @@ protected override void UpdateItem(ListViewItem listItem, object item)
}
listItem.SubItems[4].Text = String.Format("{0}", severity);
-
+
if (message != null)
{
listItem.SubItems[5].Text = String.Format("{0}", message.Text);
@@ -414,11 +415,11 @@ protected override void UpdateItem(ListViewItem listItem, object item)
{
listItem.SubItems[5].Text = String.Empty;
}
-
+
listItem.Tag = eventFields;
}
#endregion
-
+
#region Event Handlers
private void ViewMI_Click(object sender, EventArgs e)
{
@@ -429,13 +430,13 @@ private void ViewMI_Click(object sender, EventArgs e)
if (fieldList == null)
{
return;
- }
+ }
new ComplexValueEditDlg().ShowDialog(fieldList, m_subscription.FindItemByClientHandle(fieldList.ClientHandle));
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Subscriptions/FilterOperandEditDlg.cs b/Samples/Controls.Net4/Subscriptions/FilterOperandEditDlg.cs
index 578d5f521..8a5231e65 100644
--- a/Samples/Controls.Net4/Subscriptions/FilterOperandEditDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/FilterOperandEditDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -33,6 +33,7 @@
using System.Data;
using System.Drawing;
using System.Text;
+using System.Linq;
using System.Windows.Forms;
using System.Reflection;
@@ -59,31 +60,31 @@ public FilterOperandEditDlg()
DataTypeCB.Items.Add(datatype);
}
- AttributeIdCB.Items.AddRange(Attributes.GetBrowseNames());
+ AttributeIdCB.Items.AddRange(Attributes.BrowseNames.ToArray());
}
#endregion
#region Private Fields
private Session m_session;
#endregion
-
+
#region Public Interface
///
/// Displays the dialog.
///
public FilterOperand ShowDialog(
- Session session,
- IList elements,
- int index,
- FilterOperand operand)
+ Session session,
+ IList elements,
+ int index,
+ FilterOperand operand)
{
- if (session == null) throw new ArgumentNullException("session");
- if (elements == null) throw new ArgumentNullException("elements");
+ if (session == null) throw new ArgumentNullException(nameof(session));
+ if (elements == null) throw new ArgumentNullException(nameof(elements));
m_session = session;
-
+
TypeDefinitionIdCTRL.Browser = new Browser(session);
- TypeDefinitionIdCTRL.RootId = ObjectTypes.BaseEventType;
+ TypeDefinitionIdCTRL.RootId = ObjectTypes.BaseEventType;
OperandTypeCB.SelectedItem = typeof(LiteralOperand).Name;
@@ -91,32 +92,32 @@ public FilterOperand ShowDialog(
{
OperandTypeCB.SelectedItem = operand.GetType().Name;
}
-
+
ElementsCB.Items.Clear();
- for (int ii = index+1; ii < elements.Count; ii++)
+ for (int ii = index + 1; ii < elements.Count; ii++)
{
- ElementsCB.Items.Add(elements[ii].ToString(m_session.NodeCache));
+ ElementsCB.Items.Add(elements[ii].ToString(m_session.NodeCache.AsNodeTable()));
}
-
+
ElementOperand elementOperand = operand as ElementOperand;
if (elementOperand != null)
{
- ElementsCB.SelectedIndex = (int)elementOperand.Index - index -1;
+ ElementsCB.SelectedIndex = (int)elementOperand.Index - index - 1;
}
-
+
AttributeOperand attributeOperand = operand as AttributeOperand;
if (attributeOperand != null)
{
TypeDefinitionIdCTRL.Identifier = attributeOperand.NodeId;
- BrowsePathTB.Text = attributeOperand.BrowsePath.Format(session.NodeCache.TypeTree);
- AttributeIdCB.SelectedItem = Attributes.GetBrowseName(attributeOperand.AttributeId);
- IndexRangeTB.Text = attributeOperand.IndexRange;
- AliasTB.Text = attributeOperand.Alias;
+ BrowsePathTB.Text = attributeOperand.BrowsePath.Format(session.TypeTree);
+ AttributeIdCB.SelectedItem = Attributes.GetBrowseName(attributeOperand.AttributeId);
+ IndexRangeTB.Text = attributeOperand.IndexRange;
+ AliasTB.Text = attributeOperand.Alias;
}
-
+
LiteralOperand literalOperand = operand as LiteralOperand;
if (literalOperand != null)
@@ -147,7 +148,7 @@ public FilterOperand ShowDialog(
ValueTB.Text = buffer.ToString();
}
-
+
if (ShowDialog() != DialogResult.OK)
{
return null;
@@ -156,7 +157,7 @@ public FilterOperand ShowDialog(
return operand;
}
#endregion
-
+
#region Event Handlers
private void OperandTypeCB_SelectedIndexChanged(object sender, EventArgs e)
{
@@ -166,32 +167,32 @@ private void OperandTypeCB_SelectedIndexChanged(object sender, EventArgs e)
{
case "LiteralOperand":
{
- LiteralPN.Visible = true;
+ LiteralPN.Visible = true;
AttributePN.Visible = false;
- ElementPN.Visible = false;
+ ElementPN.Visible = false;
break;
}
case "AttributeOperand":
{
- LiteralPN.Visible = false;
+ LiteralPN.Visible = false;
AttributePN.Visible = true;
- ElementPN.Visible = false;
+ ElementPN.Visible = false;
break;
}
case "ElementOperand":
{
- LiteralPN.Visible = false;
+ LiteralPN.Visible = false;
AttributePN.Visible = false;
- ElementPN.Visible = true;
+ ElementPN.Visible = true;
break;
}
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Subscriptions/FilterOperandListCtrl.Designer.cs b/Samples/Controls.Net4/Subscriptions/FilterOperandListCtrl.Designer.cs
index c09719919..731d12ff4 100644
--- a/Samples/Controls.Net4/Subscriptions/FilterOperandListCtrl.Designer.cs
+++ b/Samples/Controls.Net4/Subscriptions/FilterOperandListCtrl.Designer.cs
@@ -84,7 +84,7 @@ private void InitializeComponent()
this.NewMI.Name = "NewMI";
this.NewMI.Size = new System.Drawing.Size(152, 22);
this.NewMI.Text = "New...";
- this.NewMI.Click += new System.EventHandler(this.NewMI_Click);
+ this.NewMI.Click += new System.EventHandler(this.NewMI_ClickAsync);
//
// DeleteMI
//
diff --git a/Samples/Controls.Net4/Subscriptions/FilterOperandListCtrl.cs b/Samples/Controls.Net4/Subscriptions/FilterOperandListCtrl.cs
index ffafc0da7..103c58f06 100644
--- a/Samples/Controls.Net4/Subscriptions/FilterOperandListCtrl.cs
+++ b/Samples/Controls.Net4/Subscriptions/FilterOperandListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,10 +32,11 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
@@ -45,8 +46,8 @@ public partial class FilterOperandListCtrl : Opc.Ua.Client.Controls.BaseListCtrl
{
public FilterOperandListCtrl()
{
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
}
#region Private Fields
@@ -58,11 +59,11 @@ public FilterOperandListCtrl()
/// The columns to display in the control.
///
private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Index", HorizontalAlignment.Left, null },
- new object[] { "Operand", HorizontalAlignment.Left, null },
- };
- #endregion
+ {
+ new object[] { "Index", HorizontalAlignment.Left, null },
+ new object[] { "Operand", HorizontalAlignment.Left, null },
+ };
+ #endregion
#region Public Interface
///
@@ -79,17 +80,17 @@ public void Clear()
///
public void Initialize(Session session, IList elements, int index)
{
- if (session == null) throw new ArgumentNullException("session");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
Clear();
-
- m_session = session;
+
+ m_session = session;
m_elements = elements;
- m_index = index;
+ m_index = index;
if (elements == null || index < 0 || index >= elements.Count)
{
- return;
+ return;
}
foreach (FilterOperand operand in elements[index].GetOperands())
@@ -106,7 +107,7 @@ public void Initialize(Session session, IList elements, in
public List GetOperands()
{
List operands = new List();
-
+
for (int ii = 0; ii < ItemsLV.Items.Count; ii++)
{
FilterOperand operand = ItemsLV.Items[ii].Tag as FilterOperand;
@@ -124,32 +125,32 @@ public List GetOperands()
#region Overridden Methods
///
protected override void EnableMenuItems(ListViewItem clickedItem)
- {
- NewMI.Enabled = true;
- EditMI.Enabled = ItemsLV.SelectedItems.Count == 1;
+ {
+ NewMI.Enabled = true;
+ EditMI.Enabled = ItemsLV.SelectedItems.Count == 1;
DeleteMI.Enabled = ItemsLV.SelectedItems.Count > 0;
- }
-
- ///
- protected override void UpdateItem(ListViewItem listItem, object item, int index)
+ }
+
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, int index, CancellationToken ct = default)
{
- FilterOperand operand = item as FilterOperand;
-
- if (operand == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
-
+ FilterOperand operand = item as FilterOperand;
+
+ if (operand == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
+
listItem.SubItems[0].Text = String.Format("[{0}]", index);
- listItem.SubItems[1].Text = operand.ToString(m_session.NodeCache);
-
+ listItem.SubItems[1].Text = operand.ToString(m_session.NodeCache.AsNodeTable());
+
listItem.Tag = operand;
}
#endregion
-
+
#region Event Handlers
- private void NewMI_Click(object sender, EventArgs e)
+ private async void NewMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -158,14 +159,14 @@ private void NewMI_Click(object sender, EventArgs e)
if (operand == null)
{
return;
- }
+ }
// insert after the current selection.
int index = ItemsLV.SelectedIndices.Count;
if (ItemsLV.SelectedIndices.Count > 0)
{
- index = ItemsLV.SelectedIndices[0]+1;
+ index = ItemsLV.SelectedIndices[0] + 1;
}
AddItem(operand, "SimpleItem", index);
@@ -173,9 +174,9 @@ private void NewMI_Click(object sender, EventArgs e)
// must update index for all items.
for (int ii = 0; ii < ItemsLV.Items.Count; ii++)
{
- UpdateItem(ItemsLV.Items[ii], ItemsLV.Items[ii].Tag, ii);
+ await UpdateItemAsync(ItemsLV.Items[ii], ItemsLV.Items[ii].Tag, ii);
}
-
+
AdjustColumns();
m_elements[m_index].FilterOperands.Clear();
@@ -183,7 +184,7 @@ private void NewMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -194,7 +195,7 @@ private void EditMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -205,7 +206,7 @@ private void DeleteMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Subscriptions/FilterOperatorEditDlg.cs b/Samples/Controls.Net4/Subscriptions/FilterOperatorEditDlg.cs
index 22ed971f0..a1f25f8ff 100644
--- a/Samples/Controls.Net4/Subscriptions/FilterOperatorEditDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/FilterOperatorEditDlg.cs
@@ -53,7 +53,7 @@ public FilterOperatorEditDlg()
}
}
#endregion
-
+
#region Public Interface
///
/// Displays the dialog.
@@ -66,9 +66,9 @@ public bool ShowDialog(ref FilterOperator value)
{
return false;
}
-
+
value = (FilterOperator)OperatorCB.SelectedItem;
-
+
return true;
}
#endregion
diff --git a/Samples/Controls.Net4/Subscriptions/HistoryReadDetails.cs b/Samples/Controls.Net4/Subscriptions/HistoryReadDetails.cs
index 17099e632..f6bf55118 100644
--- a/Samples/Controls.Net4/Subscriptions/HistoryReadDetails.cs
+++ b/Samples/Controls.Net4/Subscriptions/HistoryReadDetails.cs
@@ -44,14 +44,14 @@ public partial class HistoryReadDetails : UserControl
public HistoryReadDetails()
{
InitializeComponent();
-
+
QueryTypeCB.Items.Clear();
QueryTypeCB.Items.Add("Read Raw or Modified");
}
private Session m_session;
private ReadRawModifiedDetails m_details;
-
+
#region Private Methods
///
/// Initializes the control
@@ -76,18 +76,18 @@ public void Initialize(
IsModifiedCHK.Checked = details.IsReadModified;
}
#endregion
-
+
#region Private Methods
private DateTime ToControlDateTime(DateTime value)
{
- if (value < new DateTime(1900,1,1))
+ if (value < new DateTime(1900, 1, 1))
{
- return new DateTime(1900,1,1);
+ return new DateTime(1900, 1, 1);
}
- if (value > new DateTime(2100,1,1))
+ if (value > new DateTime(2100, 1, 1))
{
- return new DateTime(2100,1,1);
+ return new DateTime(2100, 1, 1);
}
return value;
@@ -95,12 +95,12 @@ private DateTime ToControlDateTime(DateTime value)
private DateTime FromControlDateTime(DateTime value)
{
- if (value <= new DateTime(1900,1,1))
+ if (value <= new DateTime(1900, 1, 1))
{
return DateTime.MinValue;
}
- if (value >= new DateTime(2100,1,1))
+ if (value >= new DateTime(2100, 1, 1))
{
return DateTime.MaxValue;
}
diff --git a/Samples/Controls.Net4/Subscriptions/HistoryReadDlg.Designer.cs b/Samples/Controls.Net4/Subscriptions/HistoryReadDlg.Designer.cs
index 2cd45f95e..3f1fe828e 100644
--- a/Samples/Controls.Net4/Subscriptions/HistoryReadDlg.Designer.cs
+++ b/Samples/Controls.Net4/Subscriptions/HistoryReadDlg.Designer.cs
@@ -99,7 +99,7 @@ private void InitializeComponent()
this.BackBTN.TabIndex = 3;
this.BackBTN.Text = "< Back";
this.BackBTN.UseVisualStyleBackColor = true;
- this.BackBTN.Click += new System.EventHandler(this.MoveBTN_Click);
+ this.BackBTN.Click += new System.EventHandler(this.MoveBTN_ClickAsync);
//
// CancelBTN
//
@@ -122,7 +122,7 @@ private void InitializeComponent()
this.NextBTN.TabIndex = 2;
this.NextBTN.Text = "Next >";
this.NextBTN.UseVisualStyleBackColor = true;
- this.NextBTN.Click += new System.EventHandler(this.MoveBTN_Click);
+ this.NextBTN.Click += new System.EventHandler(this.MoveBTN_ClickAsync);
//
// ReadBTN
//
@@ -133,7 +133,7 @@ private void InitializeComponent()
this.ReadBTN.TabIndex = 4;
this.ReadBTN.Text = "Read";
this.ReadBTN.UseVisualStyleBackColor = true;
- this.ReadBTN.Click += new System.EventHandler(this.ReadMI_Click);
+ this.ReadBTN.Click += new System.EventHandler(this.ReadMI_ClickAsync);
//
// SplitterPN
//
@@ -173,7 +173,7 @@ private void InitializeComponent()
this.BrowseCTRL.SessionTreeCtrl = null;
this.BrowseCTRL.Size = new System.Drawing.Size(291, 392);
this.BrowseCTRL.TabIndex = 1;
- this.BrowseCTRL.ItemsSelected += new Opc.Ua.Sample.Controls.NodesSelectedEventHandler(this.BrowseCTRL_ItemsSelected);
+ this.BrowseCTRL.ItemsSelected += new Opc.Ua.Sample.Controls.NodesSelectedEventHandler(this.BrowseCTRL_ItemsSelectedAsync);
//
// ReadResultsCTRL
//
diff --git a/Samples/Controls.Net4/Subscriptions/HistoryReadDlg.cs b/Samples/Controls.Net4/Subscriptions/HistoryReadDlg.cs
index 8a52167b2..92c236e0a 100644
--- a/Samples/Controls.Net4/Subscriptions/HistoryReadDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/HistoryReadDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -38,6 +38,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading;
+using System.Threading.Tasks;
namespace Opc.Ua.Sample.Controls
{
@@ -54,27 +56,27 @@ public HistoryReadDlg()
#region Private Fields
private Session m_session;
#endregion
-
+
#region Public Interface
///
/// Displays the dialog.
///
public void Show(Session session, ReadValueIdCollection valueIds)
{
- if (session == null) throw new ArgumentNullException("session");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
m_session = session;
- BrowseCTRL.SetView(m_session, BrowseViewType.Objects, null);
+ BrowseCTRL.SetViewAsync(m_session, BrowseViewType.Objects, null);
ReadValuesCTRL.Initialize(session, valueIds);
- MoveBTN_Click(BackBTN, null);
+ MoveBTN_ClickAsync(BackBTN, null);
Show();
BringToFront();
}
- private void Read()
+ private async Task ReadAsync(CancellationToken ct = default)
{
ReadValueIdCollection nodesToRead = ReadValuesCTRL.GetValueIds();
@@ -83,26 +85,25 @@ private void Read()
return;
}
- DataValueCollection values = null;
- DiagnosticInfoCollection diagnosticInfos = null;
-
- ResponseHeader responseHeader = m_session.Read(
+ ReadResponse response = await m_session.ReadAsync(
null,
0,
TimestampsToReturn.Both,
nodesToRead,
- out values,
- out diagnosticInfos);
+ ct);
+
+ DataValueCollection values = response.Results;
+ DiagnosticInfoCollection diagnosticInfos = response.DiagnosticInfos;
ClientBase.ValidateResponse(values, nodesToRead);
- ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
-
- ReadResultsCTRL.ShowValue(values, true);
+ ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
+
+ await ReadResultsCTRL.ShowValueAsync(values, true, ct);
}
#endregion
-
+
#region Event Handlers
- private void BrowseCTRL_ItemsSelected(object sender, NodesSelectedEventArgs e)
+ private async void BrowseCTRL_ItemsSelectedAsync(object sender, NodesSelectedEventArgs e)
{
try
{
@@ -110,57 +111,57 @@ private void BrowseCTRL_ItemsSelected(object sender, NodesSelectedEventArgs e)
{
if (reference.ReferenceTypeId == ReferenceTypeIds.HasProperty || reference.IsForward)
{
- ReadValuesCTRL.AddValueId(reference);
+ await ReadValuesCTRL.AddValueIdAsync(reference);
}
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void MoveBTN_Click(object sender, EventArgs e)
+ private async void MoveBTN_ClickAsync(object sender, EventArgs e)
{
try
{
if (sender == NextBTN)
{
- Read();
+ await ReadAsync();
- BackBTN.Visible = true;
- NextBTN.Visible = false;
- ReadBTN.Visible = true;
- ReadValuesCTRL.Visible = true;
+ BackBTN.Visible = true;
+ NextBTN.Visible = false;
+ ReadBTN.Visible = true;
+ ReadValuesCTRL.Visible = true;
ReadResultsCTRL.Visible = true;
- BrowseCTRL.Visible = false;
+ BrowseCTRL.Visible = false;
}
else if (sender == BackBTN)
{
- BackBTN.Visible = false;
- NextBTN.Visible = true;
- ReadBTN.Visible = false;
- ReadResultsCTRL.Visible = false;
- BrowseCTRL.Visible = true;
- ReadValuesCTRL.Visible = true;
+ BackBTN.Visible = false;
+ NextBTN.Visible = true;
+ ReadBTN.Visible = false;
+ ReadResultsCTRL.Visible = false;
+ BrowseCTRL.Visible = true;
+ ReadValuesCTRL.Visible = true;
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void ReadMI_Click(object sender, EventArgs e)
+ private async void ReadMI_ClickAsync(object sender, EventArgs e)
{
try
{
- Read();
+ await ReadAsync();
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -172,7 +173,7 @@ private void CancelBTN_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Subscriptions/MonitoredItemConfigCtrl.Designer.cs b/Samples/Controls.Net4/Subscriptions/MonitoredItemConfigCtrl.Designer.cs
index 381bec385..554d6b81a 100644
--- a/Samples/Controls.Net4/Subscriptions/MonitoredItemConfigCtrl.Designer.cs
+++ b/Samples/Controls.Net4/Subscriptions/MonitoredItemConfigCtrl.Designer.cs
@@ -95,21 +95,21 @@ private void InitializeComponent()
this.NewMI.Name = "NewMI";
this.NewMI.Size = new System.Drawing.Size(196, 22);
this.NewMI.Text = "New...";
- this.NewMI.Click += new System.EventHandler(this.NewMI_Click);
+ this.NewMI.Click += new System.EventHandler(this.NewMI_ClickAsync);
//
// EditMI
//
this.EditMI.Name = "EditMI";
this.EditMI.Size = new System.Drawing.Size(196, 22);
this.EditMI.Text = "Edit...";
- this.EditMI.Click += new System.EventHandler(this.EditMI_Click);
+ this.EditMI.Click += new System.EventHandler(this.EditMI_ClickAsync);
//
// DeleteMI
//
this.DeleteMI.Name = "DeleteMI";
this.DeleteMI.Size = new System.Drawing.Size(196, 22);
this.DeleteMI.Text = "Delete";
- this.DeleteMI.Click += new System.EventHandler(this.DeleteMI_Click);
+ this.DeleteMI.Click += new System.EventHandler(this.DeleteMI_ClickAsync);
//
// Separator1
//
@@ -128,14 +128,14 @@ private void InitializeComponent()
this.SetFilterMI.Name = "SetFilterMI";
this.SetFilterMI.Size = new System.Drawing.Size(196, 22);
this.SetFilterMI.Text = "Set Filter...";
- this.SetFilterMI.Click += new System.EventHandler(this.SetFilterMI_Click);
+ this.SetFilterMI.Click += new System.EventHandler(this.SetFilterMI_ClickAsync);
//
// SetMonitoringModeMI
//
this.SetMonitoringModeMI.Name = "SetMonitoringModeMI";
this.SetMonitoringModeMI.Size = new System.Drawing.Size(196, 22);
this.SetMonitoringModeMI.Text = "Set Monitoring Mode...";
- this.SetMonitoringModeMI.Click += new System.EventHandler(this.SetMonitoringModeMI_Click);
+ this.SetMonitoringModeMI.Click += new System.EventHandler(this.SetMonitoringModeMI_ClickAsync);
//
// Separator2
//
diff --git a/Samples/Controls.Net4/Subscriptions/MonitoredItemConfigCtrl.cs b/Samples/Controls.Net4/Subscriptions/MonitoredItemConfigCtrl.cs
index 215ca9eda..37e6ba888 100644
--- a/Samples/Controls.Net4/Subscriptions/MonitoredItemConfigCtrl.cs
+++ b/Samples/Controls.Net4/Subscriptions/MonitoredItemConfigCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,10 +32,11 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
@@ -153,7 +154,7 @@ public void SubscriptionChanged(SubscriptionStateChangedEventArgs e)
///
public MonitoredItem CreateItem(Subscription subscription)
{
- if (subscription == null) throw new ArgumentNullException("subscription");
+ if (subscription == null) throw new ArgumentNullException(nameof(subscription));
MonitoredItem monitoredItem = new MonitoredItem(subscription.DefaultItem);
monitoredItem.QueueSize = 1;
@@ -192,7 +193,7 @@ public void UpdateItems()
///
/// Returns the parent for the node.
///
- private Node FindParent(Node node)
+ private async Task FindParentAsync(Node node, CancellationToken ct = default)
{
IList parents = node.ReferenceTable.Find(ReferenceTypeIds.Aggregates, true, true, m_subscription.Session.TypeTree);
@@ -202,7 +203,7 @@ private Node FindParent(Node node)
foreach (IReference parentReference in parents)
{
- Node parent = m_subscription.Session.NodeCache.Find(parentReference.TargetId) as Node;
+ Node parent = await m_subscription.Session.NodeCache.FindAsync(parentReference.TargetId, ct) as Node;
if (followToType)
{
@@ -224,14 +225,14 @@ private Node FindParent(Node node)
///
/// Creates an item from a reference.
///
- public void AddItem(ReferenceDescription reference)
+ public async Task AddItemAsync(ReferenceDescription reference, CancellationToken ct = default)
{
if (reference == null)
{
return;
}
- Node node = m_subscription.Session.NodeCache.Find(reference.NodeId) as Node;
+ Node node = await m_subscription.Session.NodeCache.FindAsync(reference.NodeId, ct) as Node;
if (node == null)
{
@@ -243,7 +244,7 @@ public void AddItem(ReferenceDescription reference)
// if the NodeId is of type string and contains '.' do not use relative paths
if (node.NodeId.IdType != IdType.String || (node.NodeId.Identifier.ToString().IndexOf('.') == -1 && node.NodeId.Identifier.ToString().IndexOf('/') == -1))
{
- parent = FindParent(node);
+ parent = await FindParentAsync(node, ct);
}
MonitoredItem monitoredItem = new MonitoredItem(m_subscription.DefaultItem);
@@ -267,7 +268,7 @@ public void AddItem(ReferenceDescription reference)
while (parent.NodeClass != NodeClass.ObjectType && parent.NodeClass != NodeClass.VariableType)
{
- parent = FindParent(parent);
+ parent = await FindParentAsync(parent, ct);
if (parent == null)
{
@@ -305,7 +306,7 @@ public void AddItem(ReferenceDescription reference)
///
/// Apply any changes to the set of items.
///
- public void ApplyChanges(bool force)
+ public async Task ApplyChangesAsync(bool force, CancellationToken ct = default)
{
if (m_batchUpdates && !force)
{
@@ -314,11 +315,11 @@ public void ApplyChanges(bool force)
if (m_subscription != null)
{
- m_subscription.ApplyChanges();
+ await m_subscription.ApplyChangesAsync(ct);
foreach (ListViewItem listItem in ItemsLV.Items)
{
- UpdateItem(listItem, listItem.Tag);
+ await UpdateItemAsync(listItem, listItem.Tag, ct);
}
AdjustColumns();
@@ -368,14 +369,14 @@ protected override void PickItems()
MonitorMI_Click(this, null);
}
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
{
MonitoredItem monitoredItem = item as MonitoredItem;
if (monitoredItem == null)
{
- base.UpdateItem(listItem, item);
+ await base.UpdateItemAsync(listItem, item, ct);
return;
}
@@ -439,7 +440,7 @@ protected override void UpdateItem(ListViewItem listItem, object item)
///
/// Handles a drop event.
///
- protected override void ItemsLV_DragDrop(object sender, DragEventArgs e)
+ protected override async Task OnDragDropAsync(object sender, DragEventArgs e, CancellationToken ct = default)
{
try
{
@@ -450,7 +451,7 @@ protected override void ItemsLV_DragDrop(object sender, DragEventArgs e)
return;
}
- AddItem(reference);
+ await AddItemAsync(reference, ct);
AdjustColumns();
}
catch (Exception exception)
@@ -461,7 +462,7 @@ protected override void ItemsLV_DragDrop(object sender, DragEventArgs e)
#endregion
#region Event Handlers
- private void NewMI_Click(object sender, EventArgs e)
+ private async void NewMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -471,7 +472,7 @@ private void NewMI_Click(object sender, EventArgs e)
}
CreateItem(m_subscription);
- ApplyChanges(false);
+ await ApplyChangesAsync(false);
}
catch (Exception exception)
{
@@ -479,7 +480,7 @@ private void NewMI_Click(object sender, EventArgs e)
}
}
- private void EditMI_Click(object sender, EventArgs e)
+ private async void EditMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -500,7 +501,7 @@ private void EditMI_Click(object sender, EventArgs e)
return;
}
- ApplyChanges(false);
+ await ApplyChangesAsync(false);
}
catch (Exception exception)
{
@@ -508,7 +509,7 @@ private void EditMI_Click(object sender, EventArgs e)
}
}
- private void DeleteMI_Click(object sender, EventArgs e)
+ private async void DeleteMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -524,7 +525,7 @@ private void DeleteMI_Click(object sender, EventArgs e)
m_subscription.RemoveItems(monitoredItems);
}
- IList deletedItems = m_subscription.DeleteItems();
+ IList deletedItems = await m_subscription.DeleteItemsAsync();
string errorString = string.Empty;
@@ -538,7 +539,7 @@ private void DeleteMI_Click(object sender, EventArgs e)
foreach (ListViewItem listItem in ItemsLV.Items)
{
- UpdateItem(listItem, listItem.Tag);
+ await UpdateItemAsync(listItem, listItem.Tag);
}
AdjustColumns();
@@ -554,7 +555,7 @@ private void DeleteMI_Click(object sender, EventArgs e)
}
}
- private void SetMonitoringModeMI_Click(object sender, EventArgs e)
+ private async void SetMonitoringModeMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -574,7 +575,7 @@ private void SetMonitoringModeMI_Click(object sender, EventArgs e)
return;
}
- List errors = m_subscription.SetMonitoringMode(monitoringMode, monitoredItems);
+ List errors = await m_subscription.SetMonitoringModeAsync(monitoringMode, monitoredItems);
if (errors != null)
{
@@ -595,7 +596,7 @@ private void SetMonitoringModeMI_Click(object sender, EventArgs e)
}
}
- private void SetFilterMI_Click(object sender, EventArgs e)
+ private async void SetFilterMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -627,8 +628,8 @@ private void SetFilterMI_Click(object sender, EventArgs e)
monitoredItems[0].Filter = filter;
}
- m_subscription.ModifyItems();
- ApplyChanges(false);
+ await m_subscription.ModifyItemsAsync();
+ await ApplyChangesAsync(false);
}
}
catch (Exception exception)
diff --git a/Samples/Controls.Net4/Subscriptions/MonitoredItemDlg.Designer.cs b/Samples/Controls.Net4/Subscriptions/MonitoredItemDlg.Designer.cs
index 98b25fd83..37087e787 100644
--- a/Samples/Controls.Net4/Subscriptions/MonitoredItemDlg.Designer.cs
+++ b/Samples/Controls.Net4/Subscriptions/MonitoredItemDlg.Designer.cs
@@ -134,21 +134,21 @@ private void InitializeComponent()
this.MonitoringModeReportingMI.Name = "MonitoringModeReportingMI";
this.MonitoringModeReportingMI.Size = new System.Drawing.Size(126, 22);
this.MonitoringModeReportingMI.Text = "Reporting";
- this.MonitoringModeReportingMI.Click += new System.EventHandler(this.MonitoringModeMI_Click);
+ this.MonitoringModeReportingMI.Click += new System.EventHandler(this.MonitoringModeMI_ClickAsync);
//
// MonitoringModeSamplingMI
//
this.MonitoringModeSamplingMI.Name = "MonitoringModeSamplingMI";
this.MonitoringModeSamplingMI.Size = new System.Drawing.Size(126, 22);
this.MonitoringModeSamplingMI.Text = "Sampling";
- this.MonitoringModeSamplingMI.Click += new System.EventHandler(this.MonitoringModeMI_Click);
+ this.MonitoringModeSamplingMI.Click += new System.EventHandler(this.MonitoringModeMI_ClickAsync);
//
// MonitoringModeDisabledMI
//
this.MonitoringModeDisabledMI.Name = "MonitoringModeDisabledMI";
this.MonitoringModeDisabledMI.Size = new System.Drawing.Size(126, 22);
this.MonitoringModeDisabledMI.Text = "Disabled";
- this.MonitoringModeDisabledMI.Click += new System.EventHandler(this.MonitoringModeMI_Click);
+ this.MonitoringModeDisabledMI.Click += new System.EventHandler(this.MonitoringModeMI_ClickAsync);
//
// WindowMI
//
diff --git a/Samples/Controls.Net4/Subscriptions/MonitoredItemDlg.cs b/Samples/Controls.Net4/Subscriptions/MonitoredItemDlg.cs
index 93bfef1e0..ded84287c 100644
--- a/Samples/Controls.Net4/Subscriptions/MonitoredItemDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/MonitoredItemDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -50,7 +50,7 @@ public MonitoredItemDlg()
this.Icon = ClientUtils.GetAppIcon();
m_SubscriptionStateChanged = new SubscriptionStateChangedEventHandler(Subscription_StateChanged);
- m_MonitoredItemNotification = new MonitoredItemNotificationEventHandler(MonitoredItem_Notification);
+ m_MonitoredItemNotification = new MonitoredItemNotificationEventHandler(MonitoredItem_NotificationAsync);
m_PublishStatusChanged = new PublishStateChangedEventHandler(Subscription_PublishStatusChanged);
}
#endregion
@@ -69,7 +69,7 @@ public MonitoredItemDlg()
///
public void Show(MonitoredItem monitoredItem)
{
- if (monitoredItem == null) throw new ArgumentNullException("monitoredItem");
+ if (monitoredItem == null) throw new ArgumentNullException(nameof(monitoredItem));
Show();
BringToFront();
@@ -99,8 +99,8 @@ public void Show(MonitoredItem monitoredItem)
MonitoredItemsCTRL.Initialize(m_monitoredItem);
EventsCTRL.Initialize(m_subscription, m_monitoredItem);
- DataChangesCTRL.Initialize(m_subscription, m_monitoredItem);
- LatestValueCTRL.ShowValue(m_monitoredItem, false);
+ DataChangesCTRL.InitializeAsync(m_subscription, m_monitoredItem);
+ LatestValueCTRL.ShowValueAsync(m_monitoredItem, false);
}
#endregion
@@ -148,7 +148,7 @@ private void UpdateStatus()
///
/// Processes a Publish repsonse from the server.
///
- void MonitoredItem_Notification(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
+ private async void MonitoredItem_NotificationAsync(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
{
if (InvokeRequired)
{
@@ -170,11 +170,11 @@ void MonitoredItem_Notification(MonitoredItem monitoredItem, MonitoredItemNotifi
// notify controls of the change.
EventsCTRL.NotificationReceived(e);
- DataChangesCTRL.NotificationReceived(e);
+ await DataChangesCTRL.NotificationReceivedAsync(e);
if (e != null)
{
MonitoredItemNotification notification = e.NotificationValue as MonitoredItemNotification;
- LatestValueCTRL.ShowValue(notification, true);
+ await LatestValueCTRL.ShowValueAsync(notification, true);
}
// update item status.
UpdateStatus();
@@ -188,7 +188,7 @@ void MonitoredItem_Notification(MonitoredItem monitoredItem, MonitoredItemNotifi
///
/// Handles a change to the state of the subscription.
///
- void Subscription_StateChanged(Subscription subscription, SubscriptionStateChangedEventArgs e)
+ private void Subscription_StateChanged(Subscription subscription, SubscriptionStateChangedEventArgs e)
{
if (InvokeRequired)
{
@@ -225,7 +225,7 @@ void Subscription_StateChanged(Subscription subscription, SubscriptionStateChang
///
/// Handles a change to the publish status for the subscription.
///
- void Subscription_PublishStatusChanged(object subscription, PublishStateChangedEventArgs e)
+ private void Subscription_PublishStatusChanged(object subscription, PublishStateChangedEventArgs e)
{
if (InvokeRequired)
{
@@ -296,7 +296,7 @@ private void WindowMI_Click(object sender, EventArgs e)
}
}
- private void MonitoringModeMI_Click(object sender, EventArgs e)
+ private async void MonitoringModeMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -317,7 +317,7 @@ private void MonitoringModeMI_Click(object sender, EventArgs e)
monitoringMode = MonitoringMode.Disabled;
}
- m_monitoredItem.Subscription.SetMonitoringMode(monitoringMode, new MonitoredItem[] { m_monitoredItem });
+ await m_monitoredItem.Subscription.SetMonitoringModeAsync(monitoringMode, new MonitoredItem[] { m_monitoredItem });
}
catch (Exception exception)
{
diff --git a/Samples/Controls.Net4/Subscriptions/MonitoredItemEditDlg.Designer.cs b/Samples/Controls.Net4/Subscriptions/MonitoredItemEditDlg.Designer.cs
index af29e9463..0e8801922 100644
--- a/Samples/Controls.Net4/Subscriptions/MonitoredItemEditDlg.Designer.cs
+++ b/Samples/Controls.Net4/Subscriptions/MonitoredItemEditDlg.Designer.cs
@@ -203,7 +203,7 @@ private void InitializeComponent()
this.NodeIdCTRL.Name = "NodeIdCTRL";
this.NodeIdCTRL.Size = new System.Drawing.Size(259, 20);
this.NodeIdCTRL.TabIndex = 22;
- this.NodeIdCTRL.IdentifierChanged += new System.EventHandler(this.NodeIdCTRL_IdentifierChanged);
+ this.NodeIdCTRL.IdentifierChanged += new System.EventHandler(this.NodeIdCTRL_IdentifierChangedAsync);
//
// MonitoringModeCB
//
diff --git a/Samples/Controls.Net4/Subscriptions/MonitoredItemEditDlg.cs b/Samples/Controls.Net4/Subscriptions/MonitoredItemEditDlg.cs
index 4bb3e2d87..f860efd8a 100644
--- a/Samples/Controls.Net4/Subscriptions/MonitoredItemEditDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/MonitoredItemEditDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,6 +32,7 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
@@ -48,8 +49,8 @@ public MonitoredItemEditDlg()
InitializeComponent();
this.Icon = ClientUtils.GetAppIcon();
- AttributeIdCB.Items.AddRange(Attributes.GetBrowseNames());
-
+ AttributeIdCB.Items.AddRange(Attributes.BrowseNames.ToArray());
+
foreach (MonitoringMode value in Enum.GetValues(typeof(MonitoringMode)))
{
MonitoringModeCB.Items.Add(value);
@@ -76,7 +77,7 @@ public bool ShowDialog(Session session, MonitoredItem monitoredItem)
///
public bool ShowDialog(Session session, MonitoredItem monitoredItem, bool editMonitoredItem)
{
- if (monitoredItem == null) throw new ArgumentNullException("monitoredItem");
+ if (monitoredItem == null) throw new ArgumentNullException(nameof(monitoredItem));
m_session = session;
@@ -84,7 +85,7 @@ public bool ShowDialog(Session session, MonitoredItem monitoredItem, bool editMo
if (editMonitoredItem)
{
- // Disable the not changeable values
+ // Disable the not changeable values
NodeIdCTRL.Enabled = false;
RelativePathTB.Enabled = false;
NodeClassCB.Enabled = false;
@@ -152,16 +153,16 @@ public bool ShowDialog(Session session, MonitoredItem monitoredItem, bool editMo
}
private void OkBTN_Click(object sender, EventArgs e)
- {
+ {
try
{
NodeId nodeId = NodeIdCTRL.Identifier;
}
catch (Exception)
{
- MessageBox.Show("Please enter a valid node id.", this.Text);
+ MessageBox.Show("Please enter a valid node id.", this.Text);
}
-
+
try
{
if (!String.IsNullOrEmpty(RelativePathTB.Text))
@@ -171,7 +172,7 @@ private void OkBTN_Click(object sender, EventArgs e)
}
catch (Exception)
{
- MessageBox.Show("Please enter a valid relative path.", this.Text);
+ MessageBox.Show("Please enter a valid relative path.", this.Text);
}
try
@@ -183,17 +184,17 @@ private void OkBTN_Click(object sender, EventArgs e)
}
catch (Exception)
{
- MessageBox.Show("Please enter a valid index range.", this.Text);
+ MessageBox.Show("Please enter a valid index range.", this.Text);
}
DialogResult = DialogResult.OK;
}
- private void NodeIdCTRL_IdentifierChanged(object sender, EventArgs e)
+ private async void NodeIdCTRL_IdentifierChangedAsync(object sender, EventArgs e)
{
if (NodeIdCTRL.Reference != null)
{
- DisplayNameTB.Text = m_session.NodeCache.GetDisplayText(NodeIdCTRL.Reference);
+ DisplayNameTB.Text = await m_session.NodeCache.GetDisplayTextAsync(NodeIdCTRL.Reference);
NodeClassCB.SelectedItem = (NodeClass)NodeIdCTRL.Reference.NodeClass;
}
}
diff --git a/Samples/Controls.Net4/Subscriptions/MonitoredItemStatusCtrl.cs b/Samples/Controls.Net4/Subscriptions/MonitoredItemStatusCtrl.cs
index 04561224a..396720fb9 100644
--- a/Samples/Controls.Net4/Subscriptions/MonitoredItemStatusCtrl.cs
+++ b/Samples/Controls.Net4/Subscriptions/MonitoredItemStatusCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,10 +32,11 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
@@ -52,27 +53,27 @@ public MonitoredItemStatusCtrl()
InitializeComponent();
SetColumns(m_ColumnNames);
}
- #endregion
+ #endregion
#region Private Fields
private Subscription m_subscription;
private MonitoredItem m_monitoredItem;
-
+
///
- /// The columns to display in the control.
- ///
- private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "ID", HorizontalAlignment.Center, null },
- new object[] { "Name", HorizontalAlignment.Left, null },
- new object[] { "Class", HorizontalAlignment.Left, "Variable" },
- new object[] { "Sampling Rate", HorizontalAlignment.Center, null },
- new object[] { "Queue Size", HorizontalAlignment.Center, "0" },
- new object[] { "Value", HorizontalAlignment.Left, "", 200 },
- new object[] { "Status", HorizontalAlignment.Left, "", },
- new object[] { "Timestamp", HorizontalAlignment.Center, "" },
- };
- #endregion
+ /// The columns to display in the control.
+ ///
+ private readonly object[][] m_ColumnNames = new object[][]
+ {
+ new object[] { "ID", HorizontalAlignment.Center, null },
+ new object[] { "Name", HorizontalAlignment.Left, null },
+ new object[] { "Class", HorizontalAlignment.Left, "Variable" },
+ new object[] { "Sampling Rate", HorizontalAlignment.Center, null },
+ new object[] { "Queue Size", HorizontalAlignment.Center, "0" },
+ new object[] { "Value", HorizontalAlignment.Left, "", 200 },
+ new object[] { "Status", HorizontalAlignment.Left, "", },
+ new object[] { "Timestamp", HorizontalAlignment.Center, "" },
+ };
+ #endregion
#region Public Interface
///
@@ -96,13 +97,13 @@ public void Initialize(MonitoredItem monitoredItem)
}
m_monitoredItem = monitoredItem;
- m_subscription = null;
+ m_subscription = null;
Clear();
-
+
if (m_monitoredItem != null)
{
- m_subscription = monitoredItem.Subscription;
+ m_subscription = monitoredItem.Subscription;
UpdateItems();
}
}
@@ -119,16 +120,16 @@ public void Initialize(Subscription subscription)
}
m_monitoredItem = null;
- m_subscription = subscription;
+ m_subscription = subscription;
Clear();
-
+
if (m_subscription != null)
{
UpdateItems();
}
}
-
+
///
/// Called when the subscription changes.
///
@@ -159,49 +160,49 @@ public void UpdateItems()
AdjustColumns();
}
}
-
+
///
/// Apply any changes to the set of items.
///
- public void ApplyChanges()
+ public async Task ApplyChangesAsync(CancellationToken ct = default)
{
if (m_subscription != null)
{
- m_subscription.ApplyChanges();
+ await m_subscription.ApplyChangesAsync(ct);
foreach (ListViewItem listItem in ItemsLV.Items)
{
- UpdateItem(listItem, listItem.Tag);
+ await UpdateItemAsync(listItem, listItem.Tag, ct);
}
AdjustColumns();
}
}
#endregion
-
+
#region Overridden Methods
///
- protected override void EnableMenuItems(ListViewItem clickedItem)
- {
+ protected override void EnableMenuItems(ListViewItem clickedItem)
+ {
// no menu defined at this time.
- }
-
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
+ }
+
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
{
- MonitoredItem monitoredItem = item as MonitoredItem;
+ MonitoredItem monitoredItem = item as MonitoredItem;
- if (monitoredItem == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
+ if (monitoredItem == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
- listItem.SubItems[0].Text = String.Format("{0}", monitoredItem.Status.Id);
- listItem.SubItems[1].Text = String.Format("{0}", monitoredItem.DisplayName);
- listItem.SubItems[2].Text = String.Format("{0}", monitoredItem.NodeClass);
+ listItem.SubItems[0].Text = String.Format("{0}", monitoredItem.Status.Id);
+ listItem.SubItems[1].Text = String.Format("{0}", monitoredItem.DisplayName);
+ listItem.SubItems[2].Text = String.Format("{0}", monitoredItem.NodeClass);
listItem.SubItems[3].Text = String.Format("{0}", monitoredItem.Status.SamplingInterval);
- listItem.SubItems[4].Text = String.Format("{0}", monitoredItem.Status.QueueSize);
+ listItem.SubItems[4].Text = String.Format("{0}", monitoredItem.Status.QueueSize);
listItem.SubItems[5].Text = String.Empty;
listItem.SubItems[6].Text = String.Format("{0}", monitoredItem.Status.Error);
listItem.SubItems[7].Text = String.Empty;
@@ -226,13 +227,13 @@ protected override void UpdateItem(ListViewItem listItem, object item)
if (eventFields != null)
{
- listItem.SubItems[5].Text = String.Format("{0}", monitoredItem.GetEventType(eventFields));
- listItem.SubItems[7].Text = String.Format("{0:HH:mm:ss.fff}", monitoredItem.GetEventTime(eventFields).ToLocalTime());
+ listItem.SubItems[5].Text = String.Format("{0}", await monitoredItem.GetEventTypeAsync(eventFields, ct));
+ listItem.SubItems[7].Text = String.Format("{0:HH:mm:ss.fff}", monitoredItem.GetEventTime(eventFields).ToLocalTime());
}
}
-
- listItem.Tag = item;
+
+ listItem.Tag = item;
}
- #endregion
+ #endregion
}
}
diff --git a/Samples/Controls.Net4/Subscriptions/NotificationMessageListCtrl.cs b/Samples/Controls.Net4/Subscriptions/NotificationMessageListCtrl.cs
index 190bcb869..36e30e99f 100644
--- a/Samples/Controls.Net4/Subscriptions/NotificationMessageListCtrl.cs
+++ b/Samples/Controls.Net4/Subscriptions/NotificationMessageListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,10 +32,11 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
@@ -51,33 +52,33 @@ public NotificationMessageListCtrl()
{
MaxMessageCount = 10;
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
ItemsLV.Sorting = SortOrder.Descending;
m_SessionNotification = new NotificationEventHandler(Session_Notification);
}
- #endregion
+ #endregion
#region Private Fields
private Session m_session;
private Subscription m_subscription;
private NotificationEventHandler m_SessionNotification;
private int m_maxMessageCount;
-
+
///
- /// The columns to display in the control.
- ///
- private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Subscription", HorizontalAlignment.Left, null },
- new object[] { "Message ID", HorizontalAlignment.Center, null },
- new object[] { "Publish Time", HorizontalAlignment.Center, null },
- new object[] { "Notifications", HorizontalAlignment.Center, null },
- new object[] { "Data Changes", HorizontalAlignment.Center, null },
- new object[] { "EventTypes", HorizontalAlignment.Center, null }
- };
- #endregion
+ /// The columns to display in the control.
+ ///
+ private readonly object[][] m_ColumnNames = new object[][]
+ {
+ new object[] { "Subscription", HorizontalAlignment.Left, null },
+ new object[] { "Message ID", HorizontalAlignment.Center, null },
+ new object[] { "Publish Time", HorizontalAlignment.Center, null },
+ new object[] { "Notifications", HorizontalAlignment.Center, null },
+ new object[] { "Data Changes", HorizontalAlignment.Center, null },
+ new object[] { "EventTypes", HorizontalAlignment.Center, null }
+ };
+ #endregion
#region Public Interface
///
@@ -85,7 +86,7 @@ public NotificationMessageListCtrl()
///
public int MaxMessageCount
{
- get { return m_maxMessageCount; }
+ get { return m_maxMessageCount; }
set { m_maxMessageCount = value; }
}
@@ -132,8 +133,8 @@ public void Initialize(Session session, Subscription subscription)
if (m_session == null)
{
return;
- }
-
+ }
+
List tags = new List();
// display only items for current subscription.
@@ -156,26 +157,26 @@ public void Initialize(Session session, Subscription subscription)
}
}
}
-
+
// update control.
Update(tags);
}
#endregion
-
+
#region ItemData Class
///
/// Stores the data associated with a list view item.
///
public class ItemData
{
- public Subscription Subscription;
+ public Subscription Subscription;
public NotificationMessage NotificationMessage;
public ItemData(
- Subscription subscription,
+ Subscription subscription,
NotificationMessage notificationMessage)
{
- Subscription = subscription;
+ Subscription = subscription;
NotificationMessage = notificationMessage;
}
}
@@ -184,11 +185,11 @@ public ItemData(
#region Overridden Methods
///
protected override void EnableMenuItems(ListViewItem clickedItem)
- {
+ {
if (m_session != null)
{
- OptionsMI.Enabled = true;
- ClearMI.Enabled = true;
+ OptionsMI.Enabled = true;
+ ClearMI.Enabled = true;
RepublishMI.Enabled = m_subscription != null;
if (clickedItem != null)
@@ -197,28 +198,28 @@ protected override void EnableMenuItems(ListViewItem clickedItem)
if (itemData != null)
{
- ViewMI.Enabled = true;
+ ViewMI.Enabled = true;
DeleteMI.Enabled = true;
}
}
}
- }
+ }
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
{
ItemData itemData = item as ItemData;
- if (itemData == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
+ if (itemData == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
+
+ listItem.SubItems[0].Text = String.Format("{0}", itemData.Subscription.DisplayName);
+ listItem.SubItems[1].Text = String.Format("{0}", itemData.NotificationMessage.SequenceNumber);
+ listItem.SubItems[2].Text = String.Format("{0:HH:mm:ss.fff}", itemData.NotificationMessage.PublishTime.ToLocalTime());
- listItem.SubItems[0].Text = String.Format("{0}", itemData.Subscription.DisplayName);
- listItem.SubItems[1].Text = String.Format("{0}", itemData.NotificationMessage.SequenceNumber);
- listItem.SubItems[2].Text = String.Format("{0:HH:mm:ss.fff}", itemData.NotificationMessage.PublishTime.ToLocalTime());
-
int events = 0;
int datachanges = 0;
int notifications = 0;
@@ -247,23 +248,23 @@ protected override void UpdateItem(ListViewItem listItem, object item)
}
}
- listItem.SubItems[3].Text = String.Format("{0}", notifications);
- listItem.SubItems[4].Text = String.Format("{0}", datachanges);
- listItem.SubItems[5].Text = String.Format("{0}", events);
+ listItem.SubItems[3].Text = String.Format("{0}", notifications);
+ listItem.SubItems[4].Text = String.Format("{0}", datachanges);
+ listItem.SubItems[5].Text = String.Format("{0}", events);
- listItem.Tag = item;
+ listItem.Tag = item;
}
- #endregion
+ #endregion
private void Update(List tags)
{
if (tags.Count > MaxMessageCount)
{
- tags.RemoveRange(MaxMessageCount, tags.Count-MaxMessageCount);
+ tags.RemoveRange(MaxMessageCount, tags.Count - MaxMessageCount);
}
-
+
BeginUpdate();
-
+
foreach (ItemData tag in tags)
{
AddItem(tag);
@@ -283,7 +284,7 @@ private void Session_Notification(ISession sender, NotificationEventArgs e)
{
return;
}
-
+
try
{
if (m_subscription != null)
@@ -306,7 +307,7 @@ private void Session_Notification(ISession sender, NotificationEventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -317,7 +318,7 @@ private void ViewMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -332,7 +333,7 @@ private void DeleteMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -344,7 +345,7 @@ private void ClearMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -367,7 +368,7 @@ private void RepublishMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
}
diff --git a/Samples/Controls.Net4/Subscriptions/ReadDlg.Designer.cs b/Samples/Controls.Net4/Subscriptions/ReadDlg.Designer.cs
index 7b3e0c2a1..03757b714 100644
--- a/Samples/Controls.Net4/Subscriptions/ReadDlg.Designer.cs
+++ b/Samples/Controls.Net4/Subscriptions/ReadDlg.Designer.cs
@@ -98,7 +98,7 @@ private void InitializeComponent()
this.BackBTN.TabIndex = 3;
this.BackBTN.Text = "< Back";
this.BackBTN.UseVisualStyleBackColor = true;
- this.BackBTN.Click += new System.EventHandler(this.MoveBTN_Click);
+ this.BackBTN.Click += new System.EventHandler(this.MoveBTN_ClickAsync);
//
// CancelBTN
//
@@ -121,7 +121,7 @@ private void InitializeComponent()
this.NextBTN.TabIndex = 2;
this.NextBTN.Text = "Next >";
this.NextBTN.UseVisualStyleBackColor = true;
- this.NextBTN.Click += new System.EventHandler(this.MoveBTN_Click);
+ this.NextBTN.Click += new System.EventHandler(this.MoveBTN_ClickAsync);
//
// ReadBTN
//
@@ -132,7 +132,7 @@ private void InitializeComponent()
this.ReadBTN.TabIndex = 4;
this.ReadBTN.Text = "Read";
this.ReadBTN.UseVisualStyleBackColor = true;
- this.ReadBTN.Click += new System.EventHandler(this.ReadMI_Click);
+ this.ReadBTN.Click += new System.EventHandler(this.ReadMI_ClickAsync);
//
// SplitterPN
//
@@ -173,7 +173,7 @@ private void InitializeComponent()
this.BrowseCTRL.SessionTreeCtrl = null;
this.BrowseCTRL.Size = new System.Drawing.Size(291, 392);
this.BrowseCTRL.TabIndex = 1;
- this.BrowseCTRL.ItemsSelected += new Opc.Ua.Sample.Controls.NodesSelectedEventHandler(this.BrowseCTRL_ItemsSelected);
+ this.BrowseCTRL.ItemsSelected += new Opc.Ua.Sample.Controls.NodesSelectedEventHandler(this.BrowseCTRL_ItemsSelectedAsync);
//
// ReadResultsCTRL
//
diff --git a/Samples/Controls.Net4/Subscriptions/ReadDlg.cs b/Samples/Controls.Net4/Subscriptions/ReadDlg.cs
index c72f2f6dd..ce2d3b0e6 100644
--- a/Samples/Controls.Net4/Subscriptions/ReadDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/ReadDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -38,6 +38,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -54,27 +56,27 @@ public ReadDlg()
#region Private Fields
private Session m_session;
#endregion
-
+
#region Public Interface
///
/// Displays the dialog.
///
- public void Show(Session session, ReadValueIdCollection valueIds)
+ public async Task ShowAsync(Session session, ReadValueIdCollection valueIds, CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
m_session = session;
- BrowseCTRL.SetView(m_session, BrowseViewType.Objects, null);
+ await BrowseCTRL.SetViewAsync(m_session, BrowseViewType.Objects, null, ct);
ReadValuesCTRL.Initialize(session, valueIds);
- MoveBTN_Click(BackBTN, null);
+ MoveBTN_ClickAsync(BackBTN, null);
Show();
BringToFront();
}
- private void Read()
+ private async Task ReadAsync(CancellationToken ct = default)
{
ReadValueIdCollection nodesToRead = ReadValuesCTRL.GetValueIds();
@@ -83,26 +85,25 @@ private void Read()
return;
}
- DataValueCollection values = null;
- DiagnosticInfoCollection diagnosticInfos = null;
-
- ResponseHeader responseHeader = m_session.Read(
+ ReadResponse response = await m_session.ReadAsync(
null,
0,
TimestampsToReturn.Both,
nodesToRead,
- out values,
- out diagnosticInfos);
+ ct);
+
+ DataValueCollection values = response.Results;
+ DiagnosticInfoCollection diagnosticInfos = response.DiagnosticInfos;
ClientBase.ValidateResponse(values, nodesToRead);
- ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
-
- ReadResultsCTRL.ShowValue(values, true);
+ ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
+
+ await ReadResultsCTRL.ShowValueAsync(values, true, ct);
}
#endregion
-
+
#region Event Handlers
- private void BrowseCTRL_ItemsSelected(object sender, NodesSelectedEventArgs e)
+ private async void BrowseCTRL_ItemsSelectedAsync(object sender, NodesSelectedEventArgs e)
{
try
{
@@ -110,61 +111,61 @@ private void BrowseCTRL_ItemsSelected(object sender, NodesSelectedEventArgs e)
{
if (reference.ReferenceTypeId == ReferenceTypeIds.HasProperty || reference.IsForward)
{
- ReadValuesCTRL.AddValueId(reference);
+ await ReadValuesCTRL.AddValueIdAsync(reference);
}
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void MoveBTN_Click(object sender, EventArgs e)
+ private async void MoveBTN_ClickAsync(object sender, EventArgs e)
{
try
{
if (sender == NextBTN)
{
- Read();
+ await ReadAsync();
- ReadValuesCTRL.Parent = SplitterPN.Panel1;
+ ReadValuesCTRL.Parent = SplitterPN.Panel1;
- BackBTN.Visible = true;
- NextBTN.Visible = false;
- ReadBTN.Visible = true;
- ReadValuesCTRL.Visible = true;
+ BackBTN.Visible = true;
+ NextBTN.Visible = false;
+ ReadBTN.Visible = true;
+ ReadValuesCTRL.Visible = true;
ReadResultsCTRL.Visible = true;
- BrowseCTRL.Visible = false;
+ BrowseCTRL.Visible = false;
}
else if (sender == BackBTN)
{
- ReadValuesCTRL.Parent = SplitterPN.Panel2;
-
- BackBTN.Visible = false;
- NextBTN.Visible = true;
- ReadBTN.Visible = false;
- ReadResultsCTRL.Visible = false;
- BrowseCTRL.Visible = true;
- ReadValuesCTRL.Visible = true;
+ ReadValuesCTRL.Parent = SplitterPN.Panel2;
+
+ BackBTN.Visible = false;
+ NextBTN.Visible = true;
+ ReadBTN.Visible = false;
+ ReadResultsCTRL.Visible = false;
+ BrowseCTRL.Visible = true;
+ ReadValuesCTRL.Visible = true;
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void ReadMI_Click(object sender, EventArgs e)
+ private async void ReadMI_ClickAsync(object sender, EventArgs e)
{
try
{
- Read();
+ await ReadAsync();
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -176,7 +177,7 @@ private void CancelBTN_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Subscriptions/ReadValueEditDlg.cs b/Samples/Controls.Net4/Subscriptions/ReadValueEditDlg.cs
index 2ba9d23fe..1c3cc96fa 100644
--- a/Samples/Controls.Net4/Subscriptions/ReadValueEditDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/ReadValueEditDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -31,6 +31,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
+using System.Linq;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
@@ -38,6 +39,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -47,40 +50,40 @@ public ReadValueEditDlg()
{
InitializeComponent();
this.Icon = ClientUtils.GetAppIcon();
- AttributeIdCB.Items.AddRange(Attributes.GetBrowseNames());
+ AttributeIdCB.Items.AddRange(Attributes.BrowseNames.ToArray());
}
///
/// Prompts the user to specify the browse options.
///
- public bool ShowDialog(Session session, ReadValueId valueId)
+ public async Task ShowDialogAsync(Session session, ReadValueId valueId, CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
- if (valueId == null) throw new ArgumentNullException("valueId");
+ if (session == null) throw new ArgumentNullException(nameof(session));
+ if (valueId == null) throw new ArgumentNullException(nameof(valueId));
NodeIdCTRL.Browser = new Browser(session);
- INode node = session.NodeCache.Find(valueId.NodeId);
+ INode node = await session.NodeCache.FindAsync(valueId.NodeId, ct);
if (node != null)
{
DisplayNameTB.Text = node.ToString();
}
- NodeIdCTRL.Identifier = valueId.NodeId;
+ NodeIdCTRL.Identifier = valueId.NodeId;
AttributeIdCB.SelectedItem = Attributes.GetBrowseName(valueId.AttributeId);
- IndexRangeTB.Text = valueId.IndexRange;
- EncodingCB.Text = (valueId.DataEncoding != null)?valueId.DataEncoding.Name:null;
-
+ IndexRangeTB.Text = valueId.IndexRange;
+ EncodingCB.Text = (valueId.DataEncoding != null) ? valueId.DataEncoding.Name : null;
+
if (ShowDialog() != DialogResult.OK)
{
return false;
}
- valueId.NodeId = NodeIdCTRL.Identifier;
+ valueId.NodeId = NodeIdCTRL.Identifier;
valueId.AttributeId = Attributes.GetIdentifier((string)AttributeIdCB.SelectedItem);
- valueId.IndexRange = IndexRangeTB.Text;
-
+ valueId.IndexRange = IndexRangeTB.Text;
+
if (String.IsNullOrEmpty(EncodingCB.Text))
{
valueId.DataEncoding = new QualifiedName(EncodingCB.Text);
@@ -90,16 +93,16 @@ public bool ShowDialog(Session session, ReadValueId valueId)
}
private void OkBTN_Click(object sender, EventArgs e)
- {
+ {
try
{
NodeId nodeId = NodeIdCTRL.Identifier;
}
catch (Exception)
{
- MessageBox.Show("Please enter a valid node id.", this.Text);
+ MessageBox.Show("Please enter a valid node id.", this.Text);
}
-
+
try
{
if (!String.IsNullOrEmpty(IndexRangeTB.Text))
@@ -109,7 +112,7 @@ private void OkBTN_Click(object sender, EventArgs e)
}
catch (Exception)
{
- MessageBox.Show("Please enter a valid index range.", this.Text);
+ MessageBox.Show("Please enter a valid index range.", this.Text);
}
DialogResult = DialogResult.OK;
diff --git a/Samples/Controls.Net4/Subscriptions/ReadValueListCtrl.Designer.cs b/Samples/Controls.Net4/Subscriptions/ReadValueListCtrl.Designer.cs
index ca2a4328a..81ec7efc2 100644
--- a/Samples/Controls.Net4/Subscriptions/ReadValueListCtrl.Designer.cs
+++ b/Samples/Controls.Net4/Subscriptions/ReadValueListCtrl.Designer.cs
@@ -87,14 +87,14 @@ private void InitializeComponent()
this.NewMI.Name = "NewMI";
this.NewMI.Size = new System.Drawing.Size(174, 22);
this.NewMI.Text = "New...";
- this.NewMI.Click += new System.EventHandler(this.NewMI_Click);
+ this.NewMI.Click += new System.EventHandler(this.NewMI_ClickAsync);
//
// EditMI
//
this.EditMI.Name = "EditMI";
this.EditMI.Size = new System.Drawing.Size(174, 22);
this.EditMI.Text = "Edit...";
- this.EditMI.Click += new System.EventHandler(this.EditMI_Click);
+ this.EditMI.Click += new System.EventHandler(this.EditMI_ClickAsync);
//
// DeleteMI
//
diff --git a/Samples/Controls.Net4/Subscriptions/ReadValueListCtrl.cs b/Samples/Controls.Net4/Subscriptions/ReadValueListCtrl.cs
index 422c9f99b..cd1523774 100644
--- a/Samples/Controls.Net4/Subscriptions/ReadValueListCtrl.cs
+++ b/Samples/Controls.Net4/Subscriptions/ReadValueListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,10 +32,11 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
@@ -45,8 +46,8 @@ public partial class ReadValueListCtrl : Opc.Ua.Client.Controls.BaseListCtrl
{
public ReadValueListCtrl()
{
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
}
#region Private Fields
@@ -56,14 +57,14 @@ public ReadValueListCtrl()
/// The columns to display in the control.
///
private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Name", HorizontalAlignment.Left, null },
- new object[] { "NodeId", HorizontalAlignment.Left, null },
- new object[] { "Attribute", HorizontalAlignment.Left, "Value" },
- new object[] { "IndexRange", HorizontalAlignment.Left, "" },
- new object[] { "Encoding", HorizontalAlignment.Left, "" }
- };
- #endregion
+ {
+ new object[] { "Name", HorizontalAlignment.Left, null },
+ new object[] { "NodeId", HorizontalAlignment.Left, null },
+ new object[] { "Attribute", HorizontalAlignment.Left, "Value" },
+ new object[] { "IndexRange", HorizontalAlignment.Left, "" },
+ new object[] { "Encoding", HorizontalAlignment.Left, "" }
+ };
+ #endregion
#region Public Interface
///
@@ -80,10 +81,10 @@ public void Clear()
///
public void Initialize(Session session, ReadValueIdCollection valueIds)
{
- if (session == null) throw new ArgumentNullException("session");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
Clear();
-
+
m_session = session;
foreach (ReadValueId valueId in valueIds)
@@ -97,9 +98,9 @@ public void Initialize(Session session, ReadValueIdCollection valueIds)
///
/// Adds a value to the control.
///
- public void AddValueId(ReferenceDescription reference)
+ public async Task AddValueIdAsync(ReferenceDescription reference, CancellationToken ct = default)
{
- Node node = m_session.NodeCache.Find(reference.NodeId) as Node;
+ Node node = await m_session.NodeCache.FindAsync(reference.NodeId, ct) as Node;
if (node == null)
{
@@ -108,15 +109,15 @@ public void AddValueId(ReferenceDescription reference)
ReadValueId valueId = new ReadValueId();
- valueId.NodeId = node.NodeId;
- valueId.AttributeId = Attributes.Value;
- valueId.IndexRange = null;
+ valueId.NodeId = node.NodeId;
+ valueId.AttributeId = Attributes.Value;
+ valueId.IndexRange = null;
valueId.DataEncoding = null;
// read the display name for non-variables.
if ((node.NodeClass & (NodeClass.Variable | NodeClass.VariableType)) == 0)
{
- valueId.AttributeId = Attributes.DisplayName;
+ valueId.AttributeId = Attributes.DisplayName;
}
AddItem(valueId);
@@ -142,38 +143,38 @@ public ReadValueIdCollection GetValueIds()
return valueIds;
}
- #endregion
-
+ #endregion
+
#region Overridden Methods
///
protected override void PickItems()
{
base.PickItems();
- EditMI_Click(this, null);
+ EditMI_ClickAsync(this, null);
}
///
protected override void EnableMenuItems(ListViewItem clickedItem)
- {
- NewMI.Enabled = true;
- EditMI.Enabled = ItemsLV.SelectedItems.Count == 1;
- DeleteMI.Enabled = ItemsLV.SelectedItems.Count > 0;
+ {
+ NewMI.Enabled = true;
+ EditMI.Enabled = ItemsLV.SelectedItems.Count == 1;
+ DeleteMI.Enabled = ItemsLV.SelectedItems.Count > 0;
SetAttributeMI.Enabled = ItemsLV.SelectedItems.Count > 0;
- SetEncodingMI.Enabled = ItemsLV.SelectedItems.Count == 1;
- }
-
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
+ SetEncodingMI.Enabled = ItemsLV.SelectedItems.Count == 1;
+ }
+
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
{
- ReadValueId valueId = item as ReadValueId;
+ ReadValueId valueId = item as ReadValueId;
- if (valueId == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
+ if (valueId == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
- INode node = m_session.NodeCache.Find(valueId.NodeId);
+ INode node = await m_session.NodeCache.FindAsync(valueId.NodeId, ct);
if (node != null)
{
@@ -183,21 +184,21 @@ protected override void UpdateItem(ListViewItem listItem, object item)
{
listItem.SubItems[0].Text = String.Format("{0}", valueId.NodeId);
}
-
+
listItem.SubItems[1].Text = String.Format("{0}", valueId.NodeId);
listItem.SubItems[2].Text = String.Format("{0}", Attributes.GetBrowseName(valueId.AttributeId));
listItem.SubItems[3].Text = String.Format("{0}", valueId.IndexRange);
listItem.SubItems[4].Text = String.Format("{0}", valueId.DataEncoding);
- listItem.Tag = item;
+ listItem.Tag = item;
listItem.ImageKey = "Method";
}
///
/// Handles a drop event.
///
- protected override void ItemsLV_DragDrop(object sender, DragEventArgs e)
- {
+ protected override async Task OnDragDropAsync(object sender, DragEventArgs e, CancellationToken ct = default)
+ {
try
{
ReferenceDescription reference = e.Data.GetData(typeof(ReferenceDescription)) as ReferenceDescription;
@@ -206,24 +207,24 @@ protected override void ItemsLV_DragDrop(object sender, DragEventArgs e)
{
return;
}
-
- AddValueId(reference);
+
+ await AddValueIdAsync(reference, ct);
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
-
+
#region Event Handlers
- private void NewMI_Click(object sender, EventArgs e)
+ private async void NewMI_ClickAsync(object sender, EventArgs e)
{
try
{
ReadValueId valueId = new ReadValueId();
- if (new ReadValueEditDlg().ShowDialog(m_session, valueId))
+ if (await new ReadValueEditDlg().ShowDialogAsync(m_session, valueId))
{
AddItem(valueId);
}
@@ -232,11 +233,11 @@ private void NewMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void EditMI_Click(object sender, EventArgs e)
+ private async void EditMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -247,14 +248,14 @@ private void EditMI_Click(object sender, EventArgs e)
return;
}
- if (new ReadValueEditDlg().ShowDialog(m_session, valueId))
+ if (await new ReadValueEditDlg().ShowDialogAsync(m_session, valueId))
{
- UpdateItem(ItemsLV.SelectedItems[0], valueId);
+ await UpdateItemAsync(ItemsLV.SelectedItems[0], valueId);
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -266,7 +267,7 @@ private void DeleteMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Subscriptions/RepublishNotificationMessageDlg.Designer.cs b/Samples/Controls.Net4/Subscriptions/RepublishNotificationMessageDlg.Designer.cs
index 0fe416d48..f9839e538 100644
--- a/Samples/Controls.Net4/Subscriptions/RepublishNotificationMessageDlg.Designer.cs
+++ b/Samples/Controls.Net4/Subscriptions/RepublishNotificationMessageDlg.Designer.cs
@@ -101,7 +101,7 @@ private void InitializeComponent()
this.OkBTN.TabIndex = 1;
this.OkBTN.Text = "OK";
this.OkBTN.UseVisualStyleBackColor = true;
- this.OkBTN.Click += new System.EventHandler(this.OkBTN_Click);
+ this.OkBTN.Click += new System.EventHandler(this.OkBTN_ClickAsync);
//
// CancelBTN
//
diff --git a/Samples/Controls.Net4/Subscriptions/RepublishNotificationMessageDlg.cs b/Samples/Controls.Net4/Subscriptions/RepublishNotificationMessageDlg.cs
index 4cf9a9c25..18a149821 100644
--- a/Samples/Controls.Net4/Subscriptions/RepublishNotificationMessageDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/RepublishNotificationMessageDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -50,19 +50,19 @@ public RepublishNotificationMessageDlg()
this.Icon = ClientUtils.GetAppIcon();
}
#endregion
-
+
#region Private Fields
private Subscription m_subscription;
private NotificationMessage m_message;
#endregion
-
+
#region Public Interface
///
/// Displays the dialog.
///
public NotificationMessage ShowDialog(Subscription subscription)
{
- if (subscription == null) throw new ArgumentNullException("subscription");
+ if (subscription == null) throw new ArgumentNullException(nameof(subscription));
m_subscription = subscription;
@@ -86,16 +86,16 @@ public NotificationMessage ShowDialog(Subscription subscription)
#endregion
#region Event Handlers
- private void OkBTN_Click(object sender, EventArgs e)
- {
+ private async void OkBTN_ClickAsync(object sender, EventArgs e)
+ {
try
{
- m_message = m_subscription.Republish((uint)SequenceNumberNC.Value);
+ m_message = await m_subscription.RepublishAsync((uint)SequenceNumberNC.Value);
DialogResult = DialogResult.OK;
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Subscriptions/SelectClauseListCtrl.cs b/Samples/Controls.Net4/Subscriptions/SelectClauseListCtrl.cs
index 1f485fb6b..2a4532244 100644
--- a/Samples/Controls.Net4/Subscriptions/SelectClauseListCtrl.cs
+++ b/Samples/Controls.Net4/Subscriptions/SelectClauseListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,10 +32,11 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
@@ -45,8 +46,8 @@ public partial class SelectClauseListCtrl : Opc.Ua.Client.Controls.BaseListCtrl
{
public SelectClauseListCtrl()
{
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
}
#region Private Fields
@@ -57,12 +58,12 @@ public SelectClauseListCtrl()
/// The columns to display in the control.
///
private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Event Type", HorizontalAlignment.Left, null },
- new object[] { "Field Name", HorizontalAlignment.Left, null },
- new object[] { "Index Range", HorizontalAlignment.Left, null }
- };
- #endregion
+ {
+ new object[] { "Event Type", HorizontalAlignment.Left, null },
+ new object[] { "Field Name", HorizontalAlignment.Left, null },
+ new object[] { "Index Range", HorizontalAlignment.Left, null }
+ };
+ #endregion
#region Public Interface
///
@@ -79,16 +80,16 @@ public void Clear()
///
public void Initialize(Session session, SimpleAttributeOperandCollection selectClauses)
{
- if (session == null) throw new ArgumentNullException("session");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
Clear();
-
- m_session = session;
+
+ m_session = session;
m_selectClauses = selectClauses;
if (selectClauses == null)
{
- return;
+ return;
}
foreach (SimpleAttributeOperand clause in selectClauses)
@@ -105,28 +106,28 @@ public void Initialize(Session session, SimpleAttributeOperandCollection selectC
///
/// Adds a select clause to the control.
///
- public void AddSelectClause(ReferenceDescription reference)
+ public async Task AddSelectClauseAsync(ReferenceDescription reference, CancellationToken ct = default)
{
if (reference == null)
{
return;
}
- ILocalNode node = m_session.NodeCache.Find(reference.NodeId) as ILocalNode;
+ ILocalNode node = await m_session.NodeCache.FindAsync(reference.NodeId, ct) as ILocalNode;
if (node == null)
{
return;
}
-
+
SimpleAttributeOperand clause = new SimpleAttributeOperand();
-
+
clause.TypeDefinitionId = m_session.NodeCache.BuildBrowsePath(node, clause.BrowsePath);
- clause.AttributeId = Attributes.Value;
-
+ clause.AttributeId = Attributes.Value;
+
AddItem(clause, "Property", -1);
- AdjustColumns();
+ AdjustColumns();
}
///
@@ -148,28 +149,28 @@ public SimpleAttributeOperandCollection GetSelectClauses()
return clauses;
}
- #endregion
-
+ #endregion
+
#region Overridden Methods
///
- protected override void EnableMenuItems(ListViewItem clickedItem)
- {
- ViewMI.Enabled = ItemsLV.SelectedItems.Count == 1;
+ protected override void EnableMenuItems(ListViewItem clickedItem)
+ {
+ ViewMI.Enabled = ItemsLV.SelectedItems.Count == 1;
DeleteMI.Enabled = ItemsLV.SelectedItems.Count > 0;
- }
-
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
+ }
+
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
{
- SimpleAttributeOperand clause = item as SimpleAttributeOperand;
+ SimpleAttributeOperand clause = item as SimpleAttributeOperand;
- if (clause == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
+ if (clause == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
- INode eventType = m_session.NodeCache.Find(clause.TypeDefinitionId);
+ INode eventType = await m_session.NodeCache.FindAsync(clause.TypeDefinitionId, ct);
if (eventType != null)
{
@@ -180,17 +181,17 @@ protected override void UpdateItem(ListViewItem listItem, object item)
listItem.SubItems[0].Text = String.Format("(unspecified)");
}
- listItem.SubItems[1].Text = String.Format("{0}", SimpleAttributeOperand.Format(clause.BrowsePath));
- listItem.SubItems[2].Text = String.Format("{0}", clause.IndexRange);
+ listItem.SubItems[1].Text = String.Format("{0}", SimpleAttributeOperand.Format(clause.BrowsePath));
+ listItem.SubItems[2].Text = String.Format("{0}", clause.IndexRange);
- listItem.Tag = item;
+ listItem.Tag = item;
}
///
/// Handles a drop event.
///
- protected override void ItemsLV_DragDrop(object sender, DragEventArgs e)
- {
+ protected override async Task OnDragDropAsync(object sender, DragEventArgs e, CancellationToken ct = default)
+ {
try
{
ReferenceDescription reference = e.Data.GetData(typeof(ReferenceDescription)) as ReferenceDescription;
@@ -199,16 +200,16 @@ protected override void ItemsLV_DragDrop(object sender, DragEventArgs e)
{
return;
}
-
- AddSelectClause(reference);
+
+ await AddSelectClauseAsync(reference, ct);
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
-
+
#region Event Handlers
private void ViewMI_Click(object sender, EventArgs e)
{
@@ -223,7 +224,7 @@ private void ViewMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -245,7 +246,7 @@ private void DeleteMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Subscriptions/SubscriptionDlg.Designer.cs b/Samples/Controls.Net4/Subscriptions/SubscriptionDlg.Designer.cs
index 77f95ce15..c776d4874 100644
--- a/Samples/Controls.Net4/Subscriptions/SubscriptionDlg.Designer.cs
+++ b/Samples/Controls.Net4/Subscriptions/SubscriptionDlg.Designer.cs
@@ -119,7 +119,7 @@ private void InitializeComponent()
this.EditMI.Name = "EditMI";
this.EditMI.Size = new System.Drawing.Size(306, 22);
this.EditMI.Text = "Edit...";
- this.EditMI.Click += new System.EventHandler(this.EditMI_Click);
+ this.EditMI.Click += new System.EventHandler(this.EditMI_ClickAsync);
//
// SubscriptionEnablePublishingMI
//
@@ -127,7 +127,7 @@ private void InitializeComponent()
this.SubscriptionEnablePublishingMI.Name = "SubscriptionEnablePublishingMI";
this.SubscriptionEnablePublishingMI.Size = new System.Drawing.Size(306, 22);
this.SubscriptionEnablePublishingMI.Text = "Enable Publishing";
- this.SubscriptionEnablePublishingMI.Click += new System.EventHandler(this.SubscriptionEnablePublishingMI_Click);
+ this.SubscriptionEnablePublishingMI.Click += new System.EventHandler(this.SubscriptionEnablePublishingMI_ClickAsync);
//
// SubscriptionCreateItemMI
//
@@ -187,7 +187,7 @@ private void InitializeComponent()
this.ConditionRefreshMI.Name = "ConditionRefreshMI";
this.ConditionRefreshMI.Size = new System.Drawing.Size(122, 22);
this.ConditionRefreshMI.Text = "Refresh...";
- this.ConditionRefreshMI.Click += new System.EventHandler(this.ConditionRefreshMI_Click);
+ this.ConditionRefreshMI.Click += new System.EventHandler(this.ConditionRefreshMI_ClickAsync);
//
// StatusBarCTRL
//
diff --git a/Samples/Controls.Net4/Subscriptions/SubscriptionDlg.cs b/Samples/Controls.Net4/Subscriptions/SubscriptionDlg.cs
index e5c9aa484..fc7fc434e 100644
--- a/Samples/Controls.Net4/Subscriptions/SubscriptionDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/SubscriptionDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -33,10 +33,11 @@
using System.Data;
using System.Drawing;
using System.Linq;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
@@ -50,9 +51,9 @@ public SubscriptionDlg()
InitializeComponent();
this.Icon = ClientUtils.GetAppIcon();
- m_SessionNotification = new NotificationEventHandler(Session_Notification);
+ m_SessionNotification = new NotificationEventHandler(Session_NotificationAsync);
m_SubscriptionStateChanged = new SubscriptionStateChangedEventHandler(Subscription_StateChanged);
- m_PublishStatusChanged = new PublishStateChangedEventHandler(Subscription_PublishStatusChanged);
+ m_PublishStatusChanged = new PublishStateChangedEventHandler(Subscription_PublishStatusChangedAsync);
}
#endregion
@@ -68,19 +69,19 @@ public SubscriptionDlg()
///
/// Creates a new subscription.
///
- public Subscription New(Session session)
+ public async Task NewAsync(Session session, CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
+ if (session == null) throw new ArgumentNullException(nameof(session));
Subscription subscription = new Subscription(session.DefaultSubscription);
- if (!new SubscriptionEditDlg().ShowDialog(subscription))
+ if (!await new SubscriptionEditDlg().ShowDialogAsync(subscription, ct))
{
return null;
}
session.AddSubscription(subscription);
- subscription.Create();
+ await subscription.CreateAsync(ct);
Subscription duplicateSubscription = session.Subscriptions.FirstOrDefault(s => s.Id != 0 && s.Id.Equals(subscription.Id) && s != subscription);
if (duplicateSubscription != null)
@@ -90,8 +91,8 @@ public Subscription New(Session session)
DialogResult result = MessageBox.Show("Duplicate subscription was created with the id: " + duplicateSubscription.Id + ". Do you want to keep it?", "Warning", MessageBoxButtons.YesNo);
if (result == System.Windows.Forms.DialogResult.No)
{
- duplicateSubscription.Delete(false);
- session.RemoveSubscription(subscription);
+ await duplicateSubscription.DeleteAsync(false, ct);
+ await session.RemoveSubscriptionAsync(subscription, ct);
return null;
}
@@ -107,7 +108,7 @@ public Subscription New(Session session)
///
public void Show(Subscription subscription)
{
- if (subscription == null) throw new ArgumentNullException("subscription");
+ if (subscription == null) throw new ArgumentNullException(nameof(subscription));
Show();
BringToFront();
@@ -132,7 +133,7 @@ public void Show(Subscription subscription)
MonitoredItemsCTRL.Initialize(subscription);
EventsCTRL.Initialize(subscription, null);
- DataChangesCTRL.Initialize(subscription, null);
+ DataChangesCTRL.InitializeAsync(subscription, null);
WindowMI_Click(WindowDataChangesMI, null);
@@ -213,7 +214,7 @@ private void UpdateStatus()
///
/// Processes a Publish repsonse from the server.
///
- void Session_Notification(ISession session, NotificationEventArgs e)
+ private async void Session_NotificationAsync(ISession session, NotificationEventArgs e)
{
if (InvokeRequired)
{
@@ -235,7 +236,7 @@ void Session_Notification(ISession session, NotificationEventArgs e)
// notify controls of the change.
EventsCTRL.NotificationReceived(e);
- DataChangesCTRL.NotificationReceived(e);
+ await DataChangesCTRL.NotificationReceivedAsync(e);
// update subscription status.
UpdateStatus();
@@ -249,7 +250,7 @@ void Session_Notification(ISession session, NotificationEventArgs e)
///
/// Handles a change to the state of the subscription.
///
- void Subscription_StateChanged(Subscription subscription, SubscriptionStateChangedEventArgs e)
+ private void Subscription_StateChanged(Subscription subscription, SubscriptionStateChangedEventArgs e)
{
if (InvokeRequired)
{
@@ -286,7 +287,7 @@ void Subscription_StateChanged(Subscription subscription, SubscriptionStateChang
///
/// Handles a change to the publish status for the subscription.
///
- void Subscription_PublishStatusChanged(object subscription, EventArgs e)
+ private async void Subscription_PublishStatusChangedAsync(object subscription, EventArgs e)
{
if (InvokeRequired)
{
@@ -307,7 +308,7 @@ void Subscription_PublishStatusChanged(object subscription, EventArgs e)
}
// notify controls of the change.
- DataChangesCTRL.PublishStatusChanged();
+ await DataChangesCTRL.PublishStatusChangedAsync();
}
catch (Exception exception)
{
@@ -367,11 +368,11 @@ private void WindowMI_Click(object sender, EventArgs e)
}
}
- private void SubscriptionEnablePublishingMI_Click(object sender, EventArgs e)
+ private async void SubscriptionEnablePublishingMI_ClickAsync(object sender, EventArgs e)
{
try
{
- m_subscription.SetPublishingMode(SubscriptionEnablePublishingMI.Checked);
+ await m_subscription.SetPublishingModeAsync(SubscriptionEnablePublishingMI.Checked);
}
catch (Exception exception)
{
@@ -396,16 +397,16 @@ private void SubscriptionDlg_FormClosing(object sender, FormClosingEventArgs e)
}
}
- private void EditMI_Click(object sender, EventArgs e)
+ private async void EditMI_ClickAsync(object sender, EventArgs e)
{
try
{
- if (!new SubscriptionEditDlg().ShowDialog(m_subscription))
+ if (!await new SubscriptionEditDlg().ShowDialogAsync(m_subscription))
{
return;
}
- m_subscription.Modify();
+ await m_subscription.ModifyAsync();
}
catch (Exception exception)
{
@@ -464,11 +465,11 @@ private void SubscriptionCreateItemFromTypeMI_Click(object sender, EventArgs e)
}
}
- private void ConditionRefreshMI_Click(object sender, EventArgs e)
+ private async void ConditionRefreshMI_ClickAsync(object sender, EventArgs e)
{
try
{
- m_subscription.ConditionRefresh();
+ await m_subscription.ConditionRefreshAsync();
}
catch (Exception exception)
{
diff --git a/Samples/Controls.Net4/Subscriptions/SubscriptionEditDlg.cs b/Samples/Controls.Net4/Subscriptions/SubscriptionEditDlg.cs
index 5ae319ac2..c80e5c643 100644
--- a/Samples/Controls.Net4/Subscriptions/SubscriptionEditDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/SubscriptionEditDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,10 +32,11 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Reflection;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using System.Reflection;
-
using Opc.Ua.Client;
namespace Opc.Ua.Sample.Controls
@@ -50,32 +51,32 @@ public SubscriptionEditDlg()
///
/// Prompts the user to specify the browse options.
///
- public bool ShowDialog(Subscription subscription)
+ public async Task ShowDialogAsync(Subscription subscription, CancellationToken ct = default)
{
- if (subscription == null) throw new ArgumentNullException("subscription");
+ if (subscription == null) throw new ArgumentNullException(nameof(subscription));
- DisplayNameTB.Text = subscription.DisplayName;
- PublishingIntervalNC.Value = subscription.Created ? (decimal)subscription.CurrentPublishingInterval : (decimal)subscription.PublishingInterval;
- KeepAliveCountNC.Value = subscription.Created ? subscription.CurrentKeepAliveCount : subscription.KeepAliveCount;
- LifetimeCountCTRL.Value = subscription.Created ? subscription.CurrentLifetimeCount: subscription.LifetimeCount;
- MaxNotificationsCTRL.Value = subscription.MaxNotificationsPerPublish;
- PriorityNC.Value = subscription.Created ? subscription.CurrentPriority : subscription.Priority;
+ DisplayNameTB.Text = subscription.DisplayName;
+ PublishingIntervalNC.Value = subscription.Created ? (decimal)subscription.CurrentPublishingInterval : (decimal)subscription.PublishingInterval;
+ KeepAliveCountNC.Value = subscription.Created ? subscription.CurrentKeepAliveCount : subscription.KeepAliveCount;
+ LifetimeCountCTRL.Value = subscription.Created ? subscription.CurrentLifetimeCount : subscription.LifetimeCount;
+ MaxNotificationsCTRL.Value = subscription.MaxNotificationsPerPublish;
+ PriorityNC.Value = subscription.Created ? subscription.CurrentPriority : subscription.Priority;
PublishingEnabledCK.Checked = subscription.Created ? subscription.CurrentPublishingEnabled : subscription.PublishingEnabled;
-
+
if (ShowDialog() != DialogResult.OK)
{
return false;
}
- subscription.DisplayName = DisplayNameTB.Text;
- subscription.PublishingInterval = (int)PublishingIntervalNC.Value;
- subscription.KeepAliveCount = (uint)KeepAliveCountNC.Value;
- subscription.LifetimeCount = (uint)LifetimeCountCTRL.Value;
+ subscription.DisplayName = DisplayNameTB.Text;
+ subscription.PublishingInterval = (int)PublishingIntervalNC.Value;
+ subscription.KeepAliveCount = (uint)KeepAliveCountNC.Value;
+ subscription.LifetimeCount = (uint)LifetimeCountCTRL.Value;
subscription.MaxNotificationsPerPublish = (uint)MaxNotificationsCTRL.Value;
- subscription.Priority = (byte)PriorityNC.Value;
+ subscription.Priority = (byte)PriorityNC.Value;
if (subscription.Created)
{
- subscription.SetPublishingMode(PublishingEnabledCK.Checked);
+ await subscription.SetPublishingModeAsync(PublishingEnabledCK.Checked, ct);
}
else
{
diff --git a/Samples/Controls.Net4/Subscriptions/WriteDlg.Designer.cs b/Samples/Controls.Net4/Subscriptions/WriteDlg.Designer.cs
index 6d9490479..9c41fd53d 100644
--- a/Samples/Controls.Net4/Subscriptions/WriteDlg.Designer.cs
+++ b/Samples/Controls.Net4/Subscriptions/WriteDlg.Designer.cs
@@ -98,7 +98,7 @@ private void InitializeComponent()
this.BackBTN.TabIndex = 3;
this.BackBTN.Text = "< Back";
this.BackBTN.UseVisualStyleBackColor = true;
- this.BackBTN.Click += new System.EventHandler(this.MoveBTN_Click);
+ this.BackBTN.Click += new System.EventHandler(this.MoveBTN_ClickAsync);
//
// CancelBTN
//
@@ -121,7 +121,7 @@ private void InitializeComponent()
this.NextBTN.TabIndex = 2;
this.NextBTN.Text = "Next >";
this.NextBTN.UseVisualStyleBackColor = true;
- this.NextBTN.Click += new System.EventHandler(this.MoveBTN_Click);
+ this.NextBTN.Click += new System.EventHandler(this.MoveBTN_ClickAsync);
//
// WriteBTN
//
@@ -132,7 +132,7 @@ private void InitializeComponent()
this.WriteBTN.TabIndex = 4;
this.WriteBTN.Text = "Write";
this.WriteBTN.UseVisualStyleBackColor = true;
- this.WriteBTN.Click += new System.EventHandler(this.WriteMI_Click);
+ this.WriteBTN.Click += new System.EventHandler(this.WriteMI_ClickAsync);
//
// SplitterPN
//
@@ -163,7 +163,7 @@ private void InitializeComponent()
this.BrowseCTRL.SessionTreeCtrl = null;
this.BrowseCTRL.Size = new System.Drawing.Size(297, 392);
this.BrowseCTRL.TabIndex = 1;
- this.BrowseCTRL.ItemsSelected += new Opc.Ua.Sample.Controls.NodesSelectedEventHandler(this.BrowseCTRL_ItemsSelected);
+ this.BrowseCTRL.ItemsSelected += new Opc.Ua.Sample.Controls.NodesSelectedEventHandler(this.BrowseCTRL_ItemsSelectedAsync);
//
// WriteResultsCTRL
//
diff --git a/Samples/Controls.Net4/Subscriptions/WriteDlg.cs b/Samples/Controls.Net4/Subscriptions/WriteDlg.cs
index 5de42e5fb..17f2e9ff0 100644
--- a/Samples/Controls.Net4/Subscriptions/WriteDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/WriteDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -38,6 +38,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading;
+using System.Threading.Tasks;
namespace Opc.Ua.Sample.Controls
{
@@ -54,21 +56,21 @@ public WriteDlg()
#region Private Fields
private Session m_session;
#endregion
-
+
#region Public Interface
///
/// Displays the dialog.
///
- public void Show(Session session, WriteValueCollection values)
+ public async Task ShowAsync(Session session, WriteValueCollection values, CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
m_session = session;
- BrowseCTRL.SetView(m_session, BrowseViewType.Objects, null);
+ await BrowseCTRL.SetViewAsync(m_session, BrowseViewType.Objects, null, ct);
WriteValuesCTRL.Initialize(session, values);
- MoveBTN_Click(BackBTN, null);
+ MoveBTN_ClickAsync(BackBTN, null);
Show();
BringToFront();
@@ -77,7 +79,7 @@ public void Show(Session session, WriteValueCollection values)
///
/// Writes the valus to the server.
///
- private void Write()
+ private async Task WriteAsync(CancellationToken ct = default)
{
WriteValueCollection nodesToWrite = Utils.Clone(WriteValuesCTRL.GetValues()) as WriteValueCollection;
@@ -105,24 +107,23 @@ private void Write()
}
}
- StatusCodeCollection results = null;
- DiagnosticInfoCollection diagnosticInfos = null;
-
- ResponseHeader responseHeader = m_session.Write(
+ WriteResponse response = await m_session.WriteAsync(
null,
nodesToWrite,
- out results,
- out diagnosticInfos);
+ ct);
+
+ StatusCodeCollection results = response.Results;
+ DiagnosticInfoCollection diagnosticInfos = response.DiagnosticInfos;
ClientBase.ValidateResponse(results, nodesToWrite);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToWrite);
- WriteResultsCTRL.ShowValue(results, true);
+ await WriteResultsCTRL.ShowValueAsync(results, true, ct);
}
#endregion
-
+
#region Event Handlers
- private void BrowseCTRL_ItemsSelected(object sender, NodesSelectedEventArgs e)
+ private async void BrowseCTRL_ItemsSelectedAsync(object sender, NodesSelectedEventArgs e)
{
try
{
@@ -130,61 +131,61 @@ private void BrowseCTRL_ItemsSelected(object sender, NodesSelectedEventArgs e)
{
if (reference.ReferenceTypeId == ReferenceTypeIds.HasProperty || reference.IsForward)
{
- WriteValuesCTRL.AddValue(reference);
+ await WriteValuesCTRL.AddValueAsync(reference);
}
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void MoveBTN_Click(object sender, EventArgs e)
+ private async void MoveBTN_ClickAsync(object sender, EventArgs e)
{
try
{
if (sender == NextBTN)
{
- Write();
+ await WriteAsync();
- WriteValuesCTRL.Parent = SplitterPN.Panel1;
+ WriteValuesCTRL.Parent = SplitterPN.Panel1;
- BackBTN.Visible = true;
- NextBTN.Visible = false;
- WriteBTN.Visible = true;
- WriteValuesCTRL.Visible = true;
+ BackBTN.Visible = true;
+ NextBTN.Visible = false;
+ WriteBTN.Visible = true;
+ WriteValuesCTRL.Visible = true;
WriteResultsCTRL.Visible = true;
- BrowseCTRL.Visible = false;
+ BrowseCTRL.Visible = false;
}
else if (sender == BackBTN)
{
- WriteValuesCTRL.Parent = SplitterPN.Panel2;
-
- BackBTN.Visible = false;
- NextBTN.Visible = true;
- WriteBTN.Visible = false;
- WriteResultsCTRL.Visible = false;
- BrowseCTRL.Visible = true;
- WriteValuesCTRL.Visible = true;
+ WriteValuesCTRL.Parent = SplitterPN.Panel2;
+
+ BackBTN.Visible = false;
+ NextBTN.Visible = true;
+ WriteBTN.Visible = false;
+ WriteResultsCTRL.Visible = false;
+ BrowseCTRL.Visible = true;
+ WriteValuesCTRL.Visible = true;
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void WriteMI_Click(object sender, EventArgs e)
+ private async void WriteMI_ClickAsync(object sender, EventArgs e)
{
try
{
- Write();
+ await WriteAsync();
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
@@ -196,7 +197,7 @@ private void CancelBTN_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/Subscriptions/WriteValueEditDlg.cs b/Samples/Controls.Net4/Subscriptions/WriteValueEditDlg.cs
index e1ef102a2..deb5d7f27 100644
--- a/Samples/Controls.Net4/Subscriptions/WriteValueEditDlg.cs
+++ b/Samples/Controls.Net4/Subscriptions/WriteValueEditDlg.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -33,10 +33,13 @@
using System.Data;
using System.Drawing;
using System.Text;
+using System.Linq;
using System.Windows.Forms;
using System.Reflection;
using Opc.Ua.Client;
+using System.Threading;
+using System.Threading.Tasks;
namespace Opc.Ua.Sample.Controls
{
@@ -46,54 +49,54 @@ public WriteValueEditDlg()
{
InitializeComponent();
- AttributeIdCB.Items.AddRange(Attributes.GetBrowseNames());
+ AttributeIdCB.Items.AddRange(Attributes.BrowseNames.ToArray());
}
///
/// Prompts the user to specify the browse options.
///
- public bool ShowDialog(Session session, WriteValue value)
+ public async Task ShowDialogAsync(Session session, WriteValue value, CancellationToken ct = default)
{
- if (session == null) throw new ArgumentNullException("session");
- if (value == null) throw new ArgumentNullException("value");
+ if (session == null) throw new ArgumentNullException(nameof(session));
+ if (value == null) throw new ArgumentNullException(nameof(value));
+
-
NodeIdCTRL.Browser = new Browser(session);
- INode node = session.NodeCache.Find(value.NodeId);
+ INode node = await session.NodeCache.FindAsync(value.NodeId, ct);
if (node != null)
{
DisplayNameTB.Text = node.ToString();
}
- NodeIdCTRL.Identifier = value.NodeId;
+ NodeIdCTRL.Identifier = value.NodeId;
AttributeIdCB.SelectedItem = Attributes.GetBrowseName(value.AttributeId);
- IndexRangeTB.Text = value.IndexRange;
-
+ IndexRangeTB.Text = value.IndexRange;
+
if (ShowDialog() != DialogResult.OK)
{
return false;
}
- value.NodeId = NodeIdCTRL.Identifier;
+ value.NodeId = NodeIdCTRL.Identifier;
value.AttributeId = Attributes.GetIdentifier((string)AttributeIdCB.SelectedItem);
- value.IndexRange = IndexRangeTB.Text;
-
+ value.IndexRange = IndexRangeTB.Text;
+
return true;
}
private void OkBTN_Click(object sender, EventArgs e)
- {
+ {
try
{
NodeId nodeId = NodeIdCTRL.Identifier;
}
catch (Exception)
{
- MessageBox.Show("Please enter a valid node id.", this.Text);
+ MessageBox.Show("Please enter a valid node id.", this.Text);
}
-
+
try
{
if (!String.IsNullOrEmpty(IndexRangeTB.Text))
@@ -103,7 +106,7 @@ private void OkBTN_Click(object sender, EventArgs e)
}
catch (Exception)
{
- MessageBox.Show("Please enter a valid index range.", this.Text);
+ MessageBox.Show("Please enter a valid index range.", this.Text);
}
DialogResult = DialogResult.OK;
diff --git a/Samples/Controls.Net4/Subscriptions/WriteValueListCtrl.Designer.cs b/Samples/Controls.Net4/Subscriptions/WriteValueListCtrl.Designer.cs
index 1a4cd5510..d2bba53a4 100644
--- a/Samples/Controls.Net4/Subscriptions/WriteValueListCtrl.Designer.cs
+++ b/Samples/Controls.Net4/Subscriptions/WriteValueListCtrl.Designer.cs
@@ -85,21 +85,21 @@ private void InitializeComponent()
this.NewMI.Name = "NewMI";
this.NewMI.Size = new System.Drawing.Size(152, 22);
this.NewMI.Text = "New...";
- this.NewMI.Click += new System.EventHandler(this.NewMI_Click);
+ this.NewMI.Click += new System.EventHandler(this.NewMI_ClickAsync);
//
// EditMI
//
this.EditMI.Name = "EditMI";
this.EditMI.Size = new System.Drawing.Size(152, 22);
this.EditMI.Text = "Edit...";
- this.EditMI.Click += new System.EventHandler(this.EditMI_Click);
+ this.EditMI.Click += new System.EventHandler(this.EditMI_ClickAsync);
//
// EditValueMI
//
this.EditValueMI.Name = "EditValueMI";
this.EditValueMI.Size = new System.Drawing.Size(152, 22);
this.EditValueMI.Text = "Edit Value...";
- this.EditValueMI.Click += new System.EventHandler(this.EditValueMI_Click);
+ this.EditValueMI.Click += new System.EventHandler(this.EditValueMI_ClickAsync);
//
// DeleteMI
//
diff --git a/Samples/Controls.Net4/Subscriptions/WriteValueListCtrl.cs b/Samples/Controls.Net4/Subscriptions/WriteValueListCtrl.cs
index c9fdab190..47475f5b3 100644
--- a/Samples/Controls.Net4/Subscriptions/WriteValueListCtrl.cs
+++ b/Samples/Controls.Net4/Subscriptions/WriteValueListCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -38,6 +38,8 @@
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Sample.Controls
{
@@ -45,8 +47,8 @@ public partial class WriteValueListCtrl : Opc.Ua.Client.Controls.BaseListCtrl
{
public WriteValueListCtrl()
{
- InitializeComponent();
- SetColumns(m_ColumnNames);
+ InitializeComponent();
+ SetColumns(m_ColumnNames);
}
#region Private Fields
@@ -56,16 +58,16 @@ public WriteValueListCtrl()
/// The columns to display in the control.
///
private readonly object[][] m_ColumnNames = new object[][]
- {
- new object[] { "Name", HorizontalAlignment.Left, null },
- new object[] { "NodeId", HorizontalAlignment.Left, null },
- new object[] { "Attribute", HorizontalAlignment.Left, "Value" },
- new object[] { "IndexRange", HorizontalAlignment.Left, "" },
- new object[] { "Value", HorizontalAlignment.Left, "" },
- new object[] { "Status", HorizontalAlignment.Left, "" },
- new object[] { "Timestamp", HorizontalAlignment.Left, "" }
- };
- #endregion
+ {
+ new object[] { "Name", HorizontalAlignment.Left, null },
+ new object[] { "NodeId", HorizontalAlignment.Left, null },
+ new object[] { "Attribute", HorizontalAlignment.Left, "Value" },
+ new object[] { "IndexRange", HorizontalAlignment.Left, "" },
+ new object[] { "Value", HorizontalAlignment.Left, "" },
+ new object[] { "Status", HorizontalAlignment.Left, "" },
+ new object[] { "Timestamp", HorizontalAlignment.Left, "" }
+ };
+ #endregion
#region Public Interface
///
@@ -82,10 +84,10 @@ public void Clear()
///
public void Initialize(Session session, WriteValueCollection values)
{
- if (session == null) throw new ArgumentNullException("session");
-
+ if (session == null) throw new ArgumentNullException(nameof(session));
+
Clear();
-
+
m_session = session;
if (values != null)
@@ -102,9 +104,9 @@ public void Initialize(Session session, WriteValueCollection values)
///
/// Adds a value to the control.
///
- public void AddValue(ReferenceDescription reference)
+ public async Task AddValueAsync(ReferenceDescription reference, CancellationToken ct = default)
{
- Node node = m_session.NodeCache.Find(reference.NodeId) as Node;
+ Node node = await m_session.NodeCache.FindAsync(reference.NodeId, ct) as Node;
if (node == null)
{
@@ -113,17 +115,17 @@ public void AddValue(ReferenceDescription reference)
WriteValue value = new WriteValue();
- value.NodeId = node.NodeId;
+ value.NodeId = node.NodeId;
value.AttributeId = Attributes.Value;
- value.IndexRange = null;
+ value.IndexRange = null;
// read the display name for non-variables.
if ((node.NodeClass & (NodeClass.Variable | NodeClass.VariableType)) == 0)
{
- value.AttributeId = Attributes.DisplayName;
+ value.AttributeId = Attributes.DisplayName;
}
- value.Value = GetDefaultValue(value.NodeId, value.AttributeId);
+ value.Value = await GetDefaultValueAsync(value.NodeId, value.AttributeId, ct);
AddItem(value);
AdjustColumns();
@@ -157,10 +159,10 @@ public WriteValueCollection GetValues()
///
/// Returns a default value for the node.
///
- private DataValue GetDefaultValue(NodeId nodeId, uint attributeId)
+ private async Task GetDefaultValueAsync(NodeId nodeId, uint attributeId, CancellationToken ct = default)
{
// find the node.
- Node node = m_session.NodeCache.Find(nodeId) as Node;
+ Node node = await m_session.NodeCache.FindAsync(nodeId, ct) as Node;
if (node == null)
{
@@ -176,13 +178,13 @@ private DataValue GetDefaultValue(NodeId nodeId, uint attributeId)
{
value.Value = GuiUtils.GetDefaultValue(Attributes.GetDataTypeId(attributeId), ValueRanks.Scalar);
}
-
+
// update the value attribute.
if (attributeId == Attributes.Value)
{
try
{
- return m_session.ReadValue(node.NodeId);
+ return await m_session.ReadValueAsync(node.NodeId, ct);
}
catch (Exception)
{
@@ -194,50 +196,50 @@ private DataValue GetDefaultValue(NodeId nodeId, uint attributeId)
}
}
}
-
+
return value;
}
- #endregion
-
+ #endregion
+
#region Overridden Methods
///
protected override void PickItems()
{
base.PickItems();
- EditValueMI_Click(this, null);
+ EditValueMI_ClickAsync(this, null);
}
///
protected override void EnableMenuItems(ListViewItem clickedItem)
- {
- NewMI.Enabled = true;
- EditMI.Enabled = ItemsLV.SelectedItems.Count == 1;
- EditValueMI.Enabled = ItemsLV.SelectedItems.Count == 1;
- DeleteMI.Enabled = ItemsLV.SelectedItems.Count > 0;
- }
-
- ///
- protected override void UpdateItem(ListViewItem listItem, object item)
{
- WriteValue value = item as WriteValue;
-
- if (value == null)
- {
- base.UpdateItem(listItem, item);
- return;
- }
-
+ NewMI.Enabled = true;
+ EditMI.Enabled = ItemsLV.SelectedItems.Count == 1;
+ EditValueMI.Enabled = ItemsLV.SelectedItems.Count == 1;
+ DeleteMI.Enabled = ItemsLV.SelectedItems.Count > 0;
+ }
+
+ ///
+ protected override async Task UpdateItemAsync(ListViewItem listItem, object item, CancellationToken ct = default)
+ {
+ WriteValue value = item as WriteValue;
+
+ if (value == null)
+ {
+ await base.UpdateItemAsync(listItem, item, ct);
+ return;
+ }
+
if (value.Value == null)
{
value.Value = new DataValue();
}
-
+
if (value.Value.Value == null)
{
- value.Value = GetDefaultValue(value.NodeId, value.AttributeId);
+ value.Value = await GetDefaultValueAsync(value.NodeId, value.AttributeId, ct);
}
-
- Node node = m_session.NodeCache.Find(value.NodeId) as Node;
+
+ Node node = await m_session.NodeCache.FindAsync(value.NodeId, ct) as Node;
if (node != null)
{
@@ -247,23 +249,23 @@ protected override void UpdateItem(ListViewItem listItem, object item)
{
listItem.SubItems[0].Text = String.Format("{0}", value.NodeId);
}
-
+
listItem.SubItems[1].Text = String.Format("{0}", value.NodeId);
listItem.SubItems[2].Text = String.Format("{0}", Attributes.GetBrowseName(value.AttributeId));
listItem.SubItems[3].Text = String.Format("{0}", value.IndexRange);
listItem.SubItems[4].Text = String.Format("{0}", value.Value.Value);
listItem.SubItems[5].Text = String.Format("{0}", value.Value.StatusCode);
listItem.SubItems[6].Text = String.Format("{0}", value.Value.SourceTimestamp);
-
- listItem.Tag = item;
+
+ listItem.Tag = item;
listItem.ImageKey = "DataType";
}
///
/// Handles a drop event.
///
- protected override void ItemsLV_DragDrop(object sender, DragEventArgs e)
- {
+ protected override async Task OnDragDropAsync(object sender, DragEventArgs e, CancellationToken ct = default)
+ {
try
{
ReferenceDescription reference = e.Data.GetData(typeof(ReferenceDescription)) as ReferenceDescription;
@@ -272,24 +274,24 @@ protected override void ItemsLV_DragDrop(object sender, DragEventArgs e)
{
return;
}
-
- AddValue(reference);
+
+ await AddValueAsync(reference, ct);
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
-
+
#region Event Handlers
- private void NewMI_Click(object sender, EventArgs e)
+ private async void NewMI_ClickAsync(object sender, EventArgs e)
{
try
{
WriteValue value = new WriteValue();
- if (new WriteValueEditDlg().ShowDialog(m_session, value))
+ if (await new WriteValueEditDlg().ShowDialogAsync(m_session, value))
{
AddItem(value);
}
@@ -298,11 +300,11 @@ private void NewMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void EditMI_Click(object sender, EventArgs e)
+ private async void EditMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -313,9 +315,9 @@ private void EditMI_Click(object sender, EventArgs e)
return;
}
- if (new WriteValueEditDlg().ShowDialog(m_session, values[0]))
+ if (await new WriteValueEditDlg().ShowDialogAsync(m_session, values[0]))
{
- Node node = m_session.NodeCache.Find(values[0].NodeId) as Node;
+ Node node = await m_session.NodeCache.FindAsync(values[0].NodeId) as Node;
if (node != null)
{
@@ -329,16 +331,16 @@ private void EditMI_Click(object sender, EventArgs e)
}
}
- UpdateItem(ItemsLV.SelectedItems[0], values[0]);
+ await UpdateItemAsync(ItemsLV.SelectedItems[0], values[0]);
}
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
- private void EditValueMI_Click(object sender, EventArgs e)
+ private async void EditValueMI_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -354,7 +356,7 @@ private void EditValueMI_Click(object sender, EventArgs e)
if (values[0].AttributeId == Attributes.Value)
{
- VariableNode node = m_session.NodeCache.Find(values[0].NodeId) as VariableNode;
+ VariableNode node = await m_session.NodeCache.FindAsync(values[0].NodeId) as VariableNode;
if (node != null)
{
@@ -399,7 +401,7 @@ private void EditValueMI_Click(object sender, EventArgs e)
values[0].Value.Value = value;
values[0].Value.StatusCode = StatusCodes.Good;
- UpdateItem(ItemsLV.SelectedItems[0], values[0]);
+ await UpdateItemAsync(ItemsLV.SelectedItems[0], values[0]);
AdjustColumns();
}
@@ -430,7 +432,7 @@ private void DeleteMI_Click(object sender, EventArgs e)
}
catch (Exception exception)
{
- GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
}
}
#endregion
diff --git a/Samples/Controls.Net4/UA Sample Controls.csproj b/Samples/Controls.Net4/UA Sample Controls.csproj
index 59a25e85a..38d474d6a 100644
--- a/Samples/Controls.Net4/UA Sample Controls.csproj
+++ b/Samples/Controls.Net4/UA Sample Controls.csproj
@@ -46,6 +46,7 @@
4
AnyCPU
false
+ AllRules.ruleset
pdbonly
@@ -56,6 +57,7 @@
4
AnyCPU
false
+ AllRules.ruleset
@@ -200,12 +202,6 @@
SelectClauseListCtrl.cs
-
- Form
-
-
- DataEncodingDlg.cs
-
UserControl
@@ -519,10 +515,6 @@
SelectClauseListCtrl.cs
Designer
-
- DataEncodingDlg.cs
- Designer
-
Designer
PerformanceResultsListCtrl.cs
@@ -707,8 +699,11 @@
+
+ 1.5.377.11-preview
+
- 1.5.376.244
+ 1.5.377.11-preview
diff --git a/Samples/GDS/Client/Controls/ApplicationCertificateControl.cs b/Samples/GDS/Client/Controls/ApplicationCertificateControl.cs
index 5c09a8a09..523f8e065 100644
--- a/Samples/GDS/Client/Controls/ApplicationCertificateControl.cs
+++ b/Samples/GDS/Client/Controls/ApplicationCertificateControl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -32,6 +32,7 @@
using System.Drawing;
using System.IO;
using System.Security.Cryptography.X509Certificates;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -52,12 +53,13 @@ public ApplicationCertificateControl()
private bool m_temporaryCertificateCreated;
private string m_certificatePassword;
- public async Task Initialize(
+ public async Task InitializeAsync(
GlobalDiscoveryClientConfiguration configuration,
GlobalDiscoveryServerClient gds,
ServerPushConfigurationClient server,
RegisteredApplication application,
- bool isHttps)
+ bool isHttps,
+ CancellationToken ct = default)
{
m_configuration = configuration;
m_gds = gds;
@@ -100,7 +102,7 @@ public async Task Initialize(
id.StoreType = CertificateStoreIdentifier.DetermineStoreType(id.StorePath);
id.SubjectName = application.CertificateSubjectName.Replace("localhost", Utils.GetHostName());
- certificate = await id.Find(true);
+ certificate = await id.FindAsync(true, ct: ct);
}
}
}
@@ -131,7 +133,7 @@ public async Task Initialize(
SubjectName = "CN=" + url.DnsSafeHost
};
- certificate = await id.Find();
+ certificate = await id.FindAsync(ct: ct);
}
}
}
@@ -170,31 +172,31 @@ private async void RequestNewButton_Click(object sender, EventArgs e)
{
if (m_application.RegistrationType == RegistrationType.ServerPush)
{
- RequestNewCertificatePushMode(sender, e);
+ await RequestNewCertificatePushModeAsync(sender, e);
}
else
{
- await RequestNewCertificatePullMode(sender, e);
+ await RequestNewCertificatePullModeAsync(sender, e);
}
}
- private void RequestNewCertificatePushMode(object sender, EventArgs e)
+ private async Task RequestNewCertificatePushModeAsync(object sender, EventArgs e)
{
try
{
- NodeId trustListId = m_gds.GetTrustList(m_application.ApplicationId, NodeId.Null);
- var trustList = m_gds.ReadTrustList(trustListId);
- bool applyChanges = m_server.UpdateTrustList(trustList);
+ NodeId trustListId = await m_gds.GetTrustListAsync(m_application.ApplicationId, NodeId.Null);
+ var trustList = await m_gds.ReadTrustListAsync(trustListId);
+ bool applyChanges = await m_server.UpdateTrustListAsync(trustList);
- byte[] unusedNonce = new byte[0];
- byte[] certificateRequest = m_server.CreateSigningRequest(
+ byte[] unusedNonce = Array.Empty();
+ byte[] certificateRequest = await m_server.CreateSigningRequestAsync(
NodeId.Null,
m_server.ApplicationCertificateType,
string.Empty,
false,
unusedNonce);
var domainNames = m_application.GetDomainNames(m_certificate);
- NodeId requestId = m_gds.StartSigningRequest(
+ NodeId requestId = await m_gds.StartSigningRequestAsync(
m_application.ApplicationId,
NodeId.Null,
NodeId.Null,
@@ -223,7 +225,7 @@ private void RequestNewCertificatePushMode(object sender, EventArgs e)
}
}
- private async Task RequestNewCertificatePullMode(object sender, EventArgs e)
+ private async Task RequestNewCertificatePullModeAsync(object sender, EventArgs e)
{
try
{
@@ -236,7 +238,7 @@ private async Task RequestNewCertificatePullMode(object sender, EventArgs e)
StorePath = m_application.CertificateStorePath,
SubjectName = Utils.ReplaceDCLocalhost(m_application.CertificateSubjectName)
};
- m_certificate = await id.Find(true);
+ m_certificate = await id.FindAsync(true);
//test if private key is available & exportable, else create new temporary certificate for csr
if (m_certificate != null &&
m_certificate.HasPrivateKey)
@@ -246,7 +248,7 @@ private async Task RequestNewCertificatePullMode(object sender, EventArgs e)
//this line fails with a CryptographicException if export of private key is not allowed
_ = m_certificate.GetRSAPrivateKey().ExportParameters(true);
//proceed with a CSR using the exportable private key
- m_certificate = await id.LoadPrivateKey(m_certificatePassword);
+ m_certificate = await id.LoadPrivateKeyAsync(m_certificatePassword);
}
catch
{
@@ -276,7 +278,7 @@ private async Task RequestNewCertificatePullMode(object sender, EventArgs e)
if (m_certificate == null)
{
// no private key
- requestId = m_gds.StartNewKeyPairRequest(
+ requestId = await m_gds.StartNewKeyPairRequestAsync(
m_application.ApplicationId,
NodeId.Null,
NodeId.Null,
@@ -296,7 +298,7 @@ private async Task RequestNewCertificatePullMode(object sender, EventArgs e)
{
string absoluteCertificatePrivateKeyPath = Utils.GetAbsoluteFilePath(m_application.CertificatePrivateKeyPath, true, false, false);
byte[] pkcsData = File.ReadAllBytes(absoluteCertificatePrivateKeyPath);
- if (m_application.GetPrivateKeyFormat(m_server?.GetSupportedKeyFormats()) == "PFX")
+ if (m_application.GetPrivateKeyFormat(await m_server?.GetSupportedKeyFormatsAsync()) == "PFX")
{
csrCertificate = X509PfxUtils.CreateCertificateFromPKCS12(pkcsData, m_certificatePassword);
}
@@ -306,7 +308,7 @@ private async Task RequestNewCertificatePullMode(object sender, EventArgs e)
}
}
byte[] certificateRequest = CertificateFactory.CreateSigningRequest(csrCertificate, domainNames);
- requestId = m_gds.StartSigningRequest(m_application.ApplicationId, NodeId.Null, NodeId.Null, certificateRequest);
+ requestId = await m_gds.StartSigningRequestAsync(m_application.ApplicationId, NodeId.Null, NodeId.Null, certificateRequest);
}
m_application.CertificateRequestId = requestId.ToString();
@@ -326,14 +328,9 @@ private async void CertificateRequestTimer_Tick(object sender, EventArgs e)
{
NodeId requestId = NodeId.Parse(m_application.CertificateRequestId);
- byte[] privateKeyPFX = null;
- byte[][] issuerCertificates = null;
-
- byte[] certificate = m_gds.FinishRequest(
+ (byte[] certificate, byte[] privateKeyPFX, byte[][] issuerCertificates) = await m_gds.FinishRequestAsync(
m_application.ApplicationId,
- requestId,
- out privateKeyPFX,
- out issuerCertificates);
+ requestId);
if (certificate == null)
{
@@ -365,12 +362,12 @@ private async void CertificateRequestTimer_Tick(object sender, EventArgs e)
// in this case, privateKey is null
if (privateKeyPFX == null)
{
- X509Certificate2 oldCertificate = await cid.Find(true);
+ X509Certificate2 oldCertificate = await cid.FindAsync(true);
if (oldCertificate != null && oldCertificate.HasPrivateKey)
{
- oldCertificate = await cid.LoadPrivateKey(string.Empty);
+ oldCertificate = await cid.LoadPrivateKeyAsync(string.Empty);
newCert = CertificateFactory.CreateCertificateWithPrivateKey(newCert, m_temporaryCertificateCreated ? m_certificate : oldCertificate);
- await store.Delete(oldCertificate.Thumbprint);
+ await store.DeleteAsync(oldCertificate.Thumbprint);
}
else
{
@@ -382,7 +379,7 @@ private async void CertificateRequestTimer_Tick(object sender, EventArgs e)
newCert = new X509Certificate2(privateKeyPFX, string.Empty, X509KeyStorageFlags.Exportable);
newCert = CertificateFactory.Load(newCert, true);
}
- await store.Add(newCert);
+ await store.AddAsync(newCert);
if (m_temporaryCertificateCreated)
{
m_certificate.Dispose();
@@ -423,7 +420,7 @@ private async void CertificateRequestTimer_Tick(object sender, EventArgs e)
}
// if we provided a PFX or P12 with the private key, we need to merge the new cert with the private key
- if (m_application.GetPrivateKeyFormat(m_server?.GetSupportedKeyFormats()) == "PFX")
+ if (m_application.GetPrivateKeyFormat(await m_server?.GetSupportedKeyFormatsAsync()) == "PFX")
{
string absoluteCertificatePrivateKeyPath = Utils.GetAbsoluteFilePath(m_application.CertificatePrivateKeyPath, true, false, false) ?? m_application.CertificatePrivateKeyPath;
file = new FileInfo(absoluteCertificatePrivateKeyPath);
@@ -471,10 +468,10 @@ private async void CertificateRequestTimer_Tick(object sender, EventArgs e)
foreach (byte[] issuerCertificate in issuerCertificates)
{
X509Certificate2 x509 = new X509Certificate2(issuerCertificate);
- X509Certificate2Collection certs = await store.FindByThumbprint(x509.Thumbprint);
+ X509Certificate2Collection certs = await store.FindByThumbprintAsync(x509.Thumbprint);
if (certs.Count == 0)
{
- await store.Add(new X509Certificate2(issuerCertificate));
+ await store.AddAsync(new X509Certificate2(issuerCertificate));
}
}
}
@@ -491,8 +488,8 @@ private async void CertificateRequestTimer_Tick(object sender, EventArgs e)
privateKeyPFX = x509.Export(X509ContentType.Pfx);
}
- byte[] unusedPrivateKey = new byte[0];
- bool applyChanges = m_server.UpdateCertificate(
+ byte[] unusedPrivateKey = Array.Empty();
+ bool applyChanges = await m_server.UpdateCertificateAsync(
NodeId.Null,
m_server.ApplicationCertificateType,
certificate,
@@ -528,12 +525,12 @@ private async void CertificateRequestTimer_Tick(object sender, EventArgs e)
}
}
- private void ApplyChangesButton_Click(object sender, EventArgs e)
+ private async void ApplyChangesButton_Click(object sender, EventArgs e)
{
ApplyChangesButton.Enabled = false;
try
{
- m_server.ApplyChanges();
+ await m_server.ApplyChangesAsync();
}
catch (Exception exception)
{
@@ -547,9 +544,9 @@ private void ApplyChangesButton_Click(object sender, EventArgs e)
try
{
- m_server.Disconnect();
+ await m_server.DisconnectAsync();
}
- catch (Exception)
+ catch
{
// ignore.
}
diff --git a/Samples/GDS/Client/Controls/ApplicationTrustListControl.Designer.cs b/Samples/GDS/Client/Controls/ApplicationTrustListControl.Designer.cs
index 413ea3055..f2b31ce46 100644
--- a/Samples/GDS/Client/Controls/ApplicationTrustListControl.Designer.cs
+++ b/Samples/GDS/Client/Controls/ApplicationTrustListControl.Designer.cs
@@ -167,7 +167,7 @@ private void InitializeComponent()
this.ReadTrustListButton.Text = "Reload";
this.ToolTips.SetToolTip(this.ReadTrustListButton, "Reloads the Trust List from disk or by reading it from the remote Server.");
this.ReadTrustListButton.UseVisualStyleBackColor = false;
- this.ReadTrustListButton.Click += new System.EventHandler(this.ReloadTrustListButton_Click);
+ this.ReadTrustListButton.Click += new System.EventHandler(this.ReloadTrustListButton_ClickAsync);
this.ReadTrustListButton.MouseEnter += new System.EventHandler(this.Button_MouseEnter);
this.ReadTrustListButton.MouseLeave += new System.EventHandler(this.Button_MouseLeave);
//
diff --git a/Samples/GDS/Client/Controls/ApplicationTrustListControl.cs b/Samples/GDS/Client/Controls/ApplicationTrustListControl.cs
index a896d3de0..beb658b60 100644
--- a/Samples/GDS/Client/Controls/ApplicationTrustListControl.cs
+++ b/Samples/GDS/Client/Controls/ApplicationTrustListControl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -35,6 +35,7 @@
using Opc.Ua.Gds;
using System.Threading.Tasks;
using Opc.Ua.Security.Certificates;
+using System.Threading;
namespace Opc.Ua.Gds.Client
{
@@ -53,7 +54,7 @@ public ApplicationTrustListControl()
private string m_trustListStorePath;
private string m_issuerListStorePath;
- public void Initialize(GlobalDiscoveryServerClient gds, ServerPushConfigurationClient server, RegisteredApplication application, bool isHttps)
+ public async Task Initialize(GlobalDiscoveryServerClient gds, ServerPushConfigurationClient server, RegisteredApplication application, bool isHttps, CancellationToken ct = default)
{
m_gds = gds;
m_server = server;
@@ -64,14 +65,14 @@ public void Initialize(GlobalDiscoveryServerClient gds, ServerPushConfigurationC
{
m_trustListStorePath = (isHttps) ? m_application.HttpsTrustListStorePath : m_application.TrustListStorePath;
m_issuerListStorePath = (isHttps) ? m_application.HttpsIssuerListStorePath : m_application.IssuerListStorePath;
- CertificateStoreControl.Initialize(m_trustListStorePath, m_issuerListStorePath, null);
+ await CertificateStoreControl.Initialize(m_trustListStorePath, m_issuerListStorePath, null, ct);
MergeWithGdsButton.Enabled = !String.IsNullOrEmpty(m_trustListStorePath) || m_application.RegistrationType == RegistrationType.ServerPush;
}
ApplyChangesButton.Enabled = false;
}
- private void ReloadTrustListButton_Click(object sender, EventArgs e)
+ private async void ReloadTrustListButton_ClickAsync(object sender, EventArgs e)
{
try
{
@@ -83,18 +84,18 @@ private void ReloadTrustListButton_Click(object sender, EventArgs e)
if (!Enum.TryParse(TrustListMasksComboBox.SelectedItem.ToString(), out masks))
masks = TrustListMasks.All;
- var trustList = m_server.ReadTrustList(masks);
- var rejectedList = m_server.GetRejectedList();
+ var trustList = await m_server.ReadTrustListAsync(masks);
+ var rejectedList = await m_server.GetRejectedListAsync();
CertificateStoreControl.Initialize(trustList, rejectedList, true);
}
else
{
- CertificateStoreControl.Initialize(m_trustListStorePath, m_issuerListStorePath, null);
+ await CertificateStoreControl.Initialize(m_trustListStorePath, m_issuerListStorePath, null);
}
}
else
{
- CertificateStoreControl.Initialize(null, null, null);
+ await CertificateStoreControl.Initialize(null, null, null);
}
}
catch (Exception ex)
@@ -103,17 +104,31 @@ private void ReloadTrustListButton_Click(object sender, EventArgs e)
}
}
- private void MergeWithGdsButton_Click(object sender, EventArgs e)
+ private async void MergeWithGdsButton_Click(object sender, EventArgs e)
{
- PullFromGds(false);
+ try
+ {
+ await PullFromGdsAsync(false);
+ }
+ catch (Exception ex)
+ {
+ Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, ex);
+ }
}
- private void PullFromGdsButton_Click(object sender, EventArgs e)
+ private async void PullFromGdsButton_Click(object sender, EventArgs e)
{
- PullFromGds(true);
+ try
+ {
+ await PullFromGdsAsync(true);
+ }
+ catch (Exception ex)
+ {
+ Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, ex);
+ }
}
- private async Task DeleteExistingFromStore(string storePath)
+ private async Task DeleteExistingFromStoreAsync(string storePath, CancellationToken ct = default)
{
if (String.IsNullOrEmpty(storePath))
{
@@ -123,7 +138,7 @@ private async Task DeleteExistingFromStore(string storePath)
var certificateStoreIdentifier = new CertificateStoreIdentifier(storePath);
using (var store = certificateStoreIdentifier.OpenStore())
{
- X509Certificate2Collection certificates = await store.Enumerate();
+ X509Certificate2Collection certificates = await store.EnumerateAsync(ct);
foreach (var certificate in certificates)
{
List fields = X509Utils.ParseDistinguishedName(certificate.Subject);
@@ -162,24 +177,24 @@ private async Task DeleteExistingFromStore(string storePath)
}
}
- await store.Delete(certificate.Thumbprint);
+ await store.DeleteAsync(certificate.Thumbprint, ct);
}
}
}
- private void PullFromGds(bool deleteBeforeAdd)
+ private async Task PullFromGdsAsync(bool deleteBeforeAdd, CancellationToken ct = default)
{
try
{
- NodeId trustListId = m_gds.GetTrustList(m_application.ApplicationId, NodeId.Null);
+ NodeId trustListId = await m_gds.GetTrustListAsync(m_application.ApplicationId, NodeId.Null, ct);
if (trustListId == null)
{
- CertificateStoreControl.Initialize(null, null, null);
+ await CertificateStoreControl.Initialize(null, null, null, ct);
return;
}
- var trustList = m_gds.ReadTrustList(trustListId);
+ var trustList = await m_gds.ReadTrustListAsync(trustListId, ct);
if (m_application.RegistrationType == RegistrationType.ServerPush)
{
@@ -199,8 +214,8 @@ private void PullFromGds(bool deleteBeforeAdd)
{
if (deleteBeforeAdd)
{
- DeleteExistingFromStore(m_trustListStorePath).Wait();
- DeleteExistingFromStore(m_issuerListStorePath).Wait(); ;
+ await DeleteExistingFromStoreAsync(m_trustListStorePath, ct);
+ await DeleteExistingFromStoreAsync(m_issuerListStorePath, ct);
}
}
@@ -215,10 +230,10 @@ private void PullFromGds(bool deleteBeforeAdd)
{
var x509 = new X509Certificate2(certificate);
- X509Certificate2Collection certs = store.FindByThumbprint(x509.Thumbprint).Result;
+ X509Certificate2Collection certs = await store.FindByThumbprintAsync(x509.Thumbprint, ct);
if (certs.Count == 0)
{
- store.Add(x509).Wait();
+ await store.AddAsync(x509, ct: ct);
}
}
}
@@ -227,7 +242,7 @@ private void PullFromGds(bool deleteBeforeAdd)
{
foreach (var crl in trustList.TrustedCrls)
{
- store.AddCRL(new X509CRL(crl));
+ await store.AddCRLAsync(new X509CRL(crl), ct);
}
}
}
@@ -244,10 +259,10 @@ private void PullFromGds(bool deleteBeforeAdd)
{
var x509 = new X509Certificate2(certificate);
- X509Certificate2Collection certs = store.FindByThumbprint(x509.Thumbprint).Result;
+ X509Certificate2Collection certs = await store.FindByThumbprintAsync(x509.Thumbprint, ct);
if (certs.Count == 0)
{
- store.Add(x509).Wait();
+ await store.AddAsync(x509, ct: ct);
}
}
}
@@ -256,13 +271,13 @@ private void PullFromGds(bool deleteBeforeAdd)
{
foreach (var crl in trustList.IssuerCrls)
{
- store.AddCRL(new X509CRL(crl));
+ await store.AddCRLAsync(new X509CRL(crl), ct);
}
}
}
}
- CertificateStoreControl.Initialize(m_trustListStorePath, m_issuerListStorePath, null);
+ await CertificateStoreControl.Initialize(m_trustListStorePath, m_issuerListStorePath, null, ct);
MessageBox.Show(
Parent,
@@ -277,7 +292,7 @@ private void PullFromGds(bool deleteBeforeAdd)
}
}
- private void PushToServerButton_Click(object sender, EventArgs e)
+ private async void PushToServerButton_Click(object sender, EventArgs e)
{
try
{
@@ -287,7 +302,7 @@ private void PushToServerButton_Click(object sender, EventArgs e)
{
var trustList = CertificateStoreControl.GetTrustLists();
- bool applyChanges = m_server.UpdateTrustList(trustList);
+ bool applyChanges = await m_server.UpdateTrustListAsync(trustList);
if (applyChanges)
{
@@ -319,11 +334,11 @@ private void Button_MouseLeave(object sender, EventArgs e)
((Control)sender).BackColor = Color.MidnightBlue;
}
- private void ApplyChangesButton_Click(object sender, EventArgs e)
+ private async void ApplyChangesButton_Click(object sender, EventArgs e)
{
try
{
- m_server.ApplyChanges();
+ await m_server.ApplyChangesAsync();
}
catch (Exception exception)
{
@@ -337,9 +352,9 @@ private void ApplyChangesButton_Click(object sender, EventArgs e)
try
{
- m_server.Disconnect();
+ await m_server.DisconnectAsync();
}
- catch (Exception)
+ catch
{
// ignore.
}
diff --git a/Samples/GDS/Client/Controls/RegisterApplicationControl.cs b/Samples/GDS/Client/Controls/RegisterApplicationControl.cs
index 4dd24030c..3c187de5f 100644
--- a/Samples/GDS/Client/Controls/RegisterApplicationControl.cs
+++ b/Samples/GDS/Client/Controls/RegisterApplicationControl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -34,7 +34,9 @@
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
+using System.Threading.Tasks;
using System.Windows.Forms;
+using System.Xml;
using System.Xml.Serialization;
using Opc.Ua.Gds.Client.Controls;
@@ -93,8 +95,8 @@ public RegisteredApplication RegisteredApplication
return m_application;
}
}
-
- public void Initialize(GlobalDiscoveryServerClient gds, ServerPushConfigurationClient pushClient, EndpointDescription endpoint, GlobalDiscoveryClientConfiguration configuration)
+
+ public async Task InitializeAsync(GlobalDiscoveryServerClient gds, ServerPushConfigurationClient pushClient, EndpointDescription endpoint, GlobalDiscoveryClientConfiguration configuration)
{
m_gds = gds;
m_pushClient = pushClient;
@@ -105,10 +107,10 @@ public void Initialize(GlobalDiscoveryServerClient gds, ServerPushConfigurationC
m_externalEditor = configuration.ExternalEditor;
}
- InitializeEndpoint(endpoint);
+ await InitializeEndpointAsync(endpoint);
}
- private void InitializeEndpoint(EndpointDescription endpoint)
+ private async Task InitializeEndpointAsync(EndpointDescription endpoint)
{
if (endpoint != null)
{
@@ -118,7 +120,7 @@ private void InitializeEndpoint(EndpointDescription endpoint)
var server = endpoint.Server;
ApplicationUriTextBox.Text = server.ApplicationUri;
- ReadRegistration(true);
+ await ReadRegistrationAsync(true);
ApplicationNameTextBox.Text = (server.ApplicationName != null) ? server.ApplicationName.Text : "";
ProductUriTextBox.Text = server.ProductUri;
@@ -471,7 +473,7 @@ private void SetRegistrationTypeNoTrigger(RegistrationType registrationType)
}
}
- private void InitializePullConfiguration(string configurationFilePath)
+ private async void InitializePullConfiguration(string configurationFilePath)
{
string path = Utils.GetAbsoluteFilePath(configurationFilePath, true, true, false);
@@ -484,7 +486,8 @@ private void InitializePullConfiguration(string configurationFilePath)
using (FileStream reader = File.Open(path, FileMode.Open, FileAccess.Read))
{
XmlSerializer serializer = new XmlSerializer(typeof(RegisteredApplication));
- application = serializer.Deserialize(reader) as RegisteredApplication;
+ using XmlReader xml = XmlReader.Create(reader, new XmlReaderSettings() { XmlResolver = null });
+ application = serializer.Deserialize(xml) as RegisteredApplication;
}
if (application != null)
@@ -492,7 +495,7 @@ private void InitializePullConfiguration(string configurationFilePath)
SetRegistrationTypeNoTrigger(application.RegistrationType);
ApplicationUriTextBox.Text = ReplaceLocalhost(application.ApplicationUri);
- ReadRegistration(true);
+ await ReadRegistrationAsync(true);
ApplicationNameTextBox.Text = application.ApplicationName;
ProductUriTextBox.Text = application.ProductUri;
@@ -562,18 +565,19 @@ private void InitializePullConfiguration(string configurationFilePath)
#endif
if (application.Domains != null)
{
- DomainsTextBox.Text = ReplaceLocalhost(application.Domains);
+ DomainsTextBox.Text = ReplaceLocalhost(application.Domains);
}
return;
}
}
- catch (Exception)
+ catch
{
// ignore.
}
- try {
+ try
+ {
var configuration = new Opc.Ua.Security.SecurityConfigurationManager().ReadConfiguration(path);
if (configuration.ApplicationType == Security.ApplicationType.Client_1)
@@ -586,11 +590,11 @@ private void InitializePullConfiguration(string configurationFilePath)
}
ApplicationUriTextBox.Text = ReplaceLocalhost(configuration.ApplicationUri);
- ReadRegistration(true);
+ await ReadRegistrationAsync(true);
ApplicationNameTextBox.Text = configuration.ApplicationName;
ProductUriTextBox.Text = configuration.ProductName;
-
+
if (configuration.ApplicationType != Security.ApplicationType.Client_1)
{
SetDiscoveryUrls(configuration.BaseAddresses);
@@ -613,7 +617,7 @@ private void InitializePullConfiguration(string configurationFilePath)
IssuerListStorePathTextBox.Text = configuration.IssuerCertificateStore.StorePath;
}
}
- catch (Exception)
+ catch
{
// ignore.
}
@@ -647,8 +651,7 @@ private void ConfigurationFileButton_Click(object sender, EventArgs e)
directory = new FileInfo(configurationFile).Directory;
}
- OpenFileDialog dialog = new OpenFileDialog
- {
+ OpenFileDialog dialog = new OpenFileDialog {
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = ".xml",
@@ -747,8 +750,7 @@ private void CertificateStorePathButton_Click(object sender, EventArgs e)
directory = new DirectoryInfo(storePath);
}
- FolderBrowserDialog dialog = new FolderBrowserDialog
- {
+ FolderBrowserDialog dialog = new FolderBrowserDialog {
RootFolder = Environment.SpecialFolder.MyComputer,
SelectedPath = directory.FullName,
ShowNewFolderButton = true,
@@ -857,8 +859,7 @@ private void CertificatePublicKeyPathButton_Click(object sender, EventArgs e)
}
}
- OpenFileDialog dialog = new OpenFileDialog
- {
+ OpenFileDialog dialog = new OpenFileDialog {
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = ".der",
@@ -878,7 +879,7 @@ private void CertificatePublicKeyPathButton_Click(object sender, EventArgs e)
m_lastDirPath = new FileInfo(dialog.FileName).Directory.FullName;
CertificatePublicKeyPathTextBox.Text = AddSpecialFolders(dialog.FileName);
-
+
X509Certificate2 certificate = new X509Certificate2(RemoveSpecialFolders(CertificatePublicKeyPathTextBox.Text));
try
@@ -936,8 +937,7 @@ private void CertificatePrivateKeyPathButton_Click(object sender, EventArgs e)
}
}
- OpenFileDialog dialog = new OpenFileDialog
- {
+ OpenFileDialog dialog = new OpenFileDialog {
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = ".pfx",
@@ -984,8 +984,7 @@ private void HttpsCertificatePublicKeyPathButton_Click(object sender, EventArgs
}
}
- OpenFileDialog dialog = new OpenFileDialog
- {
+ OpenFileDialog dialog = new OpenFileDialog {
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = ".der",
@@ -1054,8 +1053,7 @@ private void HttpsCertificatePrivateKeyPathButton_Click(object sender, EventArgs
}
}
- OpenFileDialog dialog = new OpenFileDialog
- {
+ OpenFileDialog dialog = new OpenFileDialog {
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = ".pfx",
@@ -1101,8 +1099,7 @@ private void TrustListStorePathButton_Click(object sender, EventArgs e)
}
- FolderBrowserDialog dialog = new FolderBrowserDialog
- {
+ FolderBrowserDialog dialog = new FolderBrowserDialog {
RootFolder = Environment.SpecialFolder.MyComputer,
SelectedPath = directory.FullName,
ShowNewFolderButton = true,
@@ -1146,8 +1143,7 @@ private void IssuerListStorePathButton_Click(object sender, EventArgs e)
directory = new DirectoryInfo(storePath);
}
- FolderBrowserDialog dialog = new FolderBrowserDialog
- {
+ FolderBrowserDialog dialog = new FolderBrowserDialog {
RootFolder = Environment.SpecialFolder.MyComputer,
SelectedPath = directory.FullName,
ShowNewFolderButton = true,
@@ -1191,8 +1187,7 @@ private void HttpsTrustListStorePathButton_Click(object sender, EventArgs e)
directory = new DirectoryInfo(storePath);
}
- FolderBrowserDialog dialog = new FolderBrowserDialog
- {
+ FolderBrowserDialog dialog = new FolderBrowserDialog {
RootFolder = Environment.SpecialFolder.MyComputer,
SelectedPath = directory.FullName,
ShowNewFolderButton = true,
@@ -1236,8 +1231,7 @@ private void HttpsIssuerListStorePathButton_Click(object sender, EventArgs e)
directory = new DirectoryInfo(storePath);
}
- FolderBrowserDialog dialog = new FolderBrowserDialog
- {
+ FolderBrowserDialog dialog = new FolderBrowserDialog {
RootFolder = Environment.SpecialFolder.MyComputer,
SelectedPath = directory.FullName,
ShowNewFolderButton = true,
@@ -1268,10 +1262,11 @@ private void HttpsIssuerListStorePathButton_Click(object sender, EventArgs e)
}
}
- private void RegisterApplicationButton_Click(object sender, EventArgs e)
+ private async void RegisterApplicationButton_Click(object sender, EventArgs e)
{
try
- { string applicationName = ApplicationNameTextBox.Text.Trim();
+ {
+ string applicationName = ApplicationNameTextBox.Text.Trim();
if (String.IsNullOrEmpty(applicationName))
{
@@ -1338,7 +1333,7 @@ private void RegisterApplicationButton_Click(object sender, EventArgs e)
ApplicationRecordDataType recordToReplace = ApplicationIdTextBox.Tag as ApplicationRecordDataType;
- var records = m_gds.FindApplication(applicationUri);
+ var records = await m_gds.FindApplicationAsync(applicationUri);
if (records != null)
{
@@ -1368,13 +1363,13 @@ private void RegisterApplicationButton_Click(object sender, EventArgs e)
}
recordToReplace.ApplicationUri = applicationUri;
- recordToReplace.ApplicationType = (RegistrationTypeComboBox.SelectedIndex != ClientPullManagement)?ApplicationType.Server:ApplicationType.Client;
+ recordToReplace.ApplicationType = (RegistrationTypeComboBox.SelectedIndex != ClientPullManagement) ? ApplicationType.Server : ApplicationType.Client;
recordToReplace.ApplicationNames = new LocalizedText[] { applicationName };
recordToReplace.ProductUri = productUri;
recordToReplace.DiscoveryUrls = urls;
- recordToReplace.ServerCapabilities = (capabilities != null)?new StringCollection(capabilities):new StringCollection();
+ recordToReplace.ServerCapabilities = (capabilities != null) ? new StringCollection(capabilities) : new StringCollection();
- var applicationId = m_gds.RegisterApplication(recordToReplace);
+ var applicationId = await m_gds.RegisterApplicationAsync(recordToReplace);
recordToReplace.ApplicationId = applicationId;
@@ -1415,7 +1410,7 @@ private void RegisterApplicationButton_Click(object sender, EventArgs e)
}
}
- private void ReadRegistration(bool silent)
+ private async Task ReadRegistrationAsync(bool silent)
{
string applicationUri = ApplicationUriTextBox.Text.Trim();
@@ -1445,7 +1440,7 @@ private void ReadRegistration(bool silent)
try
{
- var records = m_gds.FindApplication(applicationUri);
+ var records = await m_gds.FindApplicationAsync(applicationUri);
if (records != null)
{
@@ -1524,13 +1519,13 @@ private void ApplyChangesButton_Click(object sender, EventArgs e)
}
}
- private void UnregisterApplicationButton_Click(object sender, EventArgs e)
+ private async void UnregisterApplicationButton_Click(object sender, EventArgs e)
{
try
{
if (ApplicationIdTextBox.Tag is ApplicationRecordDataType record)
{
- m_gds.UnregisterApplication(record.ApplicationId);
+ await m_gds.UnregisterApplicationAsync(record.ApplicationId);
ApplicationIdTextBox.Text = null;
ApplicationIdTextBox.Tag = null;
@@ -1580,17 +1575,17 @@ private void RegistrationTypeComboBox_SelectedIndexChanged(object sender, EventA
IssuerListStorePathTextBox.Visible = RegistrationTypeComboBox.SelectedIndex != ServerPushManagement;
IssuerListStorePathButton.Visible = RegistrationTypeComboBox.SelectedIndex != ServerPushManagement;
#if NO_HTTPS
- HttpsCertificatePublicKeyPathLabel.Visible =
- HttpsCertificatePublicKeyPathTextBox.Visible =
- HttpsCertificatePublicKeyPathButton.Visible =
- HttpsCertificatePrivateKeyPathLabel.Visible =
- HttpsCertificatePrivateKeyPathTextBox.Visible =
- HttpsCertificatePrivateKeyPathButton.Visible =
- HttpsTrustListStorePathLabel.Visible =
- HttpsTrustListStorePathTextBox.Visible =
- HttpsTrustListStorePathButton.Visible =
- HttpsIssuerListStorePathLabel.Visible =
- HttpsIssuerListStorePathTextBox.Visible =
+ HttpsCertificatePublicKeyPathLabel.Visible =
+ HttpsCertificatePublicKeyPathTextBox.Visible =
+ HttpsCertificatePublicKeyPathButton.Visible =
+ HttpsCertificatePrivateKeyPathLabel.Visible =
+ HttpsCertificatePrivateKeyPathTextBox.Visible =
+ HttpsCertificatePrivateKeyPathButton.Visible =
+ HttpsTrustListStorePathLabel.Visible =
+ HttpsTrustListStorePathTextBox.Visible =
+ HttpsTrustListStorePathButton.Visible =
+ HttpsIssuerListStorePathLabel.Visible =
+ HttpsIssuerListStorePathTextBox.Visible =
HttpsIssuerListStorePathButton.Visible = false;
#else
HttpsCertificatePublicKeyPathLabel.Visible = RegistrationTypeComboBox.SelectedIndex != ClientPullManagement;
@@ -1656,8 +1651,7 @@ private void SaveButton_Click(object sender, EventArgs e)
name = buffer.ToString();
}
- SaveFileDialog dialog = new SaveFileDialog
- {
+ SaveFileDialog dialog = new SaveFileDialog {
OverwritePrompt = true,
CheckFileExists = false,
CheckPathExists = true,
@@ -1745,8 +1739,7 @@ private void LoadButton_Click(object sender, EventArgs e)
DirectoryInfo directory = new DirectoryInfo(path);
- OpenFileDialog dialog = new OpenFileDialog
- {
+ OpenFileDialog dialog = new OpenFileDialog {
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = ".xml",
@@ -1764,7 +1757,7 @@ private void LoadButton_Click(object sender, EventArgs e)
}
m_lastDirPath = new FileInfo(dialog.FileName).Directory.FullName;
-
+
if (dialog.FileName.EndsWith(".der", StringComparison.OrdinalIgnoreCase))
{
ConfigurationFileTextBox.Text = null;
@@ -1778,7 +1771,7 @@ private void LoadButton_Click(object sender, EventArgs e)
ControlToData();
RaiseRegisteredApplicationChangedEvent(m_application);
-
+
}
catch (Exception ex)
{
@@ -1791,7 +1784,7 @@ private void OpenConfigurationButton_Click(object sender, EventArgs e)
try
{
var pathToFile = Utils.GetAbsoluteFilePath(ConfigurationFileTextBox.Text.Trim(), true, true, false);
- System.Diagnostics.Process.Start((m_externalEditor)??@"devenv.exe", "\"" + pathToFile + "\"");
+ System.Diagnostics.Process.Start((m_externalEditor) ?? @"devenv.exe", "\"" + pathToFile + "\"");
}
catch (Exception ex)
{
@@ -1852,13 +1845,20 @@ private void ClearButton_Click(object sender, EventArgs e)
}
}
- private void PickServerButton_Click(object sender, EventArgs e)
+ private async void PickServerButton_Click(object sender, EventArgs e)
{
- string uri = new SelectPushServerDialog().ShowDialog(null, m_pushClient, m_gds.GetDefaultServerUrls(null));
- if (uri != null && m_pushClient.IsConnected)
+ try
{
- EndpointDescription endpoint = m_pushClient.Endpoint.Description;
- InitializeEndpoint(endpoint);
+ string uri = new SelectPushServerDialog().ShowDialog(null, m_pushClient, await m_gds.GetDefaultServerUrlsAsync(null));
+ if (uri != null && m_pushClient.IsConnected)
+ {
+ EndpointDescription endpoint = m_pushClient.Endpoint.Description;
+ await InitializeEndpointAsync(endpoint);
+ }
+ }
+ catch (Exception ex)
+ {
+ Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, ex);
}
}
}
diff --git a/Samples/GDS/Client/GlobalDiscoveryClient.csproj b/Samples/GDS/Client/GlobalDiscoveryClient.csproj
index 080cd8929..c3decd33d 100644
--- a/Samples/GDS/Client/GlobalDiscoveryClient.csproj
+++ b/Samples/GDS/Client/GlobalDiscoveryClient.csproj
@@ -27,6 +27,7 @@
4
false
false
+ AllRules.ruleset
AnyCPU
@@ -37,6 +38,7 @@
prompt
4
false
+ AllRules.ruleset
false
@@ -139,10 +141,10 @@
- 1.5.376.244
+ 1.5.377.11-preview
- 1.5.376.244
+ 1.5.377.11-preview
diff --git a/Samples/GDS/Client/MainForm.cs b/Samples/GDS/Client/MainForm.cs
index 7e732fa56..1fbfd82f5 100644
--- a/Samples/GDS/Client/MainForm.cs
+++ b/Samples/GDS/Client/MainForm.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -29,13 +29,15 @@
using System;
using System.Drawing;
+using System.Reflection;
+using System.Threading.Tasks;
using System.Windows.Forms;
using Opc.Ua.Client;
using Opc.Ua.Client.Controls;
using Opc.Ua.Configuration;
using Opc.Ua.Gds;
using Opc.Ua.Gds.Client.Controls;
-using System.Threading.Tasks;
+using static System.Net.Mime.MediaTypeNames;
namespace Opc.Ua.Gds.Client
{
@@ -70,9 +72,9 @@ public MainForm(ApplicationInstance application)
m_server.AdminCredentialsRequired += Server_AdminCredentialsRequired;
m_server.KeepAlive += Server_KeepAlive;
m_server.ServerStatusChanged += Server_StatusNotification;
- m_server.ConnectionStatusChanged += Server_ConnectionStatusChanged;
+ m_server.ConnectionStatusChanged += Server_ConnectionStatusChangedAsync;
- RegistrationPanel.Initialize(m_gds, m_server, null, m_configuration);
+ RegistrationPanel.InitializeAsync(m_gds, m_server, null, m_configuration).GetAwaiter().GetResult();
m_application.ApplicationConfiguration.CertificateValidator.CertificateValidation += CertificateValidator_CertificateValidation;
UpdateStatus(true, DateTime.MinValue, "---");
@@ -114,25 +116,32 @@ private enum Panel
Discovery
}
- private void Server_ConnectionStatusChanged(object sender, EventArgs e)
+ private async void Server_ConnectionStatusChangedAsync(object sender, EventArgs e)
{
- if (InvokeRequired)
- {
- BeginInvoke(new EventHandler(Server_ConnectionStatusChanged), sender, e);
- return;
- }
-
- if (Object.ReferenceEquals(sender, m_server))
+ try
{
- if (m_server.IsConnected)
+ if (InvokeRequired)
{
- ServerStatusPanel.Initialize(m_server);
+ BeginInvoke(new EventHandler(Server_ConnectionStatusChangedAsync), sender, e);
+ return;
}
- else
+
+ if (Object.ReferenceEquals(sender, m_server))
{
- ServerStatusPanel.Initialize(null);
+ if (m_server.IsConnected)
+ {
+ await ServerStatusPanel.InitializeAsync(m_server);
+ }
+ else
+ {
+ await ServerStatusPanel.InitializeAsync(null);
+ }
}
}
+ catch (Exception exception)
+ {
+ GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
+ }
}
private void ShowPanel(Panel panel)
@@ -217,7 +226,7 @@ private void SetServer(EndpointDescription endpoint)
ServerStatusButton.Enabled = endpoint != null;
}
- private void SelectServerButton_Click(object sender, EventArgs e)
+ private async void SelectServerButton_Click(object sender, EventArgs e)
{
try
{
@@ -226,7 +235,7 @@ private void SelectServerButton_Click(object sender, EventArgs e)
if (endpoint != null)
{
SetServer(endpoint);
- RegistrationPanel.Initialize(m_gds, m_server, endpoint, m_configuration);
+ await RegistrationPanel.InitializeAsync(m_gds, m_server, endpoint, m_configuration);
SelectGdsButton.Visible = true;
return;
}
@@ -248,10 +257,10 @@ private async void ConnectButton_ClickAsync(object sender, EventArgs e)
return;
}
- await m_server.Connect(endpoint.Description.EndpointUrl);
+ await m_server.ConnectAsync(endpoint.Description.EndpointUrl);
- ServerStatusPanel.Initialize(m_server);
- await CertificatePanel.Initialize(m_configuration, m_gds, m_server, m_registeredApplication, false);
+ await ServerStatusPanel.InitializeAsync(m_server);
+ await CertificatePanel.InitializeAsync(m_configuration, m_gds, m_server, m_registeredApplication, false);
}
catch (Exception exception)
{
@@ -429,15 +438,15 @@ private void UpdateStatus(bool error, DateTime time, string status, params objec
ServerStatusTime.ForeColor = (error) ? Color.Red : Color.Empty;
}
- private void DisconnectButton_Click(object sender, EventArgs e)
+ private async void DisconnectButton_Click(object sender, EventArgs e)
{
try
{
if (m_server.IsConnected)
{
- m_server.Disconnect();
+ m_server.DisconnectAsync().GetAwaiter().GetResult();
UpdateStatus(true, DateTime.UtcNow, "Disconnected {0}", m_server.Endpoint);
- ServerStatusPanel.Initialize(null);
+ await ServerStatusPanel.InitializeAsync(null);
}
}
catch (Exception exception)
@@ -452,7 +461,7 @@ private void RegistrationButton_Click(object sender, EventArgs e)
{
if (!m_gdsConfigured)
{
- string uri = new SelectGdsDialog().ShowDialog(null, m_gds, m_gds.GetDefaultGdsUrls(m_lds));
+ string uri = new SelectGdsDialog().ShowDialog(null, m_gds, m_gds.GetDefaultGdsUrlsAsync(m_lds).GetAwaiter().GetResult());
if (uri != null)
{
m_configuration.GlobalDiscoveryServerUrl = m_gds.EndpointUrl;
@@ -485,7 +494,7 @@ private async void CertificateButton_ClickAsync(object sender, EventArgs e)
{
try
{
- await CertificatePanel.Initialize(m_configuration, m_gds, m_server, m_registeredApplication, false);
+ await CertificatePanel.InitializeAsync(m_configuration, m_gds, m_server, m_registeredApplication, false);
ShowPanel(Panel.Certificate);
}
catch (Exception ex)
@@ -498,7 +507,7 @@ private async void HttpsCertificateButton_ClickAsync(object sender, EventArgs e)
{
try
{
- await CertificatePanel.Initialize(m_configuration, m_gds, m_server, m_registeredApplication, true);
+ await CertificatePanel.InitializeAsync(m_configuration, m_gds, m_server, m_registeredApplication, true);
ShowPanel(Panel.HttpsCertificate);
}
catch (Exception ex)
@@ -507,11 +516,11 @@ private async void HttpsCertificateButton_ClickAsync(object sender, EventArgs e)
}
}
- private void TrustListButton_Click(object sender, EventArgs e)
+ private async void TrustListButton_Click(object sender, EventArgs e)
{
try
{
- TrustListPanel.Initialize(m_gds, m_server, m_registeredApplication, false);
+ await TrustListPanel.Initialize(m_gds, m_server, m_registeredApplication, false);
ShowPanel(Panel.TrustList);
}
catch (Exception ex)
@@ -520,11 +529,11 @@ private void TrustListButton_Click(object sender, EventArgs e)
}
}
- private void HttpsTrustListButton_Click(object sender, EventArgs e)
+ private async void HttpsTrustListButton_Click(object sender, EventArgs e)
{
try
{
- TrustListPanel.Initialize(m_gds, m_server, m_registeredApplication, true);
+ await TrustListPanel.Initialize(m_gds, m_server, m_registeredApplication, true);
ShowPanel(Panel.HttpsTrustList);
}
catch (Exception ex)
@@ -590,8 +599,8 @@ private async void RegistrationPanel_RegisteredApplicationChangedAsync(object se
HttpsCertificateButton.Visible = (e.Application != null && !String.IsNullOrEmpty(e.Application.GetHttpsDomainName()));
HttpsTrustListButton.Visible = (e.Application != null && !String.IsNullOrEmpty(e.Application.HttpsTrustListStorePath));
#endif
- await CertificatePanel.Initialize(m_configuration, m_gds, m_server, e.Application, false);
- TrustListPanel.Initialize(m_gds, m_server, e.Application, false);
+ await CertificatePanel.InitializeAsync(m_configuration, m_gds, m_server, e.Application, false);
+ await TrustListPanel.Initialize(m_gds, m_server, e.Application, false);
UpdateMainFormHeader();
}
catch (Exception ex)
@@ -608,11 +617,11 @@ private void ConfigurationButton_Click(object sender, EventArgs e)
private void SelectGdsButton_Click(object sender, EventArgs e)
{
m_gds.AdminCredentials = null;
- m_gds.Disconnect();
+ m_gds.DisconnectAsync().GetAwaiter().GetResult();
m_gdsConfigured = false;
UpdateGdsStatus(true, DateTime.UtcNow, "Disconnected");
- string uri = new SelectGdsDialog().ShowDialog(null, m_gds, m_gds.GetDefaultGdsUrls(m_lds));
+ string uri = new SelectGdsDialog().ShowDialog(null, m_gds, m_gds.GetDefaultGdsUrlsAsync(m_lds).GetAwaiter().GetResult());
if (uri != null)
{
m_configuration.GlobalDiscoveryServerUrl = m_gds.EndpointUrl;
diff --git a/Samples/GDS/Client/Program.cs b/Samples/GDS/Client/Program.cs
index deef60908..a339b70ec 100644
--- a/Samples/GDS/Client/Program.cs
+++ b/Samples/GDS/Client/Program.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -54,10 +54,10 @@ static void Main()
try
{
// load the application configuration.
- ApplicationConfiguration config = application.LoadApplicationConfiguration(false).Result;
+ ApplicationConfiguration config = application.LoadApplicationConfigurationAsync(false).AsTask().GetAwaiter().GetResult();
// check the application certificate.
- application.CheckApplicationInstanceCertificates(false).Wait();
+ application.CheckApplicationInstanceCertificatesAsync(false).AsTask().GetAwaiter().GetResult();
// run the application interactively.
Application.Run(new MainForm(application));
diff --git a/Samples/GDS/ClientControls/Controls/DiscoveryControl.Designer.cs b/Samples/GDS/ClientControls/Controls/DiscoveryControl.Designer.cs
index 4d774fad1..93da51751 100644
--- a/Samples/GDS/ClientControls/Controls/DiscoveryControl.Designer.cs
+++ b/Samples/GDS/ClientControls/Controls/DiscoveryControl.Designer.cs
@@ -1,4 +1,4 @@
-namespace Opc.Ua.Gds.Client.Controls
+namespace Opc.Ua.Gds.Client.Controls
{
partial class DiscoveryControl
{
@@ -37,6 +37,10 @@ private void InitializeComponent()
this.AddEndpointSeparatorMenuItem = new System.Windows.Forms.ToolStripSeparator();
this.AddEndpointMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.MainPanel = new System.Windows.Forms.SplitContainer();
+ this.EndpointsGridView = new System.Windows.Forms.DataGridView();
+ this.EndpointUrlColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.SecurityModeColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.SecurityProfileColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ServersGridView = new System.Windows.Forms.DataGridView();
this.ServerNameColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ServerCapabilitiesColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
@@ -53,19 +57,15 @@ private void InitializeComponent()
this.FilterPanel = new System.Windows.Forms.Panel();
this.FilterTextBox = new System.Windows.Forms.TextBox();
this.FilterLabel = new System.Windows.Forms.Label();
- this.EndpointsGridView = new System.Windows.Forms.DataGridView();
- this.EndpointUrlColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.SecurityModeColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.SecurityProfileColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.PopupMenuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.MainPanel)).BeginInit();
this.MainPanel.Panel1.SuspendLayout();
this.MainPanel.Panel2.SuspendLayout();
this.MainPanel.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.EndpointsGridView)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.ServersGridView)).BeginInit();
this.ApplicationDescriptionPanel.SuspendLayout();
this.FilterPanel.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.EndpointsGridView)).BeginInit();
this.SuspendLayout();
//
// DiscoveryTreeView
@@ -73,8 +73,9 @@ private void InitializeComponent()
this.DiscoveryTreeView.ContextMenuStrip = this.PopupMenuStrip;
this.DiscoveryTreeView.Dock = System.Windows.Forms.DockStyle.Fill;
this.DiscoveryTreeView.Location = new System.Drawing.Point(0, 0);
+ this.DiscoveryTreeView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.DiscoveryTreeView.Name = "DiscoveryTreeView";
- this.DiscoveryTreeView.Size = new System.Drawing.Size(296, 584);
+ this.DiscoveryTreeView.Size = new System.Drawing.Size(444, 898);
this.DiscoveryTreeView.TabIndex = 0;
this.DiscoveryTreeView.BeforeExpand += new System.Windows.Forms.TreeViewCancelEventHandler(this.DiscoveryTreeView_BeforeExpand);
this.DiscoveryTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.DiscoveryTreeView_AfterSelect);
@@ -83,6 +84,7 @@ private void InitializeComponent()
//
// PopupMenuStrip
//
+ this.PopupMenuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
this.PopupMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.RefreshMenuItem,
this.RefreshWithParametersMenuItem,
@@ -90,39 +92,39 @@ private void InitializeComponent()
this.AddEndpointSeparatorMenuItem,
this.AddEndpointMenuItem});
this.PopupMenuStrip.Name = "PopupMenuStrip";
- this.PopupMenuStrip.Size = new System.Drawing.Size(211, 98);
+ this.PopupMenuStrip.Size = new System.Drawing.Size(285, 138);
this.PopupMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.PopupMenuStrip_Opening);
//
// RefreshMenuItem
//
this.RefreshMenuItem.Name = "RefreshMenuItem";
- this.RefreshMenuItem.Size = new System.Drawing.Size(210, 22);
+ this.RefreshMenuItem.Size = new System.Drawing.Size(284, 32);
this.RefreshMenuItem.Text = "Refresh";
this.RefreshMenuItem.Click += new System.EventHandler(this.RefreshMenuItem_Click);
//
// RefreshWithParametersMenuItem
//
this.RefreshWithParametersMenuItem.Name = "RefreshWithParametersMenuItem";
- this.RefreshWithParametersMenuItem.Size = new System.Drawing.Size(210, 22);
+ this.RefreshWithParametersMenuItem.Size = new System.Drawing.Size(284, 32);
this.RefreshWithParametersMenuItem.Text = "Refresh with Parameters...";
this.RefreshWithParametersMenuItem.Click += new System.EventHandler(this.RefreshWithParametersMenuItem_Click);
//
// DeleteMenuItem
//
this.DeleteMenuItem.Name = "DeleteMenuItem";
- this.DeleteMenuItem.Size = new System.Drawing.Size(210, 22);
+ this.DeleteMenuItem.Size = new System.Drawing.Size(284, 32);
this.DeleteMenuItem.Text = "Delete...";
this.DeleteMenuItem.Click += new System.EventHandler(this.DeleteMenuItem_Click);
//
// AddEndpointSeparatorMenuItem
//
this.AddEndpointSeparatorMenuItem.Name = "AddEndpointSeparatorMenuItem";
- this.AddEndpointSeparatorMenuItem.Size = new System.Drawing.Size(207, 6);
+ this.AddEndpointSeparatorMenuItem.Size = new System.Drawing.Size(281, 6);
//
// AddEndpointMenuItem
//
this.AddEndpointMenuItem.Name = "AddEndpointMenuItem";
- this.AddEndpointMenuItem.Size = new System.Drawing.Size(210, 22);
+ this.AddEndpointMenuItem.Size = new System.Drawing.Size(284, 32);
this.AddEndpointMenuItem.Text = "Add Endpoint...";
this.AddEndpointMenuItem.Click += new System.EventHandler(this.DiscoveryTreeView_DoubleClick);
//
@@ -130,6 +132,7 @@ private void InitializeComponent()
//
this.MainPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.MainPanel.Location = new System.Drawing.Point(0, 0);
+ this.MainPanel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.MainPanel.Name = "MainPanel";
//
// MainPanel.Panel1
@@ -142,29 +145,89 @@ private void InitializeComponent()
this.MainPanel.Panel2.Controls.Add(this.ServersGridView);
this.MainPanel.Panel2.Controls.Add(this.ApplicationDescriptionPanel);
this.MainPanel.Panel2.Controls.Add(this.FilterPanel);
- this.MainPanel.Size = new System.Drawing.Size(888, 584);
- this.MainPanel.SplitterDistance = 296;
+ this.MainPanel.Size = new System.Drawing.Size(1332, 898);
+ this.MainPanel.SplitterDistance = 444;
+ this.MainPanel.SplitterWidth = 6;
this.MainPanel.TabIndex = 3;
//
+ // EndpointsGridView
+ //
+ this.EndpointsGridView.AllowUserToAddRows = false;
+ this.EndpointsGridView.AllowUserToDeleteRows = false;
+ this.EndpointsGridView.AllowUserToResizeRows = false;
+ this.EndpointsGridView.BackgroundColor = System.Drawing.SystemColors.Window;
+ this.EndpointsGridView.ColumnHeadersHeight = 34;
+ this.EndpointsGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
+ this.EndpointsGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.EndpointUrlColumn3,
+ this.SecurityModeColumn,
+ this.SecurityProfileColumn});
+ this.EndpointsGridView.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.EndpointsGridView.Location = new System.Drawing.Point(0, 212);
+ this.EndpointsGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
+ this.EndpointsGridView.MultiSelect = false;
+ this.EndpointsGridView.Name = "EndpointsGridView";
+ this.EndpointsGridView.ReadOnly = true;
+ this.EndpointsGridView.RowHeadersVisible = false;
+ this.EndpointsGridView.RowHeadersWidth = 62;
+ this.EndpointsGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
+ this.EndpointsGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
+ this.EndpointsGridView.Size = new System.Drawing.Size(882, 686);
+ this.EndpointsGridView.TabIndex = 2;
+ this.EndpointsGridView.VisibleChanged += new System.EventHandler(this.EndpointsGridView_VisibleChanged);
+ this.EndpointsGridView.DoubleClick += new System.EventHandler(this.EndpointsGridView_DoubleClick);
+ //
+ // EndpointUrlColumn3
+ //
+ this.EndpointUrlColumn3.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.EndpointUrlColumn3.DataPropertyName = "EndpointUrl";
+ this.EndpointUrlColumn3.HeaderText = "Endpoint URL";
+ this.EndpointUrlColumn3.MinimumWidth = 8;
+ this.EndpointUrlColumn3.Name = "EndpointUrlColumn3";
+ this.EndpointUrlColumn3.ReadOnly = true;
+ //
+ // SecurityModeColumn
+ //
+ this.SecurityModeColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
+ this.SecurityModeColumn.DataPropertyName = "SecurityMode";
+ this.SecurityModeColumn.HeaderText = "Security Mode";
+ this.SecurityModeColumn.MinimumWidth = 8;
+ this.SecurityModeColumn.Name = "SecurityModeColumn";
+ this.SecurityModeColumn.ReadOnly = true;
+ this.SecurityModeColumn.Width = 146;
+ //
+ // SecurityProfileColumn
+ //
+ this.SecurityProfileColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
+ this.SecurityProfileColumn.DataPropertyName = "SecurityProfile";
+ this.SecurityProfileColumn.HeaderText = "Security Profile";
+ this.SecurityProfileColumn.MinimumWidth = 8;
+ this.SecurityProfileColumn.Name = "SecurityProfileColumn";
+ this.SecurityProfileColumn.ReadOnly = true;
+ this.SecurityProfileColumn.Width = 150;
+ //
// ServersGridView
//
this.ServersGridView.AllowUserToAddRows = false;
this.ServersGridView.AllowUserToDeleteRows = false;
this.ServersGridView.AllowUserToResizeRows = false;
this.ServersGridView.BackgroundColor = System.Drawing.SystemColors.Window;
+ this.ServersGridView.ColumnHeadersHeight = 34;
this.ServersGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
this.ServersGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ServerNameColumn,
this.ServerCapabilitiesColumn,
this.EndpointUrlColumn});
this.ServersGridView.Dock = System.Windows.Forms.DockStyle.Fill;
- this.ServersGridView.Location = new System.Drawing.Point(0, 138);
+ this.ServersGridView.Location = new System.Drawing.Point(0, 212);
+ this.ServersGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.ServersGridView.Name = "ServersGridView";
this.ServersGridView.ReadOnly = true;
this.ServersGridView.RowHeadersVisible = false;
+ this.ServersGridView.RowHeadersWidth = 62;
this.ServersGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
this.ServersGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
- this.ServersGridView.Size = new System.Drawing.Size(588, 446);
+ this.ServersGridView.Size = new System.Drawing.Size(882, 686);
this.ServersGridView.TabIndex = 3;
this.ServersGridView.DoubleClick += new System.EventHandler(this.ServersGridView_DoubleClick);
//
@@ -173,24 +236,27 @@ private void InitializeComponent()
this.ServerNameColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
this.ServerNameColumn.DataPropertyName = "ServerName";
this.ServerNameColumn.HeaderText = "Server Name";
+ this.ServerNameColumn.MinimumWidth = 8;
this.ServerNameColumn.Name = "ServerNameColumn";
this.ServerNameColumn.ReadOnly = true;
- this.ServerNameColumn.Width = 94;
+ this.ServerNameColumn.Width = 137;
//
// ServerCapabilitiesColumn
//
this.ServerCapabilitiesColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
this.ServerCapabilitiesColumn.DataPropertyName = "ServerCapabilities";
this.ServerCapabilitiesColumn.HeaderText = "Server Capabilities";
+ this.ServerCapabilitiesColumn.MinimumWidth = 8;
this.ServerCapabilitiesColumn.Name = "ServerCapabilitiesColumn";
this.ServerCapabilitiesColumn.ReadOnly = true;
- this.ServerCapabilitiesColumn.Width = 119;
+ this.ServerCapabilitiesColumn.Width = 176;
//
// EndpointUrlColumn
//
this.EndpointUrlColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.EndpointUrlColumn.DataPropertyName = "EndpointUrl";
this.EndpointUrlColumn.HeaderText = "Endpoint URL";
+ this.EndpointUrlColumn.MinimumWidth = 8;
this.EndpointUrlColumn.Name = "EndpointUrlColumn";
this.EndpointUrlColumn.ReadOnly = true;
//
@@ -210,14 +276,15 @@ private void InitializeComponent()
this.ApplicationDescriptionPanel.Controls.Add(this.ApplicationUriLabel, 0, 1);
this.ApplicationDescriptionPanel.Controls.Add(this.ApplicationNameTextBox, 1, 0);
this.ApplicationDescriptionPanel.Dock = System.Windows.Forms.DockStyle.Top;
- this.ApplicationDescriptionPanel.Location = new System.Drawing.Point(0, 32);
+ this.ApplicationDescriptionPanel.Location = new System.Drawing.Point(0, 49);
+ this.ApplicationDescriptionPanel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.ApplicationDescriptionPanel.Name = "ApplicationDescriptionPanel";
this.ApplicationDescriptionPanel.RowCount = 4;
- this.ApplicationDescriptionPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 24F));
- this.ApplicationDescriptionPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 24F));
- this.ApplicationDescriptionPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 24F));
- this.ApplicationDescriptionPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 24F));
- this.ApplicationDescriptionPanel.Size = new System.Drawing.Size(588, 106);
+ this.ApplicationDescriptionPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 37F));
+ this.ApplicationDescriptionPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 37F));
+ this.ApplicationDescriptionPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 37F));
+ this.ApplicationDescriptionPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 37F));
+ this.ApplicationDescriptionPanel.Size = new System.Drawing.Size(882, 163);
this.ApplicationDescriptionPanel.TabIndex = 1;
//
// ApplicationNameLabel
@@ -225,10 +292,10 @@ private void InitializeComponent()
this.ApplicationNameLabel.AllowDrop = true;
this.ApplicationNameLabel.AutoSize = true;
this.ApplicationNameLabel.Dock = System.Windows.Forms.DockStyle.Fill;
- this.ApplicationNameLabel.Location = new System.Drawing.Point(5, 5);
- this.ApplicationNameLabel.Margin = new System.Windows.Forms.Padding(3);
+ this.ApplicationNameLabel.Location = new System.Drawing.Point(6, 7);
+ this.ApplicationNameLabel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.ApplicationNameLabel.Name = "ApplicationNameLabel";
- this.ApplicationNameLabel.Size = new System.Drawing.Size(90, 18);
+ this.ApplicationNameLabel.Size = new System.Drawing.Size(133, 27);
this.ApplicationNameLabel.TabIndex = 0;
this.ApplicationNameLabel.Text = "Application Name";
this.ApplicationNameLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -238,10 +305,10 @@ private void InitializeComponent()
this.ProductUriTextBox.AllowDrop = true;
this.ProductUriTextBox.AutoSize = true;
this.ProductUriTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
- this.ProductUriTextBox.Location = new System.Drawing.Point(103, 83);
- this.ProductUriTextBox.Margin = new System.Windows.Forms.Padding(3);
+ this.ProductUriTextBox.Location = new System.Drawing.Point(149, 124);
+ this.ProductUriTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.ProductUriTextBox.Name = "ProductUriTextBox";
- this.ProductUriTextBox.Size = new System.Drawing.Size(480, 18);
+ this.ProductUriTextBox.Size = new System.Drawing.Size(727, 32);
this.ProductUriTextBox.TabIndex = 7;
this.ProductUriTextBox.Text = "---";
this.ProductUriTextBox.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -251,10 +318,10 @@ private void InitializeComponent()
this.ProductUriLabel.AllowDrop = true;
this.ProductUriLabel.AutoSize = true;
this.ProductUriLabel.Dock = System.Windows.Forms.DockStyle.Fill;
- this.ProductUriLabel.Location = new System.Drawing.Point(5, 83);
- this.ProductUriLabel.Margin = new System.Windows.Forms.Padding(3);
+ this.ProductUriLabel.Location = new System.Drawing.Point(6, 124);
+ this.ProductUriLabel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.ProductUriLabel.Name = "ProductUriLabel";
- this.ProductUriLabel.Size = new System.Drawing.Size(90, 18);
+ this.ProductUriLabel.Size = new System.Drawing.Size(133, 32);
this.ProductUriLabel.TabIndex = 6;
this.ProductUriLabel.Text = "Product URI";
this.ProductUriLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -264,10 +331,10 @@ private void InitializeComponent()
this.ApplicationTypeTextBox.AllowDrop = true;
this.ApplicationTypeTextBox.AutoSize = true;
this.ApplicationTypeTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
- this.ApplicationTypeTextBox.Location = new System.Drawing.Point(103, 57);
- this.ApplicationTypeTextBox.Margin = new System.Windows.Forms.Padding(3);
+ this.ApplicationTypeTextBox.Location = new System.Drawing.Point(149, 85);
+ this.ApplicationTypeTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.ApplicationTypeTextBox.Name = "ApplicationTypeTextBox";
- this.ApplicationTypeTextBox.Size = new System.Drawing.Size(480, 18);
+ this.ApplicationTypeTextBox.Size = new System.Drawing.Size(727, 27);
this.ApplicationTypeTextBox.TabIndex = 5;
this.ApplicationTypeTextBox.Text = "---";
this.ApplicationTypeTextBox.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -277,10 +344,10 @@ private void InitializeComponent()
this.ApplicationTypeLabel.AllowDrop = true;
this.ApplicationTypeLabel.AutoSize = true;
this.ApplicationTypeLabel.Dock = System.Windows.Forms.DockStyle.Fill;
- this.ApplicationTypeLabel.Location = new System.Drawing.Point(5, 57);
- this.ApplicationTypeLabel.Margin = new System.Windows.Forms.Padding(3);
+ this.ApplicationTypeLabel.Location = new System.Drawing.Point(6, 85);
+ this.ApplicationTypeLabel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.ApplicationTypeLabel.Name = "ApplicationTypeLabel";
- this.ApplicationTypeLabel.Size = new System.Drawing.Size(90, 18);
+ this.ApplicationTypeLabel.Size = new System.Drawing.Size(133, 27);
this.ApplicationTypeLabel.TabIndex = 4;
this.ApplicationTypeLabel.Text = "Application Type";
this.ApplicationTypeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -290,10 +357,10 @@ private void InitializeComponent()
this.ApplicationUriTextBox.AllowDrop = true;
this.ApplicationUriTextBox.AutoSize = true;
this.ApplicationUriTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
- this.ApplicationUriTextBox.Location = new System.Drawing.Point(103, 31);
- this.ApplicationUriTextBox.Margin = new System.Windows.Forms.Padding(3);
+ this.ApplicationUriTextBox.Location = new System.Drawing.Point(149, 46);
+ this.ApplicationUriTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.ApplicationUriTextBox.Name = "ApplicationUriTextBox";
- this.ApplicationUriTextBox.Size = new System.Drawing.Size(480, 18);
+ this.ApplicationUriTextBox.Size = new System.Drawing.Size(727, 27);
this.ApplicationUriTextBox.TabIndex = 3;
this.ApplicationUriTextBox.Text = "---";
this.ApplicationUriTextBox.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -303,10 +370,10 @@ private void InitializeComponent()
this.ApplicationUriLabel.AllowDrop = true;
this.ApplicationUriLabel.AutoSize = true;
this.ApplicationUriLabel.Dock = System.Windows.Forms.DockStyle.Fill;
- this.ApplicationUriLabel.Location = new System.Drawing.Point(5, 31);
- this.ApplicationUriLabel.Margin = new System.Windows.Forms.Padding(3);
+ this.ApplicationUriLabel.Location = new System.Drawing.Point(6, 46);
+ this.ApplicationUriLabel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.ApplicationUriLabel.Name = "ApplicationUriLabel";
- this.ApplicationUriLabel.Size = new System.Drawing.Size(90, 18);
+ this.ApplicationUriLabel.Size = new System.Drawing.Size(133, 27);
this.ApplicationUriLabel.TabIndex = 2;
this.ApplicationUriLabel.Text = "Application URI";
this.ApplicationUriLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -316,10 +383,10 @@ private void InitializeComponent()
this.ApplicationNameTextBox.AllowDrop = true;
this.ApplicationNameTextBox.AutoSize = true;
this.ApplicationNameTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
- this.ApplicationNameTextBox.Location = new System.Drawing.Point(103, 5);
- this.ApplicationNameTextBox.Margin = new System.Windows.Forms.Padding(3);
+ this.ApplicationNameTextBox.Location = new System.Drawing.Point(149, 7);
+ this.ApplicationNameTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.ApplicationNameTextBox.Name = "ApplicationNameTextBox";
- this.ApplicationNameTextBox.Size = new System.Drawing.Size(480, 18);
+ this.ApplicationNameTextBox.Size = new System.Drawing.Size(727, 27);
this.ApplicationNameTextBox.TabIndex = 1;
this.ApplicationNameTextBox.Text = "---";
this.ApplicationNameTextBox.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -333,17 +400,17 @@ private void InitializeComponent()
this.FilterPanel.Location = new System.Drawing.Point(0, 0);
this.FilterPanel.Margin = new System.Windows.Forms.Padding(0);
this.FilterPanel.Name = "FilterPanel";
- this.FilterPanel.Padding = new System.Windows.Forms.Padding(2, 6, 6, 6);
- this.FilterPanel.Size = new System.Drawing.Size(588, 32);
+ this.FilterPanel.Padding = new System.Windows.Forms.Padding(3, 9, 9, 9);
+ this.FilterPanel.Size = new System.Drawing.Size(882, 49);
this.FilterPanel.TabIndex = 0;
//
// FilterTextBox
//
this.FilterTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
- this.FilterTextBox.Location = new System.Drawing.Point(77, 6);
- this.FilterTextBox.Margin = new System.Windows.Forms.Padding(0, 2, 0, 2);
+ this.FilterTextBox.Location = new System.Drawing.Point(115, 9);
+ this.FilterTextBox.Margin = new System.Windows.Forms.Padding(0, 3, 0, 3);
this.FilterTextBox.Name = "FilterTextBox";
- this.FilterTextBox.Size = new System.Drawing.Size(505, 20);
+ this.FilterTextBox.Size = new System.Drawing.Size(758, 26);
this.FilterTextBox.TabIndex = 1;
this.FilterTextBox.TextChanged += new System.EventHandler(this.FilterTextBox_TextChanged);
//
@@ -353,81 +420,33 @@ private void InitializeComponent()
this.FilterLabel.Dock = System.Windows.Forms.DockStyle.Left;
this.FilterLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FilterLabel.ForeColor = System.Drawing.Color.White;
- this.FilterLabel.Location = new System.Drawing.Point(2, 6);
- this.FilterLabel.Margin = new System.Windows.Forms.Padding(3);
+ this.FilterLabel.Location = new System.Drawing.Point(3, 9);
+ this.FilterLabel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.FilterLabel.Name = "FilterLabel";
- this.FilterLabel.Size = new System.Drawing.Size(75, 20);
+ this.FilterLabel.Size = new System.Drawing.Size(112, 31);
this.FilterLabel.TabIndex = 0;
this.FilterLabel.Text = "Text Filter";
this.FilterLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
- // EndpointsGridView
- //
- this.EndpointsGridView.AllowUserToAddRows = false;
- this.EndpointsGridView.AllowUserToDeleteRows = false;
- this.EndpointsGridView.AllowUserToResizeRows = false;
- this.EndpointsGridView.BackgroundColor = System.Drawing.SystemColors.Window;
- this.EndpointsGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- this.EndpointsGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
- this.EndpointUrlColumn3,
- this.SecurityModeColumn,
- this.SecurityProfileColumn});
- this.EndpointsGridView.Dock = System.Windows.Forms.DockStyle.Fill;
- this.EndpointsGridView.Location = new System.Drawing.Point(0, 138);
- this.EndpointsGridView.MultiSelect = false;
- this.EndpointsGridView.Name = "EndpointsGridView";
- this.EndpointsGridView.ReadOnly = true;
- this.EndpointsGridView.RowHeadersVisible = false;
- this.EndpointsGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
- this.EndpointsGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
- this.EndpointsGridView.Size = new System.Drawing.Size(588, 446);
- this.EndpointsGridView.TabIndex = 2;
- this.EndpointsGridView.VisibleChanged += new System.EventHandler(this.EndpointsGridView_VisibleChanged);
- this.EndpointsGridView.DoubleClick += new System.EventHandler(this.EndpointsGridView_DoubleClick);
- //
- // EndpointUrlColumn3
- //
- this.EndpointUrlColumn3.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
- this.EndpointUrlColumn3.DataPropertyName = "EndpointUrl";
- this.EndpointUrlColumn3.HeaderText = "Endpoint URL";
- this.EndpointUrlColumn3.Name = "EndpointUrlColumn3";
- this.EndpointUrlColumn3.ReadOnly = true;
- //
- // SecurityModeColumn
- //
- this.SecurityModeColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
- this.SecurityModeColumn.DataPropertyName = "SecurityMode";
- this.SecurityModeColumn.HeaderText = "Security Mode";
- this.SecurityModeColumn.Name = "SecurityModeColumn";
- this.SecurityModeColumn.ReadOnly = true;
- //
- // SecurityProfileColumn
- //
- this.SecurityProfileColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
- this.SecurityProfileColumn.DataPropertyName = "SecurityProfile";
- this.SecurityProfileColumn.HeaderText = "Security Profile";
- this.SecurityProfileColumn.Name = "SecurityProfileColumn";
- this.SecurityProfileColumn.ReadOnly = true;
- this.SecurityProfileColumn.Width = 102;
- //
// DiscoveryControl
//
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.MainPanel);
+ this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.Name = "DiscoveryControl";
- this.Size = new System.Drawing.Size(888, 584);
+ this.Size = new System.Drawing.Size(1332, 898);
this.PopupMenuStrip.ResumeLayout(false);
this.MainPanel.Panel1.ResumeLayout(false);
this.MainPanel.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.MainPanel)).EndInit();
this.MainPanel.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.EndpointsGridView)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.ServersGridView)).EndInit();
this.ApplicationDescriptionPanel.ResumeLayout(false);
this.ApplicationDescriptionPanel.PerformLayout();
this.FilterPanel.ResumeLayout(false);
this.FilterPanel.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.EndpointsGridView)).EndInit();
this.ResumeLayout(false);
}
diff --git a/Samples/GDS/ClientControls/Controls/DiscoveryControl.cs b/Samples/GDS/ClientControls/Controls/DiscoveryControl.cs
index 93a34ec29..653bfdde5 100644
--- a/Samples/GDS/ClientControls/Controls/DiscoveryControl.cs
+++ b/Samples/GDS/ClientControls/Controls/DiscoveryControl.cs
@@ -1,4 +1,4 @@
-/* ========================================================================
+/* ========================================================================
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
@@ -33,6 +33,8 @@
using System.Data;
using System.Text;
using System.Windows.Forms;
+using System.Threading.Tasks;
+using System.Threading;
namespace Opc.Ua.Gds.Client.Controls
{
@@ -83,12 +85,6 @@ private enum RootFolders
Add
}
- private class ExpandNodeData
- {
- public TreeNode Parent;
- public LocalDiscoveryServerClient Lds;
- }
-
[DefaultValue(300)]
[SettingsBindable(true)]
public int SplitterDistance
@@ -125,7 +121,7 @@ public EndpointDescription SelectedEndpoint
{
var endpoint = new EndpointDescription(server.DiscoveryUrl)
{
- Server = GetApplicationDescription(server)
+ Server = GetApplicationDescriptionAsync(server).GetAwaiter().GetResult()
};
return endpoint;
}
@@ -159,7 +155,7 @@ public EndpointDescription SelectedEndpoint
if (ce.Description.EndpointUrl == ce.Description.Server.ApplicationUri)
{
- ce.Description.Server = GetApplicationDescription(new ServerOnNetwork() { DiscoveryUrl = ce.Description.EndpointUrl });
+ ce.Description.Server = GetApplicationDescriptionAsync(new ServerOnNetwork() { DiscoveryUrl = ce.Description.EndpointUrl }).GetAwaiter().GetResult();
}
endpoint = ce.Description;
@@ -193,7 +189,7 @@ public EndpointDescription SelectedEndpoint
ServerOnNetwork server = (ServerOnNetwork)node.Tag;
endpoint = new EndpointDescription(server.DiscoveryUrl)
{
- Server = GetApplicationDescription(server)
+ Server = GetApplicationDescriptionAsync(server).GetAwaiter().GetResult()
};
}
@@ -205,13 +201,13 @@ public EndpointDescription SelectedEndpoint
}
}
- private ApplicationDescription GetApplicationDescription(ServerOnNetwork server)
+ private async Task GetApplicationDescriptionAsync(ServerOnNetwork server)
{
ApplicationDescription fallback = null;
try
{
- foreach (var application in m_lds.FindServers(server.DiscoveryUrl, null))
+ foreach (var application in await m_lds.FindServersAsync(server.DiscoveryUrl, null))
{
if (fallback == null)
{
@@ -350,7 +346,7 @@ private string SelectDiscoveryUrl(ApplicationDescription server)
return url;
}
- private void DiscoveryTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e)
+ private async void DiscoveryTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
if (e.Node.Nodes.Count != 1 || !String.IsNullOrEmpty(e.Node.Nodes[0].Text))
{
@@ -361,21 +357,15 @@ private void DiscoveryTreeView_BeforeExpand(object sender, TreeViewCancelEventAr
if (RootFolders.LocalMachine.Equals(e.Node.Tag))
{
- m_lds.BeginFindServers(
- OnFindServersComplete,
- new ExpandNodeData() { Parent = e.Node, Lds = m_lds });
-
+ // async replace for BeginFindServers
+ await PopulateServersNodeAsync(e.Node, null);
return;
}
if (RootFolders.LocalNetwork.Equals(e.Node.Tag))
{
- m_lds.BeginFindServersOnNetwork(
- 0,
- 100,
- OnFindServersOnNetworkComplete,
- new ExpandNodeData() { Parent = e.Node, Lds = m_lds });
-
+ // async replace for BeginFindServersOnNetwork
+ await PopulateServersOnNetworkNodeAsync(e.Node, 0, 100);
return;
}
@@ -405,32 +395,61 @@ private void DiscoveryTreeView_BeforeExpand(object sender, TreeViewCancelEventAr
if (e.Node.Tag is Uri)
{
- m_lds.BeginFindServers(
- e.Node.Tag.ToString(),
- null,
- null,
- null,
- null,
- OnFindServersComplete,
- new ExpandNodeData() { Parent = e.Node, Lds = m_lds });
-
+ await PopulateServersNodeAsync(e.Node, e.Node.Tag.ToString());
return;
}
}
- private void OnFindServersComplete(IAsyncResult result)
+ private async Task PopulateServersOnNetworkNodeAsync(TreeNode parent, uint startingRecordId, uint maxRecordsToReturn)
{
- if (InvokeRequired)
+ try
{
- BeginInvoke(new AsyncCallback(OnFindServersComplete), result);
- return;
+ var (servers, lastCounterResetTime) = await m_lds.FindServersOnNetworkAsync(
+ null,
+ null,
+ startingRecordId,
+ maxRecordsToReturn,
+ null,
+ CancellationToken.None);
+
+ foreach (ServerOnNetwork server in servers)
+ {
+ if (server.ServerCapabilities != null && server.ServerCapabilities.Contains("LDS"))
+ {
+ continue;
+ }
+
+ TreeNode node = new TreeNode(String.Format("{0}", server.ServerName));
+ node.SelectedImageIndex = node.ImageIndex = ImageIndex.Server;
+ node.Tag = server;
+ node.Nodes.Add(new TreeNode());
+ parent.Nodes.Add(node);
+ }
+
+ if (DiscoveryTreeView.SelectedNode == parent)
+ {
+ ShowServerOnNetworks(parent.Nodes);
+ }
+ else
+ {
+ parent.Expand();
+ }
}
+ catch (Exception ex)
+ {
+ Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, ex);
+ }
+ }
+ private async Task PopulateServersNodeAsync(TreeNode parent, string discoveryUrl)
+ {
try
{
- ExpandNodeData data = (ExpandNodeData)result.AsyncState;
-
- List servers = data.Lds.EndFindServers(result);
+ List servers = new List();
+ foreach (var s in await m_lds.FindServersAsync(discoveryUrl, null))
+ {
+ servers.Add(s);
+ }
foreach (ApplicationDescription server in servers)
{
@@ -443,24 +462,24 @@ private void OnFindServersComplete(IAsyncResult result)
node.SelectedImageIndex = node.ImageIndex = (server.ApplicationType == ApplicationType.DiscoveryServer) ? ImageIndex.LocalNetwork : ImageIndex.Server;
node.Tag = server;
node.Nodes.Add(new TreeNode());
- data.Parent.Nodes.Add(node);
+ parent.Nodes.Add(node);
}
- if (DiscoveryTreeView.SelectedNode == data.Parent)
+ if (DiscoveryTreeView.SelectedNode == parent)
{
- ShowApplicationDescriptions(data.Parent.Nodes);
+ ShowApplicationDescriptions(parent.Nodes);
}
else
{
- data.Parent.Expand();
+ parent.Expand();
}
}
- catch (Exception e)
+ catch (Exception ex)
{
- Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, e);
+ Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, ex);
}
}
-
+
private void ShowApplicationDescriptions(TreeNodeCollection nodes)
{
ServersTable.Rows.Clear();
@@ -509,50 +528,6 @@ private void ShowApplicationDescriptions(TreeNodeCollection nodes)
}
}
- private void OnFindServersOnNetworkComplete(IAsyncResult result)
- {
- if (InvokeRequired)
- {
- BeginInvoke(new AsyncCallback(OnFindServersOnNetworkComplete), result);
- return;
- }
-
- try
- {
- ExpandNodeData data = (ExpandNodeData)result.AsyncState;
-
- DateTime lastCounterResetTime;
- List servers = data.Lds.EndFindServersOnNetwork(result, out lastCounterResetTime);
-
- foreach (ServerOnNetwork server in servers)
- {
- if (server.ServerCapabilities.Contains("LDS"))
- {
- continue;
- }
-
- TreeNode node = new TreeNode(String.Format("{0}", server.ServerName));
- node.SelectedImageIndex = node.ImageIndex = ImageIndex.Server;
- node.Tag = server;
- node.Nodes.Add(new TreeNode());
- data.Parent.Nodes.Add(node);
- }
-
- if (DiscoveryTreeView.SelectedNode == data.Parent)
- {
- ShowServerOnNetworks(data.Parent.Nodes);
- }
- else
- {
- data.Parent.Expand();
- }
- }
- catch (Exception e)
- {
- Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, e);
- }
- }
-
private void ShowServerOnNetworks(TreeNodeCollection nodes)
{
ServersTable.Rows.Clear();
@@ -601,37 +576,6 @@ private void ShowServerOnNetworks(TreeNodeCollection nodes)
}
}
- private class GetEndpointsData
- {
- public TreeNode Parent;
- public LocalDiscoveryServerClient Lds;
- }
-
- private void OnGetEndpointsComplete(IAsyncResult result)
- {
- if (InvokeRequired)
- {
- BeginInvoke(new AsyncCallback(OnGetEndpointsComplete), result);
- return;
- }
-
- GetEndpointsData data = (GetEndpointsData)result.AsyncState;
-
- try
- {
- List endpoints = data.Lds.EndGetEndpoints(result);
-
- if (DiscoveryTreeView.SelectedNode == data.Parent)
- {
- ShowEndpointDescriptions(endpoints);
- }
- }
- catch (Exception e)
- {
- Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, e);
- }
- }
-
private void ShowEndpointDescriptions(List endpoints)
{
EndpointsTable.Rows.Clear();
@@ -845,7 +789,7 @@ private void ShowPanel(bool list)
}
}
- private void DiscoveryTreeView_AfterSelect(object sender, TreeViewEventArgs e)
+ private async void DiscoveryTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
@@ -858,9 +802,7 @@ private void DiscoveryTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
e.Node.Nodes.Clear();
- m_lds.BeginFindServers(
- OnFindServersComplete,
- new ExpandNodeData() { Parent = e.Node, Lds = m_lds });
+ await PopulateServersNodeAsync(e.Node, null);
}
else
{
@@ -879,11 +821,7 @@ private void DiscoveryTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
e.Node.Nodes.Clear();
- m_lds.BeginFindServersOnNetwork(
- 0,
- 1000,
- OnFindServersOnNetworkComplete,
- new ExpandNodeData() { Parent = e.Node, Lds = m_lds });
+ await PopulateServersOnNetworkNodeAsync(e.Node, 0, 1000);
}
else
{
@@ -945,11 +883,7 @@ private void DiscoveryTreeView_AfterSelect(object sender, TreeViewEventArgs e)
if (discoveryUrl != null)
{
- m_lds.BeginGetEndpoints(
- discoveryUrl,
- null,
- OnGetEndpointsComplete,
- new GetEndpointsData() { Parent = e.Node, Lds = m_lds });
+ await LoadEndpointsAndShowAsync(e.Node, discoveryUrl);
}
}
@@ -969,11 +903,7 @@ private void DiscoveryTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
Cursor = Cursors.WaitCursor;
- m_lds.BeginGetEndpoints(
- server.DiscoveryUrl,
- null,
- OnGetEndpointsComplete,
- new GetEndpointsData() { Parent = e.Node, Lds = m_lds });
+ await LoadEndpointsAndShowAsync(e.Node, server.DiscoveryUrl);
}
finally
{
@@ -993,11 +923,7 @@ private void DiscoveryTreeView_AfterSelect(object sender, TreeViewEventArgs e)
ApplicationUriTextBox.Text = "---";
ProductUriTextBox.Text = "---";
- m_lds.BeginGetEndpoints(
- server.EndpointUrl.ToString(),
- null,
- OnGetEndpointsComplete,
- new GetEndpointsData() { Parent = e.Node, Lds = m_lds });
+ await LoadEndpointsAndShowAsync(e.Node, server.EndpointUrl.ToString());
}
}
catch (Exception ex)
@@ -1006,6 +932,23 @@ private void DiscoveryTreeView_AfterSelect(object sender, TreeViewEventArgs e)
}
}
+ private async Task LoadEndpointsAndShowAsync(TreeNode parent, string discoveryUrl)
+ {
+ try
+ {
+ var endpoints = await m_lds.GetEndpointsAsync(discoveryUrl, null);
+
+ if (DiscoveryTreeView.SelectedNode == parent)
+ {
+ ShowEndpointDescriptions(endpoints);
+ }
+ }
+ catch (Exception e)
+ {
+ Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, e);
+ }
+ }
+
private void FilterTextBox_TextChanged(object sender, EventArgs e)
{
try
diff --git a/Samples/GDS/ClientControls/Controls/EditValueCtrl.cs b/Samples/GDS/ClientControls/Controls/EditValueCtrl.cs
index 88118a946..433ce6733 100644
--- a/Samples/GDS/ClientControls/Controls/EditValueCtrl.cs
+++ b/Samples/GDS/ClientControls/Controls/EditValueCtrl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -58,7 +58,7 @@ public EditValueCtrl()
MaxDisplayTextLength = 100;
ValuesDV.AutoGenerateColumns = false;
ImageList = new ImageListControl().ImageList;
-
+
m_dataset = new DataSet();
m_dataset.Tables.Add("Values");
@@ -81,7 +81,7 @@ public EditValueCtrl()
#endregion
#region AccessInfo Class
- private class AccessInfo
+ private sealed class AccessInfo
{
public AccessInfo Parent;
public PropertyInfo PropertyInfo;
@@ -161,7 +161,7 @@ public bool CanChangeType
{
return false;
}
-
+
if (ButtonPanel.Controls.Count > 0)
{
AccessInfo info = ButtonPanel.Controls[ButtonPanel.Controls.Count - 1].Tag as AccessInfo;
@@ -186,7 +186,7 @@ public BuiltInType CurrentType
if (ButtonPanel.Controls.Count > 0)
{
AccessInfo info = ButtonPanel.Controls[ButtonPanel.Controls.Count - 1].Tag as AccessInfo;
-
+
if (info != null)
{
Variant? value = info.Value as Variant?;
@@ -263,7 +263,7 @@ public void SetArraySize()
if (currentValue == null)
{
- dimensions = new int[0];
+ dimensions = Array.Empty();
}
Array array = currentValue as Array;
@@ -384,7 +384,7 @@ public void SetType(BuiltInType builtInType)
{
return;
}
-
+
AccessInfo info = ButtonPanel.Controls[ButtonPanel.Controls.Count - 1].Tag as AccessInfo;
Opc.Ua.TypeInfo currentType = info.TypeInfo;
@@ -485,7 +485,8 @@ private object Clone(object value)
MemoryStream mstrm = new MemoryStream();
serializer.Serialize(mstrm, value);
mstrm.Position = 0;
- return serializer.Deserialize(mstrm);
+ using XmlReader reader = XmlReader.Create(mstrm, new XmlReaderSettings() { XmlResolver = null });
+ return serializer.Deserialize(reader);
}
}
@@ -536,7 +537,7 @@ public void ShowValue(
}
}
}
-
+
AccessInfo info = new AccessInfo();
info.Value = value;
info.TypeInfo = expectedType;
@@ -645,7 +646,7 @@ private void ShowValueNoNotify(AccessInfo parent)
if (parent.Parent != null || ButtonPanel.Controls.Count == 0)
{
item = new Button();
-
+
item.AutoSize = true;
item.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
item.FlatStyle = FlatStyle.Standard;
@@ -1033,7 +1034,7 @@ private void ShowIndexedValue(AccessInfo info)
DataRow row = m_dataset.Tables[0].NewRow();
StringBuilder buffer = new StringBuilder();
- buffer.Append("[");
+ buffer.Append('[');
if (info.Indexes != null)
{
@@ -1041,14 +1042,14 @@ private void ShowIndexedValue(AccessInfo info)
{
if (ii > 0)
{
- buffer.Append(",");
+ buffer.Append(',');
}
buffer.Append(info.Indexes[ii]);
}
}
- buffer.Append("]");
+ buffer.Append(']');
info.Name = buffer.ToString();
row[0] = info;
@@ -1421,7 +1422,7 @@ private bool IsSimpleValue(AccessInfo info)
{
return false;
}
-
+
switch (typeInfo.BuiltInType)
{
case BuiltInType.String:
diff --git a/Samples/GDS/ClientControls/Controls/SelectGdsDialog.cs b/Samples/GDS/ClientControls/Controls/SelectGdsDialog.cs
index cf4268e59..c70188302 100644
--- a/Samples/GDS/ClientControls/Controls/SelectGdsDialog.cs
+++ b/Samples/GDS/ClientControls/Controls/SelectGdsDialog.cs
@@ -77,7 +77,7 @@ private void ServerUrlTextBox_TextChanged(object sender, EventArgs e)
OkButton.Enabled = Uri.IsWellFormedUriString(ServerUrlTextBox.Text.Trim(), UriKind.Absolute);
}
- private void OkButton_Click(object sender, EventArgs e)
+ private async void OkButton_Click(object sender, EventArgs e)
{
try
{
@@ -92,7 +92,7 @@ private void OkButton_Click(object sender, EventArgs e)
{
Cursor = Cursors.WaitCursor;
- var endpoint = CoreClientUtils.SelectEndpoint(m_gds.Configuration, url, true, 5000);
+ var endpoint = await CoreClientUtils.SelectEndpointAsync(m_gds.Configuration, url, true, 5000);
if (UserNameCredentialsRB.Checked)
{
@@ -109,7 +109,7 @@ private void OkButton_Click(object sender, EventArgs e)
}
}
- m_gds.Connect(url);
+ await m_gds.ConnectAsync(url);
}
finally
{
diff --git a/Samples/GDS/ClientControls/Controls/SelectPushServerDialog.cs b/Samples/GDS/ClientControls/Controls/SelectPushServerDialog.cs
index 746c89d5d..f36dfad2d 100644
--- a/Samples/GDS/ClientControls/Controls/SelectPushServerDialog.cs
+++ b/Samples/GDS/ClientControls/Controls/SelectPushServerDialog.cs
@@ -77,7 +77,7 @@ private void ServerUrlTextBox_TextChanged(object sender, EventArgs e)
OkButton.Enabled = Uri.IsWellFormedUriString(ServerUrlTextBox.Text.Trim(), UriKind.Absolute);
}
- private void OkButton_Click(object sender, EventArgs e)
+ private async void OkButton_Click(object sender, EventArgs e)
{
try
{
@@ -92,7 +92,7 @@ private void OkButton_Click(object sender, EventArgs e)
{
Cursor = Cursors.WaitCursor;
- var endpoint = CoreClientUtils.SelectEndpoint(m_pushServer.Configuration, url, false, 5000);
+ var endpoint = await CoreClientUtils.SelectEndpointAsync(m_pushServer.Configuration, url, false, 5000);
if (UserNameCredentialsRB.Checked)
{
@@ -109,7 +109,7 @@ private void OkButton_Click(object sender, EventArgs e)
}
}
- m_pushServer.Connect(url).Wait();
+ await m_pushServer.ConnectAsync(url);
}
finally
{
diff --git a/Samples/GDS/ClientControls/Controls/ServerStatusControl.cs b/Samples/GDS/ClientControls/Controls/ServerStatusControl.cs
index 4ae86a773..301dfce37 100644
--- a/Samples/GDS/ClientControls/Controls/ServerStatusControl.cs
+++ b/Samples/GDS/ClientControls/Controls/ServerStatusControl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -29,6 +29,8 @@
using System;
using System.Drawing;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
using Opc.Ua.Client;
@@ -43,10 +45,10 @@ public ServerStatusControl()
private ServerPushConfigurationClient m_server;
- public void Initialize(ServerPushConfigurationClient server)
+ public Task InitializeAsync(ServerPushConfigurationClient server, CancellationToken ct = default)
{
m_server = server;
- ServerBrowseControl.Initialize((server != null) ? server.Session as Session : null, Opc.Ua.ObjectIds.ObjectsFolder, ReferenceTypeIds.HierarchicalReferences);
+ return ServerBrowseControl.InitializeAsync((server != null) ? server.Session as Session : null, Opc.Ua.ObjectIds.ObjectsFolder, ct, ReferenceTypeIds.HierarchicalReferences);
}
public void SetServerStatus(ServerStatusDataType status)
@@ -82,8 +84,8 @@ public void SetServerStatus(ServerStatusDataType status)
StateTextBox.Text = status.State.ToString();
}
}
-
- private void ApplyChangesButton_Click(object sender, EventArgs e)
+
+ private async void ApplyChangesButton_Click(object sender, EventArgs e)
{
if (m_server == null)
{
@@ -92,7 +94,7 @@ private void ApplyChangesButton_Click(object sender, EventArgs e)
try
{
- m_server.ApplyChanges();
+ await m_server.ApplyChangesAsync();
}
catch (Exception exception)
{
@@ -106,9 +108,9 @@ private void ApplyChangesButton_Click(object sender, EventArgs e)
try
{
- m_server.Disconnect();
+ await m_server.DisconnectAsync();
}
- catch (Exception)
+ catch
{
// ignore.
}
diff --git a/Samples/GDS/ClientControls/Controls/TrustListControl.cs b/Samples/GDS/ClientControls/Controls/TrustListControl.cs
index 1633bbc8d..acc2ec25f 100644
--- a/Samples/GDS/ClientControls/Controls/TrustListControl.cs
+++ b/Samples/GDS/ClientControls/Controls/TrustListControl.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -34,6 +34,8 @@
using System.Drawing;
using System.IO;
using System.Security.Cryptography.X509Certificates;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
using Opc.Ua.Security.Certificates;
@@ -87,7 +89,7 @@ private ICertificateStore CreateStore(string storePath)
return store;
}
- public async void Initialize(string trustedStorePath, string issuerStorePath, string rejectedStorePath)
+ public async Task Initialize(string trustedStorePath, string issuerStorePath, string rejectedStorePath, CancellationToken ct = default)
{
CertificatesTable.Rows.Clear();
@@ -99,14 +101,14 @@ public async void Initialize(string trustedStorePath, string issuerStorePath, st
{
using (ICertificateStore store = CreateStore(trustedStorePath))
{
- X509CertificateCollection certificates = await store.Enumerate();
+ X509CertificateCollection certificates = await store.EnumerateAsync(ct);
foreach (X509Certificate2 certificate in certificates)
{
var crls = new X509CRLCollection();
if (store.SupportsCRLs)
{
- foreach (X509CRL crl in await store.EnumerateCRLs(certificate))
+ foreach (X509CRL crl in await store.EnumerateCRLsAsync(certificate, ct: ct))
{
crls.Add(crl);
}
@@ -126,19 +128,19 @@ public async void Initialize(string trustedStorePath, string issuerStorePath, st
{
using (ICertificateStore store = CreateStore(issuerStorePath))
{
- X509Certificate2Collection certificates = await store.Enumerate();
+ X509Certificate2Collection certificates = await store.EnumerateAsync(ct);
foreach (X509Certificate2 certificate in certificates)
{
var crls = new X509CRLCollection();
if (store.SupportsCRLs)
{
- foreach (X509CRL crl in await store.EnumerateCRLs(certificate))
+ foreach (X509CRL crl in await store.EnumerateCRLsAsync(certificate, ct: ct))
{
crls.Add(crl);
}
}
-
+
AddCertificate(certificate, Status.Issuer, crls);
}
}
@@ -149,7 +151,7 @@ public async void Initialize(string trustedStorePath, string issuerStorePath, st
{
using (ICertificateStore store = CreateStore(rejectedStorePath))
{
- X509Certificate2Collection certificates = await store.Enumerate();
+ X509Certificate2Collection certificates = await store.EnumerateAsync(ct);
foreach (X509Certificate2 certificate in certificates)
{
AddCertificate(certificate, Status.Rejected, null);
@@ -183,7 +185,7 @@ public void Initialize(TrustListDataType trustList, X509Certificate2Collection r
foreach (var crlBytes in trustList.TrustedCrls)
{
X509CRL crl = new X509CRL(crlBytes);
-
+
if (X509Utils.CompareDistinguishedName(crl.Issuer, certificate.Subject) &&
crl.VerifySignature(certificate, false))
{
@@ -385,15 +387,15 @@ private void MoveCertificate(DataRow row, Status status)
{
using (ICertificateStore store = CreateStore(targetStorePath))
{
- store.Add(certificate);
+ store.AddAsync(certificate);
}
}
-
+
if (!String.IsNullOrEmpty(oldStorePath))
{
using (ICertificateStore store = CreateStore(oldStorePath))
{
- store.Delete(certificate.Thumbprint);
+ store.DeleteAsync(certificate.Thumbprint);
}
}
}
@@ -443,7 +445,7 @@ private void DeleteMenuItem_Click(object sender, EventArgs e)
}
catch (Exception ex)
{
- Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, ex);
+ Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, ex);
}
}
@@ -544,7 +546,7 @@ private void ImportMenuItem_Click(object sender, EventArgs e)
{
using (ICertificateStore store = CreateStore(m_trustedStorePath))
{
- store.Add(certificate);
+ store.AddAsync(certificate);
}
}
}
diff --git a/Samples/GDS/ClientControls/Controls/TrustListDialog.cs b/Samples/GDS/ClientControls/Controls/TrustListDialog.cs
index 95ecd3e94..9e8e30cc4 100644
--- a/Samples/GDS/ClientControls/Controls/TrustListDialog.cs
+++ b/Samples/GDS/ClientControls/Controls/TrustListDialog.cs
@@ -1,8 +1,8 @@
-/* ========================================================================
+/* ========================================================================
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -27,6 +27,8 @@
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms;
namespace Opc.Ua.Gds.Client.Controls
@@ -39,12 +41,13 @@ public CertificatesStoreDialog()
Icon = ImageListControl.AppIcon;
}
- public void ShowDialog(ApplicationConfiguration configuration)
+ public async Task ShowDialogAsync(ApplicationConfiguration configuration, CancellationToken ct = default)
{
- CertificatesControl.Initialize(
+ await CertificatesControl.Initialize(
configuration.SecurityConfiguration.TrustedPeerCertificates.StorePath,
configuration.SecurityConfiguration.TrustedIssuerCertificates.StorePath,
- configuration.SecurityConfiguration.RejectedCertificateStore.StorePath);
+ configuration.SecurityConfiguration.RejectedCertificateStore.StorePath,
+ ct);
ApplicationNameLabel.Text = configuration.ApplicationName;
ApplicationUriLabel.Text = configuration.ApplicationUri;
diff --git a/Samples/GDS/ClientControls/Controls/ViewApplicationRecordsDialog.cs b/Samples/GDS/ClientControls/Controls/ViewApplicationRecordsDialog.cs
index b8c1fc771..1bfe9ca88 100644
--- a/Samples/GDS/ClientControls/Controls/ViewApplicationRecordsDialog.cs
+++ b/Samples/GDS/ClientControls/Controls/ViewApplicationRecordsDialog.cs
@@ -1,4 +1,4 @@
-/* ========================================================================
+/* ========================================================================
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
@@ -158,7 +158,7 @@ public ApplicationRecordDataType ShowDialog(IWin32Window owner, IList ShowDialog(IWin32Window owner, ref QueryServersFilt
ApplicationUriTextBox.Text = filters.ApplicationUri;
ApplicationNameTextBox.Text = filters.ApplicationName;
ProductUriTextBox.Text = filters.ProductUri;
-
+
if (base.ShowDialog(owner) != DialogResult.OK)
{
return null;
@@ -103,7 +103,7 @@ private void ApplicationRecordDataGridView_SelectionChanged(object sender, Event
}
}
- private void SearchButton_Click(object sender, EventArgs e)
+ private async void SearchButton_Click(object sender, EventArgs e)
{
try
{
@@ -111,12 +111,12 @@ private void SearchButton_Click(object sender, EventArgs e)
if (!m_gds.IsConnected)
{
- new SelectGdsDialog().ShowDialog(null, m_gds, m_gds.GetDefaultGdsUrls(null));
+ new SelectGdsDialog().ShowDialog(null, m_gds, await m_gds.GetDefaultGdsUrlsAsync(null));
}
uint maxNoOfRecords = (uint)NumberOfRecordsUpDown.Value;
- var servers = m_gds.QueryServers(
+ var servers = await m_gds.QueryServersAsync(
0,
ApplicationNameTextBox.Text.Trim(),
ApplicationUriTextBox.Text.Trim(),
@@ -180,7 +180,7 @@ private void SearchButton_Click(object sender, EventArgs e)
if (ServersTable.Rows.Count == 0)
{
- MessageBox.Show(ParentForm, "No servers available that meet the filter criteria.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(ParentForm, "No servers available that meet the filter criteria.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
@@ -310,7 +310,7 @@ private void ServerCapabilitiesButton_Click(object sender, EventArgs e)
{
if (buffer.Length > 0)
{
- buffer.Append(",");
+ buffer.Append(',');
}
buffer.Append(capability);
diff --git a/Samples/GDS/ClientControls/GlobalDiscoveryClientControls.csproj b/Samples/GDS/ClientControls/GlobalDiscoveryClientControls.csproj
index 95ef330c3..91b09414d 100644
--- a/Samples/GDS/ClientControls/GlobalDiscoveryClientControls.csproj
+++ b/Samples/GDS/ClientControls/GlobalDiscoveryClientControls.csproj
@@ -25,6 +25,7 @@
DEBUG;TRACE
prompt
4
+ AllRules.ruleset
pdbonly
@@ -33,6 +34,7 @@
TRACE
prompt
4
+ AllRules.ruleset
@@ -217,10 +219,10 @@
- 1.5.376.244
+ 1.5.377.11-preview
- 1.5.376.244
+ 1.5.377.11-preview
diff --git a/Samples/GDS/ConsoleServer/NetCoreGlobalDiscoveryServer.csproj b/Samples/GDS/ConsoleServer/NetCoreGlobalDiscoveryServer.csproj
index aad804d8b..074cc88b8 100644
--- a/Samples/GDS/ConsoleServer/NetCoreGlobalDiscoveryServer.csproj
+++ b/Samples/GDS/ConsoleServer/NetCoreGlobalDiscoveryServer.csproj
@@ -1,4 +1,4 @@
-
+
Exe
@@ -12,10 +12,10 @@
-
+
-
-
+
+
diff --git a/Samples/GDS/ConsoleServer/Program.cs b/Samples/GDS/ConsoleServer/Program.cs
index 61e362d61..02eb7d7df 100644
--- a/Samples/GDS/ConsoleServer/Program.cs
+++ b/Samples/GDS/ConsoleServer/Program.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -27,11 +27,6 @@
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/
-using Mono.Options;
-using Opc.Ua.Configuration;
-using Opc.Ua.Gds.Server.Database.Linq;
-using Opc.Ua.Server;
-using Opc.Ua.Server.UserDatabase;
using System;
using System.Collections.Generic;
using System.Data;
@@ -40,33 +35,37 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using System.Xml.Linq;
+using Mono.Options;
+using Opc.Ua.Configuration;
+using Opc.Ua.Gds.Server.Database.Linq;
+using Opc.Ua.Server;
+using Opc.Ua.Server.UserDatabase;
namespace Opc.Ua.Gds.Server
{
public class ApplicationMessageDlg : IApplicationMessageDlg
{
- private string message = string.Empty;
- private bool ask = false;
+ private string m_message = string.Empty;
+ private bool m_ask = false;
public override void Message(string text, bool ask)
{
- this.message = text;
- this.ask = ask;
+ this.m_message = text;
+ this.m_ask = ask;
}
public override async Task ShowAsync()
{
- if (ask)
+ if (m_ask)
{
- message += " (y/n, default y): ";
- Console.Write(message);
+ m_message += " (y/n, default y): ";
+ Console.Write(m_message);
}
else
{
- Console.WriteLine(message);
+ Console.WriteLine(m_message);
}
- if (ask)
+ if (m_ask)
{
try
{
@@ -95,7 +94,7 @@ public enum ExitCode : int
public static class Program
{
- public static int Main(string[] args)
+ public static async Task Main(string[] args)
{
Console.WriteLine(".Net Core OPC UA Global Discovery Server");
@@ -131,8 +130,8 @@ public static int Main(string[] args)
return (int)ExitCode.ErrorInvalidCommandLine;
}
- NetCoreGlobalDiscoveryServer server = new NetCoreGlobalDiscoveryServer();
- server.Run();
+ var server = new NetCoreGlobalDiscoveryServer();
+ await server.RunAsync().ConfigureAwait(false);
return (int)NetCoreGlobalDiscoveryServer.ExitCode;
}
@@ -140,22 +139,22 @@ public static int Main(string[] args)
public class NetCoreGlobalDiscoveryServer
{
- GlobalDiscoverySampleServer server;
- Task status;
- DateTime lastEventTime;
- static ExitCode exitCode;
+ private GlobalDiscoverySampleServer server;
+ private Task status;
+ private DateTime lastEventTime;
+ public static ExitCode exitCode;
public NetCoreGlobalDiscoveryServer()
{
}
- public void Run()
+ public async Task RunAsync()
{
try
{
exitCode = ExitCode.ErrorServerNotStarted;
- ConsoleGlobalDiscoveryServer().Wait();
+ await ConsoleGlobalDiscoveryServerAsync().ConfigureAwait(false);
Console.WriteLine("Server started. Press Ctrl-C to exit...");
exitCode = ExitCode.ErrorServerRunning;
}
@@ -192,7 +191,7 @@ public void Run()
{
// Stop status thread
server = null;
- status.Wait();
+ await status.ConfigureAwait(false);
// Stop server and dispose
_server.Stop();
}
@@ -201,7 +200,7 @@ public void Run()
exitCode = ExitCode.Ok;
}
- public static ExitCode ExitCode { get => exitCode; }
+ public static ExitCode ExitCode => exitCode;
private static void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
{
@@ -213,21 +212,20 @@ private static void CertificateValidator_CertificateValidation(CertificateValida
}
}
- private async Task ConsoleGlobalDiscoveryServer()
+ private async Task ConsoleGlobalDiscoveryServerAsync()
{
ApplicationInstance.MessageDlg = new ApplicationMessageDlg();
- ApplicationInstance application = new ApplicationInstance
- {
+ var application = new ApplicationInstance {
ApplicationName = "Global Discovery Server",
ApplicationType = ApplicationType.Server,
ConfigSectionName = "Opc.Ua.GlobalDiscoveryServer"
};
// load the application configuration.
- ApplicationConfiguration config = await application.LoadApplicationConfiguration(false).ConfigureAwait(false);
+ ApplicationConfiguration config = await application.LoadApplicationConfigurationAsync(false).ConfigureAwait(false);
// check the application certificate.
- bool haveAppCertificate = await application.CheckApplicationInstanceCertificates(false).ConfigureAwait(false);
+ bool haveAppCertificate = await application.CheckApplicationInstanceCertificatesAsync(false).ConfigureAwait(false);
if (!haveAppCertificate)
{
throw new Exception("Application instance certificate invalid!");
@@ -256,17 +254,17 @@ private async Task ConsoleGlobalDiscoveryServer()
userDatabase,
true,
createStandardUsers);
- await application.Start(server).ConfigureAwait(false);
+ await application.StartAsync(server).ConfigureAwait(false);
// print endpoint info
- var endpoints = application.Server.GetEndpoints().Select(e => e.EndpointUrl).Distinct();
- foreach (var endpoint in endpoints)
+ IEnumerable endpoints = application.Server.GetEndpoints().Select(e => e.EndpointUrl).Distinct();
+ foreach (string endpoint in endpoints)
{
Console.WriteLine(endpoint);
}
// start the status thread
- status = Task.Run(new Action(StatusThread));
+ status = Task.Run(new Action(StatusThreadAsync));
// print notification on session events
server.CurrentInstance.SessionManager.SessionActivated += EventStatus;
@@ -278,7 +276,7 @@ private async Task ConsoleGlobalDiscoveryServer()
private bool ConfigureUsers(JsonUserDatabase userDatabase)
{
ApplicationInstance.MessageDlg.Message("Use default users?", true);
- bool createStandardUsers = ApplicationInstance.MessageDlg.ShowAsync().Result;
+ bool createStandardUsers = ApplicationInstance.MessageDlg.ShowAsync().GetAwaiter().GetResult();
if (!createStandardUsers)
{
@@ -310,13 +308,13 @@ private bool ConfigureUsers(JsonUserDatabase userDatabase)
return createStandardUsers;
}
- private void EventStatus(Session session, SessionEventReason reason)
+ private void EventStatus(ISession session, SessionEventReason reason)
{
lastEventTime = DateTime.UtcNow;
PrintSessionStatus(session, reason.ToString());
}
- void PrintSessionStatus(Session session, string reason, bool lastContact = false)
+ private void PrintSessionStatus(ISession session, string reason, bool lastContact = false)
{
lock (session.DiagnosticsLock)
{
@@ -337,16 +335,16 @@ void PrintSessionStatus(Session session, string reason, bool lastContact = false
}
}
- private async void StatusThread()
+ private async void StatusThreadAsync()
{
while (server != null)
{
if (DateTime.UtcNow - lastEventTime > TimeSpan.FromMilliseconds(6000))
{
- IList sessions = server.CurrentInstance.SessionManager.GetSessions();
+ IList sessions = server.CurrentInstance.SessionManager.GetSessions();
for (int ii = 0; ii < sessions.Count; ii++)
{
- Session session = sessions[ii];
+ ISession session = sessions[ii];
PrintSessionStatus(session, "-Status-", true);
}
lastEventTime = DateTime.UtcNow;
diff --git a/Samples/GDS/Server/GlobalDiscoveryServer.csproj b/Samples/GDS/Server/GlobalDiscoveryServer.csproj
index d00c45fcb..164615771 100644
--- a/Samples/GDS/Server/GlobalDiscoveryServer.csproj
+++ b/Samples/GDS/Server/GlobalDiscoveryServer.csproj
@@ -235,10 +235,10 @@
6.5.1
- 1.5.376.244
+ 1.5.377.11-preview
- 1.5.376.244
+ 1.5.377.11-preview
diff --git a/Samples/GDS/Server/Program.cs b/Samples/GDS/Server/Program.cs
index d84a17bbd..f782a8a34 100644
--- a/Samples/GDS/Server/Program.cs
+++ b/Samples/GDS/Server/Program.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -61,23 +61,23 @@ static void Main()
try
{
// load the application configuration.
- var config = application.LoadApplicationConfiguration(false).Result;
+ var config = application.LoadApplicationConfigurationAsync(false).AsTask().GetAwaiter().GetResult();
// check the application certificate.
- bool haveAppCertificate = application.CheckApplicationInstanceCertificates(false).Result;
+ bool haveAppCertificate = application.CheckApplicationInstanceCertificatesAsync(false).AsTask().GetAwaiter().GetResult();
if (!haveAppCertificate)
{
throw new Exception("Application instance certificate invalid!");
}
-
+
// load the user database.
var userDatabase = new SqlUsersDatabase();
//initialize users Database
userDatabase.Initialize();
bool createStandardUsers = ConfigureUsers(userDatabase);
-
+
// start the server.
var database = new SqlApplicationsDatabase();
@@ -88,7 +88,7 @@ static void Main()
userDatabase,
true,
createStandardUsers);
- application.Start(server).Wait();
+ application.StartAsync(server).Wait();
// run the application interactively.
System.Windows.Forms.Application.Run(new ServerForm(server, application.ApplicationConfiguration));
@@ -102,7 +102,7 @@ static void Main()
private static bool ConfigureUsers(SqlUsersDatabase userDatabase)
{
ApplicationInstance.MessageDlg.Message("Use default users?", true);
- bool createStandardUsers = ApplicationInstance.MessageDlg.ShowAsync().Result;
+ bool createStandardUsers = ApplicationInstance.MessageDlg.ShowAsync().GetAwaiter().GetResult();
if (!createStandardUsers)
{
//Delete existing standard users
diff --git a/Samples/Opc.Ua.Sample/Base/CustomNodeManager.cs b/Samples/Opc.Ua.Sample/Base/CustomNodeManager.cs
index 6fd88fb7b..9f6acc759 100644
--- a/Samples/Opc.Ua.Sample/Base/CustomNodeManager.cs
+++ b/Samples/Opc.Ua.Sample/Base/CustomNodeManager.cs
@@ -2,7 +2,7 @@
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
- *
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -11,7 +11,7 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
@@ -59,7 +59,7 @@ public CustomNodeManager2(IServerInternal server)
m_systemContext.SystemHandle = null;
m_systemContext.NodeIdFactory = this;
- // create the table of nodes.
+ // create the table of nodes.
m_predefinedNodes = new NodeIdDictionary();
m_rootNotifiers = new List();
m_sampledItems = new List();
@@ -341,7 +341,7 @@ protected set
///
/// The externalReferences is an out parameter that allows the node manager to link to nodes
/// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and
- /// should have a reference to the root folder node(s) exposed by this node manager.
+ /// should have a reference to the root folder node(s) exposed by this node manager.
///
public virtual void CreateAddressSpace(IDictionary> externalReferences)
{
@@ -519,7 +519,7 @@ protected virtual void RemovePredefinedNode(
///
protected virtual void OnNodeRemoved(NodeState node)
{
- // overridden by the sub-class.
+ // overridden by the sub-class.
}
///
@@ -721,7 +721,7 @@ protected void AddTypesToTypeTree(NodeId typeId)
}
///
- /// Finds the specified and checks if it is of the expected type.
+ /// Finds the specified and checks if it is of the expected type.
///
/// Returns null if not found or not of the correct type.
public NodeState FindPredefinedNode(NodeId nodeId, Type expectedType)
@@ -765,7 +765,7 @@ public virtual void DeleteAddressSpace()
/// Returns a unique handle for the node.
///
///
- /// This must efficiently determine whether the node belongs to the node manager. If it does belong to
+ /// This must efficiently determine whether the node belongs to the node manager. If it does belong to
/// NodeManager it should return a handle that does not require the NodeId to be validated again when
/// the handle is passed into other methods such as 'Read' or 'Write'.
///
@@ -781,7 +781,7 @@ public virtual object GetManagerHandle(NodeId nodeId)
/// Returns a unique handle for the node.
///
///
- /// This must efficiently determine whether the node belongs to the node manager. If it does belong to
+ /// This must efficiently determine whether the node belongs to the node manager. If it does belong to
/// NodeManager it should return a handle that does not require the NodeId to be validated again when
/// the handle is passed into other methods such as 'Read' or 'Write'.
///
@@ -1030,7 +1030,7 @@ public virtual void Browse(
// apply filters to references.
for (IReference reference = browser.Next(); reference != null; reference = browser.Next())
{
- // create the type definition reference.
+ // create the type definition reference.
ReferenceDescription description = GetReferenceDescription(context, reference, continuationPoint);
if (description == null)
@@ -1064,7 +1064,7 @@ private ReferenceDescription GetReferenceDescription(
IReference reference,
ContinuationPoint continuationPoint)
{
- // create the type definition reference.
+ // create the type definition reference.
ReferenceDescription description = new ReferenceDescription();
description.NodeId = reference.TargetId;
@@ -1146,9 +1146,9 @@ private ReferenceDescription GetReferenceDescription(
/// Returns the target of the specified browse path fragment(s).
///
///
- /// If reference exists but the node manager does not know the browse name it must
+ /// If reference exists but the node manager does not know the browse name it must
/// return the NodeId as an unresolvedTargetIds. The caller will try to check the
- /// browse name.
+ /// browse name.
///
public virtual void TranslateBrowsePath(
OperationContext context,
@@ -1970,8 +1970,8 @@ protected virtual ServiceResult Call(
/// Subscribes or unsubscribes to events produced by the specified source.
///
///
- /// This method is called when a event subscription is created or deletes. The node manager
- /// must start/stop reporting events for the specified object and all objects below it in
+ /// This method is called when a event subscription is created or deletes. The node manager
+ /// must start/stop reporting events for the specified object and all objects below it in
/// the notifier hierarchy.
///
public virtual ServiceResult SubscribeToEvents(
@@ -2037,7 +2037,7 @@ public virtual ServiceResult SubscribeToEvents(
/// Subscribes or unsubscribes to events produced by all event sources.
///
///
- /// This method is called when a event subscription is created or deleted. The node
+ /// This method is called when a event subscription is created or deleted. The node
/// manager must start/stop reporting events for all objects that it manages.
///
public virtual ServiceResult SubscribeToAllEvents(
@@ -2544,15 +2544,14 @@ protected virtual ServiceResult CreateMonitoredItem(
/// Reads the initial value for a monitored item.
///
/// The context.
- /// The item handle.
+ /// The monitored node.
/// The monitored item.
protected virtual ServiceResult ReadInitialValue(
ISystemContext context,
MonitoredNode monitoredNode,
IDataChangeMonitoredItem2 monitoredItem)
{
- DataValue initialValue = new DataValue
- {
+ DataValue initialValue = new DataValue {
Value = null,
ServerTimestamp = DateTime.UtcNow,
SourceTimestamp = DateTime.MinValue,
@@ -2629,7 +2628,7 @@ private void DeleteSampledItem(DataChangeMonitoredItem monitoredItem)
}
///
- /// Polls each monitored item which requires sample.
+ /// Polls each monitored item which requires sample.
///
private void DoSample(object state)
{
diff --git a/Samples/Opc.Ua.Sample/Base/DataChangeMonitoredItem.cs b/Samples/Opc.Ua.Sample/Base/DataChangeMonitoredItem.cs
index d73d9f382..1a70ec592 100644
--- a/Samples/Opc.Ua.Sample/Base/DataChangeMonitoredItem.cs
+++ b/Samples/Opc.Ua.Sample/Base/DataChangeMonitoredItem.cs
@@ -30,7 +30,7 @@
using System;
using System.Collections.Generic;
using System.Text;
-using Opc.Ua.Server;
+using Opc.Ua.Server;
namespace Opc.Ua.Sample
{
@@ -111,10 +111,10 @@ public DataChangeMonitoredItem(
m_filter = filter;
m_range = 0;
m_alwaysReportUpdates = alwaysReportUpdates;
-
+
if (range != null)
{
- m_range = range.High - range.Low;
+ m_range = range.High - range.Low;
}
if (queueSize > 1)
@@ -156,7 +156,7 @@ public QualifiedName DataEncoding
///
public bool AlwaysReportUpdates
{
- get { return m_alwaysReportUpdates; }
+ get { return m_alwaysReportUpdates; }
set { m_alwaysReportUpdates = value; }
}
@@ -181,7 +181,7 @@ public int TimeToNextSample
return 0;
}
- return (int)((m_nextSampleTime - now.Ticks)/TimeSpan.TicksPerMillisecond);
+ return (int)((m_nextSampleTime - now.Ticks) / TimeSpan.TicksPerMillisecond);
}
}
}
@@ -202,7 +202,7 @@ public MonitoringMode MonitoringMode
///
public double SamplingInterval
{
- get
+ get
{
lock (m_lock)
{
@@ -210,7 +210,7 @@ public double SamplingInterval
}
}
}
-
+
///
/// Modifies the monitored item parameters,
///
@@ -222,7 +222,7 @@ public ServiceResult Modify(
{
return Modify(diagnosticsMasks, timestampsToReturn, clientHandle, samplingInterval, 0, false, null, null);
}
-
+
///
/// Modifies the monitored item parameters,
///
@@ -243,17 +243,17 @@ public ServiceResult Modify(
m_clientHandle = clientHandle;
// subtract the previous sampling interval.
- long oldSamplingInterval = (long)(m_samplingInterval*TimeSpan.TicksPerMillisecond);
+ long oldSamplingInterval = (long)(m_samplingInterval * TimeSpan.TicksPerMillisecond);
if (oldSamplingInterval < m_nextSampleTime)
{
m_nextSampleTime -= oldSamplingInterval;
}
-
+
m_samplingInterval = samplingInterval;
// calculate the next sampling interval.
- long newSamplingInterval = (long)(m_samplingInterval*TimeSpan.TicksPerMillisecond);
+ long newSamplingInterval = (long)(m_samplingInterval * TimeSpan.TicksPerMillisecond);
if (m_samplingInterval > 0)
{
@@ -270,7 +270,7 @@ public ServiceResult Modify(
if (range != null)
{
- m_range = range.High - range.Low;
+ m_range = range.High - range.Low;
}
// update the queue size.
@@ -292,7 +292,7 @@ public ServiceResult Modify(
return ServiceResult.Good;
}
}
-
+
///
/// Called when the attribute being monitored changed. Reads and queues the value.
///
@@ -322,10 +322,15 @@ public INodeManager NodeManager
get { return m_source.NodeManager; }
}
+ public NodeId NodeId
+ {
+ get { return m_source.Node.NodeId; }
+ }
+
///
/// The session for the monitored item.
///
- public Session Session
+ public ISession Session
{
get
{
@@ -494,7 +499,7 @@ public ServiceResult GetCreateResult(out MonitoredItemCreateResult result)
result.RevisedSamplingInterval = m_samplingInterval;
result.RevisedQueueSize = 0;
result.FilterResult = null;
-
+
if (m_queue != null)
{
result.RevisedQueueSize = m_queue.QueueSize;
@@ -574,7 +579,7 @@ public void QueueValue(DataValue value, ServiceResult error, bool ignoreFilters)
copy.SourcePicoseconds = value.SourcePicoseconds;
copy.ServerTimestamp = value.ServerTimestamp;
copy.ServerPicoseconds = value.ServerPicoseconds;
-
+
value = copy;
// ensure the data value matches the error status code.
@@ -611,8 +616,8 @@ public void SetSemanticsChanged()
{
m_semanticsChanged = true;
}
- }
-
+ }
+
///
/// Sets a flag indicating that the structure of the monitored node has changed.
///
@@ -625,8 +630,8 @@ public void SetStructureChanged()
{
m_structureChanged = true;
}
- }
-
+ }
+
///
/// Changes the monitoring mode.
///
@@ -649,7 +654,7 @@ public MonitoringMode SetMonitoringMode(MonitoringMode monitoringMode)
}
m_monitoringMode = monitoringMode;
-
+
if (monitoringMode == MonitoringMode.Disabled)
{
m_readyToPublish = false;
@@ -685,8 +690,8 @@ public IUserIdentity EffectiveIdentity
private void IncrementSampleTime()
{
// update next sample time.
- long now = DateTime.UtcNow.Ticks;
- long samplingInterval = (long)(m_samplingInterval*TimeSpan.TicksPerMillisecond);
+ long now = DateTime.UtcNow.Ticks;
+ long samplingInterval = (long)(m_samplingInterval * TimeSpan.TicksPerMillisecond);
if (m_nextSampleTime > 0)
{
@@ -694,7 +699,7 @@ private void IncrementSampleTime()
if (samplingInterval > 0 && delta >= 0)
{
- m_nextSampleTime += ((delta/samplingInterval)+1)*samplingInterval;
+ m_nextSampleTime += ((delta / samplingInterval) + 1) * samplingInterval;
}
}
@@ -757,15 +762,15 @@ public bool Publish(OperationContext context, Queue n
return true;
}
}
-
+
///
/// Publishes a value.
///
private void Publish(
- OperationContext context,
+ OperationContext context,
DataValue value,
ServiceResult error,
- Queue notifications,
+ Queue notifications,
Queue diagnostics)
{
// set semantics changed bit.
@@ -779,7 +784,7 @@ private void Publish(
if (error != null)
{
error = new ServiceResult(
- error.StatusCode.SetSemanticsChanged(true),
+ error.StatusCode.SetSemanticsChanged(true),
error.SymbolicId,
error.NamespaceUri,
error.LocalizedText,
@@ -789,7 +794,7 @@ private void Publish(
m_semanticsChanged = false;
}
-
+
// set structure changed bit.
if (m_structureChanged)
{
@@ -801,7 +806,7 @@ private void Publish(
if (error != null)
{
error = new ServiceResult(
- error.StatusCode.SetStructureChanged(true),
+ error.StatusCode.SetStructureChanged(true),
error.SymbolicId,
error.NamespaceUri,
error.LocalizedText,
@@ -884,7 +889,7 @@ public void Dispose()
private bool m_readyToTrigger;
private bool m_alwaysReportUpdates;
private bool m_semanticsChanged;
- private bool m_structureChanged;
+ private bool m_structureChanged;
private bool m_resendData;
#endregion
}
diff --git a/Samples/Opc.Ua.Sample/Base/MonitoredItemQueue.cs b/Samples/Opc.Ua.Sample/Base/MonitoredItemQueue.cs
index 4f0532fab..5804eec82 100644
--- a/Samples/Opc.Ua.Sample/Base/MonitoredItemQueue.cs
+++ b/Samples/Opc.Ua.Sample/Base/MonitoredItemQueue.cs
@@ -52,24 +52,24 @@ public MonitoredItemQueue()
m_nextSampleTime = 0;
m_samplingInterval = 0;
}
-
+
#region Public Methods
///
/// Gets the current queue size.
///
public uint QueueSize
{
- get
+ get
{
if (m_values == null)
{
return 0;
}
- return (uint)m_values.Length;
+ return (uint)m_values.Length;
}
}
-
+
///
/// Gets number of elements actually contained in value queue.
///
@@ -104,7 +104,7 @@ public void SetSamplingInterval(double samplingInterval)
}
// calculate the next sampling interval.
- m_samplingInterval = (long)(samplingInterval*TimeSpan.TicksPerMillisecond);
+ m_samplingInterval = (long)(samplingInterval * TimeSpan.TicksPerMillisecond);
if (m_samplingInterval > 0)
{
@@ -135,14 +135,14 @@ public void SetQueueSize(uint queueSize, bool discardOldest, DiagnosticsMasks di
int end = m_end;
// create new queue.
- DataValue[] values = new DataValue[length];
+ DataValue[] values = new DataValue[length];
ServiceResult[] errors = null;
if ((diagnosticsMasks & DiagnosticsMasks.OperationAll) != 0)
{
errors = new ServiceResult[length];
}
-
+
// copy existing values.
List existingValues = null;
List existingErrors = null;
@@ -179,7 +179,7 @@ public void SetQueueSize(uint queueSize, bool discardOldest, DiagnosticsMasks di
}
}
}
-
+
///
/// Adds the value to the queue.
///
@@ -194,11 +194,11 @@ public void QueueValue(DataValue value, ServiceResult error)
// check if too soon for another sample.
if (now < m_nextSampleTime)
{
- int last = m_end-1;
+ int last = m_end - 1;
if (last < 0)
{
- last = m_values.Length-1;
+ last = m_values.Length - 1;
}
// replace last value and error.
@@ -220,7 +220,7 @@ public void QueueValue(DataValue value, ServiceResult error)
if (m_samplingInterval > 0 && delta >= 0)
{
- m_nextSampleTime += ((delta/m_samplingInterval)+1)*m_samplingInterval;
+ m_nextSampleTime += ((delta / m_samplingInterval) + 1) * m_samplingInterval;
}
}
else
@@ -243,7 +243,7 @@ public bool Publish(out DataValue value, out ServiceResult error)
return Dequeue(out value, out error);
}
#endregion
-
+
#region Private Methods
///
/// Adds the value to the queue. Discards values if the queue is full.
@@ -282,7 +282,7 @@ private void Enqueue(DataValue value, ServiceResult error)
{
if (!m_discardOldest)
{
- m_overflow = m_end-1;
+ m_overflow = m_end - 1;
return;
}
@@ -306,7 +306,7 @@ private void Enqueue(DataValue value, ServiceResult error)
m_errors[next] = error;
}
- m_end = next+1;
+ m_end = next + 1;
}
///
@@ -328,7 +328,7 @@ private bool Dequeue(out DataValue value, out ServiceResult error)
value = m_values[m_start];
m_values[m_start] = null;
-
+
if (m_errors != null)
{
error = m_errors[m_start];
@@ -343,7 +343,7 @@ private bool Dequeue(out DataValue value, out ServiceResult error)
}
m_start++;
-
+
// check if queue has been emptied.
if (m_start == m_end)
{
@@ -356,7 +356,7 @@ private bool Dequeue(out DataValue value, out ServiceResult error)
{
m_start = 0;
}
-
+
return true;
}
diff --git a/Samples/Opc.Ua.Sample/Base/SampleNodeManager.cs b/Samples/Opc.Ua.Sample/Base/SampleNodeManager.cs
index cd0a03dbb..5ad6bef8a 100644
--- a/Samples/Opc.Ua.Sample/Base/SampleNodeManager.cs
+++ b/Samples/Opc.Ua.Sample/Base/SampleNodeManager.cs
@@ -31,7 +31,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Reflection;
-using Opc.Ua.Server;
+using Opc.Ua.Server;
using System.Linq;
namespace Opc.Ua.Sample
@@ -48,8 +48,8 @@ public class SampleNodeManager : INodeManager, INodeIdFactory, IDisposable
public SampleNodeManager(IServerInternal server)
{
// save a reference to the server that owns the node manager.
- m_server = server;
-
+ m_server = server;
+
// create the default context.
m_systemContext = m_server.DefaultSystemContext.Copy();
@@ -63,13 +63,13 @@ public SampleNodeManager(IServerInternal server)
m_minimumSamplingInterval = 100;
}
#endregion
-
+
#region IDisposable Members
///
/// Frees any unmanaged resources.
///
public void Dispose()
- {
+ {
Dispose(true);
GC.SuppressFinalize(this);
}
@@ -78,7 +78,7 @@ public void Dispose()
/// An overrideable version of the Dispose.
///
protected virtual void Dispose(bool disposing)
- {
+ {
if (disposing)
{
lock (m_lock)
@@ -314,11 +314,11 @@ protected void AddEncodeableNodeManagerTypes(Assembly assembly, string filter)
///
public virtual IEnumerable NamespaceUris
{
- get
- {
- return m_namespaceUris;
+ get
+ {
+ return m_namespaceUris;
}
-
+
protected set
{
if (value != null)
@@ -361,10 +361,10 @@ public virtual void CreateAddressSpace(IDictionary> ex
/// Loads a node set from a file or resource and addes them to the set of predefined nodes.
///
public virtual void LoadPredefinedNodes(
- ISystemContext context,
+ ISystemContext context,
Assembly assembly,
string resourcePath,
- IDictionary> externalReferences)
+ IDictionary> externalReferences)
{
// load the predefined nodes from an XML document.
NodeStateCollection predefinedNodes = new NodeStateCollection();
@@ -392,8 +392,8 @@ protected virtual NodeStateCollection LoadPredefinedNodes(ISystemContext context
/// Loads a node set from a file or resource and addes them to the set of predefined nodes.
///
protected virtual void LoadPredefinedNodes(
- ISystemContext context,
- IDictionary> externalReferences)
+ ISystemContext context,
+ IDictionary> externalReferences)
{
// load the predefined nodes from an XML document.
NodeStateCollection predefinedNodes = LoadPredefinedNodes(context);
@@ -413,8 +413,8 @@ protected virtual void LoadPredefinedNodes(
///
protected virtual NodeState AddBehaviourToPredefinedNode(ISystemContext context, NodeState predefinedNode)
{
- BaseObjectState passiveNode = predefinedNode as BaseObjectState;
-
+ BaseObjectState passiveNode = predefinedNode as BaseObjectState;
+
if (passiveNode == null)
{
return predefinedNode;
@@ -430,7 +430,7 @@ protected virtual void AddPredefinedNode(ISystemContext context, NodeState node)
{
NodeState activeNode = AddBehaviourToPredefinedNode(context, node);
m_predefinedNodes[activeNode.NodeId] = activeNode;
-
+
BaseTypeState type = activeNode as BaseTypeState;
if (type != null)
@@ -451,8 +451,8 @@ protected virtual void AddPredefinedNode(ISystemContext context, NodeState node)
/// Recursively indexes the node and its children.
///
protected virtual void RemovePredefinedNode(
- ISystemContext context,
- NodeState node,
+ ISystemContext context,
+ NodeState node,
List referencesToRemove)
{
m_predefinedNodes.Remove(node.NodeId);
@@ -481,7 +481,7 @@ protected virtual void RemovePredefinedNode(
{
RemovePredefinedNode(context, children[ii], referencesToRemove);
}
-
+
// remove from type table.
BaseTypeState type = node as BaseTypeState;
@@ -489,7 +489,7 @@ protected virtual void RemovePredefinedNode(
{
m_server.TypeTree.Remove(type.NodeId);
}
-
+
// remove inverse references.
List references = new List();
node.GetReferences(context, references);
@@ -579,8 +579,8 @@ protected virtual void AddReverseReferences(IDictionary
- protected virtual object GetManagerHandle(ISystemContext context, NodeId nodeId, IDictionary cache)
+ protected virtual object GetManagerHandle(ISystemContext context, NodeId nodeId, IDictionary cache)
{
lock (Lock)
{
@@ -836,15 +836,15 @@ public virtual void AddReferences(IDictionary> referen
}
}
}
-
+
///
/// This method is used to delete bi-directional references to nodes from other node managers.
///
public virtual ServiceResult DeleteReference(
- object sourceHandle,
- NodeId referenceTypeId,
- bool isInverse,
- ExpandedNodeId targetId,
+ object sourceHandle,
+ NodeId referenceTypeId,
+ bool isInverse,
+ ExpandedNodeId targetId,
bool deleteBidirectional)
{
lock (Lock)
@@ -884,8 +884,8 @@ public virtual ServiceResult DeleteReference(
/// This method validates any placeholder handle.
///
public virtual NodeMetadata GetNodeMetadata(
- OperationContext context,
- object targetHandle,
+ OperationContext context,
+ object targetHandle,
BrowseResultMask resultMask)
{
ServerSystemContext systemContext = m_systemContext.Copy(context);
@@ -897,7 +897,7 @@ public virtual NodeMetadata GetNodeMetadata(
if (target == null)
{
- return null;
+ return null;
}
// validate node.
@@ -941,7 +941,7 @@ public virtual NodeMetadata GetNodeMetadata(
}
metadata.ArrayDimensions = (IList)values[4];
-
+
if (values[5] != null && values[6] != null)
{
metadata.AccessLevel = (byte)(((byte)values[5]) & ((byte)values[6]));
@@ -979,8 +979,8 @@ public virtual NodeMetadata GetNodeMetadata(
/// The node manager can store its state information in the Data and Index properties.
///
public virtual void Browse(
- OperationContext context,
- ref ContinuationPoint continuationPoint,
+ OperationContext context,
+ ref ContinuationPoint continuationPoint,
IList references)
{
if (continuationPoint == null) throw new ArgumentNullException(nameof(continuationPoint));
@@ -1152,14 +1152,14 @@ private ReferenceDescription GetReferenceDescription(
/// browse name.
///
public virtual void TranslateBrowsePath(
- OperationContext context,
- object sourceHandle,
- RelativePathElement relativePath,
- IList targetIds,
- IList unresolvedTargetIds)
+ OperationContext context,
+ object sourceHandle,
+ RelativePathElement relativePath,
+ IList targetIds,
+ IList unresolvedTargetIds)
{
ServerSystemContext systemContext = m_systemContext.Copy(context);
- IDictionary operationCache = new NodeIdDictionary();
+ IDictionary operationCache = new NodeIdDictionary();
lock (Lock)
{
@@ -1246,25 +1246,25 @@ public virtual void TranslateBrowsePath(
}
}
}
-
+
///
/// Reads the value for the specified attribute.
///
public virtual void Read(
- OperationContext context,
- double maxAge,
- IList nodesToRead,
- IList values,
+ OperationContext context,
+ double maxAge,
+ IList nodesToRead,
+ IList values,
IList errors)
{
ServerSystemContext systemContext = m_systemContext.Copy(context);
- IDictionary operationCache = new NodeIdDictionary();
+ IDictionary operationCache = new NodeIdDictionary();
List nodesToValidate = new List();
lock (Lock)
{
for (int ii = 0; ii < nodesToRead.Count; ii++)
- {
+ {
ReadValueId nodeToRead = nodesToRead[ii];
// skip items that have already been processed.
@@ -1272,7 +1272,7 @@ public virtual void Read(
{
continue;
}
-
+
// check for valid handle.
NodeState source = GetManagerHandle(systemContext, nodeToRead.NodeId, operationCache) as NodeState;
@@ -1283,28 +1283,28 @@ public virtual void Read(
// owned by this node manager.
nodeToRead.Processed = true;
-
+
// create an initial value.
DataValue value = values[ii] = new DataValue();
-
- value.Value = null;
+
+ value.Value = null;
value.ServerTimestamp = DateTime.UtcNow;
value.SourceTimestamp = DateTime.MinValue;
- value.StatusCode = StatusCodes.Good;
+ value.StatusCode = StatusCodes.Good;
// check if the node is ready for reading.
if (source.ValidationRequired)
{
errors[ii] = StatusCodes.BadNodeIdUnknown;
-
+
// must validate node in a seperate operation.
ReadWriteOperationState operation = new ReadWriteOperationState();
-
+
operation.Source = source;
operation.Index = ii;
nodesToValidate.Add(operation);
-
+
continue;
}
@@ -1332,7 +1332,7 @@ public virtual void Read(
{
continue;
}
-
+
ReadValueId nodeToRead = nodesToRead[operation.Index];
DataValue value = values[operation.Index];
@@ -1345,8 +1345,8 @@ public virtual void Read(
value);
}
}
- }
-
+ }
+
///
/// Stores the state of a call method operation.
///
@@ -1354,8 +1354,8 @@ private struct ReadWriteOperationState
{
public NodeState Source;
public int Index;
- }
-
+ }
+
///
/// Verifies that the specified node exists.
///
@@ -1369,28 +1369,28 @@ protected virtual bool ValidateNode(ServerSystemContext context, NodeState node)
return true;
}
-
+
///
/// Reads the history for the specified nodes.
///
public virtual void HistoryRead(
- OperationContext context,
- HistoryReadDetails details,
- TimestampsToReturn timestampsToReturn,
- bool releaseContinuationPoints,
- IList nodesToRead,
- IList results,
- IList errors)
+ OperationContext context,
+ HistoryReadDetails details,
+ TimestampsToReturn timestampsToReturn,
+ bool releaseContinuationPoints,
+ IList nodesToRead,
+ IList results,
+ IList errors)
{
ServerSystemContext systemContext = m_systemContext.Copy(context);
- IDictionary operationCache = new NodeIdDictionary();
+ IDictionary operationCache = new NodeIdDictionary();
List nodesToValidate = new List();
List readsToComplete = new List();
lock (Lock)
{
for (int ii = 0; ii < nodesToRead.Count; ii++)
- {
+ {
HistoryReadValueId nodeToRead = nodesToRead[ii];
// skip items that have already been processed.
@@ -1398,7 +1398,7 @@ public virtual void HistoryRead(
{
continue;
}
-
+
// check for valid handle.
NodeState source = GetManagerHandle(systemContext, nodeToRead.NodeId, operationCache) as NodeState;
@@ -1418,11 +1418,11 @@ public virtual void HistoryRead(
errors[ii] = StatusCodes.BadHistoryOperationUnsupported;
continue;
}
-
+
results[ii] = new HistoryReadResult();
-
+
ReadWriteOperationState operation = new ReadWriteOperationState();
-
+
operation.Source = source;
operation.Index = ii;
@@ -1431,7 +1431,7 @@ public virtual void HistoryRead(
{
// must validate node in a seperate operation.
errors[ii] = StatusCodes.BadNodeIdUnknown;
- nodesToValidate.Add(operation);
+ nodesToValidate.Add(operation);
continue;
}
@@ -1473,13 +1473,13 @@ public virtual void HistoryRead(
/// Reads the history for a single node which has already been validated.
///
protected virtual ServiceResult HistoryRead(
- ISystemContext context,
- NodeState source,
- HistoryReadDetails details,
- TimestampsToReturn timestampsToReturn,
- bool releaseContinuationPoints,
- HistoryReadValueId nodesToRead,
- HistoryReadResult result)
+ ISystemContext context,
+ NodeState source,
+ HistoryReadDetails details,
+ TimestampsToReturn timestampsToReturn,
+ bool releaseContinuationPoints,
+ HistoryReadValueId nodesToRead,
+ HistoryReadResult result)
{
// check for variable.
BaseVariableState variable = source as BaseVariableState;
@@ -1542,72 +1542,72 @@ protected virtual ServiceResult HistoryRead(
nodesToRead,
result);
}
-
+
return StatusCodes.BadHistoryOperationUnsupported;
}
-
+
///
/// Reads the raw history for the variable value.
///
protected virtual ServiceResult HistoryReadRaw(
- ISystemContext context,
- BaseVariableState source,
- ReadRawModifiedDetails details,
- TimestampsToReturn timestampsToReturn,
- bool releaseContinuationPoints,
- HistoryReadValueId nodeToRead,
- HistoryReadResult result)
+ ISystemContext context,
+ BaseVariableState source,
+ ReadRawModifiedDetails details,
+ TimestampsToReturn timestampsToReturn,
+ bool releaseContinuationPoints,
+ HistoryReadValueId nodeToRead,
+ HistoryReadResult result)
{
return StatusCodes.BadHistoryOperationUnsupported;
}
-
+
///
/// Reads the processed history for the variable value.
///
protected virtual ServiceResult HistoryReadProcessed(
- ISystemContext context,
- BaseVariableState source,
- ReadProcessedDetails details,
- TimestampsToReturn timestampsToReturn,
- bool releaseContinuationPoints,
- HistoryReadValueId nodeToRead,
- HistoryReadResult result)
+ ISystemContext context,
+ BaseVariableState source,
+ ReadProcessedDetails details,
+ TimestampsToReturn timestampsToReturn,
+ bool releaseContinuationPoints,
+ HistoryReadValueId nodeToRead,
+ HistoryReadResult result)
{
return StatusCodes.BadHistoryOperationUnsupported;
}
-
+
///
/// Reads the history for the variable value.
///
protected virtual ServiceResult HistoryReadAtTime(
- ISystemContext context,
- BaseVariableState source,
- ReadAtTimeDetails details,
- TimestampsToReturn timestampsToReturn,
- bool releaseContinuationPoints,
- HistoryReadValueId nodeToRead,
- HistoryReadResult result)
+ ISystemContext context,
+ BaseVariableState source,
+ ReadAtTimeDetails details,
+ TimestampsToReturn timestampsToReturn,
+ bool releaseContinuationPoints,
+ HistoryReadValueId nodeToRead,
+ HistoryReadResult result)
{
return StatusCodes.BadHistoryOperationUnsupported;
}
-
-
+
+
///
/// Writes the value for the specified attributes.
///
public virtual void Write(
- OperationContext context,
- IList nodesToWrite,
+ OperationContext context,
+ IList nodesToWrite,
IList errors)
{
ServerSystemContext systemContext = m_systemContext.Copy(context);
- IDictionary operationCache = new NodeIdDictionary();
+ IDictionary operationCache = new NodeIdDictionary();
List nodesToValidate = new List();
lock (Lock)
{
for (int ii = 0; ii < nodesToWrite.Count; ii++)
- {
+ {
WriteValue nodeToWrite = nodesToWrite[ii];
// skip items that have already been processed.
@@ -1615,7 +1615,7 @@ public virtual void Write(
{
continue;
}
-
+
// check for valid handle.
NodeState source = GetManagerHandle(systemContext, nodeToWrite.NodeId, operationCache) as NodeState;
@@ -1633,20 +1633,20 @@ public virtual void Write(
errors[ii] = StatusCodes.BadWriteNotSupported;
continue;
}
-
+
// check if the node is ready for reading.
if (source.ValidationRequired)
{
errors[ii] = StatusCodes.BadNodeIdUnknown;
-
+
// must validate node in a seperate operation.
ReadWriteOperationState operation = new ReadWriteOperationState();
-
+
operation.Source = source;
operation.Index = ii;
nodesToValidate.Add(operation);
-
+
continue;
}
@@ -1676,7 +1676,7 @@ public virtual void Write(
{
continue;
}
-
+
WriteValue nodeToWrite = nodesToWrite[operation.Index];
// write the attribute value.
@@ -1691,25 +1691,25 @@ public virtual void Write(
}
}
}
-
+
///
/// Updates the history for the specified nodes.
///
public virtual void HistoryUpdate(
- OperationContext context,
- Type detailsType,
- IList nodesToUpdate,
- IList results,
- IList errors)
+ OperationContext context,
+ Type detailsType,
+ IList nodesToUpdate,
+ IList results,
+ IList errors)
{
ServerSystemContext systemContext = m_systemContext.Copy(context);
- IDictionary operationCache = new NodeIdDictionary();
+ IDictionary operationCache = new NodeIdDictionary();
List nodesToValidate = new List();
lock (Lock)
{
for (int ii = 0; ii < nodesToUpdate.Count; ii++)
- {
+ {
HistoryUpdateDetails nodeToUpdate = nodesToUpdate[ii];
// skip items that have already been processed.
@@ -1717,7 +1717,7 @@ public virtual void HistoryUpdate(
{
continue;
}
-
+
// check for valid handle.
NodeState source = GetManagerHandle(systemContext, nodeToUpdate.NodeId, operationCache) as NodeState;
@@ -1728,20 +1728,20 @@ public virtual void HistoryUpdate(
// owned by this node manager.
nodeToUpdate.Processed = true;
-
+
// check if the node is ready for reading.
if (source.ValidationRequired)
{
errors[ii] = StatusCodes.BadNodeIdUnknown;
-
+
// must validate node in a seperate operation.
ReadWriteOperationState operation = new ReadWriteOperationState();
-
+
operation.Source = source;
operation.Index = ii;
nodesToValidate.Add(operation);
-
+
continue;
}
@@ -1764,7 +1764,7 @@ public virtual void HistoryUpdate(
{
continue;
}
-
+
// historical data not available.
errors[ii] = StatusCodes.BadHistoryOperationUnsupported;
}
@@ -1775,19 +1775,19 @@ public virtual void HistoryUpdate(
/// Calls a method on the specified nodes.
///
public virtual void Call(
- OperationContext context,
- IList methodsToCall,
- IList results,
- IList errors)
+ OperationContext context,
+ IList methodsToCall,
+ IList results,
+ IList errors)
{
ServerSystemContext systemContext = m_systemContext.Copy(context);
- IDictionary operationCache = new NodeIdDictionary();
+ IDictionary operationCache = new NodeIdDictionary();
List nodesToValidate = new List();
lock (Lock)
{
for (int ii = 0; ii < methodsToCall.Count; ii++)
- {
+ {
CallMethodRequest methodToCall = methodsToCall[ii];
// skip items that have already been processed.
@@ -1795,7 +1795,7 @@ public virtual void Call(
{
continue;
}
-
+
// check for valid handle.
NodeState source = GetManagerHandle(systemContext, methodToCall.ObjectId, operationCache) as NodeState;
@@ -1831,10 +1831,10 @@ public virtual void Call(
if (source.ValidationRequired)
{
errors[ii] = StatusCodes.BadNodeIdUnknown;
-
+
// must validate node in a seperate operation.
CallOperationState operation = new CallOperationState();
-
+
operation.Source = source;
operation.Method = method;
operation.Index = ii;
@@ -1843,7 +1843,7 @@ public virtual void Call(
continue;
}
-
+
// call the method.
errors[ii] = Call(
systemContext,
@@ -1852,7 +1852,7 @@ public virtual void Call(
method,
result);
}
-
+
// check for nothing to do.
if (nodesToValidate.Count == 0)
{
@@ -1869,7 +1869,7 @@ public virtual void Call(
{
continue;
}
-
+
// call the method.
CallMethodResult result = results[operation.Index];
@@ -1882,7 +1882,7 @@ public virtual void Call(
}
}
}
-
+
///
/// Stores the state of a call method operation.
///
@@ -1892,7 +1892,7 @@ private struct CallOperationState
public MethodState Method;
public int Index;
}
-
+
///
/// Calls a method on an object.
///
@@ -1929,7 +1929,7 @@ protected virtual ServiceResult Call(
if (argumentError != null)
{
result.InputArgumentResults.Add(argumentError.StatusCode);
-
+
if (ServiceResult.IsBad(argumentError))
{
argumentsValid = false;
@@ -1980,11 +1980,11 @@ protected virtual ServiceResult Call(
/// the notifier hierarchy.
///
public virtual ServiceResult SubscribeToEvents(
- OperationContext context,
- object sourceId,
- uint subscriptionId,
- IEventMonitoredItem monitoredItem,
- bool unsubscribe)
+ OperationContext context,
+ object sourceId,
+ uint subscriptionId,
+ IEventMonitoredItem monitoredItem,
+ bool unsubscribe)
{
ServerSystemContext systemContext = m_systemContext.Copy(context);
@@ -2036,7 +2036,7 @@ public virtual ServiceResult SubscribeToEvents(
return ServiceResult.Good;
}
}
-
+
///
/// Subscribes or unsubscribes to events produced by all event sources.
///
@@ -2045,10 +2045,10 @@ public virtual ServiceResult SubscribeToEvents(
/// manager must start/stop reporting events for all objects that it manages.
///
public virtual ServiceResult SubscribeToAllEvents(
- OperationContext context,
- uint subscriptionId,
- IEventMonitoredItem monitoredItem,
- bool unsubscribe)
+ OperationContext context,
+ uint subscriptionId,
+ IEventMonitoredItem monitoredItem,
+ bool unsubscribe)
{
ServerSystemContext systemContext = m_systemContext.Copy(context);
@@ -2072,10 +2072,10 @@ public virtual ServiceResult SubscribeToAllEvents(
/// Subscribes/unsubscribes to all events produced by the specified node.
///
protected void SubscribeToAllEvents(
- ISystemContext systemContext,
- IEventMonitoredItem monitoredItem,
- bool unsubscribe,
- NodeState source)
+ ISystemContext systemContext,
+ IEventMonitoredItem monitoredItem,
+ bool unsubscribe,
+ NodeState source)
{
MonitoredNode monitoredNode = source.Handle as MonitoredNode;
@@ -2135,7 +2135,7 @@ protected virtual void OnUnsubscribeToEvents(
/// The node manager must create a refresh event for each condition monitored by the subscription.
///
public virtual ServiceResult ConditionRefresh(
- OperationContext context,
+ OperationContext context,
IList monitoredItems)
{
ServerSystemContext systemContext = m_systemContext.Copy(context);
@@ -2150,7 +2150,7 @@ public virtual ServiceResult ConditionRefresh(
{
continue;
}
-
+
// check for global subscription.
if (monitoredItem.MonitoringAllEvents)
{
@@ -2170,20 +2170,20 @@ public virtual ServiceResult ConditionRefresh(
// check for subscription to local node.
else
{
- NodeState source = IsHandleInNamespace(monitoredItem.ManagerHandle );
+ NodeState source = IsHandleInNamespace(monitoredItem.ManagerHandle);
if (source == null)
{
continue;
}
-
+
MonitoredNode monitoredNode = source.Handle as MonitoredNode;
-
+
if (monitoredNode == null)
{
continue;
}
-
+
monitoredNode.ConditionRefresh(systemContext, monitoredItem);
}
}
@@ -2199,25 +2199,25 @@ public virtual ServiceResult ConditionRefresh(
/// This method only handles data change subscriptions. Event subscriptions are created by the SDK.
///
public virtual void CreateMonitoredItems(
- OperationContext context,
- uint subscriptionId,
- double publishingInterval,
- TimestampsToReturn timestampsToReturn,
- IList itemsToCreate,
- IList errors,
- IList filterErrors,
- IList monitoredItems,
- bool createDurable,
- ref long globalIdCounter)
+ OperationContext context,
+ uint subscriptionId,
+ double publishingInterval,
+ TimestampsToReturn timestampsToReturn,
+ IList itemsToCreate,
+ IList errors,
+ IList filterErrors,
+ IList monitoredItems,
+ bool createDurable,
+ ref long globalIdCounter)
{
ServerSystemContext systemContext = m_systemContext.Copy(context);
- IDictionary operationCache = new NodeIdDictionary();
+ IDictionary operationCache = new NodeIdDictionary();
List |