Esempio n. 1
0
        /// <date>10/003/19</date>
        /// <summary>
        /// Read the contents of a version 2 file. At the point this has been called, the
        /// first line has been read and is no longer relevant to the decoding process.
        /// The next line to be read will be the unit id.
        /// </summary>
        /// <param name="reader">the open file reader</param>
        /// <returns>contents of the file being read.</returns>
        private static IndividualUnitFileContents ReadIndividualUnitFileVersion2(
            StreamReader reader)
        {
            string currentLine = string.Empty;

            try
            {
                // {number}
                string unitNumber = reader.ReadLine();

                // {mileage}
                //currentLine = reader.ReadLine();
                MilesChains unitDistance = new MilesChains(reader.ReadLine());

                // {number_entries}
                int entriesCount =
                    IndividualUnitIOController.ConvertInteger(
                        reader.ReadLine());

                IVehicleNumberType formerNumbers =
                    IndividualUnitIOController.GetFormerNumbers(
                        reader.ReadLine());

                DateTime lastEntryDate =
                    IndividualUnitIOController.ConvertDate(
                        reader.ReadLine());
                DateTime lastCheckDate =
                    IndividualUnitIOController.ConvertDate(
                        reader.ReadLine());

                // {Status}
                VehicleServiceType inService = VehicleServiceType.InService;
                inService = IndividualUnitIOController.GetServiceStatus(reader.ReadLine());

                // {Note}
                string note = string.Empty;
                note = reader.ReadLine();

                List <IJourneyDetailsType> journeys = new List <IJourneyDetailsType>();
                currentLine = reader.ReadLine();
                while (currentLine != null)
                {
                    IJourneyDetailsType journey =
                        IndividualUnitIOController.ConvertJourney(
                            currentLine);

                    if (journey != null)
                    {
                        journeys.Add(journey);
                    }

                    currentLine = reader.ReadLine();
                }

                return(new IndividualUnitFileContents(
                           unitNumber,
                           unitDistance,
                           entriesCount,
                           formerNumbers,
                           inService,
                           lastEntryDate,
                           lastCheckDate,
                           journeys,
                           note));
            }
            catch (Exception ex)
            {
                Logger.Instance.WriteLog(
                    $"ERROR: Error reading individual unit file (ver2). Error is {ex}");

                return(null);
            }
        }
Esempio n. 2
0
        /// <date>10/003/19</date>
        /// <summary>
        /// Read the contents of a version 1 file. At the point this has been called, the
        /// first line has been read and this is the unit id.
        /// </summary>
        /// <param name="reader">the open file reader</param>
        /// <param name="firstLine">contents of the first line/unit id</param>
        /// <returns>contents of the file being read.</returns>
        private static IndividualUnitFileContents ReadIndividualUnitFileVersion1(
            StreamReader reader,
            string firstLine)
        {
            string unitNumber  = firstLine;
            string currentLine = string.Empty;

            // {mileage}
            currentLine = reader.ReadLine();
            MilesChains unitDistance = new MilesChains(currentLine);

            // {number_entries}
            int entriesCount =
                IndividualUnitIOController.ConvertInteger(
                    reader.ReadLine());

            IVehicleNumberType formerNumbers =
                IndividualUnitIOController.GetFormerNumbers(
                    reader.ReadLine());

            DateTime lastCheckDate =
                IndividualUnitIOController.ConvertDate(
                    reader.ReadLine());

            List <IJourneyDetailsType> journeys = new List <IJourneyDetailsType>();

            currentLine = reader.ReadLine();
            while (currentLine != null)
            {
                IJourneyDetailsType journey = IndividualUnitIOController.ConvertJourney(currentLine);

                if (journey != null)
                {
                    journeys.Add(journey);
                }

                currentLine = reader.ReadLine();
            }

            DateTime lastJourneyDate;
            {
                if (journeys.Count > 0)
                {
                    lastJourneyDate = journeys[journeys.Count - 1].Date;
                }
                else
                {
                    lastJourneyDate = new DateTime(1970, 1, 1);
                }

                return(new IndividualUnitFileContents(
                           unitNumber,
                           unitDistance,
                           entriesCount,
                           formerNumbers,
                           VehicleServiceType.InService,
                           lastJourneyDate,
                           lastCheckDate,
                           journeys,
                           string.Empty));
            }
        }