Pārlūkot izejas kodu

pipeline-1.1.8-preview2

1.Add a paging session query interface to avoid querying all sessions;
2.Replace Task.Run of some jobs with Thread;
pull/25/head
SmallChi(Koike) pirms 2 gadiem
vecāks
revīzija
be2ed1af8d
28 mainītis faili ar 385 papildinājumiem un 105 dzēšanām
  1. +102
    -0
      api/README_Pipeline.md
  2. +40
    -59
      simples/JT808.Gateway.SimpleServer/Program.cs
  3. +16
    -0
      src/JT808.Gateway.Abstractions/Dtos/JT808PageResult.cs
  4. +1
    -1
      src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj
  5. +10
    -0
      src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.xml
  6. +10
    -2
      src/JT808.Gateway.Abstractions/JT808GatewayConstants.cs
  7. +1
    -1
      src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/JT808.Gateway.CleintBenchmark.csproj
  8. +3
    -3
      src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Services/CleintBenchmarkHostedService.cs
  9. +2
    -2
      src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/JT808.Gateway.ServerBenchmark.csproj
  10. +1
    -1
      src/JT808.Gateway.Client/JT808.Gateway.Client.csproj
  11. +3
    -2
      src/JT808.Gateway.Client/Services/JT808RetryClientHostedService.cs
  12. +1
    -1
      src/JT808.Gateway.Kafka/JT808.Gateway.Kafka.csproj
  13. +8
    -6
      src/JT808.Gateway.Kafka/JT808MsgConsumer.cs
  14. +8
    -6
      src/JT808.Gateway.Kafka/JT808MsgReplyConsumer.cs
  15. +5
    -2
      src/JT808.Gateway.Kafka/JT808MsgReplyLoggingConsumer.cs
  16. +7
    -4
      src/JT808.Gateway.Kafka/JT808SessionConsumer.cs
  17. +1
    -1
      src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808ReplyMessageHostedService.cs
  18. +2
    -2
      src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808MsgReplyConsumer.cs
  19. +2
    -2
      src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808SessionConsumer.cs
  20. +3
    -3
      src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/JT808.Gateway.NormalHosting.csproj
  21. +3
    -3
      src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/JT808.Gateway.QueueHosting.csproj
  22. +3
    -3
      src/JT808.Gateway.Tests/JT808.Gateway.Test/JT808.Gateway.Test.csproj
  23. +12
    -0
      src/JT808.Gateway.WebApiClientTool/JT808.Gateway.WebApiClientTool.xml
  24. +26
    -0
      src/JT808.Gateway.WebApiClientTool/JT808HttpClient.cs
  25. +2
    -0
      src/JT808.Gateway/JT808.Gateway.xml
  26. +91
    -0
      src/JT808.Gateway/JT808WebApi.cs
  27. +21
    -0
      src/JT808.Gateway/Session/JT808SessionManager.cs
  28. +1
    -1
      src/PipelineInfo.props

+ 102
- 0
api/README_Pipeline.md Parādīt failu

@@ -35,6 +35,7 @@
|请求Url|请求方式|说明|
|:------|:------|:------|
| 127.0.0.1:828/jt808api/Tcp/Session/GetAll| GET| 基于Tcp管理会话服务-获取会话集合|
| 127.0.0.1:828/jt808api/Tcp/Session/SessionTcpByPage?pageIndex=0&pageSize10| GET| 基于Tcp管理会话服务-获取会话分页集合|
| 127.0.0.1:828/jt808api/Tcp/Session/QuerySessionByTerminalPhoneNo| POST| 基于Tcp管理会话服务-通过设备终端号查询对应会话|
| 127.0.0.1:828/jt808api/Tcp/Session/RemoveByTerminalPhoneNo| POST| 基于Tcp管理会话服务-通过设备终端号移除对应会话|

