Revision 42800be8 trunk/Pithos.Client.WPF/ShellViewModel.cs
b/trunk/Pithos.Client.WPF/ShellViewModel.cs | ||
---|---|---|
1 | 1 |
using System.Collections.Concurrent; |
2 |
using System.ComponentModel; |
|
2 | 3 |
using System.ComponentModel.Composition; |
3 | 4 |
using System.Diagnostics; |
4 | 5 |
using System.Diagnostics.Contracts; |
... | ... | |
12 | 13 |
using Caliburn.Micro; |
13 | 14 |
using Hardcodet.Wpf.TaskbarNotification; |
14 | 15 |
using Pithos.Client.WPF.Configuration; |
16 |
using Pithos.Client.WPF.FileProperties; |
|
15 | 17 |
using Pithos.Client.WPF.Properties; |
16 | 18 |
using Pithos.Client.WPF.SelectiveSynch; |
19 |
using Pithos.Client.WPF.Services; |
|
17 | 20 |
using Pithos.Core; |
18 | 21 |
using Pithos.Interfaces; |
19 | 22 |
using System; |
... | ... | |
27 | 30 |
using System.ComponentModel.Composition; |
28 | 31 |
|
29 | 32 |
[Export(typeof(IShell))] |
30 |
public class ShellViewModel : Screen, IStatusNotification, IShell,
|
|
31 |
IHandle<Notification>, IHandle<SelectiveSynchChanges> |
|
33 |
public class ShellViewModel : Screen, IStatusNotification, IShell, |
|
34 |
IHandle<Notification>, IHandle<SelectiveSynchChanges>, IHandle<ShowFilePropertiesEvent>
|
|
32 | 35 |
{ |
33 | 36 |
|
34 | 37 |
private IStatusChecker _statusChecker; |
... | ... | |
76 | 79 |
protected override void OnActivate() |
77 | 80 |
{ |
78 | 81 |
base.OnActivate(); |
79 |
foreach (var account in Settings.Accounts) |
|
82 |
|
|
83 |
|
|
84 |
var tasks=from account in Settings.Accounts |
|
85 |
select MonitorAccount(account); |
|
86 |
|
|
87 |
try |
|
80 | 88 |
{ |
81 | 89 |
|
82 |
MonitorAccount(account); |
|
90 |
Task.Factory.Iterate(tasks).Wait(); |
|
91 |
_statusService=StatusService.Start(); |
|
92 |
|
|
93 |
} |
|
94 |
catch (AggregateException exc) |
|
95 |
{ |
|
96 |
exc.Handle(e =>{ |
|
97 |
Log.Error("Error while starting monitoring", e); |
|
98 |
return true; |
|
99 |
}); |
|
100 |
throw; |
|
83 | 101 |
} |
102 |
|
|
103 |
} |
|
84 | 104 |
|
85 |
StartStatusService(); |
|
105 |
protected override void OnDeactivate(bool close) |
|
106 |
{ |
|
107 |
base.OnDeactivate(close); |
|
108 |
if (close) |
|
109 |
{ |
|
110 |
StatusService.Stop(_statusService); |
|
111 |
_statusService = null; |
|
112 |
} |
|
86 | 113 |
} |
87 | 114 |
|
88 |
public void MonitorAccount(AccountSettings account)
|
|
115 |
public Task MonitorAccount(AccountSettings account)
|
|
89 | 116 |
{ |
90 |
Task.Factory.StartNew(() => |
|
117 |
return Task.Factory.StartNew(() =>
|
|
91 | 118 |
{ |
92 | 119 |
PithosMonitor monitor = null; |
93 | 120 |
var accountName = account.AccountName; |
... | ... | |
264 | 291 |
|
265 | 292 |
var fileProperties = new FilePropertiesViewModel(this, info,filePath); |
266 | 293 |
_windowManager.ShowWindow(fileProperties); |
294 |
} |
|
295 |
|
|
296 |
public void ShowContainerProperties() |
|
297 |
{ |
|
298 |
var account = Settings.Accounts.First(acc => acc.IsActive); |
|
299 |
var dir = new DirectoryInfo(account.RootPath); |
|
300 |
var fullName = (from folder in dir.EnumerateDirectories() |
|
301 |
where (folder.Attributes & FileAttributes.Hidden) == 0 |
|
302 |
select folder.FullName).First(); |
|
303 |
ShowContainerProperties(fullName); |
|
304 |
} |
|
305 |
|
|
306 |
public void ShowContainerProperties(string filePath) |
|
307 |
{ |
|
308 |
if (String.IsNullOrWhiteSpace(filePath)) |
|
309 |
throw new ArgumentNullException("filePath"); |
|
310 |
if (!Directory.Exists(filePath)) |
|
311 |
throw new ArgumentException(String.Format("Non existent file {0}",filePath),"filePath"); |
|
312 |
Contract.EndContractBlock(); |
|
313 |
|
|
314 |
var pair=(from monitor in Monitors |
|
315 |
where filePath.StartsWith(monitor.Value.RootPath, StringComparison.InvariantCultureIgnoreCase) |
|
316 |
select monitor).FirstOrDefault(); |
|
317 |
var account = pair.Key; |
|
318 |
var accountMonitor = pair.Value; |
|
319 |
ContainerInfo info = accountMonitor.GetContainerInfo(filePath); |
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
var containerProperties = new ContainerPropertiesViewModel(this, info,filePath); |
|
324 |
_windowManager.ShowWindow(containerProperties); |
|
267 | 325 |
} |
268 | 326 |
|
269 | 327 |
public ObjectInfo RefreshObjectInfo(ObjectInfo currentInfo) |
... | ... | |
277 | 335 |
return newInfo; |
278 | 336 |
} |
279 | 337 |
|
338 |
public ContainerInfo RefreshContainerInfo(ContainerInfo container) |
|
339 |
{ |
|
340 |
if (container == null) |
|
341 |
throw new ArgumentNullException("container"); |
|
342 |
Contract.EndContractBlock(); |
|
343 |
|
|
344 |
var monitor = Monitors[container.Account]; |
|
345 |
var newInfo = monitor.CloudClient.GetContainerInfo(container.Account, container.Name); |
|
346 |
return newInfo; |
|
347 |
} |
|
348 |
|
|
349 |
|
|
280 | 350 |
public void ToggleSynching() |
281 | 351 |
{ |
282 | 352 |
bool isPaused=false; |
... | ... | |
515 | 585 |
} |
516 | 586 |
} |
517 | 587 |
|
518 |
private void StartStatusService() |
|
519 |
{ |
|
520 |
// Create a ServiceHost for the CalculatorService type and provide the base address. |
|
521 |
var baseAddress = new Uri("net.pipe://localhost/pithos"); |
|
522 |
_statusService = new ServiceHost(typeof(StatusService), baseAddress); |
|
523 |
|
|
524 |
var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None); |
|
525 |
|
|
526 |
_statusService.AddServiceEndpoint(typeof(IStatusService), binding, "net.pipe://localhost/pithos/statuscache"); |
|
527 |
_statusService.AddServiceEndpoint(typeof(ISettingsService), binding, "net.pipe://localhost/pithos/settings"); |
|
528 |
|
|
529 |
|
|
530 |
//// Add a mex endpoint |
|
531 |
var smb = new ServiceMetadataBehavior |
|
532 |
{ |
|
533 |
HttpGetEnabled = true, |
|
534 |
HttpGetUrl = new Uri("http://localhost:30000/pithos/mex") |
|
535 |
}; |
|
536 |
_statusService.Description.Behaviors.Add(smb); |
|
537 |
|
|
538 |
|
|
539 |
_statusService.Open(); |
|
540 |
} |
|
541 |
|
|
542 |
private void StopStatusService() |
|
543 |
{ |
|
544 |
if (_statusService == null) |
|
545 |
return; |
|
546 |
|
|
547 |
if (_statusService.State == CommunicationState.Faulted) |
|
548 |
_statusService.Abort(); |
|
549 |
else if (_statusService.State != CommunicationState.Closed) |
|
550 |
_statusService.Close(); |
|
551 |
_statusService = null; |
|
552 |
|
|
553 |
} |
|
554 | 588 |
#region Event Handlers |
555 | 589 |
|
556 | 590 |
public void Handle(SelectiveSynchChanges message) |
... | ... | |
596 | 630 |
} |
597 | 631 |
} |
598 | 632 |
#endregion |
633 |
|
|
634 |
public void Handle(ShowFilePropertiesEvent message) |
|
635 |
{ |
|
636 |
if (message == null) |
|
637 |
throw new ArgumentNullException("message"); |
|
638 |
if (String.IsNullOrWhiteSpace(message.FileName) ) |
|
639 |
throw new ArgumentException("message"); |
|
640 |
Contract.EndContractBlock(); |
|
641 |
|
|
642 |
var fileName = message.FileName; |
|
643 |
|
|
644 |
if (File.Exists(fileName)) |
|
645 |
this.ShowFileProperties(fileName); |
|
646 |
else if (Directory.Exists(fileName)) |
|
647 |
this.ShowContainerProperties(fileName); |
|
648 |
} |
|
599 | 649 |
} |
600 | 650 |
} |
Also available in: Unified diff