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