Browse Source

Remove RunnableExtensions, Remove IRunnable from AbpTimer.

pull/1467/head
Halil İbrahim Kalkan 7 years ago
parent
commit
ed0895e712
  1. 16
      framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/AbpBackgroundJobsRabbitMqModule.cs
  2. 2
      framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueManager.cs
  3. 16
      framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/AbpBackgroundWorkersModule.cs
  4. 4
      framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerManager.cs
  5. 4
      framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/PeriodicBackgroundWorkerBase.cs
  6. 36
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventBusExtensions.cs
  7. 5
      framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureCheckerExtensions.cs
  8. 14
      framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureInterceptor.cs
  9. 14
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs
  10. 10
      framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumer.cs
  11. 11
      framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AbpTimer.cs
  12. 21
      framework/src/Volo.Abp.Threading/Volo/Abp/Threading/RunnableExtensions.cs

16
framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/AbpBackgroundJobsRabbitMqModule.cs

@ -29,16 +29,20 @@ namespace Volo.Abp.BackgroundJobs.RabbitMQ
private static void StartJobQueueManager(ApplicationInitializationContext context)
{
context.ServiceProvider
.GetRequiredService<IJobQueueManager>()
.Start();
AsyncHelper.RunSync(
() => context.ServiceProvider
.GetRequiredService<IJobQueueManager>()
.StartAsync()
);
}
private static void StopJobQueueManager(ApplicationShutdownContext context)
{
context.ServiceProvider
.GetRequiredService<IJobQueueManager>()
.Stop();
AsyncHelper.RunSync(
() => context.ServiceProvider
.GetRequiredService<IJobQueueManager>()
.StopAsync()
);
}
}
}

2
framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueManager.cs

@ -61,7 +61,7 @@ namespace Volo.Abp.BackgroundJobs.RabbitMQ
.GetRequiredService(typeof(IJobQueue<>)
.MakeGenericType(typeof(TArgs)));
jobQueue.Start();
AsyncHelper.RunSync(() => jobQueue.StartAsync());
return jobQueue;
});

16
framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/AbpBackgroundWorkersModule.cs

@ -15,9 +15,11 @@ namespace Volo.Abp.BackgroundWorkers
var options = context.ServiceProvider.GetRequiredService<IOptions<BackgroundWorkerOptions>>().Value;
if (options.IsEnabled)
{
context.ServiceProvider
.GetRequiredService<IBackgroundWorkerManager>()
.Start();
AsyncHelper.RunSync(
() => context.ServiceProvider
.GetRequiredService<IBackgroundWorkerManager>()
.StartAsync()
);
}
}
@ -26,9 +28,11 @@ namespace Volo.Abp.BackgroundWorkers
var options = context.ServiceProvider.GetRequiredService<IOptions<BackgroundWorkerOptions>>().Value;
if (options.IsEnabled)
{
context.ServiceProvider
.GetRequiredService<IBackgroundWorkerManager>()
.Stop();
AsyncHelper.RunSync(
() => context.ServiceProvider
.GetRequiredService<IBackgroundWorkerManager>()
.StopAsync()
);
}
}
}

4
framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerManager.cs

@ -32,7 +32,9 @@ namespace Volo.Abp.BackgroundWorkers
if (IsRunning)
{
worker.Start();
AsyncHelper.RunSync(
() => worker.StartAsync()
);
}
}

4
framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/PeriodicBackgroundWorkerBase.cs

@ -26,12 +26,12 @@ namespace Volo.Abp.BackgroundWorkers
public override async Task StartAsync(CancellationToken cancellationToken = default)
{
await base.StartAsync(cancellationToken);
await Timer.StartAsync(cancellationToken);
Timer.Start(cancellationToken);
}
public override async Task StopAsync(CancellationToken cancellationToken = default)
{
await Timer.StopAsync(cancellationToken);
Timer.Stop(cancellationToken);
await base.StopAsync(cancellationToken);
}

36
framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventBusExtensions.cs

