1.Replace HttpListener with DotNetCore WebAPI; 2.Change a small number of webAPI interface request addresses; 3.Improve the use of Demo.pull/25/head
@@ -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) | |||||
{ | |||||
} | |||||
/// <summary> | |||||
/// ext | |||||
/// </summary> | |||||
/// <returns></returns> | |||||
public async ValueTask<JT808ResultDto<string>> GetIndex1() | |||||
{ | |||||
var request = new HttpRequestMessage(HttpMethod.Get, index1); | |||||
var response = await HttpClient.SendAsync(request); | |||||
response.EnsureSuccessStatusCode(); | |||||
var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<string>>(); | |||||
return value; | |||||
} | |||||
} | |||||
} |
@@ -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<CallHttpClientJobExt>(); | |||||
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; | |||||
} | |||||
} | |||||
} |
@@ -11,6 +11,7 @@ using JT808.Gateway.Client; | |||||
using JT808.Gateway.SimpleClient.Services; | using JT808.Gateway.SimpleClient.Services; | ||||
using JT808.Gateway.SimpleClient.Jobs; | using JT808.Gateway.SimpleClient.Jobs; | ||||
using JT808.Gateway.WebApiClientTool; | using JT808.Gateway.WebApiClientTool; | ||||
using JT808.Gateway.SimpleClient.Customs; | |||||
namespace JT808.Gateway.SimpleClient | namespace JT808.Gateway.SimpleClient | ||||
{ | { | ||||
@@ -31,12 +32,14 @@ namespace JT808.Gateway.SimpleClient | |||||
services.AddJT808Configure() | services.AddJT808Configure() | ||||
.AddClient() | .AddClient() | ||||
.Builder() | .Builder() | ||||
//可以注册一个或者可以自定义扩展 | |||||
.AddWebApiClientTool(new Uri("http://127.0.0.1:828/"), "123456") | .AddWebApiClientTool(new Uri("http://127.0.0.1:828/"), "123456") | ||||
; | |||||
.AddWebApiClientTool<JT808HttpClientExt>(new Uri("http://127.0.0.1:828/"), "123456"); | |||||
services.AddHostedService<Up2011Service>(); | services.AddHostedService<Up2011Service>(); | ||||
services.AddHostedService<Up2013Service>(); | services.AddHostedService<Up2013Service>(); | ||||
services.AddHostedService<Up2019Service>(); | services.AddHostedService<Up2019Service>(); | ||||
services.AddHostedService<CallHttpClientJob>(); | services.AddHostedService<CallHttpClientJob>(); | ||||
services.AddHostedService<CallHttpClientJobExt>(); | |||||
}); | }); | ||||
await serverHostBuilder.RunConsoleAsync(); | await serverHostBuilder.RunConsoleAsync(); | ||||
} | } | ||||
@@ -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) | |||||
{ | |||||
} | |||||
/// <summary> | |||||
/// index1 | |||||
/// </summary> | |||||
/// <returns></returns> | |||||
[HttpGet] | |||||
[Route("index1")] | |||||
public ActionResult<JT808ResultDto<string>> Index1() | |||||
{ | |||||
JT808ResultDto<string> resultDto = new JT808ResultDto<string>(); | |||||
resultDto.Data = "Hello,JT808 WebApi Ext"; | |||||
resultDto.Code = JT808ResultCode.Ok; | |||||
return resultDto; | |||||
} | |||||
} | |||||
} |
@@ -1,4 +1,4 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<Project Sdk="Microsoft.NET.Sdk.Web"> | |||||
<PropertyGroup> | <PropertyGroup> | ||||
<OutputType>Exe</OutputType> | <OutputType>Exe</OutputType> | ||||
@@ -16,6 +16,7 @@ | |||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||||
</None> | </None> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions> | |||||
</Project> | </Project> |
@@ -14,6 +14,9 @@ using JT808.Gateway.SimpleServer.Impl; | |||||
using JT808.Gateway.SimpleServer.Services; | using JT808.Gateway.SimpleServer.Services; | ||||
using JT808.Gateway.Abstractions; | using JT808.Gateway.Abstractions; | ||||
using JT808.Gateway.Transmit; | using JT808.Gateway.Transmit; | ||||
using Microsoft.AspNetCore.Hosting; | |||||
using JT808.Gateway.Abstractions.Configurations; | |||||
using Microsoft.AspNetCore.Builder; | |||||
namespace JT808.Gateway.SimpleServer | namespace JT808.Gateway.SimpleServer | ||||
{ | { | ||||
@@ -30,7 +33,6 @@ namespace JT808.Gateway.SimpleServer | |||||
.ConfigureLogging((context, logging) => | .ConfigureLogging((context, logging) => | ||||
{ | { | ||||
logging.AddConsole(); | logging.AddConsole(); | ||||
logging.SetMinimumLevel(LogLevel.Trace); | |||||
}) | }) | ||||
.ConfigureServices((hostContext, services) => | .ConfigureServices((hostContext, services) => | ||||
{ | { | ||||
@@ -49,9 +51,41 @@ namespace JT808.Gateway.SimpleServer | |||||
.AddTcp() | .AddTcp() | ||||
.AddUdp() | .AddUdp() | ||||
.Builder(); | .Builder(); | ||||
}).ConfigureWebHostDefaults(webBuilder => { | |||||
webBuilder.UseKestrel((app, ksOptions) => | |||||
{ | |||||
//1.配置webapi端口监听 | |||||
var jT808Configuration = app.Configuration.GetSection(nameof(JT808Configuration)).Get<JT808Configuration>(); | |||||
ksOptions.ListenAnyIP(jT808Configuration.WebApiPort); | |||||
}) | |||||
.UseStartup<Startup>(); | |||||
}); | }); | ||||
await serverHostBuilder.RunConsoleAsync(); | 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(); | |||||
}); | |||||
} | |||||
} | |||||
} | } |
@@ -1,15 +1,11 @@ | |||||
{ | { | ||||
"Logging": { | "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": { | "JT808Configuration": { | ||||
@@ -20,10 +16,10 @@ | |||||
}, | }, | ||||
"RemoteServerOptions": { | "RemoteServerOptions": { | ||||
"DataTransfer": [ | "DataTransfer": [ | ||||
{ | |||||
"Host": "127.0.0.1:20000", | |||||
"TerminalNos": [] | |||||
} | |||||
//{ | |||||
// "Host": "127.0.0.1:20000", | |||||
// "TerminalNos": [] | |||||
//} | |||||
] | ] | ||||
} | } | ||||
} | } |
@@ -5,7 +5,6 @@ | |||||
<PackageReleaseNotes>基于Pipeline实现的JT808Gateway的抽象库</PackageReleaseNotes> | <PackageReleaseNotes>基于Pipeline实现的JT808Gateway的抽象库</PackageReleaseNotes> | ||||
<PackageId>JT808.Gateway.Abstractions</PackageId> | <PackageId>JT808.Gateway.Abstractions</PackageId> | ||||
<Product>JT808.Gateway.Abstractions</Product> | <Product>JT808.Gateway.Abstractions</Product> | ||||
<Version>$(JT808GatewayPackageVersion)</Version> | |||||
<DocumentationFile>JT808.Gateway.Abstractions.xml</DocumentationFile> | <DocumentationFile>JT808.Gateway.Abstractions.xml</DocumentationFile> | ||||
</PropertyGroup> | </PropertyGroup> | ||||
@@ -25,5 +24,6 @@ | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<None Include="..\..\LICENSE" Pack="true" PackagePath="" /> | <None Include="..\..\LICENSE" Pack="true" PackagePath="" /> | ||||
<None Include="..\..\README.md" Pack="true" PackagePath="" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
</Project> | </Project> |
@@ -18,5 +18,6 @@ | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<None Include="..\..\LICENSE" Pack="true" PackagePath="" /> | <None Include="..\..\LICENSE" Pack="true" PackagePath="" /> | ||||
<None Include="..\..\README.md" Pack="true" PackagePath="" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
</Project> | </Project> |
@@ -13,6 +13,7 @@ | |||||
<ItemGroup> | <ItemGroup> | ||||
<None Include="..\..\LICENSE" Pack="true" PackagePath="" /> | <None Include="..\..\LICENSE" Pack="true" PackagePath="" /> | ||||
<None Include="..\..\README.md" Pack="true" PackagePath="" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
@@ -12,5 +12,6 @@ | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<None Include="..\..\..\LICENSE" Pack="true" PackagePath="" /> | <None Include="..\..\..\LICENSE" Pack="true" PackagePath="" /> | ||||
<None Include="..\..\..\README.md" Pack="true" PackagePath="" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
</Project> | </Project> |
@@ -12,6 +12,7 @@ | |||||
<ItemGroup> | <ItemGroup> | ||||
<None Include="..\..\..\LICENSE" Pack="true" PackagePath="" /> | <None Include="..\..\..\LICENSE" Pack="true" PackagePath="" /> | ||||
<None Include="..\..\..\README.md" Pack="true" PackagePath="" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\..\JT808.Gateway.Abstractions\JT808.Gateway.Abstractions.csproj" /> | <ProjectReference Include="..\..\JT808.Gateway.Abstractions\JT808.Gateway.Abstractions.csproj" /> | ||||
@@ -11,6 +11,7 @@ | |||||
<ItemGroup> | <ItemGroup> | ||||
<None Include="..\..\..\LICENSE" Pack="true" PackagePath="" /> | <None Include="..\..\..\LICENSE" Pack="true" PackagePath="" /> | ||||
<None Include="..\..\..\README.md" Pack="true" PackagePath="" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\..\JT808.Gateway.Abstractions\JT808.Gateway.Abstractions.csproj" /> | <ProjectReference Include="..\..\JT808.Gateway.Abstractions\JT808.Gateway.Abstractions.csproj" /> | ||||
@@ -12,6 +12,7 @@ | |||||
<ItemGroup> | <ItemGroup> | ||||
<None Include="..\..\..\LICENSE" Pack="true" PackagePath="" /> | <None Include="..\..\..\LICENSE" Pack="true" PackagePath="" /> | ||||
<None Include="..\..\..\README.md" Pack="true" PackagePath="" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\..\JT808.Gateway.Abstractions\JT808.Gateway.Abstractions.csproj" /> | <ProjectReference Include="..\..\JT808.Gateway.Abstractions\JT808.Gateway.Abstractions.csproj" /> | ||||
@@ -10,6 +10,7 @@ | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<None Include="..\..\..\LICENSE" Pack="true" PackagePath="" /> | <None Include="..\..\..\LICENSE" Pack="true" PackagePath="" /> | ||||
<None Include="..\..\..\README.md" Pack="true" PackagePath="" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\..\JT808.Gateway.Abstractions\JT808.Gateway.Abstractions.csproj" /> | <ProjectReference Include="..\..\JT808.Gateway.Abstractions\JT808.Gateway.Abstractions.csproj" /> | ||||
@@ -10,6 +10,7 @@ | |||||
<ItemGroup> | <ItemGroup> | ||||
<None Include="..\..\LICENSE" Pack="true" PackagePath="" /> | <None Include="..\..\LICENSE" Pack="true" PackagePath="" /> | ||||
<None Include="..\..\README.md" Pack="true" PackagePath="" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" /> | <PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" /> | ||||
@@ -103,7 +103,7 @@ namespace JT808.Gateway.WebApiClientTool | |||||
public static IServiceCollection AddJT808WebApiClientTool<TJT808HttpClient>(this IServiceCollection serviceDescriptors, Uri webapiUri, string token) | public static IServiceCollection AddJT808WebApiClientTool<TJT808HttpClient>(this IServiceCollection serviceDescriptors, Uri webapiUri, string token) | ||||
where TJT808HttpClient : JT808HttpClient | where TJT808HttpClient : JT808HttpClient | ||||
{ | { | ||||
serviceDescriptors.AddHttpClient("JT808WebApiClientTool", c => | |||||
serviceDescriptors.AddHttpClient("JT808WebApiClientToolExt", c => | |||||
{ | { | ||||
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||||
c.DefaultRequestHeaders.Add("token", token); | c.DefaultRequestHeaders.Add("token", token); | ||||
@@ -123,7 +123,7 @@ namespace JT808.Gateway.WebApiClientTool | |||||
public static IServiceCollection AddJT808WebApiClientTool<TJT808HttpClient>(this IServiceCollection serviceDescriptors, IConfiguration configuration) | public static IServiceCollection AddJT808WebApiClientTool<TJT808HttpClient>(this IServiceCollection serviceDescriptors, IConfiguration configuration) | ||||
where TJT808HttpClient : JT808HttpClient | where TJT808HttpClient : JT808HttpClient | ||||
{ | { | ||||
serviceDescriptors.AddHttpClient("JT808WebApiClientTool", c => | |||||
serviceDescriptors.AddHttpClient("JT808WebApiClientToolExt", c => | |||||
{ | { | ||||
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||||
c.DefaultRequestHeaders.Add("token", configuration.GetSection("JT808WebApiClientToolConfig:Token").Get<string>()); | c.DefaultRequestHeaders.Add("token", configuration.GetSection("JT808WebApiClientToolConfig:Token").Get<string>()); | ||||
@@ -143,7 +143,7 @@ namespace JT808.Gateway.WebApiClientTool | |||||
public static IJT808Builder AddWebApiClientTool<TJT808HttpClient>(this IJT808Builder jT808Builder, IConfiguration configuration) | public static IJT808Builder AddWebApiClientTool<TJT808HttpClient>(this IJT808Builder jT808Builder, IConfiguration configuration) | ||||
where TJT808HttpClient : JT808HttpClient | where TJT808HttpClient : JT808HttpClient | ||||
{ | { | ||||
jT808Builder.Services.AddHttpClient("JT808WebApiClientTool", c => | |||||
jT808Builder.Services.AddHttpClient("JT808WebApiClientToolExt", c => | |||||
{ | { | ||||
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||||
c.DefaultRequestHeaders.Add("token", configuration.GetSection("JT808WebApiClientToolConfig:Token").Get<string>()); | c.DefaultRequestHeaders.Add("token", configuration.GetSection("JT808WebApiClientToolConfig:Token").Get<string>()); | ||||
@@ -164,7 +164,7 @@ namespace JT808.Gateway.WebApiClientTool | |||||
public static IJT808Builder AddWebApiClientTool<TJT808HttpClient>(this IJT808Builder jT808Builder, Uri webapiUri, string token) | public static IJT808Builder AddWebApiClientTool<TJT808HttpClient>(this IJT808Builder jT808Builder, Uri webapiUri, string token) | ||||
where TJT808HttpClient: JT808HttpClient | where TJT808HttpClient: JT808HttpClient | ||||
{ | { | ||||
jT808Builder.Services.AddHttpClient("JT808WebApiClientTool", c => | |||||
jT808Builder.Services.AddHttpClient("JT808WebApiClientToolExt", c => | |||||
{ | { | ||||
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||||
c.DefaultRequestHeaders.Add("token", token); | c.DefaultRequestHeaders.Add("token", token); | ||||
@@ -7,6 +7,7 @@ | |||||
<PackageId>JT808.Gateway</PackageId> | <PackageId>JT808.Gateway</PackageId> | ||||
<Product>JT808.Gateway</Product> | <Product>JT808.Gateway</Product> | ||||
<OutputType>Library</OutputType> | <OutputType>Library</OutputType> | ||||
<IsPackable>true</IsPackable> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
@@ -23,5 +24,6 @@ | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<None Include="..\..\LICENSE" Pack="true" PackagePath="" /> | <None Include="..\..\LICENSE" Pack="true" PackagePath="" /> | ||||
<None Include="..\..\README.md" Pack="true" PackagePath="" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
</Project> | </Project> |