From 5af763ad66f59724ff2ef2999116a15e4e16e776 Mon Sep 17 00:00:00 2001
From: "SmallChi(Koike)" <564952747@qq.com>
Date: Wed, 25 May 2022 22:25:38 +0800
Subject: [PATCH] pipeline-1.1.8-preview1 1.Replace HttpListener with
DotNetCore WebAPI; 2.Change a small number of webAPI interface request
addresses; 3.Improve the use of Demo.
---
.../Customs/JT808HttpClientExt.cs | 30 ++++++++++
.../Jobs/CallHttpClientJobExt.cs | 59 +++++++++++++++++++
simples/JT808.Gateway.SimpleClient/Program.cs | 5 +-
.../Customs/JT808WebApiExt.cs | 31 ++++++++++
.../JT808.Gateway.SimpleServer.csproj | 3 +-
simples/JT808.Gateway.SimpleServer/Program.cs | 36 ++++++++++-
.../appsettings.json | 24 ++++----
.../JT808.Gateway.Abstractions.csproj | 2 +-
.../JT808.Gateway.Client.csproj | 1 +
.../JT808.Gateway.Kafka.csproj | 1 +
.../JT808.Gateway.MsgIdHandler.csproj | 1 +
.../JT808.Gateway.MsgLogging.csproj | 1 +
.../JT808.Gateway.ReplyMessage.csproj | 1 +
.../JT808.Gateway.SessionNotice.csproj | 1 +
.../JT808.Gateway.Transmit.csproj | 1 +
.../JT808.Gateway.WebApiClientTool.csproj | 1 +
.../JT808HttpClientExtensions.cs | 8 +--
src/JT808.Gateway/JT808.Gateway.csproj | 2 +
18 files changed, 186 insertions(+), 22 deletions(-)
create mode 100644 simples/JT808.Gateway.SimpleClient/Customs/JT808HttpClientExt.cs
create mode 100644 simples/JT808.Gateway.SimpleClient/Jobs/CallHttpClientJobExt.cs
create mode 100644 simples/JT808.Gateway.SimpleServer/Customs/JT808WebApiExt.cs
diff --git a/simples/JT808.Gateway.SimpleClient/Customs/JT808HttpClientExt.cs b/simples/JT808.Gateway.SimpleClient/Customs/JT808HttpClientExt.cs
new file mode 100644
index 0000000..118a1e6
--- /dev/null
+++ b/simples/JT808.Gateway.SimpleClient/Customs/JT808HttpClientExt.cs
@@ -0,0 +1,30 @@
+using JT808.Gateway.Abstractions.Dtos;
+using JT808.Gateway.WebApiClientTool;
+using System.Net.Http;
+using System.Net.Http.Json;
+using System.Text.Json;
+using System.Threading.Tasks;
+
+namespace JT808.Gateway.SimpleClient.Customs
+{
+ public class JT808HttpClientExt : JT808HttpClient
+ {
+ public static string index1 = $"jt808apiext/index1";
+ public JT808HttpClientExt(HttpClient httpClient) : base(httpClient)
+ {
+ }
+
+ ///
+ /// ext
+ ///
+ ///
+ public async ValueTask> GetIndex1()
+ {
+ var request = new HttpRequestMessage(HttpMethod.Get, index1);
+ var response = await HttpClient.SendAsync(request);
+ response.EnsureSuccessStatusCode();
+ var value = await response.Content.ReadFromJsonAsync>();
+ return value;
+ }
+ }
+}
diff --git a/simples/JT808.Gateway.SimpleClient/Jobs/CallHttpClientJobExt.cs b/simples/JT808.Gateway.SimpleClient/Jobs/CallHttpClientJobExt.cs
new file mode 100644
index 0000000..edfd043
--- /dev/null
+++ b/simples/JT808.Gateway.SimpleClient/Jobs/CallHttpClientJobExt.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using System.Text.Json;
+using JT808.Protocol.Extensions;
+using Microsoft.Extensions.Options;
+using JT808.Gateway.Abstractions.Configurations;
+using JT808.Gateway.WebApiClientTool;
+using JT808.Gateway.SimpleClient.Customs;
+
+namespace JT808.Gateway.SimpleClient.Jobs
+{
+ public class CallHttpClientJobExt : IHostedService
+ {
+
+ private readonly ILogger Logger;
+ private JT808HttpClientExt jT808HttpClientExt;
+ public CallHttpClientJobExt(
+ ILoggerFactory loggerFactory,
+ JT808HttpClientExt jT808HttpClient)
+ {
+ Logger = loggerFactory.CreateLogger();
+ this.jT808HttpClientExt = jT808HttpClient;
+ }
+
+ public Task StartAsync(CancellationToken cancellationToken)
+ {
+ Task.Run(async() =>
+ {
+ while (!cancellationToken.IsCancellationRequested)
+ {
+ var result1 = await jT808HttpClientExt.GetIndex1();
+ var result2 = await jT808HttpClientExt.GetTcpSessionAll();
+ var result3 = await jT808HttpClientExt.UnificationSend(new Abstractions.Dtos.JT808UnificationSendRequestDto
+ {
+ TerminalPhoneNo= "123456789012",
+ HexData= "7E02000026123456789012007D02000000010000000200BA7F0E07E4F11C0028003C00001810151010100104000000640202007D01137E"
+ });
+ var result4 = await jT808HttpClientExt.QueryTcpSessionByTerminalPhoneNo(new Abstractions.Dtos.JT808TerminalPhoneNoDto { TerminalPhoneNo= "33333333333" });
+ Logger.LogInformation($"[GetIndex1]:{JsonSerializer.Serialize(result1)}");
+ Logger.LogInformation($"[GetTcpAtomicCounter]:{JsonSerializer.Serialize(result2)}");
+ Logger.LogInformation($"[UnificationSend]:{JsonSerializer.Serialize(result3)}");
+ Logger.LogInformation($"[QueryTcpSessionByTerminalPhoneNo]:{JsonSerializer.Serialize(result4)}");
+ Thread.Sleep(3000);
+ }
+ }, cancellationToken);
+ return Task.CompletedTask;
+ }
+
+ public Task StopAsync(CancellationToken cancellationToken)
+ {
+ return Task.CompletedTask;
+ }
+ }
+}
diff --git a/simples/JT808.Gateway.SimpleClient/Program.cs b/simples/JT808.Gateway.SimpleClient/Program.cs
index afccb24..e07af85 100644
--- a/simples/JT808.Gateway.SimpleClient/Program.cs
+++ b/simples/JT808.Gateway.SimpleClient/Program.cs
@@ -11,6 +11,7 @@ using JT808.Gateway.Client;
using JT808.Gateway.SimpleClient.Services;
using JT808.Gateway.SimpleClient.Jobs;
using JT808.Gateway.WebApiClientTool;
+using JT808.Gateway.SimpleClient.Customs;
namespace JT808.Gateway.SimpleClient
{
@@ -31,12 +32,14 @@ namespace JT808.Gateway.SimpleClient
services.AddJT808Configure()
.AddClient()
.Builder()
+ //可以注册一个或者可以自定义扩展
.AddWebApiClientTool(new Uri("http://127.0.0.1:828/"), "123456")
- ;
+ .AddWebApiClientTool(new Uri("http://127.0.0.1:828/"), "123456");
services.AddHostedService();
services.AddHostedService();
services.AddHostedService();
services.AddHostedService();
+ services.AddHostedService();
});
await serverHostBuilder.RunConsoleAsync();
}
diff --git a/simples/JT808.Gateway.SimpleServer/Customs/JT808WebApiExt.cs b/simples/JT808.Gateway.SimpleServer/Customs/JT808WebApiExt.cs
new file mode 100644
index 0000000..281ab6c
--- /dev/null
+++ b/simples/JT808.Gateway.SimpleServer/Customs/JT808WebApiExt.cs
@@ -0,0 +1,31 @@
+using JT808.Gateway.Abstractions.Dtos;
+using JT808.Gateway.Services;
+using JT808.Gateway.Session;
+using Microsoft.AspNetCore.Mvc;
+
+namespace JT808.Gateway.SimpleServer.Customs
+{
+ [Route("jt808apiext")]
+ [ApiController]
+ public class JT808WebApiExt : ControllerBase
+ {
+ public JT808WebApiExt(JT808SessionManager jT808SessionManager, JT808BlacklistManager jT808BlacklistManager)
+ {
+
+ }
+
+ ///
+ /// index1
+ ///
+ ///
+ [HttpGet]
+ [Route("index1")]
+ public ActionResult> Index1()
+ {
+ JT808ResultDto resultDto = new JT808ResultDto();
+ resultDto.Data = "Hello,JT808 WebApi Ext";
+ resultDto.Code = JT808ResultCode.Ok;
+ return resultDto;
+ }
+ }
+}
diff --git a/simples/JT808.Gateway.SimpleServer/JT808.Gateway.SimpleServer.csproj b/simples/JT808.Gateway.SimpleServer/JT808.Gateway.SimpleServer.csproj
index e8cf8f8..b0988eb 100644
--- a/simples/JT808.Gateway.SimpleServer/JT808.Gateway.SimpleServer.csproj
+++ b/simples/JT808.Gateway.SimpleServer/JT808.Gateway.SimpleServer.csproj
@@ -1,4 +1,4 @@
-
+
Exe
@@ -16,6 +16,7 @@
Always
+
diff --git a/simples/JT808.Gateway.SimpleServer/Program.cs b/simples/JT808.Gateway.SimpleServer/Program.cs
index 2cc89c1..65818b9 100644
--- a/simples/JT808.Gateway.SimpleServer/Program.cs
+++ b/simples/JT808.Gateway.SimpleServer/Program.cs
@@ -14,6 +14,9 @@ using JT808.Gateway.SimpleServer.Impl;
using JT808.Gateway.SimpleServer.Services;
using JT808.Gateway.Abstractions;
using JT808.Gateway.Transmit;
+using Microsoft.AspNetCore.Hosting;
+using JT808.Gateway.Abstractions.Configurations;
+using Microsoft.AspNetCore.Builder;
namespace JT808.Gateway.SimpleServer
{
@@ -30,7 +33,6 @@ namespace JT808.Gateway.SimpleServer
.ConfigureLogging((context, logging) =>
{
logging.AddConsole();
- logging.SetMinimumLevel(LogLevel.Trace);
})
.ConfigureServices((hostContext, services) =>
{
@@ -49,9 +51,41 @@ namespace JT808.Gateway.SimpleServer
.AddTcp()
.AddUdp()
.Builder();
+ }).ConfigureWebHostDefaults(webBuilder => {
+ webBuilder.UseKestrel((app, ksOptions) =>
+ {
+ //1.配置webapi端口监听
+ var jT808Configuration = app.Configuration.GetSection(nameof(JT808Configuration)).Get();
+ ksOptions.ListenAnyIP(jT808Configuration.WebApiPort);
+ })
+ .UseStartup();
});
await serverHostBuilder.RunConsoleAsync();
}
}
+ public class Startup
+ {
+ public Startup(IConfiguration configuration)
+ {
+ Configuration = configuration;
+ }
+
+ public IConfiguration Configuration { get; }
+
+ public void ConfigureServices(IServiceCollection services)
+ {
+ services.AddControllers();
+ }
+
+ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+ {
+ app.UseRouting();
+
+ app.UseEndpoints(endpoints =>
+ {
+ endpoints.MapControllers();
+ });
+ }
+ }
}
diff --git a/simples/JT808.Gateway.SimpleServer/appsettings.json b/simples/JT808.Gateway.SimpleServer/appsettings.json
index 322cf05..8e97a06 100644
--- a/simples/JT808.Gateway.SimpleServer/appsettings.json
+++ b/simples/JT808.Gateway.SimpleServer/appsettings.json
@@ -1,15 +1,11 @@
{
"Logging": {
- "IncludeScopes": false,
- "Debug": {
- "LogLevel": {
- "Default": "Trace"
- }
- },
- "Console": {
- "LogLevel": {
- "Default": "Trace"
- }
+ "LogLevel": {
+ "Default": "Debug",
+ "Microsoft.AspNetCore.Server.*": "Error",
+ "Microsoft.Extensions.Http.*": "Information",
+ "Microsoft.AspNetCore.Routing": "Warning",
+ "Microsoft.AspNetCore.*": "Warning"
}
},
"JT808Configuration": {
@@ -20,10 +16,10 @@
},
"RemoteServerOptions": {
"DataTransfer": [
- {
- "Host": "127.0.0.1:20000",
- "TerminalNos": []
- }
+ //{
+ // "Host": "127.0.0.1:20000",
+ // "TerminalNos": []
+ //}
]
}
}
diff --git a/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj b/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj
index bb0554b..ef826c4 100644
--- a/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj
+++ b/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj
@@ -5,7 +5,6 @@
基于Pipeline实现的JT808Gateway的抽象库
JT808.Gateway.Abstractions
JT808.Gateway.Abstractions
- $(JT808GatewayPackageVersion)
JT808.Gateway.Abstractions.xml
@@ -25,5 +24,6 @@
+
diff --git a/src/JT808.Gateway.Client/JT808.Gateway.Client.csproj b/src/JT808.Gateway.Client/JT808.Gateway.Client.csproj
index c5dfc08..9bc6fa1 100644
--- a/src/JT808.Gateway.Client/JT808.Gateway.Client.csproj
+++ b/src/JT808.Gateway.Client/JT808.Gateway.Client.csproj
@@ -18,5 +18,6 @@
+
diff --git a/src/JT808.Gateway.Kafka/JT808.Gateway.Kafka.csproj b/src/JT808.Gateway.Kafka/JT808.Gateway.Kafka.csproj
index 076a302..78ad2b8 100644
--- a/src/JT808.Gateway.Kafka/JT808.Gateway.Kafka.csproj
+++ b/src/JT808.Gateway.Kafka/JT808.Gateway.Kafka.csproj
@@ -13,6 +13,7 @@
+
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
index 663628e..9ede09c 100644
--- a/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808.Gateway.MsgIdHandler.csproj
+++ b/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808.Gateway.MsgIdHandler.csproj
@@ -12,5 +12,6 @@
+
diff --git a/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808.Gateway.MsgLogging.csproj b/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808.Gateway.MsgLogging.csproj
index da02136..ba94a91 100644
--- a/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808.Gateway.MsgLogging.csproj
+++ b/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808.Gateway.MsgLogging.csproj
@@ -12,6 +12,7 @@
+
diff --git a/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808.Gateway.ReplyMessage.csproj b/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808.Gateway.ReplyMessage.csproj
index c284f83..f367e6d 100644
--- a/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808.Gateway.ReplyMessage.csproj
+++ b/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808.Gateway.ReplyMessage.csproj
@@ -11,6 +11,7 @@
+
diff --git a/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808.Gateway.SessionNotice.csproj b/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808.Gateway.SessionNotice.csproj
index 46e9ba9..c048e40 100644
--- a/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808.Gateway.SessionNotice.csproj
+++ b/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808.Gateway.SessionNotice.csproj
@@ -12,6 +12,7 @@
+
diff --git a/src/JT808.Gateway.Services/JT808.Gateway.Transmit/JT808.Gateway.Transmit.csproj b/src/JT808.Gateway.Services/JT808.Gateway.Transmit/JT808.Gateway.Transmit.csproj
index d4624f6..e20d151 100644
--- a/src/JT808.Gateway.Services/JT808.Gateway.Transmit/JT808.Gateway.Transmit.csproj
+++ b/src/JT808.Gateway.Services/JT808.Gateway.Transmit/JT808.Gateway.Transmit.csproj
@@ -10,6 +10,7 @@
+
diff --git a/src/JT808.Gateway.WebApiClientTool/JT808.Gateway.WebApiClientTool.csproj b/src/JT808.Gateway.WebApiClientTool/JT808.Gateway.WebApiClientTool.csproj
index a24d03d..d2de7ce 100644
--- a/src/JT808.Gateway.WebApiClientTool/JT808.Gateway.WebApiClientTool.csproj
+++ b/src/JT808.Gateway.WebApiClientTool/JT808.Gateway.WebApiClientTool.csproj
@@ -10,6 +10,7 @@
+
diff --git a/src/JT808.Gateway.WebApiClientTool/JT808HttpClientExtensions.cs b/src/JT808.Gateway.WebApiClientTool/JT808HttpClientExtensions.cs
index 21edc52..c07ff70 100644
--- a/src/JT808.Gateway.WebApiClientTool/JT808HttpClientExtensions.cs
+++ b/src/JT808.Gateway.WebApiClientTool/JT808HttpClientExtensions.cs
@@ -103,7 +103,7 @@ namespace JT808.Gateway.WebApiClientTool
public static IServiceCollection AddJT808WebApiClientTool(this IServiceCollection serviceDescriptors, Uri webapiUri, string token)
where TJT808HttpClient : JT808HttpClient
{
- serviceDescriptors.AddHttpClient("JT808WebApiClientTool", c =>
+ serviceDescriptors.AddHttpClient("JT808WebApiClientToolExt", c =>
{
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
c.DefaultRequestHeaders.Add("token", token);
@@ -123,7 +123,7 @@ namespace JT808.Gateway.WebApiClientTool
public static IServiceCollection AddJT808WebApiClientTool(this IServiceCollection serviceDescriptors, IConfiguration configuration)
where TJT808HttpClient : JT808HttpClient
{
- serviceDescriptors.AddHttpClient("JT808WebApiClientTool", c =>
+ serviceDescriptors.AddHttpClient("JT808WebApiClientToolExt", c =>
{
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
c.DefaultRequestHeaders.Add("token", configuration.GetSection("JT808WebApiClientToolConfig:Token").Get());
@@ -143,7 +143,7 @@ namespace JT808.Gateway.WebApiClientTool
public static IJT808Builder AddWebApiClientTool(this IJT808Builder jT808Builder, IConfiguration configuration)
where TJT808HttpClient : JT808HttpClient
{
- jT808Builder.Services.AddHttpClient("JT808WebApiClientTool", c =>
+ jT808Builder.Services.AddHttpClient("JT808WebApiClientToolExt", c =>
{
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
c.DefaultRequestHeaders.Add("token", configuration.GetSection("JT808WebApiClientToolConfig:Token").Get());
@@ -164,7 +164,7 @@ namespace JT808.Gateway.WebApiClientTool
public static IJT808Builder AddWebApiClientTool(this IJT808Builder jT808Builder, Uri webapiUri, string token)
where TJT808HttpClient: JT808HttpClient
{
- jT808Builder.Services.AddHttpClient("JT808WebApiClientTool", c =>
+ jT808Builder.Services.AddHttpClient("JT808WebApiClientToolExt", c =>
{
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
c.DefaultRequestHeaders.Add("token", token);
diff --git a/src/JT808.Gateway/JT808.Gateway.csproj b/src/JT808.Gateway/JT808.Gateway.csproj
index d02c693..dda24c6 100644
--- a/src/JT808.Gateway/JT808.Gateway.csproj
+++ b/src/JT808.Gateway/JT808.Gateway.csproj
@@ -7,6 +7,7 @@
JT808.Gateway
JT808.Gateway
Library
+ true
@@ -23,5 +24,6 @@
+