Changeset 3835


Ignore:
Timestamp:
Sep 7, 2009, 3:54:31 PM (15 years ago)
Author:
bayral
Message:

Complete pwg.categories.* support

Location:
extensions/PiwigoLib
Files:
6 edited

Legend:

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

    r3827 r3835  
    2020        public List<PwgTag> Tags { get; set; }
    2121
     22        public List<PwgCategory> Categories { get; set; }
     23
    2224    }
    2325}
  • extensions/PiwigoLib/PiwigoLib/Proxy/PwgCategoriesProxy.cs

    r3834 r3835  
    1212    static class PwgCategoriesProxy
    1313    {
     14        /// <summary>
     15        /// pwg.categories.getList
     16        /// </summary>
     17        /// <param name="CategoryId"></param>
     18        /// <param name="Recursive"></param>
     19        /// <param name="PublicOnly"></param>
     20        /// <returns></returns>
    1421        static public PwgCategoriesProxyResponse pwg_categories_getList(Int32? CategoryId,
    1522            Boolean? Recursive, Boolean? PublicOnly)
     
    3744        }
    3845
     46        /// <summary>
     47        /// pwg.categories.getAdminList
     48        /// </summary>
     49        /// <returns></returns>
    3950        static public PwgCategoriesProxyResponse pwg_categories_getAdminList()
    4051        {
     
    5465        }
    5566
     67        /// <summary>
     68        /// pwg.categories.add
     69        /// </summary>
     70        /// <param name="categorieName"></param>
     71        /// <param name="IdUpperCat"></param>
     72        /// <returns></returns>
    5673        static public PwgAddRequestProxyResponse pwg_categories_add(String categorieName, Int32? IdUpperCat)
    5774        {
     
    7794        }
    7895
     96        /// <summary>
     97        /// pwg.categories.setInfo
     98        /// </summary>
     99        /// <param name="IdCat"></param>
     100        /// <param name="categorieName"></param>
     101        /// <param name="categorieComment"></param>
     102        /// <returns></returns>
     103        static public PwgBaseProxyReponse pwg_categories_setInfo(Int32 IdCat, String categorieName, String categorieComment)
     104        {
     105            PwgBaseProxyReponse response = null;
     106            try
     107            {
     108                StringBuilder data = new StringBuilder();
     109                data.Append("method=pwg.categories.setInfo");
     110                Boolean firstOcc = false;
     111                PwgProxyReponseHelper.buildQueryFromValue<Int32>(IdCat, "category_id", ref firstOcc, data);
     112                PwgProxyReponseHelper.buildQueryFromValue<String>(categorieName, "name", ref firstOcc, data);
     113                PwgProxyReponseHelper.buildQueryFromValue<String>(categorieComment, "comment", ref firstOcc, data);
     114
     115                response = PwgGenericProxy<PwgAddRequestProxyResponse>.Post(
     116                    PwgConfigProxy.PwgServeurUriBuilder.Uri,
     117                    data.ToString());
     118            }
     119            catch (Exception ex)
     120            {
     121                throw new PwgProxyException("pwg_categories_setInfo", ex);
     122            }
     123
     124            return response;
     125        }
     126
     127        /// <summary>
     128        /// pwg.categories.getImages
     129        /// </summary>
     130        /// <param name="catId"></param>
     131        /// <param name="recursive"></param>
     132        /// <param name="perPage"></param>
     133        /// <param name="Page"></param>
     134        /// <param name="Order"></param>
     135        /// <param name="minRate"></param>
     136        /// <param name="maxRate"></param>
     137        /// <param name="minHit"></param>
     138        /// <param name="maxHit"></param>
     139        /// <param name="minDateAvailable"></param>
     140        /// <param name="maxDateAvailable"></param>
     141        /// <param name="minDateCreated"></param>
     142        /// <param name="maxDateCreated"></param>
     143        /// <param name="minRatio"></param>
     144        /// <param name="maxRatio"></param>
     145        /// <param name="withThumbnail"></param>
     146        /// <returns></returns>
     147        static public PwgImagesProxyResponse pwg_categories_getImages(Int32 catId,
     148                                                            Boolean? recursive,
     149                                                            Int32? perPage,
     150                                                            Int32? Page,
     151                                                            Int32? Order,
     152                                                            Int32? minRate,
     153                                                            Int32? maxRate,
     154                                                            Int32? minHit,
     155                                                            Int32? maxHit,
     156                                                            DateTime? minDateAvailable,
     157                                                            DateTime? maxDateAvailable,
     158                                                            DateTime? minDateCreated,
     159                                                            DateTime? maxDateCreated,
     160                                                            Int32? minRatio,
     161                                                            Int32? maxRatio,
     162                                                            Boolean? withThumbnail)
     163        {
     164            PwgImagesProxyResponse response = null;
     165            try
     166            {
     167                StringBuilder data = new StringBuilder();
     168                Boolean firstOcc = true;
     169                data.AppendFormat("method={0}", "pwg.categories.getImages");
     170                firstOcc = false;
     171                PwgProxyReponseHelper.buildQueryFromValue<Int32>(catId, "cat_id", ref firstOcc, data);
     172
     173                PwgProxyReponseHelper.buildQueryFromValue<Boolean>(recursive, "recursive", ref firstOcc, data);
     174                PwgProxyReponseHelper.buildQueryFromValue<Int32>(perPage, "per_page", ref firstOcc, data);
     175                PwgProxyReponseHelper.buildQueryFromValue<Int32>(Page, "page", ref firstOcc, data);
     176                PwgProxyReponseHelper.buildQueryFromValue<Int32>(Order, "order", ref firstOcc, data);
     177                PwgProxyReponseHelper.buildQueryFromValue<Int32>(minRate, "f_min_rate", ref firstOcc, data);
     178                PwgProxyReponseHelper.buildQueryFromValue<Int32>(maxRate, "f_max_rate", ref firstOcc, data);
     179                PwgProxyReponseHelper.buildQueryFromValue<Int32>(minHit, "f_min_hit", ref firstOcc, data);
     180                PwgProxyReponseHelper.buildQueryFromValue<Int32>(maxHit, "f_max_hit", ref firstOcc, data);
     181                PwgProxyReponseHelper.buildQueryFromValue<DateTime>(minDateAvailable, "f_min_date_available", ref firstOcc, data);
     182                PwgProxyReponseHelper.buildQueryFromValue<DateTime>(maxDateAvailable, "f_max_date_available", ref firstOcc, data);
     183                PwgProxyReponseHelper.buildQueryFromValue<DateTime>(minDateCreated, "f_min_date_created", ref firstOcc, data);
     184                PwgProxyReponseHelper.buildQueryFromValue<DateTime>(maxDateCreated, "f_max_date_created", ref firstOcc, data);
     185                PwgProxyReponseHelper.buildQueryFromValue<Int32>(minRatio, "f_min_ratio", ref firstOcc, data);
     186                PwgProxyReponseHelper.buildQueryFromValue<Int32>(maxRatio, "f_max_ratio", ref firstOcc, data);
     187                PwgProxyReponseHelper.buildQueryFromValue<Boolean>(withThumbnail, "f_with_thumbnail", ref firstOcc, data);
     188
     189                response = PwgGenericProxy<PwgImagesProxyResponse>.Post(
     190                                PwgConfigProxy.PwgServeurUriBuilder.Uri,
     191                                data.ToString());
     192            }
     193            catch (Exception ex)
     194            {
     195                throw new PwgProxyException("pwg_categories_getImages", ex);
     196            }
     197            return response;
     198
     199        }
     200
     201        /// <summary>
     202        ///
     203        /// </summary>
     204        /// <param name="tagName"></param>
     205        /// <returns></returns>
     206        static public 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.PwgServeurUriBuilder.Uri,
     217                    data.ToString());
     218            }
     219            catch (Exception ex)
     220            {
     221                throw new PwgProxyException("pwg_tag_add", ex);
     222            }
     223
     224            return response;
     225        }
    79226
    80227    }
  • extensions/PiwigoLib/PiwigoLib/Proxy/Response/PwgImagesProxyResponse.cs

    r3827 r3835  
    3333        public PwgTagProxyResponse[] Tags { get; set; }
    3434
     35        [XmlArray("categories")]
     36        [XmlArrayItem("category")]
     37        public PwgCategoryProxyResponse[] Categories { get; set; }
     38
    3539    }
    3640
  • extensions/PiwigoLib/PiwigoLib/Service/PwgCategoriesService.cs

    r3834 r3835  
    8989
    9090        /// <summary>
    91         /// Add a Categorie
    92         /// </summary>
    93         /// <param name="tagName"></param>
    94         /// <returns></returns>
     91        /// Add a category to the gallery
     92        /// </summary>
     93        /// <param name="categoryName"></param>
     94        /// <param name="upperCatId"></param>
     95        /// <param name="newId"> Id used by the new category</param>
     96        /// <param name="messageInfo">Message returned by the server</param>
     97        /// <returns>false, if a error occurs</returns>
    9598        static public Boolean AddCategory(String categoryName, Int32? upperCatId, ref Int32 newId, ref String messageInfo)
    9699        {
     
    105108                    if (response.Erreur != null)
    106109                    {
    107                         throw new PwgServiceException("AddTag, the server has return the error.",
    108                             response.Erreur.Code,
    109                             response.Erreur.Message);
    110                     }
    111                     else
    112                     {
    113                         throw new PwgServiceException("AddTag : a error occurs during server process.");
     110                        throw new PwgServiceException("AddCategory, the server has return the error.",
     111                            response.Erreur.Code,
     112                            response.Erreur.Message);
     113                    }
     114                    else
     115                    {
     116                        throw new PwgServiceException("AddCategory : a error occurs during server process.");
    114117                    }
    115118                }
     
    123126            catch (PwgProxyException ex)
    124127            {
    125                 throw new PwgServiceException("AddTag : a error is raised by proxy.", ex);
    126             }
    127             return returnValue;
    128         }
    129 
    130         /// <summary>
    131         /// private: convert response to dto object
     128                throw new PwgServiceException("AddCategory : a error is raised by proxy.", ex);
     129            }
     130            return returnValue;
     131        }
     132
     133        static public List<PwgImage> GetListOfImagesFormCategory(Int32 categoryId,
     134                                                    Boolean? recursive,
     135                                                    Int32? perPage,
     136                                                    Int32? Page,
     137                                                    Int32? Order,
     138                                                    Int32? minRate,
     139                                                    Int32? maxRate,
     140                                                    Int32? minHit,
     141                                                    Int32? maxHit,
     142                                                    DateTime? minDateAvailable,
     143                                                    DateTime? maxDateAvailable,
     144                                                    DateTime? minDateCreated,
     145                                                    DateTime? maxDateCreated,
     146                                                    Int32? minRatio,
     147                                                    Int32? maxRatio,
     148                                                    Boolean? withThumbnail,
     149                                                    ref Int32 PageReturned,
     150                                                    ref Int32 PerPageeReturned,
     151                                                    ref Int32 CountReturned)
     152        {
     153            List<PwgImage> returnValue = new List<PwgImage>();
     154
     155            try
     156            {
     157                PwgImagesProxyResponse response = PwgCategoriesProxy.pwg_categories_getImages(categoryId,
     158                                                            recursive,
     159                                                            perPage,
     160                                                            Page,
     161                                                            Order,
     162                                                            minRate,
     163                                                            maxRate,
     164                                                            minHit,
     165                                                            maxHit,
     166                                                            minDateAvailable,
     167                                                            maxDateAvailable,
     168                                                            minDateCreated,
     169                                                            maxDateCreated,
     170                                                            minRatio,
     171                                                            maxRatio,
     172                                                            withThumbnail);
     173
     174                if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok)
     175                {
     176                    if (response.Erreur != null)
     177                    {
     178                        throw new PwgServiceException("GetListOfImagesFormCategory, the server has return the error.",
     179                            response.Erreur.Code,
     180                            response.Erreur.Message);
     181                    }
     182                    else
     183                    {
     184                        throw new PwgServiceException("GetListOfImagesFormCategory : a error occurs during server process.");
     185                    }
     186                }
     187                else
     188                {
     189                    PwgImagesService.ConvertProxyResponseToDTO(response, returnValue,
     190                                                            ref PageReturned,
     191                                                            ref PerPageeReturned,
     192                                                            ref CountReturned);
     193                }
     194            }
     195            catch (PwgProxyException ex)
     196            {
     197                throw new PwgServiceException("GetListOfImagesFormCategory : a error is raised by proxy.", ex);
     198            }
     199            return returnValue;
     200        }
     201
     202        /// <summary>
     203        /// convert response to dto object
    132204        /// </summary>
    133205        /// <param name="response"></param>
     
    147219
    148220        /// <summary>
    149         /// private: convert response to dto object
     221        /// convert response to dto object
    150222        /// </summary>
    151223        /// <param name="response"></param>
  • extensions/PiwigoLib/PiwigoLib/Service/PwgImagesService.cs

    r3828 r3835  
    3838            Count = response.Count;
    3939
    40             foreach (PwgImageProxyResponse respImg in response.Images)
     40            if (response.Images != null)
    4141            {
    42                 lstImage.Add(ConvertProxyResponseToDTO(respImg));
     42                foreach (PwgImageProxyResponse respImg in response.Images)
     43                {
     44                    lstImage.Add(ConvertProxyResponseToDTO(respImg));
     45                }
    4346            }
    4447        }
     
    8992
    9093                returnValue.Tags = new List<PwgTag>();
    91                 foreach (PwgTagProxyResponse tagResp in  response.Tags)
     94                if (response.Tags != null)
    9295                {
    93                     PwgTag aTag = PwgTagsService.ConvertProxyResponseToDTO(tagResp);
    94                     returnValue.Tags.Add(aTag);
     96                    foreach (PwgTagProxyResponse tagResp in response.Tags)
     97                    {
     98                        PwgTag aTag = PwgTagsService.ConvertProxyResponseToDTO(tagResp);
     99                        returnValue.Tags.Add(aTag);
     100                    }
     101                }
     102
     103                returnValue.Categories = new List<PwgCategory>();
     104                if (response.Categories != null)
     105                {
     106                    foreach (PwgCategoryProxyResponse catResp in response.Categories)
     107                    {
     108                        PwgCategory aCat = PwgCategoriesService.ConvertProxyResponseToDTO(catResp);
     109                        returnValue.Categories.Add(aCat);
     110                    }
    95111                }
    96112
  • extensions/PiwigoLib/TestPiwigoLib/Form1.cs

    r3834 r3835  
    4949                //List<PwgTag> lstTag = PwgTagsService.GetAdminListOfTag();
    5050
    51                 //Int32 Page = 0;
    52                 //Int32 PerPage = 0;
    53                 //Int32 Count = 0;
     51                Int32 Page = 0;
     52                Int32 PerPage = 0;
     53                Int32 Count = 0;
    5454
    5555                //List<PwgImage> lstImg = PwgTagsService.GetListOfImagesFormTags(new List<Int32>() { 1, 7 },
     
    5757                //    ref Page, ref PerPage, ref Count);
    5858
     59                List<PwgImage> lstImg = PwgCategoriesService.GetListOfImagesFormCategory(1,
     60                    null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
     61                    ref Page, ref PerPage, ref Count);
     62
    5963                //Console.WriteLine("lstImg : Page " + Page.ToString() + " PerPage " + PerPage);
    6064
    61                 List<PwgCategory> lstCat = PwgCategoriesService.GetAdminListOfCategory();
     65                //List<PwgCategory> lstCat = PwgCategoriesService.GetAdminListOfCategory();
    6266
    6367
Note: See TracChangeset for help on using the changeset viewer.