Added named pipes comm between client and shell extensions
[pithos-ms-client] / trunk / Pithos.Core / InMemStatusChecker.cs
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel.Composition;
4 using System.Diagnostics.Contracts;
5 using Pithos.Interfaces;
6
7 namespace Pithos.Core
8 {
9     //[Export(typeof(IStatusChecker)),Export(typeof(IStatusKeeper))]
10     public class InMemStatusChecker:IStatusChecker,IStatusKeeper
11     {
12         [Import]
13         public IPithosSettings Settings { get; set; }
14
15         private readonly string[] _states = {"Normal", "Modified", "Conflict","Synch"};
16
17         Dictionary<string,FileOverlayStatus> _overlayCache=new Dictionary<string,FileOverlayStatus>();
18         Dictionary<string, FileStatus> _statusCache= new Dictionary<string, FileStatus>();
19         Dictionary<string, string> _checksums = new Dictionary<string, string>();
20
21         public FileOverlayStatus GetFileOverlayStatus(string path)
22         {
23             if (!_overlayCache.ContainsKey(path))
24                 return FileOverlayStatus.NA;
25
26             var pithosPath = Settings.PithosPath;
27             if (path.StartsWith(pithosPath,true,null))
28             {
29                 var status = _overlayCache[path];
30                 return status;
31             }
32             return FileOverlayStatus.NA;
33         }
34
35
36         private PithosStatus _pithosStatus = PithosStatus.InSynch;
37         public void SetPithosStatus(PithosStatus status)
38         {
39             _pithosStatus = status;
40         }
41
42         public PithosStatus GetPithosStatus()
43         {
44             return _pithosStatus;
45         }
46
47         public void SetFileOverlayStatus(string path, FileOverlayStatus overlayStatus)
48         {
49             _overlayCache[path] = overlayStatus;
50         }
51
52         public void RemoveFileOverlayStatus(string path)
53         {
54             _overlayCache.Remove(path);
55         }
56
57         public void RenameFileOverlayStatus(string oldPath, string newPath)
58         {
59             var status=_overlayCache[oldPath];
60             _overlayCache[newPath] = status;            
61             _overlayCache.Remove(oldPath);
62         }
63
64         public void SetFileStatus(string path, FileStatus status)
65         {
66             _statusCache[path] = status;
67         }
68
69         public FileStatus GetFileStatus(string path)
70         {
71             if (!_statusCache.ContainsKey(path))
72                 return FileStatus.Missing;
73             return _statusCache[path];
74         }
75
76         public void ClearFileStatus(string path)
77         {
78             _statusCache.Remove(path);
79         }
80
81         public void UpdateFileChecksum(string path, string checksum)
82         {
83             _checksums[path] = checksum;
84         }
85     }
86 }