Example #1
0
        private static bool InitializeClient(MainApplicationServiceClient mainAppClient)
        {
            if (mainAppClient == null)
            {
                throw new ArgumentNullException("mainAppClient");
            }

            try
            {
                mainAppClient.Start();
            }
            catch (Exception e)
            {
                Log.ErrorException("Failed to establish connection with main app", e);

                MessageBox.Show(String.Format(Resources.Communications_can_t_be_established_error_message, e.Message));
                return false;
            }

            var hadException = true;
            while (hadException)
            {
                try
                {
                    mainAppClient.Initialized();
                    hadException = false;
                }
                catch (Exception e)
                {
                    Log.ErrorException("Failed to establish connection with main app", e);
                }
            }

            return true;
        }
Example #2
0
        private static bool InitializeClient(MainApplicationServiceClient mainAppClient)
        {
            if (mainAppClient == null)
            {
                throw new ArgumentNullException("mainAppClient");
            }

            try
            {
                mainAppClient.Start();
            }
            catch (Exception e)
            {
                Log.ErrorException("Failed to establish connection with main app", e);

                MessageBox.Show(String.Format(Resources.Communications_can_t_be_established_error_message, e.Message));
                return(false);
            }

            var hadException = true;

            while (hadException)
            {
                try
                {
                    mainAppClient.Initialized();
                    hadException = false;
                }
                catch (Exception e)
                {
                    Log.ErrorException("Failed to establish connection with main app", e);
                }
            }

            return(true);
        }
Example #3
0
        public SessionKeeper(MainApplicationServiceClient mainAppClient, IBrowserWindowsManager browserWindowsManager,
                             IBrowserWindowsBuilder <IBrowserWindow> browserWindowsBuilder, ILogger log, IUiHelper uiHelper)
        {
            if (mainAppClient == null)
            {
                throw new ArgumentNullException("mainAppClient");
            }

            if (browserWindowsManager == null)
            {
                throw new ArgumentNullException("browserWindowsManager");
            }

            if (browserWindowsBuilder == null)
            {
                throw new ArgumentNullException("browserWindowsBuilder");
            }

            if (log == null)
            {
                throw new ArgumentNullException("log");
            }

            if (uiHelper == null)
            {
                throw new ArgumentNullException("uiHelper");
            }

            _mainAppClient         = mainAppClient;
            _log                   = log;
            _uiHelper              = uiHelper;
            _sessionUpdator        = KeepUpdatingSession;
            _browserWindowsManager = browserWindowsManager;
            _browserWindowsBuilder = browserWindowsBuilder;
            _updaterThread         = new Thread(_sessionUpdator);
        }
Example #4
0
        public SessionKeeper(MainApplicationServiceClient mainAppClient, IBrowserWindowsManager browserWindowsManager,
            IBrowserWindowsBuilder<IBrowserWindow> browserWindowsBuilder, ILogger log, IUiHelper uiHelper)
        {
            if (mainAppClient == null)
            {
                throw new ArgumentNullException("mainAppClient");
            }

            if (browserWindowsManager == null)
            {
                throw new ArgumentNullException("browserWindowsManager");
            }

            if (browserWindowsBuilder == null)
            {
                throw new ArgumentNullException("browserWindowsBuilder");
            }

            if (log == null)
            {
                throw new ArgumentNullException("log");
            }

            if (uiHelper == null)
            {
                throw new ArgumentNullException("uiHelper");
            }

            _mainAppClient = mainAppClient;
            _log = log;
            _uiHelper = uiHelper;
            _sessionUpdator = KeepUpdatingSession;
            _browserWindowsManager = browserWindowsManager;
            _browserWindowsBuilder = browserWindowsBuilder;
            _updaterThread = new Thread(_sessionUpdator);
        }
Example #5
0
        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);
            }
        }
Example #6
0
        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);
            }
        }