/// <summary> /// Show To Do tasks step. /// </summary> /// <param name="sc">current step context.</param> /// <param name="cancellationToken">cancellation token.</param> /// <returns>Task completion.</returns> public async Task <DialogTurnResult> ShowToDoTasks(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await this.accessors.ToDoSkillState.GetAsync(sc.Context); if (string.IsNullOrEmpty(state.OneNotePageId)) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoBotResponses.SettingUpOneNoteMessage)); } var topIntent = ((ToDo)state.LuisResult)?.TopIntent().intent; if (topIntent == ToDo.Intent.ShowToDo || topIntent == ToDo.Intent.None) { var service = await this.toDoService.Init(state.MsGraphToken, state.OneNotePageId); var todosAndPageIdTuple = await service.GetMyToDoList(); state.OneNotePageId = todosAndPageIdTuple.Item2; state.ToDoTaskAllActivities = todosAndPageIdTuple.Item1; } var allTasksCount = state.ToDoTaskAllActivities.Count; var currentTaskIndex = state.ShowToDoPageIndex * state.PageSize; state.ToDoTaskActivities = state.ToDoTaskAllActivities.GetRange(currentTaskIndex, Math.Min(state.PageSize, allTasksCount - currentTaskIndex)); if (state.ToDoTaskActivities.Count <= 0) { return(await sc.NextAsync()); } else { Attachment toDoListAttachment = null; if (topIntent == ToDo.Intent.ShowToDo || topIntent == ToDo.Intent.None) { toDoListAttachment = ToDoHelper.ToAdaptiveCardAttachmentForShowToDos( state.ToDoTaskActivities, state.ToDoTaskAllActivities.Count, ToDoBotResponses.ShowToDoTasks, ToDoBotResponses.ReadToDoTasks); } else if (topIntent == ToDo.Intent.Next) { toDoListAttachment = ToDoHelper.ToAdaptiveCardAttachmentForShowToDos( state.ToDoTaskActivities, state.ToDoTaskAllActivities.Count, ToDoBotResponses.ShowNextToDoTasks, null); } else if (topIntent == ToDo.Intent.Previous) { toDoListAttachment = ToDoHelper.ToAdaptiveCardAttachmentForShowToDos( state.ToDoTaskActivities, state.ToDoTaskAllActivities.Count, ToDoBotResponses.ShowPreviousToDoTasks, null); } var toDoListReply = sc.Context.Activity.CreateReply(); toDoListReply.Attachments.Add(toDoListAttachment); await sc.Context.SendActivityAsync(toDoListReply); if ((topIntent == ToDo.Intent.ShowToDo || topIntent == ToDo.Intent.None) && allTasksCount > (state.ShowToDoPageIndex + 1) * state.PageSize) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoBotResponses.ShowingMoreTasks)); } return(await sc.EndDialogAsync(true)); } } catch (Exception ex) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ex.Message)); await this.accessors.ToDoSkillState.SetAsync(sc.Context, new ToDoSkillState()); return(await sc.CancelAllDialogsAsync()); } }