@@ -43,6 +44,7 @@
|请求Url|请求方式|说明|
|:------|:------|:------|
| 127.0.0.1:828/jt808api/Udp/Session/GetAll| GET| 基于Udp管理会话服务-获取会话集合|
| 127.0.0.1:828/jt808api/Udp/Session/SessionUdpByPage?pageIndex=0&pageSize10| GET| 基于Tcp管理会话服务-获取会话分页集合|
| 127.0.0.1:828/jt808api/Udp/Session/QuerySessionByTerminalPhoneNo| POST| 基于Udp管理会话服务-通过设备终端号查询对应会话|
| 127.0.0.1:828/jt808api/Udp/Session/RemoveByTerminalPhoneNo| POST| 基于Udp管理会话服务-通过设备终端号移除对应会话|

@@ -225,6 +227,56 @@
}
```

#### 4.获取会话分页集合

请求地址:Tcp/Session/SessionTcpByPage

请求方式:GET

请求参数:

|属性|数据类型|参数说明|
|:------:|:------:|:------|
| pageIndex| int| 当前页(默认0)|
| pageSize| int| 页容量(默认10)|

返回数据:

|属性|数据类型|参数说明|
|:------:|:------:|:------|
| Data| List\<JT808TcpSessionInfoDto> | 实际会话信息集合 |
| PageIndex| int | 当前页(默认0) |
| PageSize| int | 页容量(默认10) |
| Total| int | 总数 |

返回结果:

``` session1
{
"message":null,
"code":200,
"data":{
"pageIndex":0,
"pageSize":10,
"total":2,
"data":[
{
"lastActiveTime":"2022-09-03T19:34:07.8733605+08:00",
"startTime":"2022-09-03T19:34:07.8733615+08:00",
"terminalPhoneNo":"123456789012",
"remoteAddressIP":"127.0.0.1:9826"
},
{
"lastActiveTime":"2022-09-03T19:34:05.135997+08:00",
"startTime":"2022-09-03T19:34:05.136035+08:00",
"terminalPhoneNo":"123456789013",
"remoteAddressIP":"127.0.0.1:9825"
}
]
}
}
```

### <span id="udp_session">基于Udp管理会话服务</span>

#### 统一会话信息对象返回 JT808UdpSessionInfoDto
@@ -343,6 +395,56 @@
}
```

#### 4.获取会话分页集合

请求地址:Udp/Session/SessionUdpByPage

请求方式:GET

请求参数:

|属性|数据类型|参数说明|
|:------:|:------:|:------|
| pageIndex| int| 当前页(默认0)|
| pageSize| int| 页容量(默认10)|

返回数据:

|属性|数据类型|参数说明|
|:------:|:------:|:------|
| Data| List\<JT808UdpSessionInfoDto> | 实际会话信息集合 |
| PageIndex| int | 当前页(默认0) |
| PageSize| int | 页容量(默认10) |
| Total| int | 总数 |

返回结果:

``` session1
{
"message":null,
"code":200,
"data":{
"pageIndex":0,
"pageSize":10,
"total":2,
"data":[
{
"lastActiveTime":"2022-09-03T19:34:07.8733605+08:00",
"startTime":"2022-09-03T19:34:07.8733615+08:00",
"terminalPhoneNo":"123456789012",
"remoteAddressIP":"127.0.0.1:9826"
},
{
"lastActiveTime":"2022-09-03T19:34:05.135997+08:00",
"startTime":"2022-09-03T19:34:05.136035+08:00",
"terminalPhoneNo":"123456789013",
"remoteAddressIP":"127.0.0.1:9825"
}
]
}
}
```

### <span id="blacklist">SIM黑名单管理服务</span>

#### 1.添加sim卡黑名单


+ 40
- 59
simples/JT808.Gateway.SimpleServer/Program.cs Parādīt failu

