root / trunk / Pithos.Network / ICloudClient.cs @ 759bd3c4
History | View | Annotate | Download (14.6 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 |
IList<ShareAccountInfo> ListSharingAccounts(DateTime? since=null); |
109 |
} |
110 |
|
111 |
|
112 |
[ContractClassFor(typeof(ICloudClient))] |
113 |
public abstract class ICloudClientContract:ICloudClient |
114 |
{ |
115 |
|
116 |
public string ApiKey { get; set; } |
117 |
public string UserName { get; set; } |
118 |
public Uri StorageUrl { get; set; } |
119 |
public string Token { get; set; } |
120 |
|
121 |
public double DownloadPercentLimit { get; set; } |
122 |
public double UploadPercentLimit { get; set; } |
123 |
|
124 |
public string AuthenticationUrl { get; set; } |
125 |
|
126 |
public bool UsePithos { get; set; } |
127 |
|
128 |
public AccountInfo Authenticate() |
129 |
{ |
130 |
Contract.Requires<ArgumentNullException>(!String.IsNullOrWhiteSpace(ApiKey), "ApiKey must be filled before calling Authenticate"); |
131 |
Contract.Requires<ArgumentNullException>(!String.IsNullOrWhiteSpace(UserName), "UserName must be filled before calling Authenticate"); |
132 |
|
133 |
return default(AccountInfo); |
134 |
} |
135 |
|
136 |
public IList<ContainerInfo> ListContainers(string account) |
137 |
{ |
138 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
139 |
Contract.Requires(StorageUrl!=null); |
140 |
|
141 |
return default(IList<ContainerInfo>); |
142 |
} |
143 |
|
144 |
public IList<ObjectInfo> ListSharedObjects(DateTime? since) |
145 |
{ |
146 |
|
147 |
|
148 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
149 |
Contract.Requires(StorageUrl != null); |
150 |
|
151 |
return default(IList<ObjectInfo>); |
152 |
} |
153 |
|
154 |
public void ShareObject(string account, string container, string objectName, string shareTo, bool read, bool write) |
155 |
{ |
156 |
|
157 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
158 |
Contract.Requires(StorageUrl != null); |
159 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
160 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
161 |
Contract.Requires(!String.IsNullOrWhiteSpace(account)); |
162 |
Contract.Requires(!String.IsNullOrWhiteSpace(shareTo)); |
163 |
|
164 |
} |
165 |
|
166 |
public AccountInfo GetAccountPolicies(AccountInfo accountInfo) |
167 |
{ |
168 |
Contract.Requires(accountInfo!=null); |
169 |
|
170 |
return default(AccountInfo); |
171 |
} |
172 |
|
173 |
public void UpdateMetadata(ObjectInfo objectInfo) |
174 |
{ |
175 |
Contract.Requires(objectInfo!=null); |
176 |
|
177 |
return ; |
178 |
} |
179 |
|
180 |
public void UpdateMetadata(ContainerInfo objectInfo) |
181 |
{ |
182 |
Contract.Requires(objectInfo!=null); |
183 |
|
184 |
return ; |
185 |
} |
186 |
|
187 |
public IList<ShareAccountInfo> ListSharingAccounts(DateTime? since = new DateTime?()) |
188 |
{ |
189 |
return default(IList<ShareAccountInfo>); |
190 |
} |
191 |
|
192 |
|
193 |
public IList<ObjectInfo> ListObjects(string account, string container, DateTime? since = null) |
194 |
{ |
195 |
|
196 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
197 |
Contract.Requires(StorageUrl != null); |
198 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
199 |
|
200 |
return default(IList<ObjectInfo>); |
201 |
} |
202 |
|
203 |
public IList<ObjectInfo> ListObjects(string account, string container, string folder, DateTime? since = null) |
204 |
{ |
205 |
|
206 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
207 |
Contract.Requires(StorageUrl != null); |
208 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
209 |
//Contract.Requires(!String.IsNullOrWhiteSpace(folder)); |
210 |
|
211 |
return default(IList<ObjectInfo>); |
212 |
} |
213 |
|
214 |
public bool ContainerExists(string account, string container) |
215 |
{ |
216 |
|
217 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
218 |
Contract.Requires(StorageUrl!=null); |
219 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
220 |
|
221 |
return default(bool); |
222 |
} |
223 |
|
224 |
public ContainerInfo GetContainerInfo(string account, string container) |
225 |
{ |
226 |
|
227 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
228 |
Contract.Requires(StorageUrl!=null); |
229 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
230 |
|
231 |
return default(ContainerInfo); |
232 |
} |
233 |
|
234 |
public void CreateContainer(string account, string container) |
235 |
{ |
236 |
|
237 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
238 |
Contract.Requires(StorageUrl!=null); |
239 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
240 |
} |
241 |
|
242 |
public void DeleteContainer(string account, string container) |
243 |
{ |
244 |
|
245 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
246 |
Contract.Requires(StorageUrl!=null); |
247 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
248 |
} |
249 |
|
250 |
public Task GetObject(string account, string container, string objectName, string fileName) |
251 |
{ |
252 |
|
253 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
254 |
Contract.Requires(StorageUrl!=null); |
255 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
256 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
257 |
|
258 |
return default(Task); |
259 |
} |
260 |
|
261 |
public Task PutObject(string account, string container, string objectName, string fileName, string hash = null, string contentType = "application/octet-stream") |
262 |
{ |
263 |
|
264 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
265 |
Contract.Requires(StorageUrl!=null); |
266 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
267 |
Contract.Requires(!String.IsNullOrWhiteSpace(fileName)); |
268 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
269 |
Contract.Requires(!String.IsNullOrWhiteSpace(contentType)); |
270 |
|
271 |
return default(Task); |
272 |
} |
273 |
|
274 |
public void DeleteObject(string account, string container, string objectName) |
275 |
{ |
276 |
|
277 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
278 |
Contract.Requires(StorageUrl!=null); |
279 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
280 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
281 |
} |
282 |
|
283 |
public void MoveObject(string account, string sourceContainer, string oldObjectName, string targetContainer, string newObjectName) |
284 |
{ |
285 |
|
286 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
287 |
Contract.Requires(StorageUrl!=null); |
288 |
Contract.Requires(!String.IsNullOrWhiteSpace(sourceContainer)); |
289 |
Contract.Requires(!String.IsNullOrWhiteSpace(oldObjectName)); |
290 |
Contract.Requires(!String.IsNullOrWhiteSpace(targetContainer)); |
291 |
Contract.Requires(!String.IsNullOrWhiteSpace(newObjectName)); |
292 |
} |
293 |
|
294 |
public bool ObjectExists(string account, string container, string objectName) |
295 |
{ |
296 |
|
297 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
298 |
Contract.Requires(StorageUrl!=null); |
299 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
300 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
301 |
|
302 |
return default(bool); |
303 |
} |
304 |
|
305 |
public ObjectInfo GetObjectInfo(string account, string container, string objectName) |
306 |
{ |
307 |
|
308 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
309 |
Contract.Requires(StorageUrl!=null); |
310 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
311 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
312 |
|
313 |
return default(ObjectInfo); |
314 |
} |
315 |
|
316 |
public void CreateFolder(string account, string container, string folder) |
317 |
{ |
318 |
|
319 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
320 |
Contract.Requires(StorageUrl != null); |
321 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
322 |
Contract.Requires(!String.IsNullOrWhiteSpace(folder)); |
323 |
} |
324 |
|
325 |
public Task<TreeHash> GetHashMap(string account, string container, string objectName) |
326 |
{ |
327 |
|
328 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
329 |
Contract.Requires(StorageUrl != null); |
330 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
331 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
332 |
|
333 |
return default(Task<TreeHash>); |
334 |
} |
335 |
|
336 |
public Task<IList<string>> PutHashMap(string account, string container, string objectName, TreeHash hash) |
337 |
{ |
338 |
|
339 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
340 |
Contract.Requires(StorageUrl != null); |
341 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
342 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
343 |
Contract.Requires(hash != null); |
344 |
|
345 |
return default(Task<IList<string>>); |
346 |
} |
347 |
|
348 |
public Task PostBlock(string account, string container, byte[] block, int offset, int count) |
349 |
{ |
350 |
|
351 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
352 |
Contract.Requires(StorageUrl != null); |
353 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
354 |
Contract.Requires(block != null); |
355 |
Contract.Requires(offset>=0); |
356 |
Contract.Requires(offset < block.Length); |
357 |
Contract.Requires(count>=0); |
358 |
Contract.Requires(count <= block.Length); |
359 |
|
360 |
return default(Task); |
361 |
} |
362 |
|
363 |
public Task<byte[]> GetBlock(string account, string container, Uri relativeUrl, long start, long? end) |
364 |
{ |
365 |
|
366 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
367 |
Contract.Requires(StorageUrl != null); |
368 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
369 |
Contract.Requires(relativeUrl!=null); |
370 |
Contract.Requires(start>=0); |
371 |
Contract.Requires(end==null || end>=0); |
372 |
|
373 |
return default(Task<byte[]>); |
374 |
} |
375 |
|
376 |
} |
377 |
} |