Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1956 was 1956, checked in by aleitner, 15 years ago

Adding job with project and groups
new project can be created
(#626)

File size: 27.3 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.Project != null) {
379        lvi = null;
380        lvi = new ListViewItem();
381        lvi.Text = "Project:";
382        lvi.SubItems.Add(currentJob.Project.Name.ToString());
383        lvJobDetails.Items.Add(lvi);
384      }
385
386      if (currentJob.Client != null) {
387        lvi = null;
388        lvi = new ListViewItem();
389        lvi.Text = "Calculation begin:";
390        lvi.SubItems.Add(currentJob.DateCalculated.ToString());
391        lvJobDetails.Items.Add(lvi);
392
393
394        lvi = null;
395        lvi = new ListViewItem();
396        lvi.Text = "Client calculated:";
397        lvi.SubItems.Add(currentJob.Client.Name.ToString());
398        lvJobDetails.Items.Add(lvi);
399
400        if (currentJob.State == State.finished) {
401          IJobManager jobManager =
402            ServiceLocator.GetJobManager();
403          ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id, false);
404
405          lvi = null;
406          lvi = new ListViewItem();
407          lvi.Text = "Calculation ended:";
408          lvi.SubItems.Add(jobRes.Obj.DateFinished.ToString());
409          lvJobDetails.Items.Add(lvi);
410        }
411      }
412      if (currentJob.State != State.offline) {
413        lvSnapshots.Items.Clear();
414        GetSnapshotList();
415      } else {
416        lvSnapshots.Visible = false;
417      }
418    }
419
420    /// <summary>
421    /// if one client is clicked, the details for the clicked client are shown
422    /// in the second panel
423    /// </summary>
424    private void ClientClicked() {
425      plClientDetails.Visible = true;
426
427      if (currentClient != null) {
428        int percentageUsage = CapacityRam(currentClient.NrOfCores, currentClient.NrOfFreeCores);
429        int usage = 3;
430        if ((currentClient.State != State.offline) && (currentClient.State != State.nullState)) {
431          if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
432            usage = 0;
433          } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
434            usage = 1;
435          } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
436            usage = 2;
437          }
438        }
439        pbClientControl.Image = ilLargeImgClient.Images[usage];
440        lblClientName.Text = currentClient.Name;
441        lblLogin.Text = currentClient.Login.ToString();
442        lblState.Text = currentClient.State.ToString();
443      }
444    }
445   
446
447    private void RefreshForm() {
448      foreach (Changes change in changes) {
449        if (change.Types == Type.Job) {
450          RefreshJob(change);
451        }
452      }
453    }
454
455    private void RefreshJob(Changes change) {
456      if (change.ChangeType == Change.Update) {
457        for (int i = 0; i < lvJobControl.Items.Count; i++) {
458          if (lvJobControl.Items[i].Text == change.ID.ToString()) {
459            foreach (Job job in jobs.List) {
460              if (job.Id == change.ID) {
461                lvJobControl.Items[i].Tag = job;
462                if (currentJob.Id == change.ID) {
463                  currentJob = job;
464                  JobClicked();
465                }
466                break;
467              }
468            }
469            State state = jobs.List[change.Position].State;
470            System.Diagnostics.Debug.WriteLine(lvJobControl.Items[i].Text.ToString());
471            if (state == State.finished) {
472              lvJobControl.Items[i].Group = jobGroup[1];
473              lvJobControl.Items[i].ImageIndex = 0;
474              System.Diagnostics.Debug.WriteLine("finished");
475            } else if (state == State.calculating) {
476              lvJobControl.Items[i].Group = jobGroup[0];
477              lvJobControl.Items[i].ImageIndex = 1;
478              System.Diagnostics.Debug.WriteLine("calculating");
479            } else if (state == State.offline) {
480              lvJobControl.Items[i].Group = jobGroup[2];
481              lvJobControl.Items[i].ImageIndex = 2;
482              System.Diagnostics.Debug.WriteLine("offline");
483
484            }
485            lvJobControl.Refresh();
486          }
487        }
488      } else if (change.ChangeType == Change.Create) {
489
490        ListViewItem lvi = new ListViewItem(
491          change.ID.ToString(), 2, jobGroup[2]);
492        foreach (Job job in jobs.List) {
493          if (job.Id == change.ID) {
494            lvi.Tag = job;
495            break;
496          }
497        }
498        lvJobControl.Items.Add(lvi);
499
500      } else if (change.ChangeType == Change.Delete) {
501        for (int i = 0; i < lvJobControl.Items.Count; i++) {
502          if (change.ID.ToString() == lvJobControl.Items[i].Text.ToString()) {
503            lvJobControl.Items[i].Remove();
504            break;
505          }
506        }
507      }
508    }
509
510
511    #region Eventhandlers
512    /// <summary>
513    /// Send event to Login-GUI when closing
514    /// </summary>
515    /// <param name="sender"></param>
516    /// <param name="e"></param>
517    private void Close_Click(object sender, EventArgs e) {
518      if (closeFormEvent != null) {
519        closeFormEvent(true, false);
520      }
521      this.Close();
522    }
523
524    /// <summary>
525    /// Send evnt to Login-GUI when closing
526    /// </summary>
527    /// <param name="sender"></param>
528    /// <param name="e"></param>
529    private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
530      if (closeFormEvent != null) {
531        closeFormEvent(true, false);
532      }
533    }
534
535    private void AddJob_Click(object sender, EventArgs e) {
536      AddJobForm newForm = new AddJobForm();
537      newForm.Show();
538      newForm.addJobEvent += new addDelegate(updaterWoker.RunWorkerAsync);
539    }
540
541    private void OnLVJobControlClicked(object sender, EventArgs e) {
542      currentJob = (Job)lvJobControl.SelectedItems[0].Tag;
543      JobClicked();
544    }
545
546    private void lvJobControl_MouseMove(object sender, MouseEventArgs e) {
547      if ((lvJobControl.GetItemAt(e.X, e.Y) != null) &&
548        (lvJobControl.GetItemAt(e.X, e.Y).ToolTipText != null)) {
549        tt.SetToolTip(lvJobControl, lvJobControl.GetItemAt(e.X, e.Y).ToolTipText);
550      }
551    }
552
553    private void lvJobControl_MouseUp(object sender, MouseEventArgs e) {
554      // If the right mouse button was clicked and released,
555      // display the shortcut menu assigned to the ListView.
556      lvJobControl.ContextMenuStrip.Items.Clear();
557      ListViewHitTestInfo hitTestInfo = lvJobControl.HitTest(e.Location);
558      if (e.Button == MouseButtons.Right && hitTestInfo.Item != null && lvJobControl.SelectedItems.Count == 1) {
559        Job selectedJob = (Job)lvJobControl.SelectedItems[0].Tag;
560
561        if (selectedJob != null && selectedJob.State == State.calculating) {
562          lvJobControl.ContextMenuStrip.Items.Add(menuItemAbortJob);
563          lvJobControl.ContextMenuStrip.Items.Add(menuItemGetSnapshot);
564        }
565      }
566      lvJobControl.ContextMenuStrip.Show(new Point(e.X, e.Y));
567    }
568
569    private void tvClientControl_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {
570      lvClientControl.Items.Clear();
571      lvClientControl.Groups.Clear();
572      currentNode = e.Node;
573      AddGroupsToListView(e.Node);
574    }
575
576    private void groupToolStripMenuItem_Click(object sender, EventArgs e) {
577      AddGroup addgroup = new AddGroup();
578      parentgroup = Guid.Empty;
579      if ((tvClientControl.SelectedNode != null) && (((ClientGroup)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) {
580        parentgroup = ((ClientGroup)tvClientControl.SelectedNode.Tag).Id;
581      }
582      addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent);
583      addgroup.Show();
584    }
585
586    private void projectToolStripMenuItem_Click(object sender, EventArgs e) {
587      AddProject addproject = new AddProject();
588      addproject.AddProjectEvent += new AddProjectDelegate(addproject_AddProjectEvent);
589      addproject.Show();
590    }
591
592    private void OnLVClientClicked(object sender, EventArgs e) {
593      currentClient = (ClientInfo)lvClientControl.SelectedItems[0].Tag;
594      ClientClicked();
595    }
596
597    private void tvClientControl_MouseUp(object sender, MouseEventArgs e) {
598      // If the right mouse button was clicked and released,
599      // display the shortcut menu assigned to the ListView.
600      contextMenuGroup.Items.Clear();
601      TreeViewHitTestInfo hitTestInfo = tvClientControl.HitTest(e.Location);
602      tvClientControl.SelectedNode = hitTestInfo.Node;
603      if (e.Button != MouseButtons.Right) return;
604        if (hitTestInfo.Node != null) {
605          Resource selectedGroup = (Resource)tvClientControl.SelectedNode.Tag;
606
607          if (selectedGroup != null) {
608            contextMenuGroup.Items.Add(menuItemAddGroup);
609            contextMenuGroup.Items.Add(menuItemDeleteGroup);
610          }
611        } else {
612          contextMenuGroup.Items.Add(menuItemAddGroup);
613        }
614        tvClientControl.ContextMenuStrip.Show(tvClientControl, new Point(e.X, e.Y));
615    }
616
617    private void addproject_AddProjectEvent(string name) {
618      IJobManager jobManager = ServiceLocator.GetJobManager();
619
620      Project pg = new Project() { Name = name };
621      jobManager.CreateProject(pg);
622
623    }
624
625    private void addgroup_addGroupEvent(string name) {
626      IClientManager clientManager = ServiceLocator.GetClientManager();
627
628      if (parentgroup != Guid.Empty) {
629        ClientGroup cg = new ClientGroup() { Name = name };
630        ResponseObject<ClientGroup> respcg = clientManager.AddClientGroup(cg);
631        Response res = clientManager.AddResourceToGroup(parentgroup, respcg.Obj);
632        if (res != null && !res.Success) {
633          MessageBox.Show(res.StatusMessage, "Error adding Group", MessageBoxButtons.OK, MessageBoxIcon.Error);
634        }
635      } else {
636        ClientGroup cg = new ClientGroup() { Name = name };
637        clientManager.AddClientGroup(cg);
638        AddClients();
639      }
640    }
641
642
643    private void Refresh_Click(object sender, EventArgs e) {
644      Form overlayingForm = new Form();
645
646      overlayingForm.Show();
647      overlayingForm.FormBorderStyle = FormBorderStyle.None;
648      overlayingForm.BackColor = Color.Gray;
649      overlayingForm.Opacity = 0.4;
650      overlayingForm.Size = this.Size;
651      overlayingForm.Location = this.Location;
652
653      //Label lbl = new Label();
654      //overlayingForm.Controls.Add(lbl);
655      //lbl.AutoSize = true;
656      //lbl.Text = "Loading";
657      //lbl.Name = "lblName";
658      //lbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
659      //lbl.ForeColor = Color.Black;
660      //lbl.BackColor = Color.Transparent;
661      //lbl.Location = new Point(overlayingForm.Width / 2, overlayingForm.Height / 2);
662
663      AddClients();
664
665      overlayingForm.Close();
666    }
667
668    private void largeIconsToolStripMenuItem_Click(object sender, EventArgs e) {
669      lvClientControl.View = View.LargeIcon;
670      lvJobControl.View = View.LargeIcon;
671      largeIconsToolStripMenuItem.CheckState = CheckState.Checked;
672      smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
673      listToolStripMenuItem.CheckState = CheckState.Unchecked;
674    }
675
676    private void smallIconsToolStripMenuItem_Click(object sender, EventArgs e) {
677      lvClientControl.View = View.SmallIcon;
678      lvJobControl.View = View.SmallIcon;
679      largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
680      smallIconsToolStripMenuItem.CheckState = CheckState.Checked;
681      listToolStripMenuItem.CheckState = CheckState.Unchecked;
682    }
683
684    private void listToolStripMenuItem_Click(object sender, EventArgs e) {
685      lvClientControl.View = View.List;
686      lvJobControl.View = View.List;
687      largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
688      smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
689      listToolStripMenuItem.CheckState = CheckState.Checked;
690    }
691    #endregion
692
693    #region Helper methods
694
695    private void CloneList(ResponseList<Job> oldList, out IDictionary<int, Job> newList) {
696      newList = new Dictionary<int, Job>();
697      for (int i = 0; i < oldList.List.Count; i++) {
698        newList.Add(i, oldList.List[i]);
699      }
700    }
701
702    private bool IsEqual(ClientInfo ci1, ClientInfo ci2) {
703      if (ci2 == null) {
704        return false;
705      }
706      if (ci1.Id.Equals(ci2.Id)) {
707        return true;
708      } else return false;
709    }
710
711    private int CapacityRam(int noCores, int freeCores) {
712      if (noCores > 0) {
713        int capacity = ((noCores - freeCores) / noCores) * 100;
714        System.Diagnostics.Debug.WriteLine(capacity);
715        return capacity;
716      }
717      return 100;
718    }
719
720    private void GetDelta(IList<Job> oldJobs, IDictionary<int, Job> helpJobs) {
721      bool found = false;
722      for (int i = 0; i < jobs.List.Count; i++) {
723        Job job = jobs.List[i];
724        for (int j = 0; j < oldJobs.Count; j++) {
725
726          Job jobold = oldJobs[j];
727
728          if (job.Id.Equals(jobold.Id)) {
729
730            found = true;
731            bool change = false;
732            if (job.State != jobold.State) {
733              change = true;
734            }
735            if (job.State != State.offline) {
736              if ((!IsEqual(job.Client, jobold.Client)) || (job.State != jobold.State)
737                   || (job.Percentage != jobold.Percentage)) {
738                change = true;
739              }
740            } else if (job.DateCalculated != jobold.DateCalculated) {
741              change = true;
742            }
743            if (change) {
744              changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Update, Position = i });
745            }
746
747            int removeAt = -1;
748            foreach (KeyValuePair<int, Job> kvp in helpJobs) {
749              if (job.Id.Equals(kvp.Value.Id)) {
750                removeAt = kvp.Key;
751                break;
752              }
753            }
754            if (removeAt >= 0) {
755              helpJobs.Remove(removeAt);
756            }
757            break;
758          }
759
760        }
761        if (found == false) {
762          changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Create });
763          System.Diagnostics.Debug.WriteLine("new Job: " + job.Id);
764        }
765        found = false;
766      }
767      foreach (KeyValuePair<int, Job> kvp in helpJobs) {
768        changes.Add(new Changes { Types = Type.Job, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key });
769        System.Diagnostics.Debug.WriteLine("delete Job: " + kvp.Value.Id);
770      }
771    }
772
773    private void GetSnapshotList() {
774
775      lvSnapshots.Items.Clear();
776      IJobManager jobManager = ServiceLocator.GetJobManager();
777
778      ResponseList<JobResult> jobRes = jobManager.GetAllJobResults(currentJob.Id);
779
780      if (jobRes.List != null) {
781        foreach (JobResult jobresult in jobRes.List) {
782          ListViewItem curSnapshot = new ListViewItem(jobresult.ClientId.ToString());
783          double percentage = jobresult.Percentage * 100;
784          curSnapshot.SubItems.Add(percentage.ToString() + " %");
785          curSnapshot.SubItems.Add(jobresult.Timestamp.ToString());
786          lvSnapshots.Items.Add(curSnapshot);
787        }
788      }
789
790      if ((jobRes.List == null) && (jobRes.List.Count == 0)) {
791        lvSnapshots.Visible = false;
792      } else {
793        lvSnapshots.Visible = true;
794      }
795
796    }
797
798    #endregion
799
800  }
801}
Note: See TracBrowser for help on using the repository browser.