fix warning
This commit is contained in:
+14
-8
@@ -13,6 +13,8 @@ public partial class Synapse
|
||||
public event EventHandler<ConfigStoreItem>? OnConfigChanged;
|
||||
private Dictionary<string, string> CurrentConfig { get; } = new();
|
||||
|
||||
private string ConfigStoreTopicPrefix => $"{Options.SysName}/synapse-config-store/";
|
||||
|
||||
private bool FireSetConfig(string key, string value)
|
||||
{
|
||||
if (key.Contains('#') || key.Contains('+')) return false;
|
||||
@@ -35,22 +37,26 @@ public partial class Synapse
|
||||
|
||||
private void RunConfigStoreServer()
|
||||
{
|
||||
var csTopicPrefix = $"{Options.SysName}/synapse-config-store/";
|
||||
var eventSubOpts = MqttFactory.CreateSubscribeOptionsBuilder()
|
||||
.WithTopicFilter(o =>
|
||||
o.WithTopic($"{csTopicPrefix}#").WithRetainHandling(MqttRetainHandling.SendAtSubscribe))
|
||||
.Build();
|
||||
Client!.ApplicationMessageReceivedAsync += e =>
|
||||
{
|
||||
if (!e.ApplicationMessage.Topic.StartsWith(csTopicPrefix)) return Task.CompletedTask;
|
||||
if (!e.ApplicationMessage.Topic.StartsWith(ConfigStoreTopicPrefix)) return Task.CompletedTask;
|
||||
var reqBody = e.ApplicationMessage.ConvertPayloadToString();
|
||||
var eventName = e.ApplicationMessage.Topic.Replace(csTopicPrefix, string.Empty);
|
||||
var eventName = e.ApplicationMessage.Topic.Replace(ConfigStoreTopicPrefix, string.Empty);
|
||||
CurrentConfig[eventName] = reqBody;
|
||||
OnConfigChanged?.Invoke(this, new ConfigStoreItem(eventName, reqBody));
|
||||
logger.LogDebug("Synapse Config Changed: {Config} => {Data}", eventName, reqBody);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
Client.SubscribeAsync(eventSubOpts).Wait();
|
||||
SubConfigStoreServerTopic();
|
||||
}
|
||||
|
||||
private void SubConfigStoreServerTopic()
|
||||
{
|
||||
var csSubOpts = MqttFactory.CreateSubscribeOptionsBuilder()
|
||||
.WithTopicFilter(o =>
|
||||
o.WithTopic($"{ConfigStoreTopicPrefix}#").WithRetainHandling(MqttRetainHandling.SendAtSubscribe))
|
||||
.Build();
|
||||
Client!.SubscribeAsync(csSubOpts).Wait();
|
||||
}
|
||||
|
||||
public record ConfigStoreItem(string Key, string Value);
|
||||
|
||||
Reference in New Issue
Block a user