@ -1,36 +0,0 @@
using System;
using JetBrains.Annotations;
using Volo.Abp.Threading;
namespace Volo.Abp.EventBus
{
public static class EventBusExtensions
{
/// <summary>
/// Triggers an event.
/// </summary>
/// <typeparam name="TEvent">Event type</typeparam>
/// <param name="eventBus">Event bus instance</param>
/// <param name="eventData">Related data for the event</param>
public static void Publish<TEvent>([NotNull] this IEventBus eventBus, [NotNull] TEvent eventData)
where TEvent : class
{
Check.NotNull(eventBus, nameof(eventBus));
AsyncHelper.RunSync(() => eventBus.PublishAsync(eventData));
}
/// <summary>
/// Triggers an event.
/// </summary>
/// <param name="eventBus">Event bus instance</param>
/// <param name="eventType">Event type</param>
/// <param name="eventData">Related data for the event</param>
public static void Publish([NotNull] this IEventBus eventBus, [NotNull] Type eventType, [NotNull] object eventData)
{
Check.NotNull(eventBus, nameof(eventBus));
AsyncHelper.RunSync(() => eventBus.PublishAsync(eventType, eventData));
}
}
}

5
framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureCheckerExtensions.cs

@ -134,10 +134,5 @@ namespace Volo.Abp.Features
);
}
}
public static void CheckEnabled(this IFeatureChecker featureChecker, bool requiresAll, params string[] featureNames)
{
AsyncHelper.RunSync(() => featureChecker.CheckEnabledAsync(requiresAll, featureNames));
}
}
}

14
framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureInterceptor.cs

