1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.Text; |
---|
4 | |
---|
5 | using Com.Piwigo.Lib.DTO; |
---|
6 | using Com.Piwigo.Lib.Proxy; |
---|
7 | using Com.Piwigo.Lib.Proxy.Response; |
---|
8 | using Com.Piwigo.Lib.DTO.Helper; |
---|
9 | |
---|
10 | namespace 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 | /// <summary> |
---|
92 | /// Add a Tag |
---|
93 | /// </summary> |
---|
94 | /// <param name="tagName"></param> |
---|
95 | /// <returns></returns> |
---|
96 | static public Boolean AddTag(String tagName, ref Int32 newId, ref String messageInfo) |
---|
97 | { |
---|
98 | Boolean returnValue = false; |
---|
99 | |
---|
100 | try |
---|
101 | { |
---|
102 | PwgAddRequestProxyResponse response = PwgTagsProxy.pwg_tag_add(tagName); |
---|
103 | |
---|
104 | if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok) |
---|
105 | { |
---|
106 | if (response.Erreur != null) |
---|
107 | { |
---|
108 | throw new PwgServiceException("AddTag, the server has return the error.", |
---|
109 | response.Erreur.Code, |
---|
110 | response.Erreur.Message); |
---|
111 | } |
---|
112 | else |
---|
113 | { |
---|
114 | throw new PwgServiceException("AddTag : a error occurs during server process."); |
---|
115 | } |
---|
116 | } |
---|
117 | else |
---|
118 | { |
---|
119 | returnValue = true; |
---|
120 | newId = response.NewId; |
---|
121 | messageInfo = response.Message; |
---|
122 | } |
---|
123 | } |
---|
124 | catch (PwgProxyException ex) |
---|
125 | { |
---|
126 | throw new PwgServiceException("AddTag : a error is raised by proxy.", ex); |
---|
127 | } |
---|
128 | return returnValue; |
---|
129 | } |
---|
130 | |
---|
131 | /// <summary> |
---|
132 | /// Return the list of image form a list of tag |
---|
133 | /// </summary> |
---|
134 | /// <param name="tagsId"></param> |
---|
135 | /// <param name="tagsUrlName"></param> |
---|
136 | /// <param name="tagsName"></param> |
---|
137 | /// <param name="tagModeAnd"></param> |
---|
138 | /// <param name="perPage"></param> |
---|
139 | /// <param name="Page"></param> |
---|
140 | /// <param name="Order"></param> |
---|
141 | /// <param name="minRate"></param> |
---|
142 | /// <param name="maxRate"></param> |
---|
143 | /// <param name="minHit"></param> |
---|
144 | /// <param name="maxHit"></param> |
---|
145 | /// <param name="minDateAvailable"></param> |
---|
146 | /// <param name="maxDateAvailable"></param> |
---|
147 | /// <param name="minDateCreated"></param> |
---|
148 | /// <param name="maxDateCreated"></param> |
---|
149 | /// <param name="minRatio"></param> |
---|
150 | /// <param name="maxRatio"></param> |
---|
151 | /// <param name="withThumbnail"></param> |
---|
152 | /// <param name="PageReturned"></param> |
---|
153 | /// <param name="PerPageeReturned"></param> |
---|
154 | /// <param name="CountReturned"></param> |
---|
155 | /// <returns></returns> |
---|
156 | static public List<PwgImage> GetListOfImagesFormTags(List<Int32> tagsId, |
---|
157 | List<String> tagsUrlName, |
---|
158 | List<String> tagsName, |
---|
159 | Boolean? tagModeAnd, |
---|
160 | Int32? perPage, |
---|
161 | Int32? Page, |
---|
162 | Int32? Order, |
---|
163 | Int32? minRate, |
---|
164 | Int32? maxRate, |
---|
165 | Int32? minHit, |
---|
166 | Int32? maxHit, |
---|
167 | DateTime? minDateAvailable, |
---|
168 | DateTime? maxDateAvailable, |
---|
169 | DateTime? minDateCreated, |
---|
170 | DateTime? maxDateCreated, |
---|
171 | Int32? minRatio, |
---|
172 | Int32? maxRatio, |
---|
173 | Boolean? withThumbnail, |
---|
174 | ref Int32 PageReturned, |
---|
175 | ref Int32 PerPageeReturned, |
---|
176 | ref Int32 CountReturned) |
---|
177 | { |
---|
178 | List<PwgImage> returnValue = new List<PwgImage>(); |
---|
179 | |
---|
180 | try |
---|
181 | { |
---|
182 | PwgImagesProxyResponse response = PwgTagsProxy.pwg_tags_getImages(tagsId, |
---|
183 | tagsUrlName, |
---|
184 | tagsName, |
---|
185 | tagModeAnd, |
---|
186 | perPage, |
---|
187 | Page, |
---|
188 | Order, |
---|
189 | minRate, |
---|
190 | maxRate, |
---|
191 | minHit, |
---|
192 | maxHit, |
---|
193 | minDateAvailable, |
---|
194 | maxDateAvailable, |
---|
195 | minDateCreated, |
---|
196 | maxDateCreated, |
---|
197 | minRatio, |
---|
198 | maxRatio, |
---|
199 | withThumbnail); |
---|
200 | |
---|
201 | if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok) |
---|
202 | { |
---|
203 | if (response.Erreur != null) |
---|
204 | { |
---|
205 | throw new PwgServiceException("GetListOfImagesFormTags, the server has return the error.", |
---|
206 | response.Erreur.Code, |
---|
207 | response.Erreur.Message); |
---|
208 | } |
---|
209 | else |
---|
210 | { |
---|
211 | throw new PwgServiceException("GetListOfImagesFormTags : a error occurs during server process."); |
---|
212 | } |
---|
213 | } |
---|
214 | else |
---|
215 | { |
---|
216 | PwgImagesService.ConvertProxyResponseToDTO(response, returnValue, |
---|
217 | ref PageReturned, |
---|
218 | ref PerPageeReturned, |
---|
219 | ref CountReturned); |
---|
220 | } |
---|
221 | } |
---|
222 | catch (PwgProxyException ex) |
---|
223 | { |
---|
224 | throw new PwgServiceException("GetListOfImagesFormTags : a error is raised by proxy.", ex); |
---|
225 | } |
---|
226 | return returnValue; |
---|
227 | } |
---|
228 | |
---|
229 | |
---|
230 | /// <summary> |
---|
231 | /// private: convert response to dto object |
---|
232 | /// </summary> |
---|
233 | /// <param name="response"></param> |
---|
234 | /// <param name="session"></param> |
---|
235 | static public List<PwgTag> ConvertProxyResponseToDTO(PwgTagsProxyResponse response) |
---|
236 | { |
---|
237 | List<PwgTag> returnValue = new List<PwgTag>(); |
---|
238 | |
---|
239 | foreach (PwgTagProxyResponse respTag in response.Tags) |
---|
240 | { |
---|
241 | returnValue.Add(ConvertProxyResponseToDTO(respTag)); |
---|
242 | } |
---|
243 | |
---|
244 | return returnValue; |
---|
245 | } |
---|
246 | |
---|
247 | |
---|
248 | /// <summary> |
---|
249 | /// private: convert response to dto object |
---|
250 | /// </summary> |
---|
251 | /// <param name="response"></param> |
---|
252 | /// <param name="session"></param> |
---|
253 | static public PwgTag ConvertProxyResponseToDTO(PwgTagProxyResponse response) |
---|
254 | { |
---|
255 | PwgTag returnValue = new PwgTag(); |
---|
256 | |
---|
257 | try |
---|
258 | { |
---|
259 | returnValue.Counter = response.Counter; |
---|
260 | returnValue.Id = response.Id; |
---|
261 | returnValue.Name = response.Name; |
---|
262 | returnValue.UrlName = response.UrlName; |
---|
263 | |
---|
264 | if (String.IsNullOrEmpty(response.UrlTag)) |
---|
265 | { |
---|
266 | returnValue.UrlTag = null; |
---|
267 | } |
---|
268 | else |
---|
269 | { |
---|
270 | returnValue.UrlTag = (new UriBuilder(response.UrlTag)).Uri; |
---|
271 | } |
---|
272 | } |
---|
273 | catch (Exception ex) |
---|
274 | { |
---|
275 | throw new PwgServiceException("ConvertProxyResponseToDTO : a error is raised when converting PwgTagProxyResponse.", ex); |
---|
276 | } |
---|
277 | |
---|
278 | return returnValue; |
---|
279 | } |
---|
280 | } |
---|
281 | } |
---|