/// <summary> /// Initialise a new instance of the <see cref="RouteDetailsType"/> class. /// </summary> /// <param name="input">input string based on the to string output</param> public RouteDetailsType(string input) { string[] cells = input.Split('\t'); int miles; int chains; if (cells.Count() != 6) { return; } if (!int.TryParse(cells[2], out miles)) { return; } if (!int.TryParse(cells[3], out chains)) { return; } this.from = cells[0]; this.to = cells[1]; this.distance = new MilesChains(miles, chains); this.via = cells[4]; this.key = cells[5]; }
/// <date>12/08/2018</date> /// <summary> /// Initialises a new instance of the <see cref="VehicleDetailsViewModel"/> class. /// </summary> /// <param name="rawData"> raw data, read from the file.</param> public VehicleDetailsViewModel( IndividualUnitFileContents rawData, FirstExampleManager firstExamples) { this.UnitNumber = rawData.UnitNumber; this.FormerNumbers = new VehicleNumberTypeViewModel(); this.m_lastCheckDate = rawData.LastCheckDate; this.FormerNumbers = rawData.FormerNumbers; this.Notes = rawData.Notes; foreach (IJourneyDetailsType jny in rawData.Journeys) { IJourneyViewModel journey = JourneyFactory.ToJourneyViewModel( jny, firstExamples, this.UnitNumber); this.AddJourney(journey); } this.origMilage = UnitDistance; for (int index = 0; index < this.ServiceTypeList.Count; ++index) { if (this.ServiceTypeList[index] == rawData.InService) { this.serviceIndex = index; break; } } }
/// <date>12/08/18</date> /// <summary> /// Initialises a new instance of the <see cref="VehicleDetailsViewModel"/> class. /// </summary> public VehicleDetailsViewModel(string unitNumber) { this.UnitNumber = unitNumber; this.FormerNumbers = new VehicleNumberTypeViewModel(); this.JourneysList = new List <IJourneyViewModel>(); this.origMilage = new MilesChains(); }
/// <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)); }
/// <summary> /// Initialises a new instance of the <see cref="RouteDetailsType"/> class. /// </summary> /// <param name="from">from value</param> /// <param name="to">to value</param> /// <param name="via">via value</param> /// <param name="key">key value</param> /// <param name="distance">distance value</param> public RouteDetailsType( string from, string to, string via, string key, MilesChains distance) { this.from = from; this.to = to; this.via = via; this.key = key; this.distance = distance; }
/// <summary> /// /// </summary> /// <param name="year"></param> /// <param name="month"></param> /// <returns></returns> private static List <MilesChains> SetupDays(int year, int month) { List <MilesChains> days = new List <MilesChains>(); for (int dayIndex = 1; dayIndex <= DateTime.DaysInMonth(year, month); dayIndex++) { MilesChains day = new MilesChains(); days.Add(day); } return(days); }
/// <summary> /// Creates an instance of the JourneyDetailsType class. /// </summary> /// <param name="date">journey date</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(DateTime date, string journeyNumber, string from, string to, string via, MilesChains distance, List <string> units) { m_journeyDate = date; m_journeyNumber = journeyNumber; m_journeyFrom = from; m_journeyTo = to; m_journeyVia = via; m_journeyDistance = distance; this.units = units; }
/// <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; }
/// <summary> /// Set up the graph to show distance progress. /// </summary> /// <param name="journeysList">current set of distances.</param> public void SetUpGraph(List <IJourneyViewModel> journeysList) { this.chart1.ChartAreas[0].AxisX.LineColor = ColoursDictionary.AxisColour; this.chart1.ChartAreas[0].AxisY.LineColor = ColoursDictionary.AxisColour; this.chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false; this.chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = ColoursDictionary.AxisColour; this.chart1.ChartAreas[0].AxisX.LabelStyle.ForeColor = ColoursDictionary.AxisColour; this.chart1.ChartAreas[0].AxisY.LabelStyle.ForeColor = ColoursDictionary.AxisColour; if (journeysList == null || journeysList.Count == 0) { return; } DateTime startTime = journeysList[journeysList.Count - 1].JnyId.Date.AddMonths(-1); this.graphStartTime = startTime; DateTime lastTime = journeysList[0].JnyId.Date.AddMonths(1); double lastTimeInSeconds = lastTime.Subtract(startTime).TotalSeconds; this.chart1.Series[0].Points.Clear(); this.chart1.Series[0].Points.AddXY(0, 0); MilesChains distance = new MilesChains(); for (int index = journeysList.Count - 1; index >= 0; --index) { double time = journeysList[index].JnyId.Date.Subtract(startTime).TotalSeconds; this.chart1.Series[0].Points.AddXY(time, distance.Miles); distance += journeysList[index].Distance; this.chart1.Series[0].Points.AddXY(time, distance.Miles); } this.chart1.Series[0].Points.AddXY(lastTimeInSeconds, distance.Miles); }
/// <summary> /// Initialises a new instance of the <see cref="JourneyViewModel"/> class. /// </summary> /// <param name="modelJourney"></param> /// <param name="firstExamples"></param> public JourneyViewModel( FirstExampleManager firstExamples, string parentUnit, string journeyNumber, string from, string to, string route, DateTime date, MilesChains distance, string unitOne, string unitTwo = "", string unitThree = "", string unitFour = "") { this.firstExamples = firstExamples; this.parentUnit = parentUnit; this.JnyId = new JnyId( date, journeyNumber); this.From = from; this.To = to; this.Route = route; this.Distance = distance; this.UnitOne = unitOne; this.UnitTwo = unitTwo; this.UnitThree = unitThree; this.UnitFour = unitFour; this.FromState = ComponentState.Unknown; this.ToState = ComponentState.Unknown; this.UnitOneState = ComponentState.Unknown; this.UnitTwoState = ComponentState.Unknown; this.UnitThreeState = ComponentState.Unknown; this.UnitFourState = ComponentState.Unknown; }
/// <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); } }
/// <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)); } }