Revision 5ce54458 trunk/Pithos.Core/PithosMonitor.cs
b/trunk/Pithos.Core/PithosMonitor.cs | ||
---|---|---|
17 | 17 |
using Pithos.Core.Agents; |
18 | 18 |
using Pithos.Interfaces; |
19 | 19 |
using System.ServiceModel; |
20 |
using Pithos.Network; |
|
20 | 21 |
|
21 | 22 |
namespace Pithos.Core |
22 | 23 |
{ |
... | ... | |
26 | 27 |
private const string PithosContainer = "pithos"; |
27 | 28 |
private const string TrashContainer = "trash"; |
28 | 29 |
|
30 |
private const string FragmentsFolder = "fragments"; |
|
31 |
|
|
32 |
private int _blockSize; |
|
33 |
private string _blockHash; |
|
34 |
|
|
29 | 35 |
[Import] |
30 | 36 |
public IPithosSettings Settings{get;set;} |
31 | 37 |
|
... | ... | |
44 | 50 |
public IStatusNotification StatusNotification { get; set; } |
45 | 51 |
|
46 | 52 |
[Import] |
47 |
public FileWatcherAgent FileWatcherAgent { get; set; }
|
|
53 |
public FileAgent FileAgent { get; set; }
|
|
48 | 54 |
|
49 | 55 |
[Import] |
50 | 56 |
public WorkflowAgent WorkflowAgent { get; set; } |
... | ... | |
61 | 67 |
|
62 | 68 |
public bool Pause |
63 | 69 |
{ |
64 |
get { return FileWatcherAgent.Pause; }
|
|
70 |
get { return FileAgent.Pause; } |
|
65 | 71 |
set |
66 | 72 |
{ |
67 |
FileWatcherAgent.Pause = value;
|
|
73 |
FileAgent.Pause = value; |
|
68 | 74 |
if (value) |
69 | 75 |
{ |
70 | 76 |
StatusKeeper.SetPithosStatus(PithosStatus.SyncPaused); |
... | ... | |
101 | 107 |
|
102 | 108 |
EnsurePithosContainers(); |
103 | 109 |
|
104 |
StatusKeeper.BlockHash = "sha256"; |
|
110 |
StatusKeeper.BlockHash = _blockHash; |
|
111 |
StatusKeeper.BlockSize = _blockSize; |
|
105 | 112 |
|
106 | 113 |
StatusKeeper.StartProcessing(_cancellationSource.Token); |
107 | 114 |
IndexLocalFiles(RootPath); |
... | ... | |
117 | 124 |
CloudClient.AuthenticationUrl = this.AuthenticationUrl; |
118 | 125 |
CloudClient.Authenticate(UserName, ApiKey); |
119 | 126 |
|
120 |
var pithosContainers = new[] {PithosContainer, TrashContainer};
|
|
127 |
var pithosContainers = new[] { TrashContainer,PithosContainer};
|
|
121 | 128 |
foreach (var container in pithosContainers) |
122 | 129 |
{ |
123 |
if (!CloudClient.ContainerExists(container)) |
|
124 |
CloudClient.CreateContainer(container); |
|
130 |
var info=CloudClient.GetContainerInfo(container); |
|
131 |
if (info == ContainerInfo.Empty) |
|
132 |
{ |
|
133 |
CloudClient.CreateContainer(container); |
|
134 |
info = CloudClient.GetContainerInfo(container); |
|
135 |
} |
|
136 |
_blockSize = info.BlockSize; |
|
137 |
_blockHash = info.BlockHash; |
|
125 | 138 |
} |
139 |
|
|
140 |
var allContainers= CloudClient.ListContainers(); |
|
141 |
var extraContainers = from container in allContainers |
|
142 |
where !pithosContainers.Contains(container.Name.ToLower()) |
|
143 |
select container; |
|
144 |
|
|
145 |
|
|
146 |
|
|
126 | 147 |
} |
127 | 148 |
|
128 | 149 |
public string AuthenticationUrl { get; set; } |
... | ... | |
152 | 173 |
Trace.TraceInformation("[START] Index Local"); |
153 | 174 |
try |
154 | 175 |
{ |
176 |
var fragmentsPath=Path.Combine(RootPath, FragmentsFolder); |
|
155 | 177 |
var files = |
156 | 178 |
from filePath in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories).AsParallel() |
179 |
where !filePath.StartsWith(fragmentsPath,StringComparison.InvariantCultureIgnoreCase) && |
|
180 |
!filePath.EndsWith(".ignore",StringComparison.InvariantCultureIgnoreCase) |
|
157 | 181 |
select filePath.ToLower(); |
158 | 182 |
StatusKeeper.StoreUnversionedFiles(files); |
159 | 183 |
|
... | ... | |
227 | 251 |
StartNetworkAgent(RootPath); |
228 | 252 |
|
229 | 253 |
WorkflowAgent.StatusNotification = StatusNotification; |
254 |
WorkflowAgent.FragmentsPath = Path.Combine(RootPath, FragmentsFolder); |
|
230 | 255 |
WorkflowAgent.Start(); |
231 | 256 |
} |
232 | 257 |
catch (Exception) |
... | ... | |
271 | 296 |
private void StartNetworkAgent(string accountPath) |
272 | 297 |
{ |
273 | 298 |
NetworkAgent.StatusNotification = StatusNotification; |
274 |
|
|
275 |
NetworkAgent.Start(RootPath, PithosContainer,TrashContainer);
|
|
299 |
|
|
300 |
NetworkAgent.Start(PithosContainer, TrashContainer,_blockSize,_blockHash);
|
|
276 | 301 |
|
277 | 302 |
NetworkAgent.ProcessRemoteFiles(accountPath); |
278 | 303 |
} |
279 | 304 |
|
305 |
//Make sure a hidden fragments folder exists to store partial downloads |
|
306 |
private static string CreateHiddenFolder(string rootPath, string folderName) |
|
307 |
{ |
|
308 |
if (String.IsNullOrWhiteSpace(rootPath)) |
|
309 |
throw new ArgumentNullException("rootPath"); |
|
310 |
if (!Path.IsPathRooted(rootPath)) |
|
311 |
throw new ArgumentException("rootPath"); |
|
312 |
if (String.IsNullOrWhiteSpace(folderName)) |
|
313 |
throw new ArgumentNullException("folderName"); |
|
314 |
Contract.EndContractBlock(); |
|
315 |
|
|
316 |
var folder = Path.Combine(rootPath, folderName); |
|
317 |
if (!Directory.Exists(folder)) |
|
318 |
{ |
|
319 |
var info = Directory.CreateDirectory(folder); |
|
320 |
info.Attributes |= FileAttributes.Hidden; |
|
321 |
|
|
322 |
Trace.TraceInformation("Created Fragments Folder: {0}", folder); |
|
323 |
} |
|
324 |
return folder; |
|
325 |
} |
|
326 |
|
|
280 | 327 |
|
281 | 328 |
|
282 | 329 |
|
283 | 330 |
private void StartWatcherAgent(string path) |
284 | 331 |
{ |
285 |
FileWatcherAgent.StatusKeeper = StatusKeeper; |
|
286 |
FileWatcherAgent.Workflow = Workflow; |
|
287 |
FileWatcherAgent.Start(path); |
|
332 |
FileAgent.StatusKeeper = StatusKeeper; |
|
333 |
FileAgent.Workflow = Workflow; |
|
334 |
FileAgent.FragmentsPath = Path.Combine(RootPath, FragmentsFolder); |
|
335 |
FileAgent.Start(path); |
|
288 | 336 |
} |
289 | 337 |
|
290 | 338 |
public void Stop() |
291 | 339 |
{ |
292 |
FileWatcherAgent.Stop();
|
|
340 |
FileAgent.Stop(); |
|
293 | 341 |
if (timer != null) |
294 | 342 |
timer.Dispose(); |
295 | 343 |
timer = null; |
Also available in: Unified diff