Ignore:
Timestamp:
Aug 1, 2011, 5:47:03 PM (13 years ago)
Author:
bayral
Message:
 
File:
1 edited

Legend:

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

    r11850 r11872  
    4949        }
    5050
    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 );
     51        public PwgImageAdded addImageByMultiPartForm(FileInfo fileImage, Int32? imageId, Int32? categoryId, String imageName, String imageAuthor, String imageComment, Int32? imageLevel, List<PwgTag> imageTags)
     52        {
     53            PwgImageAdded returnValue = new PwgImageAdded();
     54
     55            try
     56            {
     57                PwgAddSimpleImageProxyResponse response = PwgImagesProxy.pwg_images_addSimple(fileImage, imageId, categoryId, imageName, imageAuthor, imageComment, imageLevel, imageTags);
    5858
    5959                if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok)
     
    7272                else
    7373                {
     74                    returnValue = ConvertProxyResponseToDTO(response);
     75                }
     76            }
     77            catch (PwgProxyException ex)
     78            {
     79                throw new PwgServiceException("addImageByMultiPartForm : a error is raised by proxy.", ex);
     80            }
     81            return returnValue;
     82        }
     83
     84        public Boolean DeleteImage(Int32 imageId, String SecurityToken)
     85        {
     86            Boolean returnValue = false;
     87
     88            try
     89            {
     90
     91                PwgBaseProxyReponse response = PwgImagesProxy.pwg_images_delete(imageId, SecurityToken);
     92
     93                if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok)
     94                {
     95                    if (response.Erreur != null)
     96                    {
     97                        throw new PwgServiceException("DeleteImage, the server has return the error.",
     98                            response.Erreur.Code,
     99                            response.Erreur.Message);
     100                    }
     101                    else
     102                    {
     103                        throw new PwgServiceException("DeleteImage : a error occurs during server process.");
     104                    }
     105                }
     106                else
     107                {
    74108                    returnValue = true;
    75109                }
     
    77111            catch (PwgProxyException ex)
    78112            {
    79                 throw new PwgServiceException("addImageByMultiPartForm : a error is raised by proxy.", ex);
    80             }
    81             return returnValue;
    82         }
     113                throw new PwgServiceException("DeleteImage : a error is raised by proxy.", ex);
     114            }
     115            return returnValue;
     116        }
     117
     118        public PwgImageInfo getImageInfo(Int32 imageId, Int32? commentPage, Int32? commentsPerPage)
     119        {
     120            PwgImageInfo returnValue = new PwgImageInfo();
     121
     122            try
     123            {
     124                PwgImageInfoProxyResponse response = PwgImagesProxy.pwg_images_getInfos(imageId, commentPage, commentsPerPage);
     125
     126                if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok)
     127                {
     128                    if (response.Erreur != null)
     129                    {
     130                        throw new PwgServiceException("RateImage, the server has return the error.",
     131                            response.Erreur.Code,
     132                            response.Erreur.Message);
     133                    }
     134                    else
     135                    {
     136                        throw new PwgServiceException("RateImage : a error occurs during server process.");
     137                    }
     138                }
     139                else
     140                {
     141                    //returnValue = ConvertProxyResponseToDTO(response);
     142                }
     143            }
     144            catch (PwgProxyException ex)
     145            {
     146                throw new PwgServiceException("RateImage : a error is raised by proxy.", ex);
     147            }
     148            return returnValue;
     149        }       
     150        /// <summary>
     151        /// private: convert response to dto object
     152        /// </summary>
     153        /// <param name="response"></param>
     154        /// <param name="session"></param>
     155        internal static PwgImageAdded ConvertProxyResponseToDTO(PwgAddSimpleImageProxyResponse response)
     156        {
     157            PwgImageAdded returnValue = new PwgImageAdded();
     158
     159            returnValue.Id = response.Id;
     160
     161            if (String.IsNullOrEmpty(response.UrlImage))
     162            {
     163                returnValue.UrlElement = null;
     164            }
     165            else
     166            {
     167                returnValue.UrlElement = (new UriBuilder(response.UrlImage)).Uri;
     168            }
     169           
     170            return returnValue;
     171        }
     172
    83173
    84174        /// <summary>
     
    163253                returnValue.Width = response.Width;
    164254
     255                if (response.AvailableDate != null)
     256                {
     257                    DateTime tryDate;
     258                    if (DateTime.TryParse(response.AvailableDate, out tryDate))
     259                    {
     260                        returnValue.AvailableDate = tryDate;
     261                    }
     262                }
     263
     264                if (response.CreatingDate != null)
     265                {
     266                    DateTime tryDate;
     267                    if (DateTime.TryParse(response.CreatingDate, out tryDate))
     268                    {
     269                        returnValue.CreatingDate = tryDate;
     270                    }
     271                }
     272
    165273                if (String.IsNullOrEmpty(response.UrlElement))
    166274                {
Note: See TracChangeset for help on using the changeset viewer.