Ejemplo n.º 1
0
        /// <summary>
        /// Starts the dialog. Depending on the dialog, its possible for the dialog to finish
        /// immediately so it's advised to check the completion object returned by `begin()` and ensure
        /// that the dialog is still active before continuing.
        /// </summary>
        /// <param name="context">Context for the current turn of the conversation with the user.</param>
        /// <param name="state">A state object that the dialog will use to persist its current state. This should be an empty object which the dialog will populate. The bot should persist this with its other conversation state for as long as the dialog is still active.</param>
        /// <param name="options">(Optional) additional options supported by the dialog.</param>
        /// <returns>DialogCompletion result</returns>
        public async Task <DialogCompletion> Begin(ITurnContext context, IDictionary <string, object> state, IDictionary <string, object> options = null)
        {
            BotAssert.ContextNotNull(context);
            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }

            // Create empty dialog set and ourselves to it
            var dialogs = new DialogSet();

            dialogs.Add("dialog", (IDialog)this);

            // Start the control
            IDictionary <string, object> result = null;
            var dc = new DialogContext(dialogs, context, state, (r) => { result = r; });

            await dc.Begin("dialog", options);

            return(dc.ActiveDialog != null
                    ?
                   new DialogCompletion {
                IsActive = true, IsCompleted = false
            }
                    :
                   new DialogCompletion {
                IsActive = false, IsCompleted = true, Result = result
            });
        }
Ejemplo n.º 2
0
        public async Task DialogBegin(DialogContext dc, IDictionary <string, object> dialogArgs = null)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            // Start the controls entry point dialog.
            IDictionary <string, object> result = null;
            var cdc = new DialogContext(this.Dialogs, dc.Context, dc.ActiveDialog.State, (r) => { result = r; });
            await cdc.Begin(DialogId, dialogArgs);

            // End if the controls dialog ends.
            if (cdc.ActiveDialog == null)
            {
                await dc.End(result);
            }
        }