From d76dc386ffd6ff4f86a78d8ac1cc265aaa2a1e62 Mon Sep 17 00:00:00 2001 From: Ankita Gojiya Date: Wed, 24 Jul 2024 17:12:10 +0530 Subject: [PATCH 1/2] Remove metric filteration --- .../VersionB/SparkplugApplication.cs | 22 +++++++++---------- src/SparkplugNet/VersionB/SparkplugNode.cs | 10 ++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/SparkplugNet/VersionB/SparkplugApplication.cs b/src/SparkplugNet/VersionB/SparkplugApplication.cs index 76f896b..f4f6d8e 100644 --- a/src/SparkplugNet/VersionB/SparkplugApplication.cs +++ b/src/SparkplugNet/VersionB/SparkplugApplication.cs @@ -149,12 +149,12 @@ private async Task HandleMessagesForVersionB(SparkplugMessageTopic topic, Payloa { // Filter out session number metric. var sessionNumberMetric = payload.Metrics.FirstOrDefault(m => m.Name == Constants.SessionNumberMetricName); - var metricsWithoutSequenceMetric = payload.Metrics.Where(m => m.Name != Constants.SessionNumberMetricName); - var filteredMetrics = this.KnownMetricsStorage.FilterMetrics(metricsWithoutSequenceMetric, topic.MessageType).ToList(); + var metrics = payload.Metrics.Where(m => m.Name != Constants.SessionNumberMetricName).ToList(); + // var filteredMetrics = this.KnownMetricsStorage.FilterMetrics(metricsWithoutSequenceMetric, topic.MessageType).ToList(); if (sessionNumberMetric is not null) { - filteredMetrics.Add(sessionNumberMetric); + metrics.Add(sessionNumberMetric); } // Handle messages. @@ -162,19 +162,19 @@ private async Task HandleMessagesForVersionB(SparkplugMessageTopic topic, Payloa { case SparkplugMessageType.NodeBirth: await this.FireNodeBirthReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifier, - this.ProcessPayload(topic, filteredMetrics, SparkplugMetricStatus.Online)); + this.ProcessPayload(topic, metrics, SparkplugMetricStatus.Online)); break; case SparkplugMessageType.DeviceBirth: if (string.IsNullOrWhiteSpace(topic.DeviceIdentifier)) { throw new InvalidOperationException($"The device identifier is invalid!"); } - + await this.FireDeviceBirthReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifier, topic.DeviceIdentifier, - this.ProcessPayload(topic, filteredMetrics, SparkplugMetricStatus.Online)); + this.ProcessPayload(topic, metrics, SparkplugMetricStatus.Online)); break; case SparkplugMessageType.NodeData: - var nodeDataMetrics = this.ProcessPayload(topic, filteredMetrics, SparkplugMetricStatus.Online); + var nodeDataMetrics = this.ProcessPayload(topic, metrics, SparkplugMetricStatus.Online); await this.FireNodeDataReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifier, nodeDataMetrics); break; case SparkplugMessageType.DeviceData: @@ -183,20 +183,20 @@ await this.FireDeviceBirthReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifi throw new InvalidOperationException($"Topic {topic} is invalid!"); } - var deviceDataMetrics = this.ProcessPayload(topic, filteredMetrics, SparkplugMetricStatus.Online); + var deviceDataMetrics = this.ProcessPayload(topic, metrics, SparkplugMetricStatus.Online); await this.FireDeviceDataReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifier, topic.DeviceIdentifier, deviceDataMetrics); break; case SparkplugMessageType.NodeDeath: - this.ProcessPayload(topic, filteredMetrics, SparkplugMetricStatus.Offline); + this.ProcessPayload(topic, metrics, SparkplugMetricStatus.Offline); await this.FireNodeDeathReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifier, sessionNumberMetric); - break; + break; case SparkplugMessageType.DeviceDeath: if (string.IsNullOrWhiteSpace(topic.DeviceIdentifier)) { throw new InvalidOperationException($"Topic {topic} is invalid!"); } - this.ProcessPayload(topic, filteredMetrics, SparkplugMetricStatus.Offline); + this.ProcessPayload(topic, metrics, SparkplugMetricStatus.Offline); await this.FireDeviceDeathReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifier, topic.DeviceIdentifier); break; } diff --git a/src/SparkplugNet/VersionB/SparkplugNode.cs b/src/SparkplugNet/VersionB/SparkplugNode.cs index 58ed39f..b67defb 100644 --- a/src/SparkplugNet/VersionB/SparkplugNode.cs +++ b/src/SparkplugNet/VersionB/SparkplugNode.cs @@ -114,12 +114,12 @@ private async Task HandleMessagesForVersionB(SparkplugMessageTopic topic, Payloa { // Filter out session number metric. var sessionNumberMetric = payload.Metrics.FirstOrDefault(m => m.Name == Constants.SessionNumberMetricName); - var metricsWithoutSequenceMetric = payload.Metrics.Where(m => m.Name != Constants.SessionNumberMetricName); - var filteredMetrics = this.KnownMetricsStorage.FilterMetrics(metricsWithoutSequenceMetric, topic.MessageType).ToList(); + var metrics = payload.Metrics.ToList(); + // var filteredMetrics = this.KnownMetricsStorage.FilterMetrics(metricsWithoutSequenceMetric, topic.MessageType).ToList(); if (sessionNumberMetric is not null) { - filteredMetrics.Add(sessionNumberMetric); + metrics.Add(sessionNumberMetric); } // Handle messages. @@ -131,11 +131,11 @@ private async Task HandleMessagesForVersionB(SparkplugMessageTopic topic, Payloa throw new InvalidOperationException($"Topic {topic} is invalid!"); } - await this.FireDeviceCommandReceived(topic.DeviceIdentifier, filteredMetrics); + await this.FireDeviceCommandReceived(topic.DeviceIdentifier, metrics); break; case SparkplugMessageType.NodeCommand: - await this.FireNodeCommandReceived(filteredMetrics); + await this.FireNodeCommandReceived(metrics); break; } } From eaba1fa8f4808a30a30ec29f2cba8a546b8adf22 Mon Sep 17 00:00:00 2001 From: Ankita Gojiya Date: Wed, 24 Jul 2024 17:46:41 +0530 Subject: [PATCH 2/2] Code fixes --- src/SparkplugNet/VersionB/SparkplugNode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SparkplugNet/VersionB/SparkplugNode.cs b/src/SparkplugNet/VersionB/SparkplugNode.cs index b67defb..3ad52cb 100644 --- a/src/SparkplugNet/VersionB/SparkplugNode.cs +++ b/src/SparkplugNet/VersionB/SparkplugNode.cs @@ -114,7 +114,7 @@ private async Task HandleMessagesForVersionB(SparkplugMessageTopic topic, Payloa { // Filter out session number metric. var sessionNumberMetric = payload.Metrics.FirstOrDefault(m => m.Name == Constants.SessionNumberMetricName); - var metrics = payload.Metrics.ToList(); + var metrics = payload.Metrics.Where(m => m.Name != Constants.SessionNumberMetricName).ToList(); // var filteredMetrics = this.KnownMetricsStorage.FilterMetrics(metricsWithoutSequenceMetric, topic.MessageType).ToList(); if (sessionNumberMetric is not null)