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 | AddClients();
|
---|
77 | AddJobs();
|
---|
78 | AddUsers();
|
---|
79 | }
|
---|
80 |
|
---|
81 | /// <summary>
|
---|
82 | /// Adds clients to ListView and TreeView
|
---|
83 | /// </summary>
|
---|
84 | private void AddClients() {
|
---|
85 | try {
|
---|
86 | IClientManager clientManager =
|
---|
87 | ServiceLocator.GetClientManager();
|
---|
88 |
|
---|
89 | clients = clientManager.GetAllClientGroups();
|
---|
90 |
|
---|
91 | lvClientControl.Items.Clear();
|
---|
92 | tvClientControl.Nodes.Clear();
|
---|
93 | int count = 0;
|
---|
94 | foreach (ClientGroup cg in clients.List) {
|
---|
95 | tvClientControl.Nodes.Add(cg.Name);
|
---|
96 | ListViewGroup lvg = new ListViewGroup(cg.Name, HorizontalAlignment.Left);
|
---|
97 | foreach (ClientInfo ci in clientManager.GetAllClients().List) {
|
---|
98 | tvClientControl.Nodes[tvClientControl.Nodes.Count - 1].Nodes.Add(ci.Name);
|
---|
99 | lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvg));
|
---|
100 | count = (count + 1) % 3;
|
---|
101 | }
|
---|
102 | lvClientControl.Groups.Add(lvg);
|
---|
103 | } // Groups
|
---|
104 |
|
---|
105 | clientInfo = clientManager.GetAllClients();
|
---|
106 | ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
|
---|
107 | foreach (ClientInfo ci in clientInfo.List) {
|
---|
108 | tvClientControl.Nodes.Add(ci.Name);
|
---|
109 | lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvunsorted));
|
---|
110 | count = (count + 1) % 3;
|
---|
111 | }
|
---|
112 | lvClientControl.Groups.Add(lvunsorted);
|
---|
113 | if (flagClient) {
|
---|
114 | ClientClicked();
|
---|
115 | }
|
---|
116 | }
|
---|
117 | catch (Exception ex) {
|
---|
118 | closeFormEvent(true, true);
|
---|
119 | this.Close();
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | /// <summary>
|
---|
124 | /// Adds jobs to ListView and TreeView
|
---|
125 | /// </summary>
|
---|
126 | private void AddJobs() {
|
---|
127 | try {
|
---|
128 | IJobManager jobManager =
|
---|
129 | ServiceLocator.GetJobManager();
|
---|
130 | jobs = jobManager.GetAllJobs();
|
---|
131 |
|
---|
132 | lvJobControl.Items.Clear();
|
---|
133 | tvJobControl.Nodes.Clear();
|
---|
134 |
|
---|
135 | ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left);
|
---|
136 | ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left);
|
---|
137 | ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left);
|
---|
138 | tvJobControl.Nodes.Add("calculating");
|
---|
139 | tvJobControl.Nodes.Add("finished");
|
---|
140 | tvJobControl.Nodes.Add("pending");
|
---|
141 | foreach (Job job in jobs.List) {
|
---|
142 | if (job.State == State.calculating) {
|
---|
143 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobCalculating);
|
---|
144 | tvJobControl.Nodes[0].Nodes.Add(job.Id.ToString());
|
---|
145 | lvJobControl.Items.Add(lvi);
|
---|
146 | lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated";
|
---|
147 | } else if (job.State == State.finished) {
|
---|
148 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobFinished);
|
---|
149 | tvJobControl.Nodes[1].Nodes.Add(job.Id.ToString());
|
---|
150 | lvJobControl.Items.Add(lvi);
|
---|
151 | } else if (job.State == State.offline) {
|
---|
152 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobPending);
|
---|
153 | tvJobControl.Nodes[2].Nodes.Add(job.Id.ToString());
|
---|
154 | lvJobControl.Items.Add(lvi);
|
---|
155 | }
|
---|
156 | } // Jobs
|
---|
157 | lvJobControl.Groups.Add(lvJobCalculating);
|
---|
158 | lvJobControl.Groups.Add(lvJobFinished);
|
---|
159 | lvJobControl.Groups.Add(lvJobPending);
|
---|
160 | if (flagJob) {
|
---|
161 | JobClicked();
|
---|
162 | }
|
---|
163 | }
|
---|
164 | catch (Exception ex) {
|
---|
165 | closeFormEvent(true, true);
|
---|
166 | this.Close();
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | /// <summary>
|
---|
171 | /// Adds users to ListView and TreeView
|
---|
172 | /// </summary>
|
---|
173 | private void AddUsers() {
|
---|
174 | try {
|
---|
175 | IUserRoleManager userRoleManager =
|
---|
176 | ServiceLocator.GetUserRoleManager();
|
---|
177 |
|
---|
178 | userGroups = userRoleManager.GetAllUserGroups();
|
---|
179 |
|
---|
180 | lvUserControl.Items.Clear();
|
---|
181 | tvUserControl.Nodes.Clear();
|
---|
182 |
|
---|
183 | foreach (UserGroup ug in userGroups.List) {
|
---|
184 | tvUserControl.Nodes.Add(ug.Name);
|
---|
185 | ListViewGroup lvg = new ListViewGroup(ug.Name, HorizontalAlignment.Left);
|
---|
186 |
|
---|
187 | foreach (PermissionOwner permOwner in ug.Members) {
|
---|
188 | if (permOwner is User) {
|
---|
189 | User users = permOwner as User;
|
---|
190 | tvUserControl.Nodes[tvUserControl.Nodes.Count - 1].Nodes.Add(users.Name);
|
---|
191 | lvUserControl.Items.Add(new ListViewItem(users.Name, 0, lvg));
|
---|
192 | }
|
---|
193 | }
|
---|
194 | lvUserControl.Groups.Add(lvg);
|
---|
195 |
|
---|
196 | } // Users
|
---|
197 | usersList = userRoleManager.GetAllUsers();
|
---|
198 | ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
|
---|
199 | foreach (User u in usersList.List) {
|
---|
200 | tvUserControl.Nodes.Add(u.Name);
|
---|
201 | lvUserControl.Items.Add(new ListViewItem(u.Name, 0, lvunsorted));
|
---|
202 | }
|
---|
203 | lvUserControl.Groups.Add(lvunsorted);
|
---|
204 | if (flagUser) {
|
---|
205 | UserClicked();
|
---|
206 | }
|
---|
207 | }
|
---|
208 | catch (Exception ex) {
|
---|
209 | closeFormEvent(true, true);
|
---|
210 | this.Close();
|
---|
211 | }
|
---|
212 | }
|
---|
213 |
|
---|
214 | /// <summary>
|
---|
215 | /// if one client is clicked, a panel is opened with the details
|
---|
216 | /// </summary>
|
---|
217 | private void ClientClicked() {
|
---|
218 | int i = 0;
|
---|
219 | while (usersList.List[i].Name != nameCurrentUser) {
|
---|
220 | i++;
|
---|
221 | }
|
---|
222 | currentClient = clientInfo.List[i];
|
---|
223 | scClientControl.Panel2.Controls.Clear();
|
---|
224 | scClientControl.Panel2.Controls.Add(plClientDetails);
|
---|
225 | pbClientControl.Image = ilClientControl.Images[0];
|
---|
226 | lblClientName.Text = currentClient.Name;
|
---|
227 | lblLogin.Text = currentClient.Login.ToString();
|
---|
228 | }
|
---|
229 |
|
---|
230 | /// <summary>
|
---|
231 | /// if one job is clicked, a panel is opened with the details
|
---|
232 | /// </summary>
|
---|
233 | private void JobClicked() {
|
---|
234 | int i = 0;
|
---|
235 | while (jobs.List[i].Id.ToString() != nameCurrentJob) {
|
---|
236 | i++;
|
---|
237 | }
|
---|
238 | lvSnapshots.Enabled = false;
|
---|
239 | int yPos = 0;
|
---|
240 | currentJob = jobs.List[i];
|
---|
241 | scJobControl.Panel2.Controls.Clear();
|
---|
242 | scJobControl.Panel2.Controls.Add(plJobDetails);
|
---|
243 | pbJobControl.Image = ilJobControl.Images[0];
|
---|
244 | lblJobName.Text = currentJob.Id.ToString();
|
---|
245 | progressJob.Value = (int)(currentJob.Percentage * 100);
|
---|
246 | yPos = progressJob.Location.Y;
|
---|
247 | yPos += 20;
|
---|
248 | lblProgress.Location = new Point(
|
---|
249 | lblProgress.Location.X, yPos);
|
---|
250 | lblProgress.Text = (int)(currentJob.Percentage * 100) + "% calculated";
|
---|
251 | yPos += 20;
|
---|
252 | lblUserCreatedJob.Location = new Point(
|
---|
253 | lblUserCreatedJob.Location.X, yPos);
|
---|
254 | lblUserCreatedJob.Text = /* currentJob.User.Name + */ " created Job";
|
---|
255 | yPos += 20;
|
---|
256 | lblJobCreated.Location = new Point(
|
---|
257 | lblJobCreated.Location.X, yPos);
|
---|
258 | lblJobCreated.Text = "Created at "/* + currentJob.User.CreatedJob + */;
|
---|
259 | if (currentJob.ParentJob != null) {
|
---|
260 | yPos += 20;
|
---|
261 | lblParentJob.Location = new Point(
|
---|
262 | lblParentJob.Location.X, yPos);
|
---|
263 | lblParentJob.Text = currentJob.ParentJob.Id + " is parent job";
|
---|
264 | }
|
---|
265 | yPos += 20;
|
---|
266 | lblPriorityJob.Location = new Point(
|
---|
267 | lblPriorityJob.Location.X, yPos);
|
---|
268 | lblPriorityJob.Text = "Priority of job is " /* + currentJob.Priority */;
|
---|
269 | if (currentJob.Client != null) {
|
---|
270 | yPos += 20;
|
---|
271 | lblClientCalculating.Location = new Point(
|
---|
272 | lblClientCalculating.Location.X, yPos);
|
---|
273 | lblClientCalculating.Text = currentJob.Client.Name + " calculated Job";
|
---|
274 | yPos += 20;
|
---|
275 | lblJobCalculationBegin.Location = new Point(
|
---|
276 | lblJobCalculationBegin.Location.X, yPos);
|
---|
277 | lblJobCalculationBegin.Text = "Startet calculation at " /* + currentJob.User.CalculationBegin */;
|
---|
278 | yPos += 20;
|
---|
279 | lblJobCalculationEnd.Location = new Point(
|
---|
280 | lblJobCalculationEnd.Location.X, yPos);
|
---|
281 | lblJobCalculationEnd.Text = "Calculation ended at " /* + currentJob.User.CalculationEnd */;
|
---|
282 | }
|
---|
283 | if (currentJob.State != State.offline) {
|
---|
284 | yPos += 30;
|
---|
285 | lvSnapshots.Location = new Point(
|
---|
286 | lvSnapshots.Location.X, yPos);
|
---|
287 | lvSnapshots.Size = new Size(lvSnapshots.Size.Width,
|
---|
288 | plJobDetails.Size.Height - 10 - yPos);
|
---|
289 | lvSnapshots.Enabled = true;
|
---|
290 | }
|
---|
291 | }
|
---|
292 |
|
---|
293 | /// <summary>
|
---|
294 | /// if one user is clicked, a panel is opened with the details
|
---|
295 | /// </summary>
|
---|
296 | private void UserClicked() {
|
---|
297 | int i = 0;
|
---|
298 | while (usersList.List[i].Name != nameCurrentUser) {
|
---|
299 | i++;
|
---|
300 | }
|
---|
301 | currentUser = usersList.List[i];
|
---|
302 | scUserControl.Panel2.Controls.Clear();
|
---|
303 | scUserControl.Panel2.Controls.Add(plUserDetails);
|
---|
304 | pbUserControl.Image = ilUserControl.Images[0];
|
---|
305 | lblUserName.Text = currentUser.Id.ToString();
|
---|
306 | }
|
---|
307 |
|
---|
308 | #region Eventhandlers
|
---|
309 | /// <summary>
|
---|
310 | /// Send event to Login-GUI when closing
|
---|
311 | /// </summary>
|
---|
312 | /// <param name="sender"></param>
|
---|
313 | /// <param name="e"></param>
|
---|
314 | private void Close_Click(object sender, EventArgs e) {
|
---|
315 | if (closeFormEvent != null) {
|
---|
316 | closeFormEvent(true, false);
|
---|
317 | }
|
---|
318 | this.Close();
|
---|
319 | }
|
---|
320 |
|
---|
321 | /// <summary>
|
---|
322 | /// Send evnt to Login-GUI when closing
|
---|
323 | /// </summary>
|
---|
324 | /// <param name="sender"></param>
|
---|
325 | /// <param name="e"></param>
|
---|
326 | private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
|
---|
327 | if (closeFormEvent != null) {
|
---|
328 | closeFormEvent(true, false);
|
---|
329 | }
|
---|
330 | }
|
---|
331 |
|
---|
332 | private void AddJob_Click(object sender, EventArgs e) {
|
---|
333 | AddJobForm newForm = new AddJobForm();
|
---|
334 | newForm.Show();
|
---|
335 | }
|
---|
336 |
|
---|
337 | private void AddUser_Click(object sender, EventArgs e) {
|
---|
338 | AddUserForm newForm = new AddUserForm("User", false);
|
---|
339 | newForm.Show();
|
---|
340 | }
|
---|
341 |
|
---|
342 | private void AddUserGroup_Click(object sender, EventArgs e) {
|
---|
343 | AddUserForm newForm = new AddUserForm("User", true);
|
---|
344 | newForm.Show();
|
---|
345 | }
|
---|
346 |
|
---|
347 | private void OnLVClientClicked(object sender, EventArgs e) {
|
---|
348 | nameCurrentClient = lvClientControl.SelectedItems[0].Text;
|
---|
349 | flagClient = true;
|
---|
350 | ClientClicked();
|
---|
351 | }
|
---|
352 |
|
---|
353 | private void OnLVJobControlClicked(object sender, EventArgs e) {
|
---|
354 | nameCurrentJob = lvJobControl.SelectedItems[0].Text;
|
---|
355 | flagJob = true;
|
---|
356 | JobClicked();
|
---|
357 | }
|
---|
358 |
|
---|
359 | private void OnTVJobControlClicked(object sender, EventArgs e) {
|
---|
360 | try {
|
---|
361 | nameCurrentJob = Convert.ToInt32(tvJobControl.SelectedNode.Text).ToString();
|
---|
362 | flagJob = true;
|
---|
363 | JobClicked();
|
---|
364 | }
|
---|
365 | catch (Exception ex) { }
|
---|
366 |
|
---|
367 | }
|
---|
368 |
|
---|
369 | private void OnLVUserControlClicked(object sender, EventArgs e) {
|
---|
370 | nameCurrentUser = lvUserControl.SelectedItems[0].Name;
|
---|
371 | flagUser = true;
|
---|
372 | UserClicked();
|
---|
373 | }
|
---|
374 |
|
---|
375 | private void btnClientClose_Click(object sender, EventArgs e) {
|
---|
376 | scClientControl.Panel2.Controls.Clear();
|
---|
377 | scClientControl.Panel2.Controls.Add(lvClientControl);
|
---|
378 | flagClient = false;
|
---|
379 | }
|
---|
380 |
|
---|
381 | private void btnJobDetailClose_Click(object sender, EventArgs e) {
|
---|
382 | scJobControl.Panel2.Controls.Clear();
|
---|
383 | scJobControl.Panel2.Controls.Add(lvJobControl);
|
---|
384 | flagJob = false;
|
---|
385 | }
|
---|
386 |
|
---|
387 | private void btnUserControlClose_Click(object sender, EventArgs e) {
|
---|
388 | scUserControl.Panel2.Controls.Clear();
|
---|
389 | scUserControl.Panel2.Controls.Add(lvUserControl);
|
---|
390 | flagUser = false;
|
---|
391 | }
|
---|
392 |
|
---|
393 | private void lvJobControl_MouseMove(object sender, MouseEventArgs e) {
|
---|
394 | if ((lvJobControl.GetItemAt(e.X, e.Y) != null) &&
|
---|
395 | (lvJobControl.GetItemAt(e.X, e.Y).ToolTipText != null)) {
|
---|
396 | tt.SetToolTip(lvJobControl, lvJobControl.GetItemAt(e.X, e.Y).ToolTipText);
|
---|
397 | }
|
---|
398 | }
|
---|
399 | #endregion
|
---|
400 | }
|
---|
401 | } |
---|