using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.Diagnostics.Contracts; using Pithos.Interfaces; namespace Pithos.Core { //[Export(typeof(IStatusChecker)),Export(typeof(IStatusKeeper))] public class InMemStatusChecker:IStatusChecker,IStatusKeeper { [Import] public IPithosSettings Settings { get; set; } private readonly string[] _states = {"Normal", "Modified", "Conflict","Synch"}; Dictionary _overlayCache=new Dictionary(); Dictionary _statusCache= new Dictionary(); Dictionary _checksums = new Dictionary(); public FileOverlayStatus GetFileOverlayStatus(string path) { if (!_overlayCache.ContainsKey(path)) return FileOverlayStatus.NA; var pithosPath = Settings.PithosPath; if (path.StartsWith(pithosPath,true,null)) { var status = _overlayCache[path]; return status; } return FileOverlayStatus.NA; } public PithosStatus GetPithosStatus() { return PithosStatus.InSynch; } public void SetFileOverlayStatus(string path, FileOverlayStatus overlayStatus) { _overlayCache[path] = overlayStatus; } public void RemoveFileOverlayStatus(string path) { _overlayCache.Remove(path); } public void RenameFileOverlayStatus(string oldPath, string newPath) { var status=_overlayCache[oldPath]; _overlayCache[newPath] = status; _overlayCache.Remove(oldPath); } public void SetFileStatus(string path, FileStatus status) { _statusCache[path] = status; } public FileStatus GetFileStatus(string path) { if (!_statusCache.ContainsKey(path)) return FileStatus.Missing; return _statusCache[path]; } public void ClearFileStatus(string path) { _statusCache.Remove(path); } public void UpdateFileChecksum(string path, string checksum) { _checksums[path] = checksum; } } }