Skip to content

Commit bf72bcb

Browse files
committed
add Demo replace demo
1 parent 873175f commit bf72bcb

File tree

3 files changed

+368
-0
lines changed

3 files changed

+368
-0
lines changed

Demo/Demo.cs

Lines changed: 307 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
1+
using System;
2+
using QBox.Auth;
3+
using QBox.RS;
4+
using QBox.FileOp;
5+
6+
namespace QBox.Demo
7+
{
8+
public class Demo
9+
{
10+
public static string bucketName;
11+
public static string key;
12+
public static string localFile;
13+
public static string DEMO_DOMAIN;
14+
public static Client conn;
15+
public static RSService rs;
16+
public static ImageOp imageOp;
17+
18+
public static void Main()
19+
{
20+
Config.ACCESS_KEY = "<Please apply your access key>";
21+
Config.SECRET_KEY = "<Dont send your secret key to anyone>";
22+
23+
bucketName = "csharpbucket";
24+
DEMO_DOMAIN = "csharpbucket.dn.qbox.me";
25+
localFile = "Resource/gogopher.jpg";
26+
key = "gogopher.jpg";
27+
28+
conn = new DigestAuthClient();
29+
rs = new RSService(conn, bucketName);
30+
imageOp = new ImageOp(conn);
31+
32+
MkBucket();
33+
RSClientPutFile();
34+
Get();
35+
Stat();
36+
Publish();
37+
UnPublish();
38+
Delete();
39+
Drop();
40+
41+
MkBucket();
42+
RSPutFile();
43+
Publish();
44+
ImageOps();
45+
46+
Console.ReadLine();
47+
}
48+
49+
public static void MkBucket()
50+
{
51+
Console.WriteLine("\n===> RSService.MkBucket");
52+
CallRet callRet = rs.MkBucket();
53+
PrintRet(callRet);
54+
}
55+
56+
public static void RSPutFile()
57+
{
58+
Console.WriteLine("\n===> RSService.PutFile");
59+
PutFileRet putFileRet = rs.PutFile(key, null, localFile, null);
60+
PrintRet(putFileRet);
61+
if (putFileRet.OK)
62+
{
63+
Console.WriteLine("Hash: " + putFileRet.Hash);
64+
}
65+
else
66+
{
67+
Console.WriteLine("Failed to PutFile");
68+
}
69+
}
70+
71+
public static void RSClientPutFile()
72+
{
73+
Console.WriteLine("\n==> PutAuth");
74+
PutAuthRet putAuthRet = rs.PutAuth();
75+
PrintRet(putAuthRet);
76+
if (putAuthRet.OK)
77+
{
78+
Console.WriteLine("Expires: " + putAuthRet.Expires.ToString());
79+
Console.WriteLine("Url: " + putAuthRet.Url);
80+
}
81+
else
82+
{
83+
Console.WriteLine("Failed to PutAuth");
84+
}
85+
86+
Console.WriteLine("\n===> RSClient.PutFile");
87+
PutFileRet putFileRet = RSClient.PutFile(putAuthRet.Url, bucketName, key, null, localFile, null, "key=<key>");
88+
PrintRet(putFileRet);
89+
if (putFileRet.OK)
90+
{
91+
Console.WriteLine("Hash: " + putFileRet.Hash);
92+
}
93+
else
94+
{
95+
Console.WriteLine("Failed to RSClient.PutFile");
96+
}
97+
98+
Console.WriteLine("\n===> Generate UpToken");
99+
var authPolicy = new AuthPolicy(bucketName, 3600);
100+
string upToken = authPolicy.MakeAuthTokenString();
101+
Console.WriteLine("upToken: " + upToken);
102+
103+
Console.WriteLine("\n===> RSClient.PutFileWithUpToken");
104+
putFileRet = RSClient.PutFileWithUpToken(upToken, bucketName, key, null, localFile, null, "key=<key>");
105+
PrintRet(putFileRet);
106+
if (putFileRet.OK)
107+
{
108+
Console.WriteLine("Hash: " + putFileRet.Hash);
109+
}
110+
else
111+
{
112+
Console.WriteLine("Failed to RSClient.PutFileWithUpToken");
113+
}
114+
}
115+
116+
public static void Get()
117+
{
118+
Console.WriteLine("\n===> Get");
119+
GetRet getRet = rs.Get(key, "attName");
120+
PrintRet(getRet);
121+
if (getRet.OK)
122+
{
123+
Console.WriteLine("Hash: " + getRet.Hash);
124+
Console.WriteLine("FileSize: " + getRet.FileSize);
125+
Console.WriteLine("MimeType: " + getRet.MimeType);
126+
Console.WriteLine("Url: " + getRet.Url);
127+
}
128+
else
129+
{
130+
Console.WriteLine("Failed to Get");
131+
}
132+
133+
Console.WriteLine("\n===> GetIfNotModified");
134+
getRet = rs.GetIfNotModified(key, "attName", getRet.Hash);
135+
PrintRet(getRet);
136+
if (getRet.OK)
137+
{
138+
Console.WriteLine("Hash: " + getRet.Hash);
139+
Console.WriteLine("FileSize: " + getRet.FileSize);
140+
Console.WriteLine("MimeType: " + getRet.MimeType);
141+
Console.WriteLine("Url: " + getRet.Url);
142+
}
143+
else
144+
{
145+
Console.WriteLine("Failed to GetIfNotModified");
146+
}
147+
}
148+
149+
public static void Stat()
150+
{
151+
Console.WriteLine("\n===> Stat");
152+
StatRet statRet = rs.Stat(key);
153+
PrintRet(statRet);
154+
if (statRet.OK)
155+
{
156+
Console.WriteLine("Hash: " + statRet.Hash);
157+
Console.WriteLine("FileSize: " + statRet.FileSize);
158+
Console.WriteLine("PutTime: " + statRet.PutTime);
159+
Console.WriteLine("MimeType: " + statRet.MimeType);
160+
}
161+
else
162+
{
163+
Console.WriteLine("Failed to Stat");
164+
}
165+
}
166+
167+
public static void Delete()
168+
{
169+
Console.WriteLine("\n===> Delete");
170+
CallRet deleteRet = rs.Delete(key);
171+
PrintRet(deleteRet);
172+
if (!deleteRet.OK)
173+
{
174+
Console.WriteLine("Failed to Delete");
175+
}
176+
}
177+
178+
public static void Drop()
179+
{
180+
Console.WriteLine("\n===> Drop");
181+
CallRet dropRet = rs.Drop();
182+
PrintRet(dropRet);
183+
if (!dropRet.OK)
184+
{
185+
Console.WriteLine("Failed to Drop");
186+
}
187+
}
188+
189+
public static void Publish()
190+
{
191+
Console.WriteLine("\n===> Publish");
192+
CallRet publishRet = rs.Publish(DEMO_DOMAIN);
193+
PrintRet(publishRet);
194+
if (!publishRet.OK)
195+
{
196+
Console.WriteLine("Failed to Publish");
197+
}
198+
}
199+
200+
public static void UnPublish()
201+
{
202+
Console.WriteLine("\n===> UnPublish");
203+
CallRet publishRet = rs.Unpublish(DEMO_DOMAIN);
204+
PrintRet(publishRet);
205+
if (!publishRet.OK)
206+
{
207+
Console.WriteLine("Failed to UnPublish");
208+
}
209+
}
210+
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+
299+
public static void PrintRet(CallRet callRet)
300+
{
301+
Console.WriteLine("\n[CallRet]");
302+
Console.WriteLine("StatusCode: " + callRet.StatusCode.ToString());
303+
Console.WriteLine("Response:\n" + callRet.Response);
304+
Console.WriteLine();
305+
}
306+
}
307+
}

Demo/Demo.csproj

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{8BA368D7-3784-4C50-9A28-4FA1A9C81555}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>Demo</RootNamespace>
12+
<AssemblyName>Demo</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
15+
<FileAlignment>512</FileAlignment>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
18+
<PlatformTarget>x86</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
28+
<PlatformTarget>x86</PlatformTarget>
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Content Include="Resource\gogopher.jpg">
38+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
39+
</Content>
40+
</ItemGroup>
41+
<ItemGroup>
42+
<Compile Include="Demo.cs" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<ProjectReference Include="..\QBox\QBox.csproj">
46+
<Project>{1C8C9909-57ED-44E4-81A5-0904E96FA00E}</Project>
47+
<Name>QBox</Name>
48+
</ProjectReference>
49+
</ItemGroup>
50+
<ItemGroup>
51+
<Reference Include="System" />
52+
</ItemGroup>
53+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
54+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
55+
Other similar extension points exist, see Microsoft.Common.targets.
56+
<Target Name="BeforeBuild">
57+
</Target>
58+
<Target Name="AfterBuild">
59+
</Target>
60+
-->
61+
</Project>

Demo/Resource/gogopher.jpg

209 KB
Loading

0 commit comments

Comments
 (0)