Exemple #1
0
 /// <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);
     }
 }
        public void WTTTimeTableCollection_Method_GetByHeadCode()
        {
            string   FullPath          = new Uri($@"{AppDomain.CurrentDomain.BaseDirectory}Resources\TestWTT_4.8.xml").LocalPath;
            XElement XMLTestTimeTables = XDocument.Load(FullPath).Element("SimSigTimetable").Element("Timetables");
            XElement XMLTestTimeTable  = XMLTestTimeTables.Elements("Timetable").Where(x => x.Element("ID").Value.ToString() == "1R09").FirstOrDefault();

            GroundFrame.Core.Timetables.WTTTimeTableCollection TestTimeTableCollection = new GroundFrame.Core.Timetables.WTTTimeTableCollection(XMLTestTimeTables, new DateTime(2018, 7, 1));
            GroundFrame.Core.Timetables.WTTTimeTable           TestTimeTable           = TestTimeTableCollection.GetByHeadCode("1R09").First();
            Assert.Equal(XMLTestTimeTable.Element("ID").Value.ToString(), TestTimeTable.Headcode);
            Assert.Equal((WTTAccelBrakeIndex)Convert.ToInt32(XMLTestTimeTable.Element("AccelBrakeIndex").Value), TestTimeTable.AccelBrakeIndex);
            Assert.Equal(Convert.ToInt32(XMLTestTimeTable.Element("AsRequiredPercent").Value.ToString()), TestTimeTable.RunAsRequiredPercentage);

            if (XMLTestTimeTable.Element("DepartTime") != null)
            {
                Assert.Equal(new GroundFrame.Core.Timetables.WTTTime(Convert.ToInt32(XMLTestTimeTable.Element("DepartTime").Value.ToString())).Seconds, TestTimeTable.DepartTime.Seconds);
            }
            else
            {
                Assert.Null(TestTimeTable.DepartTime);
            }
            Assert.Equal(XMLTestTimeTable.Element("Description").Value.ToString(), TestTimeTable.Description);
            Assert.Equal(new GroundFrame.Core.Length(Convert.ToInt32(XMLTestTimeTable.Element("SeedingGap").Value.ToString())).Meters, TestTimeTable.SeedingGap.Meters);

            if (XMLTestTimeTable.Element("EntryPoint") != null)
            {
                Assert.Equal(XMLTestTimeTable.Element("EntryPoint").Value.ToString(), TestTimeTable.EntryPoint);
            }
            else
            {
                Assert.Null(TestTimeTable.EntryPoint);
            }

            Assert.Equal(new GroundFrame.Core.Timetables.WTTSpeed(Convert.ToInt32(XMLTestTimeTable.Element("MaxSpeed").Value.ToString())).MPH, TestTimeTable.MaxSpeed.MPH);
            Assert.Equal(new GroundFrame.Core.Timetables.WTTSpeedClass(Convert.ToInt32(XMLTestTimeTable.Element("SpeedClass").Value.ToString())).Bitwise, TestTimeTable.SpeedClass.Bitwise);
            Assert.Equal(new GroundFrame.Core.Length(Convert.ToInt32(XMLTestTimeTable.Element("TrainLength").Value.ToString())).Meters, TestTimeTable.TrainLength.Meters);
            Assert.Equal(new GroundFrame.Core.Electrification(XMLTestTimeTable.Element("Electrification").Value.ToString()).ToString(), TestTimeTable.Electrification.ToString());
            Assert.Equal(new GroundFrame.Core.Electrification(XMLTestTimeTable.Element("StartTraction").Value.ToString()).ToString(), TestTimeTable.StartTraction.ToString());
            Assert.Equal(XMLTestTimeTable.Element("Category").Value.ToString(), TestTimeTable.SimSigTrainCategoryID);
            Assert.Equal(XMLTestTimeTable.Element("Trips").Elements("Trip").Count(), TestTimeTable.Trip.Count());
        }
        /// <summary>
        /// Override method to serialize a WTTTimeTable 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")));
            }

            WTTTimeTable TimeTable = (WTTTimeTable)Value;

            //Create the surrogate and serialize it instead  of the collection itself

            if (TimeTable != null)
            {
                Serializer.Serialize(Writer, TimeTable.ToSurrogateWTTTimeTable());
            }
        }