root / trunk / Pithos.Core / IStatusKeeper.cs @ 0a9d4d18
History | View | Annotate | Download (9 kB)
1 |
#region |
---|---|
2 |
/* ----------------------------------------------------------------------- |
3 |
* <copyright file="IStatusKeeper.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.IO; |
46 |
using System.Linq; |
47 |
using System.Threading; |
48 |
using System.Threading.Tasks; |
49 |
using Pithos.Interfaces; |
50 |
|
51 |
namespace Pithos.Core |
52 |
{ |
53 |
[ContractClass(typeof(IStatusKeeperContract))] |
54 |
public interface IStatusKeeper |
55 |
{ |
56 |
Task SetFileOverlayStatus(string path, FileOverlayStatus status, string shortHash = null); |
57 |
void UpdateFileChecksum(string path, string shortHash, string checksum); |
58 |
void SetFileStatus(string path, FileStatus status); |
59 |
FileStatus GetFileStatus(string path); |
60 |
void ClearFileStatus(string path); |
61 |
FileOverlayStatus GetFileOverlayStatus(string path); |
62 |
void ProcessExistingFiles(IEnumerable<FileInfo> paths); |
63 |
void Stop(); |
64 |
void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus, string localFileMissingFromServer); |
65 |
void StoreInfo(string path, ObjectInfo objectInfo); |
66 |
//T GetStatus<T>(string path,Func<FileState,T> getter,T defaultValue ); |
67 |
//void SetStatus(string path, Action<FileState> setter); |
68 |
|
69 |
void StartProcessing(CancellationToken token); |
70 |
|
71 |
string BlockHash { get; set; } |
72 |
int BlockSize { get; set; } |
73 |
void ChangeRoots(string oldPath, string newPath); |
74 |
FileState GetStateByFilePath(string path); |
75 |
void ClearFolderStatus(string path); |
76 |
IEnumerable<FileState> GetChildren(FileState fileState); |
77 |
void EnsureFileState(string path); |
78 |
|
79 |
void CleanupStaleStates(Network.AccountInfo accountInfo, List<ObjectInfo> objectInfos); |
80 |
void CleanupOrphanStates(); |
81 |
} |
82 |
|
83 |
[ContractClassFor(typeof(IStatusKeeper))] |
84 |
public abstract class IStatusKeeperContract : IStatusKeeper |
85 |
{ |
86 |
public Task SetFileOverlayStatus(string path, FileOverlayStatus status, string shortHash = null) |
87 |
{ |
88 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
89 |
Contract.Requires(Path.IsPathRooted(path)); |
90 |
return default(Task); |
91 |
} |
92 |
|
93 |
public void UpdateFileChecksum(string path, string shortHash, string checksum) |
94 |
{ |
95 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
96 |
Contract.Requires(checksum!=null); |
97 |
Contract.Requires(Path.IsPathRooted(path)); |
98 |
} |
99 |
|
100 |
/* public void RemoveFileOverlayStatus(string path) |
101 |
{ |
102 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
103 |
Contract.Requires(Path.IsPathRooted(path)); |
104 |
}*/ |
105 |
|
106 |
public void RenameFileOverlayStatus(string oldPath, string newPath) |
107 |
{ |
108 |
Contract.Requires(!String.IsNullOrWhiteSpace(oldPath)); |
109 |
Contract.Requires(Path.IsPathRooted(oldPath)); |
110 |
Contract.Requires(!String.IsNullOrWhiteSpace(newPath)); |
111 |
Contract.Requires(Path.IsPathRooted(newPath)); |
112 |
|
113 |
} |
114 |
|
115 |
public void SetFileStatus(string path, FileStatus status) |
116 |
{ |
117 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
118 |
Contract.Requires(Path.IsPathRooted(path)); |
119 |
} |
120 |
|
121 |
public FileStatus GetFileStatus(string path) |
122 |
{ |
123 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
124 |
Contract.Requires(Path.IsPathRooted(path)); |
125 |
|
126 |
return default(FileStatus); |
127 |
} |
128 |
|
129 |
public FileOverlayStatus GetFileOverlayStatus(string path) |
130 |
{ |
131 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
132 |
Contract.Requires(Path.IsPathRooted(path)); |
133 |
|
134 |
return default(FileOverlayStatus); |
135 |
} |
136 |
|
137 |
public void ProcessExistingFiles(IEnumerable<FileInfo> paths) |
138 |
{ |
139 |
Contract.Requires(paths!=null); |
140 |
} |
141 |
|
142 |
public void Stop() |
143 |
{ |
144 |
|
145 |
} |
146 |
|
147 |
public void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus, string localFileMissingFromServer) |
148 |
{ |
149 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
150 |
Contract.Requires(Path.IsPathRooted(path)); |
151 |
} |
152 |
|
153 |
public void StoreInfo(string path, ObjectInfo objectInfo) |
154 |
{ |
155 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
156 |
Contract.Requires(objectInfo!=null); |
157 |
Contract.Requires(Path.IsPathRooted(path)); |
158 |
} |
159 |
|
160 |
public T GetStatus<T>(string path, Func<FileState, T> getter, T defaultValue) |
161 |
{ |
162 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
163 |
Contract.Requires(getter!=null); |
164 |
Contract.Requires(Path.IsPathRooted(path)); |
165 |
|
166 |
return default(T); |
167 |
} |
168 |
|
169 |
public void SetStatus(string path, Action<FileState> setter) |
170 |
{ |
171 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
172 |
Contract.Requires(setter != null); |
173 |
Contract.Requires(Path.IsPathRooted(path)); |
174 |
} |
175 |
|
176 |
public void SetNetworkState(string path, NetworkOperation operation) |
177 |
{ |
178 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
179 |
Contract.Requires(Path.IsPathRooted(path)); |
180 |
Contract.Requires(Path.IsPathRooted(path)); |
181 |
} |
182 |
|
183 |
public NetworkOperation GetNetworkState(string path) |
184 |
{ |
185 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
186 |
Contract.Requires(Path.IsPathRooted(path)); |
187 |
|
188 |
return default(NetworkOperation); |
189 |
} |
190 |
|
191 |
public void ClearFileStatus(string path) |
192 |
{ |
193 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
194 |
Contract.Requires(Path.IsPathRooted(path)); |
195 |
} |
196 |
|
197 |
public void SetPithosStatus(PithosStatus status) |
198 |
{ |
199 |
} |
200 |
|
201 |
public void StartProcessing(CancellationToken token) |
202 |
{ |
203 |
Contract.Requires(token != null, "token can't be empty"); |
204 |
} |
205 |
|
206 |
public abstract string BlockHash { get; set; } |
207 |
public abstract int BlockSize { get; set; } |
208 |
public void ChangeRoots(string oldPath, string newPath) |
209 |
{ |
210 |
Contract.Requires(!String.IsNullOrWhiteSpace(oldPath)); |
211 |
Contract.Requires(Path.IsPathRooted(oldPath)); |
212 |
Contract.Requires(!string.IsNullOrWhiteSpace(newPath)); |
213 |
Contract.Requires(Path.IsPathRooted(newPath)); |
214 |
} |
215 |
|
216 |
public FileState GetStateByFilePath(string path) |
217 |
{ |
218 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
219 |
Contract.Requires(Path.IsPathRooted(path)); |
220 |
|
221 |
return null; |
222 |
} |
223 |
|
224 |
public void ClearFolderStatus(string path) |
225 |
{ |
226 |
Contract.Requires(!String.IsNullOrWhiteSpace(path)); |
227 |
Contract.Requires(Path.IsPathRooted(path)); |
228 |
} |
229 |
|
230 |
public IEnumerable<FileState> GetChildren(FileState fileState) |
231 |
{ |
232 |
Contract.Requires(fileState!=null); |
233 |
Contract.Ensures(Contract.Result<IEnumerable<FileState>>()!=null); |
234 |
return default(IEnumerable<FileState>); |
235 |
} |
236 |
|
237 |
public void EnsureFileState(string path) |
238 |
{ |
239 |
|
240 |
} |
241 |
|
242 |
|
243 |
public void CleanupStaleStates(Network.AccountInfo accountInfo, List<ObjectInfo> objectInfos) |
244 |
{ |
245 |
Contract.Requires(accountInfo != null); |
246 |
Contract.Requires(objectInfos != null); |
247 |
} |
248 |
|
249 |
|
250 |
public void CleanupOrphanStates() |
251 |
{ |
252 |
} |
253 |
} |
254 |
} |