public TargetsViewModel(IBindingOperations bindingOperations) { this.Targets = new ObservableCollection <TargetViewModel>(); this.Tests = new ObservableCollection <TestViewModel>(); bindingOperations.EnableCollectionSynchronization(this.Targets); bindingOperations.EnableCollectionSynchronization(this.Tests); this.ExecuteTests = new DelegateCommand(async() => { this.IsRunning = true; if (TokenSource != null) { TokenSource.Cancel(); } TokenSource = new CancellationTokenSource(); try { foreach (var test in this.Tests.OrderBy(t => t.SortOrder)) { await test.Execute(TokenSource.Token); } } catch (OperationCanceledException) { } catch (Exception) { //report } finally { IsRunning = false; } }, () => !this.IsRunning); this.CancelTests = new DelegateCommand(() => { if (this.TokenSource != null) { this.TokenSource.Cancel(); } }, () => this.IsRunning); }
public TargetViewModel(IBindingOperations bindingOperations, object target) { Tests = new ObservableCollection <TestViewModel>(); bindingOperations.EnableCollectionSynchronization(Tests); this.Target = target; }