-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
289 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using Artemis.Core.Modules; | ||
using Swan; | ||
|
||
namespace Artemis.Plugins.Mqtt.DataModels; | ||
|
||
public class MqttNodeDataModel : DataModel | ||
{ | ||
public string Data { get; set; } | ||
|
||
public MqttNodeDataModel() | ||
{ | ||
Data = ""; | ||
} | ||
|
||
public void PropagateValue(string[] topics, object data) | ||
{ | ||
if (topics.Length == 0) | ||
{ | ||
Data = data.ToString() ?? ""; | ||
return; | ||
} | ||
|
||
var key = topics[0]; | ||
var remainingPartialTopics = topics[1..]; | ||
if (!TryGetDynamicChild<MqttNodeDataModel>(key, out var child)) | ||
child = AddDynamicChild<MqttNodeDataModel>(key, new()); | ||
|
||
child.Value.PropagateValue(remainingPartialTopics, data); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/Artemis.Plugins.Mqtt/DataModels/MqttServersDataModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Artemis.Core.Modules; | ||
|
||
namespace Artemis.Plugins.Mqtt.DataModels; | ||
|
||
public class MqttServersDataModel : DataModel | ||
{ | ||
private readonly Dictionary<Guid, DynamicChild<MqttNodeDataModel>> _servers = new(); | ||
|
||
internal void CreateServers(IEnumerable<MqttConnectionSettings> servers) | ||
{ | ||
ClearDynamicChildren(); | ||
_servers.Clear(); | ||
|
||
foreach (var server in servers) | ||
{ | ||
var id = server.ServerId.ToString(); | ||
_servers.Add( | ||
server.ServerId, | ||
AddDynamicChild(id, new MqttNodeDataModel(), server.DisplayName) | ||
); | ||
} | ||
} | ||
|
||
public void PropagateValue(Guid sourceServer, string topic, object data) | ||
{ | ||
if (!_servers.TryGetValue(sourceServer, out var server)) | ||
return; | ||
|
||
var parts = topic.Split('/'); | ||
server.Value.PropagateValue(parts, data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.