From 2761615a17c645ac42610e87e047176b54aafe03 Mon Sep 17 00:00:00 2001 From: Hualiang Xie Date: Thu, 31 Oct 2019 13:55:44 +0800 Subject: [PATCH] [ITSM] replace enum prompt --- .../experimental/itsmskill/Dialogs/ShowTicketDialog.cs | 7 ++++--- .../experimental/itsmskill/Dialogs/SkillDialogBase.cs | 5 +++-- .../itsmskill/Prompts/AttributeWithNoPrompt.cs | 10 +++++----- .../experimental/itsmskill/Prompts/GeneralPrompt.cs | 10 +++++----- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/skills/csharp/experimental/itsmskill/Dialogs/ShowTicketDialog.cs b/skills/csharp/experimental/itsmskill/Dialogs/ShowTicketDialog.cs index 36b928a070..d5bfdec6f5 100644 --- a/skills/csharp/experimental/itsmskill/Dialogs/ShowTicketDialog.cs +++ b/skills/csharp/experimental/itsmskill/Dialogs/ShowTicketDialog.cs @@ -159,7 +159,8 @@ public ShowTicketDialog( } var state = await StateAccessor.GetAsync(sc.Context, () => new SkillState()); - state.AttributeType = (AttributeType)sc.Result; + Enum.TryParse((string)sc.Result, out AttributeType attributeType); + state.AttributeType = attributeType; return await sc.NextAsync(); } @@ -275,7 +276,7 @@ public ShowTicketDialog( throw new Exception($"Invalid InterruptedIntent {state.InterruptedIntent}"); } - var intent = (GeneralLuis.Intent)sc.Result; + Enum.TryParse((string)sc.Result, out GeneralLuis.Intent intent); if (intent == GeneralLuis.Intent.Reject) { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SharedResponses.ActionEnded)); @@ -301,7 +302,7 @@ public ShowTicketDialog( } } - protected async Task ShowNavigateValidator(PromptValidatorContext promptContext, CancellationToken cancellationToken) + protected async Task ShowNavigateValidator(PromptValidatorContext promptContext, CancellationToken cancellationToken) { if (promptContext.Recognized.Succeeded) { diff --git a/skills/csharp/experimental/itsmskill/Dialogs/SkillDialogBase.cs b/skills/csharp/experimental/itsmskill/Dialogs/SkillDialogBase.cs index 12b6b9cef1..2dfb11a477 100644 --- a/skills/csharp/experimental/itsmskill/Dialogs/SkillDialogBase.cs +++ b/skills/csharp/experimental/itsmskill/Dialogs/SkillDialogBase.cs @@ -345,7 +345,8 @@ protected async Task GetAuthToken(WaterfallStepContext sc, Can } var state = await StateAccessor.GetAsync(sc.Context, () => new SkillState()); - state.AttributeType = (AttributeType)sc.Result; + Enum.TryParse((string)sc.Result, out AttributeType attributeType); + state.AttributeType = attributeType; return await sc.NextAsync(); } @@ -881,7 +882,7 @@ protected async Task GetAuthToken(WaterfallStepContext sc, Can protected async Task IfKnowledgeHelp(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { - var intent = (GeneralLuis.Intent)sc.Result; + Enum.TryParse((string)sc.Result, out GeneralLuis.Intent intent); if (intent == GeneralLuis.Intent.Confirm) { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SharedResponses.ActionEnded)); diff --git a/skills/csharp/experimental/itsmskill/Prompts/AttributeWithNoPrompt.cs b/skills/csharp/experimental/itsmskill/Prompts/AttributeWithNoPrompt.cs index 8d5f754515..6083a855f8 100644 --- a/skills/csharp/experimental/itsmskill/Prompts/AttributeWithNoPrompt.cs +++ b/skills/csharp/experimental/itsmskill/Prompts/AttributeWithNoPrompt.cs @@ -15,11 +15,11 @@ namespace ITSMSkill.Prompts { - public class AttributeWithNoPrompt : Prompt + public class AttributeWithNoPrompt : Prompt { private readonly AttributeType[] attributes; - public AttributeWithNoPrompt(string dialogId, AttributeType[] attributes, PromptValidator validator = null, string defaultLocale = null) + public AttributeWithNoPrompt(string dialogId, AttributeType[] attributes, PromptValidator validator = null, string defaultLocale = null) : base(dialogId, validator) { this.attributes = attributes; @@ -50,14 +50,14 @@ public AttributeWithNoPrompt(string dialogId, AttributeType[] attributes, Prompt } } - protected override async Task> OnRecognizeAsync(ITurnContext turnContext, IDictionary state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken)) + protected override async Task> OnRecognizeAsync(ITurnContext turnContext, IDictionary state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken)) { if (turnContext == null) { throw new ArgumentNullException(nameof(turnContext)); } - var result = new PromptRecognizerResult(); + var result = new PromptRecognizerResult(); if (turnContext.Activity.Type == ActivityTypes.Message) { var message = turnContext.Activity.AsMessageActivity(); @@ -77,7 +77,7 @@ public AttributeWithNoPrompt(string dialogId, AttributeType[] attributes, Prompt if (IsMessageAttributeMatch(text, attribute)) { result.Succeeded = true; - result.Value = attribute; + result.Value = attribute.ToString(); break; } } diff --git a/skills/csharp/experimental/itsmskill/Prompts/GeneralPrompt.cs b/skills/csharp/experimental/itsmskill/Prompts/GeneralPrompt.cs index f7f4847524..6e49ddf1b6 100644 --- a/skills/csharp/experimental/itsmskill/Prompts/GeneralPrompt.cs +++ b/skills/csharp/experimental/itsmskill/Prompts/GeneralPrompt.cs @@ -12,12 +12,12 @@ namespace ITSMSkill.Prompts { - public class GeneralPrompt : Prompt + public class GeneralPrompt : Prompt { private readonly ISet intents; private readonly IStatePropertyAccessor stateAccessor; - public GeneralPrompt(string dialogId, ISet intents, IStatePropertyAccessor stateAccessor, PromptValidator validator = null, string defaultLocale = null) + public GeneralPrompt(string dialogId, ISet intents, IStatePropertyAccessor stateAccessor, PromptValidator validator = null, string defaultLocale = null) : base(dialogId, validator) { this.intents = intents; @@ -49,21 +49,21 @@ public GeneralPrompt(string dialogId, ISet intents, IStatePr } } - protected override async Task> OnRecognizeAsync(ITurnContext turnContext, IDictionary state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken)) + protected override async Task> OnRecognizeAsync(ITurnContext turnContext, IDictionary state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken)) { if (turnContext == null) { throw new ArgumentNullException(nameof(turnContext)); } - var result = new PromptRecognizerResult(); + var result = new PromptRecognizerResult(); var skillState = await stateAccessor.GetAsync(turnContext); if (intents.Contains(skillState.GeneralIntent)) { result.Succeeded = true; - result.Value = skillState.GeneralIntent; + result.Value = skillState.GeneralIntent.ToString(); } return await Task.FromResult(result);