Ignore:
Timestamp:
Aug 2, 2011, 4:50:49 PM (13 years ago)
Author:
bayral
Message:

First draw of pwg.image.add and pwg.imae.addtrunck.
addtrunck seem to be ok, but image.add return server error 500.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/PiwigoLib/PiwigoLib/Service/PwgImagesService.cs

    r11872 r11890  
    8282        }
    8383
     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>
    84181        public Boolean DeleteImage(Int32 imageId, String SecurityToken)
    85182        {
     
    139236                else
    140237                {
    141                     //returnValue = ConvertProxyResponseToDTO(response);
     238                    returnValue = ConvertProxyResponseToDTO(response.ImageInfo);
    142239                }
    143240            }
     
    148245            return returnValue;
    149246        }       
     247
    150248        /// <summary>
    151249        /// private: convert response to dto object
     
    234332                }
    235333            }
     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;
    236461        }
    237462
Note: See TracChangeset for help on using the changeset viewer.