Browse Source

Merge pull request #11143 from abpframework/auto-merge/rel-5-0/757

Merge branch dev with rel-5.0
pull/11145/head
liangshiwei 4 years ago
committed by GitHub
parent
commit
8e5b2e05a1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/AbpBackgroundWorkersHangfireModule.cs
  2. 22
      framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs
  3. 36
      framework/src/Volo.Abp.BackgroundWorkers.Quartz/Volo/Abp/BackgroundWorkers/Quartz/QuartzPeriodicBackgroundWorkerAdapter.cs
  4. 7
      framework/src/Volo.Abp.Core/Volo/Abp/Options/PreConfigureActionList.cs
  5. 9
      framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs
  6. 3
      framework/src/Volo.Abp.HangFire/Volo/Abp/Hangfire/AbpHangfireModule.cs
  7. 5
      framework/src/Volo.Abp.Json/Volo/Abp/Json/AbpJsonModule.cs
  8. 10
      framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs

2
framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/AbpBackgroundWorkersHangfireModule.cs

@ -10,7 +10,7 @@ namespace Volo.Abp.BackgroundWorkers.Hangfire;
[DependsOn( [DependsOn(
typeof(AbpBackgroundWorkersModule), typeof(AbpBackgroundWorkersModule),
typeof(AbpHangfireModule))] typeof(AbpHangfireModule))]
public class AbpBackgroundWorkerHangfireModule : AbpModule public class AbpBackgroundWorkersHangfireModule : AbpModule
{ {
public override void OnPreApplicationInitialization(ApplicationInitializationContext context) public override void OnPreApplicationInitialization(ApplicationInitializationContext context)
{ {

22
framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs

@ -21,7 +21,7 @@ public class HangfireBackgroundWorkerManager : IBackgroundWorkerManager, ISingle
return Task.CompletedTask; return Task.CompletedTask;
} }
public async Task AddAsync(IBackgroundWorker worker) public Task AddAsync(IBackgroundWorker worker)
{ {
if (worker is IHangfireBackgroundWorker hangfireBackgroundWorker) if (worker is IHangfireBackgroundWorker hangfireBackgroundWorker)
{ {
@ -42,18 +42,26 @@ public class HangfireBackgroundWorkerManager : IBackgroundWorkerManager, ISingle
if (worker is AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase) if (worker is AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase)
{ {
var timer = (AbpAsyncTimer) worker.GetType() var timer = worker.GetType()
.GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker); .GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker);
period = timer?.Period;
if (worker is AsyncPeriodicBackgroundWorkerBase)
{
period = ((AbpAsyncTimer)timer)?.Period;
}
else
{
period = ((AbpTimer)timer)?.Period;
}
} }
else else
{ {
return; return Task.CompletedTask;
} }
if (period == null) if (period == null)
{ {
return; return Task.CompletedTask;
} }
var adapterType = typeof(HangfirePeriodicBackgroundWorkerAdapter<>).MakeGenericType(worker.GetType()); var adapterType = typeof(HangfirePeriodicBackgroundWorkerAdapter<>).MakeGenericType(worker.GetType());
@ -61,6 +69,8 @@ public class HangfireBackgroundWorkerManager : IBackgroundWorkerManager, ISingle
RecurringJob.AddOrUpdate(() => workerAdapter.DoWorkAsync(), GetCron(period.Value)); RecurringJob.AddOrUpdate(() => workerAdapter.DoWorkAsync(), GetCron(period.Value));
} }
return Task.CompletedTask;
} }
protected virtual string GetCron(int period) protected virtual string GetCron(int period)
@ -82,7 +92,7 @@ public class HangfireBackgroundWorkerManager : IBackgroundWorkerManager, ISingle
} }
else else
{ {
cron = $"0 0 */{time.TotalDays} * *"; throw new AbpException($"Cannot convert period: {period} to cron expression, use HangfireBackgroundWorkerBase to define worker");
} }
return cron; return cron;

