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