Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Console/3.2/HiveServerManagementConsole.cs @ 1626

Last change on this file since 1626 was 1626, checked in by msteinbi, 15 years ago

renamed timestamp to Timestamp (#466)

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