36
framework/src/Volo.Abp.BackgroundWorkers.Quartz/Volo/Abp/BackgroundWorkers/Quartz/QuartzPeriodicBackgroundWorkerAdapter.cs

@ -28,15 +28,23 @@ public class QuartzPeriodicBackgroundWorkerAdapter<TWorker> : QuartzBackgroundWo
int? period; int? period;
var workerType = worker.GetType(); var workerType = worker.GetType();
if (worker is AsyncPeriodicBackgroundWorkerBase || worker is PeriodicBackgroundWorkerBase) if (worker is AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase)
{ {
if (typeof(TWorker) != worker.GetType()) if (typeof(TWorker) != worker.GetType())
{ {
throw new ArgumentException($"{nameof(worker)} type is different from the generic type"); throw new ArgumentException($"{nameof(worker)} type is different from the generic type");
} }
var timer = (AbpAsyncTimer)worker.GetType().GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker); var timer = worker.GetType().GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker);
period = timer?.Period;
if (worker is AsyncPeriodicBackgroundWorkerBase)
{
period = ((AbpAsyncTimer)timer)?.Period;
}
else
{
period = ((AbpTimer)timer)?.Period;
}
} }
else else
{ {
@ -60,26 +68,26 @@ public class QuartzPeriodicBackgroundWorkerAdapter<TWorker> : QuartzBackgroundWo
public override async Task Execute(IJobExecutionContext context) public override async Task Execute(IJobExecutionContext context)
{ {
var worker = (IBackgroundWorker)ServiceProvider.GetService(typeof(TWorker)); var worker = (IBackgroundWorker) ServiceProvider.GetService(typeof(TWorker));
var workerContext = new PeriodicBackgroundWorkerContext(ServiceProvider); var workerContext = new PeriodicBackgroundWorkerContext(ServiceProvider);
switch (worker) switch (worker)
{ {
case AsyncPeriodicBackgroundWorkerBase asyncWorker: case AsyncPeriodicBackgroundWorkerBase asyncWorker:
{
if (_doWorkAsyncMethod != null)
{ {
if (_doWorkAsyncMethod != null) await (Task) _doWorkAsyncMethod.Invoke(asyncWorker, new object[] {workerContext});
{
await (Task)_doWorkAsyncMethod.Invoke(asyncWorker, new object[] { workerContext });
}
break;
} }
break;
}
case PeriodicBackgroundWorkerBase syncWorker: case PeriodicBackgroundWorkerBase syncWorker:
{ {
_doWorkMethod?.Invoke(syncWorker, new object[] { workerContext }); _doWorkMethod?.Invoke(syncWorker, new object[] {workerContext});
break; break;
} }
} }
} }
} }

7
framework/src/Volo.Abp.Core/Volo/Abp/Options/PreConfigureActionList.cs

@ -12,4 +12,11 @@ public class PreConfigureActionList<TOptions> : List<Action<TOptions>>
action(options); action(options);
} }
} }
public TOptions Configure()
{
var options = Activator.CreateInstance<TOptions>();
Configure(options);
return options;
}
} }

9
framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs

@ -11,18 +11,17 @@ public class AbpEventBusRebusModule : AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
var options = context.Services.ExecutePreConfiguredActions<AbpRebusEventBusOptions>(); ;
context.Services.AddTransient(typeof(IHandleMessages<>), typeof(RebusDistributedEventHandlerAdapter<>)); context.Services.AddTransient(typeof(IHandleMessages<>), typeof(RebusDistributedEventHandlerAdapter<>));
var preActions = context.Services.GetPreConfigureActions<AbpRebusEventBusOptions>();
Configure<AbpRebusEventBusOptions>(rebusOptions => Configure<AbpRebusEventBusOptions>(rebusOptions =>
{ {
context.Services.ExecutePreConfiguredActions(rebusOptions); preActions.Configure(rebusOptions);
}); });
context.Services.AddRebus(configure => context.Services.AddRebus(configure =>
{ {
options.Configurer?.Invoke(configure); preActions.Configure().Configurer?.Invoke(configure);
return configure; return configure;
}); });
} }
@ -36,4 +35,4 @@ public class AbpEventBusRebusModule : AbpModule
.GetRequiredService<RebusDistributedEventBus>() .GetRequiredService<RebusDistributedEventBus>()
.Initialize(); .Initialize();
} }
} }

