Changeset 11890
- Timestamp:
- Aug 2, 2011, 4:50:49 PM (13 years ago)
- Location:
- extensions/PiwigoLib
- Files:
-
- 3 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/PiwigoLib/PiwigoLib/DTO/PwgImage.cs
r11872 r11890 42 42 public String Author { get; set; } 43 43 public Int64 ImageFileSize { get; set; } 44 public DateTime Date updateMetaData { get; set; }44 public DateTime DateUpdateMetaData { get; set; } 45 45 public Boolean hasHighDef { get; set; } 46 46 public Int64 HighDefFileSize { get; set; } 47 47 public Int32 ConfidentialLevel { get; set; } 48 public String md Sum { get; set; }48 public String md5Sum { get; set; } 49 49 public Int32 UserIdAddedBy { get; set; } 50 50 public String Name { get; set; } … … 71 71 public class PwgComment 72 72 { 73 public Int32 Id{ get; set; }73 public Int32 Id { get; set; } 74 74 public DateTime CommentDate { get; set; } 75 public String Author{ get; set; }76 public String Content{ get; set; }75 public String Author { get; set; } 76 public String Content { get; set; } 77 77 } 78 78 79 79 public class PwgImageRate 80 80 { 81 public Int32 Count { get; set; }81 public Int32 Count { get; set; } 82 82 public Double Average { get; set; } 83 83 public Double Stdev { get; set; } -
extensions/PiwigoLib/PiwigoLib/IService/IPwgImagesService.cs
r11872 r11890 9 9 Boolean DeleteImage(Int32 imageId, String SecurityToken); 10 10 Com.Piwigo.Lib.DTO.PwgImageInfo getImageInfo(Int32 imageId, Int32? commentPage, Int32? commentsPerPage); 11 Boolean addImage(System.IO.FileInfo highResFile, System.IO.FileInfo lowResFile, System.IO.FileInfo thumbFile, String imageName, String imageAuthor, DateTime creationDate, 12 String authorComment, System.Collections.Generic.List<String> lstCategories, System.Collections.Generic.List<String> lstTags, Com.Piwigo.Lib.DTO.PwgConfidentLevelEnum? confidentLevel); 11 13 } 12 14 } -
extensions/PiwigoLib/PiwigoLib/PiwigoLib.csproj
r11850 r11890 51 51 </ItemGroup> 52 52 <ItemGroup> 53 <Compile Include="DTO\PwgConfidentLevelEnum.cs" /> 54 <Compile Include="DTO\PwgFileTypeEnum.cs" /> 53 55 <Compile Include="DTO\PwgCategoryPhotoDeletionModeEnum.cs" /> 54 56 <Compile Include="DTO\PwgCategory.cs" /> … … 59 61 <Compile Include="DTO\PwgSession.cs" /> 60 62 <Compile Include="Properties\AssemblyInfo.cs" /> 63 <Compile Include="Proxy\Helper\PwgBase64Helper.cs" /> 61 64 <Compile Include="Proxy\PwgImagesProxy.cs" /> 62 65 <Compile Include="Proxy\PwgCategoriesProxy.cs" /> -
extensions/PiwigoLib/PiwigoLib/Proxy/PwgImagesProxy.cs
r11872 r11890 15 15 16 16 /* 17 * pwg.images.add 18 * pwg.images.addChunk 17 * pwg.images.add pwg_images_add 18 * pwg.images.addChunk pwg_images_addChunk 19 19 * pwg.images.addComment 20 20 * pwg.images.addFile 21 * pwg.images.addSimple pwg_images_addSimple21 * pwg.images.addSimple pwg_images_addSimple 22 22 * pwg.images.checkFiles 23 23 * pwg.images.checkUpload 24 * pwg.images.delete pwg_images_delete24 * pwg.images.delete pwg_images_delete 25 25 * pwg.images.exist 26 * pwg.images.getInfo 26 * pwg.images.getInfo pwg_images_getInfos 27 27 * pwg.images.rate pwg_images_rate 28 28 * pwg.images.regenerateThumbnail … … 31 31 * pwg.images.setPrivacyLevel 32 32 * */ 33 34 static internal PwgBaseProxyReponse pwg_images_add(String fileGuid, String thunbGuid, String HighresGuid, 35 String imageGuid, String imageFilename, String imageName, String imageAuthor, DateTime creationDate, 36 String authorComment,List<String> lstCategories, List<String> lstTags, PwgConfidentLevelEnum? confidentLevel) 37 { 38 PwgBaseProxyReponse response = null; 39 try 40 { 41 StringBuilder data = new StringBuilder(); 42 data.Append("method=pwg.images.add"); 43 Boolean firstOcc = false; 44 PwgProxyReponseHelper.buildQueryFromValue<String>(fileGuid, "file_sum", ref firstOcc, data); 45 PwgProxyReponseHelper.buildQueryFromValue<String>(thunbGuid, "thumbnail_sum", ref firstOcc, data); 46 PwgProxyReponseHelper.buildQueryFromValue<String>(HighresGuid, "high_sum", ref firstOcc, data); 47 PwgProxyReponseHelper.buildQueryFromValue<String>(imageGuid, "original_sum", ref firstOcc, data); 48 PwgProxyReponseHelper.buildQueryFromValue<String>(imageFilename, "original_filename", ref firstOcc, data); 49 PwgProxyReponseHelper.buildQueryFromValue<String>(imageName, "name", ref firstOcc, data); 50 PwgProxyReponseHelper.buildQueryFromValue<String>(imageAuthor, "author", ref firstOcc, data); 51 PwgProxyReponseHelper.buildQueryFromValue<String>(authorComment, "comment", ref firstOcc, data); 52 PwgProxyReponseHelper.buildQueryFromArray<String>(lstCategories, "categories", ref firstOcc, data); 53 PwgProxyReponseHelper.buildQueryFromArray<String>(lstTags, "tag_ids", ref firstOcc, data); 54 PwgProxyReponseHelper.buildQueryFromValue<Int32>((int?)confidentLevel, "level", ref firstOcc, data); 55 PwgProxyReponseHelper.buildQueryFromValue<DateTime>(creationDate, "date_creation", ref firstOcc, data); 56 57 response = PwgGenericProxy<PwgBaseProxyReponse>.Post( 58 PwgConfigProxy.PwgServeurUri, 59 data.ToString()); 60 } 61 catch (Exception ex) 62 { 63 throw new PwgProxyException("pwg_images_rate", ex); 64 } 65 66 return response; 67 } 68 69 /// <summary> 70 /// pwg.images.addChunk 71 /// </summary> 72 /// <param name="strb64Data"></param> 73 /// <param name="uniqueId"></param> 74 /// <param name="fileType"></param> 75 /// <param name="?"></param> 76 /// <param name="chunckNumber"></param> 77 /// <returns></returns> 78 static internal PwgBaseProxyReponse pwg_images_addChunk(String strb64Data, String uniqueId, PwgFileTypeEnum fileType, Int32 chunckNumber ) 79 { 80 PwgBaseProxyReponse response = null; 81 try 82 { 83 84 StringBuilder data = new StringBuilder(); 85 data.Append("method=pwg.images.addChunk"); 86 Boolean firstOcc = false; 87 PwgProxyReponseHelper.buildQueryFromValue<String>(strb64Data, "data", ref firstOcc, data); 88 PwgProxyReponseHelper.buildQueryFromValue<String>(uniqueId, "original_sum", ref firstOcc, data); 89 PwgProxyReponseHelper.buildQueryFromValue<PwgFileTypeEnum>(fileType, "type", ref firstOcc, data); 90 PwgProxyReponseHelper.buildQueryFromValue<Int32>(chunckNumber, "position", ref firstOcc, data); 91 92 response = PwgGenericProxy<PwgBaseProxyReponse>.Post( 93 PwgConfigProxy.PwgServeurUri, 94 data.ToString()); 95 } 96 catch (Exception ex) 97 { 98 throw new PwgProxyException("pwg_images_rate", ex); 99 } 100 101 return response; 102 } 33 103 34 104 /// <summary> -
extensions/PiwigoLib/PiwigoLib/Proxy/Response/PwgImagesProxyResponse.cs
r11872 r11890 29 29 public String Stdev { get; set; } 30 30 } 31 31 32 32 33 [Serializable()] … … 62 63 [XmlArrayItem("category")] 63 64 public PwgCategoryProxyResponse[] Categories { get; set; } 64 65 65 } 66 66 … … 75 75 [Serializable()] 76 76 [XmlRoot(ElementName = "image")] 77 public class PwgImageInfoImageProxyResponse 77 public class PwgImageInfoImageProxyResponse : PwgImageProxyResponse 78 78 { 79 [XmlAttribute(AttributeName = "id")]80 public Int32 Id { get; set; }81 [XmlAttribute(AttributeName = "width")]82 public Int32 Width { get; set; }83 [XmlAttribute(AttributeName = "height")]84 public Int32 Height { get; set; }85 [XmlAttribute(AttributeName = "file")]86 public String File { get; set; }87 [XmlAttribute(AttributeName = "tn_url")]88 public String UrlThunb { get; set; }89 [XmlAttribute(AttributeName = "element_url")]90 public String UrlElement { get; set; }91 [XmlAttribute(AttributeName = "high_url")]92 public String UrlHighDef { get; set; }93 [XmlAttribute(AttributeName = "hit")]94 public Int64 Counter { get; set; }95 [XmlAttribute(AttributeName = "date_creation")]96 public String CreatingDate { get; set; }97 [XmlAttribute(AttributeName = "date_available")]98 public String AvailableDate { get; set; }99 [XmlAttribute(AttributeName = "tn_ext")]100 79 public String ExtThumbail { get; set; } 101 80 [XmlAttribute(AttributeName = "author")] … … 112 91 public Int32 ConfidentialLevel { get; set; } 113 92 [XmlAttribute(AttributeName = "md5sum")] 114 public String md Sum { get; set; }93 public String md5Sum { get; set; } 115 94 [XmlAttribute(AttributeName = "added_by")] 116 95 public Int32 UserIdAddedBy { get; set; } … … 118 97 [XmlElement("name")] 119 98 public String Name { get; set; } 120 121 [XmlArray("tags")]122 [XmlArrayItem("tag")]123 public PwgTagProxyResponse[] Tags { get; set; }124 125 [XmlArray("categories")]126 [XmlArrayItem("category")]127 public PwgCategoryProxyResponse[] Categories { get; set; }128 99 129 100 [XmlElement("rates")] … … 134 105 135 106 [XmlElement("comment_post")] 136 public PwgPostCommentSecurityInfo PostCommen SecurityData { get; set; }107 public PwgPostCommentSecurityInfo PostCommentSecurityData { get; set; } 137 108 } 138 109 -
extensions/PiwigoLib/PiwigoLib/Service/PwgImagesService.cs
r11872 r11890 82 82 } 83 83 84 public Boolean addImage(FileInfo highResFile, FileInfo lowResFile, FileInfo thumbFile, String imageName, String imageAuthor, DateTime creationDate, 85 String authorComment, List<String> lstCategories, List<String> lstTags, PwgConfidentLevelEnum? confidentLevel) 86 { 87 Boolean returnValue = false; 88 89 try 90 { 91 String fileGuid = uploadImageByChunk(lowResFile, PwgFileTypeEnum.LowRes); 92 String thunbGuid = uploadImageByChunk(thumbFile, PwgFileTypeEnum.Thumb); 93 String HighresGuid = uploadImageByChunk(highResFile, PwgFileTypeEnum.HighDef); 94 String imageGuid = (highResFile != null ? HighresGuid : fileGuid); //Guid.NewGuid().ToString(); 95 String imageFilename = (highResFile != null ? highResFile.Name : lowResFile.Name); 96 97 PwgBaseProxyReponse response = PwgImagesProxy.pwg_images_add( fileGuid, thunbGuid, HighresGuid, 98 imageGuid, imageFilename, imageName, imageAuthor, creationDate, 99 authorComment, lstCategories, lstTags, confidentLevel); 100 101 if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok) 102 { 103 if (response.Erreur != null) 104 { 105 throw new PwgServiceException("addImage, the server has return the error.", 106 response.Erreur.Code, 107 response.Erreur.Message); 108 } 109 else 110 { 111 throw new PwgServiceException("addImage : a error occurs during server process."); 112 } 113 } 114 else 115 { 116 returnValue = true; 117 } 118 } 119 catch (PwgProxyException ex) 120 { 121 throw new PwgServiceException("addImage : a error is raised by proxy.", ex); 122 } 123 return returnValue; 124 } 125 126 public String uploadImageByChunk(FileInfo imageFile, PwgFileTypeEnum fileType) 127 { 128 byte[] buffer = new byte[5000]; 129 string strGuid = String.Empty; ; 130 int read; 131 int chunkNumber = 1; 132 133 try 134 { 135 if (imageFile != null) 136 { 137 FileStream fs = File.OpenRead(imageFile.FullName); 138 strGuid = Com.Piwigo.Lib.Proxy.Helper.PwgBase64Helper.GetphpMd5Sum(fs); 139 140 fs.Seek(0, SeekOrigin.Begin); 141 while ((read = fs.Read(buffer, 0, buffer.Length)) > 0) 142 { 143 String strB64Data = Com.Piwigo.Lib.Proxy.Helper.PwgBase64Helper.base64Encode(buffer); 144 PwgBaseProxyReponse response = PwgImagesProxy.pwg_images_addChunk(strB64Data, strGuid, fileType, chunkNumber); 145 146 chunkNumber += 1; 147 148 if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok) 149 { 150 if (response.Erreur != null) 151 { 152 throw new PwgServiceException("uploadImageByChunk, the server has return the error.", 153 response.Erreur.Code, 154 response.Erreur.Message); 155 } 156 else 157 { 158 throw new PwgServiceException("uploadImageByChunk : a error occurs during server process."); 159 } 160 } 161 } 162 } 163 else 164 { 165 strGuid = String.Empty; 166 } 167 } 168 catch (PwgProxyException ex) 169 { 170 throw new PwgServiceException("uploadImageByChunk : a error is raised by proxy.", ex); 171 } 172 return strGuid; 173 } 174 175 /// <summary> 176 /// Delete a image 177 /// </summary> 178 /// <param name="imageId"></param> 179 /// <param name="SecurityToken"></param> 180 /// <returns></returns> 84 181 public Boolean DeleteImage(Int32 imageId, String SecurityToken) 85 182 { … … 139 236 else 140 237 { 141 //returnValue = ConvertProxyResponseToDTO(response);238 returnValue = ConvertProxyResponseToDTO(response.ImageInfo); 142 239 } 143 240 } … … 148 245 return returnValue; 149 246 } 247 150 248 /// <summary> 151 249 /// private: convert response to dto object … … 234 332 } 235 333 } 334 } 335 336 /// <summary> 337 /// private: convert response to dto object 338 /// </summary> 339 /// <param name="response"></param> 340 /// <param name="session"></param> 341 internal static PwgImageInfo ConvertProxyResponseToDTO(PwgImageInfoImageProxyResponse response) 342 { 343 PwgImageInfo returnValue = null; 344 345 try 346 { 347 PwgImage pwgImg = ConvertProxyResponseToDTO(response as PwgImageProxyResponse as PwgImageProxyResponse); 348 returnValue = new PwgImageInfo(){ Id = pwgImg.Id, 349 Width = pwgImg.Width, 350 Height = pwgImg.Height, 351 File = pwgImg.File , 352 UrlThunb = pwgImg.UrlThunb, 353 UrlElement = pwgImg.UrlElement, 354 UrlHighDef = pwgImg.UrlHighDef, 355 Counter = pwgImg.Counter, 356 CreatingDate = pwgImg.CreatingDate, 357 AvailableDate= pwgImg.AvailableDate, 358 Tags = pwgImg.Tags, 359 Categories = pwgImg.Categories}; 360 361 returnValue.ExtThumbail = response.ExtThumbail ; 362 returnValue.Author = response.Author ; 363 returnValue.ImageFileSize = response.ImageFileSize ; 364 returnValue.hasHighDef = response.hasHighDef ; 365 returnValue.HighDefFileSize = response.HighDefFileSize ; 366 returnValue.ConfidentialLevel = response.ConfidentialLevel ; 367 returnValue.md5Sum = response.md5Sum ; 368 returnValue.UserIdAddedBy = response.UserIdAddedBy ; 369 returnValue.Name = response.Name ; 370 371 if (response.DateUpdateMetaData != null) 372 { 373 DateTime tryDate; 374 if (DateTime.TryParse(response.DateUpdateMetaData, out tryDate)) 375 { 376 returnValue.DateUpdateMetaData = tryDate; 377 } 378 } 379 380 if (response.ImageRate != null) 381 { 382 returnValue.ImageRate = ConvertProxyResponseToDTO(response.ImageRate); 383 } 384 if (response.ImageComments != null) 385 { 386 returnValue.ImageComments = ConvertProxyResponseToDTO(response.ImageComments); 387 } 388 if (response.PostCommentSecurityData != null) 389 { 390 returnValue.PostCommenSecurityData = ConvertProxyResponseToDTO(response.PostCommentSecurityData); 391 } 392 } 393 catch (Exception ex) 394 { 395 throw new PwgServiceException("ConvertProxyResponseToDTO : a error is raised when converting PwgTagProxyResponse.", ex); 396 } 397 398 return returnValue; 399 } 400 401 /// <summary> 402 /// private: convert response to dto object 403 /// </summary> 404 /// <param name="response"></param> 405 /// <param name="session"></param> 406 internal static PwgPostCommentSecurityInfo ConvertProxyResponseToDTO(PwgPostCommentSecurityInfo response) 407 { 408 PwgPostCommentSecurityInfo returnValue = new PwgPostCommentSecurityInfo(); 409 410 returnValue.Author = response.Author; 411 returnValue.AllowPostKey = response.AllowPostKey; 412 413 return returnValue; 414 } 415 416 /// <summary> 417 /// private: convert response to dto object 418 /// </summary> 419 /// <param name="response"></param> 420 /// <param name="session"></param> 421 internal static PwgCommentPage ConvertProxyResponseToDTO(PwgCommentPageProxyResponse response) 422 { 423 PwgCommentPage returnValue = new PwgCommentPage(); 424 425 returnValue.Page = response.Page; 426 returnValue.PerPage = response.PerPage; 427 returnValue.CountOf = response.CountOf; 428 returnValue.TotalCommentNumber = response.TotalCommentNumber; 429 430 //PwgCommentPage inherit List<PwgComment> 431 if (response.Comments != null) 432 { 433 foreach (PwgCommentProxyResponse respComment in response.Comments) 434 { 435 PwgComment pwgCom = ConvertProxyResponseToDTO(respComment); 436 if (pwgCom != null) 437 { 438 returnValue.Add(pwgCom); 439 } 440 } 441 } 442 443 return returnValue; 444 } 445 446 /// <summary> 447 /// private: convert response to dto object 448 /// </summary> 449 /// <param name="response"></param> 450 /// <param name="session"></param> 451 internal static PwgComment ConvertProxyResponseToDTO(PwgCommentProxyResponse response) 452 { 453 PwgComment returnValue = new PwgComment(); 454 455 returnValue.Id = response.Id; 456 returnValue.CommentDate = response.CommentDate; 457 returnValue.Author = response.Author; 458 returnValue.Content = response.Content; 459 460 return returnValue; 236 461 } 237 462 -
extensions/PiwigoLib/TestPiwigoLib/Form1.cs
r11872 r11890 46 46 //List<PwgTag> lstTag = PwgServiceProvider.Instance.PwgTagsService.GetAdminListOfTag(); 47 47 48 //Int32 Page = 0;49 //Int32 PerPage = 0;50 //Int32 Count = 0;48 Int32 Page = 0; 49 Int32 PerPage = 0; 50 Int32 Count = 0; 51 51 52 //List<PwgImage> lstImgTag = PwgServiceProvider.Instance.PwgTagsService.GetListOfImagesFormTags(new List<Int32>() { 1, 7 },53 //null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,54 //ref Page, ref PerPage, ref Count);52 List<PwgImage> lstImgTag = PwgServiceProvider.Instance.PwgTagsService.GetListOfImagesFormTags(new List<Int32>() { 1, 7 }, 53 null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 54 ref Page, ref PerPage, ref Count); 55 55 56 //List<PwgImage> lstImgCat = PwgServiceProvider.Instance.PwgCategoriesService.GetListOfImagesFormCategory(1,57 //null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,58 //ref Page, ref PerPage, ref Count);56 List<PwgImage> lstImgCat = PwgServiceProvider.Instance.PwgCategoriesService.GetListOfImagesFormCategory(1, 57 null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 58 ref Page, ref PerPage, ref Count); 59 59 60 60 //Console.WriteLine("lstImg : Page " + Page.ToString() + " PerPage " + PerPage); … … 74 74 //lstCat = PwgServiceProvider.Instance.PwgCategoriesService.GetAdminListOfCategory(); 75 75 76 //FileInfo fi = new FileInfo("C:\\Users\\bayral\\Downloads\\49133_1636405570_2648232_n.jpg"); 77 //PwgImageAdded imgAdd = PwgServiceProvider.Instance.PwgImagesService.addImageByMultiPartForm(fi, null, 1, "benoit", "byarl", "test upload", 0, new List<PwgTag>() { new PwgTag() { Name = "Benoit" }, new PwgTag() { Name = "Noé" } }); 76 FileInfo fiBig = new FileInfo("C:\\Users\\bayral\\Downloads\\49133_1636405570_2648232_n.jpg"); 77 FileInfo fiThumb = new FileInfo(MakeThumb(fiBig,"C:\\Users\\bayral\\Downloads\\49133_1636405570_2648232_n_thum.jpg",64)); 78 FileInfo fiLow = new FileInfo(MakeThumb(fiBig,"C:\\Users\\bayral\\Downloads\\49133_1636405570_2648232_n_low.jpg",256)); 78 79 79 rc = PwgServiceProvider.Instance.PwgImagesService.DeleteImage(319, sess.SecurityToken); 80 //PwgImageAdded imgAdd = PwgServiceProvider.Instance.PwgImagesService.addImageByMultiPartForm(fiBig, null, 1, "benoit", "byarl", "test upload", 0, new List<PwgTag>() { new PwgTag() { Name = "Benoit" }, new PwgTag() { Name = "Noé" } }); 81 rc = PwgServiceProvider.Instance.PwgImagesService.addImage(fiBig, fiLow, fiThumb, "Benoit", "bayral", DateTime.Now, "demo", null, null, PwgConfidentLevelEnum.All); 82 //rc = PwgServiceProvider.Instance.PwgImagesService.DeleteImage(319, sess.SecurityToken); 80 83 81 PwgImageInfo info = PwgServiceProvider.Instance.PwgImagesService.getImageInfo(319, null, null);82 84 //PwgImageInfo info = PwgServiceProvider.Instance.PwgImagesService.getImageInfo(imgAdd.Id, null, null); 85 83 86 //PwgImageRate imgRate = PwgServiceProvider.Instance.PwgImagesService.RateImage(1, 5); 84 87 … … 93 96 } 94 97 98 private string MakeThumb(FileInfo fi, String ext, int size) 99 { 100 // create an image object, using the filename we just retrieved 101 System.Drawing.Image image = System.Drawing.Image.FromFile(fi.FullName); 102 103 // create the actual thumbnail image 104 System.Drawing.Image thumbnailImage = image.GetThumbnailImage(size, size, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); 105 106 // make a memory stream to work with the image bytes 107 FileStream imageStream = new FileStream(ext, FileMode.OpenOrCreate); 108 109 // put the image into the memory stream 110 thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg); 111 112 imageStream.Close(); 113 return ext; 114 } 115 116 /// <summary> 117 /// Required, but not used 118 /// </summary> 119 /// <returns>true</returns> 120 public bool ThumbnailCallback() 121 { 122 return true; 123 } 124 125 95 126 private void Form1_FormClosing(object sender, FormClosingEventArgs e) 96 127 {
Note: See TracChangeset
for help on using the changeset viewer.