コード例 #1
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Break is simply returning an ActionScopeResult with BreakLoop command in it.
            var actionScopeResult = new ActionScopeResult()
            {
                ActionScopeCommand = ActionScopeCommands.BreakLoop
            };

            return(await dc.EndDialogAsync(result : actionScopeResult, cancellationToken : cancellationToken).ConfigureAwait(false));
        }
コード例 #2
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            if (this.Disabled != null && this.Disabled.GetValue(dc.State) == true)
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            // Continue is simply returning an ActionScopeResult with ContinueLoop command in it.
            var actionScopeResult = new ActionScopeResult()
            {
                ActionScopeCommand = ActionScopeCommands.ContinueLoop
            };

            return(await dc.EndDialogAsync(result : actionScopeResult, cancellationToken : cancellationToken).ConfigureAwait(false));
        }
コード例 #3
0
 /// <summary>
 /// Called when returning control to this dialog with an <see cref="ActionScopeResult"/>
 /// with the property ActionCommand set to <c>ContinueLoop</c>.
 /// </summary>
 /// <param name="dc">The dialog context for the current turn of the conversation.</param>
 /// <param name="actionScopeResult">Contains the actions scope result.</param>
 /// <param name="cancellationToken">A cancellation token that can be used by other objects
 /// or threads to receive notice of cancellation.</param>
 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
 /// <remarks>Default is to simply end the dialog and propagate to parent to handle.</remarks>
 protected virtual async Task <DialogTurnResult> OnContinueLoopAsync(DialogContext dc, ActionScopeResult actionScopeResult, CancellationToken cancellationToken = default)
 {
     // default is to simply end the dialog and propagate to parent to handle
     return(await dc.EndDialogAsync(actionScopeResult, cancellationToken).ConfigureAwait(false));
 }
コード例 #4
0
        /// <summary>
        /// Called when returning control to this dialog with an <see cref="ActionScopeResult"/>
        /// with the property ActionCommand set to <c>GoToAction</c>.
        /// </summary>
        /// <param name="dc">The dialog context for the current turn of the conversation.</param>
        /// <param name="actionScopeResult">Contains the actions scope result.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects
        /// or threads to receive notice of cancellation.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        protected virtual async Task <DialogTurnResult> OnGotoActionAsync(DialogContext dc, ActionScopeResult actionScopeResult, CancellationToken cancellationToken = default)
        {
            // Look for action to goto in our scope
            var offset = this.Actions.FindIndex((d) => d.Id == actionScopeResult.ActionId);

            // Is this a action Id for us?
            if (offset >= 0)
            {
                // begin that action
                return(await this.BeginActionAsync(dc, offset, cancellationToken).ConfigureAwait(false));
            }
            else if (dc.Stack.Count > 1)
            {
                // send it to parent to resolve
                return(await dc.EndDialogAsync(actionScopeResult, cancellationToken).ConfigureAwait(false));
            }
            else
            {
                // we have not found the goto id.
                throw new Exception($"GotoAction: could not find an action of '{actionScopeResult.ActionId}'.");
            }
        }
コード例 #5
0
        /// <summary>
        /// Called when returning control to this dialog with an <see cref="ActionScopeResult"/>.
        /// </summary>
        /// <param name="dc">The dialog context for the current turn of the conversation.</param>
        /// <param name="actionScopeResult">Contains the actions scope result.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects
        /// or threads to receive notice of cancellation.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        protected virtual async Task <DialogTurnResult> OnActionScopeResultAsync(DialogContext dc, ActionScopeResult actionScopeResult, CancellationToken cancellationToken = default)
        {
            switch (actionScopeResult.ActionScopeCommand)
            {
            case ActionScopeCommands.GotoAction:
                return(await this.OnGotoActionAsync(dc, actionScopeResult, cancellationToken).ConfigureAwait(false));

            case ActionScopeCommands.BreakLoop:
                return(await this.OnBreakLoopAsync(dc, actionScopeResult, cancellationToken).ConfigureAwait(false));

            case ActionScopeCommands.ContinueLoop:
                return(await this.OnContinueLoopAsync(dc, actionScopeResult, cancellationToken).ConfigureAwait(false));

            default:
                throw new NotImplementedException($"Unknown action scope command returned: {actionScopeResult.ActionScopeCommand}");
            }
        }
コード例 #6
0
 protected override async Task <DialogTurnResult> OnContinueLoopAsync(DialogContext dc, ActionScopeResult actionScopeResult, CancellationToken cancellationToken = default)
 {
     return(await this.NextItemAsync(dc, cancellationToken).ConfigureAwait(false));
 }
コード例 #7
0
 protected override async Task <DialogTurnResult> OnBreakLoopAsync(DialogContext dc, ActionScopeResult actionScopeResult, CancellationToken cancellationToken = default)
 {
     return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
 }