Added SQLite status storage
[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         public PithosStatus GetPithosStatus()
36         {
37             return PithosStatus.InSynch;
38         }
39
40         public void SetFileOverlayStatus(string path, FileOverlayStatus overlayStatus)
41         {
42             _overlayCache[path] = overlayStatus;
43         }
44
45         public void RemoveFileOverlayStatus(string path)
46         {
47             _overlayCache.Remove(path);
48         }
49
50         public void RenameFileOverlayStatus(string oldPath, string newPath)
51         {
52             var status=_overlayCache[oldPath];
53             _overlayCache[newPath] = status;            
54             _overlayCache.Remove(oldPath);
55         }
56
57         public void SetFileStatus(string path, FileStatus status)
58         {
59             _statusCache[path] = status;
60         }
61
62         public FileStatus GetFileStatus(string path)
63         {
64             if (!_statusCache.ContainsKey(path))
65                 return FileStatus.Missing;
66             return _statusCache[path];
67         }
68
69         public void ClearFileStatus(string path)
70         {
71             _statusCache.Remove(path);
72         }
73
74         public void UpdateFileChecksum(string path, string checksum)
75         {
76             _checksums[path] = checksum;
77         }
78     }
79 }