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