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 HeuristicLab.Hive.Contracts.Interfaces;
|
---|
31 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
32 | using HeuristicLab.Hive.Contracts;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.Hive.Server.ServerConsole {
|
---|
35 |
|
---|
36 | public delegate void closeForm(bool cf, bool error);
|
---|
37 |
|
---|
38 | public partial class HiveServerManagementConsole : Form {
|
---|
39 |
|
---|
40 | public event closeForm closeFormEvent;
|
---|
41 |
|
---|
42 | #region private variables
|
---|
43 | private ResponseList<ClientGroup> clients = null;
|
---|
44 | private ResponseList<ClientInfo> clientInfo = null;
|
---|
45 | private ResponseList<Job> jobs = null;
|
---|
46 | private ResponseList<UserGroup> userGroups = null;
|
---|
47 | private ResponseList<User> usersList = null;
|
---|
48 |
|
---|
49 | private Job currentJob = null;
|
---|
50 | private ClientInfo currentClient = null;
|
---|
51 | private User currentUser = null;
|
---|
52 | private string nameCurrentJob = "";
|
---|
53 | private string nameCurrentClient = "";
|
---|
54 | private string nameCurrentUser = "";
|
---|
55 | private bool flagJob = false;
|
---|
56 | private bool flagClient = false;
|
---|
57 | private bool flagUser = false;
|
---|
58 |
|
---|
59 | private ToolTip tt = new ToolTip();
|
---|
60 | #endregion
|
---|
61 |
|
---|
62 | public HiveServerManagementConsole() {
|
---|
63 | InitializeComponent();
|
---|
64 | AddClients();
|
---|
65 | AddJobs();
|
---|
66 | AddUsers();
|
---|
67 | timerSyncronize.Start();
|
---|
68 | }
|
---|
69 |
|
---|
70 | /// <summary>
|
---|
71 | /// event on Ticker
|
---|
72 | /// </summary>
|
---|
73 | /// <param name="obj"></param>
|
---|
74 | /// <param name="e"></param>
|
---|
75 | private void TickSync(object obj, EventArgs e) {
|
---|
76 | Refresh();
|
---|
77 | }
|
---|
78 |
|
---|
79 | /// <summary>
|
---|
80 | /// Adds clients to ListView and TreeView
|
---|
81 | /// </summary>
|
---|
82 | private void AddClients() {
|
---|
83 | try {
|
---|
84 | IClientManager clientManager =
|
---|
85 | ServiceLocator.GetClientManager();
|
---|
86 |
|
---|
87 | clients = clientManager.GetAllClientGroups();
|
---|
88 |
|
---|
89 | lvClientControl.Items.Clear();
|
---|
90 | tvClientControl.Nodes.Clear();
|
---|
91 | int count = 0;
|
---|
92 | foreach (ClientGroup cg in clients.List) {
|
---|
93 | tvClientControl.Nodes.Add(cg.Name);
|
---|
94 | ListViewGroup lvg = new ListViewGroup(cg.Name, HorizontalAlignment.Left);
|
---|
95 | foreach (ClientInfo ci in clientManager.GetAllClients().List) {
|
---|
96 | tvClientControl.Nodes[tvClientControl.Nodes.Count - 1].Nodes.Add(ci.Name);
|
---|
97 | lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvg));
|
---|
98 | count = (count + 1) % 3;
|
---|
99 | }
|
---|
100 | lvClientControl.Groups.Add(lvg);
|
---|
101 | } // Groups
|
---|
102 |
|
---|
103 | clientInfo = clientManager.GetAllClients();
|
---|
104 | ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
|
---|
105 | foreach (ClientInfo ci in clientInfo.List) {
|
---|
106 | tvClientControl.Nodes.Add(ci.Name);
|
---|
107 | lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvunsorted));
|
---|
108 | count = (count + 1) % 3;
|
---|
109 | }
|
---|
110 | lvClientControl.Groups.Add(lvunsorted);
|
---|
111 | if (flagClient) {
|
---|
112 | ClientClicked();
|
---|
113 | }
|
---|
114 | }
|
---|
115 | catch (Exception ex) {
|
---|
116 | closeFormEvent(true, true);
|
---|
117 | this.Close();
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | /// <summary>
|
---|
122 | /// Adds jobs to ListView and TreeView
|
---|
123 | /// </summary>
|
---|
124 | private void AddJobs() {
|
---|
125 | try {
|
---|
126 | IJobManager jobManager =
|
---|
127 | ServiceLocator.GetJobManager();
|
---|
128 | jobs = jobManager.GetAllJobs();
|
---|
129 |
|
---|
130 | lvJobControl.Items.Clear();
|
---|
131 | tvJobControl.Nodes.Clear();
|
---|
132 |
|
---|
133 | ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left);
|
---|
134 | ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left);
|
---|
135 | ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left);
|
---|
136 | tvJobControl.Nodes.Add("calculating");
|
---|
137 | tvJobControl.Nodes.Add("finished");
|
---|
138 | tvJobControl.Nodes.Add("pending");
|
---|
139 | foreach (Job job in jobs.List) {
|
---|
140 | if (job.State == State.calculating) {
|
---|
141 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobCalculating);
|
---|
142 | tvJobControl.Nodes[0].Nodes.Add(job.Id.ToString());
|
---|
143 | lvJobControl.Items.Add(lvi);
|
---|
144 | lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated";
|
---|
145 | } else if (job.State == State.finished) {
|
---|
146 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobFinished);
|
---|
147 | tvJobControl.Nodes[1].Nodes.Add(job.Id.ToString());
|
---|
148 | lvJobControl.Items.Add(lvi);
|
---|
149 | } else if (job.State == State.offline) {
|
---|
150 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobPending);
|
---|
151 | tvJobControl.Nodes[2].Nodes.Add(job.Id.ToString());
|
---|
152 | lvJobControl.Items.Add(lvi);
|
---|
153 | }
|
---|
154 | } // Jobs
|
---|
155 | lvJobControl.Groups.Add(lvJobCalculating);
|
---|
156 | lvJobControl.Groups.Add(lvJobFinished);
|
---|
157 | lvJobControl.Groups.Add(lvJobPending);
|
---|
158 | if (flagJob) {
|
---|
159 | JobClicked();
|
---|
160 | }
|
---|
161 | }
|
---|
162 | catch (Exception ex) {
|
---|
163 | closeFormEvent(true, true);
|
---|
164 | this.Close();
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 | /// <summary>
|
---|
169 | /// Adds users to ListView and TreeView
|
---|
170 | /// </summary>
|
---|
171 | private void AddUsers() {
|
---|
172 | try {
|
---|
173 | IUserRoleManager userRoleManager =
|
---|
174 | ServiceLocator.GetUserRoleManager();
|
---|
175 |
|
---|
176 | userGroups = userRoleManager.GetAllUserGroups();
|
---|
177 |
|
---|
178 | lvUserControl.Items.Clear();
|
---|
179 | tvUserControl.Nodes.Clear();
|
---|
180 |
|
---|
181 | foreach (UserGroup ug in userGroups.List) {
|
---|
182 | tvUserControl.Nodes.Add(ug.Name);
|
---|
183 | ListViewGroup lvg = new ListViewGroup(ug.Name, HorizontalAlignment.Left);
|
---|
184 |
|
---|
185 | foreach (PermissionOwner permOwner in ug.Members) {
|
---|
186 | if (permOwner is User) {
|
---|
187 | User users = permOwner as User;
|
---|
188 | tvUserControl.Nodes[tvUserControl.Nodes.Count - 1].Nodes.Add(users.Name);
|
---|
189 | lvUserControl.Items.Add(new ListViewItem(users.Name, 0, lvg));
|
---|
190 | }
|
---|
191 | }
|
---|
192 | lvUserControl.Groups.Add(lvg);
|
---|
193 |
|
---|
194 | } // Users
|
---|
195 | usersList = userRoleManager.GetAllUsers();
|
---|
196 | ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
|
---|
197 | foreach (User u in usersList.List) {
|
---|
198 | tvUserControl.Nodes.Add(u.Name);
|
---|
199 | lvUserControl.Items.Add(new ListViewItem(u.Name, 0, lvunsorted));
|
---|
200 | }
|
---|
201 | lvUserControl.Groups.Add(lvunsorted);
|
---|
202 | if (flagUser) {
|
---|
203 | UserClicked();
|
---|
204 | }
|
---|
205 | }
|
---|
206 | catch (Exception ex) {
|
---|
207 | closeFormEvent(true, true);
|
---|
208 | this.Close();
|
---|
209 | }
|
---|
210 | }
|
---|
211 |
|
---|
212 | /// <summary>
|
---|
213 | /// if one client is clicked, a panel is opened with the details
|
---|
214 | /// </summary>
|
---|
215 | private void ClientClicked() {
|
---|
216 | int i = 0;
|
---|
217 | while (clientInfo.List[i].Name != nameCurrentClient) {
|
---|
218 | i++;
|
---|
219 | }
|
---|
220 | currentClient = clientInfo.List[i];
|
---|
221 | scClientControl.Panel2.Controls.Clear();
|
---|
222 | scClientControl.Panel2.Controls.Add(plClientDetails);
|
---|
223 | pbClientControl.Image = ilClientControl.Images[0];
|
---|
224 | lblClientName.Text = currentClient.Name;
|
---|
225 | lblLogin.Text = currentClient.Login.ToString();
|
---|
226 | lblState.Text = currentClient.State.ToString();
|
---|
227 | }
|
---|
228 |
|
---|
229 | /// <summary>
|
---|
230 | /// if one job is clicked, a panel is opened with the details
|
---|
231 | /// </summary>
|
---|
232 | private void JobClicked() {
|
---|
233 | int i = 0;
|
---|
234 | while (jobs.List[i].Id.ToString() != nameCurrentJob) {
|
---|
235 | i++;
|
---|
236 | }
|
---|
237 | lvSnapshots.Enabled = false;
|
---|
238 | int yPos = 0;
|
---|
239 | currentJob = jobs.List[i];
|
---|
240 | scJobControl.Panel2.Controls.Clear();
|
---|
241 | scJobControl.Panel2.Controls.Add(plJobDetails);
|
---|
242 | pbJobControl.Image = ilJobControl.Images[0];
|
---|
243 | lblJobName.Text = currentJob.Id.ToString();
|
---|
244 | progressJob.Value = (int)(currentJob.Percentage * 100);
|
---|
245 | yPos = progressJob.Location.Y;
|
---|
246 | yPos += 20;
|
---|
247 | lblProgress.Location = new Point(
|
---|
248 | lblProgress.Location.X, yPos);
|
---|
249 | lblProgress.Text = (int)(currentJob.Percentage * 100) + "% calculated";
|
---|
250 | yPos += 20;
|
---|
251 | lblUserCreatedJob.Location = new Point(
|
---|
252 | lblUserCreatedJob.Location.X, yPos);
|
---|
253 | lblUserCreatedJob.Text = /* currentJob.User.Name + */ " created Job";
|
---|
254 | yPos += 20;
|
---|
255 | lblJobCreated.Location = new Point(
|
---|
256 | lblJobCreated.Location.X, yPos);
|
---|
257 | lblJobCreated.Text = "Created at " + currentJob.DateCreated;
|
---|
258 | if (currentJob.ParentJob != null) {
|
---|
259 | yPos += 20;
|
---|
260 | lblParentJob.Location = new Point(
|
---|
261 | lblParentJob.Location.X, yPos);
|
---|
262 | lblParentJob.Text = currentJob.ParentJob.Id + " is parent job";
|
---|
263 | }
|
---|
264 | yPos += 20;
|
---|
265 | lblPriorityJob.Location = new Point(
|
---|
266 | lblPriorityJob.Location.X, yPos);
|
---|
267 | lblPriorityJob.Text = "Priority of job is " + currentJob.Priority;
|
---|
268 | if (currentJob.Client != null) {
|
---|
269 | yPos += 20;
|
---|
270 | lblClientCalculating.Location = new Point(
|
---|
271 | lblClientCalculating.Location.X, yPos);
|
---|
272 | lblClientCalculating.Text = currentJob.Client.Name + " calculated Job";
|
---|
273 | yPos += 20;
|
---|
274 | lblJobCalculationBegin.Location = new Point(
|
---|
275 | lblJobCalculationBegin.Location.X, yPos);
|
---|
276 | lblJobCalculationBegin.Text = "Startet calculation at " + currentJob.DateCalculated ;
|
---|
277 |
|
---|
278 | if (currentJob.State == State.finished) {
|
---|
279 | yPos += 20;
|
---|
280 | lblJobCalculationEnd.Location = new Point(
|
---|
281 | lblJobCalculationEnd.Location.X, yPos);
|
---|
282 |
|
---|
283 | IJobManager jobManager =
|
---|
284 | ServiceLocator.GetJobManager();
|
---|
285 |
|
---|
286 | ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id);
|
---|
287 |
|
---|
288 |
|
---|
289 | lblJobCalculationEnd.Text = "Calculation ended at " + jobRes.Obj.DateFinished;
|
---|
290 | }
|
---|
291 | }
|
---|
292 | if (currentJob.State != State.offline) {
|
---|
293 | yPos += 20;
|
---|
294 | lvSnapshots.Location = new Point(
|
---|
295 | lvSnapshots.Location.X, yPos);
|
---|
296 | lvSnapshots.Size = new Size(lvSnapshots.Size.Width,
|
---|
297 | plJobDetails.Size.Height - 10 - yPos);
|
---|
298 | lvSnapshots.Enabled = true;
|
---|
299 | }
|
---|
300 | }
|
---|
301 |
|
---|
302 | /// <summary>
|
---|
303 | /// if one user is clicked, a panel is opened with the details
|
---|
304 | /// </summary>
|
---|
305 | private void UserClicked() {
|
---|
306 | int i = 0;
|
---|
307 | while (usersList.List[i].Name != nameCurrentUser) {
|
---|
308 | i++;
|
---|
309 | }
|
---|
310 | currentUser = usersList.List[i];
|
---|
311 | scUserControl.Panel2.Controls.Clear();
|
---|
312 | scUserControl.Panel2.Controls.Add(plUserDetails);
|
---|
313 | pbUserControl.Image = ilUserControl.Images[0];
|
---|
314 | lblUserName.Text = currentUser.Id.ToString();
|
---|
315 | }
|
---|
316 |
|
---|
317 | #region Eventhandlers
|
---|
318 | /// <summary>
|
---|
319 | /// Send event to Login-GUI when closing
|
---|
320 | /// </summary>
|
---|
321 | /// <param name="sender"></param>
|
---|
322 | /// <param name="e"></param>
|
---|
323 | private void Close_Click(object sender, EventArgs e) {
|
---|
324 | if (closeFormEvent != null) {
|
---|
325 | closeFormEvent(true, false);
|
---|
326 | }
|
---|
327 | this.Close();
|
---|
328 | }
|
---|
329 |
|
---|
330 | /// <summary>
|
---|
331 | /// Send evnt to Login-GUI when closing
|
---|
332 | /// </summary>
|
---|
333 | /// <param name="sender"></param>
|
---|
334 | /// <param name="e"></param>
|
---|
335 | private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
|
---|
336 | if (closeFormEvent != null) {
|
---|
337 | closeFormEvent(true, false);
|
---|
338 | }
|
---|
339 | }
|
---|
340 |
|
---|
341 | private void AddJob_Click(object sender, EventArgs e) {
|
---|
342 | AddJobForm newForm = new AddJobForm();
|
---|
343 | newForm.Show();
|
---|
344 | newForm.addJobEvent += new addDelegate(Refresh);
|
---|
345 | }
|
---|
346 |
|
---|
347 | private void Refresh() {
|
---|
348 | AddClients();
|
---|
349 | AddJobs();
|
---|
350 | AddUsers();
|
---|
351 | }
|
---|
352 |
|
---|
353 | private void AddUser_Click(object sender, EventArgs e) {
|
---|
354 | AddUserForm newForm = new AddUserForm("User", false);
|
---|
355 | newForm.Show();
|
---|
356 | newForm.addUserEvent += new addDelegate(Refresh);
|
---|
357 | }
|
---|
358 |
|
---|
359 | private void AddUserGroup_Click(object sender, EventArgs e) {
|
---|
360 | AddUserForm newForm = new AddUserForm("User", true);
|
---|
361 | newForm.Show();
|
---|
362 | newForm.addUserEvent += new addDelegate(Refresh);
|
---|
363 | }
|
---|
364 |
|
---|
365 | private void OnLVClientClicked(object sender, EventArgs e) {
|
---|
366 | nameCurrentClient = lvClientControl.SelectedItems[0].Text;
|
---|
367 | flagClient = true;
|
---|
368 | ClientClicked();
|
---|
369 | }
|
---|
370 |
|
---|
371 | private void OnTVClientClicked(object sender, TreeViewEventArgs e) {
|
---|
372 | bool clientgroup = false;
|
---|
373 | foreach (ClientGroup cg in clients.List) {
|
---|
374 | if (tvClientControl.SelectedNode.Text == cg.Name) {
|
---|
375 | clientgroup = true;
|
---|
376 | }
|
---|
377 | }
|
---|
378 | if (clientgroup == false) {
|
---|
379 | nameCurrentClient = tvClientControl.SelectedNode.Text;
|
---|
380 | flagClient = true;
|
---|
381 | ClientClicked();
|
---|
382 | }
|
---|
383 |
|
---|
384 | }
|
---|
385 |
|
---|
386 | private void OnLVJobControlClicked(object sender, EventArgs e) {
|
---|
387 | nameCurrentJob = lvJobControl.SelectedItems[0].Text;
|
---|
388 | flagJob = true;
|
---|
389 | JobClicked();
|
---|
390 | }
|
---|
391 |
|
---|
392 | private void OnTVJobControlClicked(object sender, TreeViewEventArgs e) {
|
---|
393 | try {
|
---|
394 | nameCurrentJob = Convert.ToInt32(tvJobControl.SelectedNode.Text).ToString();
|
---|
395 | flagJob = true;
|
---|
396 | JobClicked();
|
---|
397 | }
|
---|
398 | catch (Exception ex) { }
|
---|
399 |
|
---|
400 | }
|
---|
401 |
|
---|
402 | private void OnLVUserControlClicked(object sender, EventArgs e) {
|
---|
403 | nameCurrentUser = lvUserControl.SelectedItems[0].Text;
|
---|
404 | flagUser = true;
|
---|
405 | UserClicked();
|
---|
406 | }
|
---|
407 |
|
---|
408 | private void OnTVUserControlClicked(object sender, TreeViewEventArgs e) {
|
---|
409 | bool usergroup = false;
|
---|
410 | foreach (UserGroup ug in userGroups.List) {
|
---|
411 | if (tvUserControl.SelectedNode.Text == ug.Name) {
|
---|
412 | usergroup = true;
|
---|
413 | }
|
---|
414 | }
|
---|
415 | if (usergroup == false) {
|
---|
416 | nameCurrentUser = tvUserControl.SelectedNode.Text;
|
---|
417 | flagUser = true;
|
---|
418 | UserClicked();
|
---|
419 | }
|
---|
420 |
|
---|
421 | }
|
---|
422 |
|
---|
423 |
|
---|
424 | private void btnClientClose_Click(object sender, EventArgs e) {
|
---|
425 | scClientControl.Panel2.Controls.Clear();
|
---|
426 | scClientControl.Panel2.Controls.Add(lvClientControl);
|
---|
427 | flagClient = false;
|
---|
428 | }
|
---|
429 |
|
---|
430 | private void btnJobDetailClose_Click(object sender, EventArgs e) {
|
---|
431 | scJobControl.Panel2.Controls.Clear();
|
---|
432 | scJobControl.Panel2.Controls.Add(lvJobControl);
|
---|
433 | flagJob = false;
|
---|
434 | }
|
---|
435 |
|
---|
436 | private void btnUserControlClose_Click(object sender, EventArgs e) {
|
---|
437 | scUserControl.Panel2.Controls.Clear();
|
---|
438 | scUserControl.Panel2.Controls.Add(lvUserControl);
|
---|
439 | flagUser = false;
|
---|
440 | }
|
---|
441 |
|
---|
442 | private void lvJobControl_MouseMove(object sender, MouseEventArgs e) {
|
---|
443 | if ((lvJobControl.GetItemAt(e.X, e.Y) != null) &&
|
---|
444 | (lvJobControl.GetItemAt(e.X, e.Y).ToolTipText != null)) {
|
---|
445 | tt.SetToolTip(lvJobControl, lvJobControl.GetItemAt(e.X, e.Y).ToolTipText);
|
---|
446 | }
|
---|
447 | }
|
---|
448 | #endregion
|
---|
449 |
|
---|
450 | }
|
---|
451 | } |
---|