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 |
|
---|
47 | private Dictionary<Guid, ListViewGroup> clientObjects;
|
---|
48 | private Dictionary<Guid, ListViewItem> clientInfoObjects;
|
---|
49 | private Dictionary<Guid, ListViewItem> jobObjects;
|
---|
50 |
|
---|
51 | private Job currentJob = null;
|
---|
52 | private ClientInfo currentClient = null;
|
---|
53 | private string nameCurrentJob = "";
|
---|
54 | private string nameCurrentClient = "";
|
---|
55 | private bool flagJob = false;
|
---|
56 | private bool flagClient = false;
|
---|
57 |
|
---|
58 | private List<Changes> changes = new List<Changes>();
|
---|
59 |
|
---|
60 | private ToolTip tt = new ToolTip();
|
---|
61 | #endregion
|
---|
62 |
|
---|
63 | public HiveServerManagementConsole() {
|
---|
64 | InitializeComponent();
|
---|
65 | Init();
|
---|
66 | AddClients();
|
---|
67 | AddJobs();
|
---|
68 | timerSyncronize.Start();
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | #region Backgroundworker
|
---|
73 | /// <summary>
|
---|
74 | /// event on Ticker
|
---|
75 | /// </summary>
|
---|
76 | /// <param name="obj"></param>
|
---|
77 | /// <param name="e"></param>
|
---|
78 | private void TickSync(object obj, EventArgs e) {
|
---|
79 | if (!updaterWoker.IsBusy) {
|
---|
80 | updaterWoker.RunWorkerAsync();
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | private void updaterWoker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
85 | Refresh();
|
---|
86 | }
|
---|
87 |
|
---|
88 | #endregion
|
---|
89 |
|
---|
90 | private Guid ConvertStringToGuid(string stringGuid) {
|
---|
91 | Guid guid = Guid.Empty;
|
---|
92 | return (Guid)TypeDescriptor.GetConverter(guid).ConvertFrom(stringGuid);
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | private void Init() {
|
---|
97 |
|
---|
98 | //adding context menu items for jobs
|
---|
99 | menuItemAbortJob.Click += (s, e) => {
|
---|
100 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
101 | if (lvJobControl.SelectedItems.Count == 1) {
|
---|
102 | jobManager.AbortJob(ConvertStringToGuid(lvJobControl.SelectedItems[0].Text));
|
---|
103 | }
|
---|
104 | };
|
---|
105 |
|
---|
106 | menuItemGetSnapshot.Click += (s, e) => {
|
---|
107 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
108 | if (lvJobControl.SelectedItems.Count == 1) {
|
---|
109 | jobManager.RequestSnapshot(ConvertStringToGuid(lvJobControl.SelectedItems[0].Text));
|
---|
110 | }
|
---|
111 | };
|
---|
112 |
|
---|
113 | }
|
---|
114 |
|
---|
115 | private void lvJobControl_MouseUp(object sender, MouseEventArgs e) {
|
---|
116 | // If the right mouse button was clicked and released,
|
---|
117 | // display the shortcut menu assigned to the ListView.
|
---|
118 | lvJobControl.ContextMenuStrip.Items.Clear();
|
---|
119 | ListViewHitTestInfo hitTestInfo = lvJobControl.HitTest(e.Location);
|
---|
120 | if (e.Button == MouseButtons.Right && hitTestInfo.Item != null && lvJobControl.SelectedItems.Count == 1) {
|
---|
121 | Guid selectedJobGuid = ConvertStringToGuid(lvJobControl.SelectedItems[0].Text);
|
---|
122 | Job selectedJob = jobs.List.FirstOrDefault(x => x.Id == selectedJobGuid);
|
---|
123 |
|
---|
124 | if (selectedJob != null && selectedJob.State == State.calculating) {
|
---|
125 | lvJobControl.ContextMenuStrip.Items.Add(menuItemAbortJob);
|
---|
126 | lvJobControl.ContextMenuStrip.Items.Add(menuItemGetSnapshot);
|
---|
127 | }
|
---|
128 | }
|
---|
129 | lvJobControl.ContextMenuStrip.Show(new Point(e.X, e.Y));
|
---|
130 | }
|
---|
131 |
|
---|
132 | /// <summary>
|
---|
133 | /// Adds clients to ListView and TreeView
|
---|
134 | /// </summary>
|
---|
135 | private void AddClients() {
|
---|
136 | try {
|
---|
137 | clientObjects = new Dictionary<Guid, ListViewGroup>();
|
---|
138 | clientInfoObjects = new Dictionary<Guid, ListViewItem>();
|
---|
139 | IClientManager clientManager =
|
---|
140 | ServiceLocator.GetClientManager();
|
---|
141 |
|
---|
142 | clients = clientManager.GetAllClientGroups();
|
---|
143 | lvClientControl.Items.Clear();
|
---|
144 | List<Guid> inGroup = new List<Guid>();
|
---|
145 | foreach (ClientGroup cg in clients.List) {
|
---|
146 | ListViewGroup lvg = new ListViewGroup(cg.Name, HorizontalAlignment.Left);
|
---|
147 | foreach (ClientInfo ci in cg.Resources) {
|
---|
148 | ListViewItem item = null;
|
---|
149 | if ((ci.State == State.offline) || (ci.State == State.nullState)) {
|
---|
150 | item = new ListViewItem(ci.Name, 3, lvg);
|
---|
151 | } else {
|
---|
152 | int percentageUsage = CapacityRam(ci.NrOfCores, ci.NrOfFreeCores);
|
---|
153 | int usage = 0;
|
---|
154 | if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
|
---|
155 | usage = 0;
|
---|
156 | } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
|
---|
157 | usage = 1;
|
---|
158 | } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
|
---|
159 | usage = 2;
|
---|
160 | }
|
---|
161 |
|
---|
162 | item = new ListViewItem(ci.Name, usage, lvg);
|
---|
163 | }
|
---|
164 | item.Tag = ci.Id;
|
---|
165 | lvClientControl.Items.Add(item);
|
---|
166 | clientInfoObjects.Add(ci.Id, item);
|
---|
167 | inGroup.Add(ci.Id);
|
---|
168 |
|
---|
169 | }
|
---|
170 | lvClientControl.BeginUpdate();
|
---|
171 | lvClientControl.Groups.Add(lvg);
|
---|
172 | lvClientControl.EndUpdate();
|
---|
173 | clientObjects.Add(cg.Id, lvg);
|
---|
174 | } // Groups
|
---|
175 |
|
---|
176 | clientInfo = clientManager.GetAllClients();
|
---|
177 | ListViewGroup lvunsorted = new ListViewGroup("no group", HorizontalAlignment.Left);
|
---|
178 | foreach (ClientInfo ci in clientInfo.List) {
|
---|
179 | bool help = false;
|
---|
180 | foreach (Guid client in inGroup) {
|
---|
181 | if (client == ci.Id) {
|
---|
182 | help = true;
|
---|
183 | break;
|
---|
184 | }
|
---|
185 | }
|
---|
186 | if (!help) {
|
---|
187 | ListViewItem item = null;
|
---|
188 | if ((ci.State == State.offline) || (ci.State == State.nullState)) {
|
---|
189 | item = new ListViewItem(ci.Name, 3, lvunsorted);
|
---|
190 | } else {
|
---|
191 | int percentageUsage = CapacityRam(ci.NrOfCores, ci.NrOfFreeCores);
|
---|
192 | int usage = 0;
|
---|
193 | if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
|
---|
194 | usage = 0;
|
---|
195 | } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
|
---|
196 | usage = 1;
|
---|
197 | } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
|
---|
198 | usage = 2;
|
---|
199 | }
|
---|
200 | item = new ListViewItem(ci.Name, usage, lvunsorted);
|
---|
201 | }
|
---|
202 | item.Tag = ci.Id;
|
---|
203 | lvClientControl.Items.Add(item);
|
---|
204 | }
|
---|
205 | }
|
---|
206 | lvClientControl.BeginUpdate();
|
---|
207 | lvClientControl.Groups.Add(lvunsorted);
|
---|
208 | lvClientControl.EndUpdate();
|
---|
209 | if (flagClient) {
|
---|
210 | ClientClicked();
|
---|
211 | }
|
---|
212 | }
|
---|
213 | catch (Exception ex) {
|
---|
214 | closeFormEvent(true, true);
|
---|
215 | this.Close();
|
---|
216 | }
|
---|
217 | }
|
---|
218 |
|
---|
219 |
|
---|
220 | List<ListViewGroup> jobGroup;
|
---|
221 | /// <summary>
|
---|
222 | /// Adds jobs to ListView and TreeView
|
---|
223 | /// </summary>
|
---|
224 | private void AddJobs() {
|
---|
225 | try {
|
---|
226 | jobObjects = new Dictionary<Guid, ListViewItem>();
|
---|
227 | IJobManager jobManager =
|
---|
228 | ServiceLocator.GetJobManager();
|
---|
229 | jobs = jobManager.GetAllJobs();
|
---|
230 |
|
---|
231 | lvJobControl.Items.Clear();
|
---|
232 |
|
---|
233 | ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left);
|
---|
234 | ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left);
|
---|
235 | ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left);
|
---|
236 |
|
---|
237 | jobGroup = new List<ListViewGroup>();
|
---|
238 | jobGroup.Add(lvJobCalculating);
|
---|
239 | jobGroup.Add(lvJobFinished);
|
---|
240 | jobGroup.Add(lvJobPending);
|
---|
241 |
|
---|
242 | foreach (Job job in jobs.List) {
|
---|
243 | if (job.State == State.calculating) {
|
---|
244 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobCalculating);
|
---|
245 | jobObjects.Add(job.Id, lvi);
|
---|
246 |
|
---|
247 | //lvJobControl.Items.Add(lvi);
|
---|
248 |
|
---|
249 | lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated";
|
---|
250 | } else if (job.State == State.finished) {
|
---|
251 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobFinished);
|
---|
252 | jobObjects.Add(job.Id, lvi);
|
---|
253 | //lvJobControl.Items.Add(lvi);
|
---|
254 | } else if (job.State == State.offline) {
|
---|
255 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobPending);
|
---|
256 | jobObjects.Add(job.Id, lvi);
|
---|
257 | //lvJobControl.Items.Add(lvi);
|
---|
258 | }
|
---|
259 | } // Jobs
|
---|
260 | lvJobControl.BeginUpdate();
|
---|
261 | foreach (ListViewItem lvi in jobObjects.Values) {
|
---|
262 | lvJobControl.Items.Add(lvi);
|
---|
263 | }
|
---|
264 | lvJobControl.Groups.Add(lvJobCalculating);
|
---|
265 | lvJobControl.Groups.Add(lvJobFinished);
|
---|
266 | lvJobControl.Groups.Add(lvJobPending);
|
---|
267 | lvJobControl.EndUpdate();
|
---|
268 | if (flagJob) {
|
---|
269 | JobClicked();
|
---|
270 | }
|
---|
271 | }
|
---|
272 | catch (Exception ex) {
|
---|
273 | closeFormEvent(true, true);
|
---|
274 | this.Close();
|
---|
275 | }
|
---|
276 | }
|
---|
277 |
|
---|
278 | /// <summary>
|
---|
279 | /// if one client is clicked, the details for the clicked client are shown
|
---|
280 | /// in the second panel
|
---|
281 | /// </summary>
|
---|
282 | private void ClientClicked() {
|
---|
283 | plClientDetails.Visible = true;
|
---|
284 | int i = 0;
|
---|
285 | while (clientInfo.List[i].Id.ToString() != nameCurrentClient) {
|
---|
286 | i++;
|
---|
287 | }
|
---|
288 | currentClient = clientInfo.List[i];
|
---|
289 | int percentageUsage = CapacityRam(currentClient.NrOfCores, currentClient.NrOfFreeCores);
|
---|
290 | int usage = 3;
|
---|
291 | if ((currentClient.State != State.offline) && (currentClient.State != State.nullState)) {
|
---|
292 | if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
|
---|
293 | usage = 0;
|
---|
294 | } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
|
---|
295 | usage = 1;
|
---|
296 | } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
|
---|
297 | usage = 2;
|
---|
298 | }
|
---|
299 | }
|
---|
300 | pbClientControl.Image = ilLargeImgJob.Images[usage];
|
---|
301 | lblClientName.Text = currentClient.Name;
|
---|
302 | lblLogin.Text = currentClient.Login.ToString();
|
---|
303 | lblState.Text = currentClient.State.ToString();
|
---|
304 | }
|
---|
305 |
|
---|
306 | /// <summary>
|
---|
307 | /// if one job is clicked, the details for the clicked job are shown
|
---|
308 | /// in the second panel
|
---|
309 | /// </summary>
|
---|
310 | private void JobClicked() {
|
---|
311 | plJobDetails.Visible = true;
|
---|
312 | int i = 0;
|
---|
313 | while (jobs.List[i].Id.ToString() != nameCurrentJob) {
|
---|
314 | i++;
|
---|
315 | }
|
---|
316 | lvSnapshots.Enabled = true;
|
---|
317 | currentJob = jobs.List[i];
|
---|
318 | pbJobControl.Image = ilLargeImgClient.Images[0];
|
---|
319 | lblJobName.Text = currentJob.Id.ToString();
|
---|
320 | progressJob.Value = (int)(currentJob.Percentage * 100);
|
---|
321 | lblProgress.Text = (int)(currentJob.Percentage * 100) + "% calculated";
|
---|
322 | lblUserCreatedJob.Text = currentJob.UserId.ToString() + /* currentJob.User.Name + */ " created Job";
|
---|
323 | lblJobCreated.Text = "Created at " + currentJob.DateCreated;
|
---|
324 | if (currentJob.ParentJob != null) {
|
---|
325 | lblParentJob.Text = currentJob.ParentJob.Id + " is parent job";
|
---|
326 | } else {
|
---|
327 | lblParentJob.Text = "";
|
---|
328 | }
|
---|
329 | lblPriorityJob.Text = "Priority of job is " + currentJob.Priority;
|
---|
330 | if (currentJob.Client != null) {
|
---|
331 | lblClientCalculating.Text = currentJob.Client.Name + " calculated Job";
|
---|
332 | lblJobCalculationBegin.Text = "Startet calculation at " + currentJob.DateCalculated;
|
---|
333 |
|
---|
334 | if (currentJob.State == State.finished) {
|
---|
335 | IJobManager jobManager =
|
---|
336 | ServiceLocator.GetJobManager();
|
---|
337 | ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id, false);
|
---|
338 | lblJobCalculationEnd.Text = "Calculation ended at " + jobRes.Obj.DateFinished;
|
---|
339 | }
|
---|
340 | } else {
|
---|
341 | lblClientCalculating.Text = "";
|
---|
342 | lblJobCalculationBegin.Text = "";
|
---|
343 | lblJobCalculationEnd.Text = "";
|
---|
344 | }
|
---|
345 | if (currentJob.State != State.offline) {
|
---|
346 | lvSnapshots.Items.Clear();
|
---|
347 | if (currentJob.State == State.finished)
|
---|
348 | GetSnapshotList();
|
---|
349 | lvSnapshots.Visible = true;
|
---|
350 | } else {
|
---|
351 | lvSnapshots.Visible = false;
|
---|
352 | }
|
---|
353 | }
|
---|
354 |
|
---|
355 | private void Refresh() {
|
---|
356 | foreach (Changes change in changes) {
|
---|
357 | if (change.Types == Type.Job) {
|
---|
358 | RefreshJob(change);
|
---|
359 | } else if (change.Types == Type.Client) {
|
---|
360 | RefreshClient(change);
|
---|
361 | } else if (change.Types == Type.ClientGroup) {
|
---|
362 | RefreshClientGroup(change);
|
---|
363 | }
|
---|
364 | }
|
---|
365 | }
|
---|
366 |
|
---|
367 | private void RefreshJob(Changes change) {
|
---|
368 | if (change.ChangeType == Change.Update) {
|
---|
369 | for (int i = 0; i < lvJobControl.Items.Count; i++) {
|
---|
370 | if (lvJobControl.Items[i].Text == change.ID.ToString()) {
|
---|
371 | if (nameCurrentJob == change.ID.ToString()) {
|
---|
372 | JobClicked();
|
---|
373 | }
|
---|
374 | State state = jobs.List[change.Position].State;
|
---|
375 | System.Diagnostics.Debug.WriteLine(lvJobControl.Items[i].Text.ToString());
|
---|
376 | if (state == State.finished) {
|
---|
377 | lvJobControl.Items[i].Group = jobGroup[1];
|
---|
378 | System.Diagnostics.Debug.WriteLine("finished");
|
---|
379 | } else if (state == State.calculating) {
|
---|
380 | lvJobControl.Items[i].Group = jobGroup[0];
|
---|
381 | System.Diagnostics.Debug.WriteLine("calculating");
|
---|
382 | } else if (state == State.offline) {
|
---|
383 | lvJobControl.Items[i].Group = jobGroup[2];
|
---|
384 | System.Diagnostics.Debug.WriteLine("offline");
|
---|
385 |
|
---|
386 | }
|
---|
387 | lvJobControl.Refresh();
|
---|
388 | }
|
---|
389 | }
|
---|
390 | } else if (change.ChangeType == Change.Create) {
|
---|
391 | ListViewItem lvi = new ListViewItem(
|
---|
392 | change.ID.ToString(), 0, jobGroup[2]);
|
---|
393 | jobObjects.Add(change.ID, lvi);
|
---|
394 | lvJobControl.Items.Add(lvi);
|
---|
395 |
|
---|
396 | } else if (change.ChangeType == Change.Delete) {
|
---|
397 | jobObjects.Remove(change.ID);
|
---|
398 | for (int i = 0; i < lvJobControl.Items.Count; i++) {
|
---|
399 | if (change.ID.ToString() == lvJobControl.Items[i].Text.ToString()) {
|
---|
400 | lvJobControl.Items[i].Remove();
|
---|
401 | break;
|
---|
402 | }
|
---|
403 | }
|
---|
404 | }
|
---|
405 | }
|
---|
406 |
|
---|
407 | private void RefreshClient(Changes change) {
|
---|
408 | if (change.ChangeType == Change.Update) {
|
---|
409 | for (int i = 0; i < lvClientControl.Items.Count; i++) {
|
---|
410 | if (lvClientControl.Items[i].Tag.ToString() == change.ID.ToString()) {
|
---|
411 | if (nameCurrentClient == change.ID.ToString()) {
|
---|
412 | ClientClicked();
|
---|
413 | }
|
---|
414 | State state = clientInfo.List[change.Position].State;
|
---|
415 | System.Diagnostics.Debug.WriteLine(lvClientControl.Items[i].Text.ToString());
|
---|
416 |
|
---|
417 | ClientInfo ci = null;
|
---|
418 |
|
---|
419 | foreach (ClientInfo c in clientInfo.List) {
|
---|
420 | if (c.Id == change.ID) {
|
---|
421 | ci = c;
|
---|
422 | }
|
---|
423 | }
|
---|
424 |
|
---|
425 | int percentageUsage = CapacityRam(ci.NrOfCores, ci.NrOfFreeCores);
|
---|
426 | if ((state == State.offline) || (state == State.nullState)) {
|
---|
427 | lvClientControl.Items[i].ImageIndex = 3;
|
---|
428 | } else {
|
---|
429 | if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
|
---|
430 | lvClientControl.Items[i].ImageIndex = 0;
|
---|
431 | } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
|
---|
432 | lvClientControl.Items[i].ImageIndex = 1;
|
---|
433 | } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
|
---|
434 | lvClientControl.Items[i].ImageIndex = 2;
|
---|
435 | }
|
---|
436 |
|
---|
437 | }
|
---|
438 | lvClientControl.Refresh();
|
---|
439 | }
|
---|
440 | }
|
---|
441 |
|
---|
442 |
|
---|
443 | } else if (change.ChangeType == Change.Create) {
|
---|
444 |
|
---|
445 | } else if (change.ChangeType == Change.Delete) {
|
---|
446 | clientInfoObjects.Remove(change.ID);
|
---|
447 | for (int i = 0; i < lvClientControl.Items.Count; i++) {
|
---|
448 | if (change.ID.ToString() == lvClientControl.Items[i].Text.ToString()) {
|
---|
449 | lvClientControl.Items[i].Remove();
|
---|
450 | break;
|
---|
451 | }
|
---|
452 | }
|
---|
453 |
|
---|
454 | }
|
---|
455 | }
|
---|
456 |
|
---|
457 | private void RefreshClientGroup(Changes change) {
|
---|
458 |
|
---|
459 | }
|
---|
460 |
|
---|
461 | #region Eventhandlers
|
---|
462 | /// <summary>
|
---|
463 | /// Send event to Login-GUI when closing
|
---|
464 | /// </summary>
|
---|
465 | /// <param name="sender"></param>
|
---|
466 | /// <param name="e"></param>
|
---|
467 | private void Close_Click(object sender, EventArgs e) {
|
---|
468 | if (closeFormEvent != null) {
|
---|
469 | closeFormEvent(true, false);
|
---|
470 | }
|
---|
471 | this.Close();
|
---|
472 | }
|
---|
473 |
|
---|
474 | /// <summary>
|
---|
475 | /// Send evnt to Login-GUI when closing
|
---|
476 | /// </summary>
|
---|
477 | /// <param name="sender"></param>
|
---|
478 | /// <param name="e"></param>
|
---|
479 | private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
|
---|
480 | if (closeFormEvent != null) {
|
---|
481 | closeFormEvent(true, false);
|
---|
482 | }
|
---|
483 | }
|
---|
484 |
|
---|
485 | private void AddJob_Click(object sender, EventArgs e) {
|
---|
486 | AddJobForm newForm = new AddJobForm();
|
---|
487 | newForm.Show();
|
---|
488 | newForm.addJobEvent += new addDelegate(updaterWoker.RunWorkerAsync);
|
---|
489 | }
|
---|
490 |
|
---|
491 | private void OnLVClientClicked(object sender, EventArgs e) {
|
---|
492 | nameCurrentClient = lvClientControl.SelectedItems[0].Tag.ToString();
|
---|
493 | flagClient = true;
|
---|
494 | ClientClicked();
|
---|
495 | }
|
---|
496 |
|
---|
497 | private void OnLVJobControlClicked(object sender, EventArgs e) {
|
---|
498 | nameCurrentJob = lvJobControl.SelectedItems[0].Text;
|
---|
499 | flagJob = true;
|
---|
500 | JobClicked();
|
---|
501 | }
|
---|
502 |
|
---|
503 | private void lvJobControl_MouseMove(object sender, MouseEventArgs e) {
|
---|
504 | if ((lvJobControl.GetItemAt(e.X, e.Y) != null) &&
|
---|
505 | (lvJobControl.GetItemAt(e.X, e.Y).ToolTipText != null)) {
|
---|
506 | tt.SetToolTip(lvJobControl, lvJobControl.GetItemAt(e.X, e.Y).ToolTipText);
|
---|
507 | }
|
---|
508 | }
|
---|
509 |
|
---|
510 | private void updaterWoker_DoWork(object sender, DoWorkEventArgs e) {
|
---|
511 |
|
---|
512 | changes.Clear();
|
---|
513 | IClientManager clientManager =
|
---|
514 | ServiceLocator.GetClientManager();
|
---|
515 |
|
---|
516 | #region ClientInfo
|
---|
517 | ResponseList<ClientInfo> clientInfoOld = clientInfo;
|
---|
518 | clientInfo = clientManager.GetAllClients();
|
---|
519 |
|
---|
520 | IDictionary<int, ClientInfo> clientInfoOldHelp;
|
---|
521 |
|
---|
522 | CloneList(clientInfoOld, out clientInfoOldHelp);
|
---|
523 |
|
---|
524 | GetDelta(clientInfoOld.List, clientInfoOldHelp);
|
---|
525 | #endregion
|
---|
526 |
|
---|
527 | #region Clients
|
---|
528 | ResponseList<ClientGroup> clientsOld = clients;
|
---|
529 |
|
---|
530 | clients = clientManager.GetAllClientGroups();
|
---|
531 |
|
---|
532 | IDictionary<int, ClientGroup> clientsOldHelp;
|
---|
533 |
|
---|
534 | CloneList(clientsOld, out clientsOldHelp);
|
---|
535 |
|
---|
536 | GetDelta(clientsOld.List, clientsOldHelp);
|
---|
537 | #endregion
|
---|
538 |
|
---|
539 | #region Job
|
---|
540 | ResponseList<Job> jobsOld = jobs;
|
---|
541 | IJobManager jobManager =
|
---|
542 | ServiceLocator.GetJobManager();
|
---|
543 |
|
---|
544 | jobs = jobManager.GetAllJobs();
|
---|
545 |
|
---|
546 | IDictionary<int, Job> jobsOldHelp;
|
---|
547 | CloneList(jobsOld, out jobsOldHelp);
|
---|
548 |
|
---|
549 | GetDelta(jobsOld.List, jobsOldHelp);
|
---|
550 |
|
---|
551 | #endregion
|
---|
552 |
|
---|
553 | foreach (Changes change in changes) {
|
---|
554 | System.Diagnostics.Debug.WriteLine(change.ID + " " + change.ChangeType);
|
---|
555 | }
|
---|
556 |
|
---|
557 | }
|
---|
558 | #endregion
|
---|
559 |
|
---|
560 | #region Helper methods
|
---|
561 |
|
---|
562 | private void CloneList(ResponseList<Job> oldList, out IDictionary<int, Job> newList) {
|
---|
563 | newList = new Dictionary<int, Job>();
|
---|
564 | for (int i = 0; i < oldList.List.Count; i++) {
|
---|
565 | newList.Add(i, oldList.List[i]);
|
---|
566 | }
|
---|
567 | }
|
---|
568 |
|
---|
569 | private void CloneList(ResponseList<ClientInfo> oldList, out IDictionary<int, ClientInfo> newList) {
|
---|
570 | newList = new Dictionary<int, ClientInfo>();
|
---|
571 | for (int i = 0; i < oldList.List.Count; i++) {
|
---|
572 | newList.Add(i, oldList.List[i]);
|
---|
573 | }
|
---|
574 | }
|
---|
575 |
|
---|
576 | private void CloneList(ResponseList<ClientGroup> oldList, out IDictionary<int, ClientGroup> newList) {
|
---|
577 | newList = new Dictionary<int, ClientGroup>();
|
---|
578 | for (int i = 0; i < oldList.List.Count; i++) {
|
---|
579 | newList.Add(i, oldList.List[i]);
|
---|
580 | }
|
---|
581 | }
|
---|
582 |
|
---|
583 | private bool IsEqual(ClientInfo ci1, ClientInfo ci2) {
|
---|
584 | if (ci2 == null) {
|
---|
585 | return false;
|
---|
586 | }
|
---|
587 | if (ci1.Id.Equals(ci2.Id)) {
|
---|
588 | return true;
|
---|
589 | } else return false;
|
---|
590 | }
|
---|
591 |
|
---|
592 | private int CapacityRam(int noCores, int freeCores) {
|
---|
593 | int capacity = ((noCores - freeCores) / noCores) * 100;
|
---|
594 | System.Diagnostics.Debug.WriteLine(capacity);
|
---|
595 | return capacity;
|
---|
596 | }
|
---|
597 |
|
---|
598 | private void GetDelta(IList<ClientInfo> oldClient, IDictionary<int, ClientInfo> helpClients) {
|
---|
599 | bool found = false;
|
---|
600 |
|
---|
601 | for (int i = 0; i < clientInfo.List.Count; i++) {
|
---|
602 | ClientInfo ci = clientInfo.List[i];
|
---|
603 | for (int j = 0; j < oldClient.Count; j++) {
|
---|
604 | ClientInfo cio = oldClient[j];
|
---|
605 | if (ci.Id.Equals(cio.Id)) {
|
---|
606 | found = true;
|
---|
607 | if ((ci.State != cio.State) || (ci.NrOfFreeCores != cio.NrOfFreeCores)) {
|
---|
608 | changes.Add(new Changes { Types = Type.Client, ID = ci.Id, ChangeType = Change.Update, Position = i });
|
---|
609 | }
|
---|
610 | int removeAt = -1;
|
---|
611 | foreach (KeyValuePair<int, ClientInfo> kvp in helpClients) {
|
---|
612 | if (cio.Id.Equals(kvp.Value.Id)) {
|
---|
613 | removeAt = kvp.Key;
|
---|
614 | break;
|
---|
615 | }
|
---|
616 | }
|
---|
617 | if (removeAt >= 0) {
|
---|
618 | helpClients.Remove(removeAt);
|
---|
619 | }
|
---|
620 | break;
|
---|
621 | }
|
---|
622 | }
|
---|
623 | if (found == false) {
|
---|
624 | changes.Add(new Changes { Types = Type.Client, ID = ci.Id, ChangeType = Change.Create });
|
---|
625 | }
|
---|
626 | found = false;
|
---|
627 | }
|
---|
628 | foreach (KeyValuePair<int, ClientInfo> kvp in helpClients) {
|
---|
629 | changes.Add(new Changes { Types = Type.Client, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key });
|
---|
630 | }
|
---|
631 |
|
---|
632 | }
|
---|
633 |
|
---|
634 | private void GetDelta(IList<ClientGroup> oldClient, IDictionary<int, ClientGroup> helpClients) {
|
---|
635 |
|
---|
636 | bool found = false;
|
---|
637 | for (int i = 0; i < clients.List.Count; i++) {
|
---|
638 | ClientGroup cg = clients.List[i];
|
---|
639 | for (int j = 0; j < oldClient.Count; i++) {
|
---|
640 | ClientGroup cgo = oldClient[j];
|
---|
641 | if (cg.Id.Equals(cgo.Id)) {
|
---|
642 | found = true;
|
---|
643 | foreach (Resource resource in cg.Resources) {
|
---|
644 | foreach (Resource resourceold in cgo.Resources) {
|
---|
645 | if (resource.Id.Equals(resourceold.Id)) {
|
---|
646 | if (resourceold.Name != resource.Name) {
|
---|
647 | changes.Add(new Changes { Types = Type.Client, ID = cg.Id, ChangeType = Change.Update, Position = i });
|
---|
648 | }
|
---|
649 | }
|
---|
650 | }
|
---|
651 | }
|
---|
652 | for (int k = 0; k < helpClients.Count; k++) {
|
---|
653 | if (cgo.Id.Equals(helpClients[k].Id)) {
|
---|
654 | helpClients.Remove(k);
|
---|
655 | break;
|
---|
656 | }
|
---|
657 | }
|
---|
658 | break;
|
---|
659 | }
|
---|
660 | }
|
---|
661 | if (found == false) {
|
---|
662 | changes.Add(new Changes { Types = Type.ClientGroup, ID = cg.Id, ChangeType = Change.Create });
|
---|
663 | }
|
---|
664 | found = false;
|
---|
665 | }
|
---|
666 | foreach (KeyValuePair<int, ClientGroup> kvp in helpClients) {
|
---|
667 | changes.Add(new Changes { Types = Type.ClientGroup, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key });
|
---|
668 | }
|
---|
669 | }
|
---|
670 |
|
---|
671 | private void GetDelta(IList<Job> oldJobs, IDictionary<int, Job> helpJobs) {
|
---|
672 | bool found = false;
|
---|
673 | for (int i = 0; i < jobs.List.Count; i++) {
|
---|
674 | Job job = jobs.List[i];
|
---|
675 | for (int j = 0; j < oldJobs.Count; j++) {
|
---|
676 |
|
---|
677 | Job jobold = oldJobs[j];
|
---|
678 |
|
---|
679 | if (job.Id.Equals(jobold.Id)) {
|
---|
680 |
|
---|
681 | found = true;
|
---|
682 | if (job.State != State.offline) {
|
---|
683 | if ((!IsEqual(job.Client, jobold.Client)) || (job.State != jobold.State)
|
---|
684 | || (job.Percentage != jobold.Percentage)) {
|
---|
685 | changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Update, Position = i });
|
---|
686 | }
|
---|
687 | } else if (job.DateCalculated != jobold.DateCalculated) {
|
---|
688 | changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Update, Position = i });
|
---|
689 | }
|
---|
690 |
|
---|
691 | int removeAt = -1;
|
---|
692 | foreach (KeyValuePair<int, Job> kvp in helpJobs) {
|
---|
693 | if (job.Id.Equals(kvp.Value.Id)) {
|
---|
694 | removeAt = kvp.Key;
|
---|
695 | break;
|
---|
696 | }
|
---|
697 | }
|
---|
698 | if (removeAt >= 0) {
|
---|
699 | helpJobs.Remove(removeAt);
|
---|
700 | }
|
---|
701 | break;
|
---|
702 | }
|
---|
703 |
|
---|
704 | }
|
---|
705 | if (found == false) {
|
---|
706 | changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Create });
|
---|
707 | System.Diagnostics.Debug.WriteLine("new Job: " + job.Id);
|
---|
708 | }
|
---|
709 | found = false;
|
---|
710 | }
|
---|
711 | foreach (KeyValuePair<int, Job> kvp in helpJobs) {
|
---|
712 | changes.Add(new Changes { Types = Type.Job, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key });
|
---|
713 | System.Diagnostics.Debug.WriteLine("delete Job: " + kvp.Value.Id);
|
---|
714 | }
|
---|
715 | }
|
---|
716 |
|
---|
717 | private void GetSnapshotList() {
|
---|
718 |
|
---|
719 | lvSnapshots.Items.Clear();
|
---|
720 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
721 |
|
---|
722 | ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id, false);
|
---|
723 |
|
---|
724 | // iterate threw all snapshots if method is implemented
|
---|
725 |
|
---|
726 | ListViewItem curSnapshot = new ListViewItem(jobRes.Obj.Client.Name);
|
---|
727 | double percentage = jobRes.Obj.Percentage * 100;
|
---|
728 | curSnapshot.SubItems.Add(percentage.ToString() + " %");
|
---|
729 | curSnapshot.SubItems.Add(jobRes.Obj.Timestamp.ToString());
|
---|
730 | lvSnapshots.Items.Add(curSnapshot);
|
---|
731 | }
|
---|
732 |
|
---|
733 | #endregion
|
---|
734 |
|
---|
735 | private void largeIconsToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
736 | lvClientControl.View = View.LargeIcon;
|
---|
737 | lvJobControl.View = View.LargeIcon;
|
---|
738 | largeIconsToolStripMenuItem.CheckState = CheckState.Checked;
|
---|
739 | smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
740 | listToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
741 | }
|
---|
742 |
|
---|
743 | private void smallIconsToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
744 | lvClientControl.View = View.SmallIcon;
|
---|
745 | lvJobControl.View = View.SmallIcon;
|
---|
746 | largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
747 | smallIconsToolStripMenuItem.CheckState = CheckState.Checked;
|
---|
748 | listToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
749 | }
|
---|
750 |
|
---|
751 | private void listToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
752 | lvClientControl.View = View.List;
|
---|
753 | lvJobControl.View = View.List;
|
---|
754 | largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
755 | smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
756 | listToolStripMenuItem.CheckState = CheckState.Checked;
|
---|
757 | }
|
---|
758 |
|
---|
759 |
|
---|
760 |
|
---|
761 |
|
---|
762 | }
|
---|
763 | } |
---|