private PersistentFactory CreateTestFactory(bool cleanOldDataStore = true) { var dataStorePath = Path.Combine(TestContext.TestRunDirectory, "persistent40liteDatastore"); if (cleanOldDataStore) { var dirinfo = new DirectoryInfo(dataStorePath); if (dirinfo.Exists) dirinfo.Delete(true); } var logger = new TestLogger(); var storage = new PlainFilePersistentStorage(logger, dataStorePath); var serializer = new JsonPersistentSerializer(logger); var factory = new PersistentFactory(storage, serializer, logger); return factory; }
private void App_OnStartup(object sender, StartupEventArgs e) { try { Current.Dispatcher.UnhandledException += (o, args) => { ErrorManager.ShowError("Something unexpected happened in the launcher, please report this error.", args.Exception, true); args.Handled = true; }; uniqueLaunchGateway = new WurmAssistantLauncherGateway(doNotAutoEnter: true); uniqueLaunchGateway.Enter(1000); LauncherPipeCom = new PipeCom(uniqueLaunchGateway.UniqueId, "Default"); LauncherPipeCom.LoginAsEndpointAlpha(); LauncherTaskbarIcon = (TaskbarIcon)FindResource("LauncherTaskbarIcon"); AppContext.BuildContext(); Logger = new SimpleLogger(); Logger.SetLogSaveDir(PathEx.CombineWithCodeBase("LauncherLogs")); Logger.SetConsoleHandlingMode(SimpleLogger.ConsoleHandlingOption.SendConsoleToLoggerOutputDIAG); SpellbookLogger.Logged += (o, args) => { switch (args.Severity) { case LogSeverity.Debug: Logger.LogDebug(args.Message, args.Source, args.Exception); break; case LogSeverity.Info: Logger.LogInfo(args.Message, args.Source, args.Exception); break; case LogSeverity.Error: Logger.LogError(args.Message, args.Source, args.Exception); break; } }; var logger = new PersistentLogger(); var storage = new PlainFilePersistentStorage(logger, AppContext.LauncherSettingsDir); var serializer = new JsonPersistentSerializer(logger); PersistentFactory = new PersistentFactory(storage, serializer, logger); var initialSetup = new InitialSetupManager(); initialSetup.Execute(); Settings = PersistentFactory.Create<LauncherSettings>("LauncherSettings"); StartupUri = new Uri(@"Views\MainWindow.xaml", UriKind.Relative); } catch (GatewayClosedException) { // try activate existing instance of launcher using (var pipecom = new PipeCom(uniqueLaunchGateway.UniqueId, "Default")) { pipecom.LoginAsAlphaClient(); pipecom.TrySend("ShowWindow", null); } Shutdown(); } catch (Exception exception) { MessageBox.Show("Unexpected error while starting the Launcher, please report this bug! Error: " + exception.Message); Logger.LogError("error on app init", this, exception); Shutdown(); } }