Add MQTT runtime control and device data pipeline
This commit is contained in:
1 parent
96d8309793
commit
8a0aa8f7cb
31 files changed
+30842
-20
No files matched your search
@@ -0,0 +1,30 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using HHWMS.Web.Models;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace HHWMS.Web.Services
|
||||
{
|
||||
public class MqttRuntimeStateRefresher
|
||||
{
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
private readonly MqttRuntimeState _runtimeState;
|
||||
|
||||
public MqttRuntimeStateRefresher(IServiceScopeFactory scopeFactory, MqttRuntimeState runtimeState)
|
||||
{
|
||||
_scopeFactory = scopeFactory;
|
||||
_runtimeState = runtimeState;
|
||||
}
|
||||
|
||||
public Task<bool> RefreshFromSubscriptionsAsync(string changedBy = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var unitwork = scope.ServiceProvider.GetRequiredService<IUnitWork>();
|
||||
var enabled = unitwork.GetCount<MqttSubscription>(x => x.IsEnabled) > 0;
|
||||
_runtimeState.Update(enabled, changedBy);
|
||||
return Task.FromResult(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user