修改代码
This commit is contained in:
parent
bf4f631a8c
commit
5adabb3b7e
@ -0,0 +1,6 @@
|
|||||||
|
namespace JiShe.CollectBus.Protocol.Contracts.ProtocolPools
|
||||||
|
{
|
||||||
|
public interface IPluginContainer
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
using JiShe.CollectBus.Interfaces;
|
||||||
|
|
||||||
|
namespace JiShe.CollectBus.Protocol.Contracts.ProtocolPools
|
||||||
|
{
|
||||||
|
public class PluginContainer: IPluginContainer
|
||||||
|
{
|
||||||
|
public Dictionary<string, object> ProtocolPools;
|
||||||
|
|
||||||
|
public PluginContainer()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ServiceProviderKeyedServiceExtensions
|
||||||
|
{
|
||||||
|
//public static Task AddKeyedSingleton<TImp>(this IServiceProvider provider, string key)
|
||||||
|
//{
|
||||||
|
// //var aa = Activator.CreateInstance<TImp>();
|
||||||
|
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,7 +18,6 @@ namespace JiShe.CollectBus.Protocol.Test
|
|||||||
{
|
{
|
||||||
Console.WriteLine("TestProtocolPlugin OnApplicationInitializationAsync");
|
Console.WriteLine("TestProtocolPlugin OnApplicationInitializationAsync");
|
||||||
var protocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(TestProtocolPlugin));
|
var protocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(TestProtocolPlugin));
|
||||||
RemoveServiceAtRuntime(context.ServiceProvider);
|
|
||||||
await protocol.LoadAsync();
|
await protocol.LoadAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,19 +26,5 @@ namespace JiShe.CollectBus.Protocol.Test
|
|||||||
Console.WriteLine("TestProtocolPlugin OnApplicationShutdown");
|
Console.WriteLine("TestProtocolPlugin OnApplicationShutdown");
|
||||||
base.OnApplicationShutdown(context);
|
base.OnApplicationShutdown(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveServiceAtRuntime(IServiceProvider serviceProvider)
|
|
||||||
{
|
|
||||||
var services = serviceProvider.GetService<IServiceCollection>();
|
|
||||||
services?.AddKeyedSingleton<IProtocolPlugin, TestProtocolPlugin>(nameof(TestProtocolPlugin));
|
|
||||||
|
|
||||||
|
|
||||||
//var services = (IServiceCollection)serviceProvider.GetService(typeof(IServiceCollection));
|
|
||||||
//var pluginService = serviceProvider.GetKeyedService<IProtocolPlugin>(nameof(TestProtocolPlugin));
|
|
||||||
//if (services != null && pluginService!=null)
|
|
||||||
//{
|
|
||||||
// services.Remove(pluginService);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@ namespace JiShe.CollectBus.Protocol.Test
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed override ProtocolInfo Info => new(nameof(TestProtocolPlugin), "Test", "TCP", "Test协议", "DTS1980-TEST");
|
public sealed override ProtocolInfo Info => new(nameof(TestProtocolPlugin), "Test", "TCP", "Test协议", "DTS1980-TEST-01");
|
||||||
|
|
||||||
public override Task<T> AnalyzeAsync<T>(ITcpSessionClient client, string messageReceived, Action<T>? receivedAction = null)
|
public override Task<T> AnalyzeAsync<T>(ITcpSessionClient client, string messageReceived, Action<T>? receivedAction = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,34 +1,24 @@
|
|||||||
using JiShe.CollectBus.Common.Consts;
|
using System.Linq;
|
||||||
using JiShe.CollectBus.Common.Extensions;
|
|
||||||
using JiShe.CollectBus.FreeSql;
|
|
||||||
using JiShe.CollectBus.Kafka;
|
|
||||||
using JiShe.CollectBus.Kafka.AdminClient;
|
|
||||||
using JiShe.CollectBus.Protocol.Contracts;
|
|
||||||
using JiShe.CollectBus.ScheduledMeterReading;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Cassandra.Mapping;
|
using Cassandra.Mapping;
|
||||||
using JiShe.CollectBus.Cassandra;
|
using JiShe.CollectBus.Cassandra;
|
||||||
using JiShe.CollectBus.FreeRedis;
|
using JiShe.CollectBus.FreeRedis;
|
||||||
|
using JiShe.CollectBus.FreeSql;
|
||||||
|
using JiShe.CollectBus.Interceptors;
|
||||||
using JiShe.CollectBus.IoTDB;
|
using JiShe.CollectBus.IoTDB;
|
||||||
|
using JiShe.CollectBus.Kafka;
|
||||||
using JiShe.CollectBus.Mappers;
|
using JiShe.CollectBus.Mappers;
|
||||||
|
using JiShe.CollectBus.Protocol.Contracts;
|
||||||
|
using JiShe.CollectBus.ScheduledMeterReading;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Volo.Abp;
|
using Volo.Abp;
|
||||||
using Volo.Abp.Application;
|
using Volo.Abp.Application;
|
||||||
using Volo.Abp.Autofac;
|
using Volo.Abp.Autofac;
|
||||||
using Volo.Abp.AutoMapper;
|
using Volo.Abp.AutoMapper;
|
||||||
using Volo.Abp.BackgroundWorkers;
|
using Volo.Abp.BackgroundWorkers;
|
||||||
using Volo.Abp.BackgroundWorkers.Hangfire;
|
using Volo.Abp.BackgroundWorkers.Hangfire;
|
||||||
using Volo.Abp.EventBus;
|
|
||||||
using Volo.Abp.Modularity;
|
using Volo.Abp.Modularity;
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using JiShe.CollectBus.Kafka.Internal;
|
|
||||||
using JiShe.CollectBus.Interceptors;
|
|
||||||
using JiShe.CollectBus.Common.Attributes;
|
|
||||||
using ZstdSharp.Unsafe;
|
|
||||||
|
|
||||||
namespace JiShe.CollectBus;
|
namespace JiShe.CollectBus;
|
||||||
|
|
||||||
@ -45,7 +35,7 @@ namespace JiShe.CollectBus;
|
|||||||
typeof(CollectBusIoTDbModule),
|
typeof(CollectBusIoTDbModule),
|
||||||
typeof(CollectBusCassandraModule),
|
typeof(CollectBusCassandraModule),
|
||||||
typeof(CollectBusProtocolModule)
|
typeof(CollectBusProtocolModule)
|
||||||
)]
|
)]
|
||||||
public class CollectBusApplicationModule : AbpModule
|
public class CollectBusApplicationModule : AbpModule
|
||||||
{
|
{
|
||||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||||
@ -53,10 +43,7 @@ public class CollectBusApplicationModule : AbpModule
|
|||||||
var configuration = context.Services.GetConfiguration();
|
var configuration = context.Services.GetConfiguration();
|
||||||
|
|
||||||
context.Services.AddAutoMapperObjectMapper<CollectBusApplicationModule>();
|
context.Services.AddAutoMapperObjectMapper<CollectBusApplicationModule>();
|
||||||
Configure<AbpAutoMapperOptions>(options =>
|
Configure<AbpAutoMapperOptions>(options => { options.AddMaps<CollectBusApplicationModule>(true); });
|
||||||
{
|
|
||||||
options.AddMaps<CollectBusApplicationModule>(validate: true);
|
|
||||||
});
|
|
||||||
|
|
||||||
context.Services.AddSingleton(new MappingConfiguration()
|
context.Services.AddSingleton(new MappingConfiguration()
|
||||||
.Define(new CollectBusMapping()));
|
.Define(new CollectBusMapping()));
|
||||||
@ -65,11 +52,8 @@ public class CollectBusApplicationModule : AbpModule
|
|||||||
context.Services.OnRegistered(ctx =>
|
context.Services.OnRegistered(ctx =>
|
||||||
{
|
{
|
||||||
var methods = ctx.ImplementationType.GetMethods();
|
var methods = ctx.ImplementationType.GetMethods();
|
||||||
var any = methods.Any(a=>a.GetCustomAttribute<LogInterceptAttribute>()!=null);
|
var any = methods.Any(a => a.GetCustomAttribute<LogInterceptAttribute>() != null);
|
||||||
if (any)
|
if (any) ctx.Interceptors.TryAdd<LogInterceptor>();
|
||||||
{
|
|
||||||
ctx.Interceptors.TryAdd<LogInterceptor>();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,11 +61,9 @@ public class CollectBusApplicationModule : AbpModule
|
|||||||
ApplicationInitializationContext context)
|
ApplicationInitializationContext context)
|
||||||
{
|
{
|
||||||
var assembly = Assembly.GetExecutingAssembly();
|
var assembly = Assembly.GetExecutingAssembly();
|
||||||
var types = assembly.GetTypes().Where(t => typeof(ICollectWorker).IsAssignableFrom(t) && !t.IsInterface).ToList();
|
var types = assembly.GetTypes().Where(t => typeof(ICollectWorker).IsAssignableFrom(t) && !t.IsInterface)
|
||||||
foreach (var type in types)
|
.ToList();
|
||||||
{
|
foreach (var type in types) await context.AddBackgroundWorkerAsync(type);
|
||||||
await context.AddBackgroundWorkerAsync(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
@ -90,7 +72,5 @@ public class CollectBusApplicationModule : AbpModule
|
|||||||
dbContext.InitAmmeterCacheData();
|
dbContext.InitAmmeterCacheData();
|
||||||
//await dbContext.InitWatermeterCacheData();
|
//await dbContext.InitWatermeterCacheData();
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -31,30 +31,6 @@ namespace JiShe.CollectBus.DynamicModule
|
|||||||
return _moduleContainer.Modules.Select(m => m.Type).ToArray();
|
return _moduleContainer.Modules.Select(m => m.Type).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task InitializeModuleAsync(Type moduleType)
|
|
||||||
{
|
|
||||||
//if (!typeof(IAbpModule).IsAssignableFrom(moduleType))
|
|
||||||
//{
|
|
||||||
// throw new ArgumentException($"指定的类型 {moduleType.FullName} 不是有效的ABP模块类型", nameof(moduleType));
|
|
||||||
//}
|
|
||||||
|
|
||||||
//var module = (IAbpModule)Activator.CreateInstance(moduleType);
|
|
||||||
|
|
||||||
//// 配置服务
|
|
||||||
//var configureServicesMethod = moduleType.GetMethod("ConfigureServices",
|
|
||||||
// BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
|
|
||||||
|
|
||||||
//if (configureServicesMethod != null)
|
|
||||||
//{
|
|
||||||
// var serviceConfigurationContext = CreateServiceConfigurationContext();
|
|
||||||
// configureServicesMethod.Invoke(module, new object[] { serviceConfigurationContext });
|
|
||||||
//}
|
|
||||||
|
|
||||||
//await CallModuleMethodAsync(module, "OnApplicationInitializationAsync", new object[] { new ApplicationInitializationContext(_serviceProvider) });
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task ReinitializeModuleAsync(Type moduleType)
|
public async Task ReinitializeModuleAsync(Type moduleType)
|
||||||
{
|
{
|
||||||
if (!typeof(IAbpModule).IsAssignableFrom(moduleType))
|
if (!typeof(IAbpModule).IsAssignableFrom(moduleType))
|
||||||
@ -70,16 +46,14 @@ namespace JiShe.CollectBus.DynamicModule
|
|||||||
|
|
||||||
var module = moduleDescriptor.Instance;
|
var module = moduleDescriptor.Instance;
|
||||||
|
|
||||||
await CallModuleMethodAsync(module, "OnApplicationShutdown", new object[] { new ApplicationShutdownContext(_serviceProvider) });
|
await CallModuleMethodAsync(module, "OnApplicationShutdown", [new ApplicationShutdownContext(_serviceProvider)]);
|
||||||
//var configureServicesMethod = moduleType.GetMethod("ConfigureServices",
|
var configureServicesMethod = moduleType.GetMethod("ConfigureServices",BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
|
||||||
// BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
|
if (configureServicesMethod != null)
|
||||||
|
{
|
||||||
//if (configureServicesMethod != null)
|
var serviceConfigurationContext = CreateServiceConfigurationContext();
|
||||||
//{
|
configureServicesMethod.Invoke(module, [serviceConfigurationContext]);
|
||||||
// var serviceConfigurationContext = CreateServiceConfigurationContext();
|
}
|
||||||
// configureServicesMethod.Invoke(module, new object[] { serviceConfigurationContext });
|
await CallModuleMethodAsync(module, "OnApplicationInitializationAsync", [new ApplicationInitializationContext(_serviceProvider)]);
|
||||||
//}
|
|
||||||
await CallModuleMethodAsync(module, "OnApplicationInitializationAsync", new object[] { new ApplicationInitializationContext(_serviceProvider) });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UnloadModuleAsync(Type moduleType)
|
public async Task UnloadModuleAsync(Type moduleType)
|
||||||
@ -157,7 +131,7 @@ namespace JiShe.CollectBus.DynamicModule
|
|||||||
services.Add(service);
|
services.Add(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (ServiceConfigurationContext)constructor.Invoke(new object[] { services });
|
return (ServiceConfigurationContext)constructor.Invoke([services]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果反射失败,使用备选方案
|
// 如果反射失败,使用备选方案
|
||||||
|
|||||||
@ -141,5 +141,5 @@
|
|||||||
"DefaultIdempotence": true
|
"DefaultIdempotence": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"PlugInFolder": ""
|
"PlugInFolder": "C:\\Users\\Dai Zan\\Desktop\\Plugins"
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user