Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
 /// <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;
     }
 }
Exemplo n.º 3
0
 /// <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);
     }
 }