Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment.Views/3.3/JobItemView.cs @ 4173

Last change on this file since 4173 was 4173, checked in by cneumuel, 14 years ago
  • reorganized HiveExperiment code
  • disabled snapshot-functionality... this needs more refactoring serverside
  • added short documentation which explains how to use hive
  • some minor changes
File size: 5.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using HeuristicLab.Core.Views;
10using HeuristicLab.MainForm;
11using HeuristicLab.Hive.JobBase;
12using HeuristicLab.Persistence.Default.Xml;
13using System.IO;
14
15namespace HeuristicLab.Hive.Experiment.Views {
16  [View("JobItem View")]
17  [Content(typeof(JobItem), true)]
18  public partial class JobItemView : ItemView {
19    public new JobItem Content {
20      get { return (JobItem)base.Content; }
21      set {
22        if (base.Content != value) {
23          base.Content = value;
24        }
25      }
26    }
27
28    public JobItemView() {
29      InitializeComponent();
30      this.ReadOnly = true;
31    }
32
33    protected override void OnContentChanged() {
34      base.OnContentChanged();
35      if (Content != null) {
36        logView.Content = Content.Log;
37        Content_JobDtoChanged(this, EventArgs.Empty);
38        Content_JobStateChanged(this, EventArgs.Empty);
39        if (Content.LatestSnapshot != null) {
40          snapshotStatusText.InvokeIfRequired(c => c.Text = Content.LatestSnapshot.StatusMessage);
41          snapshotTimeText.InvokeIfRequired(c => { c.Text = Content.LatestSnapshotTime.ToString(); });
42        }
43      }
44    }
45
46    protected override void RegisterContentEvents() {
47      base.RegisterContentEvents();
48      Content.LatestSnapshotChanged += new EventHandler(Content_LatestSnapshotChanged);
49      Content.JobDtoChanged += new EventHandler(Content_JobDtoChanged);
50      Content.JobStateChanged += new EventHandler(Content_JobStateChanged);
51      Content.SnapshotRequestedStateChanged += new EventHandler(Content_SnapshotRequestedStateChanged);
52    }
53
54    protected override void DeregisterContentEvents() {
55      Content.LatestSnapshotChanged -= new EventHandler(Content_LatestSnapshotChanged);
56      Content.JobDtoChanged -= new EventHandler(Content_JobDtoChanged);
57      Content.JobStateChanged -= new EventHandler(Content_JobStateChanged);
58      Content.SnapshotRequestedStateChanged -= new EventHandler(Content_SnapshotRequestedStateChanged);
59      base.DeregisterContentEvents();
60    }
61
62    private void Content_JobDtoChanged(object sender, EventArgs e) {
63      if (InvokeRequired) {
64        Invoke(new EventHandler(Content_JobDtoChanged), sender, e);
65      } else {
66        this.jobIdTextBox.Text = Content.JobDto.Id.ToString();
67        this.dateCreatedTextBox.Text = Content.JobDto.DateCreated.ToString();
68        this.priorityTextBox.Text = Content.JobDto.Priority.ToString();
69        this.coresNeededTextBox.Text = Content.JobDto.CoresNeeded.ToString();
70        this.memoryNeededTextBox.Text = Content.JobDto.MemoryNeeded.ToString();
71        this.projectTextBox.Text = Content.JobDto.Project != null ? Content.JobDto.Project.Name : "-";
72      }
73    }
74
75    private void Content_JobStateChanged(object sender, EventArgs e) {
76      if (InvokeRequired) {
77        Invoke(new EventHandler(Content_JobStateChanged), sender, e);
78      } else {
79        this.stateTextBox.Text = Content.State.ToString();
80        this.percentageTextBox.Text = (Content.Percentage * 100).ToString() + "%";
81        this.percentageProgressBar.Value = Convert.ToInt32(Content.Percentage * percentageProgressBar.Maximum);
82        this.dateCalculatedText.Text = Content.DateCalculated.ToString();
83        this.dateFinishedTextBox.Text = Content.DateFinished.ToString();
84        this.exceptionTextBox.Text = Content.Exception;
85      }
86    }
87
88    void Content_LatestSnapshotChanged(object sender, EventArgs e) {
89      if (InvokeRequired) {
90        Invoke(new EventHandler(Content_LatestSnapshotChanged), sender, e);
91      } else {
92        if (Content.LatestSnapshot != null) {
93          snapshotStatusText.Text = Content.LatestSnapshot.StatusMessage;
94          snapshotTimeText.Text = Content.LatestSnapshotTime.ToString();
95        } else {
96          snapshotStatusText.Text = "";
97          snapshotTimeText.Text = "";
98        }
99        SetEnabledStateOfControls();
100      }
101    }
102
103    protected override void SetEnabledStateOfControls() {
104      if (InvokeRequired) {
105        this.InvokeIfRequired(c => { SetEnabledStateOfControls(); });
106      } else {
107        base.SetEnabledStateOfControls();
108        if (Content != null) {
109          openSnapshotButton.Enabled = Content.LatestSnapshot != null && Content.SnapshotRequestedState == SnapshotRequestedState.Idle;
110          requestSnapshotButton.Enabled = Content.SnapshotRequestedState == SnapshotRequestedState.Idle;
111        }
112        this.jobIdTextBox.ReadOnly = this.ReadOnly;
113        this.stateTextBox.ReadOnly = this.ReadOnly;
114        this.userIdTextBox.ReadOnly = this.ReadOnly;
115        this.percentageTextBox.ReadOnly = this.ReadOnly;
116        this.dateCreatedTextBox.ReadOnly = this.ReadOnly;
117        this.dateCalculatedText.ReadOnly = this.ReadOnly;
118        this.dateFinishedTextBox.ReadOnly = this.ReadOnly;
119        this.priorityTextBox.ReadOnly = this.ReadOnly;
120        this.coresNeededTextBox.ReadOnly = this.ReadOnly;
121        this.memoryNeededTextBox.ReadOnly = this.ReadOnly;
122        this.exceptionTextBox.ReadOnly = this.ReadOnly;
123        this.projectTextBox.ReadOnly = this.ReadOnly;
124        this.snapshotStatusText.ReadOnly = this.ReadOnly;
125        this.snapshotTimeText.ReadOnly = this.ReadOnly;
126      }
127    }
128
129    private void openSnapshotButton_Click(object sender, EventArgs e) {
130      OptimizerJob job = XmlParser.Deserialize<OptimizerJob>(new MemoryStream(Content.LatestSnapshot.Obj.SerializedJobData));
131      MainFormManager.MainForm.ShowContent(job.Optimizer);
132    }
133
134    private void requestSnapshotButton_Click(object sender, EventArgs e) {
135      this.Content.RequestSnapshot();
136    }
137
138    private void Content_SnapshotRequestedStateChanged(object sender, EventArgs e) {
139      SetEnabledStateOfControls();
140    }
141  }
142}
Note: See TracBrowser for help on using the repository browser.