Ejemplo n.º 1
0
        private void OnPerformanceReport(object sender, TaskProcessorPerformanceEventArgs e)
        {
            TaskProcessorViewModel processor = this.taskProcessors.FirstOrDefault(p => p.TaskProcessorId == e.PerformanceInfo.TaskProcessorId);

            if (processor == null)
            {
                return;
            }

            processor.CpuPercent = e.PerformanceInfo.CpuPercent;
            processor.RamPercent = e.PerformanceInfo.RamPercent;

            foreach (TaskPerformanceReport taskPerformance in e.PerformanceInfo.TasksPerformance)
            {
                TaskViewModel task = processor.ActiveTasks.FirstOrDefault(t => t.TaskId == taskPerformance.TaskId);

                if (task == null)
                {
                    continue;
                }

                task.CpuPercent = taskPerformance.CpuPercent;
                task.RamPercent = taskPerformance.RamPercent;
            }
        }
Ejemplo n.º 2
0
        private void InitializeTasks()
        {
            Guid?masterTaskProcessorId = this.taskProcessorFacade.GetMasterTaskProcessorId();

            foreach (ITaskProcessorRuntimeInfo processorInfo in this.taskProcessorFacade.GetTaskProcessorRuntimeInfo())
            {
                TaskProcessorViewModel processorViewModel = new TaskProcessorViewModel(processorInfo.TaskProcessorId, processorInfo.MachineName)
                {
                    State = TaskProcessorState.Active
                };

                if (masterTaskProcessorId.HasValue)
                {
                    processorViewModel.IsMaster = processorViewModel.TaskProcessorId == masterTaskProcessorId.Value;
                }

                this.taskProcessors.Add(processorViewModel);
            }

            foreach (ITaskRuntimeInfo taskInfo in this.repository.TaskRuntimeInfo.GetPending(true))
            {
                this.pendingTasks.Add(new TaskViewModel(taskInfo));
            }

            foreach (ITaskRuntimeInfo taskInfo in this.repository.TaskRuntimeInfo.GetActive())
            {
                TaskProcessorViewModel processor = this.taskProcessors.FirstOrDefault(p => p.TaskProcessorId == taskInfo.TaskProcessorId);

                if (processor != null)
                {
                    processor.ActiveTasks.Add(new TaskViewModel(taskInfo));
                }
            }
        }
Ejemplo n.º 3
0
        private void OnTaskStarted(object sender, TaskStartedEventArgs e)
        {
            TaskViewModel taskViewModel = this.pendingTasks.FirstOrDefault(t => t.TaskId == e.TaskId);

            if (taskViewModel == null)
            {
                return;
            }

            TaskProcessorViewModel processorViewModel = this.taskProcessors.FirstOrDefault(p => p.TaskProcessorId == e.TaskProcessorId);

            if (processorViewModel == null)
            {
                return;
            }

            App.Current.Dispatcher.InvokeAsync(() =>
            {
                taskViewModel.Status          = TaskStatus.InProgress.ToString();
                taskViewModel.TaskProcessorId = e.TaskProcessorId;
                taskViewModel.StartedUtc      = e.TimestampUtc;

                this.pendingTasks.Remove(taskViewModel);

                processorViewModel.ActiveTasks.Add(taskViewModel);
            });
        }
Ejemplo n.º 4
0
        private void OnChangeMasterModeClick(object sender, RoutedEventArgs e)
        {
            TaskProcessorViewModel taskProcessorViewModel = (TaskProcessorViewModel)((FrameworkElement)sender).DataContext;

            if (!taskProcessorViewModel.IsMaster)
            {
                this.ViewModel.TaskProcessorFacade.MakeTaskProcessorMaster(taskProcessorViewModel.TaskProcessorId);
            }
        }
Ejemplo n.º 5
0
        private void OnStopTaskProcessorButtonClick(object sender, RoutedEventArgs e)
        {
            FrameworkElement button = (FrameworkElement)sender;

            TaskProcessorViewModel processorViewModel = (TaskProcessorViewModel)button.DataContext;

            this.ViewModel.TaskProcessorFacade.RequestTaskProcessorToStop(processorViewModel.TaskProcessorId);

            button.IsEnabled = false;
        }
Ejemplo n.º 6
0
        private void OnMasterModeChanged(object sender, MasterModeChangeEventArgs e)
        {
            TaskProcessorViewModel taskProcessorViewModel = this.taskProcessors.FirstOrDefault(p => p.TaskProcessorId == e.TaskProcessorId);

            if (taskProcessorViewModel != null)
            {
                App.Current.Dispatcher.InvokeAsync(() =>
                {
                    taskProcessorViewModel.IsMaster = e.IsMaster;
                });
            }
        }
Ejemplo n.º 7
0
        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;
            }
        }
Ejemplo n.º 8
0
        private void OnTaskProcessorConfigurationClick(object sender, RoutedEventArgs e)
        {
            TaskProcessorViewModel processorViewModel = (TaskProcessorViewModel)((FrameworkElement)sender).DataContext;

            ITaskProcessorRuntimeInfo processorInfo = this.ViewModel.TaskProcessorFacade.GetTaskProcessorRuntimeInfo(processorViewModel.TaskProcessorId);

            ConfigurationWindow dialog = new ConfigurationWindow(processorInfo.Configuration)
            {
                Title          = "Task Processor Configuration",
                SaveButtonText = "Save"
            };

            if (dialog.ShowDialog() == true)
            {
                this.ViewModel.TaskProcessorFacade.UpdateTaskProcessorRuntimeInfo(processorInfo);
            }
        }