Skip to content

Commit

Permalink
Added session number metric to node death received event. Fixes #60.
Browse files Browse the repository at this point in the history
  • Loading branch information
SeppPenner committed Mar 22, 2024
1 parent a492e6c commit 611afa9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/SparkplugNet.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ private static Task OnApplicationVersionANodeDataReceived(VersionA.SparkplugAppl
/// <summary>
/// Handles the node death received callback for version A applications.
/// </summary>
private static Task OnApplicationVersionANodeDeathReceived(Core.SparkplugBase<VersionAData.KuraMetric>.NodeEventArgs args)
private static Task OnApplicationVersionANodeDeathReceived(Core.SparkplugBase<VersionAData.KuraMetric>.NodeDeathEventArgs args)
{
// Do something.
return Task.CompletedTask;
Expand Down Expand Up @@ -602,7 +602,7 @@ private static Task OnApplicationVersionBNodeDataReceived(VersionB.SparkplugAppl
/// <summary>
/// Handles the node death received callback for version B applications.
/// </summary>
private static Task OnApplicationVersionBNodeDeathReceived(Core.SparkplugBase<VersionBData.Metric>.NodeEventArgs args)
private static Task OnApplicationVersionBNodeDeathReceived(Core.SparkplugBase<VersionBData.Metric>.NodeDeathEventArgs args)
{
// Do something.
return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ protected virtual Task FireNodeBirthReceived(string groupIdentifier, string edge
/// <summary>
/// The node death received event.
/// </summary>
protected AsyncEvent<NodeEventArgs> NodeDeathReceivedEvent = new();
protected AsyncEvent<NodeDeathEventArgs> NodeDeathReceivedEvent = new();

/// <summary>
/// Occurs when the node death was received.
/// </summary>
public event Func<NodeEventArgs, Task> NodeDeathReceived
public event Func<NodeDeathEventArgs, Task> NodeDeathReceived
{
add => this.NodeDeathReceivedEvent.AddHandler(value);
remove => this.NodeDeathReceivedEvent.RemoveHandler(value);
Expand All @@ -178,9 +178,10 @@ protected virtual Task FireNodeBirthReceived(string groupIdentifier, string edge
/// </summary>
/// <param name="groupIdentifier">The group identifier.</param>
/// <param name="edgeNodeIdentifier">The edge node identifier.</param>
protected virtual Task FireNodeDeathReceived(string groupIdentifier, string edgeNodeIdentifier)
/// <param name="sessionNumberMetric">The session number metric.</param>
protected virtual Task FireNodeDeathReceived(string groupIdentifier, string edgeNodeIdentifier, T? sessionNumberMetric)
{
var nodeEventArgs = new NodeEventArgs(this, groupIdentifier, edgeNodeIdentifier);
var nodeEventArgs = new NodeDeathEventArgs(this, groupIdentifier, edgeNodeIdentifier, sessionNumberMetric);
return this.NodeDeathReceivedEvent.InvokeAsync(nodeEventArgs);
}
#endregion
Expand Down
28 changes: 28 additions & 0 deletions src/SparkplugNet/Core/SparkplugBase.EventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,32 @@ public NodeBirthEventArgs(SparkplugBase<T> sender, string groupIdentifier, strin
/// </summary>
public IEnumerable<T> Metrics { get; }
}

/// <inheritdoc cref="NodeEventArgs" />
/// <summary>
/// A class for the node death event args.
/// </summary>
/// <seealso cref="NodeEventArgs" />
public sealed class NodeDeathEventArgs : NodeEventArgs
{
/// <inheritdoc cref="NodeEventArgs" />
/// <summary>
/// Initializes a new instance of the <see cref="NodeDeathEventArgs"/> class.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="groupIdentifier">The group identifier.</param>
/// <param name="edgeNodeIdentifier">The edge node identifier.</param>
/// <param name="sessionNumberMetric">The session number metric.</param>
/// <seealso cref="NodeEventArgs" />
public NodeDeathEventArgs(SparkplugBase<T> sender, string groupIdentifier, string edgeNodeIdentifier, T? sessionNumberMetric)
: base(sender, groupIdentifier, edgeNodeIdentifier)
{
this.SessionNumberMetric = sessionNumberMetric;
}

/// <summary>
/// Gets the session number metric.
/// </summary>
public T? SessionNumberMetric { get; }
}
}
2 changes: 1 addition & 1 deletion src/SparkplugNet/VersionA/SparkplugApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private async Task HandleMessagesForVersionA(SparkplugMessageTopic topic, Versio
break;
case SparkplugMessageType.NodeDeath:
this.ProcessPayload(topic, filteredMetrics, SparkplugMetricStatus.Offline);
await this.FireNodeDeathReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifier);
await this.FireNodeDeathReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifier, sessionNumberMetric);
break;
case SparkplugMessageType.DeviceDeath:
if (string.IsNullOrWhiteSpace(topic.DeviceIdentifier))
Expand Down
2 changes: 1 addition & 1 deletion src/SparkplugNet/VersionB/SparkplugApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private async Task HandleMessagesForVersionB(SparkplugMessageTopic topic, Payloa
break;
case SparkplugMessageType.NodeDeath:
this.ProcessPayload(topic, filteredMetrics, SparkplugMetricStatus.Offline);
await this.FireNodeDeathReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifier);
await this.FireNodeDeathReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifier, sessionNumberMetric);
break;
case SparkplugMessageType.DeviceDeath:
if (string.IsNullOrWhiteSpace(topic.DeviceIdentifier))
Expand Down

0 comments on commit 611afa9

Please sign in to comment.