Beispiel #1
0
        /// <summary>
        /// This is the first bit of code being executed when the application is invoked (main entry point).
        ///
        /// Use the <paramref name="e"/> parameter to evaluate command line options.
        /// Invoking a program with an associated file type extension (eg.: *.txt) in Explorer
        /// results, for example, in executing this function with the path and filename being
        /// supplied in <paramref name="e"/>.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            try
            {
                // Set shutdown mode here (and reset further below) to enable showing custom dialogs (messageboxes)
                // durring start-up without shutting down application when the custom dialogs (messagebox) closes
                this.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
            }
            catch
            {
            }

            Options        options       = null;
            IThemesManager themesManager = new ThemesManager();

            try
            {
                options = SettingsManager.LoadOptions(AppHelpers.DirFileAppSettingsData, themesManager);

                Thread.CurrentThread.CurrentCulture   = new CultureInfo(options.LanguageSelected);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(options.LanguageSelected);

                if (options.RunSingleInstance == true)
                {
                    if (enforcer.ShouldApplicationExit() == true)
                    {
                        if (this.AppIsShuttingDown == false)
                        {
                            this.AppIsShuttingDown = true;
                            this.Shutdown();
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                Logger.Error(exp);
            }

            try
            {
                this.mBoot = new Bootstapper(this, e, options, themesManager);
                this.mBoot.Run();
            }
            catch (Exception exp)
            {
                Logger.Error(exp);

                // Cannot set shutdown mode when application is already shuttong down
                if (this.AppIsShuttingDown == false)
                {
                    this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                }

                // 1) Application hangs when this is set to null while MainWindow is visible
                // 2) Application throws exception when this is set as owner of window when it
                //    was never visible.
                //
                if (Application.Current.MainWindow != null)
                {
                    if (Application.Current.MainWindow.IsVisible == false)
                    {
                        Application.Current.MainWindow = null;
                    }
                }

                MsgBox.Msg.Show(exp, Strings.STR_MSG_ERROR_FINDING_RESOURCE, MsgBoxButtons.OKCopy);

                if (this.AppIsShuttingDown == false)
                {
                    this.Shutdown();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// This is the first bit of code being executed when the application is invoked (main entry point).
        ///
        /// Use the <paramref name="e"/> parameter to evaluate command line options.
        /// Invoking a program with an associated file type extension (eg.: *.txt) in Explorer
        /// results, for example, in executing this function with the path and filename being
        /// supplied in <paramref name="e"/>.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            try
            {
                // Set shutdown mode here (and reset further below) to enable showing custom dialogs (messageboxes)
                // durring start-up without shutting down application when the custom dialogs (messagebox) closes
                this.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
            }
            catch
            {
            }

            Options        options       = null;
            IThemesManager themesManager = new ThemesManager();

            try
            {
                options = SettingsManager.LoadOptions(AppHelpers.DirFileAppSettingsData, themesManager);

                Thread.CurrentThread.CurrentCulture   = new CultureInfo(options.LanguageSelected);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(options.LanguageSelected);

                if (options.RunSingleInstance == true)
                {
                    if (enforcer.ShouldApplicationExit() == true)
                    {
                        if (this.AppIsShuttingDown == false)
                        {
                            this.AppIsShuttingDown = true;
                            this.Shutdown();
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                Logger.Error(exp);
                Console.WriteLine("");
                Console.WriteLine("Unexpected Error 1 in App.Application_Startup()");
                Console.WriteLine("   Message:{0}", exp.Message);
                Console.WriteLine("StackTrace:{0}", exp.StackTrace);
                Console.WriteLine("");
            }

            try
            {
                this.mBoot = new Bootstapper(this, e, options, themesManager);
                this.mBoot.Run();
            }
            catch (Exception exp)
            {
                Logger.Error(exp);
                Console.WriteLine("");
                Console.WriteLine("Unexpected Error 2 in App.Application_Startup()");
                Console.WriteLine("   Message:{0}", exp.Message);
                Console.WriteLine("StackTrace:{0}", exp.StackTrace);
                Console.WriteLine("");

                // Typically thrown by MEF when module binding does not work
                if (exp is System.Reflection.ReflectionTypeLoadException)
                {
                    var loaderExcept = (exp as System.Reflection.ReflectionTypeLoadException).LoaderExceptions;

                    Console.WriteLine("Loader Exception(s):");
                    Logger.Error("Loader Exception(s):");

                    foreach (var item in loaderExcept)
                    {
                        Console.WriteLine("Message {0}:", item.Message);
                        Console.WriteLine("StackTrace {0}:", item.StackTrace);
                    }
                }

                // Cannot set shutdown mode when application is already shuttong down
                try
                {
                    if (this.AppIsShuttingDown == false)
                    {
                        this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                    }
                }
                catch
                {
                }

                // 1) Application hangs when this is set to null while MainWindow is visible
                // 2) Application throws exception when this is set as owner of window when it
                //    was never visible.
                //
                if (Application.Current.MainWindow != null)
                {
                    if (Application.Current.MainWindow.IsVisible == false)
                    {
                        Application.Current.MainWindow = null;
                    }
                }

//                var msgBox = ServiceLocator.Current.GetInstance<IMessageBoxService>();
//                msgBox.Show(exp, Strings.STR_MSG_ERROR_FINDING_RESOURCE, MsgBoxButtons.OKCopy, MsgBoxImage.Error);

                if (this.AppIsShuttingDown == false)
                {
                    this.Shutdown();
                }
            }
        }