Changeset 11850 for extensions/PiwigoLib/PiwigoLib
- Timestamp:
- Jul 29, 2011, 6:05:05 PM (13 years ago)
- Location:
- extensions/PiwigoLib/PiwigoLib
- Files:
-
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/PiwigoLib/PiwigoLib/DTO/Helper/PwgEnumHelper.cs
r7149 r11850 1 1 using System; 2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 2 using System.Reflection; 6 using System.ComponentModel;7 3 using System.Xml.Serialization; 8 4 … … 11 7 internal static class PwgEnumHelper<T> 12 8 { 13 internal static string stringValueOf(T value) 9 static PwgEnumHelper() 10 { 11 if (!typeof(T).IsEnum) { 12 throw new ArgumentException(String.Format("PwgEnumHelper<T>(): The type {0} is not a enum.", typeof(T).Name)); 13 } 14 } 15 16 internal static String StringValueOf(T value) 14 17 { 15 18 FieldInfo fi = value.GetType().GetField(value.ToString()); … … 25 28 } 26 29 27 internal static T enumValueOf( string value)30 internal static T enumValueOf(String value) 28 31 { 29 32 Type enumType = typeof(T); … … 31 34 foreach (T enumValue in values) 32 35 { 33 if ( stringValueOf(enumValue).Equals(value))36 if (StringValueOf(enumValue).Equals(value)) 34 37 { 35 38 return enumValue; … … 37 40 } 38 41 39 throw new ArgumentException( "The string is not a description or value of the specified enum.");42 throw new ArgumentException(String.Format("PwgEnumHelper<{0}>.enumValueOf({1}): The String is not a description or value of the specified enum.", typeof(T).Name, value)); 40 43 } 41 44 } -
extensions/PiwigoLib/PiwigoLib/DTO/PwgCategory.cs
r3834 r11850 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Text;4 3 5 4 … … 9 8 public class PwgCategory 10 9 { 10 public static Int32 RootCategoryId = 0; 11 11 12 public Int32 Id { get; set; } 12 13 public List<Int32> UpperCategoriesId { get; set; } -
extensions/PiwigoLib/PiwigoLib/DTO/PwgImage.cs
r3861 r11850 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Text;4 3 5 4 -
extensions/PiwigoLib/PiwigoLib/DTO/PwgServiceException.cs
r7150 r11850 1 1 using System; 2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 using Com.Piwigo.Lib.IService;6 2 7 3 namespace Com.Piwigo.Lib.DTO -
extensions/PiwigoLib/PiwigoLib/DTO/PwgSession.cs
r3816 r11850 1 1 using System; 2 using System.Collections.Generic;3 using System.Text;4 2 5 3 … … 18 16 public String Theme { get; set; } 19 17 public String Language { get; set; } 20 public String CharSet { get; set; } 18 public String CharSet { get; set; } 19 public String SecurityToken { get; set; } 21 20 } 22 21 } -
extensions/PiwigoLib/PiwigoLib/DTO/PwgSessionStatusEnum.cs
r3816 r11850 1 1 using System; 2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 2 using System.Xml.Serialization; 6 3 -
extensions/PiwigoLib/PiwigoLib/DTO/PwgTag.cs
r3827 r11850 1 1 using System; 2 using System.Collections.Generic;3 using System.Text;4 2 5 3 -
extensions/PiwigoLib/PiwigoLib/IService/IPwgCategoriesService.cs
r7150 r11850 4 4 public interface IPwgCategoriesService 5 5 { 6 bool AddCategory(string categoryName, int? upperCatId, ref int newId, ref string messageInfo);6 Boolean AddCategory(String categoryName, Int32? upperCatId, ref Int32 newId, ref String messageInfo); 7 7 System.Collections.Generic.List<Com.Piwigo.Lib.DTO.PwgCategory> GetAdminListOfCategory(); 8 System.Collections.Generic.List<Com.Piwigo.Lib.DTO.PwgCategory> GetListOfCategory(int? CatgeroryId, bool? Recursive, bool? PublicOnly); 9 System.Collections.Generic.List<Com.Piwigo.Lib.DTO.PwgImage> GetListOfImagesFormCategory(int categoryId, bool? recursive, int? perPage, int? Page, int? Order, int? minRate, int? maxRate, int? minHit, int? maxHit, DateTime? minDateAvailable, DateTime? maxDateAvailable, DateTime? minDateCreated, DateTime? maxDateCreated, int? minRatio, int? maxRatio, bool? withThumbnail, ref int PageReturned, ref int PerPageeReturned, ref int CountReturned); 10 bool UpdateCategoryInfo(int IdCat, string categoryName, string categoryComment); 8 System.Collections.Generic.List<Com.Piwigo.Lib.DTO.PwgCategory> GetListOfCategory(Int32? CatgeroryId, Boolean? Recursive, Boolean? PublicOnly); 9 System.Collections.Generic.List<Com.Piwigo.Lib.DTO.PwgImage> GetListOfImagesFormCategory(Int32 categoryId, Boolean? recursive, Int32? perPage, Int32? Page, Int32? Order, Int32? minRate, Int32? maxRate, Int32? minHit, Int32? maxHit, DateTime? minDateAvailable, DateTime? maxDateAvailable, DateTime? minDateCreated, DateTime? maxDateCreated, Int32? minRatio, Int32? maxRatio, Boolean? withThumbnail, ref Int32 PageReturned, ref Int32 PerPageeReturned, ref Int32 CountReturned); 10 Boolean UpdateCategoryInfo(Int32 IdCat, String categoryName, String categoryComment); 11 Boolean DeleteCategory(Int32 categoryId, String SecurityToken, Com.Piwigo.Lib.DTO.PwgCategoryPhotoDeletionModeEnum PhotoDeletionMode); 12 Boolean MoveCategory(System.Collections.Generic.List<Int32> categoriesId, Int32 parentCategoryId, String SecurityToken); 11 13 } 12 14 } -
extensions/PiwigoLib/PiwigoLib/IService/IPwgImagesService.cs
r7150 r11850 4 4 public interface IPwgImagesService 5 5 { 6 Com.Piwigo.Lib.DTO.PwgImageRate RateImage(int imageId, int imageRate); 6 Com.Piwigo.Lib.DTO.PwgImageRate RateImage(Int32 imageId, Int32 imageRate); 7 Boolean addImageByMultiPartForm(System.IO.FileInfo fileImage, Int32? imageId, Int32? categoryId, String imageName, String imageAuthor, String imageComment, Int32? imageLevel, String imageTags); 7 8 } 8 9 } -
extensions/PiwigoLib/PiwigoLib/IService/IPwgSessionService.cs
r7150 r11850 5 5 { 6 6 Com.Piwigo.Lib.DTO.PwgSession GetPwgSession(); 7 Com.Piwigo.Lib.DTO.PwgSession Login( string UserName, string Password);7 Com.Piwigo.Lib.DTO.PwgSession Login(String UserName, String Password); 8 8 Com.Piwigo.Lib.DTO.PwgSession Logout(); 9 9 } -
extensions/PiwigoLib/PiwigoLib/IService/IPwgSetupService.cs
r7150 r11850 4 4 public interface IPwgSetupService 5 5 { 6 void Setup( string PwgUserAgent, short? PwgTimeOutInSecond, Uri serverURI);6 void Setup(String PwgUserAgent, Int16? PwgTimeOutInSecond, Uri serverURI); 7 7 } 8 8 } -
extensions/PiwigoLib/PiwigoLib/IService/IPwgTagsService.cs
r7150 r11850 4 4 public interface IPwgTagsService 5 5 { 6 bool AddTag(string tagName, ref int newId, ref string messageInfo);6 Boolean AddTag(String tagName, ref Int32 newId, ref String messageInfo); 7 7 System.Collections.Generic.List<Com.Piwigo.Lib.DTO.PwgTag> GetAdminListOfTag(); 8 System.Collections.Generic.List<Com.Piwigo.Lib.DTO.PwgImage> GetListOfImagesFormTags(System.Collections.Generic.List< int> tagsId, System.Collections.Generic.List<string> tagsUrlName, System.Collections.Generic.List<string> tagsName, bool? tagModeAnd, int? perPage, int? Page, int? Order, int? minRate, int? maxRate, int? minHit, int? maxHit, DateTime? minDateAvailable, DateTime? maxDateAvailable, DateTime? minDateCreated, DateTime? maxDateCreated, int? minRatio, int? maxRatio, bool? withThumbnail, ref int PageReturned, ref int PerPageeReturned, ref intCountReturned);9 System.Collections.Generic.List<Com.Piwigo.Lib.DTO.PwgTag> GetListOfTag( bool? sortedByCounter);8 System.Collections.Generic.List<Com.Piwigo.Lib.DTO.PwgImage> GetListOfImagesFormTags(System.Collections.Generic.List<Int32> tagsId, System.Collections.Generic.List<String> tagsUrlName, System.Collections.Generic.List<String> tagsName, Boolean? tagModeAnd, Int32? perPage, Int32? Page, Int32? Order, Int32? minRate, Int32? maxRate, Int32? minHit, Int32? maxHit, DateTime? minDateAvailable, DateTime? maxDateAvailable, DateTime? minDateCreated, DateTime? maxDateCreated, Int32? minRatio, Int32? maxRatio, Boolean? withThumbnail, ref Int32 PageReturned, ref Int32 PerPageeReturned, ref Int32 CountReturned); 9 System.Collections.Generic.List<Com.Piwigo.Lib.DTO.PwgTag> GetListOfTag(Boolean? sortedByCounter); 10 10 } 11 11 } -
extensions/PiwigoLib/PiwigoLib/PiwigoLib.csproj
r7149 r11850 51 51 </ItemGroup> 52 52 <ItemGroup> 53 <Compile Include="DTO\PwgCategoryPhotoDeletionModeEnum.cs" /> 53 54 <Compile Include="DTO\PwgCategory.cs" /> 54 55 <Compile Include="DTO\PwgImage.cs" /> -
extensions/PiwigoLib/PiwigoLib/Proxy/Helper/PwgProxyReponseHelper.cs
r7149 r11850 4 4 using System.Text; 5 5 using System.Web; 6 7 using Com.Piwigo.Lib.DTO.Helper; 6 8 7 9 namespace Com.Piwigo.Lib.Proxy.Helper … … 48 50 { 49 51 String FormatString = String.Empty; 52 String ParamValue = String.Empty; 53 50 54 if (value != null) 51 55 { … … 56 60 } 57 61 58 queryStringBuilder.AppendFormat(FormatString, paramName, HttpUtility.UrlEncode(value.ToString().ToLower())); 62 if (typeof(T).IsEnum) 63 { 64 ParamValue = HttpUtility.UrlEncode(PwgEnumHelper<T>.StringValueOf(value)); 65 } 66 else 67 { 68 ParamValue = HttpUtility.UrlEncode(value.ToString().ToLower()); 69 } 70 71 queryStringBuilder.AppendFormat(FormatString, paramName, ParamValue); 72 59 73 firstOcc = false; 60 74 } -
extensions/PiwigoLib/PiwigoLib/Proxy/PwgCategoriesProxy.cs
r7149 r11850 10 10 namespace Com.Piwigo.Lib.Proxy 11 11 { 12 /// <summary> 13 /// pwg.categories.add pwg_categories_add 14 /// pwg.categories.delete pwg_categories_delete 15 /// pwg.categories.getAdminList pwg_categories_getAdminList 16 /// pwg.categories.getImages pwg_categories_getImages 17 /// pwg.categories.getList pwg_categories_getList 18 /// pwg.categories.move pwg_categories_move 19 /// pwg.categories.setInfo pwg_categories_setInfo 20 /// </summary> 12 21 static internal class PwgCategoriesProxy 13 22 { … … 200 209 201 210 /// <summary> 202 /// 203 /// </summary> 204 /// <param name="tagName"></param> 205 /// <returns></returns> 206 static internal PwgAddRequestProxyResponse pwg_tag_add(string tagName) 207 { 208 PwgAddRequestProxyResponse response = null; 209 try 210 { 211 StringBuilder data = new StringBuilder(); 212 data.Append("method=pwg.tags.add"); 213 data.Append("&name=" + HttpUtility.UrlEncode(tagName)); 214 215 response = PwgGenericProxy<PwgAddRequestProxyResponse>.Post( 216 PwgConfigProxy.PwgServeurUri, 217 data.ToString()); 218 } 219 catch (Exception ex) 220 { 221 throw new PwgProxyException("pwg_tag_add", ex); 222 } 223 224 return response; 225 } 226 211 /// pwg.categories.delete 212 /// </summary> 213 /// <param name="CategorysId"></param> 214 /// <param name="SecurityToken"></param> 215 /// <param name="PhotoDeletionMode"></param> 216 /// <returns></returns> 217 static internal PwgBaseProxyReponse pwg_categories_delete(Int32 CategoryId, 218 String SecurityToken, 219 PwgCategoryPhotoDeletionModeEnum PhotoDeletionMode) 220 { 221 PwgBaseProxyReponse response = null; 222 try 223 { 224 StringBuilder data = new StringBuilder(); 225 Boolean firstOcc = true; 226 data.Append("method=pwg.categories.delete"); 227 firstOcc = false; 228 PwgProxyReponseHelper.buildQueryFromValue<Int32>(CategoryId, "category_id", ref firstOcc, data); 229 PwgProxyReponseHelper.buildQueryFromValue<String>(SecurityToken, "pwg_token", ref firstOcc, data); 230 PwgProxyReponseHelper.buildQueryFromValue<PwgCategoryPhotoDeletionModeEnum>(PhotoDeletionMode, "photo_deletion_mode", ref firstOcc, data); 231 232 response = PwgGenericProxy<PwgBaseProxyReponse>.Post( 233 PwgConfigProxy.PwgServeurUri, 234 data.ToString()); 235 } 236 catch (Exception ex) 237 { 238 throw new PwgProxyException("pwg_categories_delete", ex); 239 } 240 241 return response; 242 } 243 244 static internal PwgBaseProxyReponse pwg_categories_move(List<Int32> CategoriesId, 245 Int32 ParentCategoryId, 246 String SecurityToken) 247 { 248 PwgBaseProxyReponse response = null; 249 try 250 { 251 StringBuilder data = new StringBuilder(); 252 Boolean firstOcc = true; 253 data.Append("method=pwg.categories.move"); 254 firstOcc = false; 255 PwgProxyReponseHelper.buildQueryFromArray<Int32>(CategoriesId, "category_id", ref firstOcc, data); 256 PwgProxyReponseHelper.buildQueryFromValue<Int32>(ParentCategoryId, "parent", ref firstOcc, data); 257 PwgProxyReponseHelper.buildQueryFromValue<String>(SecurityToken, "pwg_token", ref firstOcc, data); 258 259 response = PwgGenericProxy<PwgBaseProxyReponse>.Post( 260 PwgConfigProxy.PwgServeurUri, 261 data.ToString()); 262 } 263 catch (Exception ex) 264 { 265 throw new PwgProxyException("pwg_categories_delete", ex); 266 } 267 268 return response; 269 } 227 270 } 228 271 -
extensions/PiwigoLib/PiwigoLib/Proxy/PwgConfigProxy.cs
r7149 r11850 1 1 using System; 2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 2 using System.Net; 6 3 -
extensions/PiwigoLib/PiwigoLib/Proxy/PwgGenericProxy.cs
r7149 r11850 8 8 using System.Xml.Serialization; 9 9 using System.Xml; 10 using System.Collections.Specialized; 10 11 11 12 namespace Com.Piwigo.Lib.Proxy … … 14 15 static internal class PwgGenericProxy<T> 15 16 { 16 17 /// <summary> 18 /// Send Get data request to piwigo 19 /// </summary> 20 /// <param name="address"></param> 21 /// <param name="methodName"></param> 22 /// <param name="methodParameter"></param> 23 /// <returns></returns> 17 24 internal static T Get(Uri address, String methodName, String methodParameter) 18 25 { … … 77 84 } 78 85 86 /// <summary> 87 /// Send Post data request to piwigo 88 /// </summary> 89 /// <param name="address"></param> 90 /// <param name="data"></param> 91 /// <returns></returns> 79 92 internal static T Post(Uri address, String data) 80 93 { … … 144 157 } 145 158 159 private class MimePart 160 { 161 internal NameValueCollection Headers { get; set; } 162 internal byte[] Header { get; set; } 163 internal Stream Data { get; set; } 164 165 internal MimePart() 166 { 167 Headers = new NameValueCollection(); 168 } 169 } 170 /// <summary> 171 /// 172 /// </summary> 173 /// <param name="address">URI of server</param> 174 /// <param name="dcFiles">Dictionary(String NameOfFileFiel, String FilePath) FilePath must exist on hdd</param> 175 /// <param name="dcFields">Dictionary(String NameOfFormField, String ValueForField) others form filed to submit</param> 176 /// <returns></returns> 177 internal static T PostAsMultiPartForm(Uri address, Dictionary<String, String> dcFiles, Dictionary<String, String> dcFields) 178 { 179 List<MimePart> lstMimeParts = new List<MimePart>(); 180 T ReturnValue = default(T); 181 182 HttpWebRequest Request; 183 HttpWebResponse Response = null; 184 185 if (address == null) { throw new PwgProxyException("The get address is null."); } 186 187 try 188 { 189 // Create the web request 190 Request = WebRequest.Create(address) as HttpWebRequest; 191 Request.UserAgent = PwgConfigProxy.PwgUserAgent; 192 Request.KeepAlive = PwgConfigProxy.PwgKeepAlive; 193 Request.Timeout = PwgConfigProxy.PwgTimeOutInSecond * 1000; 194 Request.CookieContainer = PwgConfigProxy.cookieContainer; // get session cookie 195 196 // MultiPart Post Request 197 Request.ContentType = "multipart/form-data;"; 198 Request.Method = "POST"; 199 200 // Loading Mine Part data from others form fields 201 foreach (string key in dcFields.Keys) 202 { 203 MimePart part = new MimePart(); 204 part.Headers["Content-Disposition"] = "form-data; name=\"" + key + "\""; 205 part.Data = new MemoryStream(Encoding.UTF8.GetBytes(dcFields[key])); 206 lstMimeParts.Add(part); 207 } 208 209 // Loading MinePart data from form file fields 210 foreach (String strFieldName in dcFiles.Keys) 211 { 212 MimePart part = new MimePart(); 213 part.Headers["Content-Disposition"] = "form-data; name=\"" + strFieldName + "\"; filename=\"" + dcFiles[strFieldName] + "\""; 214 part.Headers["Content-Type"] = "application/octet-stream"; 215 part.Data = File.OpenRead(dcFiles[strFieldName]); // Open file for getting a stream reader on it. 216 lstMimeParts.Add(part); 217 } 218 219 string strBound = "----------" + DateTime.Now.Ticks.ToString("x"); 220 byte[] strFooter = Encoding.UTF8.GetBytes("--" + strBound + "--\r\n"); 221 Request.ContentType += " boundary=" + strBound; 222 223 long contentLength = 0; 224 foreach (MimePart part in lstMimeParts) 225 { 226 StringBuilder sb = new StringBuilder(); 227 228 sb.Append("--"); 229 sb.Append(strBound); 230 sb.AppendLine(); 231 foreach (string key in part.Headers.AllKeys) 232 { 233 sb.Append(key); 234 sb.Append(": "); 235 sb.AppendLine(part.Headers[key]); 236 } 237 sb.AppendLine(); 238 239 part.Header = Encoding.UTF8.GetBytes(sb.ToString()); 240 241 contentLength += part.Header.Length + part.Data.Length + 2; 242 243 } 244 245 Request.ContentLength = contentLength + strFooter.Length; 246 247 byte[] buffer = new byte[8192]; 248 byte[] afterFile = Encoding.UTF8.GetBytes("\r\n"); 249 int read; 250 251 using (Stream s = Request.GetRequestStream()) 252 { 253 foreach (MimePart part in lstMimeParts) 254 { 255 s.Write(part.Header, 0, part.Header.Length); 256 257 while ((read = part.Data.Read(buffer, 0, buffer.Length)) > 0) 258 s.Write(buffer, 0, read); 259 260 part.Data.Close(); 261 part.Data.Dispose(); 262 263 s.Write(afterFile, 0, afterFile.Length); 264 } 265 266 s.Write(strFooter, 0, strFooter.Length); 267 } 268 269 // Get response 270 using (Response = Request.GetResponse() as HttpWebResponse) 271 { 272 // Get the response stream 273 StreamReader reader = new StreamReader(Response.GetResponseStream()); 274 275 ReturnValue = DeserializeObject(reader); 276 } 277 } 278 catch (WebException wex) 279 { 280 // This exception will be raised if the server didn't return 200 - OK 281 // Try to retrieve more information about the network error 282 if (wex.Response != null) 283 { 284 using (HttpWebResponse ErrorResponse = (HttpWebResponse)wex.Response) 285 { 286 throw new PwgProxyException( 287 String.Format( 288 "The server returned '{0}' with the status code {1} ({2:d}).", 289 ErrorResponse.StatusDescription, ErrorResponse.StatusCode, 290 ErrorResponse.StatusCode), 291 wex); 292 } 293 } 294 } 295 catch (IOException ioex) 296 { 297 // This exception will be raised if file aren't ok on client 298 if (ioex!= null) 299 { 300 throw new PwgProxyException( 301 String.Format( 302 "A IO file exception stop the request building : {0}.", ioex.Message), 303 ioex); 304 } 305 } 306 finally 307 { 308 if (Response != null) { Response.Close(); } 309 foreach (MimePart part in lstMimeParts) 310 { 311 if (part.Data != null) 312 part.Data.Dispose(); 313 } 314 } 315 return ReturnValue; 316 } 317 318 /// <summary> 319 /// return object from xml retuned by piwigo 320 /// </summary> 321 /// <param name="xmlData"></param> 322 /// <returns></returns> 146 323 internal static T DeserializeObject(StreamReader xmlData) 147 324 { 148 325 T ReturnValue = default(T); 149 150 try 151 { 152 //Console.WriteLine(xmlData.ReadToEnd()); 153 326 String line = String.Empty; 327 try 328 { 329 #if DEBUG 330 line = xmlData.ReadToEnd(); 331 System.Diagnostics.Debug.WriteLine(line); 332 333 byte[] hexLine = System.Text.Encoding.UTF8.GetBytes(line); 334 MemoryStream m = new System.IO.MemoryStream(hexLine); 335 StreamReader xmlDat = new StreamReader(m); 336 #else 337 xmlDat = xmlData; 338 #endif 154 339 System.Xml.Serialization.XmlSerializer xsSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T)); 155 ReturnValue = (T)xsSerializer.Deserialize(xmlDat a);340 ReturnValue = (T)xsSerializer.Deserialize(xmlDat); 156 341 } 157 342 catch (Exception ex) … … 160 345 String.Format( 161 346 "The value {0} can't be deserialized in {1}, the error is {2} .", 162 xmlData, typeof(T).Name, ex.Message),347 line, typeof(T).Name, ex.Message), 163 348 ex); 164 349 } -
extensions/PiwigoLib/PiwigoLib/Proxy/PwgImagesProxy.cs
r7149 r11850 7 7 using Com.Piwigo.Lib.Proxy.Response; 8 8 using Com.Piwigo.Lib.Proxy.Helper; 9 using System.IO; 9 10 10 11 namespace Com.Piwigo.Lib.Proxy … … 12 13 static internal class PwgImagesProxy 13 14 { 15 16 /* 17 * pwg.images.add 18 * pwg.images.addChunk 19 * pwg.images.addComment 20 * pwg.images.addFile 21 * pwg.images.addSimple 22 * pwg.images.checkFiles 23 * pwg.images.checkUpload 24 * pwg.images.delete 25 * pwg.images.exist 26 * pwg.images.getInfo 27 * pwg.images.rate pwg_images_rate 28 * pwg.images.regenerateThumbnail 29 * pwg.images.search 30 * pwg.images.setInfo 31 * pwg.images.setPrivacyLevel 32 * */ 33 14 34 /// <summary> 15 35 /// pwg.images.rate … … 41 61 } 42 62 63 static internal PwgBaseProxyReponse pwg_images_addSimple(FileInfo fileImage, Int32? imageId, Int32? categoryId, String imageName, String imageAuthor, String imageComment, Int32? imageLevel, String imageTags) 64 { 65 PwgBaseProxyReponse response = null; 66 67 Dictionary<String, String> dcFiles = new Dictionary<string,string>(); 68 Dictionary<String, String> dcFields = new Dictionary<string,string>(); 69 70 try 71 { 72 dcFields.Add("method", "pwg.images.addSimple"); 73 if (imageId.HasValue) { dcFields.Add("image_id", imageId.Value.ToString()); } 74 if (categoryId.HasValue) { dcFields.Add("category", categoryId.Value.ToString()); } 75 if (imageLevel.HasValue) { dcFields.Add("level", imageLevel.Value.ToString()); } 76 if (!String.IsNullOrEmpty(imageName)) { dcFields.Add("name", imageName); } 77 if (!String.IsNullOrEmpty(imageAuthor)) { dcFields.Add("author", imageAuthor); } 78 if (!String.IsNullOrEmpty(imageComment)) { dcFields.Add("comment", imageComment); } 79 if (!String.IsNullOrEmpty(imageTags)) { dcFields.Add("tags", imageTags); } 80 81 if ((fileImage != null) && (fileImage.Exists)) 82 { 83 dcFiles.Add("image", fileImage.FullName); 84 } 85 else 86 { 87 throw new PwgProxyException("pwg_images_addSimple : no file or wrong file info provided for fileImage"); 88 } 89 90 response = PwgGenericProxy<PwgBaseProxyReponse>.PostAsMultiPartForm(PwgConfigProxy.PwgServeurUri, dcFiles, dcFields); 91 } 92 catch (Exception ex) 93 { 94 throw new PwgProxyException("pwg_images_addSimple", ex); 95 } 96 97 return response; 98 } 43 99 } 44 100 -
extensions/PiwigoLib/PiwigoLib/Proxy/PwgSessionProxy.cs
r7149 r11850 28 28 } 29 29 30 static internal PwgSessionProxyResponse pwg_session_login( string UserName, string Password)30 static internal PwgSessionProxyResponse pwg_session_login(String UserName, String Password) 31 31 { 32 32 PwgSessionProxyResponse response = null; -
extensions/PiwigoLib/PiwigoLib/Proxy/PwgTagsProxy.cs
r7149 r11850 12 12 static internal class PwgTagsProxy 13 13 { 14 /* pwg.tags.add pwg_tag_add 15 * pwg.tags.getAdminList pwg_tags_getAdminList 16 * pwg.tags.getImages pwg_tags_getImages 17 * pwg.tags.getList pwg_tags_getList 18 * */ 19 14 20 static internal PwgTagsProxyResponse pwg_tags_getList(Boolean? sortedByCounter) 15 21 { … … 108 114 109 115 } 110 static internal PwgAddRequestProxyResponse pwg_tag_add( string tagName)116 static internal PwgAddRequestProxyResponse pwg_tag_add(String tagName) 111 117 { 112 118 PwgAddRequestProxyResponse response = null; -
extensions/PiwigoLib/PiwigoLib/Proxy/Response/PwgBaseProxyReponse.cs
r7160 r11850 22 22 [Serializable()] 23 23 [XmlRoot(ElementName = "rsp")] 24 public abstractclass PwgBaseProxyReponse24 public class PwgBaseProxyReponse 25 25 { 26 26 [XmlAttribute(AttributeName="stat")] -
extensions/PiwigoLib/PiwigoLib/Proxy/Response/PwgSessionProxyResponse.cs
r7160 r11850 16 16 public String UserName { get; set; } 17 17 [XmlElement(ElementName = "status")] 18 public string Status { get; set; }18 public String Status { get; set; } 19 19 [XmlElement(ElementName = "template")] 20 20 public String Template { get; set; } … … 24 24 public String Language { get; set; } 25 25 [XmlElement(ElementName = "charset")] 26 public String CharSet { get; set; } 26 public String CharSet { get; set; } 27 [XmlElement(ElementName = "pwg_token")] 28 public String PwgToken { get; set; } 29 27 30 } 28 31 } -
extensions/PiwigoLib/PiwigoLib/Service/PwgCategoriesService.cs
r7149 r11850 264 264 return returnValue; 265 265 } 266 266 /// <summary> 267 /// Delete a category 268 /// </summary> 269 /// <param name="categoryId"></param> 270 /// <param name="SecurityToken"></param> 271 /// <param name="PhotoDeletionMode"></param> 272 /// <returns></returns> 273 public Boolean DeleteCategory(Int32 categoryId, String SecurityToken, PwgCategoryPhotoDeletionModeEnum PhotoDeletionMode) 274 { 275 Boolean returnValue = false; 276 277 try 278 { 279 if (PhotoDeletionMode == PwgCategoryPhotoDeletionModeEnum.Unknow) 280 { 281 PhotoDeletionMode = PwgCategoryPhotoDeletionModeEnum.OrphansOnly; 282 } 283 284 PwgBaseProxyReponse response = PwgCategoriesProxy.pwg_categories_delete(categoryId, SecurityToken, PhotoDeletionMode); 285 286 if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok) 287 { 288 if (response.Erreur != null) 289 { 290 throw new PwgServiceException("DeleteCategory, the server has return the error.", 291 response.Erreur.Code, 292 response.Erreur.Message); 293 } 294 else 295 { 296 throw new PwgServiceException("DeleteCategory : a error occurs during server process."); 297 } 298 } 299 else 300 { 301 returnValue = true; 302 } 303 } 304 catch (PwgProxyException ex) 305 { 306 throw new PwgServiceException("DeleteCategory : a error is raised by proxy.", ex); 307 } 308 return returnValue; 309 } 310 311 public Boolean MoveCategory(List<Int32> categoriesId, Int32 ParentCategoryId, String SecurityToken) 312 { 313 Boolean returnValue = false; 314 315 try 316 { 317 PwgBaseProxyReponse response = PwgCategoriesProxy.pwg_categories_move(categoriesId, ParentCategoryId, SecurityToken); 318 319 if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok) 320 { 321 if (response.Erreur != null) 322 { 323 throw new PwgServiceException("DeleteCategory, the server has return the error.", 324 response.Erreur.Code, 325 response.Erreur.Message); 326 } 327 else 328 { 329 throw new PwgServiceException("DeleteCategory : a error occurs during server process."); 330 } 331 } 332 else 333 { 334 returnValue = true; 335 } 336 } 337 catch (PwgProxyException ex) 338 { 339 throw new PwgServiceException("DeleteCategory : a error is raised by proxy.", ex); 340 } 341 return returnValue; 342 } 267 343 /// <summary> 268 344 /// convert response to dto object … … 301 377 returnValue.SubCategoriesCount = response.SubCategoriesCount; 302 378 303 returnValue.UpperCategoriesId = new List< int>();379 returnValue.UpperCategoriesId = new List<Int32>(); 304 380 if (response.UpperCategoryId != null) 305 381 { 306 foreach (String stringId in response.UpperCategoryId.Split(','))307 { 308 returnValue.UpperCategoriesId.Add(Int32.Parse( stringId));382 foreach (String StringId in response.UpperCategoryId.Split(',')) 383 { 384 returnValue.UpperCategoriesId.Add(Int32.Parse(StringId)); 309 385 } 310 386 } -
extensions/PiwigoLib/PiwigoLib/Service/PwgImagesService.cs
r7149 r11850 9 9 using Com.Piwigo.Lib.DTO.Helper; 10 10 using Com.Piwigo.Lib.IService; 11 using System.IO; 11 12 12 13 namespace Com.Piwigo.Lib.Service … … 44 45 { 45 46 throw new PwgServiceException("RateImage : a error is raised by proxy.", ex); 47 } 48 return returnValue; 49 } 50 51 public Boolean addImageByMultiPartForm(FileInfo fileImage, Int32? imageId, Int32? categoryId, String imageName, String imageAuthor, String imageComment, Int32? imageLevel, String imageTags) 52 { 53 Boolean returnValue = false; 54 55 try 56 { 57 PwgBaseProxyReponse response = PwgImagesProxy.pwg_images_addSimple(fileImage,imageId, categoryId, imageName, imageAuthor, imageComment, imageLevel, imageTags ); 58 59 if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok) 60 { 61 if (response.Erreur != null) 62 { 63 throw new PwgServiceException("addImageByMultiPartForm, the server has return the error.", 64 response.Erreur.Code, 65 response.Erreur.Message); 66 } 67 else 68 { 69 throw new PwgServiceException("addImageByMultiPartForm : a error occurs during server process."); 70 } 71 } 72 else 73 { 74 returnValue = true; 75 } 76 } 77 catch (PwgProxyException ex) 78 { 79 throw new PwgServiceException("addImageByMultiPartForm : a error is raised by proxy.", ex); 46 80 } 47 81 return returnValue; -
extensions/PiwigoLib/PiwigoLib/Service/PwgSessionService.cs
r7149 r11850 137 137 session.Theme = response.Theme; 138 138 session.UserName = response.UserName; 139 session.SecurityToken = response.PwgToken; 139 140 } 140 141
Note: See TracChangeset
for help on using the changeset viewer.