@ -18,9 +18,7 @@ namespace Volo.Abp.Features
public override void Intercept(IAbpMethodInvocation invocation)
{
if (AbpCrossCuttingConcerns.IsApplied(
invocation.TargetObject,
AbpCrossCuttingConcerns.FeatureChecking))
if (AbpCrossCuttingConcerns.IsApplied(invocation.TargetObject, AbpCrossCuttingConcerns.FeatureChecking))
{
invocation.Proceed();
return;
@ -32,21 +30,19 @@ namespace Volo.Abp.Features
public override async Task InterceptAsync(IAbpMethodInvocation invocation)
{
if (AbpCrossCuttingConcerns.IsApplied(
invocation.TargetObject,
AbpCrossCuttingConcerns.FeatureChecking))
if (AbpCrossCuttingConcerns.IsApplied(invocation.TargetObject, AbpCrossCuttingConcerns.FeatureChecking))
{
await invocation.ProceedAsync();
return;
}
AsyncHelper.RunSync(() => CheckFeaturesAsync(invocation));
await CheckFeaturesAsync(invocation);
await invocation.ProceedAsync();
}
protected virtual Task CheckFeaturesAsync(IAbpMethodInvocation invocation)
protected virtual async Task CheckFeaturesAsync(IAbpMethodInvocation invocation)
{
return _methodInvocationFeatureCheckerService.CheckAsync(
await _methodInvocationFeatureCheckerService.CheckAsync(
new MethodInvocationFeatureCheckerContext(
invocation.Method
)

14
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

@ -88,11 +88,11 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
if (entity is ISoftDelete softDeleteEntity && softDeleteEntity.IsDeleted)
{
SetDeletionAuditProperties(entity);
AsyncHelper.RunSync(() => TriggerEntityDeleteEvents(entity));
AsyncHelper.RunSync(() => TriggerEntityDeleteEventsAsync(entity));
}
else
{
AsyncHelper.RunSync(() => TriggerEntityUpdateEvents(entity));
AsyncHelper.RunSync(() => TriggerEntityUpdateEventsAsync(entity));
}
AsyncHelper.RunSync(() => TriggerDomainEventsAsync(entity));
@ -122,11 +122,11 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
if (entity is ISoftDelete softDeleteEntity && softDeleteEntity.IsDeleted)
{
SetDeletionAuditProperties(entity);
await TriggerEntityDeleteEvents(entity);
await TriggerEntityDeleteEventsAsync(entity);
}
else
{
await TriggerEntityUpdateEvents(entity);
await TriggerEntityUpdateEventsAsync(entity);
}
await TriggerDomainEventsAsync(entity);
@ -294,7 +294,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
await EntityChangeEventHelper.TriggerEntityCreatingEventAsync(entity);
}
protected virtual async Task TriggerEntityUpdateEvents(TEntity entity)
protected virtual async Task TriggerEntityUpdateEventsAsync(TEntity entity)
{
await EntityChangeEventHelper.TriggerEntityUpdatedEventOnUowCompletedAsync(entity);
await EntityChangeEventHelper.TriggerEntityUpdatingEventAsync(entity);
@ -303,11 +303,11 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
protected virtual async Task ApplyAbpConceptsForDeletedEntityAsync(TEntity entity)
{
SetDeletionAuditProperties(entity);
await TriggerEntityDeleteEvents(entity);
await TriggerEntityDeleteEventsAsync(entity);
await TriggerDomainEventsAsync(entity);
}
protected virtual async Task TriggerEntityDeleteEvents(TEntity entity)
protected virtual async Task TriggerEntityDeleteEventsAsync(TEntity entity)
{
await EntityChangeEventHelper.TriggerEntityDeletedEventOnUowCompletedAsync(entity);
await EntityChangeEventHelper.TriggerEntityDeletingEventAsync(entity);

10
framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumer.cs

@ -72,7 +72,7 @@ namespace Volo.Abp.RabbitMQ
await TrySendQueueBindCommandsAsync();
}
protected virtual Task TrySendQueueBindCommandsAsync()
protected virtual void TrySendQueueBindCommands()
{
try
{
@ -80,7 +80,7 @@ namespace Volo.Abp.RabbitMQ
{
if (Channel == null || Channel.IsClosed)
{
return Task.CompletedTask;
return;
}
lock (ChannelSendSyncLock)
@ -115,7 +115,11 @@ namespace Volo.Abp.RabbitMQ
{
Logger.LogException(ex, LogLevel.Warning);
}
}
protected virtual Task TrySendQueueBindCommandsAsync()
{
TrySendQueueBindCommands();
return Task.CompletedTask;
}
@ -129,7 +133,7 @@ namespace Volo.Abp.RabbitMQ
if (Channel == null || Channel.IsOpen == false)
{
TryCreateChannel();
AsyncHelper.RunSync(TrySendQueueBindCommandsAsync);
TrySendQueueBindCommands();
}
}

11
framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AbpTimer.cs

@ -1,6 +1,5 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.DependencyInjection;
@ -10,7 +9,7 @@ namespace Volo.Abp.Threading
/// <summary>
/// A roboust timer implementation that ensures no overlapping occurs. It waits exactly specified <see cref="Period"/> between ticks.
/// </summary>
public class AbpTimer : IRunnable, ITransientDependency
public class AbpTimer : ITransientDependency
{
/// <summary>
/// This event is raised periodically according to Period of Timer.
@ -41,7 +40,7 @@ namespace Volo.Abp.Threading
_taskTimer = new Timer(TimerCallBack, null, Timeout.Infinite, Timeout.Infinite);
}
public Task StartAsync(CancellationToken cancellationToken = default)
public void Start(CancellationToken cancellationToken = default)
{
if (Period <= 0)
{
@ -53,11 +52,9 @@ namespace Volo.Abp.Threading
_taskTimer.Change(RunOnStart ? 0 : Period, Timeout.Infinite);
_isRunning = true;
}
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken = default)
public void Stop(CancellationToken cancellationToken = default)
{
lock (_taskTimer)
{
@ -69,8 +66,6 @@ namespace Volo.Abp.Threading
_isRunning = false;
}
return Task.CompletedTask;
}
/// <summary>

21
framework/src/Volo.Abp.Threading/Volo/Abp/Threading/RunnableExtensions.cs

@ -1,21 +0,0 @@
using JetBrains.Annotations;
namespace Volo.Abp.Threading
{
public static class RunnableExtensions
{
public static void Start([NotNull] this IRunnable runnable)
{
Check.NotNull(runnable, nameof(runnable));
AsyncHelper.RunSync(() => runnable.StartAsync());
}
public static void Stop([NotNull] this IRunnable runnable)
{
Check.NotNull(runnable, nameof(runnable));
AsyncHelper.RunSync(() => runnable.StopAsync());
}
}
}
Loading…
Cancel
Save