private TestFlow BuildTestFlow(string folderPath, bool sendTrace = false)
        {
            TypeFactory.Configuration = new ConfigurationBuilder().Build();
            var storage          = new MemoryStorage();
            var convoState       = new ConversationState(storage);
            var userState        = new UserState(storage);
            var adapter          = new TestAdapter(TestAdapter.CreateConversation(TestContext.TestName), sendTrace);
            var resourceExplorer = new ResourceExplorer();

            resourceExplorer.AddFolder(folderPath);
            adapter
            .UseStorage(storage)
            .UseState(userState, convoState)
            .UseAdaptiveDialogs()
            .UseLanguageGeneration(resourceExplorer, "common.lg")
            .UseResourceExplorer(resourceExplorer)
            .Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

            var           resource = resourceExplorer.GetResource("Main.dialog");
            var           dialog   = DeclarativeTypeLoader.Load <AdaptiveDialog>(resource, resourceExplorer, DebugSupport.SourceMap);
            DialogManager dm       = new DialogManager(dialog);

            return(new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                if (dialog is AdaptiveDialog planningDialog)
                {
                    await dm.OnTurnAsync(turnContext, cancellationToken).ConfigureAwait(false);
                }
            }));
        }
Beispiel #2
0
        public AdaptiveBot(ResourceExplorer resourceExplorer)
        {
            this.resourceExplorer = resourceExplorer;
            var resource = this.resourceExplorer.GetResource("main.dialog");

            this.dialogManager = new DialogManager(DeclarativeTypeLoader.Load <AdaptiveDialog>(resource, resourceExplorer, DebugSupport.SourceMap));
        }
Beispiel #3
0
        private void LoadRootDialogAsync()
        {
            var rootFile = resourceExplorer.GetResource(rootDialogFile);

            rootDialog         = DeclarativeTypeLoader.Load <AdaptiveDialog>(rootFile, resourceExplorer, sourceMap);
            this.dialogManager = new DialogManager(rootDialog);
        }
Beispiel #4
0
        public AdaptiveBot(ResourceExplorer resourceExplorer)
        {
            this.resourceExplorer = resourceExplorer;

            void LoadRootDialog()
            {
                // user scoped
                //var root = this.resourceExplorer.GetResource("userScoped.dialog");
                //this.dialogManager = new DialogManager(DeclarativeTypeLoader.Load<AdaptiveDialog>(root, resourceExplorer, DebugSupport.SourceMap));

                // conversation scoped
                //var root = this.resourceExplorer.GetResource("conversationScoped.dialog");
                //this.dialogManager = new DialogManager(DeclarativeTypeLoader.Load<AdaptiveDialog>(root, resourceExplorer, DebugSupport.SourceMap));

                // dialog scoped
                //var child = this.resourceExplorer.GetResource("dialogScoped-child.dialog");
                //DeclarativeTypeLoader.Load<AdaptiveDialog>(child, resourceExplorer, DebugSupport.SourceMap);
                //var root = this.resourceExplorer.GetResource("dialogScoped-parent.dialog");
                //this.dialogManager = new DialogManager(DeclarativeTypeLoader.Load<AdaptiveDialog>(root, resourceExplorer, DebugSupport.SourceMap));

                // turn scoped
                var root = this.resourceExplorer.GetResource("turnScoped.dialog");

                this.dialogManager = new DialogManager(DeclarativeTypeLoader.Load <AdaptiveDialog>(root, resourceExplorer, DebugSupport.SourceMap));
            }

            LoadRootDialog();
        }
        private void LoadDialogs()
        {
            System.Diagnostics.Trace.TraceInformation("Loading resources...");

            var rootDialog = new AdaptiveDialog()
            {
                AutoEndDialog = false,
            };
            var choiceInput = new ChoiceInput()
            {
                Prompt       = new ActivityTemplate("What declarative sample do you want to run?"),
                Property     = "conversation.dialogChoice",
                AlwaysPrompt = true,
                Choices      = new ChoiceSet(new List <Choice>())
            };

            var handleChoice = new SwitchCondition()
            {
                Condition = "conversation.dialogChoice",
                Cases     = new List <Case>()
            };

            foreach (var resource in this.resourceExplorer.GetResources(".dialog").Where(r => r.Id.EndsWith(".main.dialog")))
            {
                try
                {
                    var name = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(resource.Id));
                    choiceInput.Choices.Value.Add(new Choice(name));
                    var dialog = DeclarativeTypeLoader.Load <Dialog>(resource, this.resourceExplorer, DebugSupport.SourceMap);
                    handleChoice.Cases.Add(new Case($"{name}", new List <Dialog>()
                    {
                        dialog
                    }));
                }
                catch (SyntaxErrorException err)
                {
                    Trace.TraceError($"{err.Source}: Error: {err.Message}");
                }
                catch (Exception err)
                {
                    Trace.TraceError(err.Message);
                }
            }

            choiceInput.Style = ListStyle.Auto;
            rootDialog.Triggers.Add(new OnBeginDialog()
            {
                Actions = new List <Dialog>()
                {
                    choiceInput,
                    new SendActivity("# Running @{conversation.dialogChoice}.main.dialog"),
                    handleChoice,
                    new RepeatDialog()
                }
            });

            this.dialogManager = new DialogManager(rootDialog);

            System.Diagnostics.Trace.TraceInformation("Done loading resources.");
        }
