/// <summary>
        /// Runs the task.
        /// </summary>
        /// <returns>The task.</returns>
        /// <param name="task">Task.</param>
        /// <param name="handleException">If set to <c>true</c> handle exception. Otherwise, throw the exeption to be handled by calling ViewModel.</param>
        /// <param name="actionOnException">If handleException is <c>false</c>, then invoke this method to handle exception.</param>
        /// <param name="messageOnException">Message on display when exception occurs.</param>
        /// <param name="lockNavigation">Lock the navigation and keep the user on the current view.</param>
        /// <param name="ignoreIsBusy">tells the Task Runner that it should not modify the state of Is Busy</param>
        /// <param name="caller">Calling method.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        protected async Task RunTask(Task task, bool handleException = true, Action <Exception, string> actionOnException = null, string messageOnException = null, bool?lockNavigation = null,
                                     bool ignoreIsBusy = false, [CallerMemberName] string caller = null)
        {
            UpdateIsBusy(!ignoreIsBusy || IsBusy, lockNavigation);

            await task.ContinueWith((thisTask) => {
                UpdateIsBusy(ignoreIsBusy && IsBusy);

                if (thisTask.IsFaulted && thisTask.Exception != null)
                {
                    Exception exception = null;
                    if (thisTask.Exception.InnerException != null)
                    {
                        exception = thisTask.Exception.InnerException;
                        while (exception.InnerException != null)
                        {
                            exception = exception.InnerException;
                        }
                    }
                    else
                    {
                        exception = thisTask.Exception;
                    }

                    if (exception is OfflineException)
                    {
                        DeviceService.BeginInvokeOnMainThread(() =>
                        {
                            //NavigationService.NavigateAsync(nameof(ServiceInfoPage), new NavigationParameters { { AppConstants.MaintenanceMessageKey, (exception.InnerException ?? exception).Message } }, true, false);
                            UserDialogs.Toast(Strings.Resources.OfflineMessage);
                        });
                    }
                    else if (!handleException)
                    {
                        if (actionOnException == null)
                        {
                            throw exception;
                        }

                        DeviceService.BeginInvokeOnMainThread(() => actionOnException.Invoke(exception, messageOnException));
                    }
                }
            });
        }
Exemple #2
0
        protected async Task NavigateToUri(string uri)
        {
            if (string.IsNullOrWhiteSpace(uri))
            {
                throw new ArgumentException("Value cannot be null or white space.", nameof(uri));
            }

            try
            {
                DeviceService.BeginInvokeOnMainThread(async() =>
                {
                    PlaySoundService.PlaySound(AppSoundsEnum.DigitalButton);
                    await NavigationService.NavigateAsync(uri, useModalNavigation: false);
                });
            }
            catch (Exception ex)
            {
                await HandleException(ex);
            }
        }
Exemple #3
0
 protected void SetIsBusy()
 {
     DeviceService.BeginInvokeOnMainThread(() => IsBusy = true);
 }
Exemple #4
0
 protected void ClearIsBusy()
 {
     DeviceService.BeginInvokeOnMainThread(() => IsBusy = false);
 }