#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 Pithos.Interfaces;
namespace Pithos.Core
{
[ContractClass(typeof(IStatusKeeperContract))]
public interface IStatusKeeper
{
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);
FileOverlayStatus GetFileOverlayStatus(string path);
void ProcessExistingFiles(IEnumerable paths);
void Stop();
void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus, string localFileMissingFromServer);
void StoreInfo(string path, ObjectInfo objectInfo);
//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; }
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();
}
[ContractClassFor(typeof(IStatusKeeper))]
public abstract class IStatusKeeperContract : IStatusKeeper
{
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 shortHash, string checksum)
{
Contract.Requires(!String.IsNullOrWhiteSpace(path));
Contract.Requires(checksum!=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)
{
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 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()
{
}
}
}