@@ -22,70 +22,51 @@ namespace JT808.Gateway.SimpleServer
{
class Program
{
static async Task Main(string[] args)
static void Main(string[] args)
{
var serverHostBuilder = new HostBuilder()
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory);
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
})
.ConfigureLogging((context, logging) =>
var builder = WebApplication.CreateBuilder();
builder.Host.ConfigureAppConfiguration((hostingContext, config) =>
{
config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory);
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
})
.ConfigureLogging((context, logging) =>
{
logging.AddConsole();
})
.ConfigureServices((hostContext, services) =>
{
services.AddSingleton<ILoggerFactory, LoggerFactory>();
services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
//使用内存队列实现会话通知
services.AddSingleton<JT808SessionService>();
services.AddSingleton<IJT808SessionProducer, JT808SessionProducer>();
services.AddSingleton<IJT808SessionConsumer, JT808SessionConsumer>();
services.AddJT808Configure()
.AddGateway(hostContext.Configuration)
.AddMessageHandler<JT808MessageHandlerImpl>()
.AddMsgLogging<JT808MsgLogging>()
.AddSessionNotice()
.AddTransmit(hostContext.Configuration)
.AddTcp()
.AddUdp()
.Builder();
});

builder.WebHost.UseKestrel((app, serverOptions) =>
{
logging.AddConsole();
//1.配置webapi端口监听
var jT808Configuration = app.Configuration.GetSection(nameof(JT808Configuration)).Get<JT808Configuration>();
serverOptions.ListenAnyIP(jT808Configuration.WebApiPort);
})
.ConfigureServices((hostContext, services) =>
{
services.AddSingleton<ILoggerFactory, LoggerFactory>();
services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
//使用内存队列实现会话通知
services.AddSingleton<JT808SessionService>();
services.AddSingleton<IJT808SessionProducer, JT808SessionProducer>();
services.AddSingleton<IJT808SessionConsumer, JT808SessionConsumer>();
services.AddJT808Configure()
.AddGateway(hostContext.Configuration)
.AddMessageHandler<JT808MessageHandlerImpl>()
.AddMsgLogging<JT808MsgLogging>()
.AddSessionNotice()
.AddTransmit(hostContext.Configuration)
.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 =>
.ConfigureServices((hostContext, services) =>
{
endpoints.MapControllers();
services.AddControllers();
});
var app = builder.Build();
app.UseRouting();
app.MapControllers();
app.Run();
}
}
}

+ 16
- 0
src/JT808.Gateway.Abstractions/Dtos/JT808PageResult.cs Parādīt failu

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JT808.Gateway.Abstractions.Dtos
{
public class JT808PageResult<T>
{
public int PageIndex { get; set; } = 1;
public int PageSize { get; set; } = 10;
public int Total { get; set; } = 0;
public T Data { get; set; }
}
}

+ 1
- 1
src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj Parādīt failu

@@ -16,7 +16,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="JT808" Version="2.5.0-preview1" />
<PackageReference Include="JT808" Version="2.5.0-preview3" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />


+ 10
- 0
src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.xml Parādīt failu

@@ -222,6 +222,11 @@
基于Tcp的会话服务集合
</summary>
</member>
<member name="F:JT808.Gateway.Abstractions.JT808GatewayConstants.JT808WebApiRouteTable.SessionTcpByPage">
<summary>
基于Tcp的会话服务集合
</summary>
</member>
<member name="F:JT808.Gateway.Abstractions.JT808GatewayConstants.JT808WebApiRouteTable.SessionRemoveByTerminalPhoneNo">
<summary>
会话服务-通过设备终端号移除对应会话
@@ -242,6 +247,11 @@
基于Udp的虚拟会话服务集合
</summary>
</member>
<member name="F:JT808.Gateway.Abstractions.JT808GatewayConstants.JT808WebApiRouteTable.SessionUdpByPage">
<summary>
基于Udp的虚拟会话服务集合
</summary>
</member>
<member name="F:JT808.Gateway.Abstractions.JT808GatewayConstants.JT808WebApiRouteTable.RemoveUdpByTerminalPhoneNo">
<summary>
会话服务-通过设备终端号移除对应会话


+ 10
- 2
src/JT808.Gateway.Abstractions/JT808GatewayConstants.cs Parādīt failu

