Skip to content

Commit 8f37206

Browse files
committed
add uptoken-upload and mkbucket
1 parent f049706 commit 8f37206

29 files changed

+4234
-4248
lines changed

Example/RSDemo.cs

Lines changed: 78 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,50 @@
33
using System.Linq;
44
using System.Text;
55
using System.Diagnostics;
6+
using QBox.Auth;
7+
using QBox.RS;
68

7-
namespace QBox
9+
namespace QBox.Example
810
{
911
public class RSDemo
1012
{
11-
public static string tableName = "Bucket";
13+
public static string bucketName;
1214
public static string key;
1315
public static string localFile;
14-
public static string DEMO_DOMAIN = "iovip.qbox.me/bucket";
16+
public static string DEMO_DOMAIN;
1517
public static Client conn;
1618
public static RSService rs;
1719

1820
public static void Main()
1921
{
2022
Config.ACCESS_KEY = "<Please apply your access key>";
2123
Config.SECRET_KEY = "<Dont send your secret key to anyone>";
22-
24+
25+
bucketName = "csharpbucket";
26+
DEMO_DOMAIN = "iovip.qbox.me/csharpbucket";
2327
conn = new DigestAuthClient();
24-
rs = new RSService(conn, tableName);
28+
rs = new RSService(conn, bucketName);
2529
localFile = Process.GetCurrentProcess().MainModule.FileName;
2630
key = System.IO.Path.GetFileName(localFile);
2731

28-
try
29-
{
30-
PutFile();
31-
Get();
32-
Stat();
33-
Delete();
34-
CliPutFile();
35-
Get();
36-
Stat();
37-
Publish();
38-
UnPublish();
39-
Drop();
32+
CallRet callRet = rs.MkBucket();
33+
PrintRet(callRet);
4034

41-
UpToken();
42-
}
43-
catch (Exception e)
44-
{
45-
Console.WriteLine("RS Exception");
46-
Console.WriteLine(e.ToString());
47-
}
35+
RSPutFile();
36+
RSClientPutFile();
37+
Get();
38+
Stat();
39+
Publish();
40+
UnPublish();
41+
Delete();
42+
Drop();
4843

4944
Console.ReadLine();
5045
}
5146

52-
public static void PutFile()
47+
public static void RSPutFile()
5348
{
54-
Console.WriteLine("\n--- PutFile ---");
55-
PrintInput(tableName, key, localFile, null);
49+
Console.WriteLine("\n===> RSService.PutFile");
5650
PutFileRet putFileRet = rs.PutFile(key, null, localFile, null);
5751
PrintRet(putFileRet);
5852
if (putFileRet.OK)
@@ -65,10 +59,54 @@ public static void PutFile()
6559
}
6660
}
6761

62+
public static void RSClientPutFile()
63+
{
64+
Console.WriteLine("\n==> PutAuth");
65+
PutAuthRet putAuthRet = rs.PutAuth();
66+
PrintRet(putAuthRet);
67+
if (putAuthRet.OK)
68+
{
69+
Console.WriteLine("Expires: " + putAuthRet.Expires.ToString());
70+
Console.WriteLine("Url: " + putAuthRet.Url);
71+
}
72+
else
73+
{
74+
Console.WriteLine("Failed to PutAuth");
75+
}
76+
77+
Console.WriteLine("\n===> RSClient.PutFile");
78+
PutFileRet putFileRet = RSClient.PutFile(putAuthRet.Url, bucketName, key, null, localFile, null, "key=<key>");
79+
PrintRet(putFileRet);
80+
if (putFileRet.OK)
81+
{
82+
Console.WriteLine("Hash: " + putFileRet.Hash);
83+
}
84+
else
85+
{
86+
Console.WriteLine("Failed to RSClient.PutFile");
87+
}
88+
89+
Console.WriteLine("\n===> Generate UpToken");
90+
var authPolicy = new AuthPolicy(bucketName, 3600);
91+
string upToken = authPolicy.MakeAuthTokenString();
92+
Console.WriteLine("upToken: " + upToken);
93+
94+
Console.WriteLine("\n===> RSClient.PutFileWithUpToken");
95+
putFileRet = RSClient.PutFileWithUpToken(upToken, bucketName, key, null, localFile, null, "key=<key>");
96+
PrintRet(putFileRet);
97+
if (putFileRet.OK)
98+
{
99+
Console.WriteLine("Hash: " + putFileRet.Hash);
100+
}
101+
else
102+
{
103+
Console.WriteLine("Failed to RSClient.PutFileWithUpToken");
104+
}
105+
}
106+
68107
public static void Get()
69108
{
70-
Console.WriteLine("\n--- Get ---");
71-
PrintInput(tableName, key, null, null);
109+
Console.WriteLine("\n===> Get");
72110
GetRet getRet = rs.Get(key, "attName");
73111
PrintRet(getRet);
74112
if (getRet.OK)
@@ -83,8 +121,7 @@ public static void Get()
83121
Console.WriteLine("Failed to Get");
84122
}
85123

86-
Console.WriteLine("\n--- GetIfNotModified ---");
87-
PrintInput(tableName, key, null, null);
124+
Console.WriteLine("\n===> GetIfNotModified");
88125
getRet = rs.GetIfNotModified(key, "attName", getRet.Hash);
89126
PrintRet(getRet);
90127
if (getRet.OK)
@@ -102,8 +139,7 @@ public static void Get()
102139

103140
public static void Stat()
104141
{
105-
Console.WriteLine("\n--- Stat ---");
106-
PrintInput(tableName, key, null, null);
142+
Console.WriteLine("\n===> Stat");
107143
StatRet statRet = rs.Stat(key);
108144
PrintRet(statRet);
109145
if (statRet.OK)
@@ -121,9 +157,8 @@ public static void Stat()
121157

122158
public static void Delete()
123159
{
124-
Console.WriteLine("\n--- Delete ---");
125-
PrintInput(tableName, key, null, null);
126-
DeleteRet deleteRet = rs.Delete(key);
160+
Console.WriteLine("\n===> Delete");
161+
CallRet deleteRet = rs.Delete(key);
127162
PrintRet(deleteRet);
128163
if (!deleteRet.OK)
129164
{
@@ -133,9 +168,8 @@ public static void Delete()
133168

134169
public static void Drop()
135170
{
136-
Console.WriteLine("\n--- Drop ---");
137-
PrintInput(tableName, null, null, null);
138-
DropRet dropRet = rs.Drop();
171+
Console.WriteLine("\n===> Drop");
172+
CallRet dropRet = rs.Drop();
139173
PrintRet(dropRet);
140174
if (!dropRet.OK)
141175
{
@@ -145,9 +179,8 @@ public static void Drop()
145179

146180
public static void Publish()
147181
{
148-
Console.WriteLine("\n--- Publish ---");
149-
PrintInput(tableName, null, null, DEMO_DOMAIN);
150-
PublishRet publishRet = rs.Publish(DEMO_DOMAIN);
182+
Console.WriteLine("\n===> Publish");
183+
CallRet publishRet = rs.Publish(DEMO_DOMAIN);
151184
PrintRet(publishRet);
152185
if (!publishRet.OK)
153186
{
@@ -157,83 +190,18 @@ public static void Publish()
157190

158191
public static void UnPublish()
159192
{
160-
Console.WriteLine("\n--- UnPublish ---");
161-
PrintInput(tableName, null, null, DEMO_DOMAIN);
162-
PublishRet publishRet = rs.Unpublish(DEMO_DOMAIN);
193+
Console.WriteLine("\n===> UnPublish");
194+
CallRet publishRet = rs.Unpublish(DEMO_DOMAIN);
163195
PrintRet(publishRet);
164196
if (!publishRet.OK)
165197
{
166198
Console.WriteLine("Failed to UnPublish");
167199
}
168200
}
169201

170-
public static PutAuthRet PutAuth()
171-
{
172-
Console.WriteLine("\n--- PutAuth ---");
173-
PrintInput(null, null, null, null);
174-
PutAuthRet putAuthRet = rs.PutAuth();
175-
PrintRet(putAuthRet);
176-
if (putAuthRet.OK)
177-
{
178-
Console.WriteLine("Expires: " + putAuthRet.Expires.ToString());
179-
Console.WriteLine("Url: " + putAuthRet.Url);
180-
}
181-
else
182-
{
183-
Console.WriteLine("Failed to PutAuth");
184-
}
185-
return putAuthRet;
186-
}
187-
188-
public static void CliPutFile()
189-
{
190-
PutAuthRet putAuthRet = PutAuth();
191-
Console.WriteLine("\n--- CliPutFile ---");
192-
PrintInput(tableName, key, localFile, null);
193-
PutFileRet putFileRet = RSClient.PutFile(putAuthRet.Url, tableName,
194-
key, null, localFile, null, "key=Config.cs");
195-
PrintRet(putFileRet);
196-
if (putFileRet.OK)
197-
{
198-
Console.WriteLine("Hash: " + putFileRet.Hash);
199-
}
200-
else
201-
{
202-
Console.WriteLine("Failed to CliPutFile");
203-
}
204-
205-
}
206-
207-
public static void UpToken()
208-
{
209-
Console.WriteLine("\n--- Gen UpToken ---");
210-
var authPolicy = new AuthPolicy(tableName, 3600);
211-
Console.WriteLine("Json: " + authPolicy.Marshal());
212-
Console.WriteLine("Token: " + authPolicy.MakeAuthTokenString());
213-
}
214-
215-
public static void PrintInput(
216-
string tblName, string key, string localFile, string domain)
217-
{
218-
StringBuilder sb = new StringBuilder();
219-
sb.AppendLine("\n[In]");
220-
if (!String.IsNullOrEmpty(tblName))
221-
sb.AppendLine("TableName: " + tblName);
222-
if (!String.IsNullOrEmpty(key))
223-
sb.AppendLine("Key: " + key);
224-
if (!String.IsNullOrEmpty(localFile))
225-
sb.AppendLine("LocalFile: " + localFile);
226-
if (!String.IsNullOrEmpty(domain))
227-
sb.AppendLine("Domain: " + domain);
228-
Console.WriteLine(sb.ToString());
229-
}
230-
231-
232202
public static void PrintRet(CallRet callRet)
233203
{
234-
Console.WriteLine("\n[Out]");
235-
236-
Console.WriteLine("\nCallRet");
204+
Console.WriteLine("\n[CallRet]");
237205
Console.WriteLine("StatusCode: " + callRet.StatusCode.ToString());
238206
Console.WriteLine("Response:\n" + callRet.Response);
239207
Console.WriteLine();

Json/IJsonWrapper.cs

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
1-
#region Header
2-
/**
3-
* IJsonWrapper.cs
4-
* Interface that represents a type capable of handling all kinds of JSON
5-
* data. This is mainly used when mapping objects through JsonMapper, and
6-
* it's implemented by JsonData.
7-
*
8-
* The authors disclaim copyright to this source code. For more details, see
9-
* the COPYING file included with this distribution.
10-
**/
11-
#endregion
12-
13-
14-
using System.Collections;
15-
using System.Collections.Specialized;
16-
17-
18-
namespace LitJson
19-
{
20-
public enum JsonType
21-
{
22-
None,
23-
24-
Object,
25-
Array,
26-
String,
27-
Int,
28-
Long,
29-
Double,
30-
Boolean
31-
}
32-
33-
public interface IJsonWrapper : IList, IOrderedDictionary
34-
{
35-
bool IsArray { get; }
36-
bool IsBoolean { get; }
37-
bool IsDouble { get; }
38-
bool IsInt { get; }
39-
bool IsLong { get; }
40-
bool IsObject { get; }
41-
bool IsString { get; }
42-
43-
bool GetBoolean ();
44-
double GetDouble ();
45-
int GetInt ();
46-
JsonType GetJsonType ();
47-
long GetLong ();
48-
string GetString ();
49-
50-
void SetBoolean (bool val);
51-
void SetDouble (double val);
52-
void SetInt (int val);
53-
void SetJsonType (JsonType type);
54-
void SetLong (long val);
55-
void SetString (string val);
56-
57-
string ToJson ();
58-
void ToJson (JsonWriter writer);
59-
}
60-
}
1+
#region Header
2+
/**
3+
* IJsonWrapper.cs
4+
* Interface that represents a type capable of handling all kinds of JSON
5+
* data. This is mainly used when mapping objects through JsonMapper, and
6+
* it's implemented by JsonData.
7+
*
8+
* The authors disclaim copyright to this source code. For more details, see
9+
* the COPYING file included with this distribution.
10+
**/
11+
#endregion
12+
13+
14+
using System.Collections;
15+
using System.Collections.Specialized;
16+
17+
18+
namespace LitJson
19+
{
20+
public enum JsonType
21+
{
22+
None,
23+
24+
Object,
25+
Array,
26+
String,
27+
Int,
28+
Long,
29+
Double,
30+
Boolean
31+
}
32+
33+
public interface IJsonWrapper : IList, IOrderedDictionary
34+
{
35+
bool IsArray { get; }
36+
bool IsBoolean { get; }
37+
bool IsDouble { get; }
38+
bool IsInt { get; }
39+
bool IsLong { get; }
40+
bool IsObject { get; }
41+
bool IsString { get; }
42+
43+
bool GetBoolean ();
44+
double GetDouble ();
45+
int GetInt ();
46+
JsonType GetJsonType ();
47+
long GetLong ();
48+
string GetString ();
49+
50+
void SetBoolean (bool val);
51+
void SetDouble (double val);
52+
void SetInt (int val);
53+
void SetJsonType (JsonType type);
54+
void SetLong (long val);
55+
void SetString (string val);
56+
57+
string ToJson ();
58+
void ToJson (JsonWriter writer);
59+
}
60+
}

0 commit comments

Comments
 (0)