diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-11-26 14:19:06 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-11-26 14:19:06 +0200 |
| commit | 6fb22273d15ed476ccbd3820de6af9bc0deee793 (patch) | |
| tree | 35c40b14471bbc191d12a1dafcd807ec16aacb87 /Software | |
| parent | 10a9435c7fece43c588addb744952d92596a8f5b (diff) | |
| download | Tango-6fb22273d15ed476ccbd3820de6af9bc0deee793.tar.gz Tango-6fb22273d15ed476ccbd3820de6af9bc0deee793.zip | |
Implemented Application Initialization Error and Handling.
Diffstat (limited to 'Software')
12 files changed, 208 insertions, 27 deletions
diff --git a/Software/Graphics/Mobile/warning-red.png b/Software/Graphics/Mobile/warning-red.png Binary files differnew file mode 100644 index 000000000..97e703bb3 --- /dev/null +++ b/Software/Graphics/Mobile/warning-red.png diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs index 0feb551b1..003229e65 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs @@ -41,6 +41,11 @@ namespace Tango.PPC.Common.Application event EventHandler SetupRequired; /// <summary> + /// Occurs when the application has encountered an error when initializing. + /// </summary> + event EventHandler<Exception> ApplicationInitializationError; + + /// <summary> /// Gets a value indicating whether the application is shutting down. /// </summary> bool IsShuttingDown { get; } @@ -51,6 +56,11 @@ namespace Tango.PPC.Common.Application void ShutDown(); /// <summary> + /// Restarts the application. + /// </summary> + void Restart(); + + /// <summary> /// Gets the application version. /// </summary> Version Version { get; } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs index c86cf148b..eefb298f7 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs @@ -12,6 +12,7 @@ namespace Tango.PPC.Common.Navigation public enum NavigationView { LoadingView, + LoadingErrorView, LayoutView, LoginView, MachineSetupView, diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/warning-red.png b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/warning-red.png Binary files differnew file mode 100644 index 000000000..97e703bb3 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/warning-red.png diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index 714b83dfa..4021d89ef 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -23,6 +23,7 @@ using Tango.SQLExaminer; using System.Data.SqlClient; using Tango.BL.Builders; using Tango.PPC.Common.Threading; +using System.Diagnostics; namespace Tango.PPC.UI.PPCApplication { @@ -64,6 +65,11 @@ namespace Tango.PPC.UI.PPCApplication public event EventHandler ContentRendered; /// <summary> + /// Occurs when the application has encountered an error when initializing. + /// </summary> + public event EventHandler<Exception> ApplicationInitializationError; + + /// <summary> /// Gets a value indicating whether the application is shutting down. /// </summary> public bool IsShuttingDown { get; private set; } @@ -125,46 +131,72 @@ namespace Tango.PPC.UI.PPCApplication { PPCSettings settings = null; + bool initialized = false; + await Task.Factory.StartNew(() => { - LogManager.Log("Reading PPC settings..."); - settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); + try + { + LogManager.Log("Reading PPC settings..."); + settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); - LogManager.Log(settings.ToJsonString()); + LogManager.Log(settings.ToJsonString()); - LogManager.Log("Reading Core settings..."); - var coreSettings = SettingsManager.Default.GetOrCreate<CoreSettings>(); + LogManager.Log("Reading Core settings..."); + var coreSettings = SettingsManager.Default.GetOrCreate<CoreSettings>(); - if (!SettingsManager.Default.IsFileExists()) - { - LogManager.Log("Settings file does not exists. creating..."); - settings.Save(); - } + if (!SettingsManager.Default.IsFileExists()) + { + LogManager.Log("Settings file does not exists. creating..."); + settings.Save(); + } - if (App.StartupArgs.Contains("-update_ok")) - { - LogManager.Log("Application started with '-update_ok' startup arguments. The application has been successfully updated."); - settings.ApplicationState = ApplicationStates.Ready; - settings.Save(); - } + if (App.StartupArgs.Contains("-update_ok")) + { + LogManager.Log("Application started with '-update_ok' startup arguments. The application has been successfully updated."); + settings.ApplicationState = ApplicationStates.Ready; + settings.Save(); + } - if (settings.ApplicationState == ApplicationStates.Ready) + if (settings.ApplicationState == ApplicationStates.Ready) + { + LogManager.Log("Initializing ObservablesStaticCollections..."); + ObservablesStaticCollections.Instance.Initialize(); + LogManager.Log("Loading machine from database..."); + _machine = new MachineBuilder(ObservablesContext.CreateDefault()).SetFirst().WithOrganization().WithConfiguration().Build(); + } + + initialized = true; + } + catch (Exception ex) { - LogManager.Log("Loading machine from database..."); - ObservablesStaticCollections.Instance.Initialize(); - _machine = new MachineBuilder(ObservablesContext.CreateDefault()).SetFirst().WithOrganization().WithConfiguration().Build(); + LogManager.Log(ex, "Application Initialization Error!"); + ApplicationInitializationError?.Invoke(this, ex); + return; } }); - if (settings.ApplicationState == ApplicationStates.PreSetup || settings.ApplicationState == ApplicationStates.SemiSetup) + if (initialized) { - LogManager.Log($"The application is in {settings.ApplicationState} state. database initialization skipped. Invoking setup required event!"); - SetupRequired?.Invoke(this, new EventArgs()); - } - else - { - PostDbInitialize(); + try + { + if (settings.ApplicationState == ApplicationStates.PreSetup || settings.ApplicationState == ApplicationStates.SemiSetup) + { + LogManager.Log($"The application is in {settings.ApplicationState} state. database initialization skipped. Invoking setup required event!"); + SetupRequired?.Invoke(this, new EventArgs()); + } + else + { + PostDbInitialize(); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Application Post Initialization Error!"); + ApplicationInitializationError?.Invoke(this, ex); + return; + } } } @@ -273,5 +305,14 @@ namespace Tango.PPC.UI.PPCApplication vm.OnApplicationShuttingDown(); } } + + /// <summary> + /// Restarts the application. + /// </summary> + public void Restart() + { + Process.Start(Application.ResourceAssembly.Location); + Environment.Exit(0); + } } } 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 2ff219906..e552d096b 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 @@ -134,6 +134,7 @@ <Compile Include="ViewModelLocator.cs" /> <Compile Include="ViewModels\ExternalBridgeViewVM.cs" /> <Compile Include="ViewModels\LayoutViewVM.cs" /> + <Compile Include="ViewModels\LoadingErrorViewVM.cs" /> <Compile Include="ViewModels\LoadingViewVM.cs" /> <Compile Include="ViewModels\LoginViewVM.cs" /> <Compile Include="ViewModels\MachineSetupViewVM.cs" /> @@ -148,6 +149,9 @@ <Compile Include="Views\LayoutView.xaml.cs"> <DependentUpon>LayoutView.xaml</DependentUpon> </Compile> + <Compile Include="Views\LoadingErrorView.xaml.cs"> + <DependentUpon>LoadingErrorView.xaml</DependentUpon> + </Compile> <Compile Include="Views\LoadingView.xaml.cs"> <DependentUpon>LoadingView.xaml</DependentUpon> </Compile> @@ -203,6 +207,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Views\LoadingErrorView.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="Views\LoadingView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> @@ -381,6 +389,7 @@ <Link>Tango.ColorLib.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> + <Resource Include="Images\warning-red.png" /> <Resource Include="Images\update.png" /> <Resource Include="Images\flash-drive.png" /> <Resource Include="Images\right-arrow-64.png" /> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index 703a2f6ae..4bf83242f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -88,6 +88,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register<ExternalBridgeViewVM>(); TangoIOC.Default.Register<MachineSetupViewVM>(); TangoIOC.Default.Register<MachineUpdateViewVM>(); + TangoIOC.Default.Register<LoadingErrorViewVM>(); TangoIOC.Default.GetInstance<IPPCApplicationManager>().ContentRendered += (_, __) => @@ -161,5 +162,13 @@ namespace Tango.PPC.UI return TangoIOC.Default.GetInstance<MachineUpdateViewVM>(); } } + + public static LoadingErrorViewVM LoadingErrorViewVM + { + get + { + return TangoIOC.Default.GetInstance<LoadingErrorViewVM>(); + } + } } }
\ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingErrorViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingErrorViewVM.cs new file mode 100644 index 000000000..3c05e3690 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingErrorViewVM.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.PPC.Common; +using Tango.PPC.Common.Navigation; + +namespace Tango.PPC.UI.ViewModels +{ + public class LoadingErrorViewVM : PPCViewModel, INavigationObjectReceiver<Exception> + { + private String _error; + public String Error + { + get { return _error; } + set { _error = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand RestartCommand { get; set; } + + public LoadingErrorViewVM() + { + RestartCommand = new RelayCommand(Restart); + } + + public override void OnApplicationStarted() + { + + } + + public void OnNavigatedToWithObject(Exception ex) + { + Error = ex.Message; + } + + private void Restart() + { + ApplicationManager.Restart(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs index 486829103..5598362be 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs @@ -54,6 +54,17 @@ namespace Tango.PPC.UI.ViewModels { Task.Delay(1000).ContinueWith((x) => { IsLoading = true; }); } + + applicationManager.ApplicationInitializationError += ApplicationManager_ApplicationInitializationError; + } + + private void ApplicationManager_ApplicationInitializationError(object sender, Exception ex) + { + InvokeUI(() => + { + NavigationManager.NavigateWithObject<Exception>(NavigationView.LoadingErrorView, ex); + IsLoading = false; + }); } /// <summary> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LoadingErrorView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LoadingErrorView.xaml new file mode 100644 index 000000000..7682ba4ce --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LoadingErrorView.xaml @@ -0,0 +1,28 @@ +<UserControl x:Class="Tango.PPC.UI.Views.LoadingErrorView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" + xmlns:vm="clr-namespace:Tango.PPC.UI.ViewModels" + xmlns:global="clr-namespace:Tango.PPC.UI" + xmlns:local="clr-namespace:Tango.PPC.UI.Views" + mc:Ignorable="d" + d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:LoadingErrorViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.LoadingErrorViewVM}"> + <Grid> + <DockPanel Margin="20 60 20 20"> + <StackPanel DockPanel.Dock="Top"> + <Image Source="../Images/warning-red.png" Width="300" Stretch="Uniform" HorizontalAlignment="Center"></Image> + <TextBlock HorizontalAlignment="Center" Margin="0 40 0 0" FontSize="{StaticResource TangoHeaderFontSize}">Application Loading Error</TextBlock> + <TextBlock HorizontalAlignment="Center" Margin="0 20 0 0" FontSize="{StaticResource TangoTitleFontSize}">The application has failed to load properly due to the following reason.</TextBlock> + <TextBlock HorizontalAlignment="Center" Foreground="{StaticResource TangoGrayTextBrush}" TextAlignment="Center" Margin="100 20 100 0" TextWrapping="Wrap" Text="{Binding Error}"></TextBlock> + </StackPanel> + + <Grid> + <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Width="320"> + <touch:TouchButton Command="{Binding RestartCommand}" Padding="0 30" CornerRadius="40">RESTART</touch:TouchButton> + </StackPanel> + </Grid> + </DockPanel> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LoadingErrorView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LoadingErrorView.xaml.cs new file mode 100644 index 000000000..0713cc320 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LoadingErrorView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.PPC.UI.Views +{ + /// <summary> + /// Interaction logic for LoadingErrorView.xaml + /// </summary> + public partial class LoadingErrorView : UserControl + { + public LoadingErrorView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml index 7eca6dba6..4ca7e39ec 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml @@ -77,6 +77,7 @@ <controls:NavigationControl TransitionAlwaysFades="True" KeepElementsAttached="True" TransitionType="Zoom" x:Name="NavigationControl" x:FieldModifier="public"> <local:LoadingView></local:LoadingView> + <local:LoadingErrorView></local:LoadingErrorView> <local:LoginView></local:LoginView> <local:LayoutView></local:LayoutView> <local:ExternalBridgeView></local:ExternalBridgeView> |
