/// <summary> /// Adds a module to the current pipeline that replaces event with a projection. /// </summary> /// <remarks> /// Projections are useful when an event needs to be serialized in order to reduce /// the size and the complexity of the serialization output. /// </remarks> /// <typeparam name="TEvent">The type of the event.</typeparam> /// <typeparam name="TToEvent">The type of the projected event.</typeparam> /// <param name="eventPipelineConfigurator"> /// The <see cref="EventPipelineConfigurator{TEvent}"/> for the pipeline being configured. /// </param> /// <param name="eventConverter"> /// A <see cref="Func{TEvent, TToEvent}"/> that takes the event as input and returns a new object. /// </param> /// <returns> /// A new <see cref="EventPipelineConfigurator{TToEvent}"/> instance so that multiple calls can be chained. /// </returns> public static EventPipelineConfigurator <TToEvent> ThenIsProjected <TEvent, TToEvent>( this EventPipelineConfigurator <TEvent> eventPipelineConfigurator, Func <TEvent, TToEvent> eventConverter ) where TEvent : class where TToEvent : class { if (eventPipelineConfigurator == null) { throw new ArgumentNullException(nameof(eventPipelineConfigurator)); } if (eventConverter == null) { throw new ArgumentNullException(nameof(eventConverter)); } var projectionPipelineModuleConfig = new ProjectionPipelineModuleConfig( new EventProjection <TEvent, TToEvent>(eventConverter) ); eventPipelineConfigurator .Get <IPipeline>() .AddModule <ProjectionPipelineModule, ProjectionPipelineModuleConfig>( projectionPipelineModuleConfig ); return(new EventPipelineConfigurator <TToEvent>( eventPipelineConfigurator.Get <IServiceProvider>(), eventPipelineConfigurator.Get <IPipeline>() )); }
/// <summary> /// Adds module to the current pipeline that queues the event in a queue /// and pauses the execution of the current pipeline until the event is dequeued. /// </summary> /// <typeparam name="TEvent">The type of the event.</typeparam> /// <param name="eventPipelineConfigurator"> /// The <see cref="EventPipelineConfigurator{TEvent}"/> for the pipeline being configured. /// </param> /// <param name="queueName">The name of the queue.</param> /// <returns> /// The same <see cref="EventPipelineConfigurator{TEvent}"/> instance so that multiple calls can be chained. /// </returns> public static EventPipelineConfigurator <TEvent> ThenIsQueuedTo <TEvent>( this EventPipelineConfigurator <TEvent> eventPipelineConfigurator, string queueName ) where TEvent : class { if (eventPipelineConfigurator == null) { throw new ArgumentNullException(nameof(eventPipelineConfigurator)); } if (queueName == null) { throw new ArgumentNullException(nameof(queueName)); } var eventsQueueNamesService = eventPipelineConfigurator .Get <IServiceProvider>() .GetRequiredService <IEventsQueueNamesService>(); eventsQueueNamesService.RegisterQueueNameIfNotExists(queueName); eventPipelineConfigurator .Get <IPipeline>() .AddModule <EnqueuePipelineModule, EnqueuePipelineModuleConfig>( new EnqueuePipelineModuleConfig { QueueName = queueName } ); return(eventPipelineConfigurator); }
private static void AddModule <TEvent>( EventPipelineConfigurator <TEvent> eventPipelineConfigurator, PublicationMethod publicationMethod, string hubName, string hubMethodName, Func <TEvent, string[]> receiverIdsProviderAction ) where TEvent : class { if (hubMethodName == null) { hubMethodName = typeof(TEvent).Name; } ((IInfrastructure <IPipeline>)eventPipelineConfigurator).Instance .AddModule <AzureSignalRPipelineModule, AzureSignalRPipelineModuleConfig>( new AzureSignalRPipelineModuleConfig { PublicationMethod = publicationMethod, HubMethodName = hubMethodName, HubName = hubName, ReceiverIdsProviderAction = receiverIdsProviderAction == null ? (Func <object, string[]>)null : e => receiverIdsProviderAction((TEvent)e) } ); }
public void SetUp() { _serviceProviderMock = new Mock <IServiceProvider>(MockBehavior.Strict); _pipelineMock = new Mock <IPipeline>(MockBehavior.Strict); _eventPipelineConfigurator = new EventPipelineConfigurator <object>( _serviceProviderMock.Object, _pipelineMock.Object ); }
public void Ctor_WithAllParameters_ShouldSetPropertiesFromParameters() { var eventPipelineConfigurator = new EventPipelineConfigurator <object>( _serviceProviderMock.Object, _pipeline ); var pipeline = eventPipelineConfigurator.Get <IPipeline>(); var serviceProvider = eventPipelineConfigurator.Get <IServiceProvider>(); Assert.That(pipeline, Is.EqualTo(_pipeline)); Assert.That(serviceProvider, Is.EqualTo(_serviceProviderMock.Object)); }
public void Ctor_WithEventConfigurator_ShouldInheritPropertyValuesFromEventConfigurator() { var eventPipelineConfigurator = new EventPipelineConfigurator <object>( _pipeline, _eventConfigurator ); var pipeline = eventPipelineConfigurator.Get <IPipeline>(); var serviceProvider = eventPipelineConfigurator.Get <IServiceProvider>(); Assert.That(pipeline, Is.EqualTo(_pipeline)); Assert.That(serviceProvider, Is.EqualTo(_serviceProviderMock.Object)); }
/// <summary> /// Adds a module to the current pipeline that publishes the event to all the subscriptions in scope locally. /// </summary> /// <typeparam name="TEvent">The type of the event.</typeparam> /// <param name="eventPipelineConfigurator"> /// The <see cref="EventPipelineConfigurator{TEvent}"/> for the pipeline being configured. /// </param> /// <returns>The same <see cref="EventPipelineConfigurator{TEvent}"/> instance so that multiple calls can be chained.</returns> public static EventPipelineConfigurator <TEvent> ThenIsPublishedToScopedSubscriptions <TEvent>( this EventPipelineConfigurator <TEvent> eventPipelineConfigurator ) where TEvent : class { if (eventPipelineConfigurator == null) { throw new ArgumentNullException(nameof(eventPipelineConfigurator)); } eventPipelineConfigurator .Get <IPipeline>() .AddModule <ScopedPublishPipelineModule, ScopedPublishPipelineModuleConfig>( new ScopedPublishPipelineModuleConfig() ); return(eventPipelineConfigurator); }
/// <summary> /// Adds a module to the current pipeline that publishes the event to all the users connected to /// the configured Azure SignalR Service. /// </summary> /// <typeparam name="TEvent">The type of the event.</typeparam> /// <param name="eventPipelineConfigurator"> /// The <see cref="EventPipelineConfigurator{TEvent}"/> for the pipeline being configured. /// </param> /// <param name="hubName">The SignalR hub name. The default value is the entity name with the "Hub" suffix (Eg. TSourceHub).</param> /// <param name="hubMethodName">The SignalR hub method name. The default value is the current event field name.</param> /// <returns> /// The same <see cref="EventPipelineConfigurator{TEvent}"/> instance so that multiple calls can be chained. /// </returns> public static EventPipelineConfigurator <TEvent> ThenIsSentToAllAzureSignalRUsers <TEvent>( this EventPipelineConfigurator <TEvent> eventPipelineConfigurator, string hubName, string hubMethodName = null ) where TEvent : class { if (eventPipelineConfigurator == null) { throw new ArgumentNullException(nameof(eventPipelineConfigurator)); } if (hubName == null) { throw new ArgumentNullException(nameof(hubName)); } AddModule(eventPipelineConfigurator, PublicationMethod.Broadcast, hubName, hubMethodName, null); return(eventPipelineConfigurator); }
/// <summary> /// Adds a module to the current pipeline that publishes the event to some users connected to /// the configured Azure SignalR Service. /// </summary> /// <typeparam name="TEvent">The type of the event.</typeparam> /// <param name="eventPipelineConfigurator"> /// The <see cref="EventPipelineConfigurator{TEvent}"/> for the pipeline being configured. /// </param> /// <param name="userIdsProviderAction"> /// A <see cref="Func{TResult}"/> that returns the ids of the users that should receive the event. /// </param> /// <param name="hubName">The SignalR hub name. The default value is the entity name with the "Hub" suffix (Eg. TSourceHub).</param> /// <param name="hubMethodName">The SignalR hub method name. The default value is the current event field name.</param> /// <returns> /// The same <see cref="EventPipelineConfigurator{TEvent}"/> instance so that multiple calls can be chained. /// </returns> public static EventPipelineConfigurator <TEvent> ThenIsSentToAzureSignalRUsers <TEvent>( this EventPipelineConfigurator <TEvent> eventPipelineConfigurator, Func <TEvent, string[]> userIdsProviderAction, string hubName, string hubMethodName = null ) where TEvent : class { if (eventPipelineConfigurator == null) { throw new ArgumentNullException(nameof(eventPipelineConfigurator)); } if (hubName == null) { throw new ArgumentNullException(nameof(hubName)); } AddModule(eventPipelineConfigurator, PublicationMethod.User, hubName, hubMethodName, userIdsProviderAction); return(eventPipelineConfigurator); }
/// <summary> /// Adds a module to the current pipeline that publishes the event to all the global subscriptions using a transmission method /// configurable with the configurePublishTransmission parameter. /// </summary> /// <remarks> /// This method can be used to configure a publication to multiple application instances with this <see cref="EventsContext"/> /// </remarks> /// <typeparam name="TEvent">The type of the event.</typeparam> /// <param name="eventPipelineConfigurator"> /// The <see cref="EventPipelineConfigurator{TEvent}"/> for the pipeline being configured. /// </param> /// <param name="configurePublishTransmission">A delegate for configuring how the event is transmitted.</param> /// <returns>The same <see cref="EventPipelineConfigurator{TEvent}"/> instance so that multiple calls can be chained.</returns> public static EventPipelineConfigurator <TEvent> ThenIsPublishedToGlobalSubscriptions <TEvent>( this EventPipelineConfigurator <TEvent> eventPipelineConfigurator, Func <ConfigureTransmission, IPublishTransmissionConfiguration> configurePublishTransmission ) where TEvent : class { if (configurePublishTransmission == null) { throw new ArgumentNullException(nameof(configurePublishTransmission)); } var globalPublishingOptionsFactory = new ConfigureTransmission(); var senderTypeConfiguration = configurePublishTransmission(globalPublishingOptionsFactory); var moduleConfig = new GlobalPublishPipelineModuleConfig { SenderType = senderTypeConfiguration.SenderType }; if (moduleConfig.SenderType != null) { var serviceProvider = eventPipelineConfigurator.Get <IServiceProvider>(); var eventSenderExists = serviceProvider .GetServices <IEventSender>() .Any(x => x.GetType() == moduleConfig.SenderType); if (!eventSenderExists) { throw new EventTransmissionPluginIsNotConfiguredException(); } } eventPipelineConfigurator .Get <IPipeline>() .AddModule <GlobalPublishPipelineModule, GlobalPublishPipelineModuleConfig>( moduleConfig ); return(eventPipelineConfigurator); }
/// <summary> /// Adds an event filtering module to the current pipeline. /// </summary> /// <typeparam name="TEvent">The type of the event.</typeparam> /// <param name="eventPipelineConfigurator"> /// The <see cref="EventPipelineConfigurator{TEvent}"/> for the pipeline being configured. /// </param> /// <param name="filter"> /// A <see cref="Func{TEvent, TResult}"/> that takes the event /// as input and returns false if it should be filtered /// (When an event is filtered any module configured after the filter won't be invoked). /// </param> /// <returns> /// The same <see cref="EventPipelineConfigurator{TEvent}"/> instance so that multiple calls can be chained. /// </returns> public static EventPipelineConfigurator <TEvent> ThenIsFiltered <TEvent>( this EventPipelineConfigurator <TEvent> eventPipelineConfigurator, Func <TEvent, bool> filter ) where TEvent : class { if (eventPipelineConfigurator == null) { throw new ArgumentNullException(nameof(eventPipelineConfigurator)); } if (filter == null) { throw new ArgumentNullException(nameof(filter)); } eventPipelineConfigurator.Get <IPipeline>() .AddModule <FilterPipelineModule, FilterPipelineModuleConfig>( new FilterPipelineModuleConfig(pipedEvent => filter((TEvent)pipedEvent)) ); return(eventPipelineConfigurator); }
private void ContinueConfiguration <TEvent>( EventPipelineConfigurator <TEvent> pipelineConfigurator ) where TEvent : class { if (_parameters.IsQueued) { pipelineConfigurator.ThenIsQueuedTo("DefaultQueue"); } switch (_parameters.PublicationType) { case PublicationType.GlobalWithServiceHandlerSubscription: pipelineConfigurator.ThenIsPublishedToGlobalSubscriptions(); break; case PublicationType.ScopedWithServiceHandlerSubscription: pipelineConfigurator.ThenIsPublishedToScopedSubscriptions(); break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Adds a module to the current pipeline that publishes the event to all the global subscriptions locally. /// </summary> /// <typeparam name="TEvent">The type that publishes the event.</typeparam> /// <param name="eventPipelineConfigurator"> /// The <see cref="EventPipelineConfigurator{TEvent}"/> for the pipeline being configured. /// </param> /// <returns>The same <see cref="EventPipelineConfigurator{TEvent}"/> instance so that multiple calls can be chained.</returns> public static EventPipelineConfigurator <TEvent> ThenIsPublishedToGlobalSubscriptions <TEvent>( this EventPipelineConfigurator <TEvent> eventPipelineConfigurator ) where TEvent : class => eventPipelineConfigurator.ThenIsPublishedToGlobalSubscriptions(x => ConfigureTransmission.Locally());