root / trunk / Pithos.Network / ICloudClient.cs @ 93dc3a84
History | View | Annotate | Download (14.4 kB)
1 |
#region |
---|---|
2 |
/* ----------------------------------------------------------------------- |
3 |
* <copyright file="ICloudClient.cs" company="GRNet"> |
4 |
* |
5 |
* Copyright 2011-2012 GRNET S.A. All rights reserved. |
6 |
* |
7 |
* Redistribution and use in source and binary forms, with or |
8 |
* without modification, are permitted provided that the following |
9 |
* conditions are met: |
10 |
* |
11 |
* 1. Redistributions of source code must retain the above |
12 |
* copyright notice, this list of conditions and the following |
13 |
* disclaimer. |
14 |
* |
15 |
* 2. Redistributions in binary form must reproduce the above |
16 |
* copyright notice, this list of conditions and the following |
17 |
* disclaimer in the documentation and/or other materials |
18 |
* provided with the distribution. |
19 |
* |
20 |
* |
21 |
* THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
22 |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
23 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
24 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
25 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
27 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
28 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
29 |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
31 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
32 |
* POSSIBILITY OF SUCH DAMAGE. |
33 |
* |
34 |
* The views and conclusions contained in the software and |
35 |
* documentation are those of the authors and should not be |
36 |
* interpreted as representing official policies, either expressed |
37 |
* or implied, of GRNET S.A. |
38 |
* </copyright> |
39 |
* ----------------------------------------------------------------------- |
40 |
*/ |
41 |
#endregion |
42 |
using System; |
43 |
using System.Collections.Generic; |
44 |
using System.Diagnostics.Contracts; |
45 |
using System.Net; |
46 |
using System.Threading.Tasks; |
47 |
using Pithos.Interfaces; |
48 |
|
49 |
namespace Pithos.Network |
50 |
{ |
51 |
[ContractClass(typeof(ICloudClientContract))] |
52 |
public interface ICloudClient |
53 |
{ |
54 |
|
55 |
string ApiKey { get; set; } |
56 |
string UserName { get; set; } |
57 |
Uri StorageUrl { get; set; } |
58 |
|
59 |
string Token { get; set; } |
60 |
|
61 |
bool UsePithos { get; set; } |
62 |
AccountInfo Authenticate(); |
63 |
//WebProxy Proxy { get; set; } |
64 |
double DownloadPercentLimit { get; set; } |
65 |
double UploadPercentLimit { get; set; } |
66 |
string AuthenticationUrl { get; set; } |
67 |
|
68 |
#region Container operations |
69 |
|
70 |
IList<ContainerInfo> ListContainers(string account); |
71 |
IList<ObjectInfo> ListObjects(string account, string container, DateTime? since = null); |
72 |
IList<ObjectInfo> ListObjects(string account, string container, string folder, DateTime? since = null); |
73 |
bool ContainerExists(string account, string container); |
74 |
ContainerInfo GetContainerInfo(string account, string container); |
75 |
void CreateContainer(string account, string container); |
76 |
void DeleteContainer(string account, string container); |
77 |
#endregion |
78 |
|
79 |
#region Object operations |
80 |
Task GetObject(string account, string container, string objectName, string fileName); |
81 |
Task PutObject(string account, string container, string objectName, string fileName, string hash = null, string contentType = "application/octet-stream"); |
82 |
void DeleteObject(string account, string container, string objectName); |
83 |
//void DeleteObject(string container, string objectName, string account = null); |
84 |
void MoveObject(string account, string sourceContainer, string oldObjectName, string targetContainer, string newObjectName); |
85 |
bool ObjectExists(string account, string container, string objectName); |
86 |
ObjectInfo GetObjectInfo(string account, string container, string objectName); |
87 |
void CreateFolder(string account, string container, string folder); |
88 |
#endregion |
89 |
|
90 |
#region Hashmap operations |
91 |
Task<TreeHash> GetHashMap(string account, string container, string objectName); |
92 |
Task<IList<string>> PutHashMap(string account, string container, string objectName, TreeHash hash); |
93 |
Task PostBlock(string account, string container, byte[] block, int offset, int count); |
94 |
Task<byte[]> GetBlock(string account, string container, Uri relativeUrl, long start, long? end); |
95 |
#endregion |
96 |
|
97 |
#region Sharing operations |
98 |
IList<ObjectInfo> ListSharedObjects(DateTime? since); |
99 |
void ShareObject(string account, string container, string objectName, string shareTo, bool read, bool write); |
100 |
|
101 |
#endregion |
102 |
|
103 |
AccountInfo GetAccountPolicies(AccountInfo accountInfo); |
104 |
|
105 |
void UpdateMetadata(ObjectInfo objectInfo); |
106 |
|
107 |
void UpdateMetadata(ContainerInfo Container); |
108 |
} |
109 |
|
110 |
|
111 |
[ContractClassFor(typeof(ICloudClient))] |
112 |
public abstract class ICloudClientContract:ICloudClient |
113 |
{ |
114 |
|
115 |
public string ApiKey { get; set; } |
116 |
public string UserName { get; set; } |
117 |
public Uri StorageUrl { get; set; } |
118 |
public string Token { get; set; } |
119 |
|
120 |
public double DownloadPercentLimit { get; set; } |
121 |
public double UploadPercentLimit { get; set; } |
122 |
|
123 |
public string AuthenticationUrl { get; set; } |
124 |
|
125 |
public bool UsePithos { get; set; } |
126 |
|
127 |
public AccountInfo Authenticate() |
128 |
{ |
129 |
Contract.Requires<ArgumentNullException>(!String.IsNullOrWhiteSpace(ApiKey), "ApiKey must be filled before calling Authenticate"); |
130 |
Contract.Requires<ArgumentNullException>(!String.IsNullOrWhiteSpace(UserName), "UserName must be filled before calling Authenticate"); |
131 |
|
132 |
return default(AccountInfo); |
133 |
} |
134 |
|
135 |
public IList<ContainerInfo> ListContainers(string account) |
136 |
{ |
137 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
138 |
Contract.Requires(StorageUrl!=null); |
139 |
|
140 |
return default(IList<ContainerInfo>); |
141 |
} |
142 |
|
143 |
public IList<ObjectInfo> ListSharedObjects(DateTime? since) |
144 |
{ |
145 |
|
146 |
|
147 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
148 |
Contract.Requires(StorageUrl != null); |
149 |
|
150 |
return default(IList<ObjectInfo>); |
151 |
} |
152 |
|
153 |
public void ShareObject(string account, string container, string objectName, string shareTo, bool read, bool write) |
154 |
{ |
155 |
|
156 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
157 |
Contract.Requires(StorageUrl != null); |
158 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
159 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
160 |
Contract.Requires(!String.IsNullOrWhiteSpace(account)); |
161 |
Contract.Requires(!String.IsNullOrWhiteSpace(shareTo)); |
162 |
|
163 |
} |
164 |
|
165 |
public AccountInfo GetAccountPolicies(AccountInfo accountInfo) |
166 |
{ |
167 |
Contract.Requires(accountInfo!=null); |
168 |
|
169 |
return default(AccountInfo); |
170 |
} |
171 |
|
172 |
public void UpdateMetadata(ObjectInfo objectInfo) |
173 |
{ |
174 |
Contract.Requires(objectInfo!=null); |
175 |
|
176 |
return ; |
177 |
} |
178 |
|
179 |
public void UpdateMetadata(ContainerInfo objectInfo) |
180 |
{ |
181 |
Contract.Requires(objectInfo!=null); |
182 |
|
183 |
return ; |
184 |
} |
185 |
|
186 |
|
187 |
public IList<ObjectInfo> ListObjects(string account, string container, DateTime? since = null) |
188 |
{ |
189 |
|
190 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
191 |
Contract.Requires(StorageUrl != null); |
192 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
193 |
|
194 |
return default(IList<ObjectInfo>); |
195 |
} |
196 |
|
197 |
public IList<ObjectInfo> ListObjects(string account, string container, string folder, DateTime? since = null) |
198 |
{ |
199 |
|
200 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
201 |
Contract.Requires(StorageUrl != null); |
202 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
203 |
//Contract.Requires(!String.IsNullOrWhiteSpace(folder)); |
204 |
|
205 |
return default(IList<ObjectInfo>); |
206 |
} |
207 |
|
208 |
public bool ContainerExists(string account, string container) |
209 |
{ |
210 |
|
211 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
212 |
Contract.Requires(StorageUrl!=null); |
213 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
214 |
|
215 |
return default(bool); |
216 |
} |
217 |
|
218 |
public ContainerInfo GetContainerInfo(string account, string container) |
219 |
{ |
220 |
|
221 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
222 |
Contract.Requires(StorageUrl!=null); |
223 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
224 |
|
225 |
return default(ContainerInfo); |
226 |
} |
227 |
|
228 |
public void CreateContainer(string account, string container) |
229 |
{ |
230 |
|
231 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
232 |
Contract.Requires(StorageUrl!=null); |
233 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
234 |
} |
235 |
|
236 |
public void DeleteContainer(string account, string container) |
237 |
{ |
238 |
|
239 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
240 |
Contract.Requires(StorageUrl!=null); |
241 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
242 |
} |
243 |
|
244 |
public Task GetObject(string account, string container, string objectName, string fileName) |
245 |
{ |
246 |
|
247 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
248 |
Contract.Requires(StorageUrl!=null); |
249 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
250 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
251 |
|
252 |
return default(Task); |
253 |
} |
254 |
|
255 |
public Task PutObject(string account, string container, string objectName, string fileName, string hash = null, string contentType = "application/octet-stream") |
256 |
{ |
257 |
|
258 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
259 |
Contract.Requires(StorageUrl!=null); |
260 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
261 |
Contract.Requires(!String.IsNullOrWhiteSpace(fileName)); |
262 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
263 |
Contract.Requires(!String.IsNullOrWhiteSpace(contentType)); |
264 |
|
265 |
return default(Task); |
266 |
} |
267 |
|
268 |
public void DeleteObject(string account, string container, string objectName) |
269 |
{ |
270 |
|
271 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
272 |
Contract.Requires(StorageUrl!=null); |
273 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
274 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
275 |
} |
276 |
|
277 |
public void MoveObject(string account, string sourceContainer, string oldObjectName, string targetContainer, string newObjectName) |
278 |
{ |
279 |
|
280 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
281 |
Contract.Requires(StorageUrl!=null); |
282 |
Contract.Requires(!String.IsNullOrWhiteSpace(sourceContainer)); |
283 |
Contract.Requires(!String.IsNullOrWhiteSpace(oldObjectName)); |
284 |
Contract.Requires(!String.IsNullOrWhiteSpace(targetContainer)); |
285 |
Contract.Requires(!String.IsNullOrWhiteSpace(newObjectName)); |
286 |
} |
287 |
|
288 |
public bool ObjectExists(string account, string container, string objectName) |
289 |
{ |
290 |
|
291 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
292 |
Contract.Requires(StorageUrl!=null); |
293 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
294 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
295 |
|
296 |
return default(bool); |
297 |
} |
298 |
|
299 |
public ObjectInfo GetObjectInfo(string account, string container, string objectName) |
300 |
{ |
301 |
|
302 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
303 |
Contract.Requires(StorageUrl!=null); |
304 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
305 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
306 |
|
307 |
return default(ObjectInfo); |
308 |
} |
309 |
|
310 |
public void CreateFolder(string account, string container, string folder) |
311 |
{ |
312 |
|
313 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
314 |
Contract.Requires(StorageUrl != null); |
315 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
316 |
Contract.Requires(!String.IsNullOrWhiteSpace(folder)); |
317 |
} |
318 |
|
319 |
public Task<TreeHash> GetHashMap(string account, string container, string objectName) |
320 |
{ |
321 |
|
322 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
323 |
Contract.Requires(StorageUrl != null); |
324 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
325 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
326 |
|
327 |
return default(Task<TreeHash>); |
328 |
} |
329 |
|
330 |
public Task<IList<string>> PutHashMap(string account, string container, string objectName, TreeHash hash) |
331 |
{ |
332 |
|
333 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
334 |
Contract.Requires(StorageUrl != null); |
335 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
336 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
337 |
Contract.Requires(hash != null); |
338 |
|
339 |
return default(Task<IList<string>>); |
340 |
} |
341 |
|
342 |
public Task PostBlock(string account, string container, byte[] block, int offset, int count) |
343 |
{ |
344 |
|
345 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
346 |
Contract.Requires(StorageUrl != null); |
347 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
348 |
Contract.Requires(block != null); |
349 |
Contract.Requires(offset>=0); |
350 |
Contract.Requires(offset < block.Length); |
351 |
Contract.Requires(count>=0); |
352 |
Contract.Requires(count <= block.Length); |
353 |
|
354 |
return default(Task); |
355 |
} |
356 |
|
357 |
public Task<byte[]> GetBlock(string account, string container, Uri relativeUrl, long start, long? end) |
358 |
{ |
359 |
|
360 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
361 |
Contract.Requires(StorageUrl != null); |
362 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
363 |
Contract.Requires(relativeUrl!=null); |
364 |
Contract.Requires(start>=0); |
365 |
Contract.Requires(end==null || end>=0); |
366 |
|
367 |
return default(Task<byte[]>); |
368 |
} |
369 |
|
370 |
} |
371 |
} |