// </copyright>
// -----------------------------------------------------------------------
+using System.Collections.Concurrent;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.IO;
}
}
- private readonly IObservableCollection<FileEntry> _recentFiles = new BindableCollection<FileEntry>();
- public IObservableCollection<FileEntry> RecentFiles
+ private readonly ObservableConcurrentCollection<FileEntry> _recentFiles = new ObservableConcurrentCollection<FileEntry>();
+ public ObservableConcurrentCollection<FileEntry> RecentFiles
{
get { return _recentFiles; }
}
- private string _statusIcon;
+ private string _statusIcon="Images/Tray.ico";
public string StatusIcon
{
get { return _statusIcon; }
_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)
{
_events.Publish(new Notification { Title = "Pithos", Message = status, Level = level });
}
+
+ public void NotifyChangedFile(string filePath)
+ {
+ var entry = new FileEntry {FullPath=filePath};
+ IProducerConsumerCollection<FileEntry> files=this.RecentFiles;
+ FileEntry popped;
+ while (files.Count > 5)
+ files.TryTake(out popped);
+ files.TryAdd(entry);
+ }
}
}