Compare commits
2 Commits
41d71a5fba
...
7adee9f257
| Author | SHA1 | Date | |
|---|---|---|---|
| 7adee9f257 | |||
| d4ae0d2a1d |
@ -1,4 +1,6 @@
|
|||||||
using JiShe.CollectBus.Common.Extensions;
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using JiShe.CollectBus.Common.Extensions;
|
||||||
using JiShe.CollectBus.IotSystems.Protocols;
|
using JiShe.CollectBus.IotSystems.Protocols;
|
||||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||||
|
|||||||
@ -9,11 +9,13 @@ namespace JiShe.CollectBus.Protocol.Test
|
|||||||
{
|
{
|
||||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("TestProtocolPlugin ConfigureServices");
|
||||||
context.Services.AddKeyedSingleton<IProtocolPlugin, TestProtocolPlugin>(nameof(TestProtocolPlugin));
|
context.Services.AddKeyedSingleton<IProtocolPlugin, TestProtocolPlugin>(nameof(TestProtocolPlugin));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("TestProtocolPlugin Initialization");
|
||||||
var protocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(TestProtocolPlugin));
|
var protocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(TestProtocolPlugin));
|
||||||
await protocol.LoadAsync();
|
await protocol.LoadAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,13 +9,14 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Volo.Abp.DependencyInjection;
|
||||||
|
|
||||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H
|
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 全部确认:对收到报文中的全部数据单元标识进行确认
|
/// 全部确认:对收到报文中的全部数据单元标识进行确认
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AFN0_F1_Analysis: IAnalysisStrategy<TB3761, AFN0_F1_AnalysisDto>
|
public class AFN0_F1_Analysis : IAnalysisStrategy<TB3761, AFN0_F1_AnalysisDto>
|
||||||
{
|
{
|
||||||
private readonly ILogger<AFN0_F1_Analysis> _logger;
|
private readonly ILogger<AFN0_F1_Analysis> _logger;
|
||||||
|
|
||||||
@ -45,4 +46,37 @@ namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class AFN0_F2_Analysis : IAnalysisStrategy<TB3761, AFN0_F1_AnalysisDto>
|
||||||
|
{
|
||||||
|
private readonly ILogger<AFN0_F1_Analysis> _logger;
|
||||||
|
|
||||||
|
public AFN0_F2_Analysis(ILogger<AFN0_F1_Analysis> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<AFN0_F1_AnalysisDto> ExecuteAsync(TB3761 tB3761)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(nameof(tB3761));
|
||||||
|
AFN0_F1_AnalysisDto dto = new AFN0_F1_AnalysisDto
|
||||||
|
{
|
||||||
|
Code = tB3761.A?.Code,
|
||||||
|
AFN = tB3761.AFN_FC?.AFN ?? 0,
|
||||||
|
Fn = tB3761.DT?.Fn ?? 0,
|
||||||
|
Pn = tB3761.DA?.Pn ?? 0
|
||||||
|
};
|
||||||
|
return Task.FromResult(dto);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, $"00_1解析失败:{tB3761.A?.Code}-{tB3761.DT?.Fn ?? 0}-{tB3761?.BaseHexMessage?.HexMessageString},{ex.Message}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,13 @@ using JiShe.CollectBus.Protocol.AnalysisData;
|
|||||||
using JiShe.CollectBus.Protocol.Contracts;
|
using JiShe.CollectBus.Protocol.Contracts;
|
||||||
using JiShe.CollectBus.Protocol.Contracts.Abstracts;
|
using JiShe.CollectBus.Protocol.Contracts.Abstracts;
|
||||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||||
|
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||||
|
using JiShe.CollectBus.Protocol.Dto;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Serilog.Core;
|
using Serilog.Core;
|
||||||
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using TouchSocket.Core;
|
using TouchSocket.Core;
|
||||||
using Volo.Abp;
|
using Volo.Abp;
|
||||||
@ -18,16 +21,30 @@ namespace JiShe.CollectBus.Protocol
|
|||||||
{
|
{
|
||||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("StandardProtocolPlugin ConfigureServices");
|
||||||
context.Services.AddKeyedSingleton<IProtocolPlugin, StandardProtocolPlugin>(nameof(StandardProtocolPlugin));
|
context.Services.AddKeyedSingleton<IProtocolPlugin, StandardProtocolPlugin>(nameof(StandardProtocolPlugin));
|
||||||
RegisterProtocolAnalysis(context.Services);
|
//RegisterProtocolAnalysis(context.Services);
|
||||||
|
LoadAnalysisStrategy(context.Services);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("StandardProtocolPlugin Initialization");
|
||||||
var standardProtocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(StandardProtocolPlugin));
|
var standardProtocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(StandardProtocolPlugin));
|
||||||
await standardProtocol.LoadAsync();
|
await standardProtocol.LoadAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void LoadAnalysisStrategy(IServiceCollection services)
|
||||||
|
{
|
||||||
|
var assembly = Assembly.GetExecutingAssembly();
|
||||||
|
var analysisStrategyTypes = assembly.GetTypes().Where(t => !t.IsAbstract && !t.IsInterface && t.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IAnalysisStrategy<,>)));
|
||||||
|
foreach (var analysisStrategyType in analysisStrategyTypes)
|
||||||
|
{
|
||||||
|
var service = analysisStrategyType.GetInterfaces().First();
|
||||||
|
services.AddKeyedSingleton(service, analysisStrategyType.Name,analysisStrategyType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void RegisterProtocolAnalysis(IServiceCollection services)
|
public void RegisterProtocolAnalysis(IServiceCollection services)
|
||||||
{
|
{
|
||||||
// 扫描并注册所有策略
|
// 扫描并注册所有策略
|
||||||
|
|||||||
@ -26,6 +26,8 @@ using System.Linq;
|
|||||||
using Cassandra;
|
using Cassandra;
|
||||||
using JiShe.CollectBus.Interceptors;
|
using JiShe.CollectBus.Interceptors;
|
||||||
using JiShe.CollectBus.IotSystems.Protocols;
|
using JiShe.CollectBus.IotSystems.Protocols;
|
||||||
|
using TouchSocket.Core;
|
||||||
|
using Volo.Abp.Modularity;
|
||||||
|
|
||||||
namespace JiShe.CollectBus.Samples;
|
namespace JiShe.CollectBus.Samples;
|
||||||
|
|
||||||
@ -36,16 +38,19 @@ public class TestAppService : CollectBusAppService
|
|||||||
private readonly ICassandraRepository<MessageIssued, string> _messageReceivedCassandraRepository;
|
private readonly ICassandraRepository<MessageIssued, string> _messageReceivedCassandraRepository;
|
||||||
private readonly ICassandraProvider _cassandraProvider;
|
private readonly ICassandraProvider _cassandraProvider;
|
||||||
private readonly IProtocolService _protocolService;
|
private readonly IProtocolService _protocolService;
|
||||||
|
private readonly IServiceProvider _serviceProvider;
|
||||||
|
|
||||||
|
|
||||||
public TestAppService(
|
public TestAppService(
|
||||||
ILogger<TestAppService> logger,
|
ILogger<TestAppService> logger,
|
||||||
ICassandraRepository<MessageIssued, string> messageReceivedCassandraRepository,
|
ICassandraRepository<MessageIssued, string> messageReceivedCassandraRepository,
|
||||||
ICassandraProvider cassandraProvider, IProtocolService protocolService)
|
ICassandraProvider cassandraProvider, IProtocolService protocolService,IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_messageReceivedCassandraRepository = messageReceivedCassandraRepository;
|
_messageReceivedCassandraRepository = messageReceivedCassandraRepository;
|
||||||
_cassandraProvider = cassandraProvider;
|
_cassandraProvider = cassandraProvider;
|
||||||
_protocolService = protocolService;
|
_protocolService = protocolService;
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
public async Task AddMessageOfCassandra()
|
public async Task AddMessageOfCassandra()
|
||||||
{
|
{
|
||||||
@ -137,4 +142,10 @@ public class TestAppService : CollectBusAppService
|
|||||||
var protocol = await _protocolService.FirstOrDefaultByDeviceAsync(deviceCode, isSpecial);
|
var protocol = await _protocolService.FirstOrDefaultByDeviceAsync(deviceCode, isSpecial);
|
||||||
return protocol;
|
return protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 重新加载插件方法
|
||||||
|
public async Task ReloadPluginsAsync()
|
||||||
|
{
|
||||||
|
//_serviceProvider.GetService<>()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,7 @@ using JiShe.CollectBus.IoTDB.Provider;
|
|||||||
using JiShe.CollectBus.Protocol.Dto;
|
using JiShe.CollectBus.Protocol.Dto;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using JiShe.CollectBus.Interfaces;
|
using JiShe.CollectBus.Interfaces;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
|
||||||
namespace JiShe.CollectBus.Subscribers
|
namespace JiShe.CollectBus.Subscribers
|
||||||
{
|
{
|
||||||
@ -206,8 +207,8 @@ namespace JiShe.CollectBus.Subscribers
|
|||||||
//var analysisStrategy = _serviceProvider.GetKeyedService<IAnalysisStrategy>($"AFN0_F1_Analysis");
|
//var analysisStrategy = _serviceProvider.GetKeyedService<IAnalysisStrategy>($"AFN0_F1_Analysis");
|
||||||
|
|
||||||
//var data = await analysisStrategy.ExecuteAsync<UnitDataDto<AFN0_F1_AnalysisDto>>(tB3761);
|
//var data = await analysisStrategy.ExecuteAsync<UnitDataDto<AFN0_F1_AnalysisDto>>(tB3761);
|
||||||
var executor = _serviceProvider.GetRequiredService<AnalysisStrategyContext>();
|
var result = _serviceProvider.GetRequiredKeyedService<IAnalysisStrategy<TB3761, AFN0_F1_AnalysisDto>>("AFN0_F1_Analysis");
|
||||||
AFN0_F1_AnalysisDto aFN0_F1_AnalysisDto= await executor.ExecuteAsync<TB3761,AFN0_F1_AnalysisDto>("AFN0_F1_Analysis", tB3761);
|
//AFN0_F1_AnalysisDto aFN0_F1_AnalysisDto = await executor.ExecuteAsync<TB3761, Object>("AFN0_F1_Analysis", tB3761);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SubscribeAck.Success();
|
return SubscribeAck.Success();
|
||||||
|
|||||||
BIN
web/JiShe.CollectBus.Host/JiShe.CollectBus.Protocol.Test.dll
Normal file
BIN
web/JiShe.CollectBus.Host/JiShe.CollectBus.Protocol.Test.dll
Normal file
Binary file not shown.
BIN
web/JiShe.CollectBus.Host/JiShe.CollectBus.Protocol.dll
Normal file
BIN
web/JiShe.CollectBus.Host/JiShe.CollectBus.Protocol.dll
Normal file
Binary file not shown.
@ -13,7 +13,8 @@
|
|||||||
"DotNetCore.CAP": "Warning",
|
"DotNetCore.CAP": "Warning",
|
||||||
"Serilog.AspNetCore": "Information",
|
"Serilog.AspNetCore": "Information",
|
||||||
"Microsoft.EntityFrameworkCore": "Warning",
|
"Microsoft.EntityFrameworkCore": "Warning",
|
||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning",
|
||||||
|
"Microsoft.AspNetCore.Diagnostics.HealthChecks": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"WriteTo": [
|
"WriteTo": [
|
||||||
@ -79,8 +80,8 @@
|
|||||||
"SaslPassword": "lixiao1980",
|
"SaslPassword": "lixiao1980",
|
||||||
"KafkaReplicationFactor": 3,
|
"KafkaReplicationFactor": 3,
|
||||||
"NumPartitions": 30,
|
"NumPartitions": 30,
|
||||||
"ServerTagName": "JiSheCollectBus30",
|
"ServerTagName": "JiSheCollectBus100",
|
||||||
"FirstCollectionTime": "2025-04-23 11:11:00"
|
"FirstCollectionTime": "2025-04-22 16:07:00"
|
||||||
},
|
},
|
||||||
"IoTDBOptions": {
|
"IoTDBOptions": {
|
||||||
"UserName": "root",
|
"UserName": "root",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user