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

Last change on this file since 11922 was 7149, checked in by bayral, 14 years ago

Piwigolib is now modify for mask the implementation of proxy.
Add start version of piwigo WPF

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