/// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>The object value.</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {

            double timestamp;

            switch (reader.TokenType) {

                case JsonToken.Null:
                    return objectType == typeof(DateTime) ? (object) default(DateTime) : null;

                case JsonToken.Integer:
                    timestamp = (long) reader.Value; break;

                case JsonToken.Float:
                    timestamp = (double) reader.Value; break;

                case JsonToken.String:
                    if (!Double.TryParse(reader.Value + "", out timestamp)) throw new JsonSerializationException("String value doesn't match a Unix timestamp: " + reader.Value); break;

                default:
                    throw new JsonSerializationException("Unexpected token type: " + reader.TokenType);

            }

            if (objectType == typeof(EssentialsDateTime)) return EssentialsDateTime.FromUnixTimestamp(timestamp);
            if (objectType == typeof(DateTime)) return TimeUtils.GetDateTimeFromUnixTime(timestamp);
            throw new JsonSerializationException("Object type " + objectType + " is not supported");

        }
        private FacebookDebugTokenData(JObject obj) : base(obj)
        {
            // If an access token doesn't have an expire date, it may be specified as "0". In other scenarios, the
            // property is not present at all. In either case, we should set the "ExpiresAt" property to "NULL".
            EssentialsDateTime expiresAt = null;

            if (obj.HasValue("expires_at"))
            {
                int value = obj.GetInt32("expires_at");
                if (value > 0)
                {
                    expiresAt = EssentialsDateTime.FromUnixTimestamp(value);
                }
            }

            // Parse the array of scopes
            FacebookScope[] scopes = (
                from name in obj.GetArray("scopes", x => x.ToString()) ?? new string[0]
                select FacebookScope.GetScope(name) ?? new FacebookScope(name)
                ).ToArray();

            // Populate the properties
            AppId       = obj.GetInt64("app_id");
            Application = obj.GetString("application");
            ExpiresAt   = expiresAt;
            IsValid     = obj.GetBoolean("is_valid");
            IssuedAt    = obj.HasValue("issued_at") ? obj.GetInt64("issued_at", EssentialsDateTime.FromUnixTimestamp) : null;
            UserId      = obj.GetString("user_id");
            Scopes      = scopes;
        }
 internal RedirectItem(RedirectItemRow row)
 {
     _created  = EssentialsDateTime.FromUnixTimestamp(row.Created);
     _updated  = EssentialsDateTime.FromUnixTimestamp(row.Updated);
     _linkMode = EnumUtils.ParseEnum(row.LinkMode, RedirectLinkMode.Content);
     Row       = row;
 }