Added header to all files. Closes #2064
[pithos-ms-client] / trunk / Pithos.Core / IStatusKeeper.cs
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 Pithos.Interfaces;
49
50 namespace Pithos.Core
51 {
52     [ContractClass(typeof(IStatusKeeperContract))]
53     public interface IStatusKeeper
54     {
55         void SetFileOverlayStatus(string path,FileOverlayStatus status);
56         void UpdateFileChecksum(string path, string checksum);
57         void SetFileStatus(string path, FileStatus status);
58         FileStatus GetFileStatus(string path);
59         void ClearFileStatus(string path);
60         void SetPithosStatus(PithosStatus status);
61         FileOverlayStatus GetFileOverlayStatus(string path);
62         void ProcessExistingFiles(IEnumerable<FileInfo> paths);
63         void Stop();
64         void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus);
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     }
78
79     [ContractClassFor(typeof(IStatusKeeper))]
80     public abstract class IStatusKeeperContract : IStatusKeeper
81     {
82         public void SetFileOverlayStatus(string path, FileOverlayStatus status)
83         {
84             Contract.Requires(!String.IsNullOrWhiteSpace(path));
85             Contract.Requires(Path.IsPathRooted(path));
86         }
87
88         public void UpdateFileChecksum(string path, string checksum)
89         {
90             Contract.Requires(!String.IsNullOrWhiteSpace(path));
91             Contract.Requires(checksum!=null);
92             Contract.Requires(Path.IsPathRooted(path));
93         }
94
95      /*   public void RemoveFileOverlayStatus(string path)
96         {
97             Contract.Requires(!String.IsNullOrWhiteSpace(path));
98             Contract.Requires(Path.IsPathRooted(path));
99         }*/
100
101         public void RenameFileOverlayStatus(string oldPath, string newPath)
102         {
103             Contract.Requires(!String.IsNullOrWhiteSpace(oldPath));
104             Contract.Requires(Path.IsPathRooted(oldPath));
105             Contract.Requires(!String.IsNullOrWhiteSpace(newPath));
106             Contract.Requires(Path.IsPathRooted(newPath));
107
108         }
109
110         public void SetFileStatus(string path, FileStatus status)
111         {
112             Contract.Requires(!String.IsNullOrWhiteSpace(path));
113             Contract.Requires(Path.IsPathRooted(path));
114         }
115
116         public FileStatus GetFileStatus(string path)
117         {
118             Contract.Requires(!String.IsNullOrWhiteSpace(path));
119             Contract.Requires(Path.IsPathRooted(path));
120
121             return default(FileStatus);
122         }
123
124         public FileOverlayStatus GetFileOverlayStatus(string path)
125         {
126             Contract.Requires(!String.IsNullOrWhiteSpace(path));
127             Contract.Requires(Path.IsPathRooted(path));
128
129             return default(FileOverlayStatus);
130         }
131
132         public void ProcessExistingFiles(IEnumerable<FileInfo> paths)
133         {
134             Contract.Requires(paths!=null);
135         }
136
137         public void Stop()
138         {
139             
140         }
141
142         public void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus)
143         {
144             Contract.Requires(!String.IsNullOrWhiteSpace(path));
145             Contract.Requires(Path.IsPathRooted(path));
146         }
147
148         public void StoreInfo(string path, ObjectInfo objectInfo)
149         {
150             Contract.Requires(!String.IsNullOrWhiteSpace(path));
151             Contract.Requires(objectInfo!=null);
152             Contract.Requires(Path.IsPathRooted(path));
153         }
154
155         public T GetStatus<T>(string path, Func<FileState, T> getter, T defaultValue)
156         {
157             Contract.Requires(!String.IsNullOrWhiteSpace(path));
158             Contract.Requires(getter!=null);
159             Contract.Requires(Path.IsPathRooted(path));
160
161             return default(T);
162         }
163
164         public void SetStatus(string path, Action<FileState> setter)
165         {
166             Contract.Requires(!String.IsNullOrWhiteSpace(path));
167             Contract.Requires(setter != null);
168             Contract.Requires(Path.IsPathRooted(path));
169         }
170
171         public void SetNetworkState(string path, NetworkOperation operation)
172         {
173             Contract.Requires(!String.IsNullOrWhiteSpace(path));
174             Contract.Requires(Path.IsPathRooted(path));
175             Contract.Requires(Path.IsPathRooted(path));
176         }
177
178         public NetworkOperation GetNetworkState(string path)
179         {
180             Contract.Requires(!String.IsNullOrWhiteSpace(path));
181             Contract.Requires(Path.IsPathRooted(path));
182
183             return default(NetworkOperation);
184         }
185
186         public void ClearFileStatus(string path)
187         {
188             Contract.Requires(!String.IsNullOrWhiteSpace(path));
189             Contract.Requires(Path.IsPathRooted(path));
190         }
191
192         public void SetPithosStatus(PithosStatus status)
193         {
194         }
195
196         public void StartProcessing(CancellationToken token)
197         {
198             Contract.Requires(token != null, "token can't be empty");
199         }
200
201         public abstract string BlockHash { get; set; }
202         public abstract int BlockSize { get; set; }
203         public void ChangeRoots(string oldPath, string newPath)
204         {
205             Contract.Requires(!String.IsNullOrWhiteSpace(oldPath));
206             Contract.Requires(Path.IsPathRooted(oldPath));
207             Contract.Requires(!string.IsNullOrWhiteSpace(newPath));
208             Contract.Requires(Path.IsPathRooted(newPath));            
209         }
210
211         public FileState GetStateByFilePath(string path)
212         {
213             Contract.Requires(!String.IsNullOrWhiteSpace(path));
214             Contract.Requires(Path.IsPathRooted(path));
215
216             return null;
217         }
218
219         public void ClearFolderStatus(string path)
220         {
221             Contract.Requires(!String.IsNullOrWhiteSpace(path));
222             Contract.Requires(Path.IsPathRooted(path));
223         }
224
225         public IEnumerable<FileState> GetChildren(FileState fileState)
226         {
227             Contract.Requires(fileState!=null);
228             Contract.Ensures(Contract.Result<IEnumerable<FileState>>()!=null);
229             return default(IEnumerable<FileState>);
230         }
231     }
232 }