示例#1
0
文件: App.xaml.cs 项目: yangmain/Edi
        /// <summary>
        /// Method executes as application entry point - that is -
        /// this bit of code executes before anything else in this
        /// class and application.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(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
                ShutdownMode = ShutdownMode.OnExplicitShutdown;
            }
            catch
            {
            }

            IOptions              options         = null;
            ISettingsManager      settingsManager = null;
            IThemesManager        themesManager   = null;
            IApplicationViewModel AppViewModel    = null;

            try
            {
                // Resolve SettingsManager to retrieve app settings/session data
                // and start with correct parameters from last session (theme, window pos etc...)
                settingsManager = _Container.Resolve <ISettingsManager>();
                themesManager   = _Container.Resolve <IThemesManager>();
                _AppCore        = _Container.Resolve <IAppCore>();

                var task = Task.Run(async() =>  // Off Loading Load Programm Settings to non-UI thread
                {
                    options = await settingsManager.LoadOptionsAsync(_AppCore.DirFileAppSettingsData, themesManager);
                });
                task.Wait(); // Block this to ensure that results are usable in next steps of sequence

                AppViewModel = _Container.Resolve <IApplicationViewModel>();
                var task1 = Task.Run(async() =>  // Off Loading Load Programm Settings to non-UI thread
                {
                    await AppViewModel.LoadConfigOnAppStartupAsync(options, settingsManager, themesManager);
                });
                task1.Wait(); // Block this to ensure that results are usable in next steps of sequence

                // This allows castle to look at the current assembly and look for implementations
                // of the IWindsorInstaller interface
                _Container.Install(FromAssembly.This());                         // Register

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

                if (options.RunSingleInstance == true)
                {
                    if (enforcer.ShouldApplicationExit() == true)
                    {
                        if (AppIsShuttingDown == false)
                        {
                            AppIsShuttingDown = true;
                            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("");
            }

            var start = _Container.Resolve <IShell <MainWindow> >();     // Resolve

            //resolve our shell to start the application.
            if (start != null)
            {
                // Configure Explorer Settings from last session


                start.ConfigureSession(AppViewModel, settingsManager);
                AppViewModel.EnableMainWindowActivated(true);

/////                var toolWindowRegistry = _Container.Resolve<IToolWindowRegistry>();
/////                toolWindowRegistry.PublishTools();

                if (this.AppIsShuttingDown == false)
                {
                    this.ShutdownMode = ShutdownMode.OnLastWindowClose;
                }
            }
            else
            {
                throw new Exception("Main Window construction failed in application boot strapper class.");
            }

            // Show the startpage if application starts for the very first time
            // (This requires that command binding was succesfully done before this line)
            if (string.IsNullOrEmpty(settingsManager.SessionData.LastActiveFile))
            {
                AppViewModel.ShowStartPage();
            }

            start.Run();                                              // Show the mainWindow

            var msgBox = _Container.Resolve <IMessageBoxService>();

            // discover via Plugin folder instead
            MiniUML.Model.MiniUmlPluginLoader.LoadPlugins(
                _AppCore.AssemblyEntryLocation + @".\Plugins\MiniUML.Plugins.UmlClassDiagram\",
                AppViewModel, msgBox);


            if (e != null)
            {
                ProcessCmdLine(e.Args, AppViewModel);
            }

            // Modules (and everything else) have been initialized if we got here
            var output = _Container.Resolve <IMessageManager>();

            output.Output.AppendLine("Get involved at: https://github.com/Dirkster99/Edi");

            _AppCore.CreateAppDataFolder();

// Cannot set shutdown mode when application is already shuttong down
//            try
//            {
//                if (AppIsShuttingDown == false)
//                    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 (Current.MainWindow != null)
            {
                if (Current.MainWindow.IsVisible == false)
                {
                    Current.MainWindow = null;
                }
            }

/////            if (AppIsShuttingDown == false)
/////                Shutdown();
        }
示例#2
0
        protected override DependencyObject CreateShell()
        {
            try
            {
                var appCore = Container.GetExportedValue <IAppCoreModel>();

                var avLayout = Container.GetExportedValue <IAvalonDockLayoutViewModel>();
                _AppVM = Container.GetExportedValue <IApplicationViewModel>();

                var toolWindowRegistry = Container.GetExportedValue <IToolWindowRegistry>();

                var task = Task.Run(async() =>  // Off Loading Load Programm Settings to non-UI thread
                {
                    await _AppVM.LoadConfigOnAppStartupAsync(_Options, _ProgramSettingsManager, _Themes);
                });
                task.Wait(); // Block this to ensure that results are usable in MainWindow construction

                // Attempt to load a MiniUML plugin via the model class
                MiniUML.Model.MiniUmlPluginLoader.LoadPlugins(appCore.AssemblyEntryLocation + @".\Plugins\MiniUML.Plugins.UmlClassDiagram\", AppViewModel); // discover via Plugin folder instead

                _MainWin = Container.GetExportedValue <MainWindow>();
                appCore.CreateAppDataFolder();

                if (_MainWin != null)
                {
                    ConstructMainWindowSession(_AppVM, _MainWin, _ProgramSettingsManager);

                    if (_App.AppIsShuttingDown == false)
                    {
                        _App.ShutdownMode = ShutdownMode.OnLastWindowClose;
                    }
                    ////this.mMainWin.Show();
                }
                else
                {
                    throw new Exception("Main Window construction failed in application boot strapper class.");
                }
            }
            catch (Exception exp)
            {
                logger.Error(exp);

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

                try
                {
                    // 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;
                        }
                    }
                }
                catch (Exception exp2)
                {
                    logger.Error(exp2);
                }

                _MsgBox.Show(exp, Strings.STR_MSG_ERROR_FINDING_RESOURCE
                             , MsgBoxButtons.OKCopy, MsgBoxImage.Error);

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

            return(_MainWin);
        }