Ignore:
Timestamp:
Sep 7, 2009, 2:46:08 PM (15 years ago)
Author:
bayral
Message:

start with pwg.catgeroies.* support

Location:
extensions/PiwigoLib/PiwigoLib/Proxy
Files:
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • extensions/PiwigoLib/PiwigoLib/Proxy/Helper/PwgProxyReponseHelper.cs

    r3827 r3834  
    77namespace Com.Piwigo.Lib.Proxy.Helper
    88{
    9     public static class PwgProxyReponseHelper<T>
     9    public static class PwgProxyReponseHelper
    1010    {
    11         public static void buildQueryFromArray(List<T> values, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder)
     11        public static void buildQueryFromArray<T>(List<T> values, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder)
    1212        {
    1313            String FormatString = String.Empty;
     
    3434
    3535            }
     36        }
    3637
     38        public static void buildQueryFromValue<T>(Nullable<T> nullableValue, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder)
     39            where T: struct
     40        {
     41            if (nullableValue.HasValue)
     42            {
     43                buildQueryFromValue<T>(nullableValue.Value, paramName, ref firstOcc, queryStringBuilder);
     44            }
     45        }
     46
     47        public static void buildQueryFromValue<T>(T value, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder)
     48        {
     49            String FormatString = String.Empty;
     50            if (value != null)
     51            {
     52                FormatString = "{0}={1}";
     53                if (firstOcc != true)
     54                {
     55                    FormatString = String.Format("&{0}", FormatString);
     56                }
     57
     58                queryStringBuilder.AppendFormat(FormatString, paramName, HttpUtility.UrlEncode(value.ToString().ToLower()));
     59                firstOcc = false;
     60            }
    3761        }
    3862    }
  • extensions/PiwigoLib/PiwigoLib/Proxy/PwgCategoriesProxy.cs

    r3833 r3834  
    1010namespace Com.Piwigo.Lib.Proxy
    1111{
    12     static class PwgTagsProxy
     12    static class PwgCategoriesProxy
    1313    {
    14         static public PwgTagsProxyResponse pwg_tags_getList(Boolean sortedByCounter)
     14        static public PwgCategoriesProxyResponse pwg_categories_getList(Int32? CategoryId,
     15            Boolean? Recursive, Boolean? PublicOnly)
    1516        {
    16             PwgTagsProxyResponse response = null;
     17            PwgCategoriesProxyResponse response = null;
    1718            try
    1819            {
    1920                StringBuilder data = new StringBuilder();
    20                 data.Append("sort_by_counter=" + HttpUtility.UrlEncode(sortedByCounter.ToString().ToLower()));
     21                Boolean firstOcc = true;
    2122
    22                 response = PwgGenericProxy<PwgTagsProxyResponse>.Get(
     23                PwgProxyReponseHelper.buildQueryFromValue<Int32>(CategoryId, "cat_id", ref firstOcc, data);
     24                PwgProxyReponseHelper.buildQueryFromValue<Boolean>(Recursive, "recursive", ref firstOcc, data);
     25                PwgProxyReponseHelper.buildQueryFromValue<Boolean>(PublicOnly, "public", ref firstOcc, data);
     26
     27                response = PwgGenericProxy<PwgCategoriesProxyResponse>.Get(
    2328                                PwgConfigProxy.PwgServeurUriBuilder.Uri,
    24                                 "pwg.tags.getList", data.ToString());
     29                                "pwg.categories.getList", data.ToString());
    2530            }
    2631            catch (Exception ex)
    2732            {
    28                 throw new PwgProxyException("pwg_tags_getList", ex);
     33                throw new PwgProxyException("pwg_categories_getList", ex);
    2934            }
    3035            return response;
     
    3237        }
    3338
    34         static public PwgTagsProxyResponse pwg_tags_getAdminList()
     39        static public PwgCategoriesProxyResponse pwg_categories_getAdminList()
    3540        {
    36             PwgTagsProxyResponse response = null;
     41            PwgCategoriesProxyResponse response = null;
    3742            try
    3843            {
    39                 response = PwgGenericProxy<PwgTagsProxyResponse>.Get(
     44                response = PwgGenericProxy<PwgCategoriesProxyResponse>.Get(
    4045                                PwgConfigProxy.PwgServeurUriBuilder.Uri,
    41                                 "pwg.tags.getAdminList", null);
     46                                "pwg.categories.getAdminList", null);
    4247            }
    4348            catch (Exception ex)
    4449            {
    45                 throw new PwgProxyException("pwg_tags_getAdminList", ex);
     50                throw new PwgProxyException("pwg_categories_getAdminList", ex);
    4651            }
    4752            return response;
     
    4954        }
    5055
    51         static public PwgImagesProxyResponse pwg_tags_getImages(List<Int32> tagsId,             
    52                                                                     List<String>    tagsUrlName,
    53                                                                     List<String>    tagsName,
    54                                                                     Boolean?         tagModeAnd,
    55                                                                     Int32?           perPage,
    56                                                                     Int32?           Page,
    57                                                                     Int32?          Order,
    58                                                                     Int32?           minRate,
    59                                                                     Int32?           maxRate,
    60                                                                     Int32?           minHit,
    61                                                                     Int32?           maxHit,
    62                                                                     DateTime?        minDateAvailable,
    63                                                                     DateTime?        maxDateAvailable,
    64                                                                     DateTime?        minDateCreated,
    65                                                                     DateTime?        maxDateCreated,
    66                                                                     Int32?           minRatio,
    67                                                                     Int32?           maxRatio,
    68                                                                     Boolean?         withThumbnail)
     56        static public PwgAddRequestProxyResponse pwg_categories_add(String categorieName, Int32? IdUpperCat)
    6957        {
    70             PwgImagesProxyResponse response = null;
     58            PwgAddRequestProxyResponse response = null;
    7159            try
    7260            {
    7361                StringBuilder data = new StringBuilder();
    74                 Boolean firstOcc = true;
    75                 data.AppendFormat("method={0}","pwg.tags.getImages");
    76                 firstOcc = false;
    77                 PwgProxyReponseHelper<Int32>.buildQueryFromArray(tagsId, "tag_id", ref firstOcc, data);
    78                 PwgProxyReponseHelper<String>.buildQueryFromArray(tagsUrlName, "tag_url_name", ref firstOcc, data);
    79                 PwgProxyReponseHelper<String>.buildQueryFromArray(tagsName, "tag_name", ref firstOcc, data);
     62                data.Append("method=pwg.categories.add");
     63                Boolean firstOcc = false;
     64                PwgProxyReponseHelper.buildQueryFromValue<String>(categorieName, "name", ref firstOcc, data);
     65                PwgProxyReponseHelper.buildQueryFromValue<Int32>(IdUpperCat, "parent", ref firstOcc, data);
    8066
    81                 if (tagModeAnd.HasValue)
    82                 {
    83                     data.Append("&tag_mode_and=" + HttpUtility.UrlEncode(tagModeAnd.ToString().ToLower()));
    84                 }
    85                 if (perPage.HasValue)
    86                 {
    87                     data.Append("&per_page=" + HttpUtility.UrlEncode(perPage.ToString().ToLower()));
    88                 }
    89                 if (Page.HasValue)
    90                 {
    91                     data.Append("&page=" + HttpUtility.UrlEncode(Page.ToString().ToLower()));
    92                 }
    93                 if (Order.HasValue)
    94                 {
    95                     data.Append("&order=" + HttpUtility.UrlEncode(Order.ToString().ToLower()));
    96                 }
    97                 if (minRate.HasValue)
    98                 {
    99                     data.Append("&f_min_rate=" + HttpUtility.UrlEncode(minRate.ToString().ToLower()));
    100                 }
    101                 if (maxRate.HasValue)
    102                 {
    103                     data.Append("&f_max_rate=" + HttpUtility.UrlEncode(maxRate.ToString().ToLower()));
    104                 }
    105                 if (minHit.HasValue)
    106                 {
    107                     data.Append("&f_min_hit=" + HttpUtility.UrlEncode(minHit.ToString().ToLower()));
    108                 }
    109                 if (maxHit.HasValue)
    110                 {
    111                     data.Append("&f_max_hit=" + HttpUtility.UrlEncode(maxHit.ToString().ToLower()));
    112                 }
    113                 if (minDateAvailable.HasValue)
    114                 {
    115                     data.Append("&f_min_date_available=" + HttpUtility.UrlEncode(minDateAvailable.ToString().ToLower()));
    116                 }
    117                 if (maxDateAvailable.HasValue)
    118                 {
    119                     data.Append("&f_max_date_available=" + HttpUtility.UrlEncode(maxDateAvailable.ToString().ToLower()));
    120                 }
    121                 if (minDateCreated.HasValue)
    122                 {
    123                     data.Append("&f_min_date_created=" + HttpUtility.UrlEncode(minDateCreated.ToString().ToLower()));
    124                 }
    125                 if (maxDateCreated.HasValue)
    126                 {
    127                     data.Append("&f_max_date_created=" + HttpUtility.UrlEncode(maxDateCreated.ToString().ToLower()));
    128                 }
    129                 if (minRatio.HasValue)
    130                 {
    131                     data.Append("&f_min_ratio=" + HttpUtility.UrlEncode(minRatio.ToString().ToLower()));
    132                 }
    133                 if (maxRatio.HasValue)
    134                 {
    135                     data.Append("&f_max_ratio=" + HttpUtility.UrlEncode(maxRatio.ToString().ToLower()));
    136                 }
    137                 if (withThumbnail.HasValue)
    138                 {
    139                     data.Append("&f_with_thumbnail=" + HttpUtility.UrlEncode(withThumbnail.ToString().ToLower()));
    140                 }
    141 
    142                 response = PwgGenericProxy<PwgImagesProxyResponse>.Post(
    143                                 PwgConfigProxy.PwgServeurUriBuilder.Uri,
    144                                 data.ToString());
    145             }
    146             catch (Exception ex)
    147             {
    148                 throw new PwgProxyException("pwg_tags_getImages", ex);
    149             }
    150             return response;
    151 
    152         }
    153         static public PwgTagsProxyResponse pwg_tag_add(string tagName)
    154         {
    155             PwgTagsProxyResponse response = null;
    156             try
    157             {
    158                 StringBuilder data = new StringBuilder();
    159                 data.Append("method=pwg.tags.add");
    160                 data.Append("&name=" + HttpUtility.UrlEncode(tagName));
    161 
    162                 response = PwgGenericProxy<PwgTagsProxyResponse>.Post(
     67                response = PwgGenericProxy<PwgAddRequestProxyResponse>.Post(
    16368                    PwgConfigProxy.PwgServeurUriBuilder.Uri,
    16469                    data.ToString());
     
    16671            catch (Exception ex)
    16772            {
    168                 throw new PwgProxyException("pwg_tag_add", ex);
     73                throw new PwgProxyException("pwg_categories_add", ex);
    16974            }
    17075
     
    17277        }
    17378
     79
    17480    }
    17581
  • extensions/PiwigoLib/PiwigoLib/Proxy/PwgTagsProxy.cs

    r3827 r3834  
    1212    static class PwgTagsProxy
    1313    {
    14         static public PwgTagsProxyResponse pwg_tags_getList(Boolean sortedByCounter)
     14        static public PwgTagsProxyResponse pwg_tags_getList(Boolean? sortedByCounter)
    1515        {
    1616            PwgTagsProxyResponse response = null;
     
    1818            {
    1919                StringBuilder data = new StringBuilder();
    20                 data.Append("sort_by_counter=" + HttpUtility.UrlEncode(sortedByCounter.ToString().ToLower()));
     20                Boolean firstOcc = true;
     21
     22                PwgProxyReponseHelper.buildQueryFromValue<Boolean>(sortedByCounter, "sort_by_counter", ref firstOcc, data);
    2123
    2224                response = PwgGenericProxy<PwgTagsProxyResponse>.Get(
     
    5557                                                                    Int32?           perPage,
    5658                                                                    Int32?           Page,
    57                                                                     Int32?          Order,
     59                                                                    Int32?           Order,
    5860                                                                    Int32?           minRate,
    5961                                                                    Int32?           maxRate,
     
    7577                data.AppendFormat("method={0}","pwg.tags.getImages");
    7678                firstOcc = false;
    77                 PwgProxyReponseHelper<Int32>.buildQueryFromArray(tagsId, "tag_id", ref firstOcc, data);
    78                 PwgProxyReponseHelper<String>.buildQueryFromArray(tagsUrlName, "tag_url_name", ref firstOcc, data);
    79                 PwgProxyReponseHelper<String>.buildQueryFromArray(tagsName, "tag_name", ref firstOcc, data);
     79                PwgProxyReponseHelper.buildQueryFromArray<Int32>(tagsId, "tag_id", ref firstOcc, data);
     80                PwgProxyReponseHelper.buildQueryFromArray<String>(tagsUrlName, "tag_url_name", ref firstOcc, data);
     81                PwgProxyReponseHelper.buildQueryFromArray<String>(tagsName, "tag_name", ref firstOcc, data);
    8082
    81                 if (tagModeAnd.HasValue)
    82                 {
    83                     data.Append("&tag_mode_and=" + HttpUtility.UrlEncode(tagModeAnd.ToString().ToLower()));
    84                 }
    85                 if (perPage.HasValue)
    86                 {
    87                     data.Append("&per_page=" + HttpUtility.UrlEncode(perPage.ToString().ToLower()));
    88                 }
    89                 if (Page.HasValue)
    90                 {
    91                     data.Append("&page=" + HttpUtility.UrlEncode(Page.ToString().ToLower()));
    92                 }
    93                 if (Order.HasValue)
    94                 {
    95                     data.Append("&order=" + HttpUtility.UrlEncode(Order.ToString().ToLower()));
    96                 }
    97                 if (minRate.HasValue)
    98                 {
    99                     data.Append("&f_min_rate=" + HttpUtility.UrlEncode(minRate.ToString().ToLower()));
    100                 }
    101                 if (maxRate.HasValue)
    102                 {
    103                     data.Append("&f_max_rate=" + HttpUtility.UrlEncode(maxRate.ToString().ToLower()));
    104                 }
    105                 if (minHit.HasValue)
    106                 {
    107                     data.Append("&f_min_hit=" + HttpUtility.UrlEncode(minHit.ToString().ToLower()));
    108                 }
    109                 if (maxHit.HasValue)
    110                 {
    111                     data.Append("&f_max_hit=" + HttpUtility.UrlEncode(maxHit.ToString().ToLower()));
    112                 }
    113                 if (minDateAvailable.HasValue)
    114                 {
    115                     data.Append("&f_min_date_available=" + HttpUtility.UrlEncode(minDateAvailable.ToString().ToLower()));
    116                 }
    117                 if (maxDateAvailable.HasValue)
    118                 {
    119                     data.Append("&f_max_date_available=" + HttpUtility.UrlEncode(maxDateAvailable.ToString().ToLower()));
    120                 }
    121                 if (minDateCreated.HasValue)
    122                 {
    123                     data.Append("&f_min_date_created=" + HttpUtility.UrlEncode(minDateCreated.ToString().ToLower()));
    124                 }
    125                 if (maxDateCreated.HasValue)
    126                 {
    127                     data.Append("&f_max_date_created=" + HttpUtility.UrlEncode(maxDateCreated.ToString().ToLower()));
    128                 }
    129                 if (minRatio.HasValue)
    130                 {
    131                     data.Append("&f_min_ratio=" + HttpUtility.UrlEncode(minRatio.ToString().ToLower()));
    132                 }
    133                 if (maxRatio.HasValue)
    134                 {
    135                     data.Append("&f_max_ratio=" + HttpUtility.UrlEncode(maxRatio.ToString().ToLower()));
    136                 }
    137                 if (withThumbnail.HasValue)
    138                 {
    139                     data.Append("&f_with_thumbnail=" + HttpUtility.UrlEncode(withThumbnail.ToString().ToLower()));
    140                 }
     83                PwgProxyReponseHelper.buildQueryFromValue<Boolean>(tagModeAnd, "tag_mode_and", ref firstOcc, data);
     84                PwgProxyReponseHelper.buildQueryFromValue<Int32>(perPage, "per_page", ref firstOcc, data);
     85                PwgProxyReponseHelper.buildQueryFromValue<Int32>(Page, "page", ref firstOcc, data);
     86                PwgProxyReponseHelper.buildQueryFromValue<Int32>(Order, "order", ref firstOcc, data);
     87                PwgProxyReponseHelper.buildQueryFromValue<Int32>(minRate, "f_min_rate", ref firstOcc, data);
     88                PwgProxyReponseHelper.buildQueryFromValue<Int32>(maxRate, "f_max_rate", ref firstOcc, data);
     89                PwgProxyReponseHelper.buildQueryFromValue<Int32>(minHit, "f_min_hit", ref firstOcc, data);
     90                PwgProxyReponseHelper.buildQueryFromValue<Int32>(maxHit, "f_max_hit", ref firstOcc, data);
     91                PwgProxyReponseHelper.buildQueryFromValue<DateTime>(minDateAvailable, "f_min_date_available", ref firstOcc, data);
     92                PwgProxyReponseHelper.buildQueryFromValue<DateTime>(maxDateAvailable, "f_max_date_available", ref firstOcc, data);
     93                PwgProxyReponseHelper.buildQueryFromValue<DateTime>(minDateCreated, "f_min_date_created", ref firstOcc, data);
     94                PwgProxyReponseHelper.buildQueryFromValue<DateTime>(maxDateCreated, "f_max_date_created", ref firstOcc, data);
     95                PwgProxyReponseHelper.buildQueryFromValue<Int32>(minRatio, "f_min_ratio", ref firstOcc, data);
     96                PwgProxyReponseHelper.buildQueryFromValue<Int32>(maxRatio, "f_max_ratio", ref firstOcc, data);
     97                PwgProxyReponseHelper.buildQueryFromValue<Boolean>(withThumbnail, "f_with_thumbnail", ref firstOcc, data);
    14198
    14299                response = PwgGenericProxy<PwgImagesProxyResponse>.Post(
     
    151108
    152109        }
    153         static public PwgTagsProxyResponse pwg_tag_add(string tagName)
     110        static public PwgAddRequestProxyResponse pwg_tag_add(string tagName)
    154111        {
    155             PwgTagsProxyResponse response = null;
     112            PwgAddRequestProxyResponse response = null;
    156113            try
    157114            {
     
    160117                data.Append("&name=" + HttpUtility.UrlEncode(tagName));
    161118
    162                 response = PwgGenericProxy<PwgTagsProxyResponse>.Post(
     119                response = PwgGenericProxy<PwgAddRequestProxyResponse>.Post(
    163120                    PwgConfigProxy.PwgServeurUriBuilder.Uri,
    164121                    data.ToString());
  • extensions/PiwigoLib/PiwigoLib/Proxy/Response/PwgAddRequestProxyResponse.cs

    r3833 r3834  
    99{
    1010    [Serializable()]
    11     [XmlRoot(ElementName = "tag")]
    12     public class PwgTagProxyResponse
     11    [XmlRoot(ElementName = "rsp")]
     12    public class PwgAddRequestProxyResponse : PwgBaseProxyReponse
    1313    {
    14         [XmlAttribute(AttributeName = "id")]
    15         public Int32 Id { get; set; }
    16         [XmlAttribute(AttributeName = "name")]
    17         public String Name { get; set; }
    18         [XmlAttribute(AttributeName = "url_name")]
    19         public String UrlName { get; set; }
    20         [XmlAttribute(AttributeName = "counter")]
    21         public Int64 Counter { get; set; }
    22         [XmlAttribute(AttributeName = "url")]
    23         public String UrlTag { get; set; }
    24     }
     14        [XmlElement(ElementName="info")]
     15        public String Message { get; set; }
     16        [XmlElement(ElementName = "id")]
     17        public Int32 NewId { get; set; }
    2518
    26     [Serializable()]
    27     [XmlRoot(ElementName = "rsp")]
    28     public class PwgTagsProxyResponse : PwgBaseProxyReponse
    29     {
    30         //[XmlElement(ElementName = "tags")]
    31         [XmlArray("tags")]
    32         [XmlArrayItem("tag")]
    33         public PwgTagProxyResponse[] Tags { get; set; }
    3419    }
    3520}
  • extensions/PiwigoLib/PiwigoLib/Proxy/Response/PwgCategoriesProxyResponse.cs

    r3827 r3834  
    99{
    1010    [Serializable()]
    11     [XmlRoot(ElementName = "categories")]
     11    [XmlRoot(ElementName = "category")]
    1212    public class PwgCategoryProxyResponse
    1313    {
    1414        [XmlAttribute(AttributeName = "id")]
    1515        public Int32 Id { get; set; }
    16         [XmlAttribute(AttributeName = "name")]
     16        [XmlElement(ElementName = "uppercats")]
     17        public String UpperCategoryId { get; set; }
     18        [XmlElement (ElementName = "name")]
    1719        public String Name { get; set; }
    18         [XmlAttribute(AttributeName = "url_name")]
    19         public String UrlName { get; set; }
    20         [XmlAttribute(AttributeName = "counter")]
    21         public Int64 Counter { get; set; }
    2220        [XmlAttribute(AttributeName = "url")]
    23         public String UrlTag { get; set; }
     21        public String Url { get; set; }
     22        [XmlAttribute(AttributeName = "nb_images")]
     23        public Int64 ImagesCount { get; set; }
     24        [XmlAttribute(AttributeName = "total_nb_images")]
     25        public Int64 DeepImagesCount { get; set; }
     26        [XmlAttribute(AttributeName = "nb_categories")]
     27        public Int64 SubCategoriesCount { get; set; }
     28        [XmlAttribute(AttributeName = "max_date_last")]
     29        public String LastDate { get; set; }
    2430    }
    2531
    2632    [Serializable()]
    2733    [XmlRoot(ElementName = "rsp")]
    28     public class PwgcategoriesProxyResponse : PwgBaseProxyReponse
     34    public class PwgCategoriesProxyResponse : PwgBaseProxyReponse
    2935    {
    3036        [XmlArray("categories")]
Note: See TracChangeset for help on using the changeset viewer.