public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default) { if (options is CancellationToken) { throw new ArgumentException($"{nameof(options)} should not ever be a cancellation token"); } EnsureDependenciesInstalled(); SetLocalGenerator(dc.Context); // replace initial activeDialog.State with clone of options if (options != null) { dc.ActiveDialog.State = JsonConvert.DeserializeObject <Dictionary <string, object> >(JsonConvert.SerializeObject(options)); } var activeDialogState = dc.ActiveDialog.State as Dictionary <string, object>; activeDialogState[AdaptiveKey] = new AdaptiveDialogState(); var state = activeDialogState[AdaptiveKey] as AdaptiveDialogState; // Evaluate events and queue up step changes var dialogEvent = new DialogEvent { Name = AdaptiveEvents.BeginDialog, Value = options, Bubble = false }; await OnDialogEventAsync(dc, dialogEvent, cancellationToken).ConfigureAwait(false); // Continue step execution return(await ContinueActionsAsync(dc, options, cancellationToken : cancellationToken).ConfigureAwait(false)); }
public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default) { if (options is CancellationToken) { throw new ArgumentException($"{nameof(options)} should not ever be a cancellation token"); } EnsureDependenciesInstalled(); var activeDialogState = dc.ActiveDialog.State as Dictionary <string, object>; activeDialogState[AdaptiveKey] = new AdaptiveDialogState(); var state = activeDialogState[AdaptiveKey] as AdaptiveDialogState; // Persist options to dialog state dc.State.SetValue(ThisPath.OPTIONS, options); // Evaluate events and queue up step changes var dialogEvent = new DialogEvent { Name = AdaptiveEvents.BeginDialog, Value = options, Bubble = false }; await OnDialogEventAsync(dc, dialogEvent, cancellationToken).ConfigureAwait(false); // Continue step execution return(await ContinueActionsAsync(dc, options, cancellationToken : cancellationToken).ConfigureAwait(false)); }
public override DialogContext CreateChildContext(DialogContext dc) { var activeDialogState = dc.ActiveDialog.State as Dictionary <string, object>; var state = activeDialogState[AdaptiveKey] as AdaptiveDialogState; if (state == null) { state = new AdaptiveDialogState(); activeDialogState[AdaptiveKey] = state; } if (state.Actions != null && state.Actions.Any()) { var ctx = new SequenceContext(this.Dialogs, dc, state.Actions.First(), state.Actions, changeTurnKey, this.Dialogs); ctx.Parent = dc; return(ctx); } return(null); }
private SequenceContext ToSequenceContext(DialogContext dc) { var activeDialogState = dc.ActiveDialog.State as Dictionary <string, object>; var state = activeDialogState[AdaptiveKey] as AdaptiveDialogState; if (state == null) { state = new AdaptiveDialogState(); activeDialogState[AdaptiveKey] = state; } if (state.Actions == null) { state.Actions = new List <ActionState>(); } var sequenceContext = new SequenceContext(dc.Dialogs, dc, new DialogState { DialogStack = dc.Stack }, state.Actions, changeTurnKey, this.Dialogs); sequenceContext.Parent = dc.Parent; return(sequenceContext); }