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