Author: stephane
Date: 2007-03-30 14:57:10 -0500 (Fri, 30 Mar 2007)
New Revision: 75233

Added:
   trunk/google-sharp/sample/tag-image.cs
Modified:
   trunk/google-sharp/ChangeLog
   trunk/google-sharp/sample/Makefile.am
   trunk/google-sharp/sample/upload-image.cs
   trunk/google-sharp/src/Mono.Google.Picasa/GDataApi.cs
   trunk/google-sharp/src/Mono.Google.Picasa/PicasaPicture.cs
Log:
2007-03-30 Stephane Delcroix <[EMAIL PROTECTED]>

        * src/Mono.Google.PicasaPicture.cs:
        * src/Mono.Google.GDataApi.cs: Adding support for picture tagging and
        a new public constructor for pictures.

        * sample/*: new tag-image.cs sample.


Modified: trunk/google-sharp/ChangeLog
===================================================================
--- trunk/google-sharp/ChangeLog        2007-03-30 19:55:56 UTC (rev 75232)
+++ trunk/google-sharp/ChangeLog        2007-03-30 19:57:10 UTC (rev 75233)
@@ -1,3 +1,11 @@
+2007-03-30 Stephane Delcroix <[EMAIL PROTECTED]>
+
+       * src/Mono.Google.PicasaPicture.cs:
+       * src/Mono.Google.GDataApi.cs: Adding support for picture tagging and
+       a new public constructor for pictures.
+
+       * sample/*: new tag-image.cs sample.
+
 2007-03-28 Stephane Delcroix <[EMAIL PROTECTED]>
 
        * configure.ac: switch to gmcs.

Modified: trunk/google-sharp/sample/Makefile.am
===================================================================
--- trunk/google-sharp/sample/Makefile.am       2007-03-30 19:55:56 UTC (rev 
75232)
+++ trunk/google-sharp/sample/Makefile.am       2007-03-30 19:57:10 UTC (rev 
75233)
@@ -1,4 +1,4 @@
-SAMPLES=list-albums.cs create-album.cs upload-image.cs
+SAMPLES=list-albums.cs create-album.cs upload-image.cs tag-image.cs
 MCSFLAGS= -debug+ -debug:full -nologo -r:Mono.Google.dll
 
 EXTRA_DIST=$(SAMPLES)

Added: trunk/google-sharp/sample/tag-image.cs
===================================================================
--- trunk/google-sharp/sample/tag-image.cs      2007-03-30 19:55:56 UTC (rev 
75232)
+++ trunk/google-sharp/sample/tag-image.cs      2007-03-30 19:57:10 UTC (rev 
75233)
@@ -0,0 +1,55 @@
+//
+// tag-image.cs
+//
+// Authors:
+//     Stephane Delcroix ([EMAIL PROTECTED])
+//
+// (C) Copyright 2007 S. Delcroix
+//
+
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Net;
+using Mono.Google;
+using Mono.Google.Picasa;
+
+class Test {
+       static void Main (string [] args)
+       {
+               string user = args [0];
+               string albumid = args [1];
+               string imageid = args [2];
+               string tag = args [3];
+               Console.Write ("Password: ");
+               string password = Console.ReadLine ();
+               if (password == null || password.Trim () == "")
+                       password = null;
+
+               ServicePointManager.CertificatePolicy = new 
NoCheckCertificatePolicy ();
+               GoogleConnection conn = new GoogleConnection 
(GoogleService.Picasa);
+               conn.Authenticate (user, password);
+               PicasaPicture picture = new PicasaPicture (conn, albumid, 
imageid);
+               Console.WriteLine ("  Image Name: {0} ID: {1}", picture.Title, 
picture.UniqueID);
+               picture.AddTag (tag);
+       }
+}
+

Modified: trunk/google-sharp/sample/upload-image.cs
===================================================================
--- trunk/google-sharp/sample/upload-image.cs   2007-03-30 19:55:56 UTC (rev 
75232)
+++ trunk/google-sharp/sample/upload-image.cs   2007-03-30 19:57:10 UTC (rev 
75233)
@@ -1,10 +1,10 @@
 //
-// list-albums.cs
+// upload-image.cs
 //
 // Authors:
-//     Gonzalo Paniagua Javier ([EMAIL PROTECTED])
+//     Stephane Delcroix ([EMAIL PROTECTED])
 //
-// (C) Copyright 2006 Novell, Inc. (http://www.novell.com)
+// (C) Copyright 2007 S. Delcroix
 //
 
 // Permission is hereby granted, free of charge, to any person obtaining

Modified: trunk/google-sharp/src/Mono.Google.Picasa/GDataApi.cs
===================================================================
--- trunk/google-sharp/src/Mono.Google.Picasa/GDataApi.cs       2007-03-30 
19:55:56 UTC (rev 75232)
+++ trunk/google-sharp/src/Mono.Google.Picasa/GDataApi.cs       2007-03-30 
19:57:10 UTC (rev 75233)
@@ -35,6 +35,7 @@
                const string gallery = "user/{userid}?kind=album";
                const string album_by_id = 
"user/{userid}/albumid/{aid}?kind=photo";
                //const string album_by_name = entry + 
"user/{userid}/album/{aname}?kind=photo";
+               const string picture_by_id = 
"user/{userid}/albumid/{aid}/photoid/{pid}";
                const string post_url = feed + "user/{userid}";
                const string post_picture = feed + 
"user/{userid}/albumid/{aid}";
                const string date_format = 
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.000Z'";
@@ -64,6 +65,16 @@
                //      return album_by_name.Replace ("{userid}", user).Replace 
("{aname}", aname);
                //}
 
+               public static string GetPictureEntry (string user, string aid, 
string pid)
+               {
+                       return entry + picture_by_id.Replace ("{userid}", 
user).Replace ("{aid}", aid).Replace ("{pid}", pid);
+               }
+
+               public static string GetPictureFeed (string user, string aid, 
string pid)
+               {
+                       return feed + picture_by_id.Replace ("{userid}", 
user).Replace ("{aid}", aid).Replace ("{pid}", pid);
+               }
+
                public static string GetPostURL (string user)
                {
                        return post_url.Replace ("{userid}", user);

Modified: trunk/google-sharp/src/Mono.Google.Picasa/PicasaPicture.cs
===================================================================
--- trunk/google-sharp/src/Mono.Google.Picasa/PicasaPicture.cs  2007-03-30 
19:55:56 UTC (rev 75232)
+++ trunk/google-sharp/src/Mono.Google.Picasa/PicasaPicture.cs  2007-03-30 
19:57:10 UTC (rev 75233)
@@ -59,6 +59,30 @@
                        ParsePicture (nodeitem, nsmgr);
                }
 
+               public PicasaPicture (GoogleConnection conn, string aid, string 
pid)
+               {
+                       if (conn == null)
+                               throw new ArgumentNullException ("conn");
+                       if (conn.User == null)
+                               throw new ArgumentException ("Need 
authentication before being used.", "conn");
+                       this.conn = conn;
+
+                       if (aid == null || aid == String.Empty)
+                               throw new ArgumentNullException ("aid");        
                
+                       this.album = new PicasaAlbum (conn, aid);
+
+                       if (pid == null || pid == String.Empty)
+                               throw new ArgumentNullException ("pid");        
                
+
+                       string received = conn.DownloadString 
(GDataApi.GetPictureEntry (conn.User, aid, pid));
+                       XmlDocument doc = new XmlDocument ();
+                       doc.LoadXml (received);
+                       XmlNamespaceManager nsmgr = new XmlNamespaceManager 
(doc.NameTable);
+                       XmlUtil.AddDefaultNamespaces (nsmgr);
+                       XmlNode entry = doc.SelectSingleNode ("atom:entry", 
nsmgr);
+                       ParsePicture (entry, nsmgr);
+               }
+
                private void ParsePicture (XmlNode nodeitem, 
XmlNamespaceManager nsmgr)
                {
                        title = nodeitem.SelectSingleNode ("atom:title", 
nsmgr).InnerText;
@@ -83,6 +107,42 @@
                        tags = nodeitem.SelectSingleNode 
("media:group/media:keywords", nsmgr).InnerText;
                }
 
+               static string GetXmlForTagging (string tag)
+               {
+                       XmlUtil xml = new XmlUtil ();
+                       xml.WriteElementString ("title", tag);
+                       xml.WriteElementStringWithAttributes ("category", null,
+                                       "scheme", 
"http://schemas.google.com/g/2005#kind";, 
+                                       "term", 
"http://schemas.google.com/photos/2007#tag";);
+                       return xml.GetDocumentString ();
+               
+               }
+
+               public void AddTag (string tag)
+               {
+                       if (tag == null)
+                               throw new ArgumentNullException ("title");
+
+                       string op_string = GetXmlForTagging (tag);
+                       byte [] op_bytes = Encoding.UTF8.GetBytes (op_string);
+                       string url = GDataApi.GetPictureFeed (conn.User, 
album.UniqueID, UniqueID);
+                       HttpWebRequest request = conn.AuthenticatedRequest 
(url);
+                       request.ContentType = "application/atom+xml; 
charset=UTF-8";
+                       request.Method = "POST";
+                       Stream output_stream = request.GetRequestStream ();
+                       output_stream.Write (op_bytes, 0, op_bytes.Length);
+                       output_stream.Close ();
+
+                       HttpWebResponse response = (HttpWebResponse) 
request.GetResponse ();
+                       string received = "";
+                       using (Stream stream = response.GetResponseStream ()) {
+                               StreamReader sr = new StreamReader (stream, 
Encoding.UTF8);
+                               received = sr.ReadToEnd ();
+                       }
+                       response.Close ();
+       
+               }
+
                public void DownloadToStream (Stream stream)
                {
                        conn.DownloadToStream (image_url, stream);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to