source: extensions/PiwigoLib/PiwigoLib/Service/PwgTagsService.cs @ 3827

Last change on this file since 3827 was 3827, checked in by bayral, 15 years ago

pwg.tags.getImages support

File size: 10.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using Com.Piwigo.Lib.DTO;
6using Com.Piwigo.Lib.Proxy;
7using Com.Piwigo.Lib.Proxy.Response;
8using Com.Piwigo.Lib.DTO.Helper;
9
10namespace Com.Piwigo.Lib.Service
11{
12
13    static public class PwgTagsService
14    {
15        /// <summary>
16        /// Get the list of tags the user is connected can access
17        /// </summary>
18        /// <param name="sortedByCounter"></param>
19        /// <returns></returns>
20        static public List<PwgTag> GetListOfTag(Boolean sortedByCounter)
21        {
22            List<PwgTag> returnValue = new List<PwgTag>();
23
24            try
25            {
26                PwgTagsProxyResponse response = PwgTagsProxy.pwg_tags_getList(sortedByCounter);
27
28                if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok)
29                {
30                    if (response.Erreur != null)
31                    {
32                        throw new PwgServiceException("GetListOfPwgTag, the server has return the error.",
33                            response.Erreur.Code,
34                            response.Erreur.Message);
35                    }
36                    else
37                    {
38                        throw new PwgServiceException("GetListOfPwgTag : a error occurs during server process.");
39                    }
40                }
41                else
42                {
43                    returnValue = ConvertProxyResponseToDTO(response);
44                }
45            }
46            catch (PwgProxyException ex)
47            {
48                throw new PwgServiceException("GetListOfPwgTag : a error is raised by proxy.", ex);
49            }
50            return returnValue;
51        }
52
53        /// <summary>
54        /// Get the list of all atgs in piwigo, you must be connected with a high level user
55        /// </summary>
56        /// <param name="sortedByCounter"></param>
57        /// <returns></returns>
58        static public List<PwgTag> GetAdminListOfTag()
59        {
60            List<PwgTag> returnValue = new List<PwgTag>();
61
62            try
63            {
64                PwgTagsProxyResponse response = PwgTagsProxy.pwg_tags_getAdminList();
65
66                if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok)
67                {
68                    if (response.Erreur != null)
69                    {
70                        throw new PwgServiceException("GetAdminListOfTag, the server has return the error.",
71                            response.Erreur.Code,
72                            response.Erreur.Message);
73                    }
74                    else
75                    {
76                        throw new PwgServiceException("GetAdminListOfTag : a error occurs during server process.");
77                    }
78                }
79                else
80                {
81                    returnValue = ConvertProxyResponseToDTO(response);
82                }
83            }
84            catch (PwgProxyException ex)
85            {
86                throw new PwgServiceException("GetAdminListOfTag : a error is raised by proxy.", ex);
87            }
88            return returnValue;
89        }
90
91
92        static public Boolean AddTag(String tagName)
93        {
94            Boolean returnValue = false;
95
96            try
97            {
98                PwgTagsProxyResponse response = PwgTagsProxy.pwg_tag_add(tagName);
99
100                if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok)
101                {
102                    if (response.Erreur != null)
103                    {
104                        throw new PwgServiceException("AddTag, the server has return the error.",
105                            response.Erreur.Code,
106                            response.Erreur.Message);
107                    }
108                    else
109                    {
110                        throw new PwgServiceException("AddTag : a error occurs during server process.");
111                    }
112                }
113                else
114                {
115                    returnValue = true;
116                }
117            }
118            catch (PwgProxyException ex)
119            {
120                throw new PwgServiceException("AddTag : a error is raised by proxy.", ex);
121            }
122            return returnValue;
123        }
124
125        /// <summary>
126        /// private: convert response to dto object
127        /// </summary>
128        /// <param name="response"></param>
129        /// <param name="session"></param>
130        static private List<PwgTag> ConvertProxyResponseToDTO(PwgTagsProxyResponse response)
131        {
132            List<PwgTag> returnValue = new List<PwgTag>();
133
134            foreach (PwgTagProxyResponse respTag in response.Tags)
135            {
136                returnValue.Add(ConvertProxyResponseToDTO(respTag));
137            }
138
139            return returnValue;
140        }
141
142        static public List<PwgImage> GetListOfImagesFormTags(List<Int32> tagsId,
143                                                            List<String> tagsUrlName,
144                                                            List<String> tagsName,
145                                                            Boolean? tagModeAnd,
146                                                            Int32? perPage,
147                                                            Int32? Page,
148                                                            Int32? Order,
149                                                            Int32? minRate,
150                                                            Int32? maxRate,
151                                                            Int32? minHit,
152                                                            Int32? maxHit,
153                                                            DateTime? minDateAvailable,
154                                                            DateTime? maxDateAvailable,
155                                                            DateTime? minDateCreated,
156                                                            DateTime? maxDateCreated,
157                                                            Int32? minRatio,
158                                                            Int32? maxRatio,
159                                                            Boolean? withThumbnail,
160                                                            ref Int32 PageReturned,
161                                                            ref Int32 PerPageeReturned,
162                                                            ref Int32 CountReturned)
163        {
164            List<PwgImage> returnValue = new List<PwgImage>();
165
166            try
167            {
168                PwgImagesProxyResponse response = PwgTagsProxy.pwg_tags_getImages(tagsId,
169                                                            tagsUrlName,
170                                                            tagsName,
171                                                            tagModeAnd,
172                                                            perPage,
173                                                            Page,
174                                                            Order,
175                                                            minRate,
176                                                            maxRate,
177                                                            minHit,
178                                                            maxHit,
179                                                            minDateAvailable,
180                                                            maxDateAvailable,
181                                                            minDateCreated,
182                                                            maxDateCreated,
183                                                            minRatio,
184                                                            maxRatio,
185                                                            withThumbnail);
186
187                if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok)
188                {
189                    if (response.Erreur != null)
190                    {
191                        throw new PwgServiceException("GetListOfImagesFormTags, the server has return the error.",
192                            response.Erreur.Code,
193                            response.Erreur.Message);
194                    }
195                    else
196                    {
197                        throw new PwgServiceException("GetListOfImagesFormTags : a error occurs during server process.");
198                    }
199                }
200                else
201                {
202                    PwgImagesService.ConvertProxyResponseToDTO(response, returnValue,
203                                                            ref PageReturned,
204                                                            ref PerPageeReturned,
205                                                            ref CountReturned);
206                }
207            }
208            catch (PwgProxyException ex)
209            {
210                throw new PwgServiceException("GetListOfImagesFormTags : a error is raised by proxy.", ex);
211            }
212            return returnValue;
213        }
214
215        /// <summary>
216        /// private: convert response to dto object
217        /// </summary>
218        /// <param name="response"></param>
219        /// <param name="session"></param>
220        static private PwgTag ConvertProxyResponseToDTO(PwgTagProxyResponse response)
221        {
222            PwgTag returnValue = new PwgTag();
223
224            try
225            {
226                returnValue.Counter = response.Counter;
227                returnValue.Id = response.Id;
228                returnValue.Name = response.Name;
229                returnValue.UrlName = response.UrlName;
230
231                if (String.IsNullOrEmpty(response.UrlTag))
232                {
233                    returnValue.UrlTag = null;
234                }
235                else
236                {
237                    returnValue.UrlTag = (new UriBuilder(response.UrlTag)).Uri;
238                }
239            }
240            catch (Exception ex)
241            {
242                throw new PwgServiceException("ConvertProxyResponseToDTO : a error is raised when converting PwgTagProxyResponse.", ex);
243            }
244
245            return returnValue;
246        }
247    }
248}
Note: See TracBrowser for help on using the repository browser.