/// <summary> /// The run. /// </summary> /// <param name="args"> /// The args. /// </param> internal void Run(string[] args) { ExecutionParam executionParam; if (!ExecutionParam.Parse(args, AppUtil.GetLocalDataPath(this.GUI_INI_FILENAME), this.Logger, out executionParam)) { ExecutionParam.ShowHelp(); return; } this.Logger.InfoFormat("Application {0} {1} was started!", AppUtil.ProductName, AppUtil.ProductVersion); this.MuteApplicationVolume(); if (args.Length < 1 && !SingleInstance.Start()) { // Show up other instance if no parameter was specified if (MessageBox.Show( "Another instance was already running. Do you want to start a new instance ?", AppUtil.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { SingleInstance.ShowFirstInstance(); return; } } string historyFile = AppUtil.GetLocalDataPath(this.HISTORY_FILENAME); bool firstStart = !File.Exists(historyFile); if (firstStart) { Directory.CreateDirectory(AppUtil.LocalProductDataPath); File.Create(historyFile); using (var introForm = new IntroForm()) introForm.ShowDialog(); } var globalContext = WinFormGlobalContext.GetInstance(this.Logger); globalContext.SetFirstStart(firstStart); AppContext.Initialize(globalContext); MonitorEnvironment env = this.GetEnvironment(executionParam, globalContext); if (env == null) { Environment.Exit(1); } env.Logger = this.Logger; globalContext.SetEnvironment(env); var mainForm = new FlightStatisticForm(null, executionParam, true); CheckFareForm checkFareForm = null; if (executionParam != null && executionParam.OperationMode != OperationMode.Unspecified) { mainForm.Hide(); mainForm.WindowState = FormWindowState.Minimized; var controller = new CheckFareController(executionParam); checkFareForm = new CheckFareForm(executionParam); checkFareForm.Attach(controller); if (executionParam.IsMinimized) { checkFareForm.WindowState = FormWindowState.Minimized; checkFareForm.ShowInTaskbar = false; } checkFareForm.Show(); } Application.Run(mainForm); SingleInstance.Stop(); this.Logger.Info("Application stopped"); }
/// <summary> /// The attach. /// </summary> /// <param name="controller"> /// The controller. /// </param> internal void Attach(CheckFareController controller) { this._controller = controller; this._controller.View = this; this._controller.Events.MonitorStarting += this.OnMonitorStarting; this._controller.Events[OperationMode.ShowFare].RequestStarting += this.FareMonitor_RequestStarting; this._controller.Events[OperationMode.ShowFare].RequestStopping += this.FareMonitor_RequestCompleted; this._controller.Events[OperationMode.ShowFare].RequestCompleted += this.ShowFare_RequestCompleted; this._controller.Events[OperationMode.GetFareAndSave].RequestStarting += this.FareMonitor_RequestStarting; this._controller.Events[OperationMode.GetFareAndSave].RequestStopping += this.FareMonitor_RequestCompleted; this._controller.Events[OperationMode.GetFareAndSave].RequestCompleted += this.CloseAndExport_RequestCompleted; this._controller.Events[OperationMode.LiveMonitor].RequestStarting += this.LiveFare_RequestStarting; this._controller.Events[OperationMode.LiveMonitor].MonitorStopping += this.LiveFareMonitorStopping; }