public async Task DialogSet_AddWorks()
        {
            var convoState          = new ConversationState(new MemoryStorage());
            var dialogStateProperty = convoState.CreateProperty <DialogState>("dialogstate");
            var ds = new DialogSet(dialogStateProperty)
                     .Add(new WaterfallDialog("A"))
                     .Add(new WaterfallDialog("B"));

            Assert.NotNull(ds.Find("A"));
            Assert.NotNull(ds.Find("B"));
            Assert.Null(ds.Find("C"));
            await Task.CompletedTask;
        }
        public async Task DialogSet_NullTelemetrySet()
        {
            var convoState          = new ConversationState(new MemoryStorage());
            var dialogStateProperty = convoState.CreateProperty <DialogState>("dialogstate");
            var ds = new DialogSet(dialogStateProperty)
                     .Add(new WaterfallDialog("A"))
                     .Add(new WaterfallDialog("B"));

            ds.TelemetryClient = new MyBotTelemetryClient();
            ds.TelemetryClient = null;
            Assert.Equal(typeof(NullBotTelemetryClient), ds.Find("A").TelemetryClient.GetType());
            Assert.Equal(typeof(NullBotTelemetryClient), ds.Find("B").TelemetryClient.GetType());
            await Task.CompletedTask;
        }
        public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            var name = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;

            var test = new global::System.Resources.ResourceManager("Form Flow Sample.Resource.DynamicPizza", typeof(Resource.DynamicPizza).Assembly);

            //turnContext.Activity.Locale = Microsoft.Recognizers.Text.Culture.English;
            // We only want to pump one activity at a time through the state.
            // Note the state is shared across all instances of this IBot class so we
            // create the semaphore globally with the accessors.
            try
            {
                await _semaphore.WaitAsync();

                var dialogContext = await _dialogs.CreateContextAsync(turnContext, cancellationToken);

                if (turnContext.Activity.Type == ActivityTypes.Message)
                {
                    // run the DialogSet - let the framework identify the current state of the dialog from
                    // the dialog stack and figure out what (if any) is the active dialog
                    var results = await dialogContext.ContinueDialogAsync(cancellationToken);

                    // HasActive = true if there is an active dialog on the dialogstack
                    // HasResults = true if the dialog just completed and the final  result can be retrived
                    // if both are false this indicates a new dialog needs to start
                    // an additional check for Responded stops a new waterfall from being automatically started over
                    if ((results.Status == DialogTurnStatus.Cancelled || results.Status == DialogTurnStatus.Empty) ||
                        (results.Status == DialogTurnStatus.Complete && dialogContext.ActiveDialog == null))
                    {
                        var text        = turnContext.Activity.Text;
                        var foundDialog = _dialogs.Find(text);
                        if (foundDialog != null)
                        {
                            await dialogContext.BeginDialogAsync(foundDialog.Id, null, cancellationToken);
                        }
                        else
                        {
                            await dialogContext.BeginDialogAsync(typeof(MenuDialog).Name, null, cancellationToken);
                        }
                    }
                }
                else if (turnContext.Activity.Type == ActivityTypes.Event && turnContext.Activity.Name == "requestMenuDialog")
                {
                    await dialogContext.BeginDialogAsync(typeof(MenuDialog).Name, null, cancellationToken);
                }
            }
            catch (FormCanceledException ex)
            {
                var dialogContext = await _dialogs.CreateContextAsync(turnContext, cancellationToken);

                await dialogContext.Context.SendActivityAsync("Form Cancelled");

                await dialogContext.BeginDialogAsync(typeof(MenuDialog).Name, null, cancellationToken);
            }
            finally
            {
                _semaphore.Release();
            }
        }
        public async Task DialogSet_HeterogeneousLoggers()
        {
            var convoState          = new ConversationState(new MemoryStorage());
            var dialogStateProperty = convoState.CreateProperty <DialogState>("dialogstate");
            var ds = new DialogSet(dialogStateProperty)
                     .Add(new WaterfallDialog("A"))
                     .Add(new WaterfallDialog("B"));

            ds.Add(new WaterfallDialog("C"));

            // Make sure we can override (after Adding) the TelemetryClient and "sticks"
            ds.Find("C").TelemetryClient = new MyBotTelemetryClient();

            Assert.Equal(typeof(NullBotTelemetryClient), ds.Find("A").TelemetryClient.GetType());
            Assert.Equal(typeof(NullBotTelemetryClient), ds.Find("B").TelemetryClient.GetType());
            Assert.Equal(typeof(MyBotTelemetryClient), ds.Find("C").TelemetryClient.GetType());
            await Task.CompletedTask;
        }
Esempio n. 5
0
        public async Task DialogSet_TelemetrySet()
        {
            var convoState          = new ConversationState(new MemoryStorage());
            var dialogStateProperty = convoState.CreateProperty <DialogState>("dialogstate");
            var ds = new DialogSet(dialogStateProperty)
                     .Add(new WaterfallDialog("A"))
                     .Add(new WaterfallDialog("B"));

            Assert.IsTrue(ds.Find("A").TelemetryClient is NullBotTelemetryClient, "A not NullBotTelemetryClient");
            Assert.IsTrue(ds.Find("B").TelemetryClient is NullBotTelemetryClient, "A not NullBotTelemetryClient");

            var botTelemetryClient = new MyBotTelemetryClient();

            ds.TelemetryClient = botTelemetryClient;

            Assert.IsTrue(ds.Find("A").TelemetryClient is MyBotTelemetryClient, "A not MyBotTelemetryClient");
            Assert.IsTrue(ds.Find("B").TelemetryClient is MyBotTelemetryClient, "A not MyBotTelemetryClient");
            await Task.CompletedTask;
        }
Esempio n. 6
0
        /// <summary>
        /// JIT creates the dialog if necessary and begins the dialog.
        /// Type <typeparamref name="T"/> is the type of dialog, deriving from <see cref="DialogBase"/>
        /// </summary>
        public async Task <DialogTurnResult> BeginDialogAsync(DialogContext dialogContext, string dialogId, object options, CancellationToken cancellationToken)
        {
            // Only create the dialog if it doesn't exist.
            if (dialogs.Find(dialogId) == null)
            {
                var dialog = CreateFromDialogId(dialogId);
                if (dialog != null)
                {
                    var waterfallDialog = await dialog.GetWaterfallDialog(dialogContext.Context, cancellationToken);

                    this.dialogs.Add(waterfallDialog);
                }
            }

            return(await dialogContext.BeginDialogAsync(dialogId, options, cancellationToken));
        }
Esempio n. 7
0
        /// <summary>
        /// Run every turn of the conversation. Handles orchestration of messages.
        /// </summary>
        /// <param name="turnContext">Bot Turn Context.</param>
        /// <param name="cancellationToken">Task CancellationToken.</param>
        /// <returns>A <see cref="TaskItem"/> representing the asynchronous operation.</returns>
        public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken)
        {
            if (_dialogs.Find(nameof(MainDialog)) == null)
            {
                _dialogs.Add(new MainDialog(_services, _conversationState, _userState, _telemetryClient, _serviceManager, MailService, _skillMode));
            }

            var dc = await _dialogs.CreateContextAsync(turnContext);

            if (dc.ActiveDialog != null)
            {
                var result = await dc.ContinueDialogAsync();
            }
            else
            {
                await dc.BeginDialogAsync(nameof(MainDialog));
            }
        }