@@ -20,7 +20,11 @@
/// <summary>
/// 基于Tcp的会话服务集合
/// </summary>
public static string SessionTcpGetAll = $"{RouteTablePrefix}/{TcpPrefix}/{SessionPrefix}/GetAll";
public static string SessionTcpGetAll = $"{RouteTablePrefix}/{TcpPrefix}/{SessionPrefix}/GetAll";
/// <summary>
/// 基于Tcp的会话服务集合
/// </summary>
public static string SessionTcpByPage = $"{RouteTablePrefix}/{TcpPrefix}/{SessionPrefix}/SessionTcpByPage";
/// <summary>
/// 会话服务-通过设备终端号移除对应会话
/// </summary>
@@ -36,7 +40,11 @@
/// <summary>
/// 基于Udp的虚拟会话服务集合
/// </summary>
public static string SessionUdpGetAll = $"{RouteTablePrefix}/{UdpPrefix}/{SessionPrefix}/GetAll";
public static string SessionUdpGetAll = $"{RouteTablePrefix}/{UdpPrefix}/{SessionPrefix}/GetAll";
/// <summary>
/// 基于Udp的虚拟会话服务集合
/// </summary>
public static string SessionUdpByPage = $"{RouteTablePrefix}/{UdpPrefix}/{SessionPrefix}/SessionUdpByPage";
/// <summary>
/// 会话服务-通过设备终端号移除对应会话
/// </summary>


+ 1
- 1
src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/JT808.Gateway.CleintBenchmark.csproj Parādīt failu

@@ -20,7 +20,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.0.4" />
</ItemGroup>

<ItemGroup>


+ 3
- 3
src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Services/CleintBenchmarkHostedService.cs Parādīt failu

@@ -45,7 +45,7 @@ namespace JT808.Gateway.CleintBenchmark.Services
logger.LogInformation($"GetMinThreads:{minWorkerThreads}-{minCompletionPortThreads}");
logger.LogInformation($"GetMaxThreads:{maxWorkerThreads}-{maxCompletionPortThreads}");
taskFactory = new TaskFactory(cancellationToken);
Task.Run(() => {
new Thread(() => {
for (int i = 0; i < clientBenchmarkOptions.DeviceCount; i++)
{
taskFactory.StartNew(async (state) => {
@@ -80,12 +80,12 @@ namespace JT808.Gateway.CleintBenchmark.Services
{
logger.LogError(ex.Message);
}
await Task.Delay(clientBenchmarkOptions.Interval);
Thread.Sleep(clientBenchmarkOptions.Interval);
}
}, i);
Thread.Sleep(300);
}
});
}).Start();
return Task.CompletedTask;
}



+ 2
- 2
src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/JT808.Gateway.ServerBenchmark.csproj Parādīt failu

@@ -8,8 +8,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.15.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.0.4" />
</ItemGroup>

<ItemGroup>


+ 1
- 1
src/JT808.Gateway.Client/JT808.Gateway.Client.csproj Parādīt failu

@@ -10,7 +10,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JT808" Version="2.5.0-preview1" />
<PackageReference Include="JT808" Version="2.5.0-preview3" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
<PackageReference Include="System.IO.Pipelines" Version="6.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />


+ 3
- 2
src/JT808.Gateway.Client/Services/JT808RetryClientHostedService.cs Parādīt failu

@@ -35,7 +35,8 @@ namespace JT808.Gateway.Client.Services

public Task StartAsync(CancellationToken cancellationToken)
{
Task.Run(async()=> {
new Thread(async () =>
{
foreach (var item in RetryBlockingCollection.RetryBlockingCollection.GetConsumingEnumerable(cancellationToken))
{
try
@@ -66,7 +67,7 @@ namespace JT808.Gateway.Client.Services
await Task.Delay(TimeSpan.FromSeconds(5));
}
}
}, cancellationToken);
}).Start();
return Task.CompletedTask;
}



+ 1
- 1
src/JT808.Gateway.Kafka/JT808.Gateway.Kafka.csproj Parādīt failu

@@ -8,7 +8,7 @@
<DocumentationFile>JT808.Gateway.Kafka.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Confluent.Kafka" Version="1.8.2" />
<PackageReference Include="Confluent.Kafka" Version="1.9.2" />
</ItemGroup>

<ItemGroup>


+ 8
- 6
src/JT808.Gateway.Kafka/JT808MsgConsumer.cs Parādīt failu

@@ -33,7 +33,7 @@ namespace JT808.Gateway.Kafka

