/// <summary> /// Parses the WTT Trips SimSig XML /// </summary> /// <param name="WTTTripsXML"></param> private void ParseTripsXML(XElement WTTTripsXML) { if (WTTTripsXML.Descendants() != null) { this.Trip = new WTTTripCollection(WTTTripsXML, this.StartDate); } }
/// <summary> /// Override method to deserialize a JSON string into a WTTTimeTableCollection /// </summary> /// <returns></returns> public override object ReadJson(JsonReader Reader, Type ObjectType, object ExistingValue, JsonSerializer Serializer) { //Validate Arguments if (Serializer == null) { throw new ArgumentNullException(ExceptionHelper.GetStaticException("GeneralNullArgument", new string[] { "Serializer" }, new System.Globalization.CultureInfo("en-GB"))); } if (Reader == null) { throw new ArgumentNullException(ExceptionHelper.GetStaticException("GeneralNullArgument", new string[] { "Reader" }, new System.Globalization.CultureInfo("en-GB"))); } //Deserialize reader into surrogate object WTTTimeTableCollectionSurrogate SurrogateTimeTableCollection = Serializer.Deserialize <WTTTimeTableCollectionSurrogate>(Reader); //Extract properties List <WTTTimeTable> TimeTables = SurrogateTimeTableCollection.TimeTables; //Instantiate new WTTTimeTableCollection WTTTimeTableCollection TimeTableCollection = new WTTTimeTableCollection(SurrogateTimeTableCollection.StartDate); //Populate the timetables and reseed WTTTripCollection Start Date foreach (WTTTimeTable TimeTable in TimeTables) { WTTTripCollection UpdatedTripCollection = new WTTTripCollection(TimeTable.StartDate); foreach (WTTTrip Trip in TimeTable.Trip) { UpdatedTripCollection.Add(Trip); } TimeTable.Trip = UpdatedTripCollection; TimeTableCollection.Add(TimeTable); } return(TimeTableCollection); }
public void WTTTripCollection_Constuctor_XElement() { string FullPath = new Uri($@"{AppDomain.CurrentDomain.BaseDirectory}Resources\TestWTT_4.8.xml").LocalPath; XElement TestTripsXML = XDocument.Load(FullPath).Element("SimSigTimetable").Element("Timetables").Elements("Timetable").Where(x => x.Element("ID").Value == "1R48").FirstOrDefault().Element("Trips"); GroundFrame.Core.Timetables.WTTTripCollection TestTripCollection = new GroundFrame.Core.Timetables.WTTTripCollection(TestTripsXML, new DateTime(2018, 7, 1)); Assert.Equal(2, TestTripCollection.Count); }
/// <summary> /// Populates the object from the supplied JSON /// </summary> /// <param name="JSON">The JSON string representing the WTTHeader object</param> private void PopulateFromJSON(string JSON) { //JSON argument will already have been validated in the constructor try { WTTTripCollection Temp = JsonConvert.DeserializeObject <WTTTripCollection>(JSON, new WTTTripCollectionConverter()); this._StartDate = Temp.StartDate; this._Trips = Temp.ToList(); } catch (Exception Ex) { throw new ApplicationException(ExceptionHelper.GetStaticException("ParseWTTTripCollectionJSONError", null, Globals.UserSettings.GetCultureInfo()), Ex); } }
/// <summary> /// Parses a WTTTimwTableSurrogate object into a WTTTimeTable Object /// </summary> /// <param name="SurrogateWTTTimeTable">The source WTTTimwTableSurrogate object</param> private void ParseSurrogateWTTTimeTable(WTTTimeTableSurrogate SurrogateWTTTimeTable) { this._StartDate = SurrogateWTTTimeTable.StartDate; this.Headcode = SurrogateWTTTimeTable.Headcode; this.UID = SurrogateWTTTimeTable.UID; this.AccelBrakeIndex = SurrogateWTTTimeTable.AccelBrakeIndex; this.RunAsRequired = SurrogateWTTTimeTable.RunAsRequired; this.RunAsRequiredPercentage = SurrogateWTTTimeTable.RunAsRequiredPercentage; if (SurrogateWTTTimeTable.Delay != null) { this.Delay = new WTTDuration(SurrogateWTTTimeTable.Delay.Seconds); } if (SurrogateWTTTimeTable.DepartTime != null) { this.DepartTime = new WTTTime(SurrogateWTTTimeTable.DepartTime.Seconds); } this.Description = SurrogateWTTTimeTable.Description; this.SeedingGap = SurrogateWTTTimeTable.SeedingGap; this.EntryPoint = SurrogateWTTTimeTable.EntryPoint; this.EntryDecision = SurrogateWTTTimeTable.EntryDecision; this.EntryChoice = SurrogateWTTTimeTable.EntryChoice; this.ActualEntryPoint = SurrogateWTTTimeTable.ActualEntryPoint; this.MaxSpeed = SurrogateWTTTimeTable.MaxSpeed; this.SpeedClass = SurrogateWTTTimeTable.SpeedClass; this.Started = SurrogateWTTTimeTable.Started; this.TrainLength = SurrogateWTTTimeTable.TrainLength; this.Electrification = SurrogateWTTTimeTable.Electrification; this.OriginName = SurrogateWTTTimeTable.OriginName; this.DestinationName = SurrogateWTTTimeTable.DestinationName; this.OriginTime = SurrogateWTTTimeTable.OriginTime; this.DestinationTime = SurrogateWTTTimeTable.DestinationTime; this.OperatorCode = SurrogateWTTTimeTable.OperatorCode; this.NonARSOnEntry = SurrogateWTTTimeTable.NonARSOnEntry; this.RunAsRequiredTested = SurrogateWTTTimeTable.RunAsRequiredTested; this.StartTraction = SurrogateWTTTimeTable.StartTraction; this.SimSigTrainCategoryID = SurrogateWTTTimeTable.SimSigTrainCategoryID; this.Trip = new WTTTripCollection(SurrogateWTTTimeTable.StartDate); foreach (WTTTrip Trip in SurrogateWTTTimeTable.Trip.ToList()) { this.Trip.Add(new WTTTrip(Trip.ToSurrogateWTTTrip())); } }
public void WTTTripCollection_Method_ToJSON() { string FullPath = new Uri($@"{AppDomain.CurrentDomain.BaseDirectory}Resources\TestWTT_4.8.xml").LocalPath; XElement TestTripsXML = XDocument.Load(FullPath).Element("SimSigTimetable").Element("Timetables").Elements("Timetable").Where(x => x.Element("ID").Value == "1R48").FirstOrDefault().Element("Trips"); GroundFrame.Core.Timetables.WTTTripCollection TestTripCollection = new GroundFrame.Core.Timetables.WTTTripCollection(TestTripsXML, new DateTime(2018, 7, 1)); Assert.Equal(2, TestTripCollection.Count); //Convert header to JSON string JSONTripCollection = TestTripCollection.ToJSON(); //Deserialize the JSON string back to an WTTHeader object GroundFrame.Core.Timetables.WTTTripCollection JSONWTTTTripCollection = new Timetables.WTTTripCollection(JSONTripCollection); Assert.Equal(2, JSONWTTTTripCollection.Count); //Check both WTTHeader objects are equal Assert.Equal(TestTripCollection.ToString(), JSONWTTTTripCollection.ToString()); Assert.Equal(TestTripCollection.StartDate, JSONWTTTTripCollection.StartDate); Assert.Equal(TestTripCollection.Count, JSONWTTTTripCollection.Count); Assert.Equal(TestTripCollection.IndexOf(0).Activities == null ? 0 : TestTripCollection.IndexOf(0).Activities.Count, JSONWTTTTripCollection.IndexOf(0).Activities == null ? 0 : JSONWTTTTripCollection.IndexOf(0).Activities.Count); }
/// <summary> /// Populates the object from the supplied JSON /// </summary> /// <param name="JSON">The JSON string representing the WTTimeTable object</param> private void PopulateFromJSON(string JSON) { //JSON argument will already have been validated in the constructor try { WTTTimeTable TempTimeTable = JsonConvert.DeserializeObject <WTTTimeTable>(JSON, new WTTTimeTableConverter()); this._StartDate = TempTimeTable.StartDate; this.Headcode = TempTimeTable.Headcode; this.UID = TempTimeTable.UID; this.AccelBrakeIndex = TempTimeTable.AccelBrakeIndex; this.RunAsRequired = TempTimeTable.RunAsRequired; this.RunAsRequiredPercentage = TempTimeTable.RunAsRequiredPercentage; this.Delay = TempTimeTable.Delay; this.DepartTime = TempTimeTable.DepartTime; this.Description = TempTimeTable.Description; this.SeedingGap = TempTimeTable.SeedingGap; this.EntryPoint = TempTimeTable.EntryPoint; this.EntryDecision = TempTimeTable.EntryDecision; this.EntryChoice = TempTimeTable.EntryChoice; this.ActualEntryPoint = TempTimeTable.ActualEntryPoint; this.MaxSpeed = TempTimeTable.MaxSpeed; this.SpeedClass = TempTimeTable.SpeedClass; this.Started = TempTimeTable.Started; this.TrainLength = TempTimeTable.TrainLength; this.Electrification = TempTimeTable.Electrification; this.OriginName = TempTimeTable.OriginName; this.DestinationName = TempTimeTable.DestinationName; this.OriginTime = TempTimeTable.OriginTime; this.DestinationTime = TempTimeTable.DestinationTime; this.OperatorCode = TempTimeTable.OperatorCode; this.NonARSOnEntry = TempTimeTable.NonARSOnEntry; this.RunAsRequiredTested = TempTimeTable.RunAsRequiredTested; this.StartTraction = TempTimeTable.StartTraction; this.SimSigTrainCategoryID = TempTimeTable.SimSigTrainCategoryID; this.Trip = TempTimeTable.Trip; } catch (Exception Ex) { throw new ApplicationException(ExceptionHelper.GetStaticException("ParseWTTTimeTableJSONError", null, Globals.UserSettings.GetCultureInfo()), Ex); } }
/// <summary> /// Override method to serialize a WTTTripCollection object to a JSON string /// </summary> /// <returns></returns> public override void WriteJson(JsonWriter Writer, object Value, JsonSerializer Serializer) { //Validate Arguments if (Serializer == null) { throw new ArgumentNullException(ExceptionHelper.GetStaticException("GeneralNullArgument", new string[] { "Serializer" }, new System.Globalization.CultureInfo("en-GB"))); } if (Writer == null) { throw new ArgumentNullException(ExceptionHelper.GetStaticException("GeneralNullArgument", new string[] { "Writer" }, new System.Globalization.CultureInfo("en-GB"))); } if (Value == null) { throw new ArgumentNullException(ExceptionHelper.GetStaticException("GeneralNullArgument", new string[] { "Value" }, new System.Globalization.CultureInfo("en-GB"))); } WTTTripCollection TripCollection = (WTTTripCollection)Value; // create the surrogate and serialize it instead // of the collection itself Serializer.Serialize(Writer, TripCollection.ToWTTTripCollectionSurrogate()); }
public void WTTTripCollection_Method_IndexOf() { string FullPath = new Uri($@"{AppDomain.CurrentDomain.BaseDirectory}Resources\TestWTT_4.8.xml").LocalPath; XElement TestTripsXML = XDocument.Load(FullPath).Element("SimSigTimetable").Element("Timetables").Elements("Timetable").Where(x => x.Element("ID").Value == "1R48").FirstOrDefault().Element("Trips"); GroundFrame.Core.Timetables.WTTTripCollection TestTripCollection = new GroundFrame.Core.Timetables.WTTTripCollection(TestTripsXML, new DateTime(2018, 7, 1)); GroundFrame.Core.Timetables.WTTTrip TestTrip = TestTripCollection.IndexOf(0); Assert.Equal(TestTripsXML.Elements("Trip").FirstOrDefault().Element("Location").Value.ToString(), TestTrip.Location); Assert.Equal(Convert.ToInt32(TestTripsXML.Elements("Trip").FirstOrDefault().Element("DepPassTime").Value.ToString()), TestTrip.DepPassTime.Seconds); if (TestTripsXML.Elements("Trip").FirstOrDefault().Element("ArrTime") == null) { Assert.Null(TestTrip.ArrTime); } else { Assert.Equal(Convert.ToInt32(TestTripsXML.Elements("Trip").FirstOrDefault().Element("ArrTime").Value.ToString()), TestTrip.ArrTime.Seconds); } if (TestTripsXML.Elements("Trip").FirstOrDefault().Element("Platform") == null) { Assert.Null(TestTrip.Platform); } else { Assert.Equal(TestTripsXML.Elements("Trip").FirstOrDefault().Element("Platform").Value.ToString(), TestTrip.Platform); } if (TestTripsXML.Elements("Trip").FirstOrDefault().Element("Line") == null) { Assert.Null(TestTrip.Line); } else { Assert.Equal(TestTripsXML.Elements("Trip").FirstOrDefault().Element("Line").Value.ToString(), TestTrip.Line); } if (TestTripsXML.Elements("Trip").FirstOrDefault().Element("Path") == null) { Assert.Null(TestTrip.Path); } else { Assert.Equal(TestTripsXML.Elements("Trip").FirstOrDefault().Element("Path").Value.ToString(), TestTrip.Path); } if (TestTripsXML.Elements("Trip").FirstOrDefault().Element("DownDirection") == null) { Assert.False(TestTrip.DownDirection); } else { Assert.Equal(Convert.ToBoolean(Convert.ToInt32(TestTripsXML.Elements("Trip").FirstOrDefault().Element("DownDirection").Value.ToString())), TestTrip.DownDirection); } if (TestTripsXML.Elements("Trip").FirstOrDefault().Element("PrevPathEndDown") == null) { Assert.False(TestTrip.PrevPathEndDown); } else { Assert.Equal(Convert.ToBoolean(Convert.ToInt32(TestTripsXML.Elements("Trip").FirstOrDefault().Element("PrevPathEndDown").Value.ToString())), TestTrip.PrevPathEndDown); } if (TestTripsXML.Elements("Trip").FirstOrDefault().Element("NextPathStartDown") == null) { Assert.False(TestTrip.NextPathStartDown); } else { Assert.Equal(Convert.ToBoolean(Convert.ToInt32(TestTripsXML.Elements("Trip").FirstOrDefault().Element("NextPathStartDown").Value.ToString())), TestTrip.NextPathStartDown); } }