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
50 using Pithos.Interfaces;
\r
51 using Pithos.Network;
\r
53 namespace Pithos.Core
\r
55 [ContractClass(typeof(IStatusKeeperContract))]
\r
56 public interface IStatusKeeper
\r
58 void SetFileOverlayStatus(string path, FileOverlayStatus status);
\r
59 void UpdateFileChecksum(string path, string etag, TreeHash treeHash);
\r
60 void UpdateFileHashes(string path, TreeHash treeHash);
\r
61 void SetFileStatus(string path, FileStatus status);
\r
62 FileStatus GetFileStatus(string path);
\r
63 void ClearFileStatus(string path);
\r
64 FileOverlayStatus GetFileOverlayStatus(string path);
\r
65 void ProcessExistingFiles(IEnumerable<FileInfo> paths);
\r
67 void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus, string localFileMissingFromServer);
\r
68 //Only update locations, not hashes
\r
69 void StoreInfo(string path, ObjectInfo objectInfo);
\r
70 void StoreInfo(string path, ObjectInfo objectInfo,TreeHash hash);
\r
71 //T GetStatus<T>(string path,Func<FileState,T> getter,T defaultValue );
\r
72 //void SetStatus(string path, Action<FileState> setter);
\r
74 void StartProcessing(CancellationToken token);
\r
76 string BlockHash { get; set; }
\r
77 int BlockSize { get; set; }
\r
78 IStatusNotification StatusNotification { get; set; }
\r
79 //ISessionFactory Factory { get; }
\r
80 //IQueryable<T> Query<T>();
\r
82 void ChangeRoots(string oldPath, string newPath);
\r
83 FileState GetStateByFilePath(string path);
\r
84 void ClearFolderStatus(string path);
\r
85 IEnumerable<FileState> GetChildren(FileState fileState);
\r
86 void EnsureFileState(string path);
\r
88 void CleanupStaleStates(Network.AccountInfo accountInfo, List<ObjectInfo> objectInfos);
\r
89 void CleanupOrphanStates();
\r
90 //void UpdateLastMD5(FileInfo path, string etag);
\r
91 void SaveCopy<T>(T state) where T:class;
\r
94 /// Mark Unversioned all FileState rows from the database whose path
\r
95 /// starts with one of the removed paths
\r
97 /// <param name="removed"></param>
\r
98 void UnversionPaths(List<string> removed);
\r
100 List<FileState> GetAllStates();
\r
101 List<string> GetAllStatePaths();
\r
102 List<FileState> GetConflictStates();
\r
105 [ContractClassFor(typeof(IStatusKeeper))]
\r
106 public abstract class IStatusKeeperContract : IStatusKeeper
\r
108 public void SetFileOverlayStatus(string path, FileOverlayStatus status)
\r
110 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
111 Contract.Requires(Path.IsPathRooted(path));
\r
115 public void UpdateFileChecksum(string path, string etag, TreeHash treeHash)
\r
117 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
118 Contract.Requires(treeHash!=null);
\r
119 Contract.Requires(Path.IsPathRooted(path));
\r
122 public void UpdateFileHashes(string path, TreeHash treeHash)
\r
124 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
125 Contract.Requires(treeHash!=null);
\r
126 Contract.Requires(Path.IsPathRooted(path));
\r
129 /* public void RemoveFileOverlayStatus(string path)
\r
131 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
132 Contract.Requires(Path.IsPathRooted(path));
\r
135 public void RenameFileOverlayStatus(string oldPath, string newPath)
\r
137 Contract.Requires(!String.IsNullOrWhiteSpace(oldPath));
\r
138 Contract.Requires(Path.IsPathRooted(oldPath));
\r
139 Contract.Requires(!String.IsNullOrWhiteSpace(newPath));
\r
140 Contract.Requires(Path.IsPathRooted(newPath));
\r
144 public void SetFileStatus(string path, FileStatus status)
\r
146 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
147 Contract.Requires(Path.IsPathRooted(path));
\r
150 public FileStatus GetFileStatus(string path)
\r
152 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
153 Contract.Requires(Path.IsPathRooted(path));
\r
155 return default(FileStatus);
\r
158 public FileOverlayStatus GetFileOverlayStatus(string path)
\r
160 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
161 Contract.Requires(Path.IsPathRooted(path));
\r
163 return default(FileOverlayStatus);
\r
166 public void ProcessExistingFiles(IEnumerable<FileInfo> paths)
\r
168 Contract.Requires(paths!=null);
\r
176 public void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus, string localFileMissingFromServer)
\r
178 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
179 Contract.Requires(Path.IsPathRooted(path));
\r
182 public void StoreInfo(string path, ObjectInfo objectInfo,TreeHash hash)
\r
184 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
185 Contract.Requires(objectInfo!=null);
\r
186 Contract.Requires(hash != null);
\r
187 Contract.Requires(Path.IsPathRooted(path));
\r
190 public void StoreInfo(string path, ObjectInfo objectInfo)
\r
192 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
193 Contract.Requires(objectInfo!=null);
\r
194 Contract.Requires(Path.IsPathRooted(path));
\r
197 public T GetStatus<T>(string path, Func<FileState, T> getter, T defaultValue)
\r
199 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
200 Contract.Requires(getter!=null);
\r
201 Contract.Requires(Path.IsPathRooted(path));
\r
206 public void SetStatus(string path, Action<FileState> setter)
\r
208 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
209 Contract.Requires(setter != null);
\r
210 Contract.Requires(Path.IsPathRooted(path));
\r
213 public void SetNetworkState(string path, NetworkOperation operation)
\r
215 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
216 Contract.Requires(Path.IsPathRooted(path));
\r
217 Contract.Requires(Path.IsPathRooted(path));
\r
220 public NetworkOperation GetNetworkState(string path)
\r
222 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
223 Contract.Requires(Path.IsPathRooted(path));
\r
225 return default(NetworkOperation);
\r
228 public void ClearFileStatus(string path)
\r
230 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
231 Contract.Requires(Path.IsPathRooted(path));
\r
234 public void SetPithosStatus(PithosStatus status)
\r
238 public void StartProcessing(CancellationToken token)
\r
240 Contract.Requires(token != null, "token can't be empty");
\r
243 public abstract string BlockHash { get; set; }
\r
244 public abstract int BlockSize { get; set; }
\r
246 public IStatusNotification StatusNotification { get; set; }
\r
248 public ISessionFactory Factory { get; private set; }
\r
250 public IQueryable<T> Query<T>()
\r
252 throw new NotImplementedException();
\r
255 public void ChangeRoots(string oldPath, string newPath)
\r
257 Contract.Requires(!String.IsNullOrWhiteSpace(oldPath));
\r
258 Contract.Requires(Path.IsPathRooted(oldPath));
\r
259 Contract.Requires(!string.IsNullOrWhiteSpace(newPath));
\r
260 Contract.Requires(Path.IsPathRooted(newPath));
\r
263 public FileState GetStateByFilePath(string path)
\r
265 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
266 Contract.Requires(Path.IsPathRooted(path));
\r
271 public void ClearFolderStatus(string path)
\r
273 Contract.Requires(!String.IsNullOrWhiteSpace(path));
\r
274 Contract.Requires(Path.IsPathRooted(path));
\r
277 public IEnumerable<FileState> GetChildren(FileState fileState)
\r
279 Contract.Requires(fileState!=null);
\r
280 Contract.Ensures(Contract.Result<IEnumerable<FileState>>()!=null);
\r
281 return default(IEnumerable<FileState>);
\r
284 public void EnsureFileState(string path)
\r
290 public void CleanupStaleStates(Network.AccountInfo accountInfo, List<ObjectInfo> objectInfos)
\r
292 Contract.Requires(accountInfo != null);
\r
293 Contract.Requires(objectInfos != null);
\r
297 public void CleanupOrphanStates()
\r
301 public void SaveCopy<T>(T state) where T:class
\r
303 Contract.Requires(state != null);
\r
306 public void UnversionPaths(List<string> removed)
\r
308 Contract.Requires(removed!=null);
\r
311 public List<FileState> GetAllStates()
\r
316 public List<string> GetAllStatePaths()
\r
321 public List<FileState> GetConflictStates()
\r
326 //public void UpdateLastMD5(FileInfo path, string etag)
\r