#region /* ----------------------------------------------------------------------- * * * 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. * * ----------------------------------------------------------------------- */ #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 NHibernate; using Pithos.Interfaces; using Pithos.Network; namespace Pithos.Core { [ContractClass(typeof(IStatusKeeperContract))] public interface IStatusKeeper { void SetFileOverlayStatus(string path, FileOverlayStatus status); void UpdateFileChecksum(string path, string etag, TreeHash treeHash); void UpdateFileHashes(string path, TreeHash treeHash); void SetFileStatus(string path, FileStatus status); FileStatus GetFileStatus(string path); void ClearFileStatus(string path); FileOverlayStatus GetFileOverlayStatus(string path); void ProcessExistingFiles(IEnumerable paths); void Stop(); void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus, string localFileMissingFromServer); //Only update locations, not hashes void StoreInfo(string path, ObjectInfo objectInfo); void StoreInfo(string path, ObjectInfo objectInfo,TreeHash hash); //T GetStatus(string path,Func getter,T defaultValue ); //void SetStatus(string path, Action setter); void StartProcessing(CancellationToken token); string BlockHash { get; set; } int BlockSize { get; set; } IStatusNotification StatusNotification { get; set; } //ISessionFactory Factory { get; } //IQueryable Query(); void ChangeRoots(string oldPath, string newPath); FileState GetStateByFilePath(string path); void ClearFolderStatus(string path); IEnumerable GetChildren(FileState fileState); void EnsureFileState(string path); void CleanupStaleStates(Network.AccountInfo accountInfo, List objectInfos); void CleanupOrphanStates(); //void UpdateLastMD5(FileInfo path, string etag); void SaveCopy(T state) where T:class; /// /// Mark Unversioned all FileState rows from the database whose path /// starts with one of the removed paths /// /// void UnversionPaths(List removed); List GetAllStates(); List GetAllStatePaths(); List GetConflictStates(); } [ContractClassFor(typeof(IStatusKeeper))] public abstract class IStatusKeeperContract : IStatusKeeper { public void SetFileOverlayStatus(string path, FileOverlayStatus status) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(Path.IsPathRooted(path)); } public void UpdateFileChecksum(string path, string etag, TreeHash treeHash) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(treeHash!=null); Contract.Requires(Path.IsPathRooted(path)); } public void UpdateFileHashes(string path, TreeHash treeHash) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(treeHash!=null); Contract.Requires(Path.IsPathRooted(path)); } /* public void RemoveFileOverlayStatus(string path) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(Path.IsPathRooted(path)); }*/ public void RenameFileOverlayStatus(string oldPath, string newPath) { Contract.Requires(!String.IsNullOrWhiteSpace(oldPath)); Contract.Requires(Path.IsPathRooted(oldPath)); Contract.Requires(!String.IsNullOrWhiteSpace(newPath)); Contract.Requires(Path.IsPathRooted(newPath)); } public void SetFileStatus(string path, FileStatus status) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(Path.IsPathRooted(path)); } public FileStatus GetFileStatus(string path) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(Path.IsPathRooted(path)); return default(FileStatus); } public FileOverlayStatus GetFileOverlayStatus(string path) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(Path.IsPathRooted(path)); return default(FileOverlayStatus); } public void ProcessExistingFiles(IEnumerable paths) { Contract.Requires(paths!=null); } public void Stop() { } public void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus, string localFileMissingFromServer) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(Path.IsPathRooted(path)); } public void StoreInfo(string path, ObjectInfo objectInfo,TreeHash hash) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(objectInfo!=null); Contract.Requires(hash != null); Contract.Requires(Path.IsPathRooted(path)); } public void StoreInfo(string path, ObjectInfo objectInfo) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(objectInfo!=null); Contract.Requires(Path.IsPathRooted(path)); } public T GetStatus(string path, Func getter, T defaultValue) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(getter!=null); Contract.Requires(Path.IsPathRooted(path)); return default(T); } public void SetStatus(string path, Action setter) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(setter != null); Contract.Requires(Path.IsPathRooted(path)); } public void SetNetworkState(string path, NetworkOperation operation) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(Path.IsPathRooted(path)); Contract.Requires(Path.IsPathRooted(path)); } public NetworkOperation GetNetworkState(string path) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(Path.IsPathRooted(path)); return default(NetworkOperation); } public void ClearFileStatus(string path) { Contract.Requires(!String.IsNullOrWhiteSpace(path)); Contract.Requires(Path.IsPathRooted(path)); } public void SetPithosStatus(PithosStatus status) { } public void StartProcessing(CancellationToken token) { Contract.Requires(token != null, "token can't be empty"); } public abstract string BlockHash { get; set; } public abstract int BlockSize { get; set; } public IStatusNotification StatusNotification { get; set; } public ISessionFactory Factory { get; private set; } public IQueryable Query() { throw new NotImplementedException(); } public void ChangeRoots(string oldPath, string newPath) { Contract.Requires(!String.IsNullOrWhiteSpace(oldPath)); Contract.Requires(Path.IsPathRooted(oldPath)); 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 GetChildren(FileState fileState) { Contract.Requires(fileState!=null); Contract.Ensures(Contract.Result>()!=null); return default(IEnumerable); } public void EnsureFileState(string path) { } public void CleanupStaleStates(Network.AccountInfo accountInfo, List objectInfos) { Contract.Requires(accountInfo != null); Contract.Requires(objectInfos != null); } public void CleanupOrphanStates() { } public void SaveCopy(T state) where T:class { Contract.Requires(state != null); } public void UnversionPaths(List removed) { Contract.Requires(removed!=null); } public List GetAllStates() { return null; } public List GetAllStatePaths() { return null; } public List GetConflictStates() { return null; } //public void UpdateLastMD5(FileInfo path, string etag) //{ //} } }