Changeset 11872


Ignore:
Timestamp:
Aug 1, 2011, 5:47:03 PM (13 years ago)
Author:
bayral
Message:
 
Location:
extensions/PiwigoLib
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • extensions/PiwigoLib/PiwigoLib/DTO/PwgImage.cs

    r11850 r11872  
    1616        public Uri UrlHighDef { get; set; }
    1717        public Int64 Counter { get; set; }
     18        public DateTime CreatingDate { get; set; }
     19        public DateTime AvailableDate { get; set; }
    1820
    1921        public List<PwgTag> Tags { get; set; }
    2022
    2123        public List<PwgCategory> Categories { get; set; }
     24    }
    2225
     26    //<image
     27    //tn_ext="jpg" author="bayral" filesize="62" date_metadata_update="2011-04-12"
     28    //has_high="true" high_filesize="1667" level="0" md5sum="198c02a16d5f69c3def90908b33089c3" added_by="1"
     29    //<name>P1120275</name>
     30    //<rates count="0" average=""/>
     31    //<comment_post author="bayral" key="1312204731.6:2:6f7f43b81bcf86540216c6f39b9122a6"/>
     32    //<comments page="0" per_page="10" count="1" nb_comments="1">
     33    //<comment id="1" date="2011-08-01 13:37:59">
     34    //  <author>bayral</author>
     35    //  <content>test[b] demod[/b]</content>
     36    //</comment>
     37    //</comments>
     38    //</image>
     39    public class PwgImageInfo : PwgImage
     40    {
     41        public String ExtThumbail { get; set; }
     42        public String Author { get; set; }
     43        public Int64  ImageFileSize { get; set; }
     44        public DateTime DateupdateMetaData { get; set; }
     45        public Boolean  hasHighDef { get; set; }
     46        public Int64 HighDefFileSize { get; set; }
     47        public Int32 ConfidentialLevel { get; set; }
     48        public String mdSum { get; set; }
     49        public Int32 UserIdAddedBy { get; set; }
     50        public String Name { get; set; }
     51
     52        public PwgImageRate ImageRate { get; set; }
     53        public PwgCommentPage ImageComments { get; set; }
     54        public PwgPostCommentSecurityInfo PostCommenSecurityData { get; set; }
     55    }
     56
     57    public class PwgPostCommentSecurityInfo
     58    {
     59        public String Author { get; set; }
     60        public String AllowPostKey { get; set; }
     61    }
     62
     63    public class PwgCommentPage : List<PwgComment>
     64    {
     65        public Int32 Page { get; set; }
     66        public Int32 PerPage { get; set; }
     67        public Int32 CountOf { get; set; }
     68        public Int32 TotalCommentNumber { get; set; }
     69    }
     70
     71    public class PwgComment
     72    {
     73        public Int32 Id { get; set; }
     74        public DateTime CommentDate { get; set; }
     75        public String Author { get; set; }
     76        public String Content { get; set; }
    2377    }
    2478
     
    2680    {
    2781        public Int32 Count { get; set; }
    28         public Double  Average { get; set; }
     82        public Double Average { get; set; }
    2983        public Double Stdev { get; set; }
    3084    }
     85
     86    public class PwgImageAdded
     87    {
     88        public Int32 Id { get; set; }
     89        public Uri UrlElement { get; set; }
     90    }
     91
    3192}
  • extensions/PiwigoLib/PiwigoLib/IService/IPwgImagesService.cs

    r11850 r11872  
    11using System;
     2
    23namespace Com.Piwigo.Lib.IService
    34{
     
    56    {
    67        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);
     8        Com.Piwigo.Lib.DTO.PwgImageAdded addImageByMultiPartForm(System.IO.FileInfo fileImage, Int32? imageId, Int32? categoryId, String imageName, String imageAuthor, String imageComment, Int32? imageLevel, System.Collections.Generic.List<Com.Piwigo.Lib.DTO.PwgTag> imageTags);
     9        Boolean DeleteImage(Int32 imageId, String SecurityToken);
     10        Com.Piwigo.Lib.DTO.PwgImageInfo getImageInfo(Int32 imageId, Int32? commentPage, Int32? commentsPerPage);
    811    }
    912}
  • extensions/PiwigoLib/PiwigoLib/Proxy/Helper/PwgProxyReponseHelper.cs

    r11850 r11872  
    66
    77using Com.Piwigo.Lib.DTO.Helper;
     8using System.Xml;
     9using Com.Piwigo.Lib.DTO;
    810
    911namespace Com.Piwigo.Lib.Proxy.Helper
     
    1113    internal static class PwgProxyReponseHelper
    1214    {
     15        internal static void buildDicFieldFromArray<T>(List<T> values, String paramName, ref Dictionary<String, String> dcFields)
     16        {
     17            String FormatString = String.Empty;
     18            String ParamValue = String.Empty;
     19
     20            Boolean firstOcc = true;
     21            if (values != null)
     22            {
     23                foreach (T occurance in values)
     24                {
     25                    if (firstOcc == true)
     26                    {
     27                        firstOcc = false;
     28                        FormatString = "{0}";
     29                    }
     30                    else
     31                    {
     32                        FormatString = ",{0}";
     33                    }
     34
     35                    ParamValue += String.Format(FormatString,GetString(occurance));
     36                }
     37
     38                dcFields.Add(paramName, ParamValue);
     39            }
     40        }
     41
     42        internal static void buildDicFieldFromValue<T>(Nullable<T> nullableValue, String paramName, ref Dictionary<String, String> dcFields) where T : struct
     43        {
     44            if (nullableValue.HasValue)
     45            {
     46                buildDicFieldFromValue<T>(nullableValue.Value, paramName, ref dcFields);
     47            }
     48        }
     49
     50        internal static void buildDicFieldFromValue<T>(T value, String paramName, ref Dictionary<String, String> dcFields)
     51        {
     52            String FormatString = String.Empty;
     53            String ParamValue = String.Empty;
     54
     55            FormatString = "{0}";
     56
     57            ParamValue = GetString(value);
     58
     59            dcFields.Add(paramName, ParamValue);
     60        }
     61
    1362        internal static void buildQueryFromArray<T>(List<T> values, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder)
    1463        {
     
    3180                foreach (T occurance in values)
    3281                {
    33                     queryStringBuilder.AppendFormat(FormatString, paramName, HttpUtility.UrlEncode(occurance.ToString().ToLower()));
     82                    queryStringBuilder.AppendFormat(FormatString, paramName, HttpUtility.UrlEncode(GetString(occurance)));
    3483                    firstOcc = false;
    3584                }
     
    3887        }
    3988
    40         internal static void buildQueryFromValue<T>(Nullable<T> nullableValue, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder)
    41             where T: struct
     89        internal static void buildQueryFromValue<T>(Nullable<T> nullableValue, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder) where T : struct
    4290        {
    4391            if (nullableValue.HasValue)
     
    52100            String ParamValue = String.Empty;
    53101           
    54             if (value != null)
    55             {
    56102                FormatString = "{0}={1}";
    57103                if (firstOcc != true)
     
    60106                }
    61107
    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                 }
     108                ParamValue = HttpUtility.UrlEncode(GetString(value));
    70109               
    71110                queryStringBuilder.AppendFormat(FormatString, paramName, ParamValue);
    72111               
    73112                firstOcc = false;
     113        }
     114
     115        public static String GetString<T>(T value)
     116        {
     117            String strRet = String.Empty;
     118            if (value is String)
     119            {
     120                strRet = (value as String);
    74121            }
     122            else if (typeof(T).IsEnum)
     123            {
     124                strRet = PwgEnumHelper<T>.StringValueOf(value);
     125            }
     126            else if (value is PwgTag)
     127            {
     128
     129                strRet = (value as PwgTag).Name;
     130            }
     131            else
     132            {
     133
     134                strRet = (value as Object).ToString().ToLowerInvariant();
     135            }
     136
     137            return strRet;
    75138        }
    76139    }
  • extensions/PiwigoLib/PiwigoLib/Proxy/PwgGenericProxy.cs

    r11850 r11872  
    4646                Request.UserAgent = PwgConfigProxy.PwgUserAgent;
    4747                Request.KeepAlive = PwgConfigProxy.PwgKeepAlive;
     48#if DEBUG
     49                Request.Timeout = PwgConfigProxy.PwgTimeOutInSecond * 1000 * 1000;
     50#else
    4851                Request.Timeout = PwgConfigProxy.PwgTimeOutInSecond * 1000;
     52#endif
     53
    4954                Request.CookieContainer = PwgConfigProxy.cookieContainer; // get session cookie
    5055
     
    105110                Request.UserAgent = PwgConfigProxy.PwgUserAgent;
    106111                Request.KeepAlive = PwgConfigProxy.PwgKeepAlive;
     112#if DEBUG
     113                Request.Timeout = PwgConfigProxy.PwgTimeOutInSecond * 1000 * 1000;
     114#else
    107115                Request.Timeout = PwgConfigProxy.PwgTimeOutInSecond * 1000;
     116#endif
     117
    108118                Request.CookieContainer = PwgConfigProxy.cookieContainer; // get session cookie
    109119
     
    191201                Request.UserAgent = PwgConfigProxy.PwgUserAgent;
    192202                Request.KeepAlive = PwgConfigProxy.PwgKeepAlive;
     203#if DEBUG
     204                Request.Timeout = PwgConfigProxy.PwgTimeOutInSecond * 1000 * 1000;
     205#else
    193206                Request.Timeout = PwgConfigProxy.PwgTimeOutInSecond * 1000;
     207#endif
     208                Request.SendChunked = true;
     209                Request.ProtocolVersion = System.Net.HttpVersion.Version11;
    194210                Request.CookieContainer = PwgConfigProxy.cookieContainer; // get session cookie       
    195211
  • extensions/PiwigoLib/PiwigoLib/Proxy/PwgImagesProxy.cs

    r11850 r11872  
    1818         * pwg.images.addChunk
    1919         * pwg.images.addComment
    20          * pwg.images.addFile
    21          * pwg.images.addSimple
     20         * pwg.images.addFile               
     21         * pwg.images.addSimple            pwg_images_addSimple
    2222         * pwg.images.checkFiles
    2323         * pwg.images.checkUpload
    24          * pwg.images.delete
     24         * pwg.images.delete               pwg_images_delete
    2525         * pwg.images.exist
    2626         * pwg.images.getInfo
     
    6161        }
    6262
    63         static internal PwgBaseProxyReponse pwg_images_addSimple(FileInfo fileImage, Int32? imageId, Int32? categoryId, String imageName, String imageAuthor, String imageComment, Int32? imageLevel, String imageTags)
     63        /// <summary>
     64        /// pwg.images.addSimple
     65        /// </summary>
     66        /// <param name="fileImage"></param>
     67        /// <param name="imageId"></param>
     68        /// <param name="categoryId"></param>
     69        /// <param name="imageName"></param>
     70        /// <param name="imageAuthor"></param>
     71        /// <param name="imageComment"></param>
     72        /// <param name="imageLevel"></param>
     73        /// <param name="imageTags"></param>
     74        /// <returns></returns>
     75        static internal PwgAddSimpleImageProxyResponse pwg_images_addSimple(FileInfo fileImage, Int32? imageId, Int32? categoryId, String imageName, String imageAuthor, String imageComment, Int32? imageLevel, List<PwgTag> imageTags)
    6476        {
    65             PwgBaseProxyReponse response = null;
     77            PwgAddSimpleImageProxyResponse response = null;
    6678
    6779            Dictionary<String, String> dcFiles  = new Dictionary<string,string>();
    6880            Dictionary<String, String> dcFields = new Dictionary<string,string>();
    69            
     81            String stringData = String.Empty;
     82
    7083            try
    7184            {
    7285                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); }
     86                PwgProxyReponseHelper.buildDicFieldFromValue<Int32>(imageId, "image_id", ref dcFields);
     87                PwgProxyReponseHelper.buildDicFieldFromValue<Int32>(categoryId, "category", ref dcFields);
     88                PwgProxyReponseHelper.buildDicFieldFromValue<Int32>(imageLevel, "level", ref dcFields);
     89                PwgProxyReponseHelper.buildDicFieldFromValue<String>(imageName, "name", ref dcFields);
     90                PwgProxyReponseHelper.buildDicFieldFromValue<String>(imageAuthor, "author", ref dcFields);
     91                PwgProxyReponseHelper.buildDicFieldFromValue<String>(imageComment,"comment",  ref dcFields);
     92                PwgProxyReponseHelper.buildDicFieldFromArray<PwgTag>(imageTags, "tags", ref dcFields);
    8093
    8194                if ((fileImage != null) && (fileImage.Exists))
     
    88101                }
    89102
    90                 response = PwgGenericProxy<PwgBaseProxyReponse>.PostAsMultiPartForm(PwgConfigProxy.PwgServeurUri, dcFiles, dcFields);           
     103                response = PwgGenericProxy<PwgAddSimpleImageProxyResponse>.PostAsMultiPartForm(PwgConfigProxy.PwgServeurUri, dcFiles, dcFields);           
    91104            }
    92105            catch (Exception ex)
     
    97110            return response;
    98111        }
     112
     113        /// <summary>
     114        /// pwg.images.delete
     115        /// </summary>
     116        /// <param name="imageId"></param>
     117        /// <param name="SecurityToken"></param>
     118        /// <returns></returns>
     119        static internal PwgBaseProxyReponse pwg_images_delete(Int32 imageId,
     120                                                              String SecurityToken)
     121        {
     122            PwgBaseProxyReponse response = null;
     123            try
     124            {
     125                StringBuilder data = new StringBuilder();
     126                Boolean firstOcc = true;
     127                data.Append("method=pwg.images.delete");
     128                firstOcc = false;
     129                PwgProxyReponseHelper.buildQueryFromValue<Int32>(imageId, "image_id", ref firstOcc, data);
     130                PwgProxyReponseHelper.buildQueryFromValue<String>(SecurityToken, "pwg_token", ref firstOcc, data);
     131
     132                response = PwgGenericProxy<PwgBaseProxyReponse>.Post(
     133                                PwgConfigProxy.PwgServeurUri,
     134                                data.ToString());
     135            }
     136            catch (Exception ex)
     137            {
     138                throw new PwgProxyException("pwg_images_delete", ex);
     139            }
     140
     141            return response;
     142        }
     143
     144        static internal PwgImageInfoProxyResponse pwg_images_getInfos(Int32 imageId, Int32? commentPage, Int32? commentsPerPage)
     145        {
     146            PwgImageInfoProxyResponse response = null;
     147            try
     148            {
     149                StringBuilder data = new StringBuilder();
     150                Boolean firstOcc = true;
     151                data.Append("method=pwg.images.getInfo");
     152                firstOcc = false;
     153                PwgProxyReponseHelper.buildQueryFromValue<Int32>(imageId, "image_id", ref firstOcc, data);
     154                PwgProxyReponseHelper.buildQueryFromValue<Int32>(commentPage, "comments_page", ref firstOcc, data);
     155                PwgProxyReponseHelper.buildQueryFromValue<Int32>(commentsPerPage, "comments_per_page", ref firstOcc, data);
     156
     157                response = PwgGenericProxy<PwgImageInfoProxyResponse>.Post(
     158                                PwgConfigProxy.PwgServeurUri,
     159                                data.ToString());
     160            }
     161            catch (Exception ex)
     162            {
     163                throw new PwgProxyException("pwg_images_getInfos", ex);
     164            }
     165
     166            return response;
     167        }
     168
    99169    }
    100170
  • extensions/PiwigoLib/PiwigoLib/Proxy/Response/PwgImagesProxyResponse.cs

    r7160 r11872  
    88namespace Com.Piwigo.Lib.Proxy.Response
    99{
     10    [Serializable()]
     11    [XmlRoot(ElementName = "rsp")]
     12    public class PwgAddSimpleImageProxyResponse : PwgBaseProxyReponse
     13    {
     14        [XmlElement("image_id")]
     15        public Int32 Id { get; set; }
     16        [XmlElement("url")]
     17        public String UrlImage { get; set; }
     18    }
    1019
    1120    [Serializable()]
     
    2332    [Serializable()]
    2433    [XmlRoot(ElementName = "categorie")]
    25     public class PwgImageProxyResponse
     34    public class PwgImageProxyResponse 
    2635    {
    2736        [XmlAttribute(AttributeName = "id")]
     
    4150        [XmlAttribute(AttributeName = "hit")]
    4251        public Int64 Counter { get; set; }
     52        [XmlAttribute(AttributeName = "date_creation")]
     53        public String CreatingDate { get; set; }
     54        [XmlAttribute(AttributeName = "date_available")]
     55        public String AvailableDate { get; set; }
    4356
    4457        [XmlArray("tags")]
     
    5063        public PwgCategoryProxyResponse[] Categories { get; set; }
    5164
     65    }
     66
     67    [Serializable()]
     68    [XmlRoot(ElementName = "rsp")]
     69    public class PwgImageInfoProxyResponse : PwgBaseProxyReponse
     70    {
     71        [XmlElement("image")]
     72        public PwgImageInfoImageProxyResponse ImageInfo { get; set; }
     73    }
     74
     75    [Serializable()]
     76    [XmlRoot(ElementName = "image")]
     77    public class PwgImageInfoImageProxyResponse
     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        public String ExtThumbail { get; set; }
     101        [XmlAttribute(AttributeName = "author")]
     102        public String Author { get; set; }
     103        [XmlAttribute(AttributeName = "filesize")]
     104        public Int64 ImageFileSize { get; set; }
     105        [XmlAttribute(AttributeName = "date_metadata_update")]
     106        public String DateUpdateMetaData { get; set; }
     107        [XmlAttribute(AttributeName = "has_high")]
     108        public Boolean hasHighDef { get; set; }
     109        [XmlAttribute(AttributeName = "high_filesize")]
     110        public Int64 HighDefFileSize { get; set; }
     111        [XmlAttribute(AttributeName = "level")]
     112        public Int32 ConfidentialLevel { get; set; }
     113        [XmlAttribute(AttributeName = "md5sum")]
     114        public String mdSum { get; set; }
     115        [XmlAttribute(AttributeName = "added_by")]
     116        public Int32 UserIdAddedBy { get; set; }
     117
     118        [XmlElement("name")]
     119        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
     129        [XmlElement("rates")]
     130        public PwgImageRateProxyResponse ImageRate { get; set; }
     131       
     132        [XmlElement("comments")]
     133        public PwgCommentPageProxyResponse ImageComments { get; set; }
     134
     135        [XmlElement("comment_post")]
     136        public PwgPostCommentSecurityInfo PostCommenSecurityData { get; set; }
     137    }
     138
     139    [Serializable()]
     140    [XmlRoot(ElementName = "comment_post")]
     141    public class PwgPostCommentSecurityInfoProxyResponse
     142    {
     143        [XmlAttribute(AttributeName = "author")]
     144        public String Author { get; set; }
     145        [XmlAttribute(AttributeName = "key")]
     146        public String AllowPostKey { get; set; }
     147    }
     148
     149    [Serializable()]
     150    [XmlRoot(ElementName = "comments")]
     151    public class PwgCommentPageProxyResponse
     152    {
     153        [XmlAttribute("page")]
     154        public Int32 Page { get; set; }
     155        [XmlAttribute("per_page")]
     156        public Int32 PerPage { get; set; }
     157        [XmlAttribute("count")]
     158        public Int32 CountOf { get; set; }
     159        [XmlAttribute("nb_comments")]
     160        public Int32 TotalCommentNumber { get; set; }
     161
     162        [XmlElement("comment", typeof(PwgCommentProxyResponse))]
     163        public PwgCommentProxyResponse[] Comments { get; set; }
     164    }
     165
     166    [Serializable()]
     167    [XmlRoot(ElementName = "comments")]
     168    public class PwgCommentProxyResponse
     169    {
     170        [XmlAttribute("id")]
     171        public Int32 Id { get; set; }
     172        [XmlAttribute("date")]
     173        public DateTime CommentDate { get; set; }
     174        [XmlAttribute("author")]
     175        public String Author { get; set; }
     176        [XmlAttribute("content")]
     177        public String Content { get; set; }
    52178    }
    53179
  • 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                {
  • extensions/PiwigoLib/TestPiwigoLib/Form1.cs

    r11850 r11872  
    5050                //Int32 Count = 0;
    5151
    52                 //List<PwgImage> lstImg = PwgServiceProvider.Instance.PwgTagsService.GetListOfImagesFormTags(new List<Int32>() { 1, 7 },
     52                //List<PwgImage> lstImgTag = PwgServiceProvider.Instance.PwgTagsService.GetListOfImagesFormTags(new List<Int32>() { 1, 7 },
    5353                //    null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
    5454                //    ref Page, ref PerPage, ref Count);
    5555
    56                 //List<PwgImage> lstImg = PwgServiceProvider.Instance.PwgCategoriesService.GetListOfImagesFormCategory(1,
     56                //List<PwgImage> lstImgCat = PwgServiceProvider.Instance.PwgCategoriesService.GetListOfImagesFormCategory(1,
    5757                //    null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
    5858                //    ref Page, ref PerPage, ref Count);
     
    7474                //lstCat = PwgServiceProvider.Instance.PwgCategoriesService.GetAdminListOfCategory();
    7575
    76                 FileInfo fi = new FileInfo("C:\\Users\\bayral\\Downloads\\49133_1636405570_2648232_n.jpg");
    77                 rc = PwgServiceProvider.Instance.PwgImagesService.addImageByMultiPartForm(fi, null, 1, "benoit", "byarl", "test upload", 0, null);
     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é" } });
     78
     79                rc = PwgServiceProvider.Instance.PwgImagesService.DeleteImage(319, sess.SecurityToken);
     80
     81                PwgImageInfo info = PwgServiceProvider.Instance.PwgImagesService.getImageInfo(319, null, null);
    7882
    7983                //PwgImageRate imgRate = PwgServiceProvider.Instance.PwgImagesService.RateImage(1, 5);
Note: See TracChangeset for help on using the changeset viewer.