Author: thomasvm
Date: 2007-01-04 01:52:40 -0500 (Thu, 04 Jan 2007)
New Revision: 70454

Modified:
   trunk/smugmug-sharp/ChangeLog
   trunk/smugmug-sharp/src/Mono.SmugMug/Album.cs
   trunk/smugmug-sharp/src/Mono.SmugMug/SmugMugUploadException.cs
   trunk/smugmug-sharp/src/Mono.SmugMug/SmugMugUtil.cs
Log:
Improve upload, fix status check

Modified: trunk/smugmug-sharp/ChangeLog
===================================================================
--- trunk/smugmug-sharp/ChangeLog       2007-01-04 06:49:41 UTC (rev 70453)
+++ trunk/smugmug-sharp/ChangeLog       2007-01-04 06:52:40 UTC (rev 70454)
@@ -1,3 +1,9 @@
+2007-01-04 Thomas Van Machelen <[EMAIL PROTECTED]>
+       * src/Mono.SmugMug/Album.cs: enhance the upload method
+       * src/Mono.SmugMug/SmugMugUtil.cs: fix the status check on the
+       returned xml
+       * src/Mono.SmugMug/SmugMugUploadException.cs: change the constructor
+
 2007-01-03 Thomas Van Machelen <[EMAIL PROTECTED]>
        * src/Mono.SmugMug/Album.cs: add some additional upload methods
        * src/Mono.SmugMug/PasswordHashConnection.cs: remove useless comment

Modified: trunk/smugmug-sharp/src/Mono.SmugMug/Album.cs
===================================================================
--- trunk/smugmug-sharp/src/Mono.SmugMug/Album.cs       2007-01-04 06:49:41 UTC 
(rev 70453)
+++ trunk/smugmug-sharp/src/Mono.SmugMug/Album.cs       2007-01-04 06:52:40 UTC 
(rev 70454)
@@ -140,42 +140,40 @@
                        if (!file.Exists)
                                throw new ArgumentException ("Image does not 
exist: " + file.FullName);
 
-                       try
-                       {
-                               WebClient client = new WebClient ();
-                               client.BaseAddress = 
"http://upload.smugmug.com";;
-                               client.Headers.Add ("Cookie:SMSESS=" + 
connection.Credentials.SessionID);
+                       string response = string.Empty;
 
-                               NameValueCollection parameters = new 
NameValueCollection ();
+                       WebClient client = new WebClient ();
+                       client.BaseAddress = "http://upload.smugmug.com";;
+                       client.Headers.Add ("Cookie:SMSESS=" + 
connection.Credentials.SessionID);
 
-                               if (caption != null && caption != string.Empty)
-                                       parameters.Add ("Caption", caption);
+                       NameValueCollection parameters = new 
NameValueCollection ();
 
-                               if (keywords != null && keywords != 
string.Empty)
-                                       parameters.Add ("Keywords", keywords);
+                       if (caption != null && caption != string.Empty)
+                               parameters.Add ("Caption", caption);
 
-                               if (filename != null && filename != 
string.Empty)
-                                       parameters.Add ("FileName", filename);
+                       if (keywords != null && keywords != string.Empty)
+                               parameters.Add ("Keywords", keywords);
 
-                               parameters.Add ("AlbumID", 
this.album_id.ToString ());
-                               parameters.Add ("ResponseType", "REST");
-                               client.QueryString = parameters;
+                       if (filename != null && filename != string.Empty)
+                               parameters.Add ("FileName", filename);
 
-                               byte[] responseArray = client.UploadFile 
("https://upload.smugmug.com/photos/xmladd.mg";, "POST", file.FullName);
-                               string response = Encoding.ASCII.GetString 
(responseArray);
+                       parameters.Add ("AlbumID", this.album_id.ToString ());
+                       parameters.Add ("ResponseType", "REST");
+                       client.QueryString = parameters;
 
-                               XmlDocument doc = new XmlDocument ();
-                               doc.LoadXml (response);
+                       byte[] responseArray = client.UploadFile 
("https://upload.smugmug.com/photos/xmladd.mg";, "POST", file.FullName);
+                       response = Encoding.ASCII.GetString (responseArray);
 
-                               Image uploaded = new Image ();
-                               uploaded.ImageID = int.Parse 
(doc.SelectSingleNode ("/rsp/ImageID").InnerText);
-                               uploaded.Connection = connection;
-                               return uploaded;
-                       }
-                       catch (Exception ex)
-                       {
-                               throw new SmugMugUploadException ("Error 
uploading image: " + file.FullName, ex.InnerException);
-                       }
+                       XmlDocument doc = new XmlDocument ();
+                       doc.LoadXml (response);
+
+                       if (doc.SelectSingleNode 
("/rsp").Attributes["stat"].Value == "failed")
+                               throw new SmugMugUploadException (string.Format 
("Failed to upload picture: {0}", path));
+
+                       Image uploaded = new Image ();
+                       uploaded.ImageID = int.Parse (doc.SelectSingleNode 
("/rsp/ImageID").InnerText);
+                       uploaded.Connection = connection;
+                       return uploaded;
                }
 
                internal static Album Create (int id, SmugMugConnection conn, 
string title, Category cat)

Modified: trunk/smugmug-sharp/src/Mono.SmugMug/SmugMugUploadException.cs
===================================================================
--- trunk/smugmug-sharp/src/Mono.SmugMug/SmugMugUploadException.cs      
2007-01-04 06:49:41 UTC (rev 70453)
+++ trunk/smugmug-sharp/src/Mono.SmugMug/SmugMugUploadException.cs      
2007-01-04 06:52:40 UTC (rev 70454)
@@ -1,10 +1,10 @@
 namespace Mono.SmugMug
 {
        public sealed class SmugMugUploadException : 
System.ApplicationException {
-               public SmugMugUploadException (string message, System.Exception 
innerException)
-                       : base (message, innerException)
+               public SmugMugUploadException (string message)
+                       : base (message)
                {
-                       System.Console.WriteLine (message, 
innerException.ToString ());
+                       System.Console.WriteLine (message); 
                }
        }
 }

Modified: trunk/smugmug-sharp/src/Mono.SmugMug/SmugMugUtil.cs
===================================================================
--- trunk/smugmug-sharp/src/Mono.SmugMug/SmugMugUtil.cs 2007-01-04 06:49:41 UTC 
(rev 70453)
+++ trunk/smugmug-sharp/src/Mono.SmugMug/SmugMugUtil.cs 2007-01-04 06:52:40 UTC 
(rev 70454)
@@ -87,7 +87,7 @@
 
                private static void CheckStatus (XmlDocument doc)
                {
-                       string status = doc.SelectSingleNode 
("/rsp").Attributes["id"].Value;
+                       string status = doc.SelectSingleNode 
("/rsp").Attributes["stat"].Value;
 
                        if (status == "ok")
                                return;

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

Reply via email to