Преглед изворни кода

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.
pull/25/head
SmallChi(Koike) пре 3 година
родитељ
комит
5af763ad66
18 измењених фајлова са 186 додато и 22 уклоњено
  1. +30
    -0
      simples/JT808.Gateway.SimpleClient/Customs/JT808HttpClientExt.cs
  2. +59
    -0
      simples/JT808.Gateway.SimpleClient/Jobs/CallHttpClientJobExt.cs
  3. +4
    -1
      simples/JT808.Gateway.SimpleClient/Program.cs
  4. +31
    -0
      simples/JT808.Gateway.SimpleServer/Customs/JT808WebApiExt.cs
  5. +2
    -1
      simples/JT808.Gateway.SimpleServer/JT808.Gateway.SimpleServer.csproj
  6. +35
    -1
      simples/JT808.Gateway.SimpleServer/Program.cs
  7. +10
    -14
      simples/JT808.Gateway.SimpleServer/appsettings.json
  8. +1
    -1
      src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj
  9. +1
    -0
      src/JT808.Gateway.Client/JT808.Gateway.Client.csproj
  10. +1
    -0
      src/JT808.Gateway.Kafka/JT808.Gateway.Kafka.csproj
  11. +1
    -0
      src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808.Gateway.MsgIdHandler.csproj
  12. +1
    -0
      src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808.Gateway.MsgLogging.csproj
  13. +1
    -0
      src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808.Gateway.ReplyMessage.csproj
  14. +1
    -0
      src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808.Gateway.SessionNotice.csproj
  15. +1
    -0
      src/JT808.Gateway.Services/JT808.Gateway.Transmit/JT808.Gateway.Transmit.csproj
  16. +1
    -0
      src/JT808.Gateway.WebApiClientTool/JT808.Gateway.WebApiClientTool.csproj
  17. +4
    -4
      src/JT808.Gateway.WebApiClientTool/JT808HttpClientExtensions.cs
  18. +2
    -0
      src/JT808.Gateway/JT808.Gateway.csproj

+ 30
- 0
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)
{
}

/// <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;
}
}
}

+ 59
- 0
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<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;
}
}
}

+ 4
- 1
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<JT808HttpClientExt>(new Uri("http://127.0.0.1:828/"), "123456");
services.AddHostedService<Up2011Service>();
services.AddHostedService<Up2013Service>();
services.AddHostedService<Up2019Service>();
services.AddHostedService<CallHttpClientJob>();
services.AddHostedService<CallHttpClientJobExt>();
});
await serverHostBuilder.RunConsoleAsync();
}


+ 31
- 0
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)
{

}

/// <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;
}
}
}

+ 2
- 1
simples/JT808.Gateway.SimpleServer/JT808.Gateway.SimpleServer.csproj Прегледај датотеку

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<OutputType>Exe</OutputType>
@@ -16,6 +16,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>


</Project>

+ 35
- 1
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<JT808Configuration>();
ksOptions.ListenAnyIP(jT808Configuration.WebApiPort);
})
.UseStartup<Startup>();
});

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();
});
}
}
}

+ 10
- 14
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": []
//}
]
}
}

+ 1
- 1
src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj Прегледај датотеку

@@ -5,7 +5,6 @@
<PackageReleaseNotes>基于Pipeline实现的JT808Gateway的抽象库</PackageReleaseNotes>
<PackageId>JT808.Gateway.Abstractions</PackageId>
<Product>JT808.Gateway.Abstractions</Product>
<Version>$(JT808GatewayPackageVersion)</Version>
<DocumentationFile>JT808.Gateway.Abstractions.xml</DocumentationFile>
</PropertyGroup>
@@ -25,5 +24,6 @@
</ItemGroup>
<ItemGroup>
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
<None Include="..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>
</Project>

+ 1
- 0
src/JT808.Gateway.Client/JT808.Gateway.Client.csproj Прегледај датотеку

@@ -18,5 +18,6 @@
</ItemGroup>
<ItemGroup>
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
<None Include="..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>
</Project>

+ 1
- 0
src/JT808.Gateway.Kafka/JT808.Gateway.Kafka.csproj Прегледај датотеку

@@ -13,6 +13,7 @@

<ItemGroup>
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
<None Include="..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>


+ 1
- 0
src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808.Gateway.MsgIdHandler.csproj Прегледај датотеку

@@ -12,5 +12,6 @@
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\LICENSE" Pack="true" PackagePath="" />
<None Include="..\..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>
</Project>

+ 1
- 0
src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808.Gateway.MsgLogging.csproj Прегледај датотеку

@@ -12,6 +12,7 @@

<ItemGroup>
<None Include="..\..\..\LICENSE" Pack="true" PackagePath="" />
<None Include="..\..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\JT808.Gateway.Abstractions\JT808.Gateway.Abstractions.csproj" />


+ 1
- 0
src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808.Gateway.ReplyMessage.csproj Прегледај датотеку

@@ -11,6 +11,7 @@

<ItemGroup>
<None Include="..\..\..\LICENSE" Pack="true" PackagePath="" />
<None Include="..\..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\JT808.Gateway.Abstractions\JT808.Gateway.Abstractions.csproj" />


+ 1
- 0
src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808.Gateway.SessionNotice.csproj Прегледај датотеку

@@ -12,6 +12,7 @@

<ItemGroup>
<None Include="..\..\..\LICENSE" Pack="true" PackagePath="" />
<None Include="..\..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\JT808.Gateway.Abstractions\JT808.Gateway.Abstractions.csproj" />


+ 1
- 0
src/JT808.Gateway.Services/JT808.Gateway.Transmit/JT808.Gateway.Transmit.csproj Прегледај датотеку

@@ -10,6 +10,7 @@
</PropertyGroup>
<ItemGroup>
<None Include="..\..\..\LICENSE" Pack="true" PackagePath="" />
<None Include="..\..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\JT808.Gateway.Abstractions\JT808.Gateway.Abstractions.csproj" />


+ 1
- 0
src/JT808.Gateway.WebApiClientTool/JT808.Gateway.WebApiClientTool.csproj Прегледај датотеку

@@ -10,6 +10,7 @@

<ItemGroup>
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
<None Include="..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />


+ 4
- 4
src/JT808.Gateway.WebApiClientTool/JT808HttpClientExtensions.cs Прегледај датотеку

@@ -103,7 +103,7 @@ namespace JT808.Gateway.WebApiClientTool
public static IServiceCollection AddJT808WebApiClientTool<TJT808HttpClient>(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<TJT808HttpClient>(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<string>());
@@ -143,7 +143,7 @@ namespace JT808.Gateway.WebApiClientTool
public static IJT808Builder AddWebApiClientTool<TJT808HttpClient>(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<string>());
@@ -164,7 +164,7 @@ namespace JT808.Gateway.WebApiClientTool
public static IJT808Builder AddWebApiClientTool<TJT808HttpClient>(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);


+ 2
- 0
src/JT808.Gateway/JT808.Gateway.csproj Прегледај датотеку

@@ -7,6 +7,7 @@
<PackageId>JT808.Gateway</PackageId>
<Product>JT808.Gateway</Product>
<OutputType>Library</OutputType>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
@@ -23,5 +24,6 @@
</ItemGroup>
<ItemGroup>
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
<None Include="..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>
</Project>

Loading…
Откажи
Сачувај