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.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
|
||||
@ -9,11 +9,13 @@ namespace JiShe.CollectBus.Protocol.Test
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
Console.WriteLine("TestProtocolPlugin ConfigureServices");
|
||||
context.Services.AddKeyedSingleton<IProtocolPlugin, TestProtocolPlugin>(nameof(TestProtocolPlugin));
|
||||
}
|
||||
|
||||
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||
{
|
||||
Console.WriteLine("TestProtocolPlugin Initialization");
|
||||
var protocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(TestProtocolPlugin));
|
||||
await protocol.LoadAsync();
|
||||
}
|
||||
|
||||
@ -9,13 +9,14 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H
|
||||
{
|
||||
/// <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;
|
||||
|
||||
@ -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.Abstracts;
|
||||
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.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog.Core;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using TouchSocket.Core;
|
||||
using Volo.Abp;
|
||||
@ -18,16 +21,30 @@ namespace JiShe.CollectBus.Protocol
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
Console.WriteLine("StandardProtocolPlugin ConfigureServices");
|
||||
context.Services.AddKeyedSingleton<IProtocolPlugin, StandardProtocolPlugin>(nameof(StandardProtocolPlugin));
|
||||
RegisterProtocolAnalysis(context.Services);
|
||||
//RegisterProtocolAnalysis(context.Services);
|
||||
LoadAnalysisStrategy(context.Services);
|
||||
}
|
||||
|
||||
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||
{
|
||||
Console.WriteLine("StandardProtocolPlugin Initialization");
|
||||
var standardProtocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(StandardProtocolPlugin));
|
||||
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)
|
||||
{
|
||||
// 扫描并注册所有策略
|
||||
|
||||
@ -26,6 +26,8 @@ using System.Linq;
|
||||
using Cassandra;
|
||||
using JiShe.CollectBus.Interceptors;
|
||||
using JiShe.CollectBus.IotSystems.Protocols;
|
||||
using TouchSocket.Core;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace JiShe.CollectBus.Samples;
|
||||
|
||||
@ -36,16 +38,19 @@ public class TestAppService : CollectBusAppService
|
||||
private readonly ICassandraRepository<MessageIssued, string> _messageReceivedCassandraRepository;
|
||||
private readonly ICassandraProvider _cassandraProvider;
|
||||
private readonly IProtocolService _protocolService;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
|
||||
public TestAppService(
|
||||
ILogger<TestAppService> logger,
|
||||
ICassandraRepository<MessageIssued, string> messageReceivedCassandraRepository,
|
||||
ICassandraProvider cassandraProvider, IProtocolService protocolService)
|
||||
ICassandraProvider cassandraProvider, IProtocolService protocolService,IServiceProvider serviceProvider)
|
||||
{
|
||||
_logger = logger;
|
||||
_messageReceivedCassandraRepository = messageReceivedCassandraRepository;
|
||||
_cassandraProvider = cassandraProvider;
|
||||
_protocolService = protocolService;
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
public async Task AddMessageOfCassandra()
|
||||
{
|
||||
@ -137,4 +142,10 @@ public class TestAppService : CollectBusAppService
|
||||
var protocol = await _protocolService.FirstOrDefaultByDeviceAsync(deviceCode, isSpecial);
|
||||
return protocol;
|
||||
}
|
||||
|
||||
// 重新加载插件方法
|
||||
public async Task ReloadPluginsAsync()
|
||||
{
|
||||
//_serviceProvider.GetService<>()
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ using JiShe.CollectBus.IoTDB.Provider;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using System.Collections;
|
||||
using JiShe.CollectBus.Interfaces;
|
||||
using System.CodeDom.Compiler;
|
||||
|
||||
namespace JiShe.CollectBus.Subscribers
|
||||
{
|
||||
@ -206,8 +207,8 @@ namespace JiShe.CollectBus.Subscribers
|
||||
//var analysisStrategy = _serviceProvider.GetKeyedService<IAnalysisStrategy>($"AFN0_F1_Analysis");
|
||||
|
||||
//var data = await analysisStrategy.ExecuteAsync<UnitDataDto<AFN0_F1_AnalysisDto>>(tB3761);
|
||||
var executor = _serviceProvider.GetRequiredService<AnalysisStrategyContext>();
|
||||
AFN0_F1_AnalysisDto aFN0_F1_AnalysisDto= await executor.ExecuteAsync<TB3761,AFN0_F1_AnalysisDto>("AFN0_F1_Analysis", tB3761);
|
||||
var result = _serviceProvider.GetRequiredKeyedService<IAnalysisStrategy<TB3761, AFN0_F1_AnalysisDto>>("AFN0_F1_Analysis");
|
||||
//AFN0_F1_AnalysisDto aFN0_F1_AnalysisDto = await executor.ExecuteAsync<TB3761, Object>("AFN0_F1_Analysis", tB3761);
|
||||
}
|
||||
|
||||
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",
|
||||
"Serilog.AspNetCore": "Information",
|
||||
"Microsoft.EntityFrameworkCore": "Warning",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.AspNetCore.Diagnostics.HealthChecks": "Warning"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
@ -79,8 +80,8 @@
|
||||
"SaslPassword": "lixiao1980",
|
||||
"KafkaReplicationFactor": 3,
|
||||
"NumPartitions": 30,
|
||||
"ServerTagName": "JiSheCollectBus30",
|
||||
"FirstCollectionTime": "2025-04-23 11:11:00"
|
||||
"ServerTagName": "JiSheCollectBus100",
|
||||
"FirstCollectionTime": "2025-04-22 16:07:00"
|
||||
},
|
||||
"IoTDBOptions": {
|
||||
"UserName": "root",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user