Beispiel #6
0
        public RootDialog(UserState userState) : base("root")
        {
            _userState = userState;

            AddDialog(new UserProfileDialog(userState));

            // The initial child Dialog to run.
            InitialDialogId = "waterfall";

            // Get Folder of dialogs.
            var resourceExplorer = new ResourceExplorer().AddFolder("Dialogs");

            // find the main composer dialog to start with
            var composerDialog = resourceExplorer.GetResource("Main.dialog");

            // hyrdate an Adaptive Dialogue
            AdaptiveDialog myComposerDialog = DeclarativeTypeLoader.Load <AdaptiveDialog>(composerDialog, resourceExplorer, DebugSupport.SourceMap);

            myComposerDialog.Id = "Main.dialog";

            // setup lanaguage generation for the dialogue
            myComposerDialog.Generator = new TemplateEngineLanguageGenerator(new TemplateEngine().AddFile(@"C:\Users\Jamie\source\repos\composer-adaptive-regular-hybrid\Dialogs\ComposerDialogs\Main\Main.lg"));

            // add to the ComponentDialog which Root dialogue inherits from
            AddDialog(myComposerDialog);

            AddDialog(new WaterfallDialog("waterfall", new WaterfallStep[] { StartDialogAsync, BeginComposerAdaptiveDialog }));
        }
        public AdaptiveBot(ConversationState conversationState, ResourceExplorer resourceExplorer)
        {
            this.dialogStateAccessor = conversationState.CreateProperty <DialogState>("RootDialogState");
            this.resourceExplorer    = resourceExplorer;
            var resource = this.resourceExplorer.GetResource("main.dialog");

            this.dialogManager = new DialogManager(DeclarativeTypeLoader.Load <AdaptiveDialog>(resource, resourceExplorer, DebugSupport.SourceMap));
        }
        private void LoadDialogs()
        {
            System.Diagnostics.Trace.TraceInformation("Loading resources...");

            var resource = this.resourceExplorer.GetResource("main.dialog");

            this.dialogManager = new DialogManager(DeclarativeTypeLoader.Load <AdaptiveDialog>(resource, resourceExplorer, DebugSupport.SourceRegistry));

            System.Diagnostics.Trace.TraceInformation("Done loading resources.");
        }
Beispiel #9
0
        private void LoadDialogs()
        {
            System.Diagnostics.Trace.TraceInformation("Loading resources...");

            var resource = this.resourceExplorer.GetResource("EchoDialogSteps.dialog");

            //var resource = this.resourceExplorer.GetResource("EchoDialogRule.dialog");
            rootDialog = DeclarativeTypeLoader.Load <AdaptiveDialog>(resource, resourceExplorer, DebugSupport.SourceRegistry);

            System.Diagnostics.Trace.TraceInformation("Done loading resources.");
        }
