This commit is contained in:
Tom Laird-McConnell 2019-03-18 18:18:28 -07:00
Родитель 119742d1a1
Коммит f7e19df509
17 изменённых файлов: 81 добавлений и 97 удалений

Просмотреть файл

@ -44,6 +44,7 @@ namespace Microsoft.Bot.Builder.AI.Luis
/// <param name="includeApiResults">(Optional) TRUE to include raw LUIS API response.</param>
/// <param name="clientHandler">(Optional) Custom handler for LUIS API calls to allow mocking.</param>
/// <param name="telemetryClient">The IBotTelemetryClient used to log the LuisResult event.</param>
/// <param name="logPersonalInformation">TRUE to include personally indentifiable information.</param>
public LuisRecognizer(LuisApplication application, LuisPredictionOptions predictionOptions = null, bool includeApiResults = false, HttpClientHandler clientHandler = null, IBotTelemetryClient telemetryClient = null, bool logPersonalInformation = false)
{
_application = application ?? throw new ArgumentNullException(nameof(application));
@ -90,20 +91,6 @@ namespace Microsoft.Bot.Builder.AI.Luis
{
}
/// <summary>
/// Initializes a new instance of the <see cref="LuisRecognizer"/> class.
/// </summary>
/// <param name="telemetryClient">The IBotTelemetryClient used to log the LuisResult event.</param>
/// <param name="application">The LUIS application to use to recognize text.</param>
/// <param name="predictionOptions">The LUIS prediction options to use.</param>
/// <param name="includeApiResults">TRUE to include raw LUIS API response.</param>
/// <param name="logPersonalInformation">TRUE to include personally indentifiable information.</param>
public LuisRecognizer(LuisApplication application, LuisPredictionOptions predictionOptions = null, bool includeApiResults = false, IBotTelemetryClient telemetryClient = null, bool logPersonalInformation = false)
: this(application, predictionOptions, includeApiResults, null, telemetryClient)
{
LogPersonalInformation = logPersonalInformation;
}
/// <summary>
/// Gets or sets a value indicating whether to log personal information that came from the user to telemetry.
/// </summary>

Просмотреть файл

@ -33,7 +33,7 @@ namespace Microsoft.Bot.Builder.AI.LanguageGeneration
if (evalutationTargetStack.Any(e => e.TemplateName == templateName))
{
throw new Exception($"Loop deteced: {String.Join(" => ", evalutationTargetStack.Reverse().Select(e => e.TemplateName))} => {templateName}");
throw new Exception($"Loop detected: {String.Join(" => ", evalutationTargetStack.Reverse().Select(e => e.TemplateName))} => {templateName}");
}
// Using a stack to track the evalution trace

Просмотреть файл

@ -49,7 +49,7 @@ namespace Microsoft.Bot.Builder.AI.LanguageGeneration
if (evalutationTargetStack.Any(e => e.TemplateName == templateName))
{
throw new Exception($"Loop deteced: {String.Join(" => ", evalutationTargetStack.Reverse().Select(e => e.TemplateName))} => {templateName}");
throw new Exception($"Loop detected: {String.Join(" => ", evalutationTargetStack.Reverse().Select(e => e.TemplateName))} => {templateName}");
}
// Using a stack to track the evalution trace

Просмотреть файл

@ -23,7 +23,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Rules
public PlanningContext(DialogContext dc, DialogContext parentDc, DialogSet dialogs, DialogState state, PlanningState plans)
: base(dialogs, dc.Context, state, dc.State.Conversation, dc.State.User)
{
this.ParentContext = parentDc;
this.Parent = parentDc;
this.Plans = plans ?? throw new ArgumentNullException(nameof(plans));
}
@ -319,7 +319,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Rules
public static PlanningContext Create(DialogContext dc, PlanningState plans)
{
return new PlanningContext(dc, dc.ParentContext, dc.Dialogs, new DialogState() { DialogStack = dc.Stack }, plans);
return new PlanningContext(dc, dc.Parent, dc.Dialogs, new DialogState() { DialogStack = dc.Stack }, plans);
}
public static PlanningContext CreateForStep(PlanningContext planning, DialogSet dialogs)

Просмотреть файл

@ -24,13 +24,13 @@ namespace Microsoft.Bot.Builder.Dialogs
{
PopCommands(dc);
if (dc.Stack.Count > 0 || dc.ParentContext == null)
if (dc.Stack.Count > 0 || dc.Parent == null)
{
return await dc.EndDialogAsync(result, cancellationToken).ConfigureAwait(false);
}
else
{
var turnResult = await dc.ParentContext.EndDialogAsync(result, cancellationToken).ConfigureAwait(false);
var turnResult = await dc.Parent.EndDialogAsync(result, cancellationToken).ConfigureAwait(false);
turnResult.ParentEnded = true;
return turnResult;
}
@ -40,13 +40,13 @@ namespace Microsoft.Bot.Builder.Dialogs
{
PopCommands(dc);
if (dc.Stack.Count > 0 || dc.ParentContext == null)
if (dc.Stack.Count > 0 || dc.Parent == null)
{
return await dc.ReplaceDialogAsync(dialogId, options, cancellationToken).ConfigureAwait(false);
}
else
{
var turnResult = await dc.ParentContext.ReplaceDialogAsync(dialogId, options, cancellationToken).ConfigureAwait(false);
var turnResult = await dc.Parent.ReplaceDialogAsync(dialogId, options, cancellationToken).ConfigureAwait(false);
turnResult.ParentEnded = true;
return turnResult;
}
@ -56,13 +56,13 @@ namespace Microsoft.Bot.Builder.Dialogs
{
PopCommands(dc);
if (dc.Stack.Count > 0 || dc.ParentContext == null)
if (dc.Stack.Count > 0 || dc.Parent == null)
{
return await dc.ReplaceDialogAsync(dc.ActiveDialog.Id, options, cancellationToken).ConfigureAwait(false);
}
else
{
var turnResult = await dc.ParentContext.ReplaceDialogAsync(dc.ParentContext.ActiveDialog.Id, options, cancellationToken).ConfigureAwait(false);
var turnResult = await dc.Parent.ReplaceDialogAsync(dc.Parent.ActiveDialog.Id, options, cancellationToken).ConfigureAwait(false);
turnResult.ParentEnded = true;
return turnResult;
}
@ -72,13 +72,13 @@ namespace Microsoft.Bot.Builder.Dialogs
{
PopCommands(dc);
if (dc.Stack.Count > 0 || dc.ParentContext == null)
if (dc.Stack.Count > 0 || dc.Parent == null)
{
return await dc.CancelAllDialogsAsync(cancellationToken).ConfigureAwait(false);
}
else
{
var turnResult = await dc.ParentContext.CancelAllDialogsAsync(cancellationToken).ConfigureAwait(false);
var turnResult = await dc.Parent.CancelAllDialogsAsync(cancellationToken).ConfigureAwait(false);
turnResult.ParentEnded = true;
return turnResult;
}

Просмотреть файл

@ -23,8 +23,8 @@ namespace Microsoft.Bot.Builder.Dialogs
public DialogContext(DialogSet dialogs, DialogContext parentDialogContext, DialogState state, StateMap conversationState = null, StateMap userState = null)
{
Dialogs = dialogs;
ParentContext = parentDialogContext ?? throw new ArgumentNullException(nameof(parentDialogContext));
Context = ParentContext.Context;
Parent = parentDialogContext ?? throw new ArgumentNullException(nameof(parentDialogContext));
Context = Parent.Context;
Stack = state.DialogStack;
conversationState = conversationState ?? state?.ConversationState ?? new StateMap();
userState = userState ?? state?.UserState ?? new StateMap();
@ -34,7 +34,7 @@ namespace Microsoft.Bot.Builder.Dialogs
public DialogContext(DialogSet dialogs, ITurnContext turnContext, DialogState state, StateMap conversationState = null, StateMap userState = null)
{
ParentContext = null;
Parent = null;
Dialogs = dialogs ?? throw new ArgumentNullException(nameof(dialogs));
Context = turnContext ?? throw new ArgumentNullException(nameof(turnContext));
Stack = state.DialogStack;
@ -44,7 +44,7 @@ namespace Microsoft.Bot.Builder.Dialogs
State = new DialogContextState(this, userState, conversationState);
}
public DialogContext ParentContext { get; protected set; }
public DialogContext Parent { get; protected set; }
public DialogSet Dialogs { get; private set; }
@ -98,9 +98,9 @@ namespace Microsoft.Bot.Builder.Dialogs
if (activeTags == null)
{
// Get parent tags that are active
if (ParentContext != null)
if (Parent != null)
{
activeTags = ParentContext.ActiveTags;
activeTags = Parent.ActiveTags;
}
else
{
@ -184,10 +184,10 @@ namespace Microsoft.Bot.Builder.Dialogs
{
state = Stack.Count - 1;
}
else if (ParentContext != null)
else if (Parent != null)
{
// We can't use -0 so index 0 in the parent's stack is encoded as -1
state = 0 - ParentContext.Stack.Count;
state = 0 - Parent.Stack.Count;
}
// Find stack entry to inherit
@ -319,7 +319,7 @@ namespace Microsoft.Bot.Builder.Dialogs
{
activeTags = null;
if (Stack.Any() || ParentContext != null)
if (Stack.Any() || Parent != null)
{
// Cancel all local and parent dialogs while checking for interception
var notify = false;
@ -345,7 +345,7 @@ namespace Microsoft.Bot.Builder.Dialogs
}
else
{
dialogContext = dialogContext.ParentContext;
dialogContext = dialogContext.Parent;
}
notify = true;
}
@ -423,9 +423,9 @@ namespace Microsoft.Bot.Builder.Dialogs
}
}
if (this.ParentContext != null)
if (this.Parent != null)
{
return this.ParentContext.FindDialog(dialogId);
return this.Parent.FindDialog(dialogId);
}
return null;
@ -468,9 +468,9 @@ namespace Microsoft.Bot.Builder.Dialogs
}
// Break out if not bubbling or no parent
if (!handled && dialogEvent.Bubble && ParentContext != null)
if (!handled && dialogEvent.Bubble && Parent != null)
{
dc = ParentContext;
dc = Parent;
}
else
{
@ -560,9 +560,9 @@ namespace Microsoft.Bot.Builder.Dialogs
throw new Exception("DialogContext.ActiveDialog: Can't find inherited state. Index out of range.");
}
}
else if (dialogContext.ParentContext != null)
else if (dialogContext.Parent != null)
{
return this.GetActiveDialogState(dialogContext.ParentContext, -stateIndex - 1);
return this.GetActiveDialogState(dialogContext.Parent, -stateIndex - 1);
}
else
{

Просмотреть файл

@ -41,9 +41,9 @@ namespace Microsoft.Bot.Builder.Dialogs
if (instance == null)
{
if (dialogContext.ParentContext != null)
if (dialogContext.Parent != null)
{
instance = dialogContext.ParentContext.ActiveDialog;
instance = dialogContext.Parent.ActiveDialog;
}
else
{
@ -60,9 +60,9 @@ namespace Microsoft.Bot.Builder.Dialogs
if (instance == null)
{
if (dialogContext.ParentContext != null)
if (dialogContext.Parent != null)
{
instance = dialogContext.ParentContext.ActiveDialog;
instance = dialogContext.Parent.ActiveDialog;
}
else
{
@ -88,9 +88,9 @@ namespace Microsoft.Bot.Builder.Dialogs
if (instance == null)
{
if (dialogContext.ParentContext != null)
if (dialogContext.Parent != null)
{
instance = dialogContext.ParentContext.ActiveDialog;
instance = dialogContext.Parent.ActiveDialog;
}
}

Просмотреть файл

@ -129,7 +129,7 @@ namespace Microsoft.Bot.Builder.Dialogs
/// </summary>
/// <param name="dialogId">ID of the dialog/prompt to look up.</param>
/// <returns>The dialog if found, otherwise null.</returns>
public Dialog Find(string dialogId)
public IDialog Find(string dialogId)
{
if (string.IsNullOrWhiteSpace(dialogId))
{

Просмотреть файл

@ -69,7 +69,10 @@
<PackageReference Include="Microsoft.Bot.Builder" Condition=" '$(PackageVersion)' != '' " Version="$(PackageVersion)" />
<PackageReference Include="Microsoft.Recognizers.Text.Choice" Version="1.1.3" />
<PackageReference Include="Microsoft.Recognizers.Text.DateTime" Version="1.1.3" />
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.1" />
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta008" PrivateAssets="all" />
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
</ItemGroup>

Просмотреть файл

@ -10,17 +10,16 @@ namespace Microsoft.Bot.Builder.Dialogs
{
public class WaterfallStepContext : DialogContext
{
private readonly WaterfallDialog _parent;
private readonly WaterfallDialog _parentWaterfall;
private bool _nextCalled;
/// <summary>
/// Provides context for a turn of a waterfall dialog. Contains ITurnContext as property 'Context'.
/// </summary>
internal WaterfallStepContext(WaterfallDialog parent, DialogContext dc, object options, IDictionary<string, object> values, int index, DialogReason reason, object result = null)
internal WaterfallStepContext(WaterfallDialog parentWaterfall, DialogContext dc, object options, IDictionary<string, object> values, int index, DialogReason reason, object result = null)
: base(dc.Dialogs, dc.Context, new DialogState(dc.Stack), dc.State.Conversation, dc.State.User)
{
this.ParentContext = dc.ParentContext;
_parent = parent;
_parentWaterfall = parentWaterfall;
_nextCalled = false;
Parent = dc.Parent;
Index = index;
@ -66,12 +65,12 @@ namespace Microsoft.Bot.Builder.Dialogs
// Ensure next hasn't been called
if (_nextCalled)
{
throw new Exception($"WaterfallStepContext.NextAsync(): method already called for dialog and step '{_parent.Id}[{Index}]'.");
throw new Exception($"WaterfallStepContext.NextAsync(): method already called for dialog and step '{_parentWaterfall.Id}[{Index}]'.");
}
// Trigger next step
_nextCalled = true;
return await _parent.ResumeDialogAsync(this, DialogReason.NextCalled, result).ConfigureAwait(false);
return await _parentWaterfall.ResumeDialogAsync(this, DialogReason.NextCalled, result).ConfigureAwait(false);
}
}
}

Просмотреть файл

@ -59,7 +59,10 @@
<PackageReference Include="Microsoft.Bot.Builder" Condition=" '$(PackageVersion)' != '' " Version="$(PackageVersion)" />
<PackageReference Include="Microsoft.Net.Http.Headers" Version="2.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.1" />
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta008" PrivateAssets="all" />
</ItemGroup>

Просмотреть файл

@ -139,6 +139,7 @@ namespace Microsoft.Bot.Builder.AI.LanguageGeneration.Tests
}
[TestMethod]
[ExpectedException(typeof(Exception))]
public void TestBasicLoopRef()
{
var engine = TemplateEngine.FromFile(GetExampleFilePath("7.lg"));

Просмотреть файл

@ -274,7 +274,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Tests
if (results.Status == DialogTurnStatus.Empty)
{
await dc.PromptAsync("ChoicePrompt",
new PromptOptions
new ChoicePromptOptions
{
Prompt = new Activity { Type = ActivityTypes.Message, Text = "favorite color?" },
Choices = colorChoices

Просмотреть файл

@ -14,14 +14,6 @@ namespace Microsoft.Bot.Builder.Dialogs.Tests
[TestClass]
public class OAuthPromptTests
{
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void OAuthPromptWithEmptyIdShouldFail()
{
var emptyId = "";
var confirmPrompt = new OAuthPrompt(emptyId, new OAuthPromptSettings());
}
[TestMethod]
public async Task OAuthPrompt()
{

Просмотреть файл

@ -294,7 +294,7 @@ namespace Microsoft.Bot.Builder.TemplateManager.Tests
await context.SendActivityAsync(templateActivity);
})
.Send("welcome")
.AssertReplyOneOf(new string[] { "Hello", "Hi" })
.AssertReplyOneOf(new string[] { "Hello", "Hi", "Hi :)", "Hello :)" })
.StartTestAsync();
}

Просмотреть файл

@ -3,7 +3,6 @@
# wPhrase
- Hi
- Hello
-
> Using a template in another template
> Sometimes the bot will say 'Hi' and other times it will say 'Hi :)'

Просмотреть файл

@ -250,46 +250,46 @@ namespace Microsoft.Bot.Builder.Integration.AspNet.Core.Tests
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("botFactory");
}
[Fact]
public void WithoutConfigurationCallback()
{
var serviceCollectionMock = CreateServiceCollectionMock();
//[Fact]
//public void WithoutConfigurationCallback()
//{
// var serviceCollectionMock = CreateServiceCollectionMock();
var botFactory = new Func<IServiceProvider, ServiceRegistrationTestBot>(sp => new ServiceRegistrationTestBot());
// var botFactory = new Func<IServiceProvider, ServiceRegistrationTestBot>(sp => new ServiceRegistrationTestBot());
serviceCollectionMock.Object.AddBot(botFactory);
// serviceCollectionMock.Object.AddBot(botFactory);
VerifyExpectedBotServicesAreRegistered(serviceCollectionMock);
}
// VerifyExpectedBotServicesAreRegistered(serviceCollectionMock);
//}
[Fact]
public void WithExplicitNullConfigurationCallback()
{
var serviceCollectionMock = CreateServiceCollectionMock();
//[Fact]
//public void WithExplicitNullConfigurationCallback()
//{
// var serviceCollectionMock = CreateServiceCollectionMock();
var botFactory = new Func<IServiceProvider, ServiceRegistrationTestBot>(sp => new ServiceRegistrationTestBot());
// var botFactory = new Func<IServiceProvider, ServiceRegistrationTestBot>(sp => new ServiceRegistrationTestBot());
serviceCollectionMock.Object.AddBot(botFactory, (Action<BotFrameworkOptions>)null);
// serviceCollectionMock.Object.AddBot(botFactory, (Action<BotFrameworkOptions>)null);
VerifyExpectedBotServicesAreRegistered(serviceCollectionMock);
}
// VerifyExpectedBotServicesAreRegistered(serviceCollectionMock);
//}
[Fact]
public void WithConfigurationCallback()
{
var serviceCollectionMock = CreateServiceCollectionMock();
//[Fact]
//public void WithConfigurationCallback()
//{
// var serviceCollectionMock = CreateServiceCollectionMock();
var botFactory = new Func<IServiceProvider, ServiceRegistrationTestBot>(sp => new ServiceRegistrationTestBot());
// var botFactory = new Func<IServiceProvider, ServiceRegistrationTestBot>(sp => new ServiceRegistrationTestBot());
serviceCollectionMock.Object.AddBot(
botFactory,
options =>
{
options.Should().NotBeNull();
});
// serviceCollectionMock.Object.AddBot(
// botFactory,
// options =>
// {
// options.Should().NotBeNull();
// });
VerifyExpectedBotServicesAreRegistered(serviceCollectionMock);
}
// VerifyExpectedBotServicesAreRegistered(serviceCollectionMock);
//}
[Fact]
public void DoesntReplaceExistingAdapterIntegration()