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