X-Git-Url: https://code.grnet.gr/git/pithos-ms-client/blobdiff_plain/0c02aa6513e46f5f555aa8f904908e6eed7cdd8a..d17258c218bac92a8a886a4114b3693092b6e00e:/trunk/Pithos.Client.WPF/TaskbarViewModel.cs diff --git a/trunk/Pithos.Client.WPF/TaskbarViewModel.cs b/trunk/Pithos.Client.WPF/TaskbarViewModel.cs index f72ab14..9454bbb 100644 --- a/trunk/Pithos.Client.WPF/TaskbarViewModel.cs +++ b/trunk/Pithos.Client.WPF/TaskbarViewModel.cs @@ -4,6 +4,7 @@ // // ----------------------------------------------------------------------- +using System.Collections.Concurrent; using System.ComponentModel.Composition; using System.Diagnostics; using System.IO; @@ -98,14 +99,14 @@ namespace Pithos.Client.WPF } } - private readonly IObservableCollection _recentFiles = new BindableCollection(); - public IObservableCollection RecentFiles + private readonly ObservableConcurrentCollection _recentFiles = new ObservableConcurrentCollection(); + public ObservableConcurrentCollection RecentFiles { get { return _recentFiles; } } - private string _statusIcon; + private string _statusIcon="Images/Tray.ico"; public string StatusIcon { get { return _statusIcon; } @@ -178,20 +179,26 @@ namespace Pithos.Client.WPF _events.Publish(new Notification { Title = "Start", Message = "Start Monitoring", Level = TraceLevel.Info}); if (!String.IsNullOrWhiteSpace(Monitor.UserName) && !String.IsNullOrWhiteSpace(Monitor.ApiKey)) - Task.Factory.StartNew(() => - Monitor.Start()) - .ContinueWith(t =>{ - if (t.IsFaulted) - { - - var message= String.Format("An exception occured. Can't start monitoring\n{0}",t.Exception); - _events.Publish(new Notification { Title = "Error",Message=message,Level= TraceLevel.Error }); - MessageBox.Show(message); - } - }); + StartMonitor(); + } + + private void StartMonitor() + { + Task.Factory.StartNew(() => + { + try + { + Monitor.Start(); + } + catch(Exception exc) + { + var message = String.Format("An exception occured. Can't start monitoring\nWill retry in 10 seconds\n{0}",exc); + _events.Publish(new Notification{Title = "Error", Message = message, Level = TraceLevel.Error}); + Task.Factory.StartNewDelayed(10000, StartMonitor); + } + }); } - public void NotifyChange(string status, TraceLevel level=TraceLevel.Info) { @@ -199,5 +206,15 @@ namespace Pithos.Client.WPF _events.Publish(new Notification { Title = "Pithos", Message = status, Level = level }); } + + public void NotifyChangedFile(string filePath) + { + var entry = new FileEntry {FullPath=filePath}; + IProducerConsumerCollection files=this.RecentFiles; + FileEntry popped; + while (files.Count > 5) + files.TryTake(out popped); + files.TryAdd(entry); + } } }