public void IsDialogActive_Variations() { var config = new DialogStateManagerConfiguration() { MemoryScopes = new List <MemoryScope>() { new MockMemoryScope("dialogContext", new { stack = new[] { "a", "d", "F" } }) } }; var dc = new DialogContext(new DialogSet(), new TurnContext(new TestAdapter(), new Schema.Activity()), new DialogState()); DialogStateManager dsm = new DialogStateManager(dc, config); Assert.AreEqual(true, Expression.Parse("isDialogActive('a')").TryEvaluate(dsm).value); Assert.AreEqual(true, Expression.Parse("isDialogActive('b','c','d')").TryEvaluate(dsm).value); Assert.AreEqual(false, Expression.Parse("isDialogActive('b','c','e')").TryEvaluate(dsm).value); Assert.AreEqual(false, Expression.Parse("isDialogActive('c')").TryEvaluate(dsm).value); Assert.AreEqual(false, Expression.Parse("isDialogActive('f')").TryEvaluate(dsm).value); Assert.AreEqual(true, Expression.Parse("isDialogActive('F')").TryEvaluate(dsm).value); }
public static void SetStateConfiguration(this DialogContext dc, DialogStateManagerConfiguration configuration) { dc.Context.TurnState.Set(configuration ?? throw new ArgumentNullException(nameof(configuration))); }
internal static async Task <DialogTurnResult> InternalRunAsync(ITurnContext turnContext, string dialogId, DialogContext dialogContext, DialogStateManagerConfiguration stateConfiguration, CancellationToken cancellationToken) { // map TurnState into root dialog context.services foreach (var service in turnContext.TurnState) { dialogContext.Services[service.Key] = service.Value; } var dialogStateManager = new DialogStateManager(dialogContext, stateConfiguration); await dialogStateManager.LoadAllScopesAsync(cancellationToken).ConfigureAwait(false); dialogContext.Context.TurnState.Add(dialogStateManager); DialogTurnResult dialogTurnResult = null; // Loop as long as we are getting valid OnError handled we should continue executing the actions for the turn. // // NOTE: We loop around this block because each pass through we either complete the turn and break out of the loop // or we have had an exception AND there was an OnError action which captured the error. We need to continue the // turn based on the actions the OnError handler introduced. var endOfTurn = false; while (!endOfTurn) { try { dialogTurnResult = await InnerRunAsync(turnContext, dialogId, dialogContext, cancellationToken).ConfigureAwait(false); // turn successfully completed, break the loop endOfTurn = true; } catch (Exception err) { // fire error event, bubbling from the leaf. var handled = await dialogContext.EmitEventAsync(DialogEvents.Error, err, bubble : true, fromLeaf : true, cancellationToken : cancellationToken).ConfigureAwait(false); if (!handled) { // error was NOT handled, throw the exception and end the turn. (This will trigger the Adapter.OnError handler and end the entire dialog stack) throw; } } } // save all state scopes to their respective botState locations. await dialogStateManager.SaveAllChangesAsync(cancellationToken).ConfigureAwait(false); // return the redundant result because the DialogManager contract expects it return(dialogTurnResult); }