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

Last change on this file since 11903 was 11903, checked in by bayral, 13 years ago

pwg.image.addImage work fine.

File size: 10.8 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                   pwg_images_add
18         * pwg.images.addChunk              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               pwg_images_getInfos
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        static internal PwgBaseProxyReponse pwg_images_add(String fileMd5sum, String thunbMd5sum, String HighresMd5sum, 
35            String imageMd5sum,  String imageFilename, String imageName, String imageAuthor, DateTime creationDate, 
36            String authorComment,List<String> lstCategories, List<String> lstTags, PwgConfidentLevelEnum? confidentLevel)
37        {
38            PwgBaseProxyReponse response = null;
39            try
40            {           
41                StringBuilder data = new StringBuilder();
42                data.Append("method=pwg.images.add");
43                Boolean firstOcc = false;
44                PwgProxyReponseHelper.buildQueryFromValue<String>(fileMd5sum, "file_sum", ref firstOcc, data);
45                PwgProxyReponseHelper.buildQueryFromValue<String>(thunbMd5sum, "thumbnail_sum", ref firstOcc, data);
46                PwgProxyReponseHelper.buildQueryFromValue<String>(HighresMd5sum, "high_sum", ref firstOcc, data);
47                PwgProxyReponseHelper.buildQueryFromValue<String>(imageMd5sum, "original_sum", ref firstOcc, data);
48                PwgProxyReponseHelper.buildQueryFromValue<String>(imageFilename, "original_filename", ref firstOcc, data);
49                PwgProxyReponseHelper.buildQueryFromValue<String>(imageName, "name", ref firstOcc, data);
50                PwgProxyReponseHelper.buildQueryFromValue<String>(imageAuthor, "author", ref firstOcc, data);
51                PwgProxyReponseHelper.buildQueryFromValue<String>(authorComment, "comment", ref firstOcc, data);
52                PwgProxyReponseHelper.buildQueryFromArray<String>(lstCategories, "categories", ref firstOcc, data);
53                PwgProxyReponseHelper.buildQueryFromArray<String>(lstTags, "tag_ids", ref firstOcc, data);
54                PwgProxyReponseHelper.buildQueryFromValue<Int32>((int?)confidentLevel, "level", ref firstOcc, data);
55                PwgProxyReponseHelper.buildQueryFromValue<DateTime>(creationDate, "date_creation", ref firstOcc, data);
56
57                response = PwgGenericProxy<PwgBaseProxyReponse>.Post(
58                    PwgConfigProxy.PwgServeurUri,
59                    data.ToString());
60            }
61            catch (Exception ex)
62            {
63                throw new PwgProxyException("pwg_images_rate", ex);
64            }
65
66            return response;
67        }
68
69       /// <summary>
70       /// pwg.images.addChunk
71       /// </summary>
72       /// <param name="strb64Data"></param>
73       /// <param name="uniqueId"></param>
74       /// <param name="fileType"></param>
75       /// <param name="?"></param>
76       /// <param name="chunckNumber"></param>
77       /// <returns></returns>
78        static internal PwgBaseProxyReponse pwg_images_addChunk(String strb64Data, String uniqueId, PwgFileTypeEnum fileType, Int32 chunckNumber )
79        {
80            PwgBaseProxyReponse response = null;
81            try
82            {
83               
84                StringBuilder data = new StringBuilder();
85                data.Append("method=pwg.images.addChunk");
86                Boolean firstOcc = false;
87                PwgProxyReponseHelper.buildQueryFromValue<String>(strb64Data, "data", ref firstOcc, data);
88                PwgProxyReponseHelper.buildQueryFromValue<String>(uniqueId, "original_sum", ref firstOcc, data);
89                PwgProxyReponseHelper.buildQueryFromValue<PwgFileTypeEnum>(fileType, "type", ref firstOcc, data);
90                PwgProxyReponseHelper.buildQueryFromValue<Int32>(chunckNumber, "position", ref firstOcc, data);
91
92                response = PwgGenericProxy<PwgBaseProxyReponse>.Post(
93                    PwgConfigProxy.PwgServeurUri,
94                    data.ToString());
95            }
96            catch (Exception ex)
97            {
98                throw new PwgProxyException("pwg_images_rate", ex);
99            }
100
101            return response;
102        }
103
104        /// <summary>
105        /// pwg.images.rate
106        /// </summary>
107        /// <param name="imageId"></param>
108        /// <param name="imageRate"></param>
109        /// <returns></returns>
110        static internal PwgImageRateProxyResponse pwg_images_rate(Int32 imageId, Int32 imageRate)
111        {
112            PwgImageRateProxyResponse response = null;
113            try
114            {
115                StringBuilder data = new StringBuilder();
116                data.Append("method=pwg.images.rate");
117                Boolean firstOcc = false;
118                PwgProxyReponseHelper.buildQueryFromValue<Int32>(imageId, "image_id", ref firstOcc, data);
119                PwgProxyReponseHelper.buildQueryFromValue<Int32>(imageRate, "rate", ref firstOcc, data);
120
121                response = PwgGenericProxy<PwgImageRateProxyResponse>.Post(
122                    PwgConfigProxy.PwgServeurUri,
123                    data.ToString());
124            }
125            catch (Exception ex)
126            {
127                throw new PwgProxyException("pwg_images_rate", ex);
128            }
129
130            return response;
131        }
132
133        /// <summary>
134        /// pwg.images.addSimple
135        /// </summary>
136        /// <param name="fileImage"></param>
137        /// <param name="imageId"></param>
138        /// <param name="categoryId"></param>
139        /// <param name="imageName"></param>
140        /// <param name="imageAuthor"></param>
141        /// <param name="imageComment"></param>
142        /// <param name="imageLevel"></param>
143        /// <param name="imageTags"></param>
144        /// <returns></returns>
145        static internal PwgAddSimpleImageProxyResponse pwg_images_addSimple(FileInfo fileImage, Int32? imageId, Int32? categoryId, String imageName, String imageAuthor, String imageComment, Int32? imageLevel, List<PwgTag> imageTags)
146        {
147            PwgAddSimpleImageProxyResponse response = null;
148
149            Dictionary<String, String> dcFiles  = new Dictionary<string,string>();
150            Dictionary<String, String> dcFields = new Dictionary<string,string>();
151            String stringData = String.Empty;
152
153            try
154            {
155                dcFields.Add("method", "pwg.images.addSimple");
156                PwgProxyReponseHelper.buildDicFieldFromValue<Int32>(imageId, "image_id", ref dcFields);
157                PwgProxyReponseHelper.buildDicFieldFromValue<Int32>(categoryId, "category", ref dcFields);
158                PwgProxyReponseHelper.buildDicFieldFromValue<Int32>(imageLevel, "level", ref dcFields);
159                PwgProxyReponseHelper.buildDicFieldFromValue<String>(imageName, "name", ref dcFields);
160                PwgProxyReponseHelper.buildDicFieldFromValue<String>(imageAuthor, "author", ref dcFields);
161                PwgProxyReponseHelper.buildDicFieldFromValue<String>(imageComment,"comment",  ref dcFields);
162                PwgProxyReponseHelper.buildDicFieldFromArray<PwgTag>(imageTags, "tags", ref dcFields);
163
164                if ((fileImage != null) && (fileImage.Exists)) 
165                {
166                    dcFiles.Add("image", fileImage.FullName); 
167                }
168                else
169                {
170                    throw new PwgProxyException("pwg_images_addSimple : no file or wrong file info provided for fileImage");
171                }
172
173                response = PwgGenericProxy<PwgAddSimpleImageProxyResponse>.PostAsMultiPartForm(PwgConfigProxy.PwgServeurUri, dcFiles, dcFields);           
174            }
175            catch (Exception ex)
176            {
177                throw new PwgProxyException("pwg_images_addSimple", ex);
178            }
179
180            return response;
181        }
182
183        /// <summary>
184        /// pwg.images.delete
185        /// </summary>
186        /// <param name="imageId"></param>
187        /// <param name="SecurityToken"></param>
188        /// <returns></returns>
189        static internal PwgBaseProxyReponse pwg_images_delete(Int32 imageId,
190                                                              String SecurityToken)
191        {
192            PwgBaseProxyReponse response = null;
193            try
194            {
195                StringBuilder data = new StringBuilder();
196                Boolean firstOcc = true;
197                data.Append("method=pwg.images.delete");
198                firstOcc = false;
199                PwgProxyReponseHelper.buildQueryFromValue<Int32>(imageId, "image_id", ref firstOcc, data);
200                PwgProxyReponseHelper.buildQueryFromValue<String>(SecurityToken, "pwg_token", ref firstOcc, data);
201
202                response = PwgGenericProxy<PwgBaseProxyReponse>.Post(
203                                PwgConfigProxy.PwgServeurUri,
204                                data.ToString());
205            }
206            catch (Exception ex)
207            {
208                throw new PwgProxyException("pwg_images_delete", ex);
209            }
210
211            return response;
212        }
213
214        static internal PwgImageInfoProxyResponse pwg_images_getInfos(Int32 imageId, Int32? commentPage, Int32? commentsPerPage)
215        {
216            PwgImageInfoProxyResponse response = null;
217            try
218            {
219                StringBuilder data = new StringBuilder();
220                Boolean firstOcc = true;
221                data.Append("method=pwg.images.getInfo");
222                firstOcc = false;
223                PwgProxyReponseHelper.buildQueryFromValue<Int32>(imageId, "image_id", ref firstOcc, data);
224                PwgProxyReponseHelper.buildQueryFromValue<Int32>(commentPage, "comments_page", ref firstOcc, data);
225                PwgProxyReponseHelper.buildQueryFromValue<Int32>(commentsPerPage, "comments_per_page", ref firstOcc, data);
226
227                response = PwgGenericProxy<PwgImageInfoProxyResponse>.Post(
228                                PwgConfigProxy.PwgServeurUri,
229                                data.ToString());
230            }
231            catch (Exception ex)
232            {
233                throw new PwgProxyException("pwg_images_getInfos", ex);
234            }
235
236            return response;
237        }
238
239    }
240
241}
242
Note: See TracBrowser for help on using the repository browser.