Exemple #1
0
        /// <summary>
        /// Override method to serialize a WTTTimeTableCollection 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")));
            }

            WTTTimeTableCollection TimeTableCollection = (WTTTimeTableCollection)Value;

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

            if (TimeTableCollection != null)
            {
                WTTTimeTableCollectionSurrogate SurrogateTimeTableCollection = new WTTTimeTableCollectionSurrogate()
                {
                    TimeTables = TimeTableCollection.ToList(),
                    StartDate  = TimeTableCollection.StartDate
                };

                Serializer.Serialize(Writer, SurrogateTimeTableCollection);
            }
        }
 /// <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
     {
         WTTTimeTableCollection Temp = JsonConvert.DeserializeObject <WTTTimeTableCollection>(JSON, new WTTTimeTableCollectionConverter());
         this._StartDate  = Temp.StartDate;
         this._TimeTables = Temp.ToList();
     }
     catch (Exception Ex)
     {
         throw new ApplicationException(ExceptionHelper.GetStaticException("ParseWTTTimeTableCollectionJSONError", null, Globals.UserSettings.GetCultureInfo()), Ex);
     }
 }