diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-07-15 01:04:34 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-07-15 01:04:34 +0300 |
| commit | cc425e019d3a7d3494ac15ffe213b6b47b1c64ed (patch) | |
| tree | 6db5ec969f92f91c2d05af55216bc4a267cc2370 /Software/Visual_Studio/PPC/Tango.PPC.UI | |
| parent | 64bcf92608faae31b7cd31ac3da5c7d1d7ebcd0b (diff) | |
| download | Tango-cc425e019d3a7d3494ac15ffe213b6b47b1c64ed.tar.gz Tango-cc425e019d3a7d3494ac15ffe213b6b47b1c64ed.zip | |
Working on PPC.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI')
6 files changed, 101 insertions, 18 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 0ede1306f..47450a68e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs @@ -11,6 +11,7 @@ using Tango.Core.Commands; using Tango.PPC.Common; using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; +using Tango.PPC.Common.Threading; using Tango.PPC.UI.Views; using Tango.SharedUI.Controls; @@ -24,6 +25,7 @@ namespace Tango.PPC.UI.Navigation { private event Action<Object, Object> NavigationCycleCompleted; + private IDispatcherProvider _dispatcherProvider; private IPPCModuleLoader _moduleLoader; private Object _currentVM; private String _lastFullPath; @@ -56,13 +58,15 @@ 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) + public DefaultNavigationManager(IPPCModuleLoader moduleLoader, IDispatcherProvider dispatcherProvider) { _navigationHistory = new Stack<String>(); _moduleLoader = moduleLoader; NavigateToCommand = new RelayCommand<string>(async (x) => await NavigateTo(x)); NavigateBackCommand = new RelayCommand(async () => await NavigateBack()); + + _dispatcherProvider = dispatcherProvider; } /// <summary> @@ -204,18 +208,16 @@ namespace Tango.PPC.UI.Navigation return true; } - private Task<bool> NavigateTo(Type moduleType, bool pushToHistory = true, params String[] viewPath) - { - if (viewPath != null && viewPath.Length > 0) - { - return NavigateTo(moduleType.Name + "." + String.Join(".", viewPath), pushToHistory); - } - else - { - return NavigateTo(moduleType.Name, pushToHistory); - } - } - + /// <summary> + /// Navigates for result. + /// </summary> + /// <typeparam name="TModule">The type of the module.</typeparam> + /// <typeparam name="TView">The type of the view.</typeparam> + /// <typeparam name="TResult">The type of the result.</typeparam> + /// <typeparam name="TObject">The type of the object.</typeparam> + /// <param name="obj">The object.</param> + /// <param name="pushToHistory">if set to <c>true</c> [push to history].</param> + /// <returns></returns> public Task<TResult> NavigateForResult<TModule, TView, TResult, TObject>(TObject obj, bool pushToHistory = true) where TModule : IPPCModule { @@ -259,6 +261,50 @@ namespace Tango.PPC.UI.Navigation } /// <summary> + /// Navigates to the specified module and view with the specified object. + /// </summary> + /// <typeparam name="TModule">The type of the module.</typeparam> + /// <typeparam name="TView">The type of the view.</typeparam> + /// <typeparam name="TPass">The type of the pass.</typeparam> + /// <param name="obj">The object.</param> + /// <param name="pushToHistory">if set to <c>true</c> [push to history].</param> + /// <returns></returns> + public Task<bool> NavigateWithObject<TModule, TView, TPass>(TPass obj, bool pushToHistory = true) where TModule : IPPCModule + { + TaskCompletionSource<bool> source = new TaskCompletionSource<bool>(); + + Action<Object, Object> handler = null; + + handler = (from, to) => + { + if (to is INavigationObjectReceiver<TPass>) + { + (to as INavigationObjectReceiver<TPass>).OnNavigatedToWithObject(obj); + } + + NavigationCycleCompleted -= handler; + }; + + NavigationCycleCompleted += handler; + + NavigateTo<TModule>(typeof(TView).Name, pushToHistory); + + return source.Task; + } + + private Task<bool> NavigateTo(Type moduleType, bool pushToHistory = true, params String[] viewPath) + { + if (viewPath != null && viewPath.Length > 0) + { + return NavigateTo(moduleType.Name + "." + String.Join(".", viewPath), pushToHistory); + } + else + { + return NavigateTo(moduleType.Name, pushToHistory); + } + } + + /// <summary> /// Gets a value indicating whether the navigation system is able to navigate to the previous view. /// </summary> public bool CanNavigateBack diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs index 0ff9982ee..ba869957d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs @@ -45,6 +45,8 @@ namespace Tango.PPC.UI.Notifications _pendingDialogs = new ConcurrentQueue<PendingNotification<DialogAndView, DialogViewVM>>(); PopNotificationCommand = new RelayCommand<NotificationItem>((x) => PopNotification(x)); + + NotificationItems.EnableCrossThreadOperations(); } private MessageBoxVM _currentMessageBox; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index dc3745bef..a8c80c3f7 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -123,6 +123,7 @@ <Compile Include="Notifications\DialogAndView.cs" /> <Compile Include="Notifications\PendingNotification.cs" /> <Compile Include="PPCApplication\DefaultPPCApplicationManager.cs" /> + <Compile Include="Threading\DefaultDispetcherProvider.cs" /> <Compile Include="ViewModelLocator.cs" /> <Compile Include="ViewModels\LayoutViewVM.cs" /> <Compile Include="ViewModels\LoadingViewVM.cs" /> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispetcherProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispetcherProvider.cs new file mode 100644 index 000000000..c33233573 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispetcherProvider.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Threading; +using Tango.PPC.Common.Threading; + +namespace Tango.PPC.UI.Threading +{ + public class DefaultDispetcherProvider : IDispatcherProvider + { + private Dispatcher _dispatcher; + + public DefaultDispetcherProvider(Dispatcher dispacther) + { + _dispatcher = dispacther; + } + + public void Invoke(Action action) + { + _dispatcher.BeginInvoke(action); + } + + public void InvokeSync(Action action) + { + _dispatcher.Invoke(action); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index e36fd4c51..d396920ab 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -11,11 +11,13 @@ using Tango.PPC.Common.EventLogging; using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.Notifications; +using Tango.PPC.Common.Threading; using Tango.PPC.UI.Authentication; using Tango.PPC.UI.Modules; using Tango.PPC.UI.Navigation; using Tango.PPC.UI.Notifications; using Tango.PPC.UI.PPCApplication; +using Tango.PPC.UI.Threading; using Tango.PPC.UI.ViewModels; using Tango.PPC.UI.Views; using Tango.PPC.UI.ViewsContracts; @@ -34,6 +36,7 @@ namespace Tango.PPC.UI /// </summary> static ViewModelLocator() { + TangoIOC.Default.Unregister<IDispatcherProvider>(); TangoIOC.Default.Unregister<INotificationProvider>(); TangoIOC.Default.Unregister<IAuthenticationProvider>(); TangoIOC.Default.Unregister<IPPCModuleLoader>(); @@ -45,6 +48,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Unregister<IEventLogger>(); TangoIOC.Default.Unregister<ITeamFoundationServiceClient>(); + TangoIOC.Default.Register<IDispatcherProvider, DefaultDispetcherProvider>(new DefaultDispetcherProvider(Application.Current.Dispatcher)); TangoIOC.Default.Register<INotificationProvider, DefaultNotificationProvider>(); TangoIOC.Default.Register<IAuthenticationProvider, DefaultAuthenticationProvider>(); TangoIOC.Default.Register<IPPCModuleLoader, DefaultPPCModuleLoader>(); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs index 11bef4827..062ade9cf 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -94,11 +94,6 @@ namespace Tango.PPC.UI.ViewModels } } - private void MachineOperator_PrintingStarted(object sender, Integration.Operation.JobHandler jobHandler) - { - _jobHandler = jobHandler; - } - /// <summary> /// Opens the menu or navigate back. /// </summary> @@ -143,6 +138,11 @@ namespace Tango.PPC.UI.ViewModels MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted; } + private void MachineOperator_PrintingStarted(object sender, PrintingEventArgs e) + { + _jobHandler = e.JobHandler; + } + /// <summary> /// Handles the ModulesLoaded event of the ModuleLoader. /// </summary> |