Beispiel #10
0
        private TestFlow BuildQnAMakerTestFlow()
        {
            var adapter = InitializeAdapter()
                          .Use(new RegisterClassMiddleware <IQnAMakerClient>(new MockQnAMakerClient()));
            var resource       = resourceExplorer.GetResource("QnAMakerBot.main.dialog");
            var dialog         = DeclarativeTypeLoader.Load <AdaptiveDialog>(resource, resourceExplorer, DebugSupport.SourceMap);
            var qnaMakerDialog = (QnAMakerDialog2)dialog.Triggers[0].Actions[0];

            dialog.Triggers[0].Actions[0] = qnaMakerDialog;

            return(GetTestAdapter(dialog, adapter));
        }
Beispiel #11
0
        public AdaptiveBot(ResourceExplorer resourceExplorer)
        {
            this.resourceExplorer = resourceExplorer;

            void LoadRootDialog()
            {
                var root = this.resourceExplorer.GetResource("regexRecognizerDemo.dialog");

                this.dialogManager = new DialogManager(DeclarativeTypeLoader.Load <AdaptiveDialog>(root, resourceExplorer, DebugSupport.SourceMap));
            }

            LoadRootDialog();
        }
 public async Task TestDialogInjectionDeclarative()
 {
     await CreateFlow("en-us", async (turnContext, cancellationToken) =>
     {
         var resource     = resourceExplorer.GetResource("test.dialog");
         var dialog       = (AdaptiveDialog)DeclarativeTypeLoader.Load <Dialog>(resource, resourceExplorer, DebugSupport.SourceMap);
         DialogManager dm = new DialogManager(dialog);
         await dm.OnTurnAsync(turnContext, cancellationToken: cancellationToken).ConfigureAwait(false);
     })
     .Send("hello")
     .AssertReply("root")
     .AssertReply("overriden")
     .StartTestAsync();
 }
        private AdaptiveDialog CreateChoiceInputForAllMainDialogs()
        {
            var dialogChoices = new List <Choice>();
            var dialogCases   = new List <Case>();

            foreach (var resource in this.resourceExplorer.GetResources(".dialog").Where(r => r.Id.EndsWith(".main.dialog")))
            {
                var name = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(resource.Id));
                dialogChoices.Add(new Choice(name));
                var subDialog = DeclarativeTypeLoader.Load <AdaptiveDialog>(resource, resourceExplorer, DebugSupport.SourceMap);
                dialogCases.Add(new Case($"{name}", new List <Dialog>()
                {
                    subDialog
                }));
            }

            var dialog = new AdaptiveDialog()
            {
                AutoEndDialog = false,
                Triggers      = new List <OnCondition>()
                {
                    new OnBeginDialog()
                    {
                        Actions = new List <Dialog>()
                        {
                            new ChoiceInput()
                            {
                                Prompt       = new ActivityTemplate("What declarative sample do you want to run?"),
                                Property     = "conversation.dialogChoice",
                                AlwaysPrompt = true,
                                Style        = ListStyle.List,
                                Choices      = new ChoiceSet(dialogChoices)
                            },
                            new SendActivity("# Running {conversation.dialogChoice}.main.dialog"),
                            new SwitchCondition()
                            {
                                Condition = "conversation.dialogChoice",
                                Cases     = dialogCases
                            },
                            new RepeatDialog()
                        }
                    }
                }
            };

            return(dialog);
        }
