From 596d1fa2d556e5b146b99177766c73bc4c8264e3 Mon Sep 17 00:00:00 2001 From: "SmallChi(Koike)" <564952747@qq.com> Date: Thu, 11 Mar 2021 10:39:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=98=E5=8E=9F=E6=B6=88=E6=81=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JT808.Gateway.MsgIdHandler.csproj | 30 ++++++++++++++++ .../JT808MsgIdHandlerExtensions.cs | 19 +++++++++++ .../JT808MsgIdHandlerHostedService.cs | 34 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808.Gateway.MsgIdHandler.csproj create mode 100644 src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerExtensions.cs create mode 100644 src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerHostedService.cs diff --git a/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808.Gateway.MsgIdHandler.csproj b/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808.Gateway.MsgIdHandler.csproj new file mode 100644 index 0000000..11a9963 --- /dev/null +++ b/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808.Gateway.MsgIdHandler.csproj @@ -0,0 +1,30 @@ + + + + + netstandard2.1 + 8.0 + Copyright 2019. + SmallChi(Koike) + https://github.com/SmallChi/JT808Gateway + https://github.com/SmallChi/JT808Gateway + https://github.com/SmallChi/JT808Gateway/blob/master/LICENSE + https://github.com/SmallChi/JT808Gateway/blob/master/LICENSE + false + $(JT808GatewayPackageVersion) + false + LICENSE + true + JT808.Gateway.MsgIdHandler + JT808.Gateway.MsgIdHandler + 基于JT808消息业务处理程序服务 + 基于JT808消息业务处理程序服务 + LICENSE + + + + + + + + diff --git a/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerExtensions.cs b/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerExtensions.cs new file mode 100644 index 0000000..4a711e8 --- /dev/null +++ b/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerExtensions.cs @@ -0,0 +1,19 @@ +using JT808.Gateway.Abstractions; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT808.Gateway.MsgIdHandler +{ + public static class JT808MsgIdHandlerExtensions + { + public static IJT808ClientBuilder AddMsgIdHandler(this IJT808ClientBuilder jT808ClientBuilder) + where TJT808MsgIdHandler: IJT808MsgIdHandler + { + jT808ClientBuilder.JT808Builder.Services.AddSingleton(typeof(IJT808MsgIdHandler),typeof(TJT808MsgIdHandler)); + jT808ClientBuilder.JT808Builder.Services.AddHostedService(); + return jT808ClientBuilder; + } + } +} diff --git a/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerHostedService.cs b/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerHostedService.cs new file mode 100644 index 0000000..db2a100 --- /dev/null +++ b/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerHostedService.cs @@ -0,0 +1,34 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Hosting; +using System.Threading; +using JT808.Gateway.Abstractions; + +namespace JT808.Gateway.MsgIdHandler +{ + public class JT808MsgIdHandlerHostedService : IHostedService + { + private readonly IJT808MsgConsumer jT808MsgConsumer; + + private readonly IJT808MsgIdHandler jT808MsgIdHandler; + public JT808MsgIdHandlerHostedService( + IJT808MsgIdHandler jT808MsgIdHandler, + IJT808MsgConsumer jT808MsgConsumer) + { + this.jT808MsgIdHandler = jT808MsgIdHandler; + this.jT808MsgConsumer = jT808MsgConsumer; + } + + public Task StartAsync(CancellationToken cancellationToken) + { + jT808MsgConsumer.Subscribe(); + jT808MsgConsumer.OnMessage(jT808MsgIdHandler.Processor); + return Task.CompletedTask; + } + + public Task StopAsync(CancellationToken cancellationToken) + { + jT808MsgConsumer.Unsubscribe(); + return Task.CompletedTask; + } + } +}