/// <summary> /// Handles an executing async service request by showing a loading overlay until it completes execution. /// </summary> /// <param name="loadingOverlay">A overlay to display over the screen during the async operation.</param> /// <param name="progress">An optional object to provide progress for the operation the overlay represents.</param> /// <param name="executingRequest">The task for an executing request.</param> /// <param name="onSuccess">Gets invoked if the request has completed successfully.</param> /// <param name="onFailed">Gets invoked if the request failed, by default a standard alert message will be shown.</param> protected async void OnAsyncServiceRequest <TResponse>( ILoadingOverlay loadingOverlay, IProgress progress, Task <ServiceResult <TResponse> > executingRequest, Action <TResponse> onSuccess, Action <ServiceResult> onFailed) { Throw.IfArgumentNull(loadingOverlay, nameof(loadingOverlay)); Throw.IfArgumentNull(executingRequest, nameof(executingRequest)); Throw.IfArgumentNull(onSuccess, nameof(onSuccess)); Throw.IfArgumentNull(onFailed, nameof(onFailed)); ServiceResult <TResponse> serviceResult; if (executingRequest.IsCompleted) { serviceResult = executingRequest.Result; } else { using (loadingOverlay.ShowLoadingOverlay(progress)) { serviceResult = await executingRequest; } } if (serviceResult.ResultCode == ServiceResultCode.Success) { onSuccess(serviceResult.Response); } else { onFailed(serviceResult); } }
/// <summary> /// Wraps the background loading task to show a loading overlay until it has completed. /// </summary> /// <param name="loadingOverlay">A loading over overlay to display.</param> /// <returns>A task representing the background loading.</returns> public async Task AwaitBackgroundLoading(ILoadingOverlay loadingOverlay) { using (loadingOverlay.ShowLoadingOverlay()) { await this.LoadingFromServiceTask; } }
/// <summary> /// Performs an async refresh of the table by pulling updated information from a service and reloading the data in the current table. /// </summary> /// <param name="loadingOverlay">An optional loading overlay to display while refreshing the table.</param> /// <returns>The refresh task.</returns> protected async Task RefreshTable(ILoadingOverlay loadingOverlay) { using (loadingOverlay.ShowLoadingOverlay()) { await this.tableSource.RefreshItemsAsync(this.ReloadTable); } }
/// <summary> /// Handles an executing async service request by showing a loading overlay until it completes execution. /// </summary> /// <param name="loadingOverlay">A overlay to display over the screen during the async operation.</param> /// <param name="executingRequest">The task for an executing request.</param> /// <param name="onSuccess">Gets invoked if the request has completed successfully.</param> /// <param name="onFailed">Gets invoked if the request failed, by default a standard alert message will be shown.</param> protected void OnAsyncServiceRequest <TResponse>( ILoadingOverlay loadingOverlay, Task <ServiceResult <TResponse> > executingRequest, Action <TResponse> onSuccess, Action <ServiceResult> onFailed) { this.OnAsyncServiceRequest(loadingOverlay, null, executingRequest, onSuccess, onFailed); }
/// <summary> /// Handles an executing async service request by showing a loading overlay until it completes execution. /// </summary> /// <param name="loadingOverlay">A overlay to display over the screen during the async operation.</param> /// <param name="progress">An optional object to provide progress for the operation the overlay represents.</param> /// <param name="executingRequest">The task for an executing request.</param> /// <param name="onSuccess">Gets invoked if the request has completed successfully.</param> protected void OnAsyncServiceRequest <TResponse>(ILoadingOverlay loadingOverlay, IProgress progress, Task <ServiceResult <TResponse> > executingRequest, Action <TResponse> onSuccess) { this.OnAsyncServiceRequest( loadingOverlay, progress, executingRequest, onSuccess, result => this.ShowLoadingFromServiceFailedAlert(result)); }
/// <summary> /// Handles an executing async service request by showing a loading overlay until it completes execution. /// </summary> /// <param name="loadingOverlay">A overlay to display over the screen during the async operation.</param> /// <param name="executingRequest">The task for an executing request.</param> /// <param name="onSuccess">Gets invoked if the request has completed successfully.</param> protected void OnAsyncServiceRequest(ILoadingOverlay loadingOverlay, LongRunningTask executingRequest, Action onSuccess) { this.OnAsyncServiceRequest( loadingOverlay, executingRequest.Progress, executingRequest.Task, onSuccess, result => this.ShowLoadingFromServiceFailedAlert(result)); }
/// <summary> /// Handles an executing async service request by showing a loading overlay until it completes execution. /// </summary> /// <param name="loadingOverlay">A overlay to display over the screen during the async operation.</param> /// <param name="progress">An optional object to provide progress for the operation the overlay represents.</param> /// <param name="executingRequest">The task for an executing request.</param> protected void OnAsyncServiceRequest(ILoadingOverlay loadingOverlay, IProgress progress, Task <ServiceResult> executingRequest) { this.OnAsyncServiceRequest( loadingOverlay, progress, executingRequest, () => { }, result => this.ShowLoadingFromServiceFailedAlert(result)); }
/// <summary> /// Handles an executing async service request by showing a loading overlay until it completes execution. /// </summary> /// <param name="loadingOverlay">A overlay to display over the screen during the async operation.</param> /// <param name="executingRequest">The task for an executing request.</param> /// <param name="onSuccess">Gets invoked if the request has completed successfully.</param> protected void OnAsyncServiceRequest(ILoadingOverlay loadingOverlay, Task <ServiceResult> executingRequest, Action onSuccess) { this.OnAsyncServiceRequest( loadingOverlay, null, executingRequest, onSuccess, result => this.ShowLoadingFromServiceFailedAlert(result)); }
/// <summary> /// Executes an asynchronous service request if it is valid and shows a waiting overlay until the operation has completed. /// </summary> /// <param name="loadingOverlay">A overlay to display over the screen during the async operation.</param> /// <param name="validateRequest">Validates the request prior to executing it.</param> /// <param name="executeRequest">Executes the asynchronous request.</param> /// <param name="onSuccess">Gets invoked if the request has completed successfully.</param> /// <param name="onFailed">Gets invoked if the request failed, by default a standard alert message will be shown.</param> protected void ExecuteServiceRequestAsync <TResponse>( ILoadingOverlay loadingOverlay, Func <ValidationResult> validateRequest, Func <Task <ServiceResult <TResponse> > > executeRequest, Action <TResponse> onSuccess, Action <ServiceResult> onFailed) { this.ExecuteServiceRequestAsync(loadingOverlay, null, validateRequest, executeRequest, onSuccess, onFailed); }
/// <summary> /// Executes an asynchronous service request if it is valid and shows a waiting overlay until the operation has completed. /// </summary> /// <param name="loadingOverlay">A overlay to display over the screen during the async operation.</param> /// <param name="validateRequest">Validates the request prior to executing it.</param> /// <param name="executeRequest">Executes the asynchronous request.</param> /// <param name="onSuccess">Gets invoked if the request has completed successfully.</param> protected void ExecuteServiceRequestAsync(ILoadingOverlay loadingOverlay, Func <ValidationResult> validateRequest, Func <Task <ServiceResult> > executeRequest, Action onSuccess) { this.ExecuteServiceRequestAsync( loadingOverlay, null, validateRequest, executeRequest, onSuccess, result => this.ShowLoadingFromServiceFailedAlert(result)); }
/// <summary> /// Handles an executing async service request by showing a loading overlay until it completes execution. /// </summary> /// <param name="loadingOverlay">A overlay to display over the screen during the async operation.</param> /// <param name="progress">An optional object to provide progress for the operation the overlay represents.</param> /// <param name="executingRequest">The task for an executing request.</param> /// <param name="onFailed">Gets invoked if the request failed, by default a standard alert message will be shown.</param> protected void OnAsyncServiceRequest( ILoadingOverlay loadingOverlay, IProgress progress, Task <ServiceResult> executingRequest, Action <ServiceResult> onFailed) { this.OnAsyncServiceRequest( loadingOverlay, progress, executingRequest, () => { }, onFailed); }
/// <summary> /// Executes an asynchronous service request if it is valid and shows a waiting overlay until the operation has completed. /// </summary> /// <param name="loadingOverlay">A overlay to display over the screen during the async operation.</param> /// <param name="progress">An optional object to provide progress for the operation the overlay represents.</param> /// <param name="validateRequest">Validates the request prior to executing it.</param> /// <param name="executeRequest">Executes the asynchronous request.</param> /// <param name="onSuccess">Gets invoked if the request has completed successfully.</param> protected void ExecuteServiceRequestAsync <TResponse>( ILoadingOverlay loadingOverlay, IProgress progress, Func <ValidationResult> validateRequest, Func <Task <ServiceResult <TResponse> > > executeRequest, Action <TResponse> onSuccess) { this.ExecuteServiceRequestAsync( loadingOverlay, progress, validateRequest, executeRequest, onSuccess, result => this.ShowLoadingFromServiceFailedAlert(result)); }
/// <summary> /// Executes an asynchronous service request if it is valid and shows a waiting overlay until the operation has completed. /// </summary> /// <param name="loadingOverlay">A overlay to display over the screen during the async operation.</param> /// <param name="progress">An optional object to provide progress for the operation the overlay represents.</param> /// <param name="validateRequest">Validates the request prior to executing it.</param> /// <param name="executeRequest">Executes the asynchronous request.</param> /// <param name="onSuccess">Gets invoked if the request has completed successfully.</param> /// <param name="onFailed">Gets invoked if the request failed, by default a standard alert message will be shown.</param> protected void ExecuteServiceRequestAsync <TResponse>( ILoadingOverlay loadingOverlay, IProgress progress, Func <ValidationResult> validateRequest, Func <Task <ServiceResult <TResponse> > > executeRequest, Action <TResponse> onSuccess, Action <ServiceResult> onFailed) { Throw.IfArgumentNull(validateRequest, nameof(validateRequest)); ValidationResult validationResult = validateRequest(); if (!validationResult.HasErrors) { this.OnAsyncServiceRequest(loadingOverlay, progress, executeRequest(), onSuccess, onFailed); } else { this.ApplicationHost.Alert.ShowAlert(validationResult.Messages.First()); } }
/// <summary> /// Handles an executing async service request by showing a loading overlay until it completes execution. /// </summary> /// <param name="loadingOverlay">A overlay to display over the screen during the async operation.</param> /// <param name="executingRequest">The task for an executing request.</param> protected void OnAsyncServiceRequest(ILoadingOverlay loadingOverlay, Task <ServiceResult> executingRequest) { this.OnAsyncServiceRequest(loadingOverlay, executingRequest, () => { }); }
/// <summary> /// Executes an asynchronous service request if it is valid and shows a waiting overlay until the operation has completed. /// </summary> /// <param name="loadingOverlay">A overlay to display over the screen during the async operation.</param> /// <param name="validateRequest">Validates the request prior to executing it.</param> /// <param name="executeRequest">Executes the asynchronous request.</param> /// <param name="onFailed">Gets invoked if the request failed, by default a standard alert message will be shown.</param> protected void ExecuteServiceRequestAsync(ILoadingOverlay loadingOverlay, Func <ValidationResult> validateRequest, Func <Task <ServiceResult> > executeRequest, Action <ServiceResult> onFailed) { this.ExecuteServiceRequestAsync(loadingOverlay, null, validateRequest, executeRequest, () => { }, onFailed); }