root / trunk / Pithos.Interfaces / ICloudClient.cs @ 5bcf6d70
History | View | Annotate | Download (7.7 kB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Diagnostics.Contracts; |
4 |
using System.IO; |
5 |
using System.Linq; |
6 |
using System.Text; |
7 |
|
8 |
namespace Pithos.Interfaces |
9 |
{ |
10 |
[ContractClass(typeof(ICloudClientContract))] |
11 |
public interface ICloudClient |
12 |
{ |
13 |
string ApiKey { get; set; } |
14 |
string UserName { get; set; } |
15 |
Uri StorageUrl { get; set; } |
16 |
string Token { get; set; } |
17 |
bool UsePithos { get; set; } |
18 |
void Authenticate(string userName,string apiKey); |
19 |
Uri Proxy { get; set; } |
20 |
|
21 |
IList<ContainerInfo> ListContainers(); |
22 |
IList<ObjectInfo> ListObjects(string container); |
23 |
IList<ObjectInfo> ListObjects(string container, string folder); |
24 |
bool ContainerExists(string container); |
25 |
ContainerInfo GetContainerInfo(string container); |
26 |
void CreateContainer(string container); |
27 |
void DeleteContainer(string container); |
28 |
|
29 |
Stream GetObject(string container, string objectName); |
30 |
void PutObject(string container, string objectName, string fileName); |
31 |
void DeleteObject(string container, string objectName); |
32 |
void MoveObject(string container, string oldObjectName, string newObjectName); |
33 |
bool ObjectExists(string container,string objectName); |
34 |
ObjectInfo GetObjectInfo(string container, string objectName); |
35 |
void CreateFolder(string container, string folder); |
36 |
|
37 |
|
38 |
} |
39 |
|
40 |
|
41 |
[ContractClassFor(typeof(ICloudClient))] |
42 |
public abstract class ICloudClientContract:ICloudClient |
43 |
{ |
44 |
public string ApiKey { get; set; } |
45 |
public string UserName { get; set; } |
46 |
public Uri StorageUrl { get; set; } |
47 |
public string Token { get; set; } |
48 |
public Uri Proxy { get; set; } |
49 |
|
50 |
public bool UsePithos { get; set; } |
51 |
|
52 |
public void Authenticate(string userName, string apiKey) |
53 |
{ |
54 |
Contract.Requires<ArgumentNullException>(!String.IsNullOrWhiteSpace(apiKey), "ApiKey must be filled before calling Authenticate"); |
55 |
Contract.Requires<ArgumentNullException>(!String.IsNullOrWhiteSpace(userName), "UserName must be filled before calling Authenticate"); |
56 |
|
57 |
|
58 |
Contract.Ensures(apiKey==ApiKey); |
59 |
Contract.Ensures(userName==UserName); |
60 |
Contract.Ensures(StorageUrl!=null); |
61 |
Contract.Ensures(!String.IsNullOrWhiteSpace(Token)); |
62 |
|
63 |
} |
64 |
|
65 |
public IList<ContainerInfo> ListContainers() |
66 |
{ |
67 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
68 |
Contract.Requires(StorageUrl!=null); |
69 |
|
70 |
return default(IList<ContainerInfo>); |
71 |
} |
72 |
|
73 |
public IList<ObjectInfo> ListObjects(string container) |
74 |
{ |
75 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
76 |
Contract.Requires(StorageUrl != null); |
77 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
78 |
|
79 |
return default(IList<ObjectInfo>); |
80 |
} |
81 |
|
82 |
public IList<ObjectInfo> ListObjects(string container, string folder) |
83 |
{ |
84 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
85 |
Contract.Requires(StorageUrl != null); |
86 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
87 |
Contract.Requires(!String.IsNullOrWhiteSpace(folder)); |
88 |
|
89 |
return default(IList<ObjectInfo>); |
90 |
} |
91 |
|
92 |
public bool ContainerExists(string container) |
93 |
{ |
94 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
95 |
Contract.Requires(StorageUrl!=null); |
96 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
97 |
|
98 |
return default(bool); |
99 |
} |
100 |
|
101 |
public ContainerInfo GetContainerInfo(string container) |
102 |
{ |
103 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
104 |
Contract.Requires(StorageUrl!=null); |
105 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
106 |
|
107 |
return default(ContainerInfo); |
108 |
} |
109 |
|
110 |
public void CreateContainer(string container) |
111 |
{ |
112 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
113 |
Contract.Requires(StorageUrl!=null); |
114 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
115 |
} |
116 |
|
117 |
public void DeleteContainer(string container) |
118 |
{ |
119 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
120 |
Contract.Requires(StorageUrl!=null); |
121 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
122 |
} |
123 |
|
124 |
public Stream GetObject(string container, string objectName) |
125 |
{ |
126 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
127 |
Contract.Requires(StorageUrl!=null); |
128 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
129 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
130 |
|
131 |
return default(Stream); |
132 |
} |
133 |
|
134 |
public void PutObject(string container, string objectName, string fileName) |
135 |
{ |
136 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
137 |
Contract.Requires(StorageUrl!=null); |
138 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
139 |
Contract.Requires(!String.IsNullOrWhiteSpace(fileName)); |
140 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
141 |
} |
142 |
|
143 |
public void DeleteObject(string container, string objectName) |
144 |
{ |
145 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
146 |
Contract.Requires(StorageUrl!=null); |
147 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
148 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
149 |
} |
150 |
|
151 |
public void MoveObject(string container, string oldObjectName, string newObjectName) |
152 |
{ |
153 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
154 |
Contract.Requires(StorageUrl!=null); |
155 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
156 |
Contract.Requires(!String.IsNullOrWhiteSpace(oldObjectName)); |
157 |
Contract.Requires(!String.IsNullOrWhiteSpace(newObjectName)); |
158 |
} |
159 |
|
160 |
public bool ObjectExists(string container,string objectName) |
161 |
{ |
162 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
163 |
Contract.Requires(StorageUrl!=null); |
164 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
165 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
166 |
|
167 |
return default(bool); |
168 |
} |
169 |
|
170 |
public ObjectInfo GetObjectInfo(string container,string objectName) |
171 |
{ |
172 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
173 |
Contract.Requires(StorageUrl!=null); |
174 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
175 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
176 |
|
177 |
return default(ObjectInfo); |
178 |
} |
179 |
|
180 |
public void CreateFolder(string container, string folder) |
181 |
{ |
182 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
183 |
Contract.Requires(StorageUrl != null); |
184 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
185 |
Contract.Requires(!String.IsNullOrWhiteSpace(folder)); |
186 |
} |
187 |
} |
188 |
|
189 |
public class ContainerInfo |
190 |
{ |
191 |
public string Name { get; set; } |
192 |
public long Count { get; set; } |
193 |
public long Bytes { get; set; } |
194 |
|
195 |
public static ContainerInfo Empty=new ContainerInfo(); |
196 |
} |
197 |
|
198 |
public class ObjectInfo |
199 |
{ |
200 |
public string Name { get; set; } |
201 |
public string Hash { get; set; } |
202 |
public long Bytes { get; set; } |
203 |
public string Content_Type { get; set; } |
204 |
public DateTime Last_Modified { get; set; } |
205 |
|
206 |
public static ObjectInfo Empty=new ObjectInfo {Name=String.Empty,Hash=String.Empty,Bytes=0,Content_Type=String.Empty,Last_Modified=DateTime.MinValue}; |
207 |
} |
208 |
} |