Skip to content

Commit 18a061c

Browse files
committed
more fixes
1 parent 064a580 commit 18a061c

File tree

12 files changed

+232
-210
lines changed

12 files changed

+232
-210
lines changed

Samples/Controls.Net4/Common/AttributeListCtrl.cs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
using System.ComponentModel;
3333
using System.Data;
3434
using System.Drawing;
35+
using System.Reflection;
3536
using System.Text;
37+
using System.Threading.Tasks;
3638
using System.Windows.Forms;
37-
using System.Reflection;
38-
3939
using Opc.Ua.Client;
4040
using Opc.Ua.Client.Controls;
41-
using System.Threading.Tasks;
41+
using static System.Net.Mime.MediaTypeNames;
4242

4343
namespace Opc.Ua.Sample.Controls
4444
{
@@ -302,7 +302,7 @@ private async Task AddReferencesAsync(NodeId referenceTypeId, BrowseDirection br
302302
/// <summary>
303303
/// Formats the value of an attribute.
304304
/// </summary>
305-
private string FormatAttributeValue(uint attributeId, object value)
305+
private async Task<string> FormatAttributeValueAsync(uint attributeId, object value)
306306
{
307307
switch (attributeId)
308308
{
@@ -322,7 +322,7 @@ private string FormatAttributeValue(uint attributeId, object value)
322322

323323
if (datatypeId != null)
324324
{
325-
INode datatype = m_session.NodeCache.Find(datatypeId);
325+
INode datatype = await m_session.NodeCache.FindAsync(datatypeId);
326326

327327
if (datatype != null)
328328
{
@@ -519,39 +519,46 @@ protected override void EnableMenuItems(ListViewItem clickedItem)
519519
}
520520

521521
/// <see cref="BaseListCtrl.UpdateItem" />
522-
protected override void UpdateItem(ListViewItem listItem, object item)
522+
protected override async void UpdateItem(ListViewItem listItem, object item)
523523
{
524-
NodeField field = item as NodeField;
525-
526-
if (field == null)
524+
try
527525
{
528-
base.UpdateItem(listItem, item);
529-
return;
530-
}
526+
NodeField field = item as NodeField;
531527

532-
Array array = field.Value as Array;
528+
if (field == null)
529+
{
530+
base.UpdateItem(listItem, item);
531+
return;
532+
}
533533

534-
listItem.SubItems[0].Text = String.Format("{0}", field.Name);
534+
Array array = field.Value as Array;
535535

536-
if (array == null)
537-
{
538-
if (field.ValueId != null)
536+
listItem.SubItems[0].Text = String.Format("{0}", field.Name);
537+
538+
if (array == null)
539539
{
540-
listItem.SubItems[1].Text = FormatAttributeValue(field.ValueId.AttributeId, field.Value);
540+
if (field.ValueId != null)
541+
{
542+
listItem.SubItems[1].Text = await FormatAttributeValueAsync(field.ValueId.AttributeId, field.Value);
543+
}
544+
else
545+
{
546+
listItem.SubItems[1].Text = String.Format("{0}", field.Value);
547+
}
541548
}
542549
else
543550
{
544-
listItem.SubItems[1].Text = String.Format("{0}", field.Value);
551+
listItem.SubItems[1].Text = String.Format("{0}[{1}]", field.Value.GetType().GetElementType().Name, array.Length);
545552
}
553+
554+
listItem.SubItems[2].Text = String.Format("{0}", field.StatusCode);
555+
556+
listItem.Tag = item;
546557
}
547-
else
558+
catch (Exception exception)
548559
{
549-
listItem.SubItems[1].Text = String.Format("{0}[{1}]", field.Value.GetType().GetElementType().Name, array.Length);
560+
GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
550561
}
551-
552-
listItem.SubItems[2].Text = String.Format("{0}", field.StatusCode);
553-
554-
listItem.Tag = item;
555562
}
556563
#endregion
557564

Samples/Controls.Net4/Common/DataValueListCtrl.cs

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
using Opc.Ua.Client;
4040
using Opc.Ua.Client.Controls;
41+
using System.Threading.Tasks;
4142

4243
namespace Opc.Ua.Sample.Controls
4344
{
@@ -46,8 +47,8 @@ public partial class DataValueListCtrl : Opc.Ua.Client.Controls.BaseListCtrl
4647
#region Constructors
4748
public DataValueListCtrl()
4849
{
49-
InitializeComponent();
50-
SetColumns(m_ColumnNames);
50+
InitializeComponent();
51+
SetColumns(m_ColumnNames);
5152
}
5253
#endregion
5354

@@ -59,24 +60,24 @@ public DataValueListCtrl()
5960
/// The columns to display in the control.
6061
/// </summary>
6162
private readonly object[][] m_ColumnNames = new object[][]
62-
{
63-
new object[] { "Node", HorizontalAlignment.Left, null },
64-
new object[] { "Attribute", HorizontalAlignment.Left, "Value", },
65-
new object[] { "Value", HorizontalAlignment.Left, "", 200 },
66-
new object[] { "Status", HorizontalAlignment.Left, "" },
67-
new object[] { "Source Time", HorizontalAlignment.Left, "" },
68-
new object[] { "Server Time", HorizontalAlignment.Left, "" },
69-
};
70-
#endregion
63+
{
64+
new object[] { "Node", HorizontalAlignment.Left, null },
65+
new object[] { "Attribute", HorizontalAlignment.Left, "Value", },
66+
new object[] { "Value", HorizontalAlignment.Left, "", 200 },
67+
new object[] { "Status", HorizontalAlignment.Left, "" },
68+
new object[] { "Source Time", HorizontalAlignment.Left, "" },
69+
new object[] { "Server Time", HorizontalAlignment.Left, "" },
70+
};
71+
#endregion
7172

7273
#region Public Interface
7374
/// <summary>
7475
/// The control used to display the details of a value.
7576
/// </summary>
7677
public DataListCtrl DataListCtrl
7778
{
78-
get { return m_DataListCtrl; }
79-
set { m_DataListCtrl = value; }
79+
get { return m_DataListCtrl; }
80+
set { m_DataListCtrl = value; }
8081
}
8182

8283
/// <summary>
@@ -91,25 +92,25 @@ public void Clear()
9192
/// <summary>
9293
/// Sets the nodes in the control.
9394
/// </summary>
94-
public void Initialize(
95-
Session session,
96-
ReadValueIdCollection valueIds,
97-
DataValueCollection values,
98-
List<ServiceResult> results)
95+
public async Task InitializeAsync(
96+
Session session,
97+
ReadValueIdCollection valueIds,
98+
DataValueCollection values,
99+
List<ServiceResult> results)
99100
{
100101
if (session == null) throw new ArgumentNullException("session");
101-
102+
102103
Clear();
103-
104-
m_session = session;
104+
105+
m_session = session;
105106

106107
if (valueIds != null)
107108
{
108109
for (int ii = 0; ii < valueIds.Count; ii++)
109110
{
110111
ValueItem item = new ValueItem();
111112

112-
item.Node = m_session.NodeCache.Find(valueIds[ii].NodeId) as Node;
113+
item.Node = await m_session.NodeCache.FindAsync(valueIds[ii].NodeId) as Node;
113114
item.AttributeId = valueIds[ii].AttributeId;
114115

115116
if (values != null && ii < values.Count)
@@ -132,26 +133,26 @@ public void Initialize(
132133
/// <summary>
133134
/// Sets the nodes in the control.
134135
/// </summary>
135-
public void Initialize(
136-
Session session,
137-
WriteValueCollection values,
138-
List<ServiceResult> results)
136+
public async Task InitializeAsync(
137+
Session session,
138+
WriteValueCollection values,
139+
List<ServiceResult> results)
139140
{
140141
if (session == null) throw new ArgumentNullException("session");
141-
142+
142143
Clear();
143-
144+
144145
m_session = session;
145-
146+
146147
if (values != null)
147148
{
148149
for (int ii = 0; ii < values.Count; ii++)
149150
{
150151
ValueItem item = new ValueItem();
151152

152-
item.Node = m_session.NodeCache.Find(values[ii].NodeId) as Node;
153+
item.Node = await m_session.NodeCache.FindAsync(values[ii].NodeId) as Node;
153154
item.AttributeId = values[ii].AttributeId;
154-
item.Value = values[ii].Value;
155+
item.Value = values[ii].Value;
155156

156157
if (results != null && ii < results.Count)
157158
{
@@ -164,35 +165,35 @@ public void Initialize(
164165

165166
AdjustColumns();
166167
}
167-
#endregion
168-
168+
#endregion
169+
169170
#region NodeField Class
170171
/// <summary>
171172
/// A field associated with a node.
172173
/// </summary>
173174
private class ValueItem
174-
{
175+
{
175176
public Node Node;
176177
public uint AttributeId;
177178
public DataValue Value;
178179
public ServiceResult Result;
179180
}
180-
#endregion
181+
#endregion
181182

182183
#region Private Methods
183-
#endregion
184-
184+
#endregion
185+
185186
#region Overridden Methods
186187
/// <see cref="BaseListCtrl.UpdateItem" />
187188
protected override void UpdateItem(ListViewItem listItem, object item)
188189
{
189-
ValueItem dataValue = item as ValueItem;
190+
ValueItem dataValue = item as ValueItem;
190191

191-
if (dataValue == null)
192-
{
193-
base.UpdateItem(listItem, item);
194-
return;
195-
}
192+
if (dataValue == null)
193+
{
194+
base.UpdateItem(listItem, item);
195+
return;
196+
}
196197

197198
listItem.SubItems[0].Text = String.Format("{0}", dataValue.Node);
198199
listItem.SubItems[1].Text = Attributes.GetBrowseName(dataValue.AttributeId);
@@ -218,12 +219,12 @@ protected override void UpdateItem(ListViewItem listItem, object item)
218219

219220
if (dataValue.Result != null)
220221
{
221-
listItem.SubItems[3].Text =String.Format("{0}", dataValue.Result);
222+
listItem.SubItems[3].Text = String.Format("{0}", dataValue.Result);
222223
}
223224

224-
listItem.Tag = item;
225+
listItem.Tag = item;
225226
}
226-
227+
227228
/// <see cref="BaseListCtrl.SelectItems" />
228229
protected override void SelectItems()
229230
{

0 commit comments

Comments
 (0)