Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1939 was 1939, checked in by svonolfe, 15 years ago

Large amounts of data are now transferred streamed (fixed ticket #660)

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