提交 8f29aedb 编写于 作者: 麦壳饼's avatar 麦壳饼

重构

上级 d77d7848
......@@ -8,7 +8,6 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Builder;
using MQTTnet.AspNetCore;
using MQTTnet.Diagnostics;
using IoTSharp.Handlers;
using IoTSharp.Services;
using MQTTnet.Server;
using System.Diagnostics;
......@@ -51,11 +50,11 @@ namespace IoTSharp
}).AddMqttConnectionHandler()
.AddConnections();
services.AddMqttWebSocketServerAdapter();
services.AddSingleton<MQTTServerHandler>();
services.AddSingleton<MQTTService>();
}
public static void UseIotSharpMqttServer(this IApplicationBuilder app)
{
var mqttEvents = app.ApplicationServices.CreateScope().ServiceProvider.GetService<MQTTServerHandler>();
var mqttEvents = app.ApplicationServices.CreateScope().ServiceProvider.GetService<MQTTService>();
app.UseMqttServer(server =>
{
server.ClientConnectedAsync += mqttEvents.Server_ClientConnectedAsync;
......
......@@ -211,6 +211,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="ClientApp\" />
<Folder Include="Services\MQTTControllers\" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
......
......@@ -2,6 +2,7 @@
using DotNetCore.CAP;
using IoTSharp.Data;
using IoTSharp.Handlers;
using IoTSharp.Services.CoApResources;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
......
......@@ -10,7 +10,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
namespace IoTSharp.Handlers
namespace IoTSharp.Services.CoApResources
{
public class CoApResource : Resource
{
......@@ -114,12 +114,12 @@ namespace IoTSharp.Handlers
switch (_res)
{
case CoApRes.Attributes:
_eventBus.PublishAttributeData(new PlayloadData() { MsgBody = keyValues, DataCatalog = DataCatalog.AttributeData, DataSide = DataSide.ClientSide, DeviceId = dev.Id });
_eventBus.PublishAttributeData(new PlayloadData() { MsgBody = keyValues, DataCatalog = DataCatalog.AttributeData, DataSide = DataSide.ClientSide, DeviceId = dev.Id });
exchange.Respond(StatusCode.Changed, $"OK");
break;
case CoApRes.Telemetry:
_eventBus.PublishTelemetryData(new PlayloadData() { MsgBody = keyValues, DataCatalog = DataCatalog.AttributeData, DataSide = DataSide.ClientSide, DeviceId = dev.Id });
_eventBus.PublishTelemetryData(new PlayloadData() { MsgBody = keyValues, DataCatalog = DataCatalog.AttributeData, DataSide = DataSide.ClientSide, DeviceId = dev.Id });
exchange.Respond(StatusCode.Created, $"OK");
break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册