public void OnMessage(Action<(string TerminalNo, byte[] Data)> callback)
{
Task.Run(() =>
new Thread(() =>
{
while (!Cts.IsCancellationRequested)
{
@@ -49,20 +49,22 @@ namespace JT808.Gateway.Kafka
}
callback((data.Message.Key, data.Message.Value));
}
catch (ConsumeException ex)
catch (OperationCanceledException)
{
logger.LogError(ex, TopicName);
break;
}
catch (OperationCanceledException)
catch (ConsumeException ex)
{

logger.LogError(ex, TopicName);
break;
}
catch (Exception ex)
{
logger.LogError(ex, TopicName);
break;
}
}
});
}).Start();
}
public void Subscribe()
{


+ 8
- 6
src/JT808.Gateway.Kafka/JT808MsgReplyConsumer.cs Parādīt failu

@@ -33,8 +33,7 @@ namespace JT808.Gateway.Kafka

public void OnMessage(Action<(string TerminalNo, byte[] Data)> callback)
{
Task.Run(() =>
{
new Thread(() => {
while (!Cts.IsCancellationRequested)
{
if (disposed) return;
@@ -49,19 +48,22 @@ namespace JT808.Gateway.Kafka
}
callback((data.Message.Key, data.Message.Value));
}
catch (ConsumeException ex)
catch (OperationCanceledException)
{
logger.LogError(ex, TopicName);
break;
}
catch (OperationCanceledException)
catch (ConsumeException ex)
{
logger.LogError(ex, TopicName);
break;
}
catch (Exception ex)
{
logger.LogError(ex, TopicName);
break;
}
}
});
}).Start();
}

public void Subscribe()


+ 5
- 2
src/JT808.Gateway.Kafka/JT808MsgReplyLoggingConsumer.cs Parādīt failu

@@ -33,7 +33,7 @@ namespace JT808.Gateway.Kafka

public void OnMessage(Action<(string TerminalNo, byte[] Data)> callback)
{
Task.Run(() =>
new Thread(() =>
{
while (!Cts.IsCancellationRequested)
{
@@ -52,16 +52,19 @@ namespace JT808.Gateway.Kafka
catch (ConsumeException ex)
{
logger.LogError(ex, TopicName);
break;
}
catch (OperationCanceledException)
{
break;
}
catch (Exception ex)
{
logger.LogError(ex, TopicName);
break;
}
}
});
}).Start();
}

public void Subscribe()


+ 7
- 4
src/JT808.Gateway.Kafka/JT808SessionConsumer.cs Parādīt failu

@@ -33,7 +33,7 @@ namespace JT808.Gateway.Kafka

public void OnMessage(Action<(string Notice, string TerminalNo)> callback)
{
Task.Run(() =>
new Thread(() =>
{
while (!Cts.IsCancellationRequested)
{
@@ -49,20 +49,23 @@ namespace JT808.Gateway.Kafka
}
callback((data.Message.Key, data.Message.Value));
}
catch (ConsumeException ex)
catch (OperationCanceledException ex)
{
logger.LogError(ex, TopicName);
break;
}
catch (OperationCanceledException ex)
catch (ConsumeException ex)
{
logger.LogError(ex, TopicName);
break;
}
catch (Exception ex)
{
logger.LogError(ex, TopicName);
break;
}
}
});
}).Start();
}

public void Subscribe()


+ 1
- 1
src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808ReplyMessageHostedService.cs Parādīt failu

@@ -24,7 +24,7 @@ namespace JT808.Gateway.ReplyMessage
/// <param name="jT808MsgConsumer"></param>
public JT808ReplyMessageHostedService(
ILoggerFactory loggerFactory,
IJT808DownMessageHandler jT808ReplyMessageHandler,
IJT808DownMessageHandler jT808ReplyMessageHandler,
IJT808MsgReplyProducer jT808MsgReplyProducer,
IJT808MsgConsumer jT808MsgConsumer)
{


+ 2
- 2
src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808MsgReplyConsumer.cs Parādīt failu

@@ -34,7 +34,7 @@ namespace JT808.Gateway.NormalHosting.Impl

public void OnMessage(Action<(string TerminalNo, byte[] Data)> callback)
{
Task.Run(async () =>
new Thread(async () =>
{
while (!Cts.IsCancellationRequested)
{
@@ -48,7 +48,7 @@ namespace JT808.Gateway.NormalHosting.Impl
logger.LogError(ex, "");
}
}
}, Cts.Token);
}).Start();
}

