source: extensions/PiwigoLib/PiwigoLib/Proxy/PwgImagesProxy.cs @ 11872

Last change on this file since 11872 was 11872, checked in by bayral, 13 years ago
File size: 6.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using Com.Piwigo.Lib.DTO;
6using System.Web;
7using Com.Piwigo.Lib.Proxy.Response;
8using Com.Piwigo.Lib.Proxy.Helper;
9using System.IO;
10
11namespace Com.Piwigo.Lib.Proxy
12{
13    static internal class PwgImagesProxy
14    {
15
16        /*
17         * pwg.images.add
18         * pwg.images.addChunk
19         * pwg.images.addComment
20         * pwg.images.addFile               
21         * pwg.images.addSimple            pwg_images_addSimple
22         * pwg.images.checkFiles
23         * pwg.images.checkUpload
24         * pwg.images.delete               pwg_images_delete
25         * pwg.images.exist
26         * pwg.images.getInfo
27         * pwg.images.rate                  pwg_images_rate
28         * pwg.images.regenerateThumbnail
29         * pwg.images.search
30         * pwg.images.setInfo
31         * pwg.images.setPrivacyLevel
32 * */
33
34        /// <summary>
35        /// pwg.images.rate
36        /// </summary>
37        /// <param name="imageId"></param>
38        /// <param name="imageRate"></param>
39        /// <returns></returns>
40        static internal PwgImageRateProxyResponse pwg_images_rate(Int32 imageId, Int32 imageRate)
41        {
42            PwgImageRateProxyResponse response = null;
43            try
44            {
45                StringBuilder data = new StringBuilder();
46                data.Append("method=pwg.images.rate");
47                Boolean firstOcc = false;
48                PwgProxyReponseHelper.buildQueryFromValue<Int32>(imageId, "image_id", ref firstOcc, data);
49                PwgProxyReponseHelper.buildQueryFromValue<Int32>(imageRate, "rate", ref firstOcc, data);
50
51                response = PwgGenericProxy<PwgImageRateProxyResponse>.Post(
52                    PwgConfigProxy.PwgServeurUri,
53                    data.ToString());
54            }
55            catch (Exception ex)
56            {
57                throw new PwgProxyException("pwg_images_rate", ex);
58            }
59
60            return response;
61        }
62
63        /// <summary>
64        /// pwg.images.addSimple
65        /// </summary>
66        /// <param name="fileImage"></param>
67        /// <param name="imageId"></param>
68        /// <param name="categoryId"></param>
69        /// <param name="imageName"></param>
70        /// <param name="imageAuthor"></param>
71        /// <param name="imageComment"></param>
72        /// <param name="imageLevel"></param>
73        /// <param name="imageTags"></param>
74        /// <returns></returns>
75        static internal PwgAddSimpleImageProxyResponse pwg_images_addSimple(FileInfo fileImage, Int32? imageId, Int32? categoryId, String imageName, String imageAuthor, String imageComment, Int32? imageLevel, List<PwgTag> imageTags)
76        {
77            PwgAddSimpleImageProxyResponse response = null;
78
79            Dictionary<String, String> dcFiles  = new Dictionary<string,string>();
80            Dictionary<String, String> dcFields = new Dictionary<string,string>();
81            String stringData = String.Empty;
82
83            try
84            {
85                dcFields.Add("method", "pwg.images.addSimple");
86                PwgProxyReponseHelper.buildDicFieldFromValue<Int32>(imageId, "image_id", ref dcFields);
87                PwgProxyReponseHelper.buildDicFieldFromValue<Int32>(categoryId, "category", ref dcFields);
88                PwgProxyReponseHelper.buildDicFieldFromValue<Int32>(imageLevel, "level", ref dcFields);
89                PwgProxyReponseHelper.buildDicFieldFromValue<String>(imageName, "name", ref dcFields);
90                PwgProxyReponseHelper.buildDicFieldFromValue<String>(imageAuthor, "author", ref dcFields);
91                PwgProxyReponseHelper.buildDicFieldFromValue<String>(imageComment,"comment",  ref dcFields);
92                PwgProxyReponseHelper.buildDicFieldFromArray<PwgTag>(imageTags, "tags", ref dcFields);
93
94                if ((fileImage != null) && (fileImage.Exists)) 
95                {
96                    dcFiles.Add("image", fileImage.FullName); 
97                }
98                else
99                {
100                    throw new PwgProxyException("pwg_images_addSimple : no file or wrong file info provided for fileImage");
101                }
102
103                response = PwgGenericProxy<PwgAddSimpleImageProxyResponse>.PostAsMultiPartForm(PwgConfigProxy.PwgServeurUri, dcFiles, dcFields);           
104            }
105            catch (Exception ex)
106            {
107                throw new PwgProxyException("pwg_images_addSimple", ex);
108            }
109
110            return response;
111        }
112
113        /// <summary>
114        /// pwg.images.delete
115        /// </summary>
116        /// <param name="imageId"></param>
117        /// <param name="SecurityToken"></param>
118        /// <returns></returns>
119        static internal PwgBaseProxyReponse pwg_images_delete(Int32 imageId,
120                                                              String SecurityToken)
121        {
122            PwgBaseProxyReponse response = null;
123            try
124            {
125                StringBuilder data = new StringBuilder();
126                Boolean firstOcc = true;
127                data.Append("method=pwg.images.delete");
128                firstOcc = false;
129                PwgProxyReponseHelper.buildQueryFromValue<Int32>(imageId, "image_id", ref firstOcc, data);
130                PwgProxyReponseHelper.buildQueryFromValue<String>(SecurityToken, "pwg_token", ref firstOcc, data);
131
132                response = PwgGenericProxy<PwgBaseProxyReponse>.Post(
133                                PwgConfigProxy.PwgServeurUri,
134                                data.ToString());
135            }
136            catch (Exception ex)
137            {
138                throw new PwgProxyException("pwg_images_delete", ex);
139            }
140
141            return response;
142        }
143
144        static internal PwgImageInfoProxyResponse pwg_images_getInfos(Int32 imageId, Int32? commentPage, Int32? commentsPerPage)
145        {
146            PwgImageInfoProxyResponse response = null;
147            try
148            {
149                StringBuilder data = new StringBuilder();
150                Boolean firstOcc = true;
151                data.Append("method=pwg.images.getInfo");
152                firstOcc = false;
153                PwgProxyReponseHelper.buildQueryFromValue<Int32>(imageId, "image_id", ref firstOcc, data);
154                PwgProxyReponseHelper.buildQueryFromValue<Int32>(commentPage, "comments_page", ref firstOcc, data);
155                PwgProxyReponseHelper.buildQueryFromValue<Int32>(commentsPerPage, "comments_per_page", ref firstOcc, data);
156
157                response = PwgGenericProxy<PwgImageInfoProxyResponse>.Post(
158                                PwgConfigProxy.PwgServeurUri,
159                                data.ToString());
160            }
161            catch (Exception ex)
162            {
163                throw new PwgProxyException("pwg_images_getInfos", ex);
164            }
165
166            return response;
167        }
168
169    }
170
171}
172
Note: See TracBrowser for help on using the repository browser.