Skip to content

Commit 249bce5

Browse files
committed
add package rpc
1 parent 7c9819e commit 249bce5

18 files changed

+87
-65
lines changed

Demo/Demo.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using QBox.Auth;
33
using QBox.RS;
44
using QBox.FileOp;
5+
using QBox.RPC;
56

67
namespace QBox.Demo
78
{
@@ -15,7 +16,6 @@ public class Demo
1516
public static string DEMO_DOMAIN;
1617
public static Client conn;
1718
public static RSService rs;
18-
public static ImageOp imageOp;
1919

2020
public static void Main()
2121
{
@@ -31,7 +31,6 @@ public static void Main()
3131

3232
conn = new DigestAuthClient();
3333
rs = new RSService(conn, bucketName);
34-
imageOp = new ImageOp(conn);
3534

3635
MkBucket();
3736
RSClientPutFile();
@@ -195,7 +194,7 @@ public static void MakeDownloadToken()
195194
public static void ImageOps()
196195
{
197196
Console.WriteLine("\n===> FileOp.ImageInfo");
198-
ImageInfoRet infoRet = imageOp.ImageInfo("http://" + DEMO_DOMAIN + "/" + key);
197+
ImageInfoRet infoRet = ImageOp.ImageInfo("http://" + DEMO_DOMAIN + "/" + key);
199198
PrintRet(infoRet);
200199
if (infoRet.OK)
201200
{
@@ -210,7 +209,7 @@ public static void ImageOps()
210209
}
211210

212211
Console.WriteLine("\n===> FileOp.ImageExif");
213-
CallRet exifRet = imageOp.ImageExif("http://" + DEMO_DOMAIN + "/" + key);
212+
CallRet exifRet = ImageOp.ImageExif("http://" + DEMO_DOMAIN + "/" + key);
214213
PrintRet(exifRet);
215214
if (!exifRet.OK)
216215
{
@@ -219,24 +218,24 @@ public static void ImageOps()
219218

220219
Console.WriteLine("\n===> FileOp.ImageViewUrl");
221220
ImageViewSpec viewSpec = new ImageViewSpec{Mode = 0, Width = 200, Height= 200};
222-
string viewUrl = imageOp.ImageViewUrl("http://" + DEMO_DOMAIN + "/" + key, viewSpec);
221+
string viewUrl = ImageOp.ImageViewUrl("http://" + DEMO_DOMAIN + "/" + key, viewSpec);
223222
Console.WriteLine("ImageViewUrl 1:" + viewUrl);
224223
viewSpec.Quality = 1;
225224
viewSpec.Format = "gif";
226-
viewUrl = imageOp.ImageViewUrl("http://" + DEMO_DOMAIN + "/" + key, viewSpec);
225+
viewUrl = ImageOp.ImageViewUrl("http://" + DEMO_DOMAIN + "/" + key, viewSpec);
227226
Console.WriteLine("ImageViewUrl 2:" + viewUrl);
228227
viewSpec.Quality = 90;
229228
viewSpec.Sharpen = 10;
230229
viewSpec.Format = "png";
231-
viewUrl = imageOp.ImageViewUrl("http://" + DEMO_DOMAIN + "/" + key, viewSpec);
230+
viewUrl = ImageOp.ImageViewUrl("http://" + DEMO_DOMAIN + "/" + key, viewSpec);
232231
Console.WriteLine("ImageViewUrl 3:" + viewUrl);
233232

234233
Console.WriteLine("\n===> FileOp.ImageMogrifyUrl");
235234
ImageMogrifySpec mogrSpec = new ImageMogrifySpec {
236235
Thumbnail = "!50x50r", Gravity = "center", Rotate = 90,
237236
Crop = "!50x50", Quality = 80, AutoOrient = true
238237
};
239-
string mogrUrl = imageOp.ImageMogrifyUrl("http://" + DEMO_DOMAIN + "/" + key, mogrSpec);
238+
string mogrUrl = ImageOp.ImageMogrifyUrl("http://" + DEMO_DOMAIN + "/" + key, mogrSpec);
240239
Console.WriteLine("ImageMogrifyUrl:" + mogrUrl);
241240

242241
Console.WriteLine("\n===> Get");

QBox/Auth/DigestAuthClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
using System.Net;
44
using System.IO;
55
using System.Security.Cryptography;
6-
using QBox.RS;
76
using QBox.Util;
7+
using QBox.RPC;
8+
using QBox.RS;
89

910
namespace QBox.Auth
1011
{

QBox/Auth/PutAuthClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Net;
33
using System.IO;
4-
using QBox.RS;
4+
using QBox.RPC;
55

66
namespace QBox.Auth
77
{

QBox/FileOp/FileOpClient.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Net;
3+
using System.IO;
4+
using QBox.RPC;
5+
6+
namespace QBox.FileOp
7+
{
8+
public static class FileOpClient
9+
{
10+
public static CallRet Get(string url)
11+
{
12+
Console.WriteLine("Client.Get ==> URL: " + url);
13+
try
14+
{
15+
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
16+
request.Method = "GET";
17+
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
18+
{
19+
return HandleResult(response);
20+
}
21+
}
22+
catch (Exception e)
23+
{
24+
Console.WriteLine(e.ToString());
25+
return new CallRet(HttpStatusCode.BadRequest, e);
26+
}
27+
}
28+
29+
public static CallRet HandleResult(HttpWebResponse response)
30+
{
31+
HttpStatusCode statusCode = response.StatusCode;
32+
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
33+
{
34+
string responseStr = reader.ReadToEnd();
35+
return new CallRet(statusCode, responseStr);
36+
}
37+
}
38+
}
39+
}

QBox/FileOp/ImageInfoRet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2-
using QBox.RS;
32
using LitJson;
3+
using QBox.RPC;
44

55
namespace QBox.FileOp
66
{

QBox/FileOp/ImageOp.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
using System;
2-
using QBox.RS;
2+
using QBox.RPC;
33

44
namespace QBox.FileOp
55
{
6-
public class ImageOp
6+
public static class ImageOp
77
{
8-
public Client Conn { get; private set; }
9-
10-
public ImageOp(Client conn)
11-
{
12-
Conn = conn;
13-
}
14-
15-
public ImageInfoRet ImageInfo(string url)
8+
public static ImageInfoRet ImageInfo(string url)
169
{
17-
CallRet callRet = Conn.Get(url + "?imageInfo");
10+
CallRet callRet = FileOpClient.Get(url + "?imageInfo");
1811
return new ImageInfoRet(callRet);
1912
}
2013

21-
public CallRet ImageExif(string url)
14+
public static CallRet ImageExif(string url)
2215
{
23-
return Conn.Get(url + "?exif");
16+
return FileOpClient.Get(url + "?exif");
2417
}
2518

26-
public string ImageViewUrl(string url, ImageViewSpec spec)
19+
public static string ImageViewUrl(string url, ImageViewSpec spec)
2720
{
2821
return url + spec.MakeSpecString();
2922
}
3023

31-
public string ImageMogrifyUrl(string url, ImageMogrifySpec spec)
24+
public static string ImageMogrifyUrl(string url, ImageMogrifySpec spec)
3225
{
3326
return url + spec.MakeSpecString();
3427
}

QBox/QBox.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<Compile Include="Auth\AuthToken.cs" />
4242
<Compile Include="Auth\DownloadPolicy.cs" />
4343
<Compile Include="Auth\PutAuthClient.cs" />
44+
<Compile Include="FileOp\FileOpClient.cs" />
4445
<Compile Include="FileOp\ImageMogrifySpec.cs" />
4546
<Compile Include="FileOp\ImageViewSpec.cs" />
4647
<Compile Include="Json\IJsonWrapper.cs" />
@@ -57,8 +58,8 @@
5758
<Compile Include="FileOp\ImageOp.cs" />
5859
<Compile Include="Properties\AssemblyInfo.cs" />
5960
<Compile Include="Util\Base64UrlSafe.cs" />
60-
<Compile Include="RS\CallRet.cs" />
61-
<Compile Include="RS\Client.cs" />
61+
<Compile Include="RPC\CallRet.cs" />
62+
<Compile Include="RPC\Client.cs" />
6263
<Compile Include="RS\Config.cs" />
6364
<Compile Include="RS\FileParameter.cs" />
6465
<Compile Include="RS\GetRet.cs" />

QBox/RS/CallRet.cs renamed to QBox/RPC/CallRet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Net;
33

4-
namespace QBox.RS
4+
namespace QBox.RPC
55
{
66
public class CallRet
77
{

QBox/RS/Client.cs renamed to QBox/RPC/Client.cs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,13 @@
33
using System.IO;
44
using QBox.Util;
55

6-
namespace QBox.RS
6+
namespace QBox.RPC
77
{
88
public class Client
99
{
1010
public virtual void SetAuth(HttpWebRequest request, Stream body) { }
1111

12-
public CallRet Get(string url)
13-
{
14-
Console.WriteLine("Client.Get ==> URL: " + url);
15-
try
16-
{
17-
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
18-
request.Method = "GET";
19-
SetAuth(request, null);
20-
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
21-
{
22-
return HandleResult(response);
23-
}
24-
}
25-
catch (Exception e)
26-
{
27-
Console.WriteLine(e.ToString());
28-
return new CallRet(HttpStatusCode.BadRequest, e);
29-
}
30-
}
31-
32-
public CallRet Post(string url)
12+
public CallRet Call(string url)
3313
{
3414
Console.WriteLine("Client.Post ==> URL: " + url);
3515
try
@@ -49,7 +29,7 @@ public CallRet Post(string url)
4929
}
5030
}
5131

52-
public CallRet PostWithBinary(string url, string contentType, Stream body, long length)
32+
public CallRet CallWithBinary(string url, string contentType, Stream body, long length)
5333
{
5434
Console.WriteLine("Client.PostWithBinary ==> URL: {0} Length:{1}", url, length);
5535
try

QBox/RS/GetRet.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Net;
33
using LitJson;
4+
using QBox.RPC;
45

56
namespace QBox.RS
67
{

0 commit comments

Comments
 (0)