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(
typeof(AbpBackgroundWorkersModule),
typeof(AbpHangfireModule))]
public class AbpBackgroundWorkerHangfireModule : AbpModule
public class AbpBackgroundWorkersHangfireModule : AbpModule
{
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;
}
public async Task AddAsync(IBackgroundWorker worker)
public Task AddAsync(IBackgroundWorker worker)
{
if (worker is IHangfireBackgroundWorker hangfireBackgroundWorker)
{
@ -42,18 +42,26 @@ public class HangfireBackgroundWorkerManager : IBackgroundWorkerManager, ISingle
if (worker is AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase)
{
var timer = (AbpAsyncTimer) worker.GetType()
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
{
return;
return Task.CompletedTask;
}
if (period == null)
{
return;
return Task.CompletedTask;
}
var adapterType = typeof(HangfirePeriodicBackgroundWorkerAdapter<>).MakeGenericType(worker.GetType());
@ -61,6 +69,8 @@ public class HangfireBackgroundWorkerManager : IBackgroundWorkerManager, ISingle
RecurringJob.AddOrUpdate(() => workerAdapter.DoWorkAsync(), GetCron(period.Value));
}
return Task.CompletedTask;
}
protected virtual string GetCron(int period)
@ -82,7 +92,7 @@ public class HangfireBackgroundWorkerManager : IBackgroundWorkerManager, ISingle
}
else
{
cron = $"0 0 */{time.TotalDays} * *";
throw new AbpException($"Cannot convert period: {period} to cron expression, use HangfireBackgroundWorkerBase to define worker");
}
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;
var workerType = worker.GetType();
if (worker is AsyncPeriodicBackgroundWorkerBase || worker is PeriodicBackgroundWorkerBase)
if (worker is AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase)
{
if (typeof(TWorker) != worker.GetType())
{
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);
period = timer?.Period;
var timer = worker.GetType().GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker);
if (worker is AsyncPeriodicBackgroundWorkerBase)
{
period = ((AbpAsyncTimer)timer)?.Period;
}
else
{
period = ((AbpTimer)timer)?.Period;
}
}
else
{
@ -60,26 +68,26 @@ public class QuartzPeriodicBackgroundWorkerAdapter<TWorker> : QuartzBackgroundWo
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);
switch (worker)
{
case AsyncPeriodicBackgroundWorkerBase asyncWorker:
{
if (_doWorkAsyncMethod != null)
{
if (_doWorkAsyncMethod != null)
{
await (Task)_doWorkAsyncMethod.Invoke(asyncWorker, new object[] { workerContext });
}
break;
await (Task) _doWorkAsyncMethod.Invoke(asyncWorker, new object[] {workerContext});
}
break;
}
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);
}
}
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)
{
var options = context.Services.ExecutePreConfiguredActions<AbpRebusEventBusOptions>(); ;
context.Services.AddTransient(typeof(IHandleMessages<>), typeof(RebusDistributedEventHandlerAdapter<>));
var preActions = context.Services.GetPreConfigureActions<AbpRebusEventBusOptions>();
Configure<AbpRebusEventBusOptions>(rebusOptions =>
{
context.Services.ExecutePreConfiguredActions(rebusOptions);
preActions.Configure(rebusOptions);
});
context.Services.AddRebus(configure =>
{
options.Configurer?.Invoke(configure);
preActions.Configure().Configurer?.Invoke(configure);
return configure;
});
}
@ -36,4 +35,4 @@ public class AbpEventBusRebusModule : AbpModule
.GetRequiredService<RebusDistributedEventBus>()
.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)
{
var preActions = context.Services.GetPreConfigureActions<IGlobalConfiguration>();
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
.Transient<IConfigureOptions<AbpSystemTextJsonSerializerOptions>, AbpSystemTextJsonSerializerOptionsSetup>());
var preActions = context.Services.GetPreConfigureActions<AbpJsonOptions>();
Configure<AbpJsonOptions>(options =>
{
options.Providers.Add<AbpNewtonsoftJsonSerializerProvider>();
var abpJsonOptions = context.Services.ExecutePreConfiguredActions<AbpJsonOptions>();
if (abpJsonOptions.UseHybridSerializer)
if (preActions.Configure().UseHybridSerializer)
{
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)
{
var preActions = context.Services.GetPreConfigureActions<AbpAspNetCoreMvcOptions>();
Configure<AbpAspNetCoreMvcOptions>(options =>
{
context.Services.ExecutePreConfiguredActions(options);
preActions.Configure(options);
});
context.Services.AddAbpApiVersioning(options =>
@ -48,11 +49,10 @@ public class AbpAspNetCoreMvcVersioningTestModule : AbpModule
options.ReportApiVersions = true;
options.AssumeDefaultVersionWhenUnspecified = true;
//options.ApiVersionReader = new HeaderApiVersionReader("api-version"); //Supports header too
//options.ApiVersionReader = new MediaTypeApiVersionReader(); //Supports accept header too
//options.ApiVersionReader = new HeaderApiVersionReader("api-version"); //Supports header too
//options.ApiVersionReader = new MediaTypeApiVersionReader(); //Supports accept header too
var mvcOptions = context.Services.ExecutePreConfiguredActions<AbpAspNetCoreMvcOptions>();
options.ConfigureAbp(mvcOptions);
options.ConfigureAbp(preActions.Configure());
});
context.Services.AddHttpClientProxies(typeof(AbpAspNetCoreMvcVersioningTestModule).Assembly);

Loading…
Cancel
Save