Skip to content

Commit 7d2507c

Browse files
committed
init
0 parents  commit 7d2507c

25 files changed

+4836
-0
lines changed

Example/RSDemo.cs

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Diagnostics;
6+
7+
namespace QBox
8+
{
9+
public class RSDemo
10+
{
11+
public static string tableName = "Bucket";
12+
public static string key;
13+
public static string localFile;
14+
public static string DEMO_DOMAIN = "iovip.qbox.me/bucket";
15+
public static Client conn;
16+
public static RSService rs;
17+
18+
public static void PutFile()
19+
{
20+
Console.WriteLine("\n--- PutFile ---");
21+
PrintInput(tableName, key, localFile, null);
22+
PutFileRet putFileRet = rs.PutFile(key, null, localFile, null);
23+
PrintRet(putFileRet);
24+
if (putFileRet.OK)
25+
{
26+
Console.WriteLine("Hash: " + putFileRet.Hash);
27+
}
28+
else
29+
{
30+
Console.WriteLine("Failed to PutFile");
31+
}
32+
}
33+
34+
public static void Get()
35+
{
36+
Console.WriteLine("\n--- Get ---");
37+
PrintInput(tableName, key, null, null);
38+
GetRet getRet = rs.Get(key, "attName");
39+
PrintRet(getRet);
40+
if (getRet.OK)
41+
{
42+
Console.WriteLine("Hash: " + getRet.Hash);
43+
Console.WriteLine("FileSize: " + getRet.FileSize);
44+
Console.WriteLine("MimeType: " + getRet.MimeType);
45+
Console.WriteLine("Url: " + getRet.Url);
46+
}
47+
else
48+
{
49+
Console.WriteLine("Failed to Get");
50+
}
51+
52+
Console.WriteLine("\n--- GetIfNotModified ---");
53+
PrintInput(tableName, key, null, null);
54+
getRet = rs.GetIfNotModified(key, "attName", getRet.Hash);
55+
PrintRet(getRet);
56+
if (getRet.OK)
57+
{
58+
Console.WriteLine("Hash: " + getRet.Hash);
59+
Console.WriteLine("FileSize: " + getRet.FileSize);
60+
Console.WriteLine("MimeType: " + getRet.MimeType);
61+
Console.WriteLine("Url: " + getRet.Url);
62+
}
63+
else
64+
{
65+
Console.WriteLine("Failed to GetIfNotModified");
66+
}
67+
}
68+
69+
public static void Stat()
70+
{
71+
Console.WriteLine("\n--- Stat ---");
72+
PrintInput(tableName, key, null, null);
73+
StatRet statRet = rs.Stat(key);
74+
PrintRet(statRet);
75+
if (statRet.OK)
76+
{
77+
Console.WriteLine("Hash: " + statRet.Hash);
78+
Console.WriteLine("FileSize: " + statRet.FileSize);
79+
Console.WriteLine("PutTime: " + statRet.PutTime);
80+
Console.WriteLine("MimeType: " + statRet.MimeType);
81+
}
82+
else
83+
{
84+
Console.WriteLine("Failed to Stat");
85+
}
86+
}
87+
88+
public static void Delete()
89+
{
90+
Console.WriteLine("\n--- Delete ---");
91+
PrintInput(tableName, key, null, null);
92+
DeleteRet deleteRet = rs.Delete(key);
93+
PrintRet(deleteRet);
94+
if (!deleteRet.OK)
95+
{
96+
Console.WriteLine("Failed to Delete");
97+
}
98+
}
99+
100+
public static void Drop()
101+
{
102+
Console.WriteLine("\n--- Drop ---");
103+
PrintInput(tableName, null, null, null);
104+
DropRet dropRet = rs.Drop();
105+
PrintRet(dropRet);
106+
if (!dropRet.OK)
107+
{
108+
Console.WriteLine("Failed to Drop");
109+
}
110+
}
111+
112+
public static void Publish()
113+
{
114+
Console.WriteLine("\n--- Publish ---");
115+
PrintInput(tableName, null, null, DEMO_DOMAIN);
116+
PublishRet publishRet = rs.Publish(DEMO_DOMAIN);
117+
PrintRet(publishRet);
118+
if (!publishRet.OK)
119+
{
120+
Console.WriteLine("Failed to Publish");
121+
}
122+
}
123+
124+
public static void UnPublish()
125+
{
126+
Console.WriteLine("\n--- UnPublish ---");
127+
PrintInput(tableName, null, null, DEMO_DOMAIN);
128+
PublishRet publishRet = rs.UnPublish(DEMO_DOMAIN);
129+
PrintRet(publishRet);
130+
if (!publishRet.OK)
131+
{
132+
Console.WriteLine("Failed to UnPublish");
133+
}
134+
}
135+
136+
public static PutAuthRet PutAuth()
137+
{
138+
Console.WriteLine("\n--- PutAuth ---");
139+
PrintInput(null, null, null, null);
140+
PutAuthRet putAuthRet = rs.PutAuth();
141+
PrintRet(putAuthRet);
142+
if (putAuthRet.OK)
143+
{
144+
Console.WriteLine("Expires: " + putAuthRet.Expires.ToString());
145+
Console.WriteLine("Url: " + putAuthRet.Url);
146+
}
147+
else
148+
{
149+
Console.WriteLine("Failed to PutAuth");
150+
}
151+
return putAuthRet;
152+
}
153+
154+
public static void CliPutFile()
155+
{
156+
PutAuthRet putAuthRet = PutAuth();
157+
Console.WriteLine("\n--- CliPutFile ---");
158+
PrintInput(tableName, key, localFile, null);
159+
PutFileRet putFileRet = RSClient.PutFile(putAuthRet.Url, tableName,
160+
key, null, localFile, null, "key=Config.cs");
161+
PrintRet(putFileRet);
162+
if (putFileRet.OK)
163+
{
164+
Console.WriteLine("Hash: " + putFileRet.Hash);
165+
}
166+
else
167+
{
168+
Console.WriteLine("Failed to CliPutFile");
169+
}
170+
171+
}
172+
173+
public static void PrintInput(
174+
string tblName, string key, string localFile, string domain)
175+
{
176+
StringBuilder sb = new StringBuilder();
177+
sb.AppendLine("\n[In]");
178+
if (!String.IsNullOrEmpty(tblName))
179+
sb.AppendLine("TableName: " + tblName);
180+
if (!String.IsNullOrEmpty(key))
181+
sb.AppendLine("Key: " + key);
182+
if (!String.IsNullOrEmpty(localFile))
183+
sb.AppendLine("LocalFile: " + localFile);
184+
if (!String.IsNullOrEmpty(domain))
185+
sb.AppendLine("Domain: " + domain);
186+
Console.WriteLine(sb.ToString());
187+
}
188+
189+
190+
public static void PrintRet(CallRet callRet)
191+
{
192+
Console.WriteLine("\n[Out]");
193+
194+
Console.WriteLine("\nCallRet");
195+
Console.WriteLine("StatusCode: " + callRet.StatusCode.ToString());
196+
Console.WriteLine("Response:\n" + callRet.Response);
197+
Console.WriteLine();
198+
}
199+
200+
public static void Main()
201+
{
202+
Config.ACCESS_KEY = "RLT1NBD08g3kih5-0v8Yi6nX6cBhesa2Dju4P7mT";
203+
Config.SECRET_KEY = "k6uZoSDAdKBXQcNYG3UOm4bP3spDVkTg-9hWHIKm";
204+
205+
conn = new DigestAuthClient();
206+
rs = new RSService(conn, tableName);
207+
localFile = Process.GetCurrentProcess().MainModule.FileName;
208+
key = System.IO.Path.GetFileName(localFile);
209+
210+
PutFile();
211+
Get();
212+
Stat();
213+
Delete();
214+
CliPutFile();
215+
Get();
216+
Stat();
217+
Publish();
218+
UnPublish();
219+
Drop();
220+
221+
Console.ReadLine();
222+
}
223+
}
224+
}

Json/IJsonWrapper.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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+
}

0 commit comments

Comments
 (0)