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

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

get Tags List support

File size: 4.8 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        /// <summary>
93        /// private: convert response to dto object
94        /// </summary>
95        /// <param name="response"></param>
96        /// <param name="session"></param>
97        static private List<PwgTag> ConvertProxyResponseToDTO(PwgTagsProxyResponse response)
98        {
99            List<PwgTag> returnValue = new List<PwgTag>();
100
101            foreach (PwgTagProxyResponse respTag in response.Tags)
102            {
103                returnValue.Add(ConvertProxyResponseToDTO(respTag));
104            }
105
106            return returnValue;
107        }
108
109        /// <summary>
110        /// private: convert response to dto object
111        /// </summary>
112        /// <param name="response"></param>
113        /// <param name="session"></param>
114        static private PwgTag ConvertProxyResponseToDTO(PwgTagProxyResponse response)
115        {
116            PwgTag returnValue = new PwgTag();
117
118            try
119            {
120                returnValue.Counter = response.Counter;
121                returnValue.Id = response.Id;
122                returnValue.Name = response.Name;
123                returnValue.UrlName = response.UrlName;
124
125                if (String.IsNullOrEmpty(response.UrlTag))
126                {
127                    returnValue.UrlTag = null;
128                }
129                else
130                {
131                    returnValue.UrlTag = (new UriBuilder(response.UrlTag)).Uri;
132                }
133            }
134            catch (Exception ex)
135            {
136                throw new PwgServiceException("ConvertProxyResponseToDTO : a error is raised when converting PwgTagProxyResponse.", ex);
137            }
138
139            return returnValue;
140        }
141    }
142}
Note: See TracBrowser for help on using the repository browser.