示例#1
0
 /// <summary>
 /// Initialises a new instance of the <see cref="IndividualUnitFileContents"/> class.
 /// </summary>
 /// <param name="unitNumber">unit number</param>
 /// <param name="formerNumbers">collection of former numbers</param>
 /// <param name="inService">index of the service, see in service enumeration</param>
 /// <param name="lastCheckDate">last check date</param>
 /// <param name="journeys">journeys collection</param>
 /// <param name="notes">notes pertaining to unit</param>
 public IndividualUnitFileContents(
     string unitNumber,
     MilesChains distance,
     int entriesCount,
     IVehicleNumberType formerNumbers,
     VehicleServiceType inService,
     DateTime lastEntryDate,
     DateTime lastCheckDate,
     List <IJourneyDetailsType> journeys,
     string notes)
 {
     this.UnitNumber    = unitNumber;
     this.Distance      = distance;
     this.EntriesCount  = entriesCount;
     this.FormerNumbers = formerNumbers;
     this.InService     = inService;
     this.LastEntryDate = lastEntryDate;
     this.LastCheckDate = lastCheckDate;
     this.Journeys      = journeys;
     this.Notes         = notes;
 }
示例#2
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);
            }
        }
示例#3
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));
            }
        }