Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Commit

Permalink
Fix mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeaugrand committed Sep 19, 2022
1 parent 31118db commit c4b9676
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/PlcPublisher/modules/PLC-Publisher/PLCPublisherModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,25 @@ private void StartPublisherThread()
var jsonTagValue = JsonConvert.SerializeObject(item.Data);
this.logger.LogTrace($"handling message for tag {item.Tag.Name} with value {jsonTagValue}");
JObject jsonEvent = null;
if (item.Tag.Transform != null)
{
this.logger.LogTrace("Transforming message with {0}", item.Tag.Transform.ToString());
JObject inputMessage = new JObject();
inputMessage.Add("input", JToken.FromObject(item.Data));
jsonTagValue = JsonTransformer.Transform(item.Tag.Transform.ToString(), inputMessage.ToString()).ToString();
jsonEvent = JObject.Parse(JsonTransformer.Transform(item.Tag.Transform.ToString(), inputMessage.ToString()));
}
else
{
jsonEvent = JObject.Parse($"{{\"{item.Tag.Name}\":{jsonTagValue}}}");
}
this.logger.LogTrace("Tag {0} value: {1}", item.Tag.TagName, jsonTagValue);
jsonEvent.Add("timestamp", item.EnqueuedTime.ToString("o"));
var jsonData = jsonEvent.ToString();
string jsonData = $"{{\"timestamp\":\"{item.EnqueuedTime.ToString("o")}\",\"{item.Tag.Name}\":{jsonTagValue}}}";
this.logger.LogTrace("{1}", jsonData);
return new Message(Encoding.UTF8.GetBytes(jsonData))
{
Expand Down

0 comments on commit c4b9676

Please sign in to comment.