2 /* -----------------------------------------------------------------------
\r
3 * <copyright file="IStatusKeeper.cs" company="GRNet">
\r
5 * Copyright 2011-2012 GRNET S.A. All rights reserved.
\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
11 * 1. Redistributions of source code must retain the above
\r
12 * copyright notice, this list of conditions and the following
\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
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
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
39 * -----------------------------------------------------------------------
\r
43 using System.Collections.Generic;
\r
44 using System.Diagnostics.Contracts;
\r
47 using System.Threading;
\r
48 using System.Threading.Tasks;
\r
49 using Pithos.Interfaces;
\r
50 using Pithos.Network;
\r
52 namespace Pithos.Core
\r
54 [ContractClass(typeof(IStatusKeeperContract))]
\r
55 public interface IStatusKeeper
\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
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
71 void StartProcessing(CancellationToken token);
\r
73 string BlockHash { get; set; }
\r
74 int BlockSize { get; set; }
\r
75 IStatusNotification StatusNotification { get; set; }
\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
83 void CleanupStaleStates(Network.AccountInfo accountInfo, List<ObjectInfo> objectInfos);
\r
84 void CleanupOrphanStates();
\r
85 void UpdateLastMD5(FileInfo path, string etag);
\r
88 [ContractClassFor(typeof(IStatusKeeper))]
\r
89 public abstract class IStatusKeeperContract : IStatusKeeper
\r
91 public Task SetFileOverlayStatus(string path, FileOverlayStatus status, string etag = null)
\r
93 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
94 Contract.Requires(Path.IsPathRooted(path));
\r
95 return default(Task);
\r
98 public void UpdateFileChecksum(string path, string etag, string checksum)
\r
100 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
101 Contract.Requires(checksum!=null);
\r
102 Contract.Requires(Path.IsPathRooted(path));
\r
105 public void UpdateFileTreeHash(string path, TreeHash treeHash)
\r
107 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
108 Contract.Requires(treeHash!=null);
\r
109 Contract.Requires(Path.IsPathRooted(path));
\r
112 /* public void RemoveFileOverlayStatus(string path)
\r
114 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
115 Contract.Requires(Path.IsPathRooted(path));
\r
118 public void RenameFileOverlayStatus(string oldPath, string newPath)
\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
127 public void SetFileStatus(string path, FileStatus status)
\r
129 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
130 Contract.Requires(Path.IsPathRooted(path));
\r
133 public FileStatus GetFileStatus(string path)
\r
135 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
136 Contract.Requires(Path.IsPathRooted(path));
\r
138 return default(FileStatus);
\r
141 public FileOverlayStatus GetFileOverlayStatus(string path)
\r
143 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
144 Contract.Requires(Path.IsPathRooted(path));
\r
146 return default(FileOverlayStatus);
\r
149 public void ProcessExistingFiles(IEnumerable<FileInfo> paths)
\r
151 Contract.Requires(paths!=null);
\r
159 public void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus, string localFileMissingFromServer)
\r
161 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
162 Contract.Requires(Path.IsPathRooted(path));
\r
165 public void StoreInfo(string path, ObjectInfo objectInfo)
\r
167 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
168 Contract.Requires(objectInfo!=null);
\r
169 Contract.Requires(Path.IsPathRooted(path));
\r
172 public T GetStatus<T>(string path, Func<FileState, T> getter, T defaultValue)
\r
174 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
175 Contract.Requires(getter!=null);
\r
176 Contract.Requires(Path.IsPathRooted(path));
\r
181 public void SetStatus(string path, Action<FileState> setter)
\r
183 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
184 Contract.Requires(setter != null);
\r
185 Contract.Requires(Path.IsPathRooted(path));
\r
188 public void SetNetworkState(string path, NetworkOperation operation)
\r
190 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
191 Contract.Requires(Path.IsPathRooted(path));
\r
192 Contract.Requires(Path.IsPathRooted(path));
\r
195 public NetworkOperation GetNetworkState(string path)
\r
197 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
198 Contract.Requires(Path.IsPathRooted(path));
\r
200 return default(NetworkOperation);
\r
203 public void ClearFileStatus(string path)
\r
205 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
206 Contract.Requires(Path.IsPathRooted(path));
\r
209 public void SetPithosStatus(PithosStatus status)
\r
213 public void StartProcessing(CancellationToken token)
\r
215 Contract.Requires(token != null, "token can't be empty");
\r
218 public abstract string BlockHash { get; set; }
\r
219 public abstract int BlockSize { get; set; }
\r
221 public IStatusNotification StatusNotification { get; set; }
\r
223 public void ChangeRoots(string oldPath, string newPath)
\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
231 public FileState GetStateByFilePath(string path)
\r
233 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
234 Contract.Requires(Path.IsPathRooted(path));
\r
239 public void ClearFolderStatus(string path)
\r
241 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
242 Contract.Requires(Path.IsPathRooted(path));
\r
245 public IEnumerable<FileState> GetChildren(FileState fileState)
\r
247 Contract.Requires(fileState!=null);
\r
248 Contract.Ensures(Contract.Result<IEnumerable<FileState>>()!=null);
\r
249 return default(IEnumerable<FileState>);
\r
252 public void EnsureFileState(string path)
\r
258 public void CleanupStaleStates(Network.AccountInfo accountInfo, List<ObjectInfo> objectInfos)
\r
260 Contract.Requires(accountInfo != null);
\r
261 Contract.Requires(objectInfos != null);
\r
265 public void CleanupOrphanStates()
\r
269 public void UpdateLastMD5(FileInfo path, string etag)
\r