/// <summary> /// Starts activity processing for the current bot turn. /// </summary> /// <param name="context">The turn's context object.</param> /// <param name="callback">A callback method to run at the end of the pipeline.</param> /// <returns>A task that represents the work queued to execute.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="context"/> is null.</exception> /// <remarks>The adapter calls middleware in the order in which you added it. /// The adapter passes in the context object for the turn and a next delegate, /// and the middleware calls the delegate to pass control to the next middleware /// in the pipeline. Once control reaches the end of the pipeline, the adapter calls /// the <paramref name="callback"/> method. If a middleware component doesn’t call /// the next delegate, the adapter does not call any of the subsequent middleware’s /// <see cref="IMiddleware.OnTurn(ITurnContext, MiddlewareSet.NextDelegate)"/> /// methods or the callback method, and the pipeline short circuits. /// <para>When the turn is initiated by a user activity (reactive messaging), the /// callback method will be a reference to the bot's /// <see cref="IBot.OnTurn(ITurnContext)"/> method. When the turn is /// initiated by a call to <see cref="ContinueConversation(string, ConversationReference, Func{ITurnContext, Task})"/> /// (proactive messaging), the callback method is the callback method that was provided in the call.</para> /// </remarks> protected async Task RunPipeline(ITurnContext context, Func <ITurnContext, Task> callback, CancellationToken cancellationToken) { BotAssert.ContextNotNull(context); // Call any registered Middleware Components looking for ReceiveActivity() if (context.Activity != null) { try { await _middlewareSet.ReceiveActivityWithStatus(context, callback, cancellationToken).ConfigureAwait(false); } catch (Exception e) { if (ErrorHandler != null) { await ErrorHandler.Invoke(context, e).ConfigureAwait(false); } else { throw; } } } else { // call back to caller on proactive case if (callback != null) { await callback(context).ConfigureAwait(false); } } }
/// <summary> /// Starts activity processing for the current bot turn. /// </summary> /// <param name="context">The turn's context object.</param> /// <param name="callback">A callback method to run at the end of the pipeline.</param> /// <param name="cancelToken">A cancellation token for the task.</param> /// <returns>A task that represents the work queued to execute.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="context"/> is null.</exception> /// <remarks>The adapter calls middleware in the order in which you added it. /// The adapter passes in the context object for the turn and a next delegate, /// and the middleware calls the delegate to pass control to the next middleware /// in the pipeline. Once control reaches the end of the pipeline, the adapter calls /// the <paramref name="callback"/> method. If a middleware component doesn’t call /// the next delegate, the adapter does not call any of the subsequent middleware’s /// <see cref="IMiddleware.OnTurn(ITurnContext, MiddlewareSet.NextDelegate)"/> /// methods or the callback method, and the pipeline short circuits. /// <para>When the turn is initiated by a user activity (reactive messaging), the /// callback method will be a reference to the bot's /// <see cref="IBot.OnTurn(ITurnContext)"/> method. When the turn is /// initiated by a call to <see cref="ContinueConversation(ConversationReference, Func{ITurnContext, Task})"/> /// (proactive messaging), the callback method is the callback method that was provided in the call.</para> /// </remarks> protected async Task RunPipeline(ITurnContext context, Func <ITurnContext, Task> callback = null, CancellationTokenSource cancelToken = null) { BotAssertSlack.ContextNotNull(context); // Call any registered Middleware Components looking for ReceiveActivity() if (context.Activity != null) { await _middlewareSet.ReceiveActivityWithStatus(context, callback).ConfigureAwait(false); } else { // call back to caller on proactive case if (callback != null) { await callback(context).ConfigureAwait(false); } } }