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
RevLine 
[794]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;
[831]30using HeuristicLab.Hive.Contracts.Interfaces;
31using HeuristicLab.Hive.Contracts.BusinessObjects;
[904]32using HeuristicLab.Hive.Contracts;
[794]33
[1089]34namespace HeuristicLab.Hive.Server.ServerConsole {
[794]35
[1030]36  public delegate void closeForm(bool cf, bool error);
[794]37
38  public partial class HiveServerManagementConsole : Form {
39
40    public event closeForm closeFormEvent;
41
[1136]42    #region private variables
43    private ResponseList<ClientGroup> clients = null;
44    private ResponseList<ClientInfo> clientInfo = null;
45    private ResponseList<Job> jobs = null;
[844]46
[1449]47    private Dictionary<Guid, ListViewGroup> clientObjects;
48    private Dictionary<Guid, ListViewItem> clientInfoObjects;
49    private Dictionary<Guid, ListViewItem> jobObjects;
[1261]50
[1136]51    private Job currentJob = null;
52    private ClientInfo currentClient = null;
[1148]53    private string nameCurrentJob = "";
54    private string nameCurrentClient = "";
[1136]55    private bool flagJob = false;
56    private bool flagClient = false;
[1098]57
[1483]58    private List<Changes> changes = new List<Changes>();
59
[1136]60    private ToolTip tt = new ToolTip();
61    #endregion
62
[794]63    public HiveServerManagementConsole() {
64      InitializeComponent();
[1598]65      Init();
[1037]66      AddClients();
67      AddJobs();
[1018]68      timerSyncronize.Start();
[844]69    }
[831]70
[1590]71
72    #region Backgroundworker
[1136]73    /// <summary>
74    /// event on Ticker
75    /// </summary>
76    /// <param name="obj"></param>
77    /// <param name="e"></param>
[1267]78    private void TickSync(object obj, EventArgs e) {
[1483]79      if (!updaterWoker.IsBusy) {
80        updaterWoker.RunWorkerAsync();
81      }
[1018]82    }
83
[1581]84    private void updaterWoker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
85      Refresh();
86    }
[1512]87
[1590]88    #endregion
[1512]89
[1598]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
[1136]121    /// <summary>
122    /// Adds clients to ListView and TreeView
123    /// </summary>
[1037]124    private void AddClients() {
[1030]125      try {
[1449]126        clientObjects = new Dictionary<Guid, ListViewGroup>();
127        clientInfoObjects = new Dictionary<Guid, ListViewItem>();
[1030]128        IClientManager clientManager =
129          ServiceLocator.GetClientManager();
[831]130
[1030]131        clients = clientManager.GetAllClientGroups();
132        lvClientControl.Items.Clear();
[1483]133        List<Guid> inGroup = new List<Guid>();
[1030]134        foreach (ClientGroup cg in clients.List) {
135          ListViewGroup lvg = new ListViewGroup(cg.Name, HorizontalAlignment.Left);
[1483]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 {
[1590]141              int percentageUsage = CapacityRam(ci.NrOfCores, ci.NrOfFreeCores);
[1512]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);
[1483]152            }
153            item.Tag = ci.Id;
[1261]154            lvClientControl.Items.Add(item);
155            clientInfoObjects.Add(ci.Id, item);
[1483]156            inGroup.Add(ci.Id);
[1495]157
[1030]158          }
[1483]159          lvClientControl.BeginUpdate();
[1030]160          lvClientControl.Groups.Add(lvg);
[1483]161          lvClientControl.EndUpdate();
[1261]162          clientObjects.Add(cg.Id, lvg);
[1030]163        } // Groups
164
165        clientInfo = clientManager.GetAllClients();
[1483]166        ListViewGroup lvunsorted = new ListViewGroup("no group", HorizontalAlignment.Left);
[1030]167        foreach (ClientInfo ci in clientInfo.List) {
[1483]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 {
[1512]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);
[1483]190            }
191            item.Tag = ci.Id;
192            lvClientControl.Items.Add(item);
193          }
[831]194        }
[1483]195        lvClientControl.BeginUpdate();
[1030]196        lvClientControl.Groups.Add(lvunsorted);
[1483]197        lvClientControl.EndUpdate();
[1136]198        if (flagClient) {
199          ClientClicked();
200        }
[1018]201      }
[1030]202      catch (Exception ex) {
203        closeFormEvent(true, true);
204        this.Close();
205      }
[1018]206    }
[956]207
[1483]208
209    List<ListViewGroup> jobGroup;
[1136]210    /// <summary>
211    /// Adds jobs to ListView and TreeView
212    /// </summary>
[1037]213    private void AddJobs() {
[1030]214      try {
[1449]215        jobObjects = new Dictionary<Guid, ListViewItem>();
[1030]216        IJobManager jobManager =
217          ServiceLocator.GetJobManager();
218        jobs = jobManager.GetAllJobs();
[1018]219
[1030]220        lvJobControl.Items.Clear();
[1018]221
[1037]222        ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left);
[1030]223        ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left);
[1037]224        ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left);
[1483]225
226        jobGroup = new List<ListViewGroup>();
227        jobGroup.Add(lvJobCalculating);
228        jobGroup.Add(lvJobFinished);
229        jobGroup.Add(lvJobPending);
[1495]230
[1030]231        foreach (Job job in jobs.List) {
[1037]232          if (job.State == State.calculating) {
[1126]233            ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobCalculating);
[1261]234            jobObjects.Add(job.Id, lvi);
[1483]235
236            //lvJobControl.Items.Add(lvi);
[1495]237
[1126]238            lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated";
[1037]239          } else if (job.State == State.finished) {
[1126]240            ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobFinished);
[1261]241            jobObjects.Add(job.Id, lvi);
[1483]242            //lvJobControl.Items.Add(lvi);
[1030]243          } else if (job.State == State.offline) {
[1126]244            ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobPending);
[1261]245            jobObjects.Add(job.Id, lvi);
[1483]246            //lvJobControl.Items.Add(lvi);
[1030]247          }
248        } // Jobs
[1483]249        lvJobControl.BeginUpdate();
250        foreach (ListViewItem lvi in jobObjects.Values) {
251          lvJobControl.Items.Add(lvi);
252        }
[1037]253        lvJobControl.Groups.Add(lvJobCalculating);
[1030]254        lvJobControl.Groups.Add(lvJobFinished);
[1037]255        lvJobControl.Groups.Add(lvJobPending);
[1483]256        lvJobControl.EndUpdate();
[1136]257        if (flagJob) {
258          JobClicked();
259        }
[1030]260      }
261      catch (Exception ex) {
262        closeFormEvent(true, true);
263        this.Close();
264      }
[1018]265    }
266
[1136]267    /// <summary>
[1581]268    /// if one client is clicked, the details for the clicked client are shown
269    /// in the second panel
[1136]270    /// </summary>
271    private void ClientClicked() {
[1512]272      plClientDetails.Visible = true;
[1148]273      int i = 0;
[1495]274      while (clientInfo.List[i].Id.ToString() != nameCurrentClient) {
[1148]275        i++;
276      }
277      currentClient = clientInfo.List[i];
[1512]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];
[1136]290      lblClientName.Text = currentClient.Name;
291      lblLogin.Text = currentClient.Login.ToString();
[1164]292      lblState.Text = currentClient.State.ToString();
[1136]293    }
294
295    /// <summary>
[1581]296    /// if one job is clicked, the details for the clicked job are shown
297    /// in the second panel
[1136]298    /// </summary>
299    private void JobClicked() {
[1512]300      plJobDetails.Visible = true;
[1148]301      int i = 0;
302      while (jobs.List[i].Id.ToString() != nameCurrentJob) {
303        i++;
304      }
[1512]305      lvSnapshots.Enabled = true;
[1148]306      currentJob = jobs.List[i];
[1136]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";
[1495]311      lblUserCreatedJob.Text = currentJob.UserId.ToString() + /* currentJob.User.Name + */ " created Job";
[1173]312      lblJobCreated.Text = "Created at " + currentJob.DateCreated;
[1136]313      if (currentJob.ParentJob != null) {
314        lblParentJob.Text = currentJob.ParentJob.Id + " is parent job";
[1495]315      } else {
316        lblParentJob.Text = "";
[1136]317      }
[1173]318      lblPriorityJob.Text = "Priority of job is " + currentJob.Priority;
[1136]319      if (currentJob.Client != null) {
320        lblClientCalculating.Text = currentJob.Client.Name + " calculated Job";
[1495]321        lblJobCalculationBegin.Text = "Startet calculation at " + currentJob.DateCalculated;
322
[1173]323        if (currentJob.State == State.finished) {
324          IJobManager jobManager =
325            ServiceLocator.GetJobManager();
[1509]326          ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id, false);
[1173]327          lblJobCalculationEnd.Text = "Calculation ended at " + jobRes.Obj.DateFinished;
328        }
[1495]329      } else {
330        lblClientCalculating.Text = "";
331        lblJobCalculationBegin.Text = "";
332        lblJobCalculationEnd.Text = "";
333      }
[1173]334      if (currentJob.State != State.offline) {
[1590]335        lvSnapshots.Items.Clear();
336        if (currentJob.State == State.finished)
337          GetSnapshotList();
[1512]338        lvSnapshots.Visible = true;
[1495]339      } else {
[1512]340        lvSnapshots.Visible = false;
[1148]341      }
[1136]342    }
343
[1483]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) {
[1590]349          RefreshClient(change);
[1483]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()) {
[1495]360            if (nameCurrentJob == change.ID.ToString()) {
361              JobClicked();
362            }
[1483]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()) {
[1495]400            if (nameCurrentClient == change.ID.ToString()) {
401              ClientClicked();
402            }
[1483]403            State state = clientInfo.List[change.Position].State;
404            System.Diagnostics.Debug.WriteLine(lvClientControl.Items[i].Text.ToString());
[1595]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);
[1483]415            if ((state == State.offline) || (state == State.nullState)) {
416              lvClientControl.Items[i].ImageIndex = 3;
417            } else {
[1512]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
[1483]426            }
427            lvClientControl.Refresh();
428          }
429        }
430
431
432      } else if (change.ChangeType == Change.Create) {
[1495]433
[1483]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
[1148]450    #region Eventhandlers
[1136]451    /// <summary>
[794]452    /// Send event to Login-GUI when closing
453    /// </summary>
454    /// <param name="sender"></param>
455    /// <param name="e"></param>
[1037]456    private void Close_Click(object sender, EventArgs e) {
[794]457      if (closeFormEvent != null) {
[1030]458        closeFormEvent(true, false);
[794]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) {
[1030]470        closeFormEvent(true, false);
[794]471      }
472    }
[956]473
[1136]474    private void AddJob_Click(object sender, EventArgs e) {
[1018]475      AddJobForm newForm = new AddJobForm();
[956]476      newForm.Show();
[1581]477      newForm.addJobEvent += new addDelegate(updaterWoker.RunWorkerAsync);
[956]478    }
479
[1098]480    private void OnLVClientClicked(object sender, EventArgs e) {
[1495]481      nameCurrentClient = lvClientControl.SelectedItems[0].Tag.ToString();
[1136]482      flagClient = true;
[1098]483      ClientClicked();
484    }
485
[1136]486    private void OnLVJobControlClicked(object sender, EventArgs e) {
[1148]487      nameCurrentJob = lvJobControl.SelectedItems[0].Text;
[1136]488      flagJob = true;
489      JobClicked();
[1098]490    }
491
[1126]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    }
[1261]498
499    private void updaterWoker_DoWork(object sender, DoWorkEventArgs e) {
[1483]500
[1495]501      changes.Clear();
[1261]502      IClientManager clientManager =
503          ServiceLocator.GetClientManager();
[1495]504
[1483]505      #region ClientInfo
506      ResponseList<ClientInfo> clientInfoOld = clientInfo;
[1261]507      clientInfo = clientManager.GetAllClients();
[1483]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;
[1495]518
[1483]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>();
[1495]560      for (int i = 0; i < oldList.List.Count; i++) {
[1483]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
[1590]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
[1483]587    private void GetDelta(IList<ClientInfo> oldClient, IDictionary<int, ClientInfo> helpClients) {
588      bool found = false;
589
[1495]590      for (int i = 0; i < clientInfo.List.Count; i++) {
[1483]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;
[1595]596            if ((ci.State != cio.State) || (ci.NrOfFreeCores != cio.NrOfFreeCores)) {
[1483]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          }
[1261]611        }
[1483]612        if (found == false) {
613          changes.Add(new Changes { Types = Type.Client, ID = ci.Id, ChangeType = Change.Create });
614        }
615        found = false;
[1261]616      }
[1483]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
[1261]621    }
[1483]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;
[1495]662      for (int i = 0; i < jobs.List.Count; i++) {
[1483]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) {
[1590]672              if ((!IsEqual(job.Client, jobold.Client)) || (job.State != jobold.State)
[1512]673                   || (job.Percentage != jobold.Percentage)) {
[1483]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
[1581]706    private void GetSnapshotList() {
[1483]707
[1581]708      lvSnapshots.Items.Clear();
[1590]709      IJobManager jobManager = ServiceLocator.GetJobManager();
710
[1581]711      ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id, false);
[1590]712
713      // iterate threw all snapshots if method is implemented
714
[1581]715      ListViewItem curSnapshot = new ListViewItem(jobRes.Obj.Client.Name);
716      double percentage = jobRes.Obj.Percentage * 100;
717      curSnapshot.SubItems.Add(percentage.ToString() + " %");
[1626]718      curSnapshot.SubItems.Add(jobRes.Obj.Timestamp.ToString());
[1581]719      lvSnapshots.Items.Add(curSnapshot);
[1483]720    }
721
[1581]722    #endregion
[1483]723
[1598]724
725
726
[794]727  }
[844]728}
Note: See TracBrowser for help on using the repository browser.