diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs | 173 |
1 files changed, 95 insertions, 78 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs index 2a825cc19..3502648d4 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs @@ -12,6 +12,7 @@ using Tango.Core.Commands; using Tango.PPC.Common; using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; +using Tango.PPC.Common.Notifications; using Tango.PPC.Common.Threading; using Tango.PPC.UI.Views; using Tango.SharedUI.Controls; @@ -36,6 +37,7 @@ namespace Tango.PPC.UI.Navigation private List<AwaitingVMResult> _awaitingVMResults; private IDispatcherProvider _dispatcherProvider; private IPPCModuleLoader _moduleLoader; + private INotificationProvider _notificationProvider; private Object _currentVM; private String _lastFullPath; private bool _preventHistory; @@ -75,12 +77,13 @@ namespace Tango.PPC.UI.Navigation /// Initializes a new instance of the <see cref="DefaultNavigationManager"/> class. /// </summary> /// <param name="moduleLoader">The module loader.</param> - public DefaultNavigationManager(IPPCModuleLoader moduleLoader, IDispatcherProvider dispatcherProvider) + public DefaultNavigationManager(IPPCModuleLoader moduleLoader, IDispatcherProvider dispatcherProvider, INotificationProvider notificationProvider) { IsBackEnabled = true; _awaitingVMResults = new List<AwaitingVMResult>(); _navigationHistory = new Stack<String>(); _moduleLoader = moduleLoader; + _notificationProvider = notificationProvider; NavigateToCommand = new RelayCommand<string>(async (x) => await NavigateTo(x)); NavigateBackCommand = new RelayCommand(async () => await NavigateBack()); @@ -197,105 +200,127 @@ namespace Tango.PPC.UI.Navigation /// <param name="fullPath">The full path.</param> public async Task<bool> NavigateTo(String fullPath, bool pushToHistory = true, Action<PPCViewModel, PPCViewModel> onNavigating = null, Action<PPCViewModel, PPCViewModel> onNavigated = null) { - String[] path = fullPath.Split('.'); - var module = _moduleLoader.UserModules.SingleOrDefault(x => x.GetType().Name == path[0] || x.Name == path[0]); + try + { + String[] path = fullPath.Split('.'); + var module = _moduleLoader.UserModules.SingleOrDefault(x => x.GetType().Name == path[0] || x.Name == path[0]); + + if (module == null) + { + await _notificationProvider.ShowError("The specified module was not loaded."); + return false; + } - if (path.Length == 1 && path[0] == CurrentModule.Name) return true; + if (path.Length == 1 && path[0] == CurrentModule.Name) return true; - LogManager.Log($"Navigating to: {fullPath}..."); + LogManager.Log($"Navigating to: {fullPath}..."); - var fromVM = _currentVM; + var fromVM = _currentVM; - if (_currentVM != null && _currentVM is INavigationBlocker) - { - if (_navigating_back) + if (_currentVM != null && _currentVM is INavigationBlocker) { - if (!await (_currentVM as INavigationBlocker).OnNavigateBackRequest()) + if (_navigating_back) { - return false; + if (!await (_currentVM as INavigationBlocker).OnNavigateBackRequest()) + { + return false; + } } - } - else - { - if (!await (_currentVM as INavigationBlocker).OnNavigateOutRequest()) + else { - return false; + if (!await (_currentVM as INavigationBlocker).OnNavigateOutRequest()) + { + return false; + } } } - } - if (pushToHistory && _lastFullPath != null && !_preventHistory) - { - _navigationHistory.Push(_lastFullPath); - RaisePropertyChanged(nameof(CanNavigateBack)); - } - - _lastFullPath = fullPath; + if (pushToHistory && _lastFullPath != null && !_preventHistory) + { + _navigationHistory.Push(_lastFullPath); + RaisePropertyChanged(nameof(CanNavigateBack)); + } - MainView.Instance.NavigationControl.NavigateTo(NavigationView.LayoutView.ToString()); - var navigationControl = LayoutView.Instance.NavigationControl; - CurrentModule = module; - var moduleView = navigationControl.NavigateTo(module.Name); + _lastFullPath = fullPath; - _currentVM = moduleView.DataContext; + MainView.Instance.NavigationControl.NavigateTo(NavigationView.LayoutView.ToString()); + var navigationControl = LayoutView.Instance.NavigationControl; + CurrentModule = module; + var moduleView = navigationControl.NavigateTo(module.Name); - if (path.Length > 1) - { - var moduleNavigation = moduleView.FindChildOffline<NavigationControl>(); + _currentVM = moduleView.DataContext; - if (moduleNavigation != null) + if (path.Length > 1) { - moduleNavigation.RegisterForLoadedOrNow(async (x, e) => - { - var lastView = moduleNavigation.GetElement(path.Last()); - - if (lastView != null) - { - onNavigating?.Invoke(fromVM as PPCViewModel, lastView.DataContext as PPCViewModel); - } + var moduleNavigation = moduleView.FindChildOffline<NavigationControl>(); - foreach (var view in path.Skip(1)) + if (moduleNavigation != null) + { + moduleNavigation.RegisterForLoadedOrNow(async (x, e) => { - await Task.Delay(100); + var lastView = moduleNavigation.GetElement(path.Last()); - FrameworkElement v = null; + if (lastView != null) + { + onNavigating?.Invoke(fromVM as PPCViewModel, lastView.DataContext as PPCViewModel); + } - v = moduleNavigation.NavigateTo(view, () => + foreach (var view in path.Skip(1)) { - if (v != null) + await Task.Delay(100); + + FrameworkElement v = null; + + v = moduleNavigation.NavigateTo(view, () => { - NotifyOnNavigated(fromVM, v.DataContext); - onNavigated?.Invoke(fromVM as PPCViewModel, v.DataContext as PPCViewModel); - NotifyAwaitingVMResults(fromVM as PPCViewModel, v.DataContext as PPCViewModel); - } - }); + if (v != null) + { + NotifyOnNavigated(fromVM, v.DataContext); + onNavigated?.Invoke(fromVM as PPCViewModel, v.DataContext as PPCViewModel); + NotifyAwaitingVMResults(fromVM as PPCViewModel, v.DataContext as PPCViewModel); + } + }); - NotifyOnBeforeNavigated(fromVM, v.DataContext); + NotifyOnBeforeNavigated(fromVM, v.DataContext); - if (v != null) - { - _currentVM = v.DataContext; + if (v != null) + { + _currentVM = v.DataContext; - if (view != path.Last()) + if (view != path.Last()) + { + moduleNavigation = v.FindChildOffline<NavigationControl>(); + } + } + else { - moduleNavigation = v.FindChildOffline<NavigationControl>(); + throw LogManager.Log(new ArgumentNullException("Could not navigate to " + fullPath)); } } - else - { - throw LogManager.Log(new ArgumentNullException("Could not navigate to " + fullPath)); - } - } - }); + }); + } + else + { + onNavigating?.Invoke(fromVM as PPCViewModel, _currentVM as PPCViewModel); + + NotifyOnBeforeNavigated(fromVM, _currentVM); + + await Task.Delay(navigationControl.TransitionDuration.TimeSpan); + + NotifyOnNavigated(fromVM, _currentVM); + + onNavigated?.Invoke(fromVM as PPCViewModel, _currentVM as PPCViewModel); + NotifyAwaitingVMResults(fromVM as PPCViewModel, _currentVM as PPCViewModel); + } } else { - onNavigating?.Invoke(fromVM as PPCViewModel, _currentVM as PPCViewModel); - NotifyOnBeforeNavigated(fromVM, _currentVM); + onNavigating?.Invoke(fromVM as PPCViewModel, _currentVM as PPCViewModel); + await Task.Delay(navigationControl.TransitionDuration.TimeSpan); NotifyOnNavigated(fromVM, _currentVM); @@ -303,22 +328,14 @@ namespace Tango.PPC.UI.Navigation onNavigated?.Invoke(fromVM as PPCViewModel, _currentVM as PPCViewModel); NotifyAwaitingVMResults(fromVM as PPCViewModel, _currentVM as PPCViewModel); } + + return true; } - else + catch (Exception ex) { - NotifyOnBeforeNavigated(fromVM, _currentVM); - - onNavigating?.Invoke(fromVM as PPCViewModel, _currentVM as PPCViewModel); - - await Task.Delay(navigationControl.TransitionDuration.TimeSpan); - - NotifyOnNavigated(fromVM, _currentVM); - - onNavigated?.Invoke(fromVM as PPCViewModel, _currentVM as PPCViewModel); - NotifyAwaitingVMResults(fromVM as PPCViewModel, _currentVM as PPCViewModel); + await _notificationProvider.ShowError($"Error navigating to '{fullPath}'."); + return false; } - - return true; } /// <summary> |