public void Subscribe()


+ 2
- 2
src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808SessionConsumer.cs Parādīt failu

@@ -28,7 +28,7 @@ namespace JT808.Gateway.NormalHosting.Impl

public void OnMessage(Action<(string Notice, string TerminalNo)> callback)
{
Task.Run(async () =>
new Thread((async () =>
{
while (!Cts.IsCancellationRequested)
{
@@ -42,7 +42,7 @@ namespace JT808.Gateway.NormalHosting.Impl
logger.LogError(ex, "");
}
}
}, Cts.Token);
})).Start();
}

public void Unsubscribe()


+ 3
- 3
src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/JT808.Gateway.NormalHosting.csproj Parādīt failu

@@ -24,9 +24,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.0.4" />
</ItemGroup>
<ItemGroup>


+ 3
- 3
src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/JT808.Gateway.QueueHosting.csproj Parādīt failu

@@ -11,9 +11,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.0.4" />
</ItemGroup>

<ItemGroup>


+ 3
- 3
src/JT808.Gateway.Tests/JT808.Gateway.Test/JT808.Gateway.Test.csproj Parādīt failu

@@ -9,9 +9,9 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>


+ 12
- 0
src/JT808.Gateway.WebApiClientTool/JT808.Gateway.WebApiClientTool.xml Parādīt failu

@@ -33,6 +33,12 @@
</summary>
<returns></returns>
</member>
<member name="M:JT808.Gateway.WebApiClientTool.JT808HttpClient.SessionTcpByPage(System.Int32,System.Int32)">
<summary>
会话服务集合
</summary>
<returns></returns>
</member>
<member name="M:JT808.Gateway.WebApiClientTool.JT808HttpClient.QueryTcpSessionByTerminalPhoneNo(JT808.Gateway.Abstractions.Dtos.JT808TerminalPhoneNoDto)">
<summary>
会话服务-通过设备终端号查询对应会话信息
@@ -53,6 +59,12 @@
</summary>
<returns></returns>
</member>
<member name="M:JT808.Gateway.WebApiClientTool.JT808HttpClient.SessionUdpByPage(System.Int32,System.Int32)">
<summary>
会话服务集合
</summary>
<returns></returns>
</member>
<member name="M:JT808.Gateway.WebApiClientTool.JT808HttpClient.QueryUdpSessionByTerminalPhoneNo(JT808.Gateway.Abstractions.Dtos.JT808TerminalPhoneNoDto)">
<summary>
会话服务-通过设备终端号查询对应会话信息


+ 26
- 0
src/JT808.Gateway.WebApiClientTool/JT808HttpClient.cs Parādīt failu

@@ -56,6 +56,19 @@ namespace JT808.Gateway.WebApiClientTool
return value;
}

/// <summary>
/// 会话服务集合
/// </summary>
/// <returns></returns>
public async ValueTask<JT808ResultDto<JT808PageResult<List<JT808TcpSessionInfoDto>>>> SessionTcpByPage(int pageIndex=0,int pageSize=10)
{
var request = new HttpRequestMessage(HttpMethod.Get, $"{JT808GatewayConstants.JT808WebApiRouteTable.SessionTcpByPage}?pageIndex={pageIndex}&pageSize={pageSize}");
var response = await HttpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<JT808PageResult<List<JT808TcpSessionInfoDto>>>>();
return value;
}

/// <summary>
/// 会话服务-通过设备终端号查询对应会话信息
/// </summary>
@@ -94,6 +107,19 @@ namespace JT808.Gateway.WebApiClientTool
return value;
}

