Revision 3c43ec9b trunk/Pithos.Core/StatusKeeper.cs
b/trunk/Pithos.Core/StatusKeeper.cs | ||
---|---|---|
1 | 1 |
using System; |
2 |
using System.Collections; |
|
2 | 3 |
using System.Collections.Concurrent; |
3 | 4 |
using System.Collections.Generic; |
4 | 5 |
using System.ComponentModel.Composition; |
... | ... | |
12 | 13 |
using System.Threading; |
13 | 14 |
using System.Threading.Tasks; |
14 | 15 |
using Castle.ActiveRecord; |
15 |
using Castle.ActiveRecord.Framework; |
|
16 | 16 |
using Castle.ActiveRecord.Framework.Config; |
17 | 17 |
using Pithos.Interfaces; |
18 | 18 |
|
... | ... | |
24 | 24 |
[System.ComponentModel.Composition.Import] |
25 | 25 |
public IPithosSettings Settings { get; set; } |
26 | 26 |
|
27 |
private BlockingCollection<Action> _statusUpdateQueue = new BlockingCollection<Action>(); |
|
28 |
//private readonly CancellationToken _cancel=new CancellationToken(); |
|
27 |
private BlockingCollection<Action> _statusUpdateQueue = new BlockingCollection<Action>(); |
|
29 | 28 |
|
30 | 29 |
public StatusKeeper() |
31 |
{ |
|
32 |
var source = new XmlConfigurationSource("DbConfig.xml"); |
|
33 |
ActiveRecordStarter.Initialize(source,typeof(FileState)); |
|
30 |
{ |
|
31 |
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); |
|
32 |
var pithosDbPath = Path.Combine(appDataPath , "Pithos"); |
|
33 |
|
|
34 |
var source = GetConfiguration(pithosDbPath); |
|
35 |
ActiveRecordStarter.Initialize(source,typeof(FileState),typeof(FileTag)); |
|
34 | 36 |
|
35 |
if (!File.Exists("pithos.db"))
|
|
37 |
if (!File.Exists(Path.Combine(pithosDbPath ,"pithos.db")))
|
|
36 | 38 |
ActiveRecordStarter.CreateSchema(); |
37 | 39 |
|
38 |
Task.Factory.StartNew(ProcessUpdates); |
|
40 |
} |
|
41 |
|
|
42 |
private static InPlaceConfigurationSource GetConfiguration(string pithosDbPath) |
|
43 |
{ |
|
44 |
var properties = new Dictionary<string, string> |
|
45 |
{ |
|
46 |
{"connection.driver_class", "NHibernate.Driver.SQLite20Driver"}, |
|
47 |
{"dialect", "NHibernate.Dialect.SQLiteDialect"}, |
|
48 |
{"connection.provider", "NHibernate.Connection.DriverConnectionProvider"}, |
|
49 |
{ |
|
50 |
"proxyfactory.factory_class", |
|
51 |
"NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle" |
|
52 |
}, |
|
53 |
}; |
|
54 |
|
|
55 |
var connectionString = String.Format(@"Data Source={0}\pithos.db;Version=3", pithosDbPath); |
|
56 |
properties.Add("connection.connection_string", connectionString); |
|
57 |
|
|
58 |
var source = new InPlaceConfigurationSource(); |
|
59 |
|
|
60 |
source.Add(typeof (ActiveRecordBase), properties); |
|
61 |
return source; |
|
62 |
} |
|
63 |
|
|
64 |
public void StartProcessing(CancellationToken token) |
|
65 |
{ |
|
66 |
Task.Factory.StartNew(ProcessUpdates,token); |
|
39 | 67 |
} |
40 | 68 |
|
41 | 69 |
public void ProcessUpdates() |
... | ... | |
48 | 76 |
|
49 | 77 |
public void Stop() |
50 | 78 |
{ |
51 |
_statusUpdateQueue.CompleteAdding(); |
|
79 |
_statusUpdateQueue.CompleteAdding();
|
|
52 | 80 |
} |
53 | 81 |
|
54 | 82 |
|
... | ... | |
142 | 170 |
return NetworkState.None; |
143 | 171 |
} |
144 | 172 |
|
145 |
|
|
146 | 173 |
public T GetStatus<T>(string path,Func<FileState,T> getter,T defaultValue ) |
147 | 174 |
{ |
148 | 175 |
|
... | ... | |
236 | 263 |
SetStatus(path,s=>s.OverlayStatus=overlayStatus); |
237 | 264 |
} |
238 | 265 |
|
239 |
/* private static void InnerSetOverlayStatus(string path, FileOverlayStatus overlayStatus) |
|
240 |
{ |
|
241 |
var filePath = path.ToLower(); |
|
242 |
var state = FileState.TryFind(filePath); |
|
243 |
if (state != null) |
|
244 |
{ |
|
245 |
state.OverlayStatus = overlayStatus; |
|
246 |
state.Update(); |
|
247 |
} |
|
248 |
else |
|
249 |
{ |
|
250 |
state = new FileState |
|
251 |
{FilePath = filePath, OverlayStatus = overlayStatus}; |
|
252 |
state.Save(); |
|
253 |
} |
|
254 |
}*/ |
|
255 |
|
|
256 | 266 |
public void RemoveFileOverlayStatus(string path) |
257 | 267 |
{ |
258 | 268 |
_statusUpdateQueue.Add(() => |
... | ... | |
306 | 316 |
state.FilePath = path.ToLower(); |
307 | 317 |
state.Checksum = objectInfo.Hash; |
308 | 318 |
state.FileStatus = FileStatus.Unchanged; |
309 |
state.OverlayStatus = FileOverlayStatus.Normal; |
|
319 |
state.OverlayStatus = FileOverlayStatus.Normal; |
|
320 |
foreach (var tag in objectInfo.Tags) |
|
321 |
{ |
|
322 |
state.Tags.Add(new FileTag |
|
323 |
{ |
|
324 |
FilePath=state.FilePath, |
|
325 |
FileState=state, |
|
326 |
Value=tag.Value |
|
327 |
}); |
|
328 |
} |
|
310 | 329 |
|
311 | 330 |
state.Save(); |
312 | 331 |
|
Also available in: Unified diff