Exemplo n.º 1
0
        public void Bootstrap()
        {
            var marshaller = new WinFormsMainThreadEventMarshaller(mainForm);

            try
            {
                dataDirectory = new SharedDataDirectory();
            }
            catch (LockFailedException)
            {
                // must have exclusive lock on data directory, else most likely another app instance is using it
                //mainForm.Close();
                Application.Exit();
                return;
            }

            persistentLibrary = new PersistentCollectionsLibrary(new FlatFilesPersistenceStrategy(
                Path.Combine(dataDirectory.FullName, "WurmAssistantLiteSettings")));

            var globalSettings =
                new WurmAssistantLiteSettings(
                    persistentLibrary.DefaultCollection.GetObject<GlobalSettingsEntity>("GlobalSettings"))
                {
                    DataDirectoryFullPath = dataDirectory.FullName
                };

            var configurator = new Configurator(globalSettings);

            var valid = configurator.ExecConfig();
            if (!valid)
            {
                // stopping construction and exiting
                //mainForm.Close();
                Application.Exit();
                return;
            }

            var wurmAssistantConfig = configurator.BuildWurmAssistantConfig();

            // bind app specific dependencies
            kernel.Bind<WurmAssistantLiteSettings>().ToConstant(globalSettings);
            kernel.Bind<IWurmAssistantConfig, WurmAssistantConfig>().ToConstant(wurmAssistantConfig);
            kernel.Bind<IEventMarshaller, WinFormsMainThreadEventMarshaller>().ToConstant(marshaller);
            kernel.Bind<IEnvironment, Environment>().ToConstant(environment);
            kernel.Bind<ILogSearcherModuleGui>().To<LogSearcherForm>();

            // bootstrap core
            coreBootstrapper = new CoreBootstrapper(kernel);

            var appStartViewModel = coreBootstrapper.GetAppStartViewModel();
            var appStartView = new AppStartView(appStartViewModel);
            mainForm.SetAppCoreView(appStartView);

            var logOutputViewModel = appStartViewModel.LogOutputViewModel;
            var logOutputTempView = new LogOutputView(logOutputViewModel);
            mainForm.SetLogOutputView(logOutputTempView);

            coreBootstrapper.BootstrapRuntime();
            globalLogger = kernel.Get<LoggerFactory>().Create("WA-Lite");
            globalLogger.Info("Core bootstrapping completed");

            globalLogger.Info("Resolving application runtime");
            var appRunningViewModel = coreBootstrapper.GetAppRunningViewModel();
            var appRunningView = new AppRunningView(appRunningViewModel, globalSettings);
            mainForm.SetAppCoreView(appRunningView);
            globalLogger.Info("Application runtime resolved");

            Bootstrapped = true;
            // save last, so if configuration causes bootstrap crash, it does not get saved
            SaveSettings();
            globalLogger.Info("Settings saved");
        }
Exemplo n.º 2
0
        protected override void OnStartup(object sender, StartupEventArgs e)
        {
            // configure and bind app-specific dependencies

            kernel.Bind<IEnvironment>().ToConstant(environment).InSingletonScope();

            windowManager = new WindowManager();
            kernel.Bind<WindowManager>().ToConstant(windowManager);
            kernel.Bind<IWindowManager>().To<WindowManager>();

            kernel.Bind<AppHostViewModel>().ToSelf().InSingletonScope();

            try
            {
                sharedDataDirectory = new SharedDataDirectory();
            }
            catch (LockFailedException)
            {
                // if cannot obtain exclusive lock on data directory, it means another instance is already running
                Application.Current.Shutdown();
                return;
            }

            var config = new WurmAssistantConfig() {DataDirectoryFullPath = sharedDataDirectory.FullName};
            kernel.Bind<IWurmAssistantConfig>().ToConstant(config);
            var marshaller = new WpfGuiThreadEventMarshaller(environment);
            kernel.Bind<IEventMarshaller, WpfGuiThreadEventMarshaller>().ToConstant(marshaller);

            // bind app-specific dependencies
            kernel.Bind<ILogSearcherModuleGui>().To<LogSearcherForm>();

            // create hosting window for the app
            var hostView = kernel.Get<AppHostViewModel>();
            windowManager.ShowWindow(hostView, null, new Dictionary<string, object>());

            // initialize and resolve the app
            coreBootstrapper = new CoreBootstrapper(kernel);

            // show the application startup screen

            var appStartVm = coreBootstrapper.GetAppStartViewModel();
            hostView.CurrentScreen = appStartVm;

            // initialize application

            coreBootstrapper.BootstrapRuntime();
            globalLogger = kernel.Get<LoggerFactory>().Create();

            // show the application running screen

            var appRunningVm = coreBootstrapper.GetAppRunningViewModel();
            hostView.CurrentScreen = appRunningVm;
        }