1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Windows.Forms;
|
---|
24 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core.Views;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 |
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Clients.Hive.SlaveCore.Views {
|
---|
31 |
|
---|
32 | [View("HeuristicLab Slave Stats View")]
|
---|
33 | [Content(typeof(SlaveItem), IsDefaultView = false)]
|
---|
34 | public partial class SlaveStats : ItemView {
|
---|
35 | private SlaveDisplayStat lastSlaveDisplayStat;
|
---|
36 |
|
---|
37 |
|
---|
38 | public new SlaveItem Content {
|
---|
39 | get { return (SlaveItem)base.Content; }
|
---|
40 | set {
|
---|
41 | if (base.Content != value) {
|
---|
42 | base.Content = value;
|
---|
43 | }
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | public SlaveStats() {
|
---|
48 | InitializeComponent();
|
---|
49 | lblSlaveState.Text = SlaveDisplayStat.NoService.ToString();
|
---|
50 | lastSlaveDisplayStat = SlaveDisplayStat.NoService;
|
---|
51 | Content_SlaveDisplayStateChanged(this, new EventArgs<SlaveDisplayStat>(lastSlaveDisplayStat));
|
---|
52 | }
|
---|
53 |
|
---|
54 | #region Register Content Events
|
---|
55 | protected override void DeregisterContentEvents() {
|
---|
56 | Content.SlaveStatusChanged -= new System.EventHandler<EventArgs<StatusCommons>>(Content_SlaveStatusChanged);
|
---|
57 | Content.SlaveDisplayStateChanged -= new EventHandler<EventArgs<SlaveDisplayStat>>(Content_SlaveDisplayStateChanged);
|
---|
58 | Content.CoreConnectionChanged -= new EventHandler<EventArgs<CoreConnection>>(Content_CoreConnectionChanged);
|
---|
59 |
|
---|
60 | base.DeregisterContentEvents();
|
---|
61 | }
|
---|
62 |
|
---|
63 | protected override void RegisterContentEvents() {
|
---|
64 | base.RegisterContentEvents();
|
---|
65 |
|
---|
66 | Content.SlaveStatusChanged += new System.EventHandler<EventArgs<StatusCommons>>(Content_SlaveStatusChanged);
|
---|
67 | Content.SlaveDisplayStateChanged += new EventHandler<EventArgs<SlaveDisplayStat>>(Content_SlaveDisplayStateChanged);
|
---|
68 | Content.CoreConnectionChanged += new EventHandler<EventArgs<CoreConnection>>(Content_CoreConnectionChanged);
|
---|
69 | }
|
---|
70 | #endregion
|
---|
71 |
|
---|
72 | protected override void OnContentChanged() {
|
---|
73 | base.OnContentChanged();
|
---|
74 | }
|
---|
75 |
|
---|
76 | protected override void SetEnabledStateOfControls() {
|
---|
77 | base.SetEnabledStateOfControls();
|
---|
78 | //do nothing at the moment, we have nothing editable
|
---|
79 | }
|
---|
80 |
|
---|
81 | #region Event Handlers
|
---|
82 | void Content_SlaveStatusChanged(object sender, EventArgs<StatusCommons> e) {
|
---|
83 | RenderJobChart(e.Value);
|
---|
84 | RenderCoreChart(e.Value);
|
---|
85 | }
|
---|
86 |
|
---|
87 | void Content_SlaveDisplayStateChanged(object sender, EventArgs<SlaveDisplayStat> e) {
|
---|
88 | lblSlaveState.Text = e.Value.ToString();
|
---|
89 | lastSlaveDisplayStat = e.Value;
|
---|
90 | }
|
---|
91 |
|
---|
92 | void Content_CoreConnectionChanged(object sender, EventArgs<CoreConnection> e) {
|
---|
93 |
|
---|
94 | }
|
---|
95 | #endregion
|
---|
96 |
|
---|
97 | private void RenderJobChart(StatusCommons status) {
|
---|
98 | jobChart.Series[0].Points.Clear();
|
---|
99 | jobChart.Series[1].Points.Clear();
|
---|
100 | jobChart.Series[2].Points.Clear();
|
---|
101 | jobChart.Series[3].Points.Clear();
|
---|
102 | jobChart.Series[4].Points.Clear();
|
---|
103 |
|
---|
104 |
|
---|
105 | DataPoint pJobs = new DataPoint(1, status.Jobs.Count);
|
---|
106 | DataPoint pJobsAborted = new DataPoint(2, status.JobsAborted);
|
---|
107 | DataPoint pJobsDone = new DataPoint(3, status.JobsFinished);
|
---|
108 | DataPoint pJobsFetched = new DataPoint(4, status.JobsFetched);
|
---|
109 | DataPoint pJobsFailed = new DataPoint(5, status.JobsFailed);
|
---|
110 |
|
---|
111 | pJobs.LegendText = "Current jobs: " + status.Jobs.Count;
|
---|
112 | pJobs.Color = System.Drawing.Color.Yellow;
|
---|
113 | pJobs.ToolTip = pJobs.LegendText;
|
---|
114 | jobChart.Series[0].Color = System.Drawing.Color.Yellow;
|
---|
115 | jobChart.Series[0].LegendText = pJobs.LegendText;
|
---|
116 | jobChart.Series[0].Points.Add(pJobs);
|
---|
117 |
|
---|
118 | pJobsAborted.LegendText = "Aborted jobs: " + status.JobsAborted;
|
---|
119 | pJobsAborted.Color = System.Drawing.Color.Orange;
|
---|
120 | pJobsAborted.ToolTip = pJobsAborted.LegendText;
|
---|
121 | jobChart.Series[1].Color = System.Drawing.Color.Orange;
|
---|
122 | jobChart.Series[1].LegendText = pJobsAborted.LegendText;
|
---|
123 | jobChart.Series[1].Points.Add(pJobsAborted);
|
---|
124 |
|
---|
125 | pJobsDone.LegendText = "Finished jobs: " + status.JobsFinished;
|
---|
126 | pJobsDone.Color = System.Drawing.Color.Green;
|
---|
127 | pJobsDone.ToolTip = pJobsDone.LegendText;
|
---|
128 | jobChart.Series[2].Color = System.Drawing.Color.Green;
|
---|
129 | jobChart.Series[2].LegendText = pJobsDone.LegendText;
|
---|
130 | jobChart.Series[2].Points.Add(pJobsDone);
|
---|
131 |
|
---|
132 | pJobsFetched.LegendText = "Fetched jobs: " + status.JobsFetched;
|
---|
133 | pJobsFetched.ToolTip = pJobsFetched.LegendText;
|
---|
134 | pJobsFetched.Color = System.Drawing.Color.Blue;
|
---|
135 | jobChart.Series[3].Color = System.Drawing.Color.Blue;
|
---|
136 | jobChart.Series[3].LegendText = pJobsFetched.LegendText;
|
---|
137 | jobChart.Series[3].Points.Add(pJobsFetched);
|
---|
138 |
|
---|
139 | pJobsFailed.LegendText = "Failed jobs: " + status.JobsFailed;
|
---|
140 | pJobsFailed.ToolTip = pJobsFailed.LegendText;
|
---|
141 | pJobsFailed.Color = System.Drawing.Color.Red;
|
---|
142 | jobChart.Series[4].Color = System.Drawing.Color.Red;
|
---|
143 | jobChart.Series[4].LegendText = pJobsFailed.LegendText;
|
---|
144 | jobChart.Series[4].Points.Add(pJobsFailed);
|
---|
145 | }
|
---|
146 |
|
---|
147 | private void RenderCoreChart(StatusCommons statusCommons) {
|
---|
148 | int usedCores = statusCommons.TotalCores - statusCommons.FreeCores;
|
---|
149 | DataPoint pFreeCores = new DataPoint(statusCommons.FreeCores, statusCommons.FreeCores);
|
---|
150 | DataPoint pUsedCores = new DataPoint(usedCores, usedCores);
|
---|
151 |
|
---|
152 | coresChart.Series[0].Points.Clear();
|
---|
153 |
|
---|
154 | pFreeCores.LegendText = "Free cores: " + statusCommons.FreeCores;
|
---|
155 | pFreeCores.Color = System.Drawing.Color.Green;
|
---|
156 | pUsedCores.LegendText = "Used cores: " + usedCores;
|
---|
157 | pUsedCores.Color = System.Drawing.Color.Red;
|
---|
158 |
|
---|
159 | coresChart.Series[0].Points.Add(pFreeCores);
|
---|
160 | coresChart.Series[0].Points.Add(pUsedCores);
|
---|
161 | }
|
---|
162 | }
|
---|
163 | }
|
---|