Exemple #1
0
        /// <summary>
        /// Determine if clear the context.
        /// </summary>
        /// <param name="sc">current step context.</param>
        /// <param name="cancellationToken">cancellation token.</param>
        /// <returns>Task completion.</returns>
        public async Task <DialogTurnResult> ClearContext(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            var state = await this.accessors.ToDoSkillState.GetAsync(sc.Context);

            var topIntent = ((ToDo)state.LuisResult)?.TopIntent().intent;

            if (topIntent == ToDo.Intent.ShowToDo)
            {
                state.ShowToDoPageIndex     = 0;
                state.ToDoTaskActivities    = new List <ToDoTaskActivityModel>();
                state.ToDoTaskAllActivities = new List <ToDoTaskActivityModel>();
            }
            else if (topIntent == ToDo.Intent.Next)
            {
                if ((state.ShowToDoPageIndex + 1) * state.PageSize < state.ToDoTaskAllActivities.Count)
                {
                    state.ShowToDoPageIndex++;
                }
            }
            else if (topIntent == ToDo.Intent.Previous && state.ShowToDoPageIndex > 0)
            {
                state.ShowToDoPageIndex--;
            }
            else if (topIntent == ToDo.Intent.AddToDo)
            {
                state.ToDoTaskContent = null;
                await ToDoHelper.DigestLuisResultAsync(sc.Context, this.accessors);
            }
            else if (topIntent == ToDo.Intent.MarkToDo || topIntent == ToDo.Intent.DeleteToDo)
            {
                state.ToDoTaskIndexes          = new List <int>();
                state.MarkOrDeleteAllTasksFlag = false;
                state.ToDoTaskContent          = null;
                await ToDoHelper.DigestLuisResultAsync(sc.Context, this.accessors);
            }

            return(await sc.NextAsync());
        }