private static void Main(string[] args) { var startTicks = Environment.TickCount; var currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += ExceptionHandler; bool createdNew; _instanceMutex = new Mutex(true, @"AppDirect.WindowsClient Browser Mutex", out createdNew); if (!createdNew) { Log.Info("Instance already exists, exit."); _instanceMutex = null; Environment.Exit(0); } try { BrowserObject.Initialize(); } catch (Exception e) { Log.ErrorException("Failed to initialize the browser", e); MessageBox.Show(String.Format(Resources.Failed_to_initialize_browser_error_message, e.Message)); return; } var api = new BrowsersManagerApi(BrowserWindowsManager, UiHelper); var apiStarter = new IpcMainWindowStarter(api); var mainAppClient = new MainApplicationServiceClient(new MainApplicationClientServiceStarter(), UiHelper, new NLogLogger("MainApplicationServiceClient")); var appDirectClientProcessWatcher = new ProcessWatcher(_mainApplicationName, new AbstractProcess(_mainApplicationName, new NLogLogger("BrowserMainProcess")), Log); var sessionKeeper = new SessionKeeper(mainAppClient, BrowserWindowsManager, BrowserWindowsBuilder, new NLogLogger("Browser.SessionKeeper"), UiHelper); try { var app = new App(); app.InitializeComponent(); UiHelper.IgnoreException(sessionKeeper.Start); bool hadStartException = false; try { apiStarter.Start(); } catch (Exception e) { Log.ErrorException("Failed to start server communication", e); hadStartException = true; } UiHelper.IgnoreException(appDirectClientProcessWatcher.Start); if (!hadStartException) { var wasInitialized = InitializeClient(mainAppClient); if (wasInitialized) { var timeElapsed = Environment.TickCount - startTicks; Log.Warn("BrowserManager startup completed in " + timeElapsed + "ms."); app.Run(); } } } finally { UiHelper.IgnoreException(apiStarter.Stop); UiHelper.IgnoreException(appDirectClientProcessWatcher.Stop); UiHelper.IgnoreException(sessionKeeper.Stop); UiHelper.IgnoreException(BrowserObject.Unload); UiHelper.IgnoreException(_instanceMutex.ReleaseMutex); } }
public void Init() { _browsersManagerApi = Substitute.For<IBrowsersManagerApi>(); _communicationObjectMock = Substitute.For<ICommunicationObject>(); _ipcMainWindowStarter = new TestIpcMainWindowStarter(_browsersManagerApi, _communicationObjectMock); }
public void Init() { _browsersManagerApi = Substitute.For <IBrowsersManagerApi>(); _communicationObjectMock = Substitute.For <ICommunicationObject>(); _ipcMainWindowStarter = new TestIpcMainWindowStarter(_browsersManagerApi, _communicationObjectMock); }
private static void Main(string[] args) { var startTicks = Environment.TickCount; var currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += ExceptionHandler; bool createdNew; _instanceMutex = new Mutex(true, @"AppDirect.WindowsClient Browser Mutex", out createdNew); if (!createdNew) { Log.Info("Instance already exists, exit."); _instanceMutex = null; Environment.Exit(0); } try { BrowserObject.Initialize(); } catch (Exception e) { Log.ErrorException("Failed to initialize the browser", e); MessageBox.Show(String.Format(Resources.Failed_to_initialize_browser_error_message, e.Message)); return; } var api = new BrowsersManagerApi(BrowserWindowsManager, UiHelper); var apiStarter = new IpcMainWindowStarter(api); var mainAppClient = new MainApplicationServiceClient(new MainApplicationClientServiceStarter(), UiHelper, new NLogLogger("MainApplicationServiceClient")); var appDirectClientProcessWatcher = new ProcessWatcher(_mainApplicationName, new AbstractProcess(_mainApplicationName, new NLogLogger("BrowserMainProcess")), Log); var sessionKeeper = new SessionKeeper(mainAppClient, BrowserWindowsManager, BrowserWindowsBuilder, new NLogLogger("Browser.SessionKeeper"), UiHelper); try { var app = new App(); app.InitializeComponent(); UiHelper.IgnoreException(sessionKeeper.Start); bool hadStartException = false; try { apiStarter.Start(); } catch (Exception e) { Log.ErrorException("Failed to start server communication", e); hadStartException = true; } UiHelper.IgnoreException(appDirectClientProcessWatcher.Start); if (!hadStartException) { var wasInitialized = InitializeClient(mainAppClient); if (wasInitialized) { var timeElapsed = Environment.TickCount - startTicks; Log.Warn("BrowserManager startup completed in " + timeElapsed + "ms."); app.Run(); } } } finally { UiHelper.IgnoreException(apiStarter.Stop); UiHelper.IgnoreException(appDirectClientProcessWatcher.Stop); UiHelper.IgnoreException(sessionKeeper.Stop); UiHelper.IgnoreException(BrowserObject.Unload); UiHelper.IgnoreException(_instanceMutex.ReleaseMutex); } }