11using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Text ;
5- using System . Diagnostics ;
62using QBox . Auth ;
73using QBox . RS ;
4+ using QBox . FileOp ;
85
9- namespace QBox . Example
6+ namespace QBox . Demo
107{
11- public class RSDemo
8+ public class Demo
129 {
1310 public static string bucketName ;
1411 public static string key ;
1512 public static string localFile ;
1613 public static string DEMO_DOMAIN ;
1714 public static Client conn ;
1815 public static RSService rs ;
16+ public static ImageOp imageOp ;
1917
2018 public static void Main ( )
2119 {
2220 Config . ACCESS_KEY = "<Please apply your access key>" ;
2321 Config . SECRET_KEY = "<Dont send your secret key to anyone>" ;
2422
2523 bucketName = "csharpbucket" ;
26- DEMO_DOMAIN = "iovip.qbox.me/csharpbucket" ;
24+ DEMO_DOMAIN = "csharpbucket.dn.qbox.me" ;
25+ localFile = "Resource/gogopher.jpg" ;
26+ key = "gogopher.jpg" ;
27+
2728 conn = new DigestAuthClient ( ) ;
2829 rs = new RSService ( conn , bucketName ) ;
29- localFile = Process . GetCurrentProcess ( ) . MainModule . FileName ;
30- key = System . IO . Path . GetFileName ( localFile ) ;
31-
32- CallRet callRet = rs . MkBucket ( ) ;
33- PrintRet ( callRet ) ;
30+ imageOp = new ImageOp ( conn ) ;
3431
35- RSPutFile ( ) ;
32+ MkBucket ( ) ;
3633 RSClientPutFile ( ) ;
3734 Get ( ) ;
3835 Stat ( ) ;
@@ -41,9 +38,21 @@ public static void Main()
4138 Delete ( ) ;
4239 Drop ( ) ;
4340
41+ MkBucket ( ) ;
42+ RSPutFile ( ) ;
43+ Publish ( ) ;
44+ ImageOps ( ) ;
45+
4446 Console . ReadLine ( ) ;
4547 }
4648
49+ public static void MkBucket ( )
50+ {
51+ Console . WriteLine ( "\n ===> RSService.MkBucket" ) ;
52+ CallRet callRet = rs . MkBucket ( ) ;
53+ PrintRet ( callRet ) ;
54+ }
55+
4756 public static void RSPutFile ( )
4857 {
4958 Console . WriteLine ( "\n ===> RSService.PutFile" ) ;
@@ -199,6 +208,94 @@ public static void UnPublish()
199208 }
200209 }
201210
211+ public static void ImageOps ( )
212+ {
213+ Console . WriteLine ( "\n ===> ImageInfo" ) ;
214+ ImageInfoRet infoRet = imageOp . ImageInfo ( "http://" + DEMO_DOMAIN + "/" + key ) ;
215+ PrintRet ( infoRet ) ;
216+ if ( infoRet . OK )
217+ {
218+ Console . WriteLine ( "Format: " + infoRet . Format ) ;
219+ Console . WriteLine ( "Width: " + infoRet . Width ) ;
220+ Console . WriteLine ( "Heigth: " + infoRet . Height ) ;
221+ Console . WriteLine ( "ColorModel: " + infoRet . ColorModel ) ;
222+ }
223+ else
224+ {
225+ Console . WriteLine ( "Failed to ImageInfo" ) ;
226+ }
227+
228+ Console . WriteLine ( "\n ===> ImageExif" ) ;
229+ CallRet exifRet = imageOp . ImageExif ( "http://" + DEMO_DOMAIN + "/" + key ) ;
230+ PrintRet ( exifRet ) ;
231+ if ( ! exifRet . OK )
232+ {
233+ Console . WriteLine ( "Failed to ImageExif" ) ;
234+ }
235+
236+ Console . WriteLine ( "\n ===> ImageViewUrl" ) ;
237+ ImageViewSpec viewSpec = new ImageViewSpec { Mode = 0 , Width = 200 , Height = 200 } ;
238+ string viewUrl = imageOp . ImageViewUrl ( "http://" + DEMO_DOMAIN + "/" + key , viewSpec ) ;
239+ Console . WriteLine ( "ImageViewUrl 1:" + viewUrl ) ;
240+ viewSpec . Quality = 1 ;
241+ viewSpec . Format = "gif" ;
242+ viewUrl = imageOp . ImageViewUrl ( "http://" + DEMO_DOMAIN + "/" + key , viewSpec ) ;
243+ Console . WriteLine ( "ImageViewUrl 2:" + viewUrl ) ;
244+ viewSpec . Quality = 90 ;
245+ viewSpec . Sharpen = 10 ;
246+ viewSpec . Format = "png" ;
247+ viewUrl = imageOp . ImageViewUrl ( "http://" + DEMO_DOMAIN + "/" + key , viewSpec ) ;
248+ Console . WriteLine ( "ImageViewUrl 3:" + viewUrl ) ;
249+
250+ Console . WriteLine ( "\n ===> ImageMogrifyUrl" ) ;
251+ ImageMogrifySpec mogrSpec = new ImageMogrifySpec {
252+ Thumbnail = "!50x50r" , Gravity = "center" , Rotate = 90 ,
253+ Crop = "!50x50" , Quality = 80 , AutoOrient = true
254+ } ;
255+ string mogrUrl = imageOp . ImageMogrifyUrl ( "http://" + DEMO_DOMAIN + "/" + key , mogrSpec ) ;
256+ Console . WriteLine ( "ImageMogrifyUrl:" + mogrUrl ) ;
257+
258+ Console . WriteLine ( "\n ===> Get" ) ;
259+ GetRet getRet = rs . Get ( key , "save-as" ) ;
260+ PrintRet ( getRet ) ;
261+ if ( getRet . OK )
262+ {
263+ Console . WriteLine ( "Hash: " + getRet . Hash ) ;
264+ Console . WriteLine ( "FileSize: " + getRet . FileSize ) ;
265+ Console . WriteLine ( "MimeType: " + getRet . MimeType ) ;
266+ Console . WriteLine ( "Url: " + getRet . Url ) ;
267+ }
268+ else
269+ {
270+ Console . WriteLine ( "Failed to Get" ) ;
271+ }
272+ Console . WriteLine ( "\n ===> ImageMogrifySaveAs" ) ;
273+ PutFileRet saveAsRet = rs . ImageMogrifySaveAs ( getRet . Url , mogrSpec , key + ".mogr-save-as" ) ;
274+ PrintRet ( saveAsRet ) ;
275+ if ( saveAsRet . OK )
276+ {
277+ Console . WriteLine ( "Hash: " + saveAsRet . Hash ) ;
278+ }
279+ else
280+ {
281+ Console . WriteLine ( "Failed to ImageMogrifySaveAs" ) ;
282+ }
283+ Console . WriteLine ( "\n ===> Get" ) ;
284+ getRet = rs . Get ( key + ".mogr-save-as" , "mogr-save-as.jpg" ) ;
285+ PrintRet ( getRet ) ;
286+ if ( getRet . OK )
287+ {
288+ Console . WriteLine ( "Hash: " + getRet . Hash ) ;
289+ Console . WriteLine ( "FileSize: " + getRet . FileSize ) ;
290+ Console . WriteLine ( "MimeType: " + getRet . MimeType ) ;
291+ Console . WriteLine ( "Url: " + getRet . Url ) ;
292+ }
293+ else
294+ {
295+ Console . WriteLine ( "Failed to Get" ) ;
296+ }
297+ }
298+
202299 public static void PrintRet ( CallRet callRet )
203300 {
204301 Console . WriteLine ( "\n [CallRet]" ) ;
0 commit comments