1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 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.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Data;
|
---|
26 | using System.Drawing;
|
---|
27 | using System.Linq;
|
---|
28 | using System.Text;
|
---|
29 | using System.Windows.Forms;
|
---|
30 | using System.Diagnostics;
|
---|
31 | using System.Threading;
|
---|
32 | using ZedGraph;
|
---|
33 | using HeuristicLab.Hive.Client.Console.ClientService;
|
---|
34 | using System.ServiceModel;
|
---|
35 | using System.Net;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.Hive.Client.Console {
|
---|
38 |
|
---|
39 | delegate void UpdateTextDelegate(EventLogEntry ev);
|
---|
40 |
|
---|
41 | public partial class HiveClientConsole : Form {
|
---|
42 |
|
---|
43 | private EventLog HiveClientEventLog;
|
---|
44 | private ClientConsoleCommunicatorClient cccc;
|
---|
45 | private System.Windows.Forms.Timer refreshTimer;
|
---|
46 | private ListViewColumnSorterDate lvwColumnSorter;
|
---|
47 |
|
---|
48 |
|
---|
49 | public HiveClientConsole() {
|
---|
50 | InitializeComponent();
|
---|
51 | lvwColumnSorter = new ListViewColumnSorterDate();
|
---|
52 | lvLog.ListViewItemSorter = lvwColumnSorter;
|
---|
53 | lvwColumnSorter.SortColumn = 3;
|
---|
54 | lvwColumnSorter.Order = SortOrder.Descending;
|
---|
55 | InitTimer();
|
---|
56 | ConnectToClient();
|
---|
57 | RefreshGui();
|
---|
58 | GetEventLog();
|
---|
59 | }
|
---|
60 |
|
---|
61 | private void InitTimer() {
|
---|
62 | refreshTimer = new System.Windows.Forms.Timer();
|
---|
63 | refreshTimer.Interval = 1000;
|
---|
64 | refreshTimer.Tick += new EventHandler(refreshTimer_Tick);
|
---|
65 | refreshTimer.Start();
|
---|
66 | }
|
---|
67 |
|
---|
68 | void refreshTimer_Tick(object sender, EventArgs e) {
|
---|
69 | RefreshGui();
|
---|
70 | }
|
---|
71 |
|
---|
72 | private void RefreshGui() {
|
---|
73 | try {
|
---|
74 | cccc.GetStatusInfosAsync();
|
---|
75 | }
|
---|
76 | catch (Exception ex) {
|
---|
77 | refreshTimer.Stop();
|
---|
78 | DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running!", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
79 | if (res == DialogResult.OK)
|
---|
80 | this.Close();
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | private void ConnectToClient() {
|
---|
85 | try {
|
---|
86 | cccc = new ClientConsoleCommunicatorClient();
|
---|
87 | cccc.GetStatusInfosCompleted += new EventHandler<GetStatusInfosCompletedEventArgs>(cccc_GetStatusInfosCompleted);
|
---|
88 | cccc.GetCurrentConnectionCompleted += new EventHandler<GetCurrentConnectionCompletedEventArgs>(cccc_GetCurrentConnectionCompleted);
|
---|
89 | }
|
---|
90 | catch (Exception) {
|
---|
91 | refreshTimer.Stop();
|
---|
92 | DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running!", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
93 | if (res == DialogResult.OK)
|
---|
94 | this.Close();
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | void cccc_GetCurrentConnectionCompleted(object sender, GetCurrentConnectionCompletedEventArgs e) {
|
---|
99 | if (e.Error == null) {
|
---|
100 | ConnectionContainer curConnection = e.Result;
|
---|
101 | tbIPAdress.Text = curConnection.IPAdress;
|
---|
102 | tbPort.Text = curConnection.Port.ToString();
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | void cccc_GetStatusInfosCompleted(object sender, GetStatusInfosCompletedEventArgs e) {
|
---|
107 |
|
---|
108 | if (e.Error == null) {
|
---|
109 | StatusCommons sc = e.Result;
|
---|
110 |
|
---|
111 | lbGuid.Text = sc.ClientGuid.ToString();
|
---|
112 | lbCs.Text = sc.ConnectedSince.ToString();
|
---|
113 | lbConnectionStatus.Text = sc.Status.ToString();
|
---|
114 | lbJobdone.Text = sc.JobsDone.ToString();
|
---|
115 | lbJobsAborted.Text = sc.JobsAborted.ToString();
|
---|
116 | lbJobsFetched.Text = sc.JobsFetched.ToString();
|
---|
117 |
|
---|
118 | this.Text = "Client Console (" + sc.Status.ToString() + ")";
|
---|
119 | lbStatus.Text = sc.Status.ToString();
|
---|
120 |
|
---|
121 | ListViewItem curJobStatusItem;
|
---|
122 |
|
---|
123 | if (sc.Jobs != null) {
|
---|
124 | lvJobDetail.Items.Clear();
|
---|
125 | double progress;
|
---|
126 | foreach (JobStatus curJob in sc.Jobs) {
|
---|
127 | curJobStatusItem = new ListViewItem(curJob.JobId.ToString());
|
---|
128 | curJobStatusItem.SubItems.Add(curJob.Since.ToString());
|
---|
129 | progress = curJob.Progress * 100;
|
---|
130 | curJobStatusItem.SubItems.Add(progress.ToString());
|
---|
131 | lvJobDetail.Items.Add(curJobStatusItem);
|
---|
132 | }
|
---|
133 | lvJobDetail.Sort();
|
---|
134 | }
|
---|
135 |
|
---|
136 | UpdateGraph(sc.JobsDone, sc.JobsAborted);
|
---|
137 |
|
---|
138 | if (sc.Status == NetworkEnumWcfConnState.Connected) {
|
---|
139 | btConnect.Enabled = false;
|
---|
140 | btnDisconnect.Enabled = true;
|
---|
141 | cccc.GetCurrentConnectionAsync();
|
---|
142 | } else if (sc.Status == NetworkEnumWcfConnState.Disconnected) {
|
---|
143 | btConnect.Enabled = true;
|
---|
144 | btnDisconnect.Enabled = false;
|
---|
145 | } else if (sc.Status == NetworkEnumWcfConnState.Failed) {
|
---|
146 | btConnect.Enabled = true;
|
---|
147 | btnDisconnect.Enabled = false;
|
---|
148 | }
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | private void GetEventLog() {
|
---|
153 | HiveClientEventLog = new EventLog("Hive Client");
|
---|
154 | HiveClientEventLog.Source = "Hive Client";
|
---|
155 | HiveClientEventLog.EntryWritten += new EntryWrittenEventHandler(OnEntryWritten);
|
---|
156 | HiveClientEventLog.EnableRaisingEvents = true;
|
---|
157 |
|
---|
158 | ListViewItem curEventLogEntry;
|
---|
159 | foreach (EventLogEntry eve in HiveClientEventLog.Entries) {
|
---|
160 | curEventLogEntry = new ListViewItem("", 0);
|
---|
161 | if(eve.EntryType == EventLogEntryType.Error)
|
---|
162 | curEventLogEntry = new ListViewItem("", 1);
|
---|
163 | curEventLogEntry.SubItems.Add(eve.InstanceId.ToString());
|
---|
164 | curEventLogEntry.SubItems.Add(eve.Message);
|
---|
165 | curEventLogEntry.SubItems.Add(eve.TimeGenerated.ToString());
|
---|
166 | lvLog.Items.Add(curEventLogEntry);
|
---|
167 | }
|
---|
168 | lvJobDetail.Sort();
|
---|
169 | }
|
---|
170 |
|
---|
171 | private void HiveClientConsole_Load(object sender, EventArgs e) {
|
---|
172 | //SetSize();
|
---|
173 | }
|
---|
174 |
|
---|
175 | private void UpdateText(EventLogEntry ev) {
|
---|
176 | if (this.lvLog.InvokeRequired) {
|
---|
177 | this.lvLog.Invoke(new
|
---|
178 | UpdateTextDelegate(UpdateText), new object[] { ev });
|
---|
179 | } else {
|
---|
180 | ListViewItem curEventLogEntry;
|
---|
181 | curEventLogEntry = new ListViewItem("", 0);
|
---|
182 | if (ev.EntryType == EventLogEntryType.Error)
|
---|
183 | curEventLogEntry = new ListViewItem("", 1);
|
---|
184 | curEventLogEntry.SubItems.Add(ev.InstanceId.ToString());
|
---|
185 | curEventLogEntry.SubItems.Add(ev.Message);
|
---|
186 | curEventLogEntry.SubItems.Add(ev.TimeGenerated.ToString());
|
---|
187 | lvLog.Items.Add(curEventLogEntry);
|
---|
188 | lvJobDetail.Sort();
|
---|
189 | }
|
---|
190 | }
|
---|
191 |
|
---|
192 | public void OnEntryWritten(object source, EntryWrittenEventArgs e) {
|
---|
193 | UpdateText(e.Entry);
|
---|
194 | }
|
---|
195 |
|
---|
196 | private void UpdateGraph(int jobsDone, int jobsAborted) {
|
---|
197 | ZedGraphControl zgc = new ZedGraphControl();
|
---|
198 | GraphPane myPane = zgc.GraphPane;
|
---|
199 | myPane.GraphObjList.Clear();
|
---|
200 |
|
---|
201 | myPane.Title.IsVisible = false; // no title
|
---|
202 | myPane.Border.IsVisible = false; // no border
|
---|
203 | myPane.Chart.Border.IsVisible = false; // no border around the chart
|
---|
204 | myPane.XAxis.IsVisible = false; // no x-axis
|
---|
205 | myPane.YAxis.IsVisible = false; // no y-axis
|
---|
206 | myPane.Legend.IsVisible = false; // no legend
|
---|
207 |
|
---|
208 | myPane.Fill.Color = Color.FromKnownColor(KnownColor.Control);
|
---|
209 |
|
---|
210 | myPane.Chart.Fill.Type = FillType.None;
|
---|
211 | myPane.Fill.Type = FillType.Solid;
|
---|
212 |
|
---|
213 | double sum = (double)jobsDone + jobsAborted;
|
---|
214 | double perDone = (double)jobsDone / sum * 100;
|
---|
215 | double perAborted = (double)jobsAborted / sum * 100;
|
---|
216 |
|
---|
217 | myPane.AddPieSlice(perDone, Color.Green, 0.1, "");
|
---|
218 | myPane.AddPieSlice(perAborted, Color.Red, 0.1, "");
|
---|
219 |
|
---|
220 | myPane.AxisChange();
|
---|
221 |
|
---|
222 | pbGraph.Image = zgc.GetImage();
|
---|
223 | }
|
---|
224 |
|
---|
225 | private void HiveClientConsole_Resize(object sender, EventArgs e) {
|
---|
226 | //SetSize();
|
---|
227 | }
|
---|
228 |
|
---|
229 | private void lvLog_DoubleClick(object sender, EventArgs e) {
|
---|
230 | ListViewItem lvi = lvLog.SelectedItems[0];
|
---|
231 | HiveEventEntry hee = new HiveEventEntry(lvi.SubItems[2].Text, lvi.SubItems[3].Text, lvi.SubItems[1].Text);
|
---|
232 |
|
---|
233 | Form EventlogDetails = new EventLogEntryForm(hee);
|
---|
234 | EventlogDetails.Show();
|
---|
235 | }
|
---|
236 |
|
---|
237 | private void btConnect_Click(object sender, EventArgs e) {
|
---|
238 | IPAddress ipAdress;
|
---|
239 | int port;
|
---|
240 | ConnectionContainer cc = new ConnectionContainer();
|
---|
241 | //IPAddress.TryParse(tbIPAdress.Text.ToString(), ipAdress);
|
---|
242 | if (IPAddress.TryParse(tbIPAdress.Text, out ipAdress) && int.TryParse(tbPort.Text, out port)) {
|
---|
243 | cc.IPAdress = tbIPAdress.Text;
|
---|
244 | cc.Port = port;
|
---|
245 | cccc.SetConnectionAsync(cc);
|
---|
246 | } else {
|
---|
247 | MessageBox.Show("IP Adress and/or Port Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 | private void btnDisconnect_Click(object sender, EventArgs e) {
|
---|
252 | cccc.DisconnectAsync();
|
---|
253 | }
|
---|
254 |
|
---|
255 | private void lvLog_ColumnClick(object sender, ColumnClickEventArgs e) {
|
---|
256 | // Determine if clicked column is already the column that is being sorted.
|
---|
257 | if (e.Column == lvwColumnSorter.SortColumn) {
|
---|
258 | // Reverse the current sort direction for this column.
|
---|
259 | if (lvwColumnSorter.Order == SortOrder.Ascending) {
|
---|
260 | lvwColumnSorter.Order = SortOrder.Descending;
|
---|
261 | } else {
|
---|
262 | lvwColumnSorter.Order = SortOrder.Ascending;
|
---|
263 | }
|
---|
264 | } else {
|
---|
265 | // Set the column number that is to be sorted; default to ascending.
|
---|
266 | lvwColumnSorter.SortColumn = e.Column;
|
---|
267 | lvwColumnSorter.Order = SortOrder.Ascending;
|
---|
268 | }
|
---|
269 |
|
---|
270 | // Perform the sort with these new sort options.
|
---|
271 | lvLog.Sort();
|
---|
272 | }
|
---|
273 | }
|
---|
274 | } |
---|