Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1483 was 1483, checked in by aleitner, 16 years ago

merged brunch into trunk (#565)

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