Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Console/3.3/JobListView.cs @ 4302

Last change on this file since 4302 was 4302, checked in by cneumuel, 14 years ago
  • made ServerConsole work with wsHttpBinding
  • applied role-base restrictions to all WCF-Services
  • made wcf-services work with certificates
  • renamed ExecutionEngineFacade to ClientFacade

(#1168)

File size: 5.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Forms;
6using HeuristicLab.Hive.Contracts.BusinessObjects;
7using HeuristicLab.Hive.Contracts.Interfaces;
8
9namespace HeuristicLab.Hive.Server.ServerConsole {
10  public class JobListView : ListView {
11    private ContextMenuStrip contextMenuJob;
12    private System.ComponentModel.IContainer components;
13    private ToolStripMenuItem menuItemAbortJob;
14    private ToolStripMenuItem menuItemGetSnapshot;
15    private ImageList ilLargeImgJob;
16    private ImageList ilSmallImgJob;
17
18    public int NrOfEntriesOnPage {
19      get {
20        return jdf.NrOfEntriesOnPage;
21      }
22      set {
23        jdf.NrOfEntriesOnPage = value;
24      }
25    }
26
27
28    private JobDataFetcher jdf;
29
30    public JobListView(IEnumerable<JobState> states, int nrOfEntries)
31      : base() {
32      InitializeComponent();
33      InitializeCustomControls();
34      jdf = new JobDataFetcher(states, nrOfEntries);
35      jdf.NewDataAvailable += new EventHandler(JdfNewDataAvailable);
36      jdf.Start();
37    }
38
39    private void JdfNewDataAvailable(object sender, EventArgs e) {
40      JobDataFetcher datafetcher = (JobDataFetcher)sender;
41      this.BeginUpdate();
42      if (datafetcher.PollStates.Contains(JobState.Finished)) {
43        this.Items.Clear();
44        ListViewItem lviDummy = new ListViewItem("blahr", 0);
45        this.Items.Add(lviDummy);
46        foreach (JobDto job in datafetcher.CachedJobs) {
47          ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0);
48          lvi.Tag = job;
49          this.Items.Add(lvi);
50        }
51      }
52      this.EndUpdate();
53    }
54
55    public void Forward() {
56      jdf.Forward();
57    }
58
59    public void Backward() {
60      jdf.Backward();
61    }
62
63    private void InitializeComponent() {
64      this.components = new System.ComponentModel.Container();
65      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(JobListView));
66      this.contextMenuJob = new System.Windows.Forms.ContextMenuStrip(this.components);
67      this.menuItemAbortJob = new System.Windows.Forms.ToolStripMenuItem();
68      this.menuItemGetSnapshot = new System.Windows.Forms.ToolStripMenuItem();
69      this.ilLargeImgJob = new System.Windows.Forms.ImageList(this.components);
70      this.ilSmallImgJob = new System.Windows.Forms.ImageList(this.components);
71      this.contextMenuJob.SuspendLayout();
72      this.SuspendLayout();
73      //
74      // contextMenuJob
75      //
76      this.contextMenuJob.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
77            this.menuItemAbortJob,
78            this.menuItemGetSnapshot});
79      this.contextMenuJob.Name = "contextMenuJob";
80      this.contextMenuJob.Size = new System.Drawing.Size(145, 48);
81      //
82      // menuItemAbortJob
83      //
84      this.menuItemAbortJob.Name = "menuItemAbortJob";
85      this.menuItemAbortJob.Size = new System.Drawing.Size(144, 22);
86      this.menuItemAbortJob.Text = "Abort";
87      //
88      // menuItemGetSnapshot
89      //
90      this.menuItemGetSnapshot.Name = "menuItemGetSnapshot";
91      this.menuItemGetSnapshot.Size = new System.Drawing.Size(144, 22);
92      this.menuItemGetSnapshot.Text = "Get Snapshot";
93      //
94      // ilLargeImgJob
95      //
96      this.ilLargeImgJob.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilLargeImgJob.ImageStream")));
97      this.ilLargeImgJob.TransparentColor = System.Drawing.Color.Transparent;
98      this.ilLargeImgJob.Images.SetKeyName(0, "ok.png");
99      this.ilLargeImgJob.Images.SetKeyName(1, "Forward.png");
100      this.ilLargeImgJob.Images.SetKeyName(2, "pause.png");
101      //
102      // ilSmallImgJob
103      //
104      this.ilSmallImgJob.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilSmallImgJob.ImageStream")));
105      this.ilSmallImgJob.TransparentColor = System.Drawing.Color.Transparent;
106      this.ilSmallImgJob.Images.SetKeyName(0, "ok.png");
107      this.ilSmallImgJob.Images.SetKeyName(1, "Forward.png");
108      this.ilSmallImgJob.Images.SetKeyName(2, "pause.png");
109      //
110      // JobListView
111      //
112      this.LargeImageList = this.ilLargeImgJob;
113      this.SmallImageList = this.ilSmallImgJob;
114      this.contextMenuJob.ResumeLayout(false);
115      this.ResumeLayout(false);
116
117    }
118
119    private void InitializeCustomControls() {
120      menuItemAbortJob.Click += (s, e) => {
121        IJobManager jobManager = ServiceLocator.GetJobManager();
122        if (this.SelectedItems.Count == 1) {
123          jobManager.AbortJob(((JobDto)(this.SelectedItems[0].Tag)).Id);
124        }
125      };
126
127      //adding context menu items for jobs
128      menuItemGetSnapshot.Click += (s, e) => {
129        IJobManager jobManager = ServiceLocator.GetJobManager();
130        if (this.SelectedItems.Count == 1) {
131          jobManager.RequestSnapshot(((JobDto)(this.SelectedItems[0].Tag)).Id);
132        }
133      };
134    }
135  }
136}
Note: See TracBrowser for help on using the repository browser.