root / trunk / Pithos.Interfaces / ICloudClient.cs @ b5061ac8
History | View | Annotate | Download (8 kB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Diagnostics.Contracts; |
4 |
using System.IO; |
5 |
using System.Linq; |
6 |
using System.Text; |
7 |
using System.Threading.Tasks; |
8 |
|
9 |
namespace Pithos.Interfaces |
10 |
{ |
11 |
[ContractClass(typeof(ICloudClientContract))] |
12 |
public interface ICloudClient |
13 |
{ |
14 |
string ApiKey { get; set; } |
15 |
string UserName { get; set; } |
16 |
Uri StorageUrl { get; set; } |
17 |
string Token { get; set; } |
18 |
bool UsePithos { get; set; } |
19 |
void Authenticate(string userName,string apiKey); |
20 |
Uri Proxy { get; set; } |
21 |
double DownloadPercentLimit { get; set; } |
22 |
double UploadPercentLimit { 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 |
Stream GetObject(string container, string objectName); |
34 |
Task PutObject(string container, string objectName, string fileName, string hash = null); |
35 |
void DeleteObject(string container, string objectName); |
36 |
void MoveObject(string container, string oldObjectName, 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 bool UsePithos { get; set; } |
57 |
|
58 |
public void Authenticate(string userName, string apiKey) |
59 |
{ |
60 |
Contract.Requires<ArgumentNullException>(!String.IsNullOrWhiteSpace(apiKey), "ApiKey must be filled before calling Authenticate"); |
61 |
Contract.Requires<ArgumentNullException>(!String.IsNullOrWhiteSpace(userName), "UserName must be filled before calling Authenticate"); |
62 |
|
63 |
|
64 |
Contract.Ensures(apiKey==ApiKey); |
65 |
Contract.Ensures(userName==UserName); |
66 |
Contract.Ensures(StorageUrl!=null); |
67 |
Contract.Ensures(!String.IsNullOrWhiteSpace(Token)); |
68 |
|
69 |
} |
70 |
|
71 |
public IList<ContainerInfo> ListContainers() |
72 |
{ |
73 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
74 |
Contract.Requires(StorageUrl!=null); |
75 |
|
76 |
return default(IList<ContainerInfo>); |
77 |
} |
78 |
|
79 |
public IList<ObjectInfo> ListObjects(string container) |
80 |
{ |
81 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
82 |
Contract.Requires(StorageUrl != null); |
83 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
84 |
|
85 |
return default(IList<ObjectInfo>); |
86 |
} |
87 |
|
88 |
public IList<ObjectInfo> ListObjects(string container, string folder) |
89 |
{ |
90 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
91 |
Contract.Requires(StorageUrl != null); |
92 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
93 |
Contract.Requires(!String.IsNullOrWhiteSpace(folder)); |
94 |
|
95 |
return default(IList<ObjectInfo>); |
96 |
} |
97 |
|
98 |
public bool ContainerExists(string container) |
99 |
{ |
100 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
101 |
Contract.Requires(StorageUrl!=null); |
102 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
103 |
|
104 |
return default(bool); |
105 |
} |
106 |
|
107 |
public ContainerInfo GetContainerInfo(string container) |
108 |
{ |
109 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
110 |
Contract.Requires(StorageUrl!=null); |
111 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
112 |
|
113 |
return default(ContainerInfo); |
114 |
} |
115 |
|
116 |
public void CreateContainer(string container) |
117 |
{ |
118 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
119 |
Contract.Requires(StorageUrl!=null); |
120 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
121 |
} |
122 |
|
123 |
public void DeleteContainer(string container) |
124 |
{ |
125 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
126 |
Contract.Requires(StorageUrl!=null); |
127 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
128 |
} |
129 |
|
130 |
public Stream GetObject(string container, string objectName) |
131 |
{ |
132 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
133 |
Contract.Requires(StorageUrl!=null); |
134 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
135 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
136 |
|
137 |
return default(Stream); |
138 |
} |
139 |
|
140 |
public Task PutObject(string container, string objectName, string fileName, string hash = null) |
141 |
{ |
142 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
143 |
Contract.Requires(StorageUrl!=null); |
144 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
145 |
Contract.Requires(!String.IsNullOrWhiteSpace(fileName)); |
146 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
147 |
|
148 |
return default(Task); |
149 |
} |
150 |
|
151 |
public void DeleteObject(string container, string objectName) |
152 |
{ |
153 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
154 |
Contract.Requires(StorageUrl!=null); |
155 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
156 |
Contract.Requires(!String.IsNullOrWhiteSpace(objectName)); |
157 |
} |
158 |
|
159 |
public void MoveObject(string container, string oldObjectName, string newObjectName) |
160 |
{ |
161 |
Contract.Requires(!String.IsNullOrWhiteSpace(Token)); |
162 |
Contract.Requires(StorageUrl!=null); |
163 |
Contract.Requires(!String.IsNullOrWhiteSpace(container)); |
164 |
Contract.Requires(!String.IsNullOrWhiteSpace(oldObjectName)); |
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 |
|
206 |
public class ObjectInfo |
207 |
{ |
208 |
public string Name { get; set; } |
209 |
public string Hash { get; set; } |
210 |
public long Bytes { get; set; } |
211 |
public string Content_Type { get; set; } |
212 |
public DateTime Last_Modified { get; set; } |
213 |
|
214 |
public static ObjectInfo Empty=new ObjectInfo {Name=String.Empty,Hash=String.Empty,Bytes=0,Content_Type=String.Empty,Last_Modified=DateTime.MinValue}; |
215 |
} |
216 |
} |