Beispiel #14
0
        private void LoadDialogs()
        {
            System.Diagnostics.Trace.TraceInformation("Loading resources...");

            this.rootDialog = new AdaptiveDialog()
            {
                AutoEndDialog = false,
                Steps         = new List <IDialog>()
            };
            var choiceInput = new ChoiceInput()
            {
                Prompt        = new ActivityTemplate("What declarative sample do you want to run?"),
                OutputBinding = "conversation.dialogChoice",
                AlwaysPrompt  = true,
                Choices       = new List <Choice>()
            };

            var handleChoice = new SwitchCondition()
            {
                Condition = "conversation.dialogChoice",
                Cases     = new List <Case>()
            };

            foreach (var resource in this.resourceExplorer.GetResources(".dialog").Where(r => r.Id.EndsWith(".main.dialog")))
            {
                var name = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(resource.Id));
                choiceInput.Choices.Add(new Choice(name));
                var dialog = DeclarativeTypeLoader.Load <IDialog>(resource, this.resourceExplorer, DebugSupport.SourceRegistry);
                handleChoice.Cases.Add(new Case($"'{name}'", new List <IDialog>()
                {
                    dialog
                }));
            }
            choiceInput.Style = ListStyle.Auto;
            this.rootDialog.Steps.Add(choiceInput);
            this.rootDialog.Steps.Add(new SendActivity("# Running {conversation.dialogChoice}.main.dialog"));
            this.rootDialog.Steps.Add(handleChoice);
            this.rootDialog.Steps.Add(new RepeatDialog());

            System.Diagnostics.Trace.TraceInformation("Done loading resources.");
        }
        private AdaptiveDialog CreateChoiceInputForAllMainDialogs()
        {
            var dialog = new AdaptiveDialog()
            {
                AutoEndDialog = false,
                Steps         = new List <IDialog>()
            };
            var choiceInput = new ChoiceInput()
            {
                Prompt       = new ActivityTemplate("What declarative sample do you want to run?"),
                Property     = "conversation.dialogChoice",
                AlwaysPrompt = true,
                Choices      = new List <Choice>(),
            };

            var handleChoice = new SwitchCondition()
            {
                Condition = "conversation.dialogChoice",
                Cases     = new List <Case>()
            };

            foreach (var resource in this.resourceExplorer.GetResources(".dialog").Where(r => r.Id.EndsWith(".main.dialog")))
            {
                var name = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(resource.Id));
                choiceInput.Choices.Add(new Choice(name));
                var subDialog = DeclarativeTypeLoader.Load <IDialog>(resource, this.resourceExplorer, DebugSupport.SourceRegistry);
                handleChoice.Cases.Add(new Case($"{name}", new List <IDialog>()
                {
                    subDialog
                }));
            }
            choiceInput.Style = ListStyle.List;
            dialog.Steps.Add(choiceInput);
            dialog.Steps.Add(new SendActivity("# Running {conversation.dialogChoice}.main.dialog"));
            dialog.Steps.Add(handleChoice);
            dialog.Steps.Add(new RepeatDialog());
            return(dialog);
        }
Beispiel #16
0
        public RootDialog(UserState userState) : base("root")
        {
            _userState = userState;

            // Get Folder of dialogs.
            var resourceExplorer = new ResourceExplorer().AddFolder(@"Dialogs");

            // find the main composer dialog to start with
            var composerDialog = resourceExplorer.GetResource("Main.dialog");

            // hyrdate an Adaptive Dialogue
            AdaptiveDialog myComposerDialog = DeclarativeTypeLoader.Load <AdaptiveDialog>(composerDialog, resourceExplorer, DebugSupport.SourceMap);

            myComposerDialog.Id = "Main.dialog";

            // setup lanaguage generation for the dialogue
            myComposerDialog.Generator = new TemplateEngineLanguageGenerator(new TemplateEngine().AddFile(@"Dialogs\ComposerDialogs\Main\Main.lg"));

            // add to the ComponentDialog which Root dialogue inherits from
            AddDialog(myComposerDialog);

            // create a waterfall dialogue and begin our adaptive dialogue
            AddDialog(new WaterfallDialog("waterfall", new WaterfallStep[] { BeginComposerAdaptiveDialog }));
        }
 /// <summary>
 /// Create Type from resource.
 /// </summary>
 /// <typeparam name="T">type to create.</typeparam>
 /// <param name="resource">resource to bind to.</param>
 /// <returns>created type.</returns>
 public T LoadType <T>(IResource resource)
 {
     return(DeclarativeTypeLoader.Load <T>(resource, this, DebugSupport.SourceMap));
 }
        private Dialog FetchDialogFromResource(string resourceName)
        {
            var resource = resourceExplorer.GetResource(resourceName);

            return(DeclarativeTypeLoader.Load <Dialog>(resource, resourceExplorer, DebugSupport.SourceMap));
        }