示例#1
0
 private static void ThrowIfNotSuccess(INavigationResult r)
 {
     if (!r.Success)
     {
         throw r.Exception;
     }
 }
示例#2
0
        protected override async void OnInitialized()
        {
            InitializeComponent();

            LoggerService = Container.Resolve <ILoggerService>();
            LoggerService.StartMethod();
            LogFileService = Container.Resolve <ILogFileService>();
            LogFileService.AddSkipBackupAttribute();

            // Local Notification tap event listener
            //NotificationCenter.Current.NotificationTapped += OnNotificationTapped;
            LogUnobservedTaskExceptions();

            INavigationResult result = await NavigationService.NavigateAsync("/" + nameof(SplashPage));

            if (!result.Success)
            {
                LoggerService.Info($"Failed transition.");

                MainPage = new ExceptionPage
                {
                    BindingContext = new ExceptionPageViewModel()
                    {
                        Message = result.Exception.Message
                    }
                };
                System.Diagnostics.Debugger.Break();
            }

            LoggerService.EndMethod();
        }
        /**
         * Set the main page depending on if the user logged in before | not
         **/
        private async Task SetMainPageAsync()
        {
            // Resolve storage service
            _PreferencesService = Container.Resolve <IStorageService>();

            // Get if first time App launched
            var isFirstTimeLaunched = await _PreferencesService.GetAsync <bool>(AppSettings.IsFirstTimeAppLaunched, AppSettings.IsFirstTimeAppLaunchedDefaultValue);

            INavigationResult result = null;

            if (isFirstTimeLaunched)
            {
                await _PreferencesService.SaveAsync(AppSettings.IsFirstTimeAppLaunched, false);

                result = await NavigationService.NavigateAsync($"/{nameof(LoginPage)}");
            }
            else
            {
                result = await NavigationService.NavigateAsync($"{nameof(NavigationPage)}/{nameof(TabbedMainPage)}?{KnownNavigationParameters.SelectedTab}={nameof(HomePage)}");
            }

            if (!result.Success)
            {
                SetMainPageFromException(result.Exception);
            }
        }
示例#4
0
 private async Task ShowExceptionIfOccured(INavigationResult result)
 {
     if (!result.Success)
     {
         await _pageDialogService.DisplayAlertAsync("ClearPopupStackAsync", result.Exception.Message, "OK");
     }
 }
示例#5
0
        private async Task GoBackAsync()
        {
            INavigationResult navigationResult = await NavigationService.GoBackAsync();

            if (!navigationResult.Success)
            {
                System.Diagnostics.Debugger.Break();
            }
        }
        public virtual async Task NavigateAsync(string name, INavigationParameters parameters = null)
        {
            INavigationResult navigationResult = await PrismNavigationService.NavigateAsync(name, parameters, useModalNavigation : false, animated : false);

            if (!navigationResult.Success)
            {
                throw navigationResult.Exception;
            }
        }
示例#7
0
        protected override async Task <INavigationResult> GoBackInternal(INavigationParameters parameters, bool?useModalNavigation, bool animated)
        {
            INavigationResult result = null;

            try
            {
                NavigationSource = PageNavigationSource.NavigationService;

                switch (PopupUtilities.TopPage(_popupNavigation, _applicationProvider))
                {
                case PopupPage popupPage:
                    var segmentParameters = UriParsingHelper.GetSegmentParameters(null, parameters);
                    ((INavigationParametersInternal)segmentParameters).Add("__NavigationMode", NavigationMode.Back);
                    var previousPage = PopupUtilities.GetOnNavigatedToTarget(_popupNavigation, _applicationProvider);

                    PageUtilities.OnNavigatingTo(previousPage, segmentParameters);
                    await DoPop(popupPage.Navigation, false, animated);

                    if (popupPage != null)
                    {
                        PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(popupPage, a => a.IsActive = false);
                        PageUtilities.OnNavigatedFrom(popupPage, segmentParameters);
                        PageUtilities.OnNavigatedTo(previousPage, segmentParameters);
                        await InvokeOnNavigatedToAsync(previousPage, segmentParameters);

                        PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(previousPage, a => a.IsActive = true);
                        PageUtilities.DestroyPage(popupPage);
                        result = new NavigationResult {
                            Success = true
                        };
                        break;
                    }
                    throw new NullReferenceException("The PopupPage was null following the Pop");

                default:
                    result = await base.GoBackInternal(parameters, useModalNavigation, animated);

                    break;
                }
            }
            catch (Exception e)
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                _logger.Log(e.ToString(), Category.Exception, Priority.High);
                result = new NavigationResult {
                    Success = false, Exception = e
                };;
            }
            finally
            {
                NavigationSource = PageNavigationSource.Device;
            }
            return(result);
        }
示例#8
0
        private async Task OnNavigateTapped(string page)
        {
            switch (page)
            {
            case "Simple":
                INavigationResult result = await _navigationService.NavigateAsync("ViewA");

                if (!result.Success)
                {
                    Console.WriteLine($"Navigation failed {result.Exception.Message}");
                }
                break;

            case "Params":
                await _navigationService.NavigateAsync("ViewA", new NavigationParameters { { "name", "Hussain" } });

                break;

            case "ParamsBoth":
                await _navigationService.NavigateAsync("ViewA", new NavigationParameters("?title=Hussain A") { { "name", "Hussain" } });

                break;

            case "AutoInit":
                await _navigationService.NavigateAsync("ViewB?name=Hussain");

                break;

            case "Deep":
                await _navigationService.NavigateAsync("ViewA/ViewB/ViewC");

                break;

            case "DeepParams":
                await _navigationService.NavigateAsync("ViewA?name=HussainA/ViewB?name=HussainB/ViewC");

                break;

            case "Deeper":
                await _navigationService.NavigateAsync("ViewA/ViewB/ViewC?selectedTab=TabB");

                break;

            case "DeeperParams":
                // Any parameter passed to a TabbedPage will be propagated to all children pages (tabs).
                await _navigationService.NavigateAsync("ViewA?name=HussainA/ViewB?name=HussainB/ViewC?selectedTab=TabB&name=Hussain&message=folks");

                break;

            case "Remove":
                await _navigationService.NavigateAsync("../ViewA/ViewB/ViewC");

                break;
            }
        }
