8c49f0c28a062681af107c8ce70a05a9fdcaf073
[pithos-ms-client] / trunk / Pithos.Core / IStatusKeeper.cs
1 #region\r
2 /* -----------------------------------------------------------------------\r
3  * <copyright file="IStatusKeeper.cs" company="GRNet">\r
4  * \r
5  * Copyright 2011-2012 GRNET S.A. All rights reserved.\r
6  *\r
7  * Redistribution and use in source and binary forms, with or\r
8  * without modification, are permitted provided that the following\r
9  * conditions are met:\r
10  *\r
11  *   1. Redistributions of source code must retain the above\r
12  *      copyright notice, this list of conditions and the following\r
13  *      disclaimer.\r
14  *\r
15  *   2. Redistributions in binary form must reproduce the above\r
16  *      copyright notice, this list of conditions and the following\r
17  *      disclaimer in the documentation and/or other materials\r
18  *      provided with the distribution.\r
19  *\r
20  *\r
21  * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS\r
22  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
24  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR\r
25  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
28  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED\r
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
32  * POSSIBILITY OF SUCH DAMAGE.\r
33  *\r
34  * The views and conclusions contained in the software and\r
35  * documentation are those of the authors and should not be\r
36  * interpreted as representing official policies, either expressed\r
37  * or implied, of GRNET S.A.\r
38  * </copyright>\r
39  * -----------------------------------------------------------------------\r
40  */\r
41 #endregion\r
42 using System;\r
43 using System.Collections.Generic;\r
44 using System.Diagnostics.Contracts;\r
45 using System.IO;\r
46 using System.Linq;\r
47 using System.Threading;\r
48 using System.Threading.Tasks;\r
49 using Pithos.Interfaces;\r
50 using Pithos.Network;\r
51 \r
52 namespace Pithos.Core\r
53 {\r
54     [ContractClass(typeof(IStatusKeeperContract))]\r
55     public interface IStatusKeeper\r
56     {\r
57         Task SetFileOverlayStatus(string path, FileOverlayStatus status, string etag = null);\r
58         void UpdateFileChecksum(string path, string etag, string checksum);\r
59         void UpdateFileTreeHash(string path, TreeHash treeHash);\r
60         void SetFileStatus(string path, FileStatus status);\r
61         FileStatus GetFileStatus(string path);\r
62         void ClearFileStatus(string path);\r
63         FileOverlayStatus GetFileOverlayStatus(string path);\r
64         void ProcessExistingFiles(IEnumerable<FileInfo> paths);\r
65         void Stop();\r
66         void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus, string localFileMissingFromServer);\r
67         void StoreInfo(string path, ObjectInfo objectInfo);\r
68         //T GetStatus<T>(string path,Func<FileState,T> getter,T defaultValue );\r
69         //void SetStatus(string path, Action<FileState> setter);        \r
70 \r
71         void StartProcessing(CancellationToken token);\r
72 \r
73         string BlockHash { get; set; }\r
74         int BlockSize { get; set; }\r
75         IStatusNotification StatusNotification { get; set; }\r
76 \r
77         void ChangeRoots(string oldPath, string newPath);\r
78         FileState GetStateByFilePath(string path);\r
79         void ClearFolderStatus(string path);\r
80         IEnumerable<FileState> GetChildren(FileState fileState);\r
81         void EnsureFileState(string path);\r
82 \r
83         void CleanupStaleStates(Network.AccountInfo accountInfo, List<ObjectInfo> objectInfos);\r
84         void CleanupOrphanStates();\r
85         void UpdateLastMD5(FileInfo path, string etag);\r
86     }\r
87 \r
88     [ContractClassFor(typeof(IStatusKeeper))]\r
89     public abstract class IStatusKeeperContract : IStatusKeeper\r
90     {\r
91         public Task SetFileOverlayStatus(string path, FileOverlayStatus status, string etag = null)\r
92         {\r
93             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
94             Contract.Requires(Path.IsPathRooted(path));\r
95             return default(Task);\r
96         }\r
97 \r
98         public void UpdateFileChecksum(string path, string etag, string checksum)\r
99         {\r
100             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
101             Contract.Requires(checksum!=null);\r
102             Contract.Requires(Path.IsPathRooted(path));\r
103         }\r
104 \r
105         public void UpdateFileTreeHash(string path, TreeHash treeHash)\r
106         {\r
107             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
108             Contract.Requires(treeHash!=null);\r
109             Contract.Requires(Path.IsPathRooted(path));\r
110         }\r
111 \r
112      /*   public void RemoveFileOverlayStatus(string path)\r
113         {\r
114             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
115             Contract.Requires(Path.IsPathRooted(path));\r
116         }*/\r
117 \r
118         public void RenameFileOverlayStatus(string oldPath, string newPath)\r
119         {\r
120             Contract.Requires(!String.IsNullOrWhiteSpace(oldPath));\r
121             Contract.Requires(Path.IsPathRooted(oldPath));\r
122             Contract.Requires(!String.IsNullOrWhiteSpace(newPath));\r
123             Contract.Requires(Path.IsPathRooted(newPath));\r
124 \r
125         }\r
126 \r
127         public void SetFileStatus(string path, FileStatus status)\r
128         {\r
129             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
130             Contract.Requires(Path.IsPathRooted(path));\r
131         }\r
132 \r
133         public FileStatus GetFileStatus(string path)\r
134         {\r
135             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
136             Contract.Requires(Path.IsPathRooted(path));\r
137 \r
138             return default(FileStatus);\r
139         }\r
140 \r
141         public FileOverlayStatus GetFileOverlayStatus(string path)\r
142         {\r
143             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
144             Contract.Requires(Path.IsPathRooted(path));\r
145 \r
146             return default(FileOverlayStatus);\r
147         }\r
148 \r
149         public void ProcessExistingFiles(IEnumerable<FileInfo> paths)\r
150         {\r
151             Contract.Requires(paths!=null);\r
152         }\r
153 \r
154         public void Stop()\r
155         {\r
156             \r
157         }\r
158 \r
159         public void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus, string localFileMissingFromServer)\r
160         {\r
161             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
162             Contract.Requires(Path.IsPathRooted(path));\r
163         }\r
164 \r
165         public void StoreInfo(string path, ObjectInfo objectInfo)\r
166         {\r
167             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
168             Contract.Requires(objectInfo!=null);\r
169             Contract.Requires(Path.IsPathRooted(path));\r
170         }\r
171 \r
172         public T GetStatus<T>(string path, Func<FileState, T> getter, T defaultValue)\r
173         {\r
174             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
175             Contract.Requires(getter!=null);\r
176             Contract.Requires(Path.IsPathRooted(path));\r
177 \r
178             return default(T);\r
179         }\r
180 \r
181         public void SetStatus(string path, Action<FileState> setter)\r
182         {\r
183             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
184             Contract.Requires(setter != null);\r
185             Contract.Requires(Path.IsPathRooted(path));\r
186         }\r
187 \r
188         public void SetNetworkState(string path, NetworkOperation operation)\r
189         {\r
190             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
191             Contract.Requires(Path.IsPathRooted(path));\r
192             Contract.Requires(Path.IsPathRooted(path));\r
193         }\r
194 \r
195         public NetworkOperation GetNetworkState(string path)\r
196         {\r
197             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
198             Contract.Requires(Path.IsPathRooted(path));\r
199 \r
200             return default(NetworkOperation);\r
201         }\r
202 \r
203         public void ClearFileStatus(string path)\r
204         {\r
205             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
206             Contract.Requires(Path.IsPathRooted(path));\r
207         }\r
208 \r
209         public void SetPithosStatus(PithosStatus status)\r
210         {\r
211         }\r
212 \r
213         public void StartProcessing(CancellationToken token)\r
214         {\r
215             Contract.Requires(token != null, "token can't be empty");\r
216         }\r
217 \r
218         public abstract string BlockHash { get; set; }\r
219         public abstract int BlockSize { get; set; }\r
220 \r
221         public IStatusNotification StatusNotification { get; set; }\r
222 \r
223         public void ChangeRoots(string oldPath, string newPath)\r
224         {\r
225             Contract.Requires(!String.IsNullOrWhiteSpace(oldPath));\r
226             Contract.Requires(Path.IsPathRooted(oldPath));\r
227             Contract.Requires(!string.IsNullOrWhiteSpace(newPath));\r
228             Contract.Requires(Path.IsPathRooted(newPath));            \r
229         }\r
230 \r
231         public FileState GetStateByFilePath(string path)\r
232         {\r
233             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
234             Contract.Requires(Path.IsPathRooted(path));\r
235 \r
236             return null;\r
237         }\r
238 \r
239         public void ClearFolderStatus(string path)\r
240         {\r
241             Contract.Requires(!String.IsNullOrWhiteSpace(path));\r
242             Contract.Requires(Path.IsPathRooted(path));\r
243         }\r
244 \r
245         public IEnumerable<FileState> GetChildren(FileState fileState)\r
246         {\r
247             Contract.Requires(fileState!=null);\r
248             Contract.Ensures(Contract.Result<IEnumerable<FileState>>()!=null);\r
249             return default(IEnumerable<FileState>);\r
250         }\r
251 \r
252         public void EnsureFileState(string path)\r
253         {\r
254             \r
255         }\r
256 \r
257 \r
258         public void CleanupStaleStates(Network.AccountInfo accountInfo, List<ObjectInfo> objectInfos)\r
259         {\r
260             Contract.Requires(accountInfo != null);\r
261             Contract.Requires(objectInfos != null);\r
262         }\r
263 \r
264 \r
265         public void CleanupOrphanStates()\r
266         {            \r
267         }\r
268 \r
269         public void UpdateLastMD5(FileInfo path, string etag)\r
270         {\r
271             \r
272         }\r
273     }\r
274 }\r