public void DiscardQueuedEvents(IEventsScope eventsScope, string queueName) { if (eventsScope == null) { throw new ArgumentNullException(nameof(eventsScope)); } if (queueName != null) { if (!_eventsQueueNamesService.IsQueueNameExisting(queueName)) { throw new EventsQueueNotFoundException(); } var eventsQueue = eventsScope.GetQueuesFeature().GetOrAddEventsQueue(_eventsContext, queueName); eventsQueue.DiscardQueuedEvents(); } else { foreach (var eventsQueue in eventsScope.GetQueuesFeature().GetEventsQueues(_eventsContext)) { eventsQueue.DiscardQueuedEvents(); } } }
/// <inheritdoc /> public void Attach(object source, IEventsScope eventsScope) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (eventsScope == null) { throw new ArgumentNullException(nameof(eventsScope)); } foreach (var attachingInterceptor in _attachingInterceptors) { attachingInterceptor.OnAttaching(this, source, eventsScope); } var sourceType = source.GetType(); foreach (var baseSourceType in sourceType.GetBaseTypesAndInterfacesInclusive()) { var sourceModel = _sourceModelsService.GetOrCreateSourceModel(baseSourceType); _forwardingService.ForwardEventsToRouting(sourceModel, source, eventsScope); } }
public async Task ProcessQueuedEventsAsync(IEventsScope eventsScope, string queueName) { if (eventsScope == null) { throw new ArgumentNullException(nameof(eventsScope)); } if (queueName != null) { if (!_eventsQueueNamesService.IsQueueNameExisting(queueName)) { throw new EventsQueueNotFoundException(); } var eventsQueue = eventsScope.GetQueuesFeature().GetOrAddEventsQueue(_eventsContext, queueName); await ProcessQueueAsync(eventsQueue).ConfigureAwait(false); } else { foreach (var eventsQueue in eventsScope.GetQueuesFeature().GetEventsQueues(_eventsContext)) { await ProcessQueueAsync(eventsQueue).ConfigureAwait(false); } } }
/// <inheritdoc /> public Task ProcessEventAsync( PipelineEvent pipelineEvent, IEventsScope eventsScope ) { var pipeline = _nextModule ?? (_nextModule = Build()); return(pipeline(new PipelineContext(pipelineEvent, eventsScope, _internalServiceProvider))); }
public void OnAttaching(IAttachingService attachingService, object source, IEventsScope eventsScope) { if (source is TDbContext dbContext) { ((IObjectContextAdapter)dbContext).ObjectContext.ObjectMaterialized += (sender, args) => { attachingService.Attach(args.Entity, eventsScope); } } ; } }
public void OnAttaching(IAttachingService attachingService, object source, IEventsScope eventsScope) { if (source is TDbContext dbContext) { dbContext.ChangeTracker.Tracked += (sender, args) => { attachingService.Attach(args.Entry.Entity, eventsScope); } } ; } }
/// <inheritdoc /> public async Task RouteEventAsync(PipelineEvent pipelineEvent, IEventsScope eventsScope) { using (_logger.BeginEventRoutingScope(pipelineEvent)) { var pipelines = _pipelinesService.GetPipelines(pipelineEvent.EventType); foreach (var pipeline in pipelines) { _logger.EventRoutedToPipeline(); await pipeline.ProcessEventAsync(pipelineEvent, eventsScope).ConfigureAwait(false); } } }
/// <inheritdoc /> public void ForwardEventsToRouting(SourceModel sourceModel, object source, IEventsScope eventsScope) { if (!sourceModel.ClrType.IsInstanceOfType(source)) { throw new SourceDoesNotMatchModelTypeException(); } foreach (var eventField in sourceModel.EventFields) { void HandlerAction(object @event) => HandlerActionAsync(@event).GetAwaiter().GetResult(); Task HandlerActionAsync(object @event) => _routingService.RouteEventAsync(new PipelineEvent(@event), eventsScope); var eventHandler = eventField.IsAsync ? sourceModel.CreateEventHandler <Func <object, Task> >(eventField, HandlerActionAsync) : sourceModel.CreateEventHandler <Action <object> >(eventField, HandlerAction); eventField.EventInfo.AddEventHandler(source, eventHandler); } }
public void EnqueueEvent(IEventsScope eventsScope, PipelineEvent pipelineEvent, string queueName, Func <Task> invokeNextModule) { if (eventsScope == null) { throw new ArgumentNullException(nameof(eventsScope)); } if (pipelineEvent == null) { throw new ArgumentNullException(nameof(pipelineEvent)); } if (queueName == null) { throw new ArgumentNullException(nameof(queueName)); } if (!_eventsQueueNamesService.IsQueueNameExisting(queueName)) { throw new EventsQueueNotFoundException(); } var queue = eventsScope.GetQueuesFeature().GetOrAddEventsQueue(_eventsContext, queueName); queue.Enqueue(new QueuedPipelineEvent(invokeNextModule)); }
public static IEventsScopeQueuesFeature GetQueuesFeature(this IEventsScope eventsScope) { return(eventsScope.GetOrAddFeature <IEventsScopeQueuesFeature>(x => new EventsScopeQueuesFeature())); }
public Task PublishEventToScopedSubscriptionsAsync(PipelineEvent pipelineEvent, IEventsScope eventsScope) { if (eventsScope == null) { throw new ArgumentNullException(nameof(eventsScope)); } var subscriptions = eventsScope.GetSubscriptionsFeature().GetSubscriptions(_scopedSubscriptionsService); return(PublishInternalAsync(pipelineEvent, subscriptions)); }
public void SetUp() { _scopedAppServiceProviderMock = new Mock <IScopedAppServiceProvider>(MockBehavior.Strict); _eventsScope = new EventsScope(_scopedAppServiceProviderMock.Object); }
/// <summary> /// Creates a new instance of a <see cref="PipelineContext"/>. /// </summary> /// <param name="pipelineEvent">The event being processed.</param> /// <param name="eventsScope">The current events scope.</param> /// <param name="serviceProvider">The internal service provider.</param> public PipelineContext(PipelineEvent pipelineEvent, IEventsScope eventsScope, IServiceProvider serviceProvider) { PipelineEvent = pipelineEvent ?? throw new ArgumentNullException(nameof(pipelineEvent)); EventsScope = eventsScope ?? throw new ArgumentNullException(nameof(eventsScope)); ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); }
public static IEventsScopeSubscriptionsFeature GetSubscriptionsFeature(this IEventsScope eventsScope) { return(eventsScope.GetOrAddFeature <IEventsScopeSubscriptionsFeature>( x => new EventsScopeSubscriptionsFeature(x) )); }