コード例 #1
0
        /// <summary>
        /// Called when the dialog is started and pushed onto the dialog stack.
        /// </summary>
        /// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
        /// <param name="options">Optional, initial information to pass to the dialog.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects
        /// or threads to receive notice of cancellation.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (this.Disabled != null && this.Disabled.GetValue(dc.State) == true)
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            if (dc.Parent is ActionContext ac)
            {
                var planActions = Actions.Select(s => new ActionState()
                {
                    DialogStack = new List <DialogInstance>(),
                    DialogId    = s.Id,
                    Options     = options
                });

                var changes = new ActionChangeList()
                {
                    ChangeType = ChangeType.GetValue(dc.State),
                    Actions    = planActions.ToList()
                };

                ac.QueueChanges(changes);

                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }
            else
            {
                throw new Exception("`EditActions` should only be used in the context of an adaptive dialog.");
            }
        }
コード例 #2
0
        protected virtual ActionChangeList OnCreateChangeList(SequenceContext planning, object dialogOptions = null)
        {
            var changeList = new ActionChangeList()
            {
                Actions = new List <ActionState>()
            };

            Actions.ForEach(s =>
            {
                var stepState = new ActionState()
                {
                    DialogStack = new List <DialogInstance>(),
                    DialogId    = s.Id
                };

                if (dialogOptions != null)
                {
                    stepState.Options = dialogOptions;
                }

                changeList.Actions.Add(stepState);
            });

            return(changeList);
        }
コード例 #3
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (dc is SequenceContext sc)
            {
                var planActions = Actions.Select(s => new ActionState()
                {
                    DialogStack = new List <DialogInstance>(),
                    DialogId    = s.Id,
                    Options     = options
                });

                var changes = new ActionChangeList()
                {
                    ChangeType = ChangeType,
                    Actions    = planActions.ToList()
                };

                sc.QueueChanges(changes);

                return(await sc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }
            else
            {
                throw new Exception("`EditAction` should only be used in the context of an adaptive dialog.");
            }
        }
コード例 #4
0
        /// <summary>
        /// Called when a change list is created.
        /// </summary>
        /// <param name="actionContext">Context to use for evaluation.</param>
        /// <param name="dialogOptions">Optional, object with dialog options.</param>
        /// <returns>An <see cref="ActionChangeList"/> with the list of actions.</returns>
        protected virtual ActionChangeList OnCreateChangeList(ActionContext actionContext, object dialogOptions = null)
        {
            var changeList = new ActionChangeList()
            {
                Actions = new List <ActionState>()
                {
                    new ActionState()
                    {
                        DialogId = this.ActionScope.Id,
                        Options  = dialogOptions
                    }
                },
            };

            return(changeList);
        }
コード例 #5
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            // Ensure planning context
            if (dc is SequenceContext sc)
            {
                Expression itemsProperty = new ExpressionEngine().Parse(this.ItemsProperty);
                int        offset        = 0;
                int        pageSize      = 0;
                if (options != null && options is ForeachPageOptions)
                {
                    var opt = options as ForeachPageOptions;
                    itemsProperty = opt.Items;
                    offset        = opt.Offset;
                    pageSize      = opt.PageSize;
                }

                if (pageSize == 0)
                {
                    pageSize = this.PageSize;
                }

                var(items, error) = itemsProperty.TryEvaluate(dc.GetState());
                if (error == null)
                {
                    var page = this.GetPage(items, offset, pageSize);

                    if (page.Count() > 0)
                    {
                        dc.GetState().SetValue(ForEachPage, page);
                        var changes = new ActionChangeList()
                        {
                            ChangeType = ActionChangeType.InsertActions,
                            Actions    = new List <ActionState>()
                        };
                        this.Actions.ForEach(step => changes.Actions.Add(new ActionState(step.Id)));

                        changes.Actions.Add(new ActionState()
                        {
                            DialogStack = new List <DialogInstance>(),
                            DialogId    = this.Id,
                            Options     = new ForeachPageOptions()
                            {
                                Items    = itemsProperty,
                                Offset   = offset + pageSize,
                                PageSize = pageSize
                            }
                        });
                        sc.QueueChanges(changes);
                    }
                }

                return(await sc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }
            else
            {
                throw new Exception("`Foreach` should only be used in the context of an adaptive dialog.");
            }
        }
コード例 #6
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            // Ensure planning context
            if (dc is SequenceContext sc)
            {
                Expression itemsProperty = null;
                int        offset        = 0;
                if (options != null && options is ForeachOptions)
                {
                    var opt = options as ForeachOptions;
                    if (!string.IsNullOrEmpty(opt.List))
                    {
                        itemsProperty = new ExpressionEngine().Parse(opt.List);
                    }

                    offset = opt.Offset;
                }

                itemsProperty        = new ExpressionEngine().Parse(this.ItemsProperty);
                var(itemList, error) = itemsProperty.TryEvaluate(dc.State);

                if (error == null)
                {
                    var item = this.GetItem(itemList, offset);
                    if (item != null)
                    {
                        dc.State.SetValue(VALUE, item);
                        dc.State.SetValue(INDEX, offset);
                        var changes = new ActionChangeList()
                        {
                            ChangeType = ActionChangeType.InsertActions,
                            Actions    = new List <ActionState>()
                        };
                        this.Actions.ForEach(step => changes.Actions.Add(new ActionState(step.Id)));

                        changes.Actions.Add(new ActionState()
                        {
                            DialogStack = new List <DialogInstance>(),
                            DialogId    = this.Id,
                            Options     = new ForeachOptions()
                            {
                                List   = ItemsProperty,
                                Offset = offset + 1
                            }
                        });
                        sc.QueueChanges(changes);
                    }
                }

                return(await sc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }
            else
            {
                throw new Exception("`Foreach` should only be used in the context of an adaptive dialog.");
            }
        }