Exemplo n.º 1
0
        private void SetChoiceSets()
        {
            List <int> choices = new List <int>();

            for (int i = 0; i < OrderedAdaptors.Count - 1; i++)
            {
                choices.Add(OrderedAdaptors[i]);

                if (OrderedAdaptors[i + 1] == OrderedAdaptors[i] + 3)
                {
                    ChoiceSet.Add(choices);
                    choices = new List <int>();
                }
            }
        }
Exemplo n.º 2
0
        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>()
            };

            Dialog lastDialog = null;
            var    choices    = new ChoiceSet();

            foreach (var resource in this.resourceExplorer.GetResources(".dialog").Where(r => r.Id.EndsWith(".main.dialog")))
            {
                try
                {
                    var name = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(resource.Id));
                    choices.Add(new Choice(name));
                    var dialog = resourceExplorer.LoadType <Dialog>(resource);
                    lastDialog = dialog;
                    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);
                }
            }

            if (handleChoice.Cases.Count() == 1)
            {
                rootDialog.Triggers.Add(new OnBeginDialog()
                {
                    Actions = new List <Dialog>()
                    {
                        lastDialog,
                        new RepeatDialog()
                    }
                });
            }
            else
            {
                choiceInput.Choices = choices;
                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)
                                 .UseResourceExplorer(this.resourceExplorer)
                                 .UseLanguageGeneration();

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

            // Create a non-used dialog just to make sure the target assembly is referred so that
            // the target assembly's component registration can be used to deserialize declarative components
            var qnaDialog = new QnAMakerDialog();

            System.Diagnostics.Trace.TraceInformation($"Touch ${qnaDialog.GetType().ToString()} to make sure assembly is referred.");

            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>()
            };

            Dialog lastDialog = null;
            var    choices    = new ChoiceSet();
            var    dialogName = configuration["dialog"];

            foreach (var resource in this.resourceExplorer.GetResources(".dialog").Where(r => dialogName != null ? r.Id == dialogName : r.Id.EndsWith(".main.dialog")))
            {
                try
                {
                    var name = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(resource.Id));
                    choices.Add(new Choice(name));
                    var dialog = resourceExplorer.LoadType <Dialog>(resource);
                    lastDialog = dialog;
                    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);
                }
            }

            if (handleChoice.Cases.Count() == 1)
            {
                rootDialog.Triggers.Add(new OnBeginDialog
                {
                    Actions = new List <Dialog>
                    {
                        lastDialog,
                        new RepeatDialog()
                    }
                });
            }
            else
            {
                choiceInput.Choices = choices;
                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)
                                 .UseResourceExplorer(this.resourceExplorer)
                                 .UseLanguageGeneration();

            Trace.TraceInformation("Done loading resources.");
        }