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