private void ParseDates(System.Xml.XmlReader reader) { while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "posted": DatePosted = UtilityMethods.UnixTimestampToDate(reader.Value); break; case "taken": DateTaken = UtilityMethods.ParseDateWithGranularity(reader.Value); break; case "takengranularity": DateTakenGranularity = (DateGranularity)int.Parse(reader.Value, System.Globalization.NumberFormatInfo.InvariantInfo); break; case "lastupdate": DateLastUpdated = UtilityMethods.UnixTimestampToDate(reader.Value); break; case "takenunknown": DateTakenUnknown = reader.Value == "1"; break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Read(); }
void ITwentyThreeParsable.Load(System.Xml.XmlReader reader) { reader.Read(); while (reader.LocalName != "photos") { switch (reader.LocalName) { case "firstdatetaken": FirstTakenDate = UtilityMethods.ParseDateWithGranularity(reader.ReadElementContentAsString()); break; case "firstdate": FirstDate = UtilityMethods.UnixTimestampToDate(reader.ReadElementContentAsString()); break; case "count": PhotoCount = reader.ReadElementContentAsInt(); break; case "views": Views = reader.ReadElementContentAsInt(); break; default: UtilityMethods.CheckParsingException(reader); reader.Skip(); break; } } reader.Read(); }
/// <summary> /// Protected method that does the actual initialization of the Photo instance. Should be called by subclasses of the Photo class. /// </summary> /// <param name="reader">The reader containing the XML to be parsed.</param> /// <param name="allowExtraAtrributes">Wheither to allow unknown extra attributes. /// In debug builds will throw an exception if this parameter is false and an unknown attribute is found.</param> protected void Load(XmlReader reader, bool allowExtraAtrributes) { if (reader.LocalName != "photo" && reader.LocalName != "primary_photo_extras") { UtilityMethods.CheckParsingException(reader); } while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "photo": case "id": PhotoId = reader.Value; if (string.IsNullOrEmpty(reader.Value)) { reader.Skip(); return; } break; case "owner": UserId = reader.Value; break; case "secret": Secret = reader.Value; break; case "server": Server = reader.Value; break; case "farm": Farm = reader.Value; break; case "title": Title = reader.Value; break; case "ispublic": IsPublic = reader.Value == "1"; break; case "isfamily": IsFamily = reader.Value == "1"; break; case "isfriend": IsFriend = reader.Value == "1"; break; case "tags": foreach (string tag in reader.Value.Split(' ')) { Tags.Add(tag); } break; case "datetaken": // For example : 2007-11-04 08:55:18 DateTaken = UtilityMethods.ParseDateWithGranularity(reader.Value); break; case "datetakengranularity": break; case "datetakenunknown": DateTakenUnknown = reader.Value == "1"; break; case "dateupload": DateUploaded = UtilityMethods.UnixTimestampToDate(reader.Value); break; case "license": License = (LicenseType)int.Parse(reader.Value, System.Globalization.CultureInfo.InvariantCulture); break; case "ownername": OwnerName = reader.Value; break; case "last_update": LastUpdated = UtilityMethods.UnixTimestampToDate(reader.Value); break; break; case "views": Views = int.Parse(reader.Value, System.Globalization.CultureInfo.InvariantCulture); break; case "media": Media = reader.Value; break; case "media_status": MediaStatus = reader.Value; break; case "iconserver": IconServer = reader.Value; break; case "username": OwnerName = reader.Value; break; case "isprimary": case "is_primary": break; case "dateadded": DateAddedToGroup = UtilityMethods.UnixTimestampToDate(reader.Value); break; case "date_faved": DateFavorited = UtilityMethods.UnixTimestampToDate(reader.Value); break; case "has_comment": // Gallery photos return this, but we ignore it and set GalleryPhoto.Comment instead. break; case "can_comment": CanComment = reader.Value == "1"; break; case "can_addmeta": CanAddMeta = reader.Value == "1"; break; case "can_blog": CanBlog = reader.Value == "1"; break; case "can_print": CanPrint = reader.Value == "1"; break; case "can_download": CanDownload = reader.Value == "1"; break; case "can_share": CanShare = reader.Value == "1"; break; case "geo_is_family": if (GeoPermissions == null) { GeoPermissions = new GeoPermissions(); GeoPermissions.PhotoId = PhotoId; } GeoPermissions.IsFamily = reader.Value == "1"; break; case "geo_is_friend": if (GeoPermissions == null) { GeoPermissions = new GeoPermissions(); GeoPermissions.PhotoId = PhotoId; } GeoPermissions.IsFriend = reader.Value == "1"; break; case "geo_is_public": if (GeoPermissions == null) { GeoPermissions = new GeoPermissions(); GeoPermissions.PhotoId = PhotoId; } GeoPermissions.IsPublic = reader.Value == "1"; break; case "geo_is_contact": if (GeoPermissions == null) { GeoPermissions = new GeoPermissions(); GeoPermissions.PhotoId = PhotoId; } GeoPermissions.IsContact = reader.Value == "1"; break; case "rotation": Rotation = reader.ReadContentAsInt(); break; default: if (!allowExtraAtrributes) { UtilityMethods.CheckParsingException(reader); } break; } } reader.Read(); if (reader.LocalName == "description") { Description = reader.ReadElementContentAsString(); } }