private void App_Start(object sender, StartupEventArgs e) { if (!SingleInstance.Start()) { System.Windows.MessageBox.Show("The P99 Auction Assistant is already running."); Application.Current?.Shutdown(); return; } var launchedByWindows = e.Args.Any(arg => arg.Equals(ClientController.StartMinimizedArgumentFlag, StringComparison.CurrentCultureIgnoreCase)); //global settings IGlobalSettings _globalSettings = new GlobalSettings(); //load logging log4net.GlobalContext.Properties["StartMode"] = launchedByWindows ? "SILENT" : "USER"; LoggerConfiguration.Setup(_globalSettings); _logger = log4net.LogManager.GetLogger("P99AuctionAssistant"); //client changable settings IClientSettings _clientSettings = ClientSettings.Load(); //server communications IDataDispatcher dispatcher = new SignalRDataDispatcher(_logger, _clientSettings.ApiKey, _globalSettings.ServiceUrlBase,_globalSettings.DispatchRetryCount); //setup the logging utility try { notifyIcon = (TaskbarIcon) this.FindResource("NotifyIcon"); _balloonController = new BalloonHelper(notifyIcon); //create the controller and start the application _controller = new ClientController(_clientSettings, _globalSettings, _balloonController, _logger, dispatcher,this); _controller.ApplicationShutDownRequested += this.Controller_ApplicationShutDownRequested; //wireup the notify icon if (notifyIcon != null) notifyIcon.DataContext = _controller.NotificationModel; _controller.StartApplication(launchedByWindows); } catch (Exception ex) { if (_logger != null) { _logger.Fatal("A fatal error occured during primary execution", ex); MessageBox.Show("A fatal error occured, the Auction Assistant will now close. See the log for details.", "Fatal Error", MessageBoxButton.OK, MessageBoxImage.Error); } System.Environment.Exit(1); } }
/// <summary> /// Initializes a new instance of the <see cref="ClientController" /> class. /// </summary> /// <param name="clientSettings">The client settings.</param> /// <param name="globalSettings">The global settings.</param> /// <param name="balloonController">The balloon controller.</param> /// <param name="logger">The logger.</param> /// <param name="dataDispatcher">The data dispatcher.</param> /// <param name="viewResolver">The view resolver.</param> /// <exception cref="ArgumentNullException"> /// </exception> /// <exception cref="System.ArgumentNullException"></exception> public ClientController(IClientSettings clientSettings, IGlobalSettings globalSettings, IBalloonController balloonController, ILog logger, IDataDispatcher dataDispatcher, IViewResolver viewResolver) { if (clientSettings == null) throw new ArgumentNullException(nameof(clientSettings)); if (globalSettings == null) throw new ArgumentNullException(nameof(globalSettings)); if (balloonController == null) throw new ArgumentNullException(nameof(balloonController)); if (logger == null) throw new ArgumentNullException(nameof(logger)); if (dataDispatcher == null) throw new ArgumentNullException(nameof(dataDispatcher)); if (viewResolver == null) throw new ArgumentNullException(nameof(viewResolver)); _balloonController = balloonController; _clientSettings = clientSettings; _globalSettings = globalSettings; _viewResolver = viewResolver; _logger = logger; _dataDispatcher = dataDispatcher; //setup the view model for the notification window (sys tray) _notificationModel = new NotifyIconViewModel(); _notificationModel.ExitApplication += this.MainWindow_CloseExplicit; _notificationModel.ShowAuctionTracker += this.NotificationView_ShowAuctionTracker; //wire up the dispatcher _dataDispatcher.MessageReceived += this.MessageMonitor_MessageReceived; _dataDispatcher.StatusChanged += this.DataDispatcher_StatusChanged; //Primary window view model _trackerWindowModel = new MainWindowViewModel(); //status message switcher _uiMessageQueue = new UiMessageQueue(500); _uiMessageQueue.ActiveItemChanged += this.UiMessageQueue_ActiveItemChanged; }