Skip to content

Commit 601cabf

Browse files
authored
Replace all use of object in code and API with Variant (#3550)
1 parent f66ceff commit 601cabf

File tree

117 files changed

+4503
-9523
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+4503
-9523
lines changed

.azurepipelines/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,8 @@ jobs:
9292
command: test
9393
projects: $(file)
9494
arguments: '--no-restore ${{ variables.DotCliCommandline }} --configuration ${{ parameters.configuration }}'
95+
- task: PublishBuildArtifacts@1
96+
displayName: 'Publish Fuzzing artifacts on failure'
97+
condition: and(failed(), ne(variables['fuzzingartifacts.secureFilePath'], ''))
98+
inputs:
99+
PathtoPublish: '$(Agent.TempDirectory)/FuzzingArtifacts.zip'

.azurepipelines/testcc.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,8 @@ jobs:
106106
COMMIT_UUID: '$(Build.SourceVersion)'
107107
continueOnError: true
108108
displayName: 'Upload to Codacy'
109+
- task: PublishBuildArtifacts@1
110+
displayName: 'Publish Fuzzing artifacts on failure'
111+
condition: and(failed(), ne(variables['fuzzingartifacts.secureFilePath'], ''))
112+
inputs:
113+
PathtoPublish: '$(Agent.TempDirectory)/FuzzingArtifacts.zip'

Applications/ConsoleReferenceClient/ClientSamples.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -307,23 +307,21 @@ public async Task CallMethodAsync(ISession session, CancellationToken ct = defau
307307

308308
// Define the method parameters
309309
// Input argument requires a Float and an UInt32 value
310-
object[] inputArguments = [(float)10.5, (uint)10];
311-
IList<object> outputArguments = null;
312-
313310
// Invoke Call service
314311
Console.WriteLine($"Calling UAMethod for node {methodId} ...");
315-
outputArguments = await session.CallAsync(
312+
VariantCollection outputArguments = await session.CallAsync(
316313
objectId,
317314
methodId,
318315
ct,
319-
inputArguments).ConfigureAwait(false);
316+
(float)10.5,
317+
(uint)10).ConfigureAwait(false);
320318

321319
// Display results
322320
Console.WriteLine($"Method call returned {outputArguments.Count} output argument(s):");
323321

324-
foreach (object outputArgument in outputArguments)
322+
foreach (Variant outputArgument in outputArguments)
325323
{
326-
Console.WriteLine($" OutputValue = {outputArgument}");
324+
Console.WriteLine($" OutputValue = {outputArgument.Value}");
327325
}
328326
}
329327
catch (Exception ex)
@@ -356,23 +354,20 @@ public async Task EnableEventsAsync(
356354

357355
// Define the method parameters
358356
// Input argument requires a Float and an UInt32 value
359-
object[] inputArguments = [timeToRun];
360-
IList<object> outputArguments = null;
361-
362357
// Invoke Call service
363358
Console.WriteLine($"Calling UAMethod for node {methodId} ...");
364-
outputArguments = await session.CallAsync(
359+
VariantCollection outputArguments = await session.CallAsync(
365360
objectId,
366361
methodId,
367362
ct,
368-
inputArguments).ConfigureAwait(false);
363+
timeToRun).ConfigureAwait(false);
369364

370365
// Display results
371366
Console.WriteLine($"Method call returned {outputArguments.Count} output argument(s):");
372367

373-
foreach (object outputArgument in outputArguments)
368+
foreach (Variant outputArgument in outputArguments)
374369
{
375-
Console.WriteLine($" OutputValue = {outputArgument}");
370+
Console.WriteLine($" OutputValue = {outputArgument.Value}");
376371
}
377372
}
378373
catch (Exception ex)

Applications/ConsoleReferenceSubscriber/Program.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,7 @@ private static PubSubConfigurationDataType CreateSubscriberConfiguration_UdpUadp
446446
TargetNodeId = new NodeId(fieldMetaData.Name, NamespaceIndexSimple),
447447
AttributeId = Attributes.Value,
448448
OverrideValueHandling = OverrideValueHandling.OverrideValue,
449-
OverrideValue = new Variant(
450-
TypeInfo.GetDefaultValue(fieldMetaData.DataType, ValueRanks.Scalar)
451-
)
449+
OverrideValue = TypeInfo.GetDefaultVariantValue(fieldMetaData.DataType, ValueRanks.Scalar)
452450
}
453451
);
454452
}
@@ -501,9 +499,7 @@ private static PubSubConfigurationDataType CreateSubscriberConfiguration_UdpUadp
501499
TargetNodeId = new NodeId(fieldMetaData.Name, NamespaceIndexAllTypes),
502500
AttributeId = Attributes.Value,
503501
OverrideValueHandling = OverrideValueHandling.OverrideValue,
504-
OverrideValue = new Variant(
505-
TypeInfo.GetDefaultValue(fieldMetaData.DataType, ValueRanks.Scalar)
506-
)
502+
OverrideValue = TypeInfo.GetDefaultVariantValue(fieldMetaData.DataType, ValueRanks.Scalar)
507503
}
508504
);
509505
}
@@ -610,9 +606,7 @@ private static PubSubConfigurationDataType CreateSubscriberConfiguration_MqttJso
610606
TargetNodeId = new NodeId(fieldMetaData.Name, NamespaceIndexSimple),
611607
AttributeId = Attributes.Value,
612608
OverrideValueHandling = OverrideValueHandling.OverrideValue,
613-
OverrideValue = new Variant(
614-
TypeInfo.GetDefaultValue(fieldMetaData.DataType, ValueRanks.Scalar)
615-
)
609+
OverrideValue = TypeInfo.GetDefaultVariantValue(fieldMetaData.DataType, ValueRanks.Scalar)
616610
}
617611
);
618612
}
@@ -673,9 +667,7 @@ private static PubSubConfigurationDataType CreateSubscriberConfiguration_MqttJso
673667
TargetNodeId = new NodeId(fieldMetaData.Name, NamespaceIndexAllTypes),
674668
AttributeId = Attributes.Value,
675669
OverrideValueHandling = OverrideValueHandling.OverrideValue,
676-
OverrideValue = new Variant(
677-
TypeInfo.GetDefaultValue(fieldMetaData.DataType, ValueRanks.Scalar)
678-
)
670+
OverrideValue = TypeInfo.GetDefaultVariantValue(fieldMetaData.DataType, ValueRanks.Scalar)
679671
}
680672
);
681673
}
@@ -782,9 +774,7 @@ private static PubSubConfigurationDataType CreateSubscriberConfiguration_MqttUad
782774
TargetNodeId = new NodeId(fieldMetaData.Name, NamespaceIndexSimple),
783775
AttributeId = Attributes.Value,
784776
OverrideValueHandling = OverrideValueHandling.OverrideValue,
785-
OverrideValue = new Variant(
786-
TypeInfo.GetDefaultValue(fieldMetaData.DataType, ValueRanks.Scalar)
787-
)
777+
OverrideValue = TypeInfo.GetDefaultVariantValue(fieldMetaData.DataType, ValueRanks.Scalar)
788778
}
789779
);
790780
}
@@ -840,9 +830,7 @@ private static PubSubConfigurationDataType CreateSubscriberConfiguration_MqttUad
840830
TargetNodeId = new NodeId(fieldMetaData.Name, NamespaceIndexAllTypes),
841831
AttributeId = Attributes.Value,
842832
OverrideValueHandling = OverrideValueHandling.OverrideValue,
843-
OverrideValue = new Variant(
844-
TypeInfo.GetDefaultValue(fieldMetaData.DataType, ValueRanks.Scalar)
845-
)
833+
OverrideValue = TypeInfo.GetDefaultVariantValue(fieldMetaData.DataType, ValueRanks.Scalar)
846834
}
847835
);
848836
}