/// <summary>
/// 会话服务集合
/// </summary>
/// <returns></returns>
public async ValueTask<JT808ResultDto<JT808PageResult<List<JT808TcpSessionInfoDto>>>> SessionUdpByPage(int pageIndex = 0, int pageSize = 10)
{
var request = new HttpRequestMessage(HttpMethod.Get, $"{JT808GatewayConstants.JT808WebApiRouteTable.SessionUdpByPage}?pageIndex={pageIndex}&pageSize={pageSize}");
var response = await HttpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<JT808PageResult<List<JT808TcpSessionInfoDto>>>>();
return value;
}

/// <summary>
/// 会话服务-通过设备终端号查询对应会话信息
/// </summary>


+ 2
- 0
src/JT808.Gateway/JT808.Gateway.xml Parādīt failu

@@ -161,6 +161,7 @@
</summary>
<returns></returns>
</member>
<!-- Badly formed XML comment ignored for member "M:JT808.Gateway.JT808WebApi.SessionTcpByPage(System.Int32,System.Int32)" -->
<member name="M:JT808.Gateway.JT808WebApi.QueryTcpSessionByTerminalPhoneNo(JT808.Gateway.Abstractions.Dtos.JT808TerminalPhoneNoDto)">
<summary>
会话服务-通过设备终端号查询对应会话
@@ -181,6 +182,7 @@
</summary>
<returns></returns>
</member>
<!-- Badly formed XML comment ignored for member "M:JT808.Gateway.JT808WebApi.SessionUdpByPage(System.Int32,System.Int32)" -->
<member name="M:JT808.Gateway.JT808WebApi.QueryUdpSessionByTerminalPhoneNo(JT808.Gateway.Abstractions.Dtos.JT808TerminalPhoneNoDto)">
<summary>
会话服务-通过设备终端号查询对应会话


+ 91
- 0
src/JT808.Gateway/JT808WebApi.cs Parādīt failu

@@ -5,6 +5,7 @@ using JT808.Gateway.Services;
using JT808.Gateway.Session;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -110,6 +111,51 @@ namespace JT808.Gateway
return resultDto;
}

/// <summary>
/// 会话服务-Tcp分页会话查询
/// jt808api/Tcp/Session/SessionTcpByPage?pageIndex=0&pageSize10
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("Tcp/Session/SessionTcpByPage")]
[JT808Token]
public ActionResult<JT808ResultDto<JT808PageResult<List<JT808TcpSessionInfoDto>>>> SessionTcpByPage([FromQuery]int pageIndex=0, [FromQuery] int pageSize=10)
{
JT808ResultDto<JT808PageResult<List<JT808TcpSessionInfoDto>>> resultDto = new JT808ResultDto<JT808PageResult<List<JT808TcpSessionInfoDto>>>();
try
{
if (pageIndex < 0)
{
pageIndex = 0;
}
if (pageSize >= 1000)
{
pageSize = 1000;
}
JT808PageResult<List<JT808TcpSessionInfoDto>> pageResult = new JT808PageResult<List<JT808TcpSessionInfoDto>>();
IEnumerable<JT808TcpSession> sessionInfoDtos = SessionManager.GetTcpByPage();
pageResult.Data = sessionInfoDtos.Select(s => new JT808TcpSessionInfoDto
{
LastActiveTime = s.ActiveTime,
StartTime = s.StartTime,
TerminalPhoneNo = s.TerminalPhoneNo,
RemoteAddressIP = s.RemoteEndPoint.ToString(),
}).OrderByDescending(o => o.LastActiveTime).Skip(pageIndex* pageSize).Take(pageSize).ToList();
pageResult.Total = sessionInfoDtos.Count();
pageResult.PageIndex = pageIndex;
pageResult.PageSize = pageSize;
resultDto.Data = pageResult;
resultDto.Code = JT808ResultCode.Ok;
}
catch (Exception ex)
{
resultDto.Data = new JT808PageResult<List<JT808TcpSessionInfoDto>>();
resultDto.Code = JT808ResultCode.Error;
resultDto.Message = ex.StackTrace;
}
return resultDto;
}

/// <summary>
/// 会话服务-通过设备终端号查询对应会话
/// </summary>
@@ -198,6 +244,51 @@ namespace JT808.Gateway
return resultDto;
}

