Skip to content

Commit c5adced

Browse files
committed
Renamed events to not use "Async" as postfix andymore, reworked events to handle mutiple metrics at once (Fixes #73).
1 parent f8af191 commit c5adced

13 files changed

+149
-178
lines changed

src/SparkplugNet.Examples/Program.cs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,18 @@ private static async Task RunVersionAApplication()
149149
Log.Information("Application started...");
150150

151151
// Handles the application's connected and disconnected events.
152-
application.ConnectedAsync += OnApplicationVersionAConnected;
153-
application.DisconnectedAsync += OnApplicationVersionADisconnected;
152+
application.Connected += OnApplicationVersionAConnected;
153+
application.Disconnected += OnApplicationVersionADisconnected;
154154

155155
// Handles the application's device related events.
156-
application.DeviceBirthReceivedAsync += OnApplicationVersionADeviceBirthReceived;
157-
application.DeviceDataReceivedAsync += OnApplicationVersionADeviceDataReceived;
158-
application.DeviceDeathReceivedAsync += OnApplicationVersionADeviceDeathReceived;
156+
application.DeviceBirthReceived += OnApplicationVersionADeviceBirthReceived;
157+
application.DeviceDataReceived += OnApplicationVersionADeviceDataReceived;
158+
application.DeviceDeathReceived += OnApplicationVersionADeviceDeathReceived;
159159

160160
// Handles the application's node related events.
161-
application.NodeBirthReceivedAsync += OnApplicationVersionANodeBirthReceived;
162-
application.NodeDataReceivedAsync += OnApplicationVersionANodeDataReceived;
163-
application.NodeDeathReceivedAsync += OnApplicationVersionANodeDeathReceived;
161+
application.NodeBirthReceived += OnApplicationVersionANodeBirthReceived;
162+
application.NodeDataReceived += OnApplicationVersionANodeDataReceived;
163+
application.NodeDeathReceived += OnApplicationVersionANodeDeathReceived;
164164

165165
// Publish node commands.
166166
Log.Information("Publishing a node command ...");
@@ -226,19 +226,19 @@ private static async Task RunVersionANode()
226226
var isApplicationConnected = node.IsConnected;
227227

228228
// Handles the node's connected and disconnected events.
229-
node.ConnectedAsync += OnVersionANodeConnected;
230-
node.DisconnectedAsync += OnVersionANodeDisconnected;
229+
node.Connected += OnVersionANodeConnected;
230+
node.Disconnected += OnVersionANodeDisconnected;
231231

232232
// Handles the node's device related events.
233-
node.DeviceBirthPublishingAsync += OnVersionANodeDeviceBirthPublishing;
234-
node.DeviceCommandReceivedAsync += OnVersionANodeDeviceCommandReceived;
235-
node.DeviceDeathPublishingAsync += OnVersionANodeDeviceDeathPublishing;
233+
node.DeviceBirthPublishing += OnVersionANodeDeviceBirthPublishing;
234+
node.DeviceCommandReceived += OnVersionANodeDeviceCommandReceived;
235+
node.DeviceDeathPublishing += OnVersionANodeDeviceDeathPublishing;
236236

237237
// Handles the node's node command received event.
238-
node.NodeCommandReceivedAsync += OnVersionANodeNodeCommandReceived;
238+
node.NodeCommandReceived += OnVersionANodeNodeCommandReceived;
239239

240240
// Handles the node's status message received event.
241-
node.StatusMessageReceivedAsync += OnVersionANodeStatusMessageReceived;
241+
node.StatusMessageReceived += OnVersionANodeStatusMessageReceived;
242242

243243
// Get the known devices.
244244
var knownDevices = node.KnownDevices;
@@ -289,18 +289,18 @@ private static async Task RunVersionBApplication()
289289
Log.Information("Application started...");
290290

291291
// Handles the application's connected and disconnected events.
292-
application.ConnectedAsync += OnApplicationVersionBConnected;
293-
application.DisconnectedAsync += OnApplicationVersionBDisconnected;
292+
application.Connected += OnApplicationVersionBConnected;
293+
application.Disconnected += OnApplicationVersionBDisconnected;
294294

295295
// Handles the application's device related events.
296-
application.DeviceBirthReceivedAsync += OnApplicationVersionBDeviceBirthReceived;
297-
application.DeviceDataReceivedAsync += OnApplicationVersionBDeviceDataReceived;
298-
application.DeviceDeathReceivedAsync += OnApplicationVersionBDeviceDeathReceived;
296+
application.DeviceBirthReceived += OnApplicationVersionBDeviceBirthReceived;
297+
application.DeviceDataReceived += OnApplicationVersionBDeviceDataReceived;
298+
application.DeviceDeathReceived += OnApplicationVersionBDeviceDeathReceived;
299299

300300
// Handles the application's node related events.
301-
application.NodeBirthReceivedAsync += OnApplicationVersionBNodeBirthReceived;
302-
application.NodeDataReceivedAsync += OnApplicationVersionBNodeDataReceived;
303-
application.NodeDeathReceivedAsync += OnApplicationVersionBNodeDeathReceived;
301+
application.NodeBirthReceived += OnApplicationVersionBNodeBirthReceived;
302+
application.NodeDataReceived += OnApplicationVersionBNodeDataReceived;
303+
application.NodeDeathReceived += OnApplicationVersionBNodeDeathReceived;
304304

305305
// Publish node commands.
306306
Log.Information("Publishing a node command ...");
@@ -366,19 +366,19 @@ private static async Task RunVersionBNode()
366366
var isApplicationConnected = node.IsConnected;
367367

368368
// Handles the node's connected and disconnected events.
369-
node.ConnectedAsync += OnVersionBNodeConnected;
370-
node.DisconnectedAsync += OnVersionBNodeDisconnected;
369+
node.Connected += OnVersionBNodeConnected;
370+
node.Disconnected += OnVersionBNodeDisconnected;
371371

372372
// Handles the node's device related events.
373-
node.DeviceBirthPublishingAsync += OnVersionBNodeDeviceBirthPublishing;
374-
node.DeviceCommandReceivedAsync += OnVersionBNodeDeviceCommandReceived;
375-
node.DeviceDeathPublishingAsync += OnVersionBNodeDeviceDeathPublishing;
373+
node.DeviceBirthPublishing += OnVersionBNodeDeviceBirthPublishing;
374+
node.DeviceCommandReceived += OnVersionBNodeDeviceCommandReceived;
375+
node.DeviceDeathPublishing += OnVersionBNodeDeviceDeathPublishing;
376376

377377
// Handles the node's node command received event.
378-
node.NodeCommandReceivedAsync += OnVersionBNodeNodeCommandReceived;
378+
node.NodeCommandReceived += OnVersionBNodeNodeCommandReceived;
379379

380380
// Handles the node's status message received event.
381-
node.StatusMessageReceivedAsync += OnVersionBNodeStatusMessageReceived;
381+
node.StatusMessageReceived += OnVersionBNodeStatusMessageReceived;
382382

383383
// Get the known devices.
384384
var knownDevices = node.KnownDevices;
@@ -404,7 +404,7 @@ private static async Task RunVersionBNode()
404404
/// <summary>
405405
/// Handles the connected callback for version A applications.
406406
/// </summary>
407-
private static Task OnApplicationVersionAConnected(Core.SparkplugBase<VersionAData.KuraMetric>.SparkplugEventArgs arg)
407+
private static Task OnApplicationVersionAConnected(Core.SparkplugBase<VersionAData.KuraMetric>.SparkplugEventArgs args)
408408
{
409409
// Do something.
410410
return Task.CompletedTask;
@@ -413,7 +413,7 @@ private static Task OnApplicationVersionAConnected(Core.SparkplugBase<VersionADa
413413
/// <summary>
414414
/// Handles the disconnected callback for version A applications.
415415
/// </summary>
416-
private static Task OnApplicationVersionADisconnected(VersionA.SparkplugApplication.SparkplugEventArgs arg)
416+
private static Task OnApplicationVersionADisconnected(VersionA.SparkplugApplication.SparkplugEventArgs args)
417417
{
418418
// Do something.
419419
return Task.CompletedTask;
@@ -422,7 +422,7 @@ private static Task OnApplicationVersionADisconnected(VersionA.SparkplugApplicat
422422
/// <summary>
423423
/// Handles the device birth received callback for version A applications.
424424
/// </summary>
425-
private static Task OnApplicationVersionADeviceBirthReceived(Core.SparkplugBase<VersionAData.KuraMetric>.DeviceBirthEventArgs arg)
425+
private static Task OnApplicationVersionADeviceBirthReceived(Core.SparkplugBase<VersionAData.KuraMetric>.DeviceBirthEventArgs args)
426426
{
427427
// Do something.
428428
return Task.CompletedTask;
@@ -440,7 +440,7 @@ private static Task OnApplicationVersionADeviceDataReceived(VersionA.SparkplugAp
440440
/// <summary>
441441
/// Handles the device death received callback for version A applications.
442442
/// </summary>
443-
private static Task OnApplicationVersionADeviceDeathReceived(Core.SparkplugBase<VersionAData.KuraMetric>.DeviceEventArgs arg)
443+
private static Task OnApplicationVersionADeviceDeathReceived(Core.SparkplugBase<VersionAData.KuraMetric>.DeviceEventArgs args)
444444
{
445445
// Do something.
446446
return Task.CompletedTask;
@@ -449,7 +449,7 @@ private static Task OnApplicationVersionADeviceDeathReceived(Core.SparkplugBase<
449449
/// <summary>
450450
/// Handles the node birth received callback for version A applications.
451451
/// </summary>
452-
private static Task OnApplicationVersionANodeBirthReceived(Core.SparkplugBase<VersionAData.KuraMetric>.NodeBirthEventArgs arg)
452+
private static Task OnApplicationVersionANodeBirthReceived(Core.SparkplugBase<VersionAData.KuraMetric>.NodeBirthEventArgs args)
453453
{
454454
// Do something.
455455
return Task.CompletedTask;
@@ -467,7 +467,7 @@ private static Task OnApplicationVersionANodeDataReceived(VersionA.SparkplugAppl
467467
/// <summary>
468468
/// Handles the node death received callback for version A applications.
469469
/// </summary>
470-
private static Task OnApplicationVersionANodeDeathReceived(Core.SparkplugBase<VersionAData.KuraMetric>.NodeEventArgs arg)
470+
private static Task OnApplicationVersionANodeDeathReceived(Core.SparkplugBase<VersionAData.KuraMetric>.NodeEventArgs args)
471471
{
472472
// Do something.
473473
return Task.CompletedTask;
@@ -476,7 +476,7 @@ private static Task OnApplicationVersionANodeDeathReceived(Core.SparkplugBase<Ve
476476
/// <summary>
477477
/// Handles the connected callback for version A nodes.
478478
/// </summary>
479-
private static Task OnVersionANodeConnected(Core.SparkplugBase<VersionAData.KuraMetric>.SparkplugEventArgs arg)
479+
private static Task OnVersionANodeConnected(Core.SparkplugBase<VersionAData.KuraMetric>.SparkplugEventArgs args)
480480
{
481481
// Do something.
482482
return Task.CompletedTask;
@@ -485,7 +485,7 @@ private static Task OnVersionANodeConnected(Core.SparkplugBase<VersionAData.Kura
485485
/// <summary>
486486
/// Handles the disconnected callback for version A nodes.
487487
/// </summary>
488-
private static Task OnVersionANodeDisconnected(VersionA.SparkplugNode.SparkplugEventArgs arg)
488+
private static Task OnVersionANodeDisconnected(VersionA.SparkplugNode.SparkplugEventArgs args)
489489
{
490490
// Do something.
491491
return Task.CompletedTask;
@@ -546,7 +546,7 @@ private static Task OnVersionANodeStatusMessageReceived(VersionA.SparkplugNode.S
546546
/// <summary>
547547
/// Handles the connected callback for version B applications.
548548
/// </summary>
549-
private static Task OnApplicationVersionBConnected(Core.SparkplugBase<VersionBData.Metric>.SparkplugEventArgs arg)
549+
private static Task OnApplicationVersionBConnected(Core.SparkplugBase<VersionBData.Metric>.SparkplugEventArgs args)
550550
{
551551
// Do something.
552552
return Task.CompletedTask;
@@ -555,7 +555,7 @@ private static Task OnApplicationVersionBConnected(Core.SparkplugBase<VersionBDa
555555
/// <summary>
556556
/// Handles the disconnected callback for version B applications.
557557
/// </summary>
558-
private static Task OnApplicationVersionBDisconnected(VersionB.SparkplugApplication.SparkplugEventArgs arg)
558+
private static Task OnApplicationVersionBDisconnected(VersionB.SparkplugApplication.SparkplugEventArgs args)
559559
{
560560
// Do something.
561561
return Task.CompletedTask;
@@ -564,7 +564,7 @@ private static Task OnApplicationVersionBDisconnected(VersionB.SparkplugApplicat
564564
/// <summary>
565565
/// Handles the device birth received callback for version B applications.
566566
/// </summary>
567-
private static Task OnApplicationVersionBDeviceBirthReceived(Core.SparkplugBase<VersionBData.Metric>.DeviceBirthEventArgs arg)
567+
private static Task OnApplicationVersionBDeviceBirthReceived(Core.SparkplugBase<VersionBData.Metric>.DeviceBirthEventArgs args)
568568
{
569569
// Do something.
570570
return Task.CompletedTask;
@@ -582,7 +582,7 @@ private static Task OnApplicationVersionBDeviceDataReceived(VersionB.SparkplugAp
582582
/// <summary>
583583
/// Handles the device death received callback for version B applications.
584584
/// </summary>
585-
private static Task OnApplicationVersionBDeviceDeathReceived(Core.SparkplugBase<VersionBData.Metric>.DeviceEventArgs arg)
585+
private static Task OnApplicationVersionBDeviceDeathReceived(Core.SparkplugBase<VersionBData.Metric>.DeviceEventArgs args)
586586
{
587587
// Do something.
588588
return Task.CompletedTask;
@@ -591,7 +591,7 @@ private static Task OnApplicationVersionBDeviceDeathReceived(Core.SparkplugBase<
591591
/// <summary>
592592
/// Handles the node birth received callback for version B applications.
593593
/// </summary>
594-
private static Task OnApplicationVersionBNodeBirthReceived(Core.SparkplugBase<VersionBData.Metric>.NodeBirthEventArgs arg)
594+
private static Task OnApplicationVersionBNodeBirthReceived(Core.SparkplugBase<VersionBData.Metric>.NodeBirthEventArgs args)
595595
{
596596
// Do something.
597597
return Task.CompletedTask;
@@ -609,7 +609,7 @@ private static Task OnApplicationVersionBNodeDataReceived(VersionB.SparkplugAppl
609609
/// <summary>
610610
/// Handles the node death received callback for version B applications.
611611
/// </summary>
612-
private static Task OnApplicationVersionBNodeDeathReceived(Core.SparkplugBase<VersionBData.Metric>.NodeEventArgs arg)
612+
private static Task OnApplicationVersionBNodeDeathReceived(Core.SparkplugBase<VersionBData.Metric>.NodeEventArgs args)
613613
{
614614
// Do something.
615615
return Task.CompletedTask;
@@ -618,7 +618,7 @@ private static Task OnApplicationVersionBNodeDeathReceived(Core.SparkplugBase<Ve
618618
/// <summary>
619619
/// Handles the connected callback for version B nodes.
620620
/// </summary>
621-
private static Task OnVersionBNodeConnected(Core.SparkplugBase<VersionBData.Metric>.SparkplugEventArgs arg)
621+
private static Task OnVersionBNodeConnected(Core.SparkplugBase<VersionBData.Metric>.SparkplugEventArgs args)
622622
{
623623
// Do something.
624624
return Task.CompletedTask;
@@ -627,7 +627,7 @@ private static Task OnVersionBNodeConnected(Core.SparkplugBase<VersionBData.Metr
627627
/// <summary>
628628
/// Handles the disconnected callback for version B nodes.
629629
/// </summary>
630-
private static Task OnVersionBNodeDisconnected(VersionB.SparkplugNode.SparkplugEventArgs arg)
630+
private static Task OnVersionBNodeDisconnected(VersionB.SparkplugNode.SparkplugEventArgs args)
631631
{
632632
// Do something.
633633
return Task.CompletedTask;

src/SparkplugNet/Core/Application/SparkplugApplicationBase.EventArgs.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ public class NodeDataEventArgs : NodeEventArgs
2727
/// <param name="sender">The sender.</param>
2828
/// <param name="groupIdentifier">The group identifier.</param>
2929
/// <param name="edgeNodeIdentifier">The edge node identifier.</param>
30-
/// <param name="metric">The metric.</param>
31-
public NodeDataEventArgs(SparkplugApplicationBase<T> sender, string groupIdentifier, string edgeNodeIdentifier, T metric)
30+
/// <param name="metrics">The metrics.</param>
31+
public NodeDataEventArgs(SparkplugApplicationBase<T> sender, string groupIdentifier, string edgeNodeIdentifier, IEnumerable<T> metrics)
3232
: base(sender, groupIdentifier, edgeNodeIdentifier)
3333
{
34-
this.Metric = metric;
34+
this.Metrics = metrics;
3535
}
3636

3737
/// <summary>
38-
/// Gets the metric.
38+
/// Gets the metrics.
3939
/// </summary>
40-
public T Metric { get; }
40+
public IEnumerable<T> Metrics { get; }
4141
}
4242

4343
/// <inheritdoc cref="NodeDataEventArgs"/>
@@ -55,10 +55,10 @@ public sealed class DeviceDataEventArgs : NodeDataEventArgs
5555
/// <param name="groupIdentifier">The group identifier.</param>
5656
/// <param name="edgeNodeIdentifier">The edge node identifier.</param>
5757
/// <param name="deviceIdentifier">The device identifier.</param>
58-
/// <param name="metric">The metric.</param>
58+
/// <param name="metrics">The metrics.</param>
5959
/// <seealso cref="NodeDataEventArgs"/>
60-
public DeviceDataEventArgs(SparkplugApplicationBase<T> sender, string groupIdentifier, string edgeNodeIdentifier, string deviceIdentifier, T metric)
61-
: base(sender, groupIdentifier, edgeNodeIdentifier, metric)
60+
public DeviceDataEventArgs(SparkplugApplicationBase<T> sender, string groupIdentifier, string edgeNodeIdentifier, string deviceIdentifier, IEnumerable<T> metrics)
61+
: base(sender, groupIdentifier, edgeNodeIdentifier, metrics)
6262
{
6363
this.DeviceIdentifier = deviceIdentifier;
6464
}

0 commit comments

Comments
 (0)