2 using System.Collections.Concurrent;
3 using System.Collections.Generic;
4 using System.ComponentModel.Composition;
5 using System.Diagnostics.Contracts;
7 using Pithos.Interfaces;
11 //[Export(typeof(IStatusChecker)),Export(typeof(IStatusKeeper))]
12 public class InMemStatusChecker:IStatusChecker,IStatusKeeper
15 public IPithosSettings Settings { get; set; }
17 private readonly string[] _states = {"Normal", "Modified", "Conflict","Synch"};
19 ConcurrentDictionary<string, FileOverlayStatus> _overlayCache = new ConcurrentDictionary<string, FileOverlayStatus>();
20 ConcurrentDictionary<string, FileStatus> _statusCache = new ConcurrentDictionary<string, FileStatus>();
21 ConcurrentDictionary<string, string> _checksums = new ConcurrentDictionary<string, string>();
23 public FileOverlayStatus GetFileOverlayStatus(string path)
25 if (!_overlayCache.ContainsKey(path))
26 return FileOverlayStatus.Unversioned;
28 var pithosPath = Settings.PithosPath;
29 if (path.StartsWith(pithosPath,true,null))
31 var status = _overlayCache[path];
34 return FileOverlayStatus.Unversioned;
37 public IEnumerable<string> StoreUnversionedFiles(ParallelQuery<string> paths)
40 var newFiles = (from file in paths
41 where !_overlayCache.ContainsKey(file)
44 OverlayStatus = FileOverlayStatus.Unversioned,
45 FileStatus = FileStatus.Created,
46 Checksum = Signature.CalculateHash(file)
48 ConcurrentBag<string> files = new ConcurrentBag<string>();
49 newFiles.ForAll(state =>
51 _overlayCache[state.FilePath] = state.OverlayStatus;
52 _statusCache[state.FilePath] = state.FileStatus;
53 _checksums[state.FilePath] = state.Checksum;
54 files.Add(state.FilePath);
56 return files.GetConsumingEnumerable();
65 private PithosStatus _pithosStatus = PithosStatus.InSynch;
66 public void SetPithosStatus(PithosStatus status)
68 _pithosStatus = status;
71 public PithosStatus GetPithosStatus()
76 public void SetFileOverlayStatus(string path, FileOverlayStatus overlayStatus)
78 _overlayCache[path] = overlayStatus;
81 public void RemoveFileOverlayStatus(string path)
83 FileOverlayStatus value;
84 _overlayCache.TryRemove(path, out value);
87 public void RenameFileOverlayStatus(string oldPath, string newPath)
89 var status=_overlayCache[oldPath];
90 _overlayCache[newPath] = status;
91 FileOverlayStatus value;
92 _overlayCache.TryRemove(oldPath,out value);
95 public void SetFileStatus(string path, FileStatus status)
97 _statusCache[path] = status;
100 public FileStatus GetFileStatus(string path)
102 if (!_statusCache.ContainsKey(path))
103 return FileStatus.Missing;
104 return _statusCache[path];
107 public void ClearFileStatus(string path)
110 _statusCache.TryRemove(path,out value);
113 public void UpdateFileChecksum(string path, string checksum)
115 _checksums[path] = checksum;