示例#9
0
 private static void HandleNavigationResult(INavigationResult navigationResult)
 {
     if (!navigationResult.Success)
     {
         Exception ex = new InvalidNavigationException();
         if (navigationResult.Exception != null)
         {
             ex = navigationResult.Exception;
         }
         SetMainPageFromException(ex);
     }
 }
示例#10
0
        protected override async void OnInitialized()
        {
            InitializeComponent();

            string destination = GetNavigationPath();

            INavigationResult result = await NavigationService.NavigateAsync(destination);

            if (!result.Success)
            {
                Debugger.Break();
            }
        }
示例#11
0
        /// <summary>
        /// 捕获异常
        /// </summary>
        /// <param name="navigationResult"></param>
        private static void HandleNavigationResult(INavigationResult navigationResult)
        {
            if (!navigationResult.Success)
            {
                Exception ex = new InvalidNavigationException();

                if (navigationResult.Exception != null)
                {
                    ex = navigationResult.Exception;
                }
                //An unknown error occurred. You may need to specify whether to Use Modal Navigation or not
                SetMainPageFromException(ex);
            }
        }
示例#12
0
        private async void OnNavigateCommandExecuted(string page)
        {
            // await CommonRoutines.NavigateMainPage(BaseNavigationService, path);

            if (page != CurrentPage)
            {
                CurrentPage = page;

                INavigationResult result = await BaseNavigationService.NavigateAsync(nameof(NavigationPage) + "/" + page.Trim()).ConfigureAwait(false);

                if (!result.Success)
                {
                    DataStore.CN.NotifyException("OnNavigateCommandExecuted", result.Exception);
                }
            }
        }
示例#13
0
        private async void OnNavigateParmsCommandExecuted(INavigationParameters obj)
        {
            obj.TryGetValue("Target", out string target);

            if (target != CurrentPage)
            {
                CurrentPage = target;

                string t = nameof(NavigationPage) + "/" + target.Trim();

                INavigationResult result = await BaseNavigationService.NavigateAsync(t, obj).ConfigureAwait(false);

                if (!result.Success)
                {
                    DataStore.CN.NotifyException("OnNavigateCommandExecuted", result.Exception);
                }
            }
        }
示例#14
0
        public virtual async Task NavigateAsync(string name, INavigationParameters?parameters = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (name.StartsWith("/", StringComparison.InvariantCultureIgnoreCase))
            {
                await ClearPopupStackAsync(parameters);
            }

            INavigationResult navigationResult = await PrismNavigationService.NavigateAsync(name, parameters, useModalNavigation : false, animated : false);

            if (!navigationResult.Success)
            {
                throw navigationResult.Exception;
            }
        }
示例#15
0
        protected override async void OnInitialized()
        {
            InitializeComponent();

            LoggerService = Container.Resolve <ILoggerService>();
            LoggerService.StartMethod();
            LogFileService = Container.Resolve <ILogFileService>();
            LogFileService.AddSkipBackupAttribute();

#if USE_MOCK
            // For debug mode, set the mock api provider to interact
            // with some fake data
            Xamarin.ExposureNotifications.ExposureNotification.OverrideNativeImplementation(new Services.TestNativeImplementation());
#endif
            Xamarin.ExposureNotifications.ExposureNotification.Init();

            // var enabled = await Xamarin.ExposureNotifications.ExposureNotification.IsEnabledAsync();
            // App.LoggerService.Info($"IsEnabledAsync is {enabled}");

            // Local Notification tap event listener
            //NotificationCenter.Current.NotificationTapped += OnNotificationTapped;
            LogUnobservedTaskExceptions();

            INavigationResult result = await NavigationService.NavigateAsync("/" + nameof(SplashPage));

            if (!result.Success)
            {
                LoggerService.Info($"Failed transition.");

                MainPage = new ExceptionPage
                {
                    BindingContext = new ExceptionPageViewModel()
                    {
                        Message = result.Exception.Message
                    }
                };
                System.Diagnostics.Debugger.Break();
            }

            LoggerService.EndMethod();
        }
示例#16
0
        private async void OnNavigateCommandExecuted(string page)
        {
            try
            {
                if (page != CurrentPage)
                {
                    CurrentPage = page;

                    INavigationResult result = await BaseNavigationService.NavigateAsync(nameof(NavigationPage) + "/" + page.Trim()).ConfigureAwait(false);

                    if (!result.Success)
                    {
                        DataStore.CN.NotifyException("OnNavigateCommandExecuted", result.Exception);
                    }
                }
            }
            catch (System.Exception ex)
            {
                DataStore.CN.NotifyException("OnNavigateCommandExecuted", ex);
                throw;
            }
        }
示例#17
0
 public HttpResult(INavigationResult navigationResult)
 {
     TimeSpentInMs = navigationResult.TimeSpent;
     Response = navigationResult.Response;
     Request = navigationResult.Request;
 }
 protected virtual void OnNavigationFailed(INavigationResult result)
 {
     NavigationFailedHandler?.Invoke(result);
 }