Author: fmantek Date: Mon Sep 17 04:16:14 2007 New Revision: 252 Added: trunk/clients/cs/src/gphotos/picasaentry.cs trunk/clients/cs/src/gphotos/picasafeed.cs Removed: trunk/clients/cs/src/gphotos/photofeed.cs
Log: baseclasses for picasa Added: trunk/clients/cs/src/gphotos/picasaentry.cs ============================================================================== --- (empty file) +++ trunk/clients/cs/src/gphotos/picasaentry.cs Mon Sep 17 04:16:14 2007 @@ -0,0 +1,330 @@ +/* Copyright (c) 2006 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ +#define USE_TRACING + +using System; +using System.Xml; +using System.IO; +using System.Collections; +using Google.GData.Client; +using Google.GData.Extensions; +using Google.GData.Extensions.MediaRss; +using Google.GData.Extensions.Exif; +using Google.GData.Extensions.Location; + + +namespace Google.GData.Photos { + + + ////////////////////////////////////////////////////////////////////// + /// <summary> + /// Entry API customization class for defining entries in an Event feed. + /// </summary> + ////////////////////////////////////////////////////////////////////// + public class PicasaEntry : AbstractEntry + { + /// <summary> + /// Category used to label entries that contain photo extension data. + /// </summary> + public static AtomCategory PHOTO_CATEGORY = + new AtomCategory(GPhotoNameTable.PhotoKind, new AtomUri(BaseNameTable.gKind)); + + /// <summary> + /// Category used to label entries that contain photo extension data. + /// </summary> + public static AtomCategory ALBUM_CATEGORY = + new AtomCategory(GPhotoNameTable.AlbumKind, new AtomUri(BaseNameTable.gKind)); + + /// <summary> + /// Category used to label entries that contain comment extension data. + /// </summary> + public static AtomCategory COMMENT_CATEGORY = + new AtomCategory(GPhotoNameTable.CommentKind, new AtomUri(BaseNameTable.gKind)); + + /// <summary> + /// Category used to label entries that contain photo extension data. + /// </summary> + public static AtomCategory TAG_CATEGORY = + new AtomCategory(GPhotoNameTable.TagKind, new AtomUri(BaseNameTable.gKind)); + + /// <summary> + /// Constructs a new EventEntry instance with the appropriate category + /// to indicate that it is an event. + /// </summary> + public PicasaEntry() + : base() + { + Tracing.TraceMsg("Created PicasaEntry"); + GPhotoExtensions.AddExtension(this); + MediaRssExtensions.AddExtension(this); + ExifExtensions.AddExtension(this); + GeoRssExtensions.AddExtension(this); + } + + /// <summary> + /// getter/setter for the GeoRssWhere extension element + /// </summary> + public GeoRssWhere Location + { + get + { + return FindExtension(GeoNametable.GeoRssWhereElement, + GeoNametable.NSGeoRss) as GeoRssWhere; + } + set + { + ReplaceExtension(GeoNametable.GeoRssWhereElement, + GeoNametable.NSGeoRss, + value); + } + } + + /// <summary> + /// getter/setter for the ExifTags extension element + /// </summary> + public ExifTags Exif + { + get + { + return FindExtension(ExifNameTable.ExifTags, + ExifNameTable.NSExif) as ExifTags; + } + set + { + ReplaceExtension(ExifNameTable.ExifTags, + ExifNameTable.NSExif, + value); + } + } + + /// <summary> + /// returns the media:rss group container element + /// </summary> + public MediaGroup Media + { + get + { + return FindExtension(MediaRssNameTable.MediaRssGroup, + MediaRssNameTable.NSMediaRss) as MediaGroup; + } + set + { + ReplaceExtension(MediaRssNameTable.MediaRssGroup, + MediaRssNameTable.NSMediaRss, + value); + } + } + + + /// <summary> + /// casts an intance of a photoentry to access + /// </summary> + public PhotoEntry Photo + { + get + { + if (this.IsPhoto == true) + { + return (PhotoEntry) this.MemberwiseClone(); + } + return null; + } + } + + public AlbumEntry Album + { + get + { + if (this.IsAlbum == true) + { + return this.MemberwiseClone() as AlbumEntry; + } + return null; + } + } + public CommentEntry Comment + { + get + { + if (this.IsComment == true) + { + return this.MemberwiseClone() as CommentEntry; + } + return null; + } + } + + public TagEntry Tag + { + get + { + if (this.IsTag == true) + { + return this.MemberwiseClone() as TagEntry; + } + return null; + } + } + + + /// <summary> + /// instead of having 20 extension elements + /// we have one string based getter + /// usage is: entry.getPhotoExtension("albumid") to get the element + /// </summary> + /// <param name="extension">the name of the extension to look for</param> + /// <returns>SimpleElement, or NULL if the extension was not found</returns> + public SimpleElement getPhotoExtension(string extension) + { + return FindExtension(extension, GPhotoNameTable.NSGPhotos) as SimpleElement; + } + + /// <summary> + /// instead of having 20 extension elements + /// we have one string based getter + /// usage is: entry.getPhotoExtensionValue("albumid") to get the elements value + /// </summary> + /// <param name="extension">the name of the extension to look for</param> + /// <returns>value as string, or NULL if the extension was not found</returns> + public string getPhotoExtensionValue(string extension) + { + SimpleElement e = getPhotoExtension(extension); + if (e != null) + { + return e.Value; + } + return null; + } + + + + + /// <summary> + /// instead of having 20 extension elements + /// we have one string based setter + /// usage is: entry.setPhotoExtension("albumid") to set the element + /// this will create the extension if it's not there + /// note, you can ofcourse, just get an existing one and work with that + /// object: + /// SimpleElement e = entry.getPhotoExtension("albumid"); + /// e.Value = "new value"; + /// + /// or + /// entry.setPhotoExtension("albumid", "new Value"); + /// </summary> + /// <param name="extension">the name of the extension to look for</param> + /// <returns>SimpleElement, either a brand new one, or the one + /// returned by the service</returns> + public SimpleElement setPhotoExtension(string extension, string newValue) + { + if (extension == null) + { + throw new System.ArgumentNullException("extension"); + } + + SimpleElement ele = getPhotoExtension(extension); + if (ele == null) + { + ele = CreateExtension(extension, GPhotoNameTable.NSGPhotos) as SimpleElement; + this.ExtensionElements.Add(ele); + } + ele.Value = newValue; + + return ele; + } + + /// <summary> + /// returns true if the entry is a photo entry + /// </summary> + public bool IsPhoto + { + get + { + return (this.Categories.Contains(PHOTO_CATEGORY)); + } + set + { + ToggleCategory(PHOTO_CATEGORY, value); + } + } + + /// <summary> + /// returns true if the entry is a comment entry + /// </summary> + public bool IsComment + { + get + { + return (this.Categories.Contains(COMMENT_CATEGORY)); + } + set + { + ToggleCategory(COMMENT_CATEGORY, value); + } + } + + /// <summary> + /// returns true if the entry is an album entry + /// </summary> + public bool IsAlbum + { + get + { + return (this.Categories.Contains(ALBUM_CATEGORY)); + } + set + { + ToggleCategory(ALBUM_CATEGORY, value); + } + } + + /// <summary> + /// returns true if the entry is a tag entry + /// </summary> + public bool IsTag + { + get + { + return (this.Categories.Contains(TAG_CATEGORY)); + } + set + { + ToggleCategory(TAG_CATEGORY, value); + } + } + + + /// <summary> + /// helper to toggle categories + /// </summary> + /// <param name="cat"></param> + /// <param name="value"></param> + private void ToggleCategory(AtomCategory cat, bool value) + { + if (value == true) + { + if (this.Categories.Contains(cat) == false) + { + this.Categories.Add(cat); + } + } + else + { + this.Categories.Remove(cat); + } + } + } +} + Added: trunk/clients/cs/src/gphotos/picasafeed.cs ============================================================================== --- (empty file) +++ trunk/clients/cs/src/gphotos/picasafeed.cs Mon Sep 17 04:16:14 2007 @@ -0,0 +1,83 @@ +/* Copyright (c) 2006 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +using System; +using System.Collections; +using System.Text; +using System.Xml; +using Google.GData.Client; +using Google.GData.Extensions; + +namespace Google.GData.Photos { + + + ////////////////////////////////////////////////////////////////////// + /// <summary> + /// Picasa Web Albums provides a variety of representations of photo- + /// and album-related data. There are three independent axes for + /// specifying what you want when you request data: visibility, projection, and path/kind. + /// Visibility values let you request data at various levels of sharing. + /// For example, a visibility value of public requests publicly visible data. + /// For a list of values, see Visibility values, below. The default visibility + /// depends on whether the request is authenticated or not. + /// Projection values let you indicate what elements and extensions + /// should appear in the feed you're requesting. For example, a projection + /// value of base indicates that the representation is a basic Atom feed + /// without any extension elements, suitable for display in an Atom reader. + /// You must specify a projection value. Path and kind values let you indicate what + /// type of items you want information about. For example, a path of user/liz + /// and a kind value of tag requests a feed of tags associated with the + /// user whose username is liz. Path and kind values are separate parts of the + /// URI, but they're used together to indicate the item type(s) desired. + /// You must specify a path, but kind is optional; the default kind depends on the path. + /// To request a particular representation, you specify a visibility value, + /// a projection value, and a path and kind in the URI that you send + /// to Picasa Web Albums. + /// </summary> + ////////////////////////////////////////////////////////////////////// + public class PicasaFeed : AbstractFeed + { + + /// <summary> + /// default constructor + /// </summary> + /// <param name="uriBase">the base URI of the feedEntry</param> + /// <param name="iService">the Service to use</param> + public PicasaFeed(Uri uriBase, IService iService) : base(uriBase, iService) + { + GPhotoExtensions.AddExtension(this); + } + + /// <summary> + /// this needs to get implemented by subclasses + /// </summary> + /// <returns>AtomEntry</returns> + public override AtomEntry CreateFeedEntry() + { + return new PicasaEntry(); + } + + /// <summary> + /// get's called after we already handled the custom entry, to handle all + /// other potential parsing tasks + /// </summary> + /// <param name="e"></param> + /// <param name="parser">the atom feed parser used</param> + protected override void HandleExtensionElements(ExtensionElementEventArgs e, AtomFeedParser parser) + { + base.HandleExtensionElements(e, parser); + } + } +} --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Data API" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-help-dataapi?hl=en -~----------~----~----~----~------~----~------~--~---
