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."); }
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); }
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(); 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..."); var rootDialog = new AdaptiveDialog() { AutoEndDialog = false, }; var choiceInput = new ChoiceInput() { Prompt = new ActivityTemplate("What dialog 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 _resourceExplorer.GetResources(".dialog").Where(r => dialogName != null ? r.Id == dialogName : r.Id.Count(c => c == '.') == 1)) { 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}.dialog"), handleChoice, new RepeatDialog() } }); } _dialogManager = new DialogManager(rootDialog) .UseResourceExplorer(_resourceExplorer) .UseLanguageGeneration(); Trace.TraceInformation("Done loading resources."); }