/// <summary>
/// 会话服务-Udp分页会话查询
/// jt808api/Udp/Session/SessionUdpByPage?pageIndex=0&pageSize10
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("Udp/Session/SessionUdpByPage")]
[JT808Token]
public ActionResult<JT808ResultDto<JT808PageResult<List<JT808UdpSessionInfoDto>>>> SessionUdpByPage([FromQuery] int pageIndex = 0, [FromQuery] int pageSize = 10)
{
JT808ResultDto<JT808PageResult<List<JT808UdpSessionInfoDto>>> resultDto = new JT808ResultDto<JT808PageResult<List<JT808UdpSessionInfoDto>>>();
try
{
if (pageIndex < 0)
{
pageIndex = 0;
}
if (pageSize >= 1000)
{
pageSize = 1000;
}
JT808PageResult<List<JT808UdpSessionInfoDto>> pageResult = new JT808PageResult<List<JT808UdpSessionInfoDto>>();
IEnumerable<JT808UdpSession> sessionInfoDtos = SessionManager.GetUdpByPage();
pageResult.Data = sessionInfoDtos.Select(s => new JT808UdpSessionInfoDto
{
LastActiveTime = s.ActiveTime,
StartTime = s.StartTime,
TerminalPhoneNo = s.TerminalPhoneNo,
RemoteAddressIP = s.RemoteEndPoint.ToString(),
}).OrderByDescending(o => o.LastActiveTime).Skip(pageIndex * pageSize).Take(pageSize).ToList();
pageResult.Total = sessionInfoDtos.Count();
pageResult.PageIndex = pageIndex;
pageResult.PageSize = pageSize;
resultDto.Data = pageResult;
resultDto.Code = JT808ResultCode.Ok;
}
catch (Exception ex)
{
resultDto.Data = new JT808PageResult<List<JT808UdpSessionInfoDto>>();
resultDto.Code = JT808ResultCode.Error;
resultDto.Message = ex.StackTrace;
}
return resultDto;
}

/// <summary>
/// 会话服务-通过设备终端号查询对应会话
/// </summary>


+ 21
- 0
src/JT808.Gateway/Session/JT808SessionManager.cs Parādīt failu

@@ -271,6 +271,17 @@ namespace JT808.Gateway.Session
return query.Select(s => (JT808TcpSession)s.Value).ToList();
}

public IEnumerable<JT808TcpSession> GetTcpByPage(Func<IJT808Session, bool> predicate = null)
{
var query = TerminalPhoneNoSessions.Where(w => w.Value.TransportProtocolType == JT808TransportProtocolType.tcp);
if (predicate != null)
{
query = query.Where(s => predicate(s.Value));
}
return query.Select(s => (JT808TcpSession)s.Value);
}


public List<JT808UdpSession> GetUdpAll(Func<IJT808Session, bool> predicate = null)
{
var query = TerminalPhoneNoSessions.Where(w => w.Value.TransportProtocolType == JT808TransportProtocolType.udp);
@@ -280,5 +291,15 @@ namespace JT808.Gateway.Session
}
return query.Select(s => (JT808UdpSession)s.Value).ToList();
}

public IEnumerable<JT808UdpSession> GetUdpByPage(Func<IJT808Session, bool> predicate = null)
{
var query = TerminalPhoneNoSessions.Where(w => w.Value.TransportProtocolType == JT808TransportProtocolType.udp);
if (predicate != null)
{
query = query.Where(s => predicate(s.Value));
}
return query.Select(s => (JT808UdpSession)s.Value);
}
}
}

+ 1
- 1
src/PipelineInfo.props Parādīt failu

@@ -8,7 +8,7 @@
<PackageProjectUrl>https://github.com/SmallChi/JT808Gateway</PackageProjectUrl>
<licenseUrl>https://github.com/SmallChi/JT808Gateway/blob/master/LICENSE</licenseUrl>
<license>https://github.com/SmallChi/JT808Gateway/blob/master/LICENSE</license>
<Version>1.1.8-preview1</Version>
<Version>1.1.8-preview2</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<AnalysisLevel>latest</AnalysisLevel>


||||||
x
 
000:0
Notiek ielāde…
Atcelt
Saglabāt