Fix for FileState.Create constraint violation in StatusAgent.cs
[pithos-ms-client] / trunk / Pithos.Core / IStatusKeeper.cs
index b4f2163..c039109 100644 (file)
@@ -1,9 +1,51 @@
+#region
+/* -----------------------------------------------------------------------
+ * <copyright file="IStatusKeeper.cs" company="GRNet">
+ * 
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ * </copyright>
+ * -----------------------------------------------------------------------
+ */
+#endregion
 using System;
 using System.Collections.Generic;
 using System.Diagnostics.Contracts;
 using System.IO;
 using System.Linq;
 using System.Threading;
+using System.Threading.Tasks;
 using Pithos.Interfaces;
 
 namespace Pithos.Core
@@ -11,37 +53,44 @@ namespace Pithos.Core
     [ContractClass(typeof(IStatusKeeperContract))]
     public interface IStatusKeeper
     {
-        void SetFileOverlayStatus(string path,FileOverlayStatus status);
-        void UpdateFileChecksum(string path, string checksum);
+        Task SetFileOverlayStatus(string path, FileOverlayStatus status, string shortHash = null);
+        void UpdateFileChecksum(string path, string shortHash, string checksum);
         void SetFileStatus(string path, FileStatus status);
         FileStatus GetFileStatus(string path);
         void ClearFileStatus(string path);
-        void SetPithosStatus(PithosStatus status);
         FileOverlayStatus GetFileOverlayStatus(string path);
         void ProcessExistingFiles(IEnumerable<FileInfo> paths);
         void Stop();
-        void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus);
+        void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus, string localFileMissingFromServer);
         void StoreInfo(string path, ObjectInfo objectInfo);
-        T GetStatus<T>(string path,Func<FileState,T> getter,T defaultValue );
-        void SetStatus(string path, Action<FileState> setter);        
+        //T GetStatus<T>(string path,Func<FileState,T> getter,T defaultValue );
+        //void SetStatus(string path, Action<FileState> setter);        
 
         void StartProcessing(CancellationToken token);
 
         string BlockHash { get; set; }
         int BlockSize { get; set; }
         void ChangeRoots(string oldPath, string newPath);
+        FileState GetStateByFilePath(string path);
+        void ClearFolderStatus(string path);
+        IEnumerable<FileState> GetChildren(FileState fileState);
+        void EnsureFileState(string path);
+
+        void CleanupStaleStates(Network.AccountInfo accountInfo, List<ObjectInfo> objectInfos);
+        void CleanupOrphanStates();
     }
 
     [ContractClassFor(typeof(IStatusKeeper))]
     public abstract class IStatusKeeperContract : IStatusKeeper
     {
-        public void SetFileOverlayStatus(string path, FileOverlayStatus status)
+        public Task SetFileOverlayStatus(string path, FileOverlayStatus status, string shortHash = null)
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(path));
             Contract.Requires(Path.IsPathRooted(path));
+            return default(Task);
         }
 
-        public void UpdateFileChecksum(string path, string checksum)
+        public void UpdateFileChecksum(string path, string shortHash, string checksum)
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(path));
             Contract.Requires(checksum!=null);
@@ -95,7 +144,7 @@ namespace Pithos.Core
             
         }
 
-        public void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus)
+        public void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus, string localFileMissingFromServer)
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(path));
             Contract.Requires(Path.IsPathRooted(path));
@@ -163,5 +212,43 @@ namespace Pithos.Core
             Contract.Requires(!string.IsNullOrWhiteSpace(newPath));
             Contract.Requires(Path.IsPathRooted(newPath));            
         }
+
+        public FileState GetStateByFilePath(string path)
+        {
+            Contract.Requires(!String.IsNullOrWhiteSpace(path));
+            Contract.Requires(Path.IsPathRooted(path));
+
+            return null;
+        }
+
+        public void ClearFolderStatus(string path)
+        {
+            Contract.Requires(!String.IsNullOrWhiteSpace(path));
+            Contract.Requires(Path.IsPathRooted(path));
+        }
+
+        public IEnumerable<FileState> GetChildren(FileState fileState)
+        {
+            Contract.Requires(fileState!=null);
+            Contract.Ensures(Contract.Result<IEnumerable<FileState>>()!=null);
+            return default(IEnumerable<FileState>);
+        }
+
+        public void EnsureFileState(string path)
+        {
+            
+        }
+
+
+        public void CleanupStaleStates(Network.AccountInfo accountInfo, List<ObjectInfo> objectInfos)
+        {
+            Contract.Requires(accountInfo != null);
+            Contract.Requires(objectInfos != null);
+        }
+
+
+        public void CleanupOrphanStates()
+        {            
+        }
     }
 }