Beispiel #1
0
 /// <summary>
 /// Populates the object from the supplied JSON
 /// </summary>
 /// <param name="JSON">The JSON string representing the WTTTrip object</param>
 private void PopulateFromJSON(string JSON)
 {
     //JSON argument will already have been validated in the constructor
     try
     {
         WTTTrip TempTrip = JsonConvert.DeserializeObject <WTTTrip>(JSON, new WTTTripConverter());
         this._StartDate               = TempTrip.StartDate;
         this.Location                 = TempTrip.Location;
         this.DepPassTime              = TempTrip.DepPassTime;
         this.ArrTime                  = TempTrip.ArrTime;
         this.IsPassTime               = TempTrip.IsPassTime;
         this.Platform                 = TempTrip.Platform;
         this.Line                     = TempTrip.Line;
         this.Path                     = TempTrip.Path;
         this.AutoLine                 = TempTrip.AutoLine;
         this.AutoPath                 = TempTrip.AutoPath;
         this.DownDirection            = TempTrip.DownDirection;
         this.PrevPathEndDown          = TempTrip.PrevPathEndDown;
         this.NextPathStartDown        = TempTrip.NextPathStartDown;
         this.StopLocation             = TempTrip.StopLocation;
         this.DwellTime                = TempTrip.DwellTime;
         this.BerthsHere               = TempTrip.BerthsHere;
         this.AllowStopsOnThroughLines = TempTrip.AllowStopsOnThroughLines;
         this.WaitForBookedTime        = TempTrip.WaitForBookedTime;
         this.SetDownOnly              = TempTrip.SetDownOnly;
     }
     catch (Exception Ex)
     {
         throw new ApplicationException(ExceptionHelper.GetStaticException("ParseWTTTripJSONError", null, Globals.UserSettings.GetCultureInfo()), Ex);
     }
 }
        /// <summary>
        /// Override method to serialize a WTTTrip object to a JSON string
        /// </summary>
        /// <returns>void</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" }, Globals.UserSettings.GetCultureInfo()));
            }

            if (Writer == null)
            {
                throw new ArgumentNullException(ExceptionHelper.GetStaticException("GeneralNullArgument", new string[] { "Writer" }, Globals.UserSettings.GetCultureInfo()));
            }

            if (Value == null)
            {
                throw new ArgumentNullException(ExceptionHelper.GetStaticException("GeneralNullArgument", new string[] { "Value" }, Globals.UserSettings.GetCultureInfo()));
            }

            WTTTrip OldWTTTrip = (WTTTrip)Value;

            // create the surrogate and serialize it instead
            Serializer.Serialize(Writer, OldWTTTrip.ToSurrogateWTTTrip());
        }
Beispiel #3
0
        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);
            }
        }