3
framework/src/Volo.Abp.HangFire/Volo/Abp/Hangfire/AbpHangfireModule.cs

@ -13,9 +13,10 @@ public class AbpHangfireModule : AbpModule
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
var preActions = context.Services.GetPreConfigureActions<IGlobalConfiguration>();
context.Services.AddHangfire(configuration => context.Services.AddHangfire(configuration =>
{ {
context.Services.ExecutePreConfiguredActions(configuration); preActions.Configure(configuration);
}); });
} }

5
framework/src/Volo.Abp.Json/Volo/Abp/Json/AbpJsonModule.cs

@ -16,12 +16,11 @@ public class AbpJsonModule : AbpModule
context.Services.TryAddEnumerable(ServiceDescriptor context.Services.TryAddEnumerable(ServiceDescriptor
.Transient<IConfigureOptions<AbpSystemTextJsonSerializerOptions>, AbpSystemTextJsonSerializerOptionsSetup>()); .Transient<IConfigureOptions<AbpSystemTextJsonSerializerOptions>, AbpSystemTextJsonSerializerOptionsSetup>());
var preActions = context.Services.GetPreConfigureActions<AbpJsonOptions>();
Configure<AbpJsonOptions>(options => Configure<AbpJsonOptions>(options =>
{ {
options.Providers.Add<AbpNewtonsoftJsonSerializerProvider>(); options.Providers.Add<AbpNewtonsoftJsonSerializerProvider>();
if (preActions.Configure().UseHybridSerializer)
var abpJsonOptions = context.Services.ExecutePreConfiguredActions<AbpJsonOptions>();
if (abpJsonOptions.UseHybridSerializer)
{ {
options.Providers.Add<AbpSystemTextJsonSerializerProvider>(); options.Providers.Add<AbpSystemTextJsonSerializerProvider>();
} }

10
framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs

@ -38,9 +38,10 @@ public class AbpAspNetCoreMvcVersioningTestModule : AbpModule
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
var preActions = context.Services.GetPreConfigureActions<AbpAspNetCoreMvcOptions>();
Configure<AbpAspNetCoreMvcOptions>(options => Configure<AbpAspNetCoreMvcOptions>(options =>
{ {
context.Services.ExecutePreConfiguredActions(options); preActions.Configure(options);
}); });
context.Services.AddAbpApiVersioning(options => context.Services.AddAbpApiVersioning(options =>
@ -48,11 +49,10 @@ public class AbpAspNetCoreMvcVersioningTestModule : AbpModule
options.ReportApiVersions = true; options.ReportApiVersions = true;
options.AssumeDefaultVersionWhenUnspecified = true; options.AssumeDefaultVersionWhenUnspecified = true;
//options.ApiVersionReader = new HeaderApiVersionReader("api-version"); //Supports header too //options.ApiVersionReader = new HeaderApiVersionReader("api-version"); //Supports header too
//options.ApiVersionReader = new MediaTypeApiVersionReader(); //Supports accept header too //options.ApiVersionReader = new MediaTypeApiVersionReader(); //Supports accept header too
var mvcOptions = context.Services.ExecutePreConfiguredActions<AbpAspNetCoreMvcOptions>(); options.ConfigureAbp(preActions.Configure());
options.ConfigureAbp(mvcOptions);
}); });
context.Services.AddHttpClientProxies(typeof(AbpAspNetCoreMvcVersioningTestModule).Assembly); context.Services.AddHttpClientProxies(typeof(AbpAspNetCoreMvcVersioningTestModule).Assembly);

Loading…
Cancel
Save