コード例 #1
0
        /// <summary>
        /// Executes the processing necessary to bootstrap the application
        /// including module detection, registration, and loading.
        /// http://stackoverflow.com/questions/10466304/event-upon-initialization-complete-in-wpf-prism-app
        /// </summary>
        public override void Run(bool runWithDefaultConfiguration)
        {
            try
            {
                base.Run(runWithDefaultConfiguration);

                // Register imported tool window definitions with Avalondock
                var toolWindowRegistry = Container.GetExportedValue <IToolWindowRegistry>();

                MEFLoadFiles.Initialize(appVM.AdLayout,
                                        mProgramSettingsManager,
                                        toolWindowRegistry,
                                        appVM as IFileOpenService);

                toolWindowRegistry.PublishTools();


                // Show the startpage if application starts for the very first time
                // (This requires that command binding was succesfully done before this line)
                if (appVM.AdLayout.LayoutSoure == Core.Models.Enums.LayoutLoaded.FromDefault)
                {
                    AppCommand.ShowStartPage.Execute(null, null);
                }

                if (mEventArgs != null)
                {
                    ProcessCmdLine(mEventArgs.Args, appVM);
                }

                // PRISM modules (and everything else) have been initialized if we got here
                var output = Container.GetExportedValue <IMessageManager>();
                output.Output.AppendLine("Get involved at: https://github.com/Dirkster99/Edi");

                appVM.EnableMainWindowActivated(true);
            }
            catch (Exception exp)
            {
                logger.Error(exp);
            }
        }
コード例 #2
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();
        }