Esempio n. 1
0
        private void LoadElements(System.Xml.XmlReader reader)
        {
            while (reader.LocalName != "photo")
            {
                switch (reader.LocalName)
                {
                case "owner":
                    ParseOwner(reader);
                    break;

                case "title":
                    Title = reader.ReadElementContentAsString();
                    break;

                case "description":
                    Description = reader.ReadElementContentAsString();
                    break;

                case "visibility":
                    ParseVisibility(reader);
                    break;

                case "permissions":
                    ParsePermissions(reader);
                    break;

                case "editability":
                    ParseEditability(reader);
                    break;

                case "publiceditability":
                    ParsePublicEditability(reader);
                    break;

                case "dates":
                    ParseDates(reader);
                    break;

                case "usage":
                    ParseUsage(reader);
                    break;

                case "comments":
                    CommentsCount = reader.ReadElementContentAsInt();
                    break;

                case "notes":
                    ParseNotes(reader);
                    break;

                case "tags":
                    ParseTags(reader);
                    break;

                case "urls":
                    ParseUrls(reader);
                    break;

                case "location":
                    Location = new PlaceInfo();
                    ((ITwentyThreeParsable)Location).Load(reader);
                    break;

                case "geoperms":
                    GeoPermissions = new GeoPermissions();
                    ((ITwentyThreeParsable)GeoPermissions).Load(reader);
                    break;

                case "people":
                    HasPeople = reader.GetAttribute("haspeople") == "1";
                    reader.Skip();
                    break;

                default:
                    UtilityMethods.CheckParsingException(reader);
                    reader.Skip();
                    break;
                }
            }

            reader.Skip();
        }
Esempio n. 2
0
        /// <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();
            }
        }