Revision 0c02aa65 trunk/Pithos.Client.WPF/TaskbarViewModel.cs
b/trunk/Pithos.Client.WPF/TaskbarViewModel.cs | ||
---|---|---|
7 | 7 |
using System.ComponentModel.Composition; |
8 | 8 |
using System.Diagnostics; |
9 | 9 |
using System.IO; |
10 |
using System.Threading.Tasks; |
|
10 | 11 |
using System.Windows; |
11 | 12 |
using Caliburn.Micro; |
12 | 13 |
using Pithos.Client.WPF.Properties; |
... | ... | |
24 | 25 |
/// TODO: Update summary. |
25 | 26 |
/// </summary> |
26 | 27 |
[Export] |
27 |
public class TaskbarViewModel:ViewAware |
|
28 |
public class TaskbarViewModel:ViewAware,IStatusNotification
|
|
28 | 29 |
{ |
29 | 30 |
private IStatusChecker _statusChecker; |
31 |
private IEventAggregator _events; |
|
30 | 32 |
|
31 | 33 |
public PithosMonitor Monitor { get; private set; } |
32 | 34 |
|
... | ... | |
35 | 37 |
public IScreen Parent { get; set; } |
36 | 38 |
|
37 | 39 |
[ImportingConstructor] |
38 |
public TaskbarViewModel(IStatusChecker statusChecker,PithosMonitor monitor,IPithosSettings settings) |
|
40 |
public TaskbarViewModel(IEventAggregator events, IStatusChecker statusChecker,PithosMonitor monitor,IPithosSettings settings)
|
|
39 | 41 |
{ |
40 | 42 |
OpenPithosFolderCommand = new PithosCommand(OpenPithosFolder); |
41 | 43 |
_statusChecker = statusChecker; |
44 |
_events = events; |
|
42 | 45 |
Settings = settings; |
43 | 46 |
Monitor = monitor; |
47 |
Monitor.StatusNotification = this; |
|
48 |
|
|
49 |
|
|
44 | 50 |
|
45 | 51 |
var account=settings.Accounts.FirstOrDefault(act => act.IsActive); |
46 | 52 |
if (account != null) |
... | ... | |
167 | 173 |
StatusIcon = String.Format(@"Images/{0}.ico", info.IconName); |
168 | 174 |
StatusMessage = String.Format("Pithos 1.0\r\n{0}", info.StatusText); |
169 | 175 |
} |
176 |
|
|
177 |
var tv=this.GetView(); |
|
178 |
_events.Publish(new Notification { Title = "Start", Message = "Start Monitoring", Level = TraceLevel.Info}); |
|
170 | 179 |
if (!String.IsNullOrWhiteSpace(Monitor.UserName) && |
171 | 180 |
!String.IsNullOrWhiteSpace(Monitor.ApiKey)) |
172 |
try |
|
173 |
{ |
|
174 |
Monitor.Start(); |
|
175 |
} |
|
176 |
catch (Exception exc) |
|
177 |
{ |
|
178 |
MessageBox.Show("An exception occured. Can't start monitoring"); |
|
179 |
} |
|
181 |
Task.Factory.StartNew(() => |
|
182 |
Monitor.Start()) |
|
183 |
.ContinueWith(t =>{ |
|
184 |
if (t.IsFaulted) |
|
185 |
{ |
|
186 |
|
|
187 |
var message= String.Format("An exception occured. Can't start monitoring\n{0}",t.Exception); |
|
188 |
_events.Publish(new Notification { Title = "Error",Message=message,Level= TraceLevel.Error }); |
|
189 |
MessageBox.Show(message); |
|
190 |
} |
|
191 |
}); |
|
192 |
} |
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
public void NotifyChange(string status, TraceLevel level=TraceLevel.Info) |
|
197 |
{ |
|
198 |
this.StatusMessage = status; |
|
199 |
|
|
200 |
_events.Publish(new Notification { Title = "Pithos", Message = status, Level = level }); |
|
180 | 201 |
} |
181 | 202 |
} |
182 | 203 |
} |
Also available in: Unified diff