Пример #1
0
        /// <summary>
        /// Starts a new dialog and pushes it onto the dialog stack.
        /// </summary>
        /// <param name="dialogId">ID of the dialog to start.</param>
        /// <param name="options">Optional, information to pass to the dialog being started.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects
        /// or threads to receive notice of cancellation.</param>
        /// <returns>A task that represents the work queued to execute.</returns>
        /// <remarks>If the task is successful, the result indicates whether the dialog is still
        /// active after the turn has been processed by the dialog.</remarks>
        /// <seealso cref="EndDialogAsync(object, CancellationToken)"/>
        /// <seealso cref="PromptAsync(string, PromptOptions, CancellationToken)"/>
        /// <seealso cref="Dialog.BeginDialogAsync(DialogContext, object, CancellationToken)"/>
        public async Task <DialogTurnResult> BeginDialogAsync(string dialogId, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                if (string.IsNullOrEmpty(dialogId))
                {
                    throw new ArgumentNullException(nameof(dialogId));
                }

                // Look up dialog
                var dialog = FindDialog(dialogId);
                if (dialog == null)
                {
                    throw new Exception(
                              $"DialogContext.BeginDialogAsync(): A dialog with an id of '{dialogId}' wasn't found." +
                              " The dialog must be included in the current or parent DialogSet." +
                              " For example, if subclassing a ComponentDialog you can call AddDialog() within your constructor.");
                }

                // Push new instance onto stack
                var instance = new DialogInstance
                {
                    Id    = dialogId,
                    State = new Dictionary <string, object>(),
                };

                Stack.Insert(0, instance);

                // Call dialog's BeginAsync() method
                await this.DebuggerStepAsync(dialog, DialogEvents.BeginDialog, cancellationToken).ConfigureAwait(false);

                return(await dialog.BeginDialogAsync(this, options : options, cancellationToken : cancellationToken).ConfigureAwait(false));
            }
            catch (Exception err)
            {
                SetExceptionContextData(err);
                throw;
            }
        }
Пример #2
0
        public override async Task EndDialogAsync(ITurnContext turnContext, DialogInstance instance, DialogReason reason, CancellationToken cancellationToken = default)
        {
            // Send of of conversation to the skill if the dialog has been cancelled.
            if (reason == DialogReason.CancelCalled || reason == DialogReason.ReplaceCalled)
            {
                await turnContext.TraceActivityAsync($"{GetType().Name}.EndDialogAsync()", label : $"ActivityType: {turnContext.Activity.Type}", cancellationToken : cancellationToken).ConfigureAwait(false);

                var activity = (Activity)Activity.CreateEndOfConversationActivity();

                // Apply conversation reference and common properties from incoming activity before sending.
                activity.ApplyConversationReference(turnContext.Activity.GetConversationReference(), true);
                activity.ChannelData = turnContext.Activity.ChannelData;
                activity.Properties  = turnContext.Activity.Properties;

                var skillConversationId = (string)instance.State[SkillConversationIdStateKey];

                // connection Name is not applicable for an EndDialog, as we don't expect as OAuthCard in response.
                await SendToSkillAsync(turnContext, activity, skillConversationId, cancellationToken).ConfigureAwait(false);
            }

            await base.EndDialogAsync(turnContext, instance, reason, cancellationToken).ConfigureAwait(false);
        }
Пример #3
0
 protected virtual Task OnRepromptDialogAsync(ITurnContext turnContext, DialogInstance instance, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Task.CompletedTask);
 }
Пример #4
0
 protected virtual Task OnEndDialogAsync(ITurnContext context, DialogInstance instance, DialogReason reason, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Task.CompletedTask);
 }
Пример #5
0
 public virtual Task DialogEndAsync(ITurnContext turnContext, DialogInstance instance, DialogReason reason, CancellationToken cancellationToken = default(CancellationToken))
 {
     // No-op by default
     return(Task.CompletedTask);
 }
Пример #6
0
 /// <summary>
 /// Called when the dialog should re-prompt the user for input.
 /// </summary>
 /// <param name="turnContext">The context object for this turn.</param>
 /// <param name="instance">State information for this dialog.</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>
 /// <seealso cref="DialogContext.RepromptDialogAsync(CancellationToken)"/>
 public virtual Task RepromptDialogAsync(ITurnContext turnContext, DialogInstance instance, CancellationToken cancellationToken = default(CancellationToken))
 {
     // No-op by default
     return(Task.CompletedTask);
 }
        // NOTE: You should only call this if you don't have a dc to work with (such as OnResume())
        private DialogContext CreateInnerDc(ITurnContext turnContext, DialogInstance instance)
        {
            var state = BuildDialogState(instance);

            return(new DialogContext(this.Dialogs, turnContext, state));
        }
        private DialogContext CreateInnerDc(DialogContext outerDc, DialogInstance instance)
        {
            var state = BuildDialogState(instance);

            return(new DialogContext(this.Dialogs, outerDc, state));
        }
Пример #9
0
 public virtual Task DialogEndAsync(ITurnContext context, DialogInstance instance, DialogReason reason)
 {
     // No-op by default
     return(Task.CompletedTask);
 }
Пример #10
0
 public virtual Task DialogRepromptAsync(ITurnContext context, DialogInstance instance)
 {
     // No-op by default
     return(Task.CompletedTask);
 }