/// <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 (options is CancellationToken) { throw new ArgumentException($"{nameof(options)} cannot be a cancellation token"); } if (Disabled != null && Disabled.GetValue(dc.State)) { return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false)); } dc.State.SetValue(PageIndex.GetValue(dc.State), 0); return(await NextPageAsync(dc, cancellationToken).ConfigureAwait(false)); }
private async Task <DialogTurnResult> NextPageAsync(DialogContext dc, CancellationToken cancellationToken) { int pageIndex = dc.State.GetIntValue(PageIndex.GetValue(dc.State), 0); int pageSize = this.PageSize.GetValue(dc.State); int itemOffset = pageSize * pageIndex; var itemsProperty = this.ItemsProperty.GetValue(dc.State); if (dc.State.TryGetValue <object>(itemsProperty, out object items)) { var page = this.GetPage(items, itemOffset, pageSize); if (page.Any()) { dc.State.SetValue(Page.GetValue(dc.State), page); dc.State.SetValue(PageIndex.GetValue(dc.State), ++pageIndex); return(await this.BeginActionAsync(dc, 0, cancellationToken).ConfigureAwait(false)); } } // End of list has been reached return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false)); }