From afc7a07d285e08d905c58dd5978441c155b2f296 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 19 Dec 2017 10:25:40 +0200 Subject: MERGE. --- .../ViewModels/LoadingViewVM.cs | 50 ++++++++++++++++++---- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs index 72ab5aca9..f50b734f4 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -4,26 +4,58 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using Tango.Core.Threading; +using Tango.DAL.Observables; using Tango.MachineStudio.Common.Modules; using Tango.MachineStudio.Common.Navigation; +using Tango.MachineStudio.Common.Notifications; using Tango.SharedUI; namespace Tango.MachineStudio.UI.ViewModels { public class LoadingViewVM : ViewModel { - public LoadingViewVM(INavigationManager navigationManager, IStudioModuleLoader studioModuleLoader) + private INotificationProvider _notificationProvider; + private INavigationManager _navigationManager; + private IStudioModuleLoader _studioModuleLoader; + + public LoadingViewVM(INavigationManager navigationManager, IStudioModuleLoader studioModuleLoader, INotificationProvider notificationProvider) + { + _navigationManager = navigationManager; + _studioModuleLoader = studioModuleLoader; + _notificationProvider = notificationProvider; + Load(); + } + + private void Load() { - Task.Factory.StartNew(() => + StaThreadHelper.StartStaThread(() => { Thread.Sleep(3000); - }).ContinueWith((x) => - { - - studioModuleLoader.LoadModules(); - navigationManager.NavigateTo(NavigationView.LoginView); - - }, TaskScheduler.FromCurrentSynchronizationContext()); + try + { + ObservablesEntitiesAdapter.Instance.Initialize(); + InvokeUI(() => + { + _studioModuleLoader.LoadModules(); + _navigationManager.NavigateTo(NavigationView.LoginView); + }); + } + catch (Exception ex) + { + InvokeUINow(() => + { + if (_notificationProvider.ShowQuestion("An error occurred while trying to connect to Twine database." + Environment.NewLine + "Would you like to try again?")) + { + Load(); + } + else + { + Environment.Exit(0); + } + }); + } + }); } } } -- cgit v1.3.1