/// <summary>
 /// Ingests the specified <see cref="CloudEvent"/>
 /// </summary>
 /// <param name="serviceProvider">The current <see cref="IServiceProvider"/></param>
 /// <param name="e">The <see cref="CloudEvent"/> to ingest</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/></param>
 /// <returns>A new awaitable <see cref="Task"/></returns>
 protected virtual async Task CorrelateAsync(IServiceProvider serviceProvider, CloudEvent e, CancellationToken cancellationToken)
 {
     try
     {
         var mediator = serviceProvider.GetRequiredService <IMediator>();
         await mediator.ExecuteAndUnwrapAsync(new V1CorrelateEventCommand(V1Event.CreateFrom(e)), cancellationToken);
     }
     catch (TaskCanceledException)
     {
         throw;
     }
     catch (Exception ex)
     {
         this.Logger.LogError("An error occured while processing an incoming cloud event: {ex}", ex.ToString());
     }
 }
        /// <summary>
        /// Handles an incoming <see cref="CloudEvent"/>
        /// </summary>
        /// <param name="e">The <see cref="CloudEvent"/> to handle</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/></param>
        /// <returns>A new awaitable <see cref="Task"/></returns>
        protected virtual async Task OnEventAsync(CloudEvent e)
        {
            using (await this.Lock.LockAsync(this.CancellationTokenSource.Token))
            {
                if (this.IdleTimer != null)
                {
                    this.IdleTimer.Dispose();
                    this.IdleTimer = null !;
                }
                if ((!string.IsNullOrWhiteSpace(this.EventDefinition.Source) && !Regex.IsMatch(e.Source !.ToString(), this.EventDefinition.Source, RegexOptions.IgnoreCase)) ||
                    (!string.IsNullOrWhiteSpace(this.EventDefinition.Type) && !Regex.IsMatch(e.Type !, this.EventDefinition.Type, RegexOptions.IgnoreCase)))
                {
                    return;
                }
                if (!await this.Context.Workflow.TryCorrelateAsync(V1Event.CreateFrom(e), this.EventDefinition.Correlations?.Select(c => c.ContextAttributeName) !, this.CancellationTokenSource.Token))
                {
                    return;
                }
                await this.OnNextAsync(new V1WorkflowActivityCompletedIntegrationEvent(this.Activity.Id, e.Data), this.CancellationTokenSource.Token);

                await this.OnCompletedAsync(this.CancellationTokenSource.Token);
            }
        }