/// <summary>
        /// Method to Get the input from the user for input file path and out put file path
        /// </summary>
        /// <param name="objFlightSummary">To encapsulate all the fields in single summary object</param>
        public static void ReadFilePath(FlightSummary objFlightSummary)
        {
            Regex regex = new Regex(@"^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)+\.(txt)$"); //Regex for checking filepath - Allowed only text document

            #region"          Reading Input File Path                      "
            Console.Write("Enter the Input File Path: ");
            objFlightSummary.strInputFilePath = _console.strInputFilePath();
            //Looping until we get the correct input
            while (!(regex.IsMatch(objFlightSummary.strInputFilePath) && File.Exists(objFlightSummary.strInputFilePath)))
            {
                Console.Write("Error!! Enter Valid Input File Path: ");
                objFlightSummary.strInputFilePath = _console.strInputFilePath();
            }
            #endregion

            #region"          Reading Output File Path                     "
            Console.Write("Enter the Output File Path: ");
            //Looping until we get the correct input
            objFlightSummary.strOutputFilePath = _console.strOutPutFilePath();
            while (!(regex.IsMatch(objFlightSummary.strOutputFilePath) && File.Exists(objFlightSummary.strOutputFilePath)
                    && objFlightSummary.strInputFilePath != objFlightSummary.strOutputFilePath))
            {
                Console.Write("Error!! Enter Valid Input File Path: ");
                objFlightSummary.strOutputFilePath = _console.strOutPutFilePath();
            }
            #endregion
        }
 /// <summary>
 /// Read the line carrying passenger data for the route details in the input file and process the data
 /// </summary>
 /// <param name="obFlightSummary"></param>
 /// <param name="passengerData"></param>
 /// <returns> true -> when the information is processed successfully</returns>
 public static bool FillPassengerData(FlightSummary obFlightSummary, string[] passengerData)
 {
     bool validLine = false;
     //There was CRLF in the description but the sample was different
     //-> So, assuming sample to be correct
     //Expected input for the passenger
     //"add" SP (general-passenger / airline-passenger / loyalty-passenger) SP first-name SP age /(SP current-loyalty-points SP using-loyalty-points SP using-extra-baggage)
     if (passengerData.Count() > 1)
     {
         switch (passengerData[1].ToLower())
         {
             case "general":
                 obFlightSummary.generalPassenger++;
                 obFlightSummary.totalBag++;
                 obFlightSummary.totalPassenger++;
                 break;
             case "airline":
                 obFlightSummary.airLinePassenger++;
                 obFlightSummary.totalBag++;
                 obFlightSummary.totalPassenger++;
                 break;
             case "loyalty":
                 obFlightSummary.loyaltyPassenger++;
                 obFlightSummary.totalBag++;
                 obFlightSummary.totalPassenger++;
                 if (Convert.ToBoolean(passengerData[5]))
                     obFlightSummary.totalLoyaltyPointsRedeemed += Convert.ToInt32(passengerData[4]);
                 if (Convert.ToBoolean(passengerData[6]))
                     obFlightSummary.totalBag++;
                 break;
         }
         validLine = true;
     }
     return validLine;
 }
 /// <summary>
 /// Heart method  which process the airline report based on the input data
 /// </summary>
 /// <param name="_Console">Wrapper for Console Read to bypass for test case execution</param>
 /// <exception cref="System.Exception">Generic Exception Catch to catch all exception</exception>
 public static void ProcessReport(ConsoleInputRetreiver _Console)
 {
     try
     {
         _console = _Console;
         FlightSummary objFlightSummary = new FlightSummary();
         ReadFilePath(objFlightSummary);
         AirPlaneReportBusinessLogic.PullReportData(objFlightSummary);
         string strOutput = string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9}",
                             objFlightSummary.totalPassenger,
                             objFlightSummary.generalPassenger,
                             objFlightSummary.airLinePassenger,
                             objFlightSummary.loyaltyPassenger,
                             objFlightSummary.totalBag,
                             objFlightSummary.totalLoyaltyPointsRedeemed,
                             objFlightSummary.totalCost,
                             objFlightSummary.ticketRevenueUnAdjusted,
                             objFlightSummary.ticetRevenueAdjusted,
                             objFlightSummary.canFlightFly.ToString().ToUpper());
         File.WriteAllText(objFlightSummary.strOutputFilePath, strOutput);
         Console.WriteLine("Successfully generated report for the given data!!");
     }
     catch (Exception ex)
     {
         Console.WriteLine("Something Went Wrong. Please close the application and try again or contact your administrator");
         if (!Directory.Exists(ConfigurationManager.AppSettings["logdirectory"]))
             Directory.CreateDirectory(ConfigurationManager.AppSettings["logdirectory"]);
         File.AppendAllText(ConfigurationManager.AppSettings["logpath"], ex.Message);
         if (_console != null)
             Console.ReadKey();
     }
 }
 /// <summary>
 /// Read the line carrying flight data for the route details in the input file and process the data
 /// </summary>
 /// <param name="obFlightSummary"></param>
 /// <param name="airCraftData"></param>
 /// <returns> true -> when the information is processed successfully</returns>
 public static bool FillAirCraftData(FlightSummary obFlightSummary, string[] airCraftData)
 {
     bool validLine = false;
     //add-aircraft = "add aircraft" SP aircraft-title SP number-of-seats CRLF
     if (airCraftData.Count() > 1)
     {
         obFlightSummary.airCraftTitle = airCraftData[2];
         obFlightSummary.noOfSeats = Convert.ToInt32(airCraftData[3]);
         validLine = true;
     }
     return validLine;
 }
        /// <summary>
        /// Read the line carrying route data for the route details in the input file and process the data
        /// </summary>
        /// <param name="obFlightSummary"></param>
        /// <param name="routeData"></param>
        /// <returns> true -> when the information is processed successfully</returns>
        public static bool FillRouteData(FlightSummary obFlightSummary, string[] routeData)
        {
            //add-route = "add route" SP origin SP destination SP cost-per-passenger SP ticket-price SP minimum-takeof-load-percentage CRLF
            bool validLine = false;
            if (routeData.Count() > 1)

            {
                obFlightSummary.origin = routeData[2];
                obFlightSummary.destination = routeData[3];
                obFlightSummary.costPerPassenger = Convert.ToInt32(routeData[4]);
                obFlightSummary.ticketPrice = Convert.ToInt32(routeData[5]);
                obFlightSummary.minimumTakeOffLoad = Convert.ToInt32(routeData[6]);
                validLine = true;
            }
            return validLine;
        }
 /// <summary>
 /// Check for the three predefined condition and calculate whether the flight can fly or not
 /// </summary>
 /// <param name="objFlightSummary"></param>
 public static void CanFlightFly(FlightSummary objFlightSummary)
 {
     objFlightSummary.canFlightFly = ((objFlightSummary.totalPassenger <= objFlightSummary.noOfSeats)
                                         && (objFlightSummary.ticetRevenueAdjusted > objFlightSummary.totalCost)
                                         && (objFlightSummary.totalPassenger / objFlightSummary.noOfSeats * 100 >= objFlightSummary.minimumTakeOffLoad));
 }
        /// <summary>
        /// Main block which generated report for the data in the given input file
        /// </summary>
        /// <param name="objFlightSummary"></param>
        public static void PullReportData(FlightSummary objFlightSummary)
        {
            using (StreamReader reader = new StreamReader(objFlightSummary.strInputFilePath))
            {
                string strLine = string.Empty;
                int counter = 0;
                bool increaseCounter = false; // Inorder to check if there is no empty line in the file
                while ((strLine = reader.ReadLine()) != null)
                {

                    strLine = strLine.Trim();
                    if (counter == 0)
                    {
                        string[] routeData = strLine.Split(new char[0]);
                        increaseCounter = FillRouteData(objFlightSummary, routeData);
                    }
                    else if (counter == 1)
                    {
                        string[] airCraftData = strLine.Split(new char[0]);
                        increaseCounter = FillAirCraftData(objFlightSummary, airCraftData);
                    }
                    else
                    {
                        string[] passengerData = strLine.Split(new char[0]);
                        increaseCounter = FillPassengerData(objFlightSummary, passengerData);
                    }
                    if (increaseCounter)
                        counter++;
                }
                objFlightSummary.totalCost = objFlightSummary.costPerPassenger*objFlightSummary.totalPassenger;
                objFlightSummary.ticketRevenueUnAdjusted = objFlightSummary.ticketPrice*objFlightSummary.totalPassenger;
                objFlightSummary.ticetRevenueAdjusted = (objFlightSummary.ticketPrice * objFlightSummary.totalPassenger) -
                                                    (objFlightSummary.airLinePassenger * objFlightSummary.ticketPrice) -
                                                    objFlightSummary.totalLoyaltyPointsRedeemed;
                CanFlightFly(objFlightSummary);
            }
        }
 public void Init()
 {
     objFlightSummary = new FlightSummary()
     {
         strInputFilePath = ConfigurationManager.AppSettings["inputfilepath"],
         strOutputFilePath = ConfigurationManager.AppSettings["outputfilepath"]
     };
     objFlightCanFly = new FlightSummary()
     {
         totalPassenger = 8,
         noOfSeats = 8,
         ticetRevenueAdjusted = 1010,
         ticketRevenueUnAdjusted = 1200,
         totalCost = 800,
         minimumTakeOffLoad = 75
     };
 }