private void OnTaskProcessorStateChanged(object sender, TaskProcessorStateEventArgs e) { switch (e.TaskProcessorState) { case TaskProcessorState.Active: { ITaskProcessorRuntimeInfo processorInfo = this.taskProcessorFacade.GetTaskProcessorRuntimeInfo(e.TaskProcessorId); if (processorInfo == null) { return; } TaskProcessorViewModel processorViewModel = new TaskProcessorViewModel(processorInfo.TaskProcessorId, processorInfo.MachineName) { State = TaskProcessorState.Active }; Guid?masterId = this.taskProcessorFacade.GetMasterTaskProcessorId(); if (masterId.HasValue && masterId.Value == e.TaskProcessorId) { processorViewModel.IsMaster = true; } App.Current.Dispatcher.InvokeAsync(() => { this.taskProcessors.Add(processorViewModel); }); } break; case TaskProcessorState.Stopping: case TaskProcessorState.Inactive: { TaskProcessorViewModel processorViewModel = this.taskProcessors.FirstOrDefault(p => p.TaskProcessorId == e.TaskProcessorId); if (processorViewModel == null) { return; } App.Current.Dispatcher.InvokeAsync(() => { processorViewModel.State = e.TaskProcessorState; }); } break; } }
public virtual void RaiseTaskProcessorStateChanged() { Guid taskProcessorId = Guid.NewGuid(); this.Receiver.SubscribeForChannels(MessageBusChannel.TaskProcessorState); TaskProcessorStateEventArgs args = Helpers.WaitForEvent <TaskProcessorStateEventArgs>( this.Timeout, handler => this.Receiver.StateChanged += handler, () => this.Sender.NotifyStateChanged(taskProcessorId, TaskProcessorState.Active)); Assert.AreEqual(taskProcessorId, args.TaskProcessorId); Assert.AreEqual(TaskProcessorState.Active, args.TaskProcessorState); }