remove last will with delete
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Diagnostics.EventLog" Version="10.0.0" />
|
||||
<PackageReference Include="System.Diagnostics.EventLog" Version="10.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="MQTTnet" Version="5.0.1.1416" />
|
||||
@@ -41,7 +41,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Telegram.Bot" Version="22.7.5" />
|
||||
<PackageReference Include="Telegram.Bot" Version="22.8.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
@implements IDisposable
|
||||
@using Microsoft.Extensions.DependencyInjection
|
||||
@using Microsoft.Extensions.Hosting
|
||||
@using UCS_Status_Monitor.MQTT
|
||||
@implements IDisposable
|
||||
@inject IDbContextFactory<MonitorDbContext> _contextFactory
|
||||
@inject MonitorHandler _monitorHandler
|
||||
@inject Telegram.ITelegramBotMessageChannel _telegramBotMessageChannel
|
||||
@* @inject MQTT.MQTTService _mqttService *@
|
||||
@inject IServiceProvider _serviceProvider
|
||||
|
||||
<table class="table table-hover table-responsive">
|
||||
<thead>
|
||||
@@ -159,12 +162,14 @@
|
||||
db.AxisCams.Remove(camera);
|
||||
|
||||
await _telegramBotMessageChannel.Send($"🚮 <b>{camera.Location} - {camera.Device}</b>{Environment.NewLine} Removed from SDN monitor", default);
|
||||
|
||||
string topic = $"{camera.Location}/{camera.Device}";
|
||||
MQTTService? mqttService = _serviceProvider.GetServices<IHostedService>().OfType<MQTTService>().Single();
|
||||
await mqttService.RemoveLastWillClient(topic);
|
||||
}
|
||||
db.SaveChanges();
|
||||
_monitorHandler.RemoveDevice(device);
|
||||
|
||||
//_mqttService.RemoveClient();
|
||||
|
||||
await UpdateTable();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MQTTnet;
|
||||
using MQTTnet.Protocol;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -16,6 +17,7 @@ using UCS_Status_Monitor.Log;
|
||||
using UCS_Status_Monitor.Monitor;
|
||||
using UCS_Status_Monitor.MQTT.Axis;
|
||||
using UCS_Status_Monitor.MQTT.Teltonika;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace UCS_Status_Monitor.MQTT
|
||||
{
|
||||
@@ -290,23 +292,34 @@ namespace UCS_Status_Monitor.MQTT
|
||||
}
|
||||
|
||||
|
||||
//public void RemoveClient()
|
||||
//{
|
||||
// MqttClientFactory mqttFactory = new();
|
||||
// MqttClientDisconnectOptions mqttClientDisconnectOptions = mqttFactory.CreateClientDisconnectOptionsBuilder().Build();
|
||||
public async Task RemoveLastWillClient(string topic)
|
||||
{
|
||||
Debug.WriteLine($"MQTT Service Remove Client {topic}");
|
||||
|
||||
// //MqttClientDisconnectOptions disconnectOptions = new()
|
||||
// //{
|
||||
// // Reason = MqttClientDisconnectOptionsReason.UnspecifiedError,
|
||||
// //};
|
||||
// //disconnectOptions.UserProperties.Add(new MQTTnet.Packets.MqttUserProperty("", ""));
|
||||
if (_mqttClient != null)
|
||||
{
|
||||
await _mqttClient.PublishAsync(
|
||||
new MqttApplicationMessageBuilder()
|
||||
.WithTopic($"{topic}/event/connection")
|
||||
.WithRetainFlag(true)
|
||||
.Build()
|
||||
);
|
||||
|
||||
// foreach (var options in mqttClientDisconnectOptions.UserProperties)
|
||||
// {
|
||||
// Debug.WriteLine($"{options.Name} {options.Value}");
|
||||
// }
|
||||
await _mqttClient.PublishAsync(
|
||||
new MqttApplicationMessageBuilder()
|
||||
.WithTopic($"{topic}/status")
|
||||
.WithRetainFlag(true)
|
||||
.Build()
|
||||
);
|
||||
|
||||
// //_mqttClient.DisconnectAsync(disconnectOptions);
|
||||
//}
|
||||
await _mqttClient.PublishAsync(
|
||||
new MqttApplicationMessageBuilder()
|
||||
.WithTopic(topic)
|
||||
.WithRetainFlag(true)
|
||||
.Build()
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,16 +35,16 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.0">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MQTTnet" Version="5.0.1.1416" />
|
||||
<PackageReference Include="MQTTnet.Extensions.ManagedClient" Version="4.3.7.1207" />
|
||||
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="10.0.0" />
|
||||
<PackageReference Include="System.Management" Version="10.0.0" />
|
||||
<PackageReference Include="Telegram.Bot" Version="22.7.5" />
|
||||
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="10.0.1" />
|
||||
<PackageReference Include="System.Management" Version="10.0.1" />
|
||||
<PackageReference Include="Telegram.Bot" Version="22.8.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user