Applications/Quickstarts.Servers/Alarms/AlarmHolders/AlarmHolder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public ServiceResult OnWriteAlarmTrigger(
239239
NodeState node,
240240
NumericRange indexRange,
241241
QualifiedName dataEncoding,
242-
ref object value,
242+
ref Variant value,
243243
ref StatusCode statusCode,
244244
ref DateTime timestamp)
245245
{

Applications/Quickstarts.Servers/Alarms/AlarmNodeManager.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ private void DoSimulation(object state)
347347
public ServiceResult OnStart(
348348
ISystemContext context,
349349
NodeState node,
350-
IList<object> inputArguments,
351-
IList<object> outputArguments)
350+
VariantCollection inputArguments,
351+
VariantCollection outputArguments)
352352
{
353353
// all arguments must be provided.
354354
uint seconds;
@@ -409,8 +409,8 @@ public ServiceResult OnStart(
409409
public ServiceResult OnStartBranch(
410410
ISystemContext context,
411411
NodeState node,
412-
IList<object> inputArguments,
413-
IList<object> outputArguments)
412+
VariantCollection inputArguments,
413+
VariantCollection outputArguments)
414414
{
415415
// all arguments must be provided.
416416
uint seconds;
@@ -473,8 +473,8 @@ public ServiceResult OnStartBranch(
473473
public ServiceResult OnEnd(
474474
ISystemContext context,
475475
NodeState node,
476-
IList<object> inputArguments,
477-
IList<object> outputArguments)
476+
VariantCollection inputArguments,
477+
VariantCollection outputArguments)
478478
{
479479
ServiceResult result = ServiceResult.Good;
480480

@@ -520,7 +520,7 @@ public ServiceResult OnWriteAlarmTrigger(
520520
NodeState node,
521521
NumericRange indexRange,
522522
QualifiedName dataEncoding,
523-
ref object value,
523+
ref Variant value,
524524
ref StatusCode statusCode,
525525
ref DateTime timestamp)
526526
{

Applications/Quickstarts.Servers/Boiler/BoilerNodeManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ private void CreateBoiler(ISystemContext context, int unitNumber)
142142

143143
// Autostart boiler simulation state machine
144144
MethodState start = boiler.Simulation.Start;
145-
IList<Variant> inputArguments = [];
146-
IList<Variant> outputArguments = [];
145+
VariantCollection inputArguments = [];
146+
VariantCollection outputArguments = [];
147147
var errors = new List<ServiceResult>();
148148
start.Call(context, boiler.NodeId, inputArguments, errors, outputArguments);
149149
}
@@ -214,8 +214,8 @@ protected override NodeState AddBehaviourToPredefinedNode(
214214

215215
// Autostart boiler simulation state machine
216216
MethodState start = activeNode.Simulation.Start;
217-
IList<Variant> inputArguments = [];
218-
IList<Variant> outputArguments = [];
217+
VariantCollection inputArguments = [];
218+
VariantCollection outputArguments = [];
219219
var errors = new List<ServiceResult>();
220220
start.Call(context, activeNode.NodeId, inputArguments, errors, outputArguments);
221221

Applications/Quickstarts.Servers/Boiler/BoilerState.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
* ======================================================================*/
2929

3030
using System;
31-
using System.Collections.Generic;
3231
using System.Threading;
3332
using Microsoft.Extensions.Logging;
3433
using Opc.Ua;
@@ -74,8 +73,8 @@ private ServiceResult OnControlSimulation(
7473
StateMachineState machine,
7574
uint transitionId,
7675
uint causeId,
77-
IList<object> inputArguments,
78-
IList<object> outputArguments)
76+
VariantCollection inputArguments,
77+
VariantCollection outputArguments)
7978
{
8079
switch (causeId)
8180
{

Applications/Quickstarts.Servers/MemoryBuffer/MemoryBufferState.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public ServiceResult ReadTagValue(
200200
NodeState node,
201201
NumericRange indexRange,
202202
QualifiedName dataEncoding,
203-
ref object value,
203+
ref Variant value,
204204
ref StatusCode statusCode,
205205
ref DateTime timestamp)
206206
{
@@ -233,7 +233,7 @@ public ServiceResult ReadTagValue(
233233
return StatusCodes.BadOutOfService;
234234
}
235235

236-
value = GetValueAtOffset(offset).AsBoxedObject();
236+
value = GetValueAtOffset(offset);
237237
}
238238

239239
statusCode = StatusCodes.Good;
@@ -251,7 +251,7 @@ public ServiceResult WriteTagValue(
251251
NodeState node,
252252
NumericRange indexRange,
253253
QualifiedName dataEncoding,
254-
ref object value,
254+
ref Variant value,
255255
ref StatusCode statusCode,
256256
ref DateTime timestamp)
257257
{
@@ -301,26 +301,22 @@ public ServiceResult WriteTagValue(
301301
{
302302
case BuiltInType.UInt32:
303303
{
304-
uint? valueToWrite = value as uint?;
305-
306-
if (valueToWrite == null)
304+
if (!value.TryGet(out uint valueToWrite))
307305
{
308306
return StatusCodes.BadTypeMismatch;
309307
}
310308

311-
bytes = BitConverter.GetBytes(valueToWrite.Value);
309+
bytes = BitConverter.GetBytes(valueToWrite);
312310
break;
313311
}
314312
case BuiltInType.Double:
315313
{
316-
double? valueToWrite = value as double?;
317-
318-
if (valueToWrite == null)
314+
if (!value.TryGet(out double valueToWrite))
319315
{
320316
return StatusCodes.BadTypeMismatch;
321317
}
322318

323-
bytes = BitConverter.GetBytes(valueToWrite.Value);
319+
bytes = BitConverter.GetBytes(valueToWrite);
324320
break;
325321
}
326322
case >= BuiltInType.Null and <= BuiltInType.Enumeration:

Applications/Quickstarts.Servers/Quickstarts.Servers.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
<Import Project="..\..\Tools\Opc.Ua.SourceGeneration\OPCFoundation.Opc.Ua.SourceGeneration.props" />
3131
<PropertyGroup>
3232
<ModelSourceGeneratorUseAllowSubtypes>true</ModelSourceGeneratorUseAllowSubtypes>
33-
<ModelSourceGeneratorEmbedNodeSet2Xml>true</ModelSourceGeneratorEmbedNodeSet2Xml>
3433
</PropertyGroup>
3534
<ItemGroup>
3635
<None Remove="Boiler\Generated\Boiler.NodeIds.csv" />

0 commit comments

Comments
 (0)