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 | using System.Threading;
|
---|
34 | using System.ServiceModel;
|
---|
35 |
|
---|
36 | namespace HeuristicLab.Hive.Server.ServerConsole {
|
---|
37 |
|
---|
38 | /// <summary>
|
---|
39 | /// if form is closed the loginform gets an information
|
---|
40 | /// </summary>
|
---|
41 | /// <param name="cf"></param>
|
---|
42 | /// <param name="error"></param>
|
---|
43 | public delegate void closeForm(bool cf, bool error);
|
---|
44 |
|
---|
45 | public partial class HiveServerManagementConsole : Form {
|
---|
46 |
|
---|
47 | public event closeForm closeFormEvent;
|
---|
48 |
|
---|
49 | #region private variables
|
---|
50 | private ResponseList<Job> jobs = null;
|
---|
51 |
|
---|
52 | List<ListViewGroup> jobGroup;
|
---|
53 | private Dictionary<Guid, List<ListViewItem>> clientList = new Dictionary<Guid, List<ListViewItem>>();
|
---|
54 | private List<Changes> changes = new List<Changes>();
|
---|
55 |
|
---|
56 | private Job currentJob = null;
|
---|
57 | private ClientInfo currentClient = null;
|
---|
58 |
|
---|
59 | private TreeNode currentGroupNode = null;
|
---|
60 | Guid parentgroup = Guid.Empty;
|
---|
61 | private ToolTip tt = new ToolTip();
|
---|
62 |
|
---|
63 | private const string NOGROUP = "No group";
|
---|
64 |
|
---|
65 | #endregion
|
---|
66 |
|
---|
67 | #region Properties
|
---|
68 | private IClientManager ClientManager {
|
---|
69 | get {
|
---|
70 | try {
|
---|
71 | return ServiceLocator.GetClientManager();
|
---|
72 | }
|
---|
73 | catch (FaultException ex) {
|
---|
74 | MessageBox.Show(ex.Message);
|
---|
75 | }
|
---|
76 | return null;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | #endregion
|
---|
80 |
|
---|
81 | public HiveServerManagementConsole() {
|
---|
82 | InitializeComponent();
|
---|
83 | Init();
|
---|
84 | AddClients();
|
---|
85 | AddJobs();
|
---|
86 | timerSyncronize.Start();
|
---|
87 | }
|
---|
88 |
|
---|
89 | private TreeNode hoverNode; // node being hovered over during DnD
|
---|
90 | private void Init() {
|
---|
91 |
|
---|
92 | //adding context menu items for jobs
|
---|
93 | menuItemAbortJob.Click += (s, e) => {
|
---|
94 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
95 | if (lvJobControl.SelectedItems.Count == 1) {
|
---|
96 | jobManager.AbortJob(((Job)(lvJobControl.SelectedItems[0].Tag)).Id);
|
---|
97 | }
|
---|
98 | };
|
---|
99 |
|
---|
100 | //adding context menu items for jobs
|
---|
101 | menuItemGetSnapshot.Click += (s, e) => {
|
---|
102 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
103 | if (lvJobControl.SelectedItems.Count == 1) {
|
---|
104 | jobManager.RequestSnapshot(((Job)(lvJobControl.SelectedItems[0].Tag)).Id);
|
---|
105 | }
|
---|
106 | };
|
---|
107 |
|
---|
108 | //adding group
|
---|
109 | menuItemAddGroup.Click += (s, e) => {
|
---|
110 | AddGroup addgroup = new AddGroup();
|
---|
111 | parentgroup = Guid.Empty;
|
---|
112 | if ((tvClientControl.SelectedNode != null) && (((ClientGroup)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) {
|
---|
113 | parentgroup = ((ClientGroup)tvClientControl.SelectedNode.Tag).Id;
|
---|
114 | }
|
---|
115 | addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent);
|
---|
116 | addgroup.Show();
|
---|
117 | };
|
---|
118 |
|
---|
119 | //adding group
|
---|
120 | menuItemDeleteGroup.Click += (s, e) => {
|
---|
121 | IClientManager clientManager = ServiceLocator.GetClientManager();
|
---|
122 | if (tvClientControl.SelectedNode != null) {
|
---|
123 | Response resp = clientManager.DeleteClientGroup(((ClientGroup)tvClientControl.SelectedNode.Tag).Id);
|
---|
124 | if (tvClientControl.SelectedNode == currentGroupNode) {
|
---|
125 | currentGroupNode = null;
|
---|
126 | }
|
---|
127 | tvClientControl.Nodes.Remove(tvClientControl.SelectedNode);
|
---|
128 | AddClients();
|
---|
129 | }
|
---|
130 | };
|
---|
131 |
|
---|
132 | lvClientControl.ItemDrag += delegate(object sender, ItemDragEventArgs e) {
|
---|
133 | List<string> itemIDs = new List<string>((sender as ListView).SelectedItems.Count);
|
---|
134 | foreach (ListViewItem item in (sender as ListView).SelectedItems) {
|
---|
135 | itemIDs.Add(item.Name);
|
---|
136 | }
|
---|
137 | (sender as ListView).DoDragDrop(itemIDs.ToArray(), DragDropEffects.Move);
|
---|
138 | };
|
---|
139 |
|
---|
140 | tvClientControl.DragEnter += delegate(object sender, DragEventArgs e) {
|
---|
141 | e.Effect = DragDropEffects.Move;
|
---|
142 | };
|
---|
143 |
|
---|
144 | tvClientControl.DragOver += delegate(object sender, DragEventArgs e) {
|
---|
145 | Point mouseLocation = tvClientControl.PointToClient(new Point(e.X, e.Y));
|
---|
146 | TreeNode node = tvClientControl.GetNodeAt(mouseLocation);
|
---|
147 | if (node != null && ((ClientGroup)node.Tag).Id != Guid.Empty) {
|
---|
148 | e.Effect = DragDropEffects.Move;
|
---|
149 | if (hoverNode == null) {
|
---|
150 | node.BackColor = Color.LightBlue;
|
---|
151 | node.ForeColor = Color.White;
|
---|
152 | hoverNode = node;
|
---|
153 | } else if (hoverNode != node) {
|
---|
154 | hoverNode.BackColor = Color.White;
|
---|
155 | hoverNode.ForeColor = Color.Black;
|
---|
156 | node.BackColor = Color.LightBlue;
|
---|
157 | node.ForeColor = Color.White;
|
---|
158 | hoverNode = node;
|
---|
159 | }
|
---|
160 | } else {
|
---|
161 | e.Effect = DragDropEffects.None;
|
---|
162 | }
|
---|
163 | };
|
---|
164 |
|
---|
165 | tvClientControl.DragDrop += delegate(object sender, DragEventArgs e) {
|
---|
166 | if (e.Data.GetDataPresent(typeof(string[]))) {
|
---|
167 | Point dropLocation = (sender as TreeView).PointToClient(new Point(e.X, e.Y));
|
---|
168 | TreeNode dropNode = (sender as TreeView).GetNodeAt(dropLocation);
|
---|
169 | if (((ClientGroup)dropNode.Tag).Id != Guid.Empty) {
|
---|
170 | Dictionary<ClientInfo, Guid> clients = new Dictionary<ClientInfo, Guid>();
|
---|
171 | foreach (ListViewItem lvi in lvClientControl.SelectedItems) {
|
---|
172 | Guid groupId = Guid.Empty;
|
---|
173 | foreach (ListViewGroup lvg in lvClientGroups) {
|
---|
174 | if (lvi.Group.Header == ((ClientGroup)lvg.Tag).Name) {
|
---|
175 | groupId = ((ClientGroup)lvg.Tag).Id;
|
---|
176 | }
|
---|
177 | }
|
---|
178 | clients.Add((ClientInfo)lvi.Tag, groupId);
|
---|
179 | }
|
---|
180 | ChangeGroup(clients, ((ClientGroup)dropNode.Tag).Id);
|
---|
181 | }
|
---|
182 | tvClientControl_DragLeave(null, EventArgs.Empty);
|
---|
183 | AddClients();
|
---|
184 | }
|
---|
185 | };
|
---|
186 | }
|
---|
187 |
|
---|
188 | private void ChangeGroup(Dictionary<ClientInfo, Guid> clients, Guid clientgroupID) {
|
---|
189 | IClientManager clientManager = ServiceLocator.GetClientManager();
|
---|
190 | foreach (KeyValuePair<ClientInfo, Guid> client in clients) {
|
---|
191 | if (client.Key.Id != Guid.Empty) {
|
---|
192 | Response resp = clientManager.DeleteResourceFromGroup(client.Value, client.Key.Id);
|
---|
193 | }
|
---|
194 | clientManager.AddResourceToGroup(clientgroupID, client.Key);
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | #region Backgroundworker
|
---|
199 | /// <summary>
|
---|
200 | /// event on Ticker
|
---|
201 | /// </summary>
|
---|
202 | /// <param name="obj"></param>
|
---|
203 | /// <param name="e"></param>
|
---|
204 | private void TickSync(object obj, EventArgs e) {
|
---|
205 | if (!updaterWoker.IsBusy) {
|
---|
206 | updaterWoker.RunWorkerAsync();
|
---|
207 | }
|
---|
208 | }
|
---|
209 |
|
---|
210 | private void updaterWoker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
211 | RefreshForm();
|
---|
212 | }
|
---|
213 |
|
---|
214 | private void updaterWoker_DoWork(object sender, DoWorkEventArgs e) {
|
---|
215 |
|
---|
216 | changes.Clear();
|
---|
217 |
|
---|
218 | //#region ClientInfo
|
---|
219 | //ResponseList<ClientInfo> clientInfoOld = clientInfo;
|
---|
220 | //clientInfo = ClientManager.GetAllClients();
|
---|
221 |
|
---|
222 | //IDictionary<int, ClientInfo> clientInfoOldHelp;
|
---|
223 |
|
---|
224 | //CloneList(clientInfoOld, out clientInfoOldHelp);
|
---|
225 |
|
---|
226 | //GetDelta(clientInfoOld.List, clientInfoOldHelp);
|
---|
227 | //#endregion
|
---|
228 |
|
---|
229 | #region Clients
|
---|
230 | //ResponseList<ClientGroup> clientsOld = clients;
|
---|
231 |
|
---|
232 | // newClients = ClientManager.GetAllClientGroups();
|
---|
233 |
|
---|
234 | //IDictionary<Guid, ClientGroup> clientsOldHelp;
|
---|
235 |
|
---|
236 | //CloneList(clientsOld, out clientsOldHelp);
|
---|
237 |
|
---|
238 | //GetDelta(clientsOld.List, clientsOldHelp);
|
---|
239 | //DetermineDelta();
|
---|
240 | #endregion
|
---|
241 |
|
---|
242 | #region Job
|
---|
243 | ResponseList<Job> jobsOld = jobs;
|
---|
244 | try {
|
---|
245 | IJobManager jobManager =
|
---|
246 | ServiceLocator.GetJobManager();
|
---|
247 |
|
---|
248 | jobs = jobManager.GetAllJobs();
|
---|
249 |
|
---|
250 | IDictionary<int, Job> jobsOldHelp;
|
---|
251 | CloneList(jobsOld, out jobsOldHelp);
|
---|
252 |
|
---|
253 | GetDelta(jobsOld.List, jobsOldHelp);
|
---|
254 |
|
---|
255 | }
|
---|
256 | catch (FaultException fe) {
|
---|
257 | MessageBox.Show(fe.Message);
|
---|
258 | }
|
---|
259 |
|
---|
260 | #endregion
|
---|
261 |
|
---|
262 | foreach (Changes change in changes) {
|
---|
263 | System.Diagnostics.Debug.WriteLine(change.ID + " " + change.ChangeType);
|
---|
264 | }
|
---|
265 |
|
---|
266 | }
|
---|
267 |
|
---|
268 | #endregion
|
---|
269 |
|
---|
270 |
|
---|
271 | /// <summary>
|
---|
272 | /// Adds Exceptionobs to ListView and TreeView
|
---|
273 | /// </summary>
|
---|
274 | private void AddJobs() {
|
---|
275 | try {
|
---|
276 | List<ListViewItem> jobObjects = new List<ListViewItem>();
|
---|
277 | IJobManager jobManager =
|
---|
278 | ServiceLocator.GetJobManager();
|
---|
279 | jobs = jobManager.GetAllJobs();
|
---|
280 |
|
---|
281 | lvJobControl.Items.Clear();
|
---|
282 |
|
---|
283 | ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left);
|
---|
284 | ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left);
|
---|
285 | ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left);
|
---|
286 |
|
---|
287 | jobGroup = new List<ListViewGroup>();
|
---|
288 | jobGroup.Add(lvJobCalculating);
|
---|
289 | jobGroup.Add(lvJobFinished);
|
---|
290 | jobGroup.Add(lvJobPending);
|
---|
291 |
|
---|
292 | foreach (Job job in jobs.List) {
|
---|
293 | if (job.State == State.calculating) {
|
---|
294 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 1, lvJobCalculating);
|
---|
295 | lvi.Tag = job;
|
---|
296 | jobObjects.Add(lvi);
|
---|
297 |
|
---|
298 | lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated";
|
---|
299 | } else if (job.State == State.finished) {
|
---|
300 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobFinished);
|
---|
301 | lvi.Tag = job;
|
---|
302 | jobObjects.Add(lvi);
|
---|
303 | //lvJobControl.Items.Add(lvi);
|
---|
304 | } else if (job.State == State.offline) {
|
---|
305 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 2, lvJobPending);
|
---|
306 | lvi.Tag = job;
|
---|
307 | jobObjects.Add(lvi);
|
---|
308 | }
|
---|
309 | } // Jobs
|
---|
310 | lvJobControl.BeginUpdate();
|
---|
311 | foreach (ListViewItem lvi in jobObjects) {
|
---|
312 | lvJobControl.Items.Add(lvi);
|
---|
313 | }
|
---|
314 | // actualization
|
---|
315 | lvJobControl.Groups.Add(lvJobCalculating);
|
---|
316 | lvJobControl.Groups.Add(lvJobFinished);
|
---|
317 | lvJobControl.Groups.Add(lvJobPending);
|
---|
318 | lvJobControl.EndUpdate();
|
---|
319 |
|
---|
320 | if (currentJob != null) {
|
---|
321 | JobClicked();
|
---|
322 | }
|
---|
323 | }
|
---|
324 | catch (Exception ex) {
|
---|
325 | closeFormEvent(true, true);
|
---|
326 | this.Close();
|
---|
327 | }
|
---|
328 | }
|
---|
329 |
|
---|
330 | List<ListViewGroup> lvClientGroups;
|
---|
331 | private void AddClients() {
|
---|
332 | lvClientGroups = new List<ListViewGroup>();
|
---|
333 | clientList.Clear();
|
---|
334 | tvClientControl.Nodes.Clear();
|
---|
335 | try {
|
---|
336 | ResponseList<ClientGroup> clientGroups = ClientManager.GetAllClientGroups();
|
---|
337 |
|
---|
338 | foreach (ClientGroup cg in clientGroups.List) {
|
---|
339 | AddClientOrGroup(cg, null);
|
---|
340 | }
|
---|
341 |
|
---|
342 | if (currentGroupNode != null) {
|
---|
343 | lvClientControl.Items.Clear();
|
---|
344 | lvClientControl.Groups.Clear();
|
---|
345 | AddGroupsToListView(currentGroupNode);
|
---|
346 | }
|
---|
347 | tvClientControl.ExpandAll();
|
---|
348 |
|
---|
349 | }
|
---|
350 | catch (FaultException fe) {
|
---|
351 | MessageBox.Show(fe.Message);
|
---|
352 | }
|
---|
353 | }
|
---|
354 |
|
---|
355 | private void AddClientOrGroup(ClientGroup clientGroup, TreeNode currentNode) {
|
---|
356 | currentNode = CreateTreeNode(clientGroup, currentNode);
|
---|
357 | List<ListViewItem> clientGroupList = new List<ListViewItem>();
|
---|
358 | ListViewGroup lvg;
|
---|
359 | if (string.IsNullOrEmpty(clientGroup.Name)) {
|
---|
360 | lvg = new ListViewGroup(NOGROUP, HorizontalAlignment.Left);
|
---|
361 | } else {
|
---|
362 | lvg = new ListViewGroup(clientGroup.Name, HorizontalAlignment.Left);
|
---|
363 | }
|
---|
364 | lvClientControl.Groups.Add(lvg);
|
---|
365 | lvg.Tag = clientGroup;
|
---|
366 | lvClientGroups.Add(lvg);
|
---|
367 | foreach (Resource resource in clientGroup.Resources) {
|
---|
368 | if (resource is ClientInfo) {
|
---|
369 | int percentageUsage = CapacityRam(((ClientInfo)resource).NrOfCores, ((ClientInfo)resource).NrOfFreeCores);
|
---|
370 | int usage = 3;
|
---|
371 | if ((((ClientInfo)resource).State != State.offline) &&
|
---|
372 | (((ClientInfo)resource).State != State.nullState)) {
|
---|
373 | if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
|
---|
374 | usage = 0;
|
---|
375 | } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
|
---|
376 | usage = 1;
|
---|
377 | } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
|
---|
378 | usage = 2;
|
---|
379 | }
|
---|
380 | }
|
---|
381 | ListViewItem lvi = new ListViewItem(resource.Name, usage, lvg);
|
---|
382 | lvi.Tag = resource as ClientInfo;
|
---|
383 | clientGroupList.Add(lvi);
|
---|
384 | } else if (resource is ClientGroup) {
|
---|
385 | AddClientOrGroup(resource as ClientGroup, currentNode);
|
---|
386 | }
|
---|
387 | }
|
---|
388 | clientList.Add(clientGroup.Id, clientGroupList);
|
---|
389 | }
|
---|
390 |
|
---|
391 | private TreeNode CreateTreeNode(ClientGroup clientGroup, TreeNode currentNode) {
|
---|
392 | TreeNode tn;
|
---|
393 | if (string.IsNullOrEmpty(clientGroup.Name)) {
|
---|
394 | tn = new TreeNode(NOGROUP);
|
---|
395 | } else {
|
---|
396 | tn = new TreeNode(clientGroup.Name);
|
---|
397 | }
|
---|
398 | tn.Tag = clientGroup;
|
---|
399 | if (currentNode == null) {
|
---|
400 | tvClientControl.Nodes.Add(tn);
|
---|
401 | } else {
|
---|
402 | currentNode.Nodes.Add(tn);
|
---|
403 | }
|
---|
404 | return tn;
|
---|
405 | }
|
---|
406 |
|
---|
407 | private void AddGroupsToListView(TreeNode node) {
|
---|
408 | if (node != null) {
|
---|
409 | ListViewGroup lvg = new ListViewGroup(node.Text, HorizontalAlignment.Left);
|
---|
410 | lvClientControl.Groups.Add(lvg);
|
---|
411 | lvg.Tag = node.Tag;
|
---|
412 | foreach (ListViewItem item in clientList[((ClientGroup)node.Tag).Id]) {
|
---|
413 | item.Group = lvg;
|
---|
414 | lvClientControl.Items.Add(item);
|
---|
415 | }
|
---|
416 |
|
---|
417 | if (node.Nodes != null) {
|
---|
418 | foreach (TreeNode curNode in node.Nodes) {
|
---|
419 | AddGroupsToListView(curNode);
|
---|
420 | }
|
---|
421 | }
|
---|
422 | }
|
---|
423 | }
|
---|
424 |
|
---|
425 | /// <summary>
|
---|
426 | /// if one job is clicked, the details for the clicked job are shown
|
---|
427 | /// in the second panel
|
---|
428 | /// </summary>
|
---|
429 | private void JobClicked() {
|
---|
430 | plJobDetails.Visible = true;
|
---|
431 | lvJobDetails.Items.Clear();
|
---|
432 |
|
---|
433 | lvSnapshots.Enabled = true;
|
---|
434 |
|
---|
435 | if (currentJob.State == State.offline) {
|
---|
436 | pbJobControl.Image = ilLargeImgJob.Images[2];
|
---|
437 | } else if (currentJob.State == State.calculating) {
|
---|
438 | pbJobControl.Image = ilLargeImgJob.Images[1];
|
---|
439 | } else if (currentJob.State == State.finished) {
|
---|
440 | pbJobControl.Image = ilLargeImgJob.Images[0];
|
---|
441 | }
|
---|
442 |
|
---|
443 | lblJobName.Text = currentJob.Id.ToString();
|
---|
444 | progressJob.Value = (int)(currentJob.Percentage * 100);
|
---|
445 | lblProgress.Text = (int)(currentJob.Percentage * 100) + "% calculated";
|
---|
446 |
|
---|
447 | ListViewItem lvi = new ListViewItem();
|
---|
448 | lvi.Text = "User:";
|
---|
449 | lvi.SubItems.Add(currentJob.UserId.ToString());
|
---|
450 | lvJobDetails.Items.Add(lvi);
|
---|
451 |
|
---|
452 | lvi = null;
|
---|
453 | lvi = new ListViewItem();
|
---|
454 | lvi.Text = "created at:";
|
---|
455 | lvi.SubItems.Add(currentJob.DateCreated.ToString());
|
---|
456 | lvJobDetails.Items.Add(lvi);
|
---|
457 |
|
---|
458 | if (currentJob.ParentJob != null) {
|
---|
459 | lvi = null;
|
---|
460 | lvi = new ListViewItem();
|
---|
461 | lvi.Text = "Parent job:";
|
---|
462 | lvi.SubItems.Add(currentJob.ParentJob.ToString());
|
---|
463 | lvJobDetails.Items.Add(lvi);
|
---|
464 | }
|
---|
465 |
|
---|
466 | lvi = null;
|
---|
467 | lvi = new ListViewItem();
|
---|
468 | lvi.Text = "Priority:";
|
---|
469 | lvi.SubItems.Add(currentJob.Priority.ToString());
|
---|
470 | lvJobDetails.Items.Add(lvi);
|
---|
471 |
|
---|
472 | if (currentJob.Project != null) {
|
---|
473 | lvi = null;
|
---|
474 | lvi = new ListViewItem();
|
---|
475 | lvi.Text = "Project:";
|
---|
476 | lvi.SubItems.Add(currentJob.Project.Name.ToString());
|
---|
477 | lvJobDetails.Items.Add(lvi);
|
---|
478 | }
|
---|
479 |
|
---|
480 | if (currentJob.Client != null) {
|
---|
481 | lvi = null;
|
---|
482 | lvi = new ListViewItem();
|
---|
483 | lvi.Text = "Calculation begin:";
|
---|
484 | lvi.SubItems.Add(currentJob.DateCalculated.ToString());
|
---|
485 | lvJobDetails.Items.Add(lvi);
|
---|
486 |
|
---|
487 |
|
---|
488 | lvi = null;
|
---|
489 | lvi = new ListViewItem();
|
---|
490 | lvi.Text = "Client calculated:";
|
---|
491 | lvi.SubItems.Add(currentJob.Client.Name.ToString());
|
---|
492 | lvJobDetails.Items.Add(lvi);
|
---|
493 |
|
---|
494 | if (currentJob.State == State.finished) {
|
---|
495 | IJobManager jobManager =
|
---|
496 | ServiceLocator.GetJobManager();
|
---|
497 | ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id, false);
|
---|
498 |
|
---|
499 | lvi = null;
|
---|
500 | lvi = new ListViewItem();
|
---|
501 | lvi.Text = "Calculation ended:";
|
---|
502 | lvi.SubItems.Add(jobRes.Obj.DateFinished.ToString());
|
---|
503 | lvJobDetails.Items.Add(lvi);
|
---|
504 | }
|
---|
505 | }
|
---|
506 | if (currentJob.State != State.offline) {
|
---|
507 | lvSnapshots.Items.Clear();
|
---|
508 | GetSnapshotList();
|
---|
509 | } else {
|
---|
510 | lvSnapshots.Visible = false;
|
---|
511 | }
|
---|
512 | }
|
---|
513 |
|
---|
514 | /// <summary>
|
---|
515 | /// if one client is clicked, the details for the clicked client are shown
|
---|
516 | /// in the second panel
|
---|
517 | /// </summary>
|
---|
518 | private void ClientClicked() {
|
---|
519 | plClientDetails.Visible = true;
|
---|
520 |
|
---|
521 | if (currentClient != null) {
|
---|
522 | int percentageUsage = CapacityRam(currentClient.NrOfCores, currentClient.NrOfFreeCores);
|
---|
523 | int usage = 3;
|
---|
524 | if ((currentClient.State != State.offline) && (currentClient.State != State.nullState)) {
|
---|
525 | if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
|
---|
526 | usage = 0;
|
---|
527 | } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
|
---|
528 | usage = 1;
|
---|
529 | } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
|
---|
530 | usage = 2;
|
---|
531 | }
|
---|
532 | }
|
---|
533 | pbClientControl.Image = ilLargeImgClient.Images[usage];
|
---|
534 | lblClientName.Text = currentClient.Name;
|
---|
535 | lblLogin.Text = currentClient.Login.ToString();
|
---|
536 | lblState.Text = currentClient.State.ToString();
|
---|
537 | }
|
---|
538 | }
|
---|
539 |
|
---|
540 |
|
---|
541 | private void RefreshForm() {
|
---|
542 | foreach (Changes change in changes) {
|
---|
543 | if (change.Types == Type.Job) {
|
---|
544 | RefreshJob(change);
|
---|
545 | }
|
---|
546 | }
|
---|
547 | }
|
---|
548 |
|
---|
549 | private void RefreshJob(Changes change) {
|
---|
550 | if (change.ChangeType == Change.Update) {
|
---|
551 | for (int i = 0; i < lvJobControl.Items.Count; i++) {
|
---|
552 | if (lvJobControl.Items[i].Text == change.ID.ToString()) {
|
---|
553 | foreach (Job job in jobs.List) {
|
---|
554 | if (job.Id == change.ID) {
|
---|
555 | lvJobControl.Items[i].Tag = job;
|
---|
556 | if (currentJob.Id == change.ID) {
|
---|
557 | currentJob = job;
|
---|
558 | JobClicked();
|
---|
559 | }
|
---|
560 | break;
|
---|
561 | }
|
---|
562 | }
|
---|
563 | State state = jobs.List[change.Position].State;
|
---|
564 | System.Diagnostics.Debug.WriteLine(lvJobControl.Items[i].Text.ToString());
|
---|
565 | if (state == State.finished) {
|
---|
566 | lvJobControl.Items[i].Group = jobGroup[1];
|
---|
567 | lvJobControl.Items[i].ImageIndex = 0;
|
---|
568 | System.Diagnostics.Debug.WriteLine("finished");
|
---|
569 | } else if (state == State.calculating) {
|
---|
570 | lvJobControl.Items[i].Group = jobGroup[0];
|
---|
571 | lvJobControl.Items[i].ImageIndex = 1;
|
---|
572 | System.Diagnostics.Debug.WriteLine("calculating");
|
---|
573 | } else if (state == State.offline) {
|
---|
574 | lvJobControl.Items[i].Group = jobGroup[2];
|
---|
575 | lvJobControl.Items[i].ImageIndex = 2;
|
---|
576 | System.Diagnostics.Debug.WriteLine("offline");
|
---|
577 |
|
---|
578 | }
|
---|
579 | lvJobControl.Refresh();
|
---|
580 | }
|
---|
581 | }
|
---|
582 | } else if (change.ChangeType == Change.Create) {
|
---|
583 |
|
---|
584 | ListViewItem lvi = new ListViewItem(
|
---|
585 | change.ID.ToString(), 2, jobGroup[2]);
|
---|
586 | foreach (Job job in jobs.List) {
|
---|
587 | if (job.Id == change.ID) {
|
---|
588 | lvi.Tag = job;
|
---|
589 | break;
|
---|
590 | }
|
---|
591 | }
|
---|
592 | lvJobControl.Items.Add(lvi);
|
---|
593 |
|
---|
594 | } else if (change.ChangeType == Change.Delete) {
|
---|
595 | for (int i = 0; i < lvJobControl.Items.Count; i++) {
|
---|
596 | if (change.ID.ToString() == lvJobControl.Items[i].Text.ToString()) {
|
---|
597 | lvJobControl.Items[i].Remove();
|
---|
598 | break;
|
---|
599 | }
|
---|
600 | }
|
---|
601 | }
|
---|
602 | }
|
---|
603 |
|
---|
604 |
|
---|
605 | #region Eventhandlers
|
---|
606 | /// <summary>
|
---|
607 | /// Send event to Login-GUI when closing
|
---|
608 | /// </summary>
|
---|
609 | /// <param name="sender"></param>
|
---|
610 | /// <param name="e"></param>
|
---|
611 | private void Close_Click(object sender, EventArgs e) {
|
---|
612 | if (closeFormEvent != null) {
|
---|
613 | closeFormEvent(true, false);
|
---|
614 | }
|
---|
615 | this.Close();
|
---|
616 | }
|
---|
617 |
|
---|
618 | /// <summary>
|
---|
619 | /// Send evnt to Login-GUI when closing
|
---|
620 | /// </summary>
|
---|
621 | /// <param name="sender"></param>
|
---|
622 | /// <param name="e"></param>
|
---|
623 | private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
|
---|
624 | if (closeFormEvent != null) {
|
---|
625 | closeFormEvent(true, false);
|
---|
626 | }
|
---|
627 | }
|
---|
628 |
|
---|
629 | private void AddJob_Click(object sender, EventArgs e) {
|
---|
630 | AddJobForm newForm = new AddJobForm();
|
---|
631 | newForm.Show();
|
---|
632 | newForm.addJobEvent += new addDelegate(updaterWoker.RunWorkerAsync);
|
---|
633 | }
|
---|
634 |
|
---|
635 | private void OnLVJobControlClicked(object sender, EventArgs e) {
|
---|
636 | currentJob = (Job)lvJobControl.SelectedItems[0].Tag;
|
---|
637 | JobClicked();
|
---|
638 | }
|
---|
639 |
|
---|
640 | private void lvJobControl_MouseMove(object sender, MouseEventArgs e) {
|
---|
641 | if ((lvJobControl.GetItemAt(e.X, e.Y) != null) &&
|
---|
642 | (lvJobControl.GetItemAt(e.X, e.Y).ToolTipText != null)) {
|
---|
643 | tt.SetToolTip(lvJobControl, lvJobControl.GetItemAt(e.X, e.Y).ToolTipText);
|
---|
644 | }
|
---|
645 | }
|
---|
646 |
|
---|
647 | private void lvJobControl_MouseUp(object sender, MouseEventArgs e) {
|
---|
648 | // If the right mouse button was clicked and released,
|
---|
649 | // display the shortcut menu assigned to the ListView.
|
---|
650 | lvJobControl.ContextMenuStrip.Items.Clear();
|
---|
651 | ListViewHitTestInfo hitTestInfo = lvJobControl.HitTest(e.Location);
|
---|
652 | if (e.Button == MouseButtons.Right && hitTestInfo.Item != null && lvJobControl.SelectedItems.Count == 1) {
|
---|
653 | Job selectedJob = (Job)lvJobControl.SelectedItems[0].Tag;
|
---|
654 |
|
---|
655 | if (selectedJob != null && selectedJob.State == State.calculating) {
|
---|
656 | lvJobControl.ContextMenuStrip.Items.Add(menuItemAbortJob);
|
---|
657 | lvJobControl.ContextMenuStrip.Items.Add(menuItemGetSnapshot);
|
---|
658 | }
|
---|
659 | }
|
---|
660 | lvJobControl.ContextMenuStrip.Show(new Point(e.X, e.Y));
|
---|
661 | }
|
---|
662 |
|
---|
663 | private void tvClientControl_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {
|
---|
664 | lvClientControl.Items.Clear();
|
---|
665 | lvClientControl.Groups.Clear();
|
---|
666 | currentGroupNode = e.Node;
|
---|
667 | AddGroupsToListView(e.Node);
|
---|
668 | }
|
---|
669 |
|
---|
670 | private void groupToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
671 | AddGroup addgroup = new AddGroup();
|
---|
672 | parentgroup = Guid.Empty;
|
---|
673 | if ((tvClientControl.SelectedNode != null) && (((ClientGroup)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) {
|
---|
674 | parentgroup = ((ClientGroup)tvClientControl.SelectedNode.Tag).Id;
|
---|
675 | }
|
---|
676 | addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent);
|
---|
677 | addgroup.Show();
|
---|
678 | }
|
---|
679 |
|
---|
680 | private void projectToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
681 | AddProject addproject = new AddProject();
|
---|
682 | addproject.AddProjectEvent += new AddProjectDelegate(addproject_AddProjectEvent);
|
---|
683 | addproject.Show();
|
---|
684 | }
|
---|
685 |
|
---|
686 | private void OnLVClientClicked(object sender, EventArgs e) {
|
---|
687 | currentClient = (ClientInfo)lvClientControl.SelectedItems[0].Tag;
|
---|
688 | ClientClicked();
|
---|
689 | }
|
---|
690 |
|
---|
691 | private void tvClientControl_MouseUp(object sender, MouseEventArgs e) {
|
---|
692 | // If the right mouse button was clicked and released,
|
---|
693 | // display the shortcut menu assigned to the ListView.
|
---|
694 | contextMenuGroup.Items.Clear();
|
---|
695 | TreeViewHitTestInfo hitTestInfo = tvClientControl.HitTest(e.Location);
|
---|
696 | tvClientControl.SelectedNode = hitTestInfo.Node;
|
---|
697 | if (e.Button != MouseButtons.Right) return;
|
---|
698 | if (hitTestInfo.Node != null) {
|
---|
699 | Resource selectedGroup = (Resource)tvClientControl.SelectedNode.Tag;
|
---|
700 |
|
---|
701 | if (selectedGroup != null) {
|
---|
702 | contextMenuGroup.Items.Add(menuItemAddGroup);
|
---|
703 | contextMenuGroup.Items.Add(menuItemDeleteGroup);
|
---|
704 | }
|
---|
705 | } else {
|
---|
706 | contextMenuGroup.Items.Add(menuItemAddGroup);
|
---|
707 | }
|
---|
708 | tvClientControl.ContextMenuStrip.Show(tvClientControl, new Point(e.X, e.Y));
|
---|
709 | }
|
---|
710 |
|
---|
711 | private void addproject_AddProjectEvent(string name) {
|
---|
712 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
713 |
|
---|
714 | Project pg = new Project() { Name = name };
|
---|
715 | jobManager.CreateProject(pg);
|
---|
716 |
|
---|
717 | }
|
---|
718 |
|
---|
719 | private void addgroup_addGroupEvent(string name) {
|
---|
720 | IClientManager clientManager = ServiceLocator.GetClientManager();
|
---|
721 |
|
---|
722 | if (parentgroup != Guid.Empty) {
|
---|
723 | ClientGroup cg = new ClientGroup() { Name = name };
|
---|
724 | ResponseObject<ClientGroup> respcg = clientManager.AddClientGroup(cg);
|
---|
725 | Response res = clientManager.AddResourceToGroup(parentgroup, respcg.Obj);
|
---|
726 | if (res != null && !res.Success) {
|
---|
727 | MessageBox.Show(res.StatusMessage, "Error adding Group", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
728 | }
|
---|
729 | } else {
|
---|
730 | ClientGroup cg = new ClientGroup() { Name = name };
|
---|
731 | clientManager.AddClientGroup(cg);
|
---|
732 | }
|
---|
733 | AddClients();
|
---|
734 | }
|
---|
735 |
|
---|
736 |
|
---|
737 | private void Refresh_Click(object sender, EventArgs e) {
|
---|
738 | Form overlayingForm = new Form();
|
---|
739 |
|
---|
740 | overlayingForm.Show();
|
---|
741 | overlayingForm.FormBorderStyle = FormBorderStyle.None;
|
---|
742 | overlayingForm.BackColor = Color.Gray;
|
---|
743 | overlayingForm.Opacity = 0.4;
|
---|
744 | overlayingForm.Size = this.Size;
|
---|
745 | overlayingForm.Location = this.Location;
|
---|
746 |
|
---|
747 | //Label lbl = new Label();
|
---|
748 | //overlayingForm.Controls.Add(lbl);
|
---|
749 | //lbl.AutoSize = true;
|
---|
750 | //lbl.Text = "Loading";
|
---|
751 | //lbl.Name = "lblName";
|
---|
752 | //lbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
---|
753 | //lbl.ForeColor = Color.Black;
|
---|
754 | //lbl.BackColor = Color.Transparent;
|
---|
755 | //lbl.Location = new Point(overlayingForm.Width / 2, overlayingForm.Height / 2);
|
---|
756 |
|
---|
757 | AddClients();
|
---|
758 |
|
---|
759 | overlayingForm.Close();
|
---|
760 | }
|
---|
761 |
|
---|
762 | private void largeIconsToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
763 | lvClientControl.View = View.LargeIcon;
|
---|
764 | lvJobControl.View = View.LargeIcon;
|
---|
765 | largeIconsToolStripMenuItem.CheckState = CheckState.Checked;
|
---|
766 | smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
767 | listToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
768 | }
|
---|
769 |
|
---|
770 | private void smallIconsToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
771 | lvClientControl.View = View.SmallIcon;
|
---|
772 | lvJobControl.View = View.SmallIcon;
|
---|
773 | largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
774 | smallIconsToolStripMenuItem.CheckState = CheckState.Checked;
|
---|
775 | listToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
776 | }
|
---|
777 |
|
---|
778 | private void listToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
779 | lvClientControl.View = View.List;
|
---|
780 | lvJobControl.View = View.List;
|
---|
781 | largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
782 | smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
783 | listToolStripMenuItem.CheckState = CheckState.Checked;
|
---|
784 | }
|
---|
785 |
|
---|
786 | private void tvClientControl_DragLeave(object sender, EventArgs e) {
|
---|
787 | foreach (TreeNode node in tvClientControl.Nodes) {
|
---|
788 | node.BackColor = Color.White;
|
---|
789 | node.ForeColor = Color.Black;
|
---|
790 | }
|
---|
791 | }
|
---|
792 | #endregion
|
---|
793 |
|
---|
794 | #region Helper methods
|
---|
795 |
|
---|
796 | private void CloneList(ResponseList<Job> oldList, out IDictionary<int, Job> newList) {
|
---|
797 | newList = new Dictionary<int, Job>();
|
---|
798 | for (int i = 0; i < oldList.List.Count; i++) {
|
---|
799 | newList.Add(i, oldList.List[i]);
|
---|
800 | }
|
---|
801 | }
|
---|
802 |
|
---|
803 | private bool IsEqual(ClientInfo ci1, ClientInfo ci2) {
|
---|
804 | if (ci2 == null) {
|
---|
805 | return false;
|
---|
806 | }
|
---|
807 | if (ci1.Id.Equals(ci2.Id)) {
|
---|
808 | return true;
|
---|
809 | } else return false;
|
---|
810 | }
|
---|
811 |
|
---|
812 | private int CapacityRam(int noCores, int freeCores) {
|
---|
813 | if (noCores > 0) {
|
---|
814 | int capacity = ((noCores - freeCores) / noCores) * 100;
|
---|
815 | System.Diagnostics.Debug.WriteLine(capacity);
|
---|
816 | return capacity;
|
---|
817 | }
|
---|
818 | return 100;
|
---|
819 | }
|
---|
820 |
|
---|
821 | private void GetDelta(IList<Job> oldJobs, IDictionary<int, Job> helpJobs) {
|
---|
822 | bool found = false;
|
---|
823 | for (int i = 0; i < jobs.List.Count; i++) {
|
---|
824 | Job job = jobs.List[i];
|
---|
825 | for (int j = 0; j < oldJobs.Count; j++) {
|
---|
826 |
|
---|
827 | Job jobold = oldJobs[j];
|
---|
828 |
|
---|
829 | if (job.Id.Equals(jobold.Id)) {
|
---|
830 |
|
---|
831 | found = true;
|
---|
832 | bool change = false;
|
---|
833 | if (job.State != jobold.State) {
|
---|
834 | change = true;
|
---|
835 | }
|
---|
836 | if (job.State != State.offline) {
|
---|
837 | if ((!IsEqual(job.Client, jobold.Client)) || (job.State != jobold.State)
|
---|
838 | || (job.Percentage != jobold.Percentage)) {
|
---|
839 | change = true;
|
---|
840 | }
|
---|
841 | } else if (job.DateCalculated != jobold.DateCalculated) {
|
---|
842 | change = true;
|
---|
843 | }
|
---|
844 | if (change) {
|
---|
845 | changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Update, Position = i });
|
---|
846 | }
|
---|
847 |
|
---|
848 | int removeAt = -1;
|
---|
849 | foreach (KeyValuePair<int, Job> kvp in helpJobs) {
|
---|
850 | if (job.Id.Equals(kvp.Value.Id)) {
|
---|
851 | removeAt = kvp.Key;
|
---|
852 | break;
|
---|
853 | }
|
---|
854 | }
|
---|
855 | if (removeAt >= 0) {
|
---|
856 | helpJobs.Remove(removeAt);
|
---|
857 | }
|
---|
858 | break;
|
---|
859 | }
|
---|
860 |
|
---|
861 | }
|
---|
862 | if (found == false) {
|
---|
863 | changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Create });
|
---|
864 | System.Diagnostics.Debug.WriteLine("new Job: " + job.Id);
|
---|
865 | }
|
---|
866 | found = false;
|
---|
867 | }
|
---|
868 | foreach (KeyValuePair<int, Job> kvp in helpJobs) {
|
---|
869 | changes.Add(new Changes { Types = Type.Job, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key });
|
---|
870 | System.Diagnostics.Debug.WriteLine("delete Job: " + kvp.Value.Id);
|
---|
871 | }
|
---|
872 | }
|
---|
873 |
|
---|
874 | private void GetSnapshotList() {
|
---|
875 |
|
---|
876 | lvSnapshots.Items.Clear();
|
---|
877 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
878 |
|
---|
879 | ResponseList<JobResult> jobRes = jobManager.GetAllJobResults(currentJob.Id);
|
---|
880 |
|
---|
881 | if (jobRes.List != null) {
|
---|
882 | foreach (JobResult jobresult in jobRes.List) {
|
---|
883 | ListViewItem curSnapshot = new ListViewItem(jobresult.ClientId.ToString());
|
---|
884 | double percentage = jobresult.Percentage * 100;
|
---|
885 | curSnapshot.SubItems.Add(percentage.ToString() + " %");
|
---|
886 | curSnapshot.SubItems.Add(jobresult.Timestamp.ToString());
|
---|
887 | lvSnapshots.Items.Add(curSnapshot);
|
---|
888 | }
|
---|
889 | }
|
---|
890 |
|
---|
891 | if ((jobRes.List == null) && (jobRes.List.Count == 0)) {
|
---|
892 | lvSnapshots.Visible = false;
|
---|
893 | } else {
|
---|
894 | lvSnapshots.Visible = true;
|
---|
895 | }
|
---|
896 |
|
---|
897 | }
|
---|
898 |
|
---|
899 | #endregion
|
---|
900 |
|
---|
901 |
|
---|
902 |
|
---|
903 | }
|
---|
904 | } |
---|