Пример #1
0
        /// <summary>
        /// Translate string to <see cref="IJourneyDetailsType"/>
        /// </summary>
        /// <remarks>
        /// Currently total_vehicles isn't being used.
        /// </remarks>
        /// <param name="rawLine">raw data</param>
        /// <returns>
        /// Converted <see cref="IJourneyDetailsType"/>.
        /// </returns>
        private static IJourneyDetailsType ConvertJourney(
            string rawLine)
        {
            // {day}^t{month}^t{year}^t{journeyNumber}^t{from}^t{to}^t{via}^t{miles-chains}^t{total_vehicles}^t{number1}^t{number2}^t{number3}^t{number4}
            int         currentJourneyDay      = 0;
            int         currentJourneyMonth    = 0;
            int         currentJourneyYear     = 0;
            DateTime    currentJourneyDate     = new DateTime();
            MilesChains currentJourneyDistance = new MilesChains();

            string[] currentJourneyArray = rawLine.Split('\t');
            if (currentJourneyArray.Count() < FullJourneyStringSize)
            {
                Logger.Instance.WriteLog($"TRACE: IndividualUnitIOController - Invalid journey line: {rawLine}");
                return(null);
            }

            if (int.TryParse(currentJourneyArray[0], out currentJourneyDay))
            {
                if (int.TryParse(currentJourneyArray[1], out currentJourneyMonth))
                {
                    if (int.TryParse(currentJourneyArray[2], out currentJourneyYear))
                    {
                        currentJourneyDate =
                            new DateTime(
                                currentJourneyYear,
                                currentJourneyMonth,
                                currentJourneyDay);
                    }
                }
            }

            currentJourneyDistance.Update(currentJourneyArray[7]);

            List <string> units =
                new List <string>();

            for (int index = 9; index < currentJourneyArray.Length; ++index)
            {
                // Use add to ensure that whitespace is not added. The historical implementation
                // was to always have 4 tabs and leave whitespace where none existed. Now it only
                // uses one tab per unit.
                IndividualUnitIOController.Add(units, currentJourneyArray[index]);
            }


            return
                (new JourneyDetailsType(
                     currentJourneyDate,
                     currentJourneyArray[3],
                     currentJourneyArray[4],
                     currentJourneyArray[5],
                     currentJourneyArray[6],
                     currentJourneyDistance,
                     units));
        }
Пример #2
0
        ///// <summary>
        ///// Creates an instance of the JourneyDetailsType class.
        ///// </summary>
        ///// <param name="day">journey day</param>
        ///// <param name="month">journey month</param>
        ///// <param name="year">journey year</param>
        ///// <param name="journeyNumber">journey number</param>
        ///// <param name="from">journey from</param>
        ///// <param name="to">journey to</param>
        ///// <param name="via">journey via</param>
        ///// <param name="distance">journey distance</param>
        ///// <param name="totalVehicles">total vehicles</param>
        ///// <param name="firstNumber">first identifier</param>
        ///// <param name="secondNumber">second identifier</param>
        ///// <param name="thirdNumber">third identifier</param>
        ///// <param name="fourthNumber">fourth identifier</param>
        //public JourneyDetailsType(int day,
        //                          int month,
        //                          int year,
        //                          string      journeyNumber,
        //                          string      from,
        //                          string      to,
        //                          string      via,
        //                          MilesChains distance,
        //                          List<string> units)
        //{
        //  m_journeyDate     = new DateTime(year, month, day);
        //  m_journeyNumber   = journeyNumber;
        //  m_journeyFrom     = from;
        //  m_journeyTo       = to;
        //  m_journeyVia      = via;
        //  m_journeyDistance = distance;
        //  this.units = units;
        //}

        /// <summary>
        /// Creates an instance of the JourneyDetailsType class.
        /// </summary>
        /// <param name="journeyDetails">journey details as string</param>
        /// <param name="year">journey year</param>
        /// <param name="month">journey month</param>
        public JourneyDetailsType(string journeyDetails,
                                  int year,
                                  int month)
        {
            // {day}^t{journeyNumber}^t{from}^t{to}^t{via}^t{miles-chains}^t{total_vehicles}^t{number1}^t{number2}^t{number3}^t{number4}
            bool inputValid = true;

            string[] cells       = journeyDetails.Split('\t');
            int      day         = 0;
            int      firstNumber = 7;

            this.units = new List <string>();

            if (cells.Count() >= 8 && cells.Count() <= 11)
            {
                if (inputValid)
                {
                    if (int.TryParse(cells[0], out day))
                    {
                        m_journeyDate = new DateTime(year, month, day);
                    }
                    else
                    {
                        inputValid = false;
                    }
                }

                m_journeyNumber = cells[1];
                m_journeyFrom   = cells[2];
                m_journeyTo     = cells[3];
                m_journeyVia    = cells[4];
                m_journeyDistance.Update(cells[5]);

                //if (inputValid)
                //{
                //  if (!int.TryParse(cells[6], out m_totalVehicles))
                //  {
                //    inputValid = false;
                //  }
                //}

                if (inputValid)
                {
                    for (int index = firstNumber; index < cells.Length; ++index)
                    {
                        this.units.Add(cells[index]);
                    }
                    //m_firstNumber = cells[7];
                    //if (cells.Count() > 8)
                    //{
                    //  m_secondNumber = cells[8];
                    //  if (cells.Count() > 9)
                    //  {
                    //    m_thirdNumber = cells[9];
                    //    if (cells.Count() > 10)
                    //    {
                    //      m_fourthNumber = cells[10];
                    //    }
                    //  }
                    //}
                }
            }
            else
            {
                inputValid = false;
            }

            if (!inputValid)
            {
                m_journeyDate = new DateTime(1970, 1, 1);
                m_journeyFrom = string.Empty;
                m_journeyTo   = string.Empty;
                m_journeyVia  = string.Empty;
                m_journeyDistance.Update(0, 0);
                this.units = new List <string>();

                Logger.Instance.WriteLog("ERROR: JourneyDetailsType - failed constructor. Set everything to zero.");
            }
        }