Example #1
0
        /// <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");
        }
Example #2
0
        /// <summary>
        /// The btn summary_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void btnSummary_Click(object sender, EventArgs e)
        {
            string err = null;
            IList<TravelRoute> tabData = null;
            var tabPagesCount = this.fareBrowserTabs.TabPages.Count;

            if (tabPagesCount < 1)
            {
                err = "There is no loaded flight data. Select to show the fare first before viewing the summary!";
            }
            else
            {
                tabData = this.ExtractTabData();

                // Remove empty data set
                for (int i = 0; i < tabData.Count; i++)
                {
                    var route = tabData[i];
                    if (route.Journeys.Count < 1)
                    {
                        tabData.RemoveAt(i--);
                    }
                }

                // Set error message if there is not sufficient data for summary view
                if (tabData != null)
                {
                    if (tabData.Count < 1)
                    {
                        err = "There is no available data. Please wait until the fare browser has finished loading data!";
                    }
                    else if (tabData.Count == 1)
                    {
                        if (tabPagesCount == 1)
                        {
                            err =
                                "There is only one loaded journey. The summary view is only helpful when you have loaded multiple journeys. Try changing the travel date offsets and try again!";
                        }
                        else if (tabData[0].Journeys.Count == 1)
                        {
                            err =
                                "Only one journey has completed loading. The summary view is only helpful when you have multiple loaded journeys. Please wait until the application has finished loading another journey and try again!";
                        }
                    }
                }
            }

            if (err != null)
            {
                MessageBox.Show(this, err, "There is not enough data", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            var newParam = this._executionParam.ReflectionDeepClone(AppContext.Logger);
            int minStay = 0, maxStay = 0;
            double maxPrice = 0;
            foreach (var r in tabData)
            {
                foreach (var j in r.Journeys)
                {
                    if (j.StayDuration < minStay)
                    {
                        minStay = j.StayDuration;
                    }
                    else if (j.StayDuration > maxStay)
                    {
                        maxStay = j.StayDuration;
                    }

                    var jPrice = j.Data.Max(d => d.Flights.Max(f => f.Fares.Max(p => p.Price)));
                    if (jPrice > maxPrice)
                    {
                        maxPrice = jPrice;
                    }
                }
            }

            var priceLim = (int)Math.Ceiling(maxPrice);
            newParam.MinStayDuration = minStay;
            newParam.MaxStayDuration = maxStay;
            newParam.PriceLimit = priceLim;
            var summaryForm = new FlightStatisticForm(tabData, newParam, false);
            summaryForm.Show(this);
        }