// </copyright>
// -----------------------------------------------------------------------
+using System.Collections.Concurrent;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.IO;
+using System.Threading.Tasks;
using System.Windows;
using Caliburn.Micro;
using Pithos.Client.WPF.Properties;
/// TODO: Update summary.
/// </summary>
[Export]
- public class TaskbarViewModel:ViewAware
+ public class TaskbarViewModel:ViewAware,IStatusNotification
{
private IStatusChecker _statusChecker;
+ private IEventAggregator _events;
public PithosMonitor Monitor { get; private set; }
public IScreen Parent { get; set; }
[ImportingConstructor]
- public TaskbarViewModel(IStatusChecker statusChecker,PithosMonitor monitor,IPithosSettings settings)
+ public TaskbarViewModel(IEventAggregator events, IStatusChecker statusChecker,PithosMonitor monitor,IPithosSettings settings)
{
OpenPithosFolderCommand = new PithosCommand(OpenPithosFolder);
_statusChecker = statusChecker;
+ _events = events;
Settings = settings;
Monitor = monitor;
+ Monitor.StatusNotification = this;
+
+
var account=settings.Accounts.FirstOrDefault(act => act.IsActive);
if (account != null)
}
}
- 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; }
StatusIcon = String.Format(@"Images/{0}.ico", info.IconName);
StatusMessage = String.Format("Pithos 1.0\r\n{0}", info.StatusText);
}
+
+ var tv=this.GetView();
+ _events.Publish(new Notification { Title = "Start", Message = "Start Monitoring", Level = TraceLevel.Info});
if (!String.IsNullOrWhiteSpace(Monitor.UserName) &&
!String.IsNullOrWhiteSpace(Monitor.ApiKey))
+ StartMonitor();
+ }
+
+ private void StartMonitor()
+ {
+ Task.Factory.StartNew(() =>
+ {
try
{
Monitor.Start();
}
- catch (Exception exc)
+ catch(Exception exc)
{
- MessageBox.Show("An exception occured. Can't start monitoring");
+ 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)
+ {
+ this.StatusMessage = status;
+
+ _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);
}
}
}