1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Windows.Forms;
|
---|
9 | using HeuristicLab.Core.Views;
|
---|
10 | using HeuristicLab.MainForm;
|
---|
11 | using HeuristicLab.Hive.JobBase;
|
---|
12 | using HeuristicLab.Persistence.Default.Xml;
|
---|
13 | using System.IO;
|
---|
14 |
|
---|
15 | namespace 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 | if (Content.LatestSnapshot != null) {
|
---|
39 | snapshotStatusText.InvokeIfRequired(c => c.Text = Content.LatestSnapshot.StatusMessage);
|
---|
40 | snapshotTimeText.InvokeIfRequired(c => { c.Text = Content.LatestSnapshotTime.ToString(); });
|
---|
41 | }
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | protected override void RegisterContentEvents() {
|
---|
46 | base.RegisterContentEvents();
|
---|
47 | Content.LatestSnapshotChanged += new EventHandler(Content_LatestSnapshotChanged);
|
---|
48 | Content.JobDtoChanged += new EventHandler(Content_JobDtoChanged);
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected override void DeregisterContentEvents() {
|
---|
52 | Content.LatestSnapshotChanged -= new EventHandler(Content_LatestSnapshotChanged);
|
---|
53 | Content.JobDtoChanged -= new EventHandler(Content_JobDtoChanged);
|
---|
54 | base.DeregisterContentEvents();
|
---|
55 | }
|
---|
56 |
|
---|
57 | void Content_JobDtoChanged(object sender, EventArgs e) {
|
---|
58 | if (InvokeRequired) {
|
---|
59 | Invoke(new EventHandler(Content_JobDtoChanged), sender, e);
|
---|
60 | } else {
|
---|
61 | this.stateTextBox.Text = Content.JobDto.State.ToString();
|
---|
62 | this.userIdTextBox.Text = Content.JobDto.UserId.ToString();
|
---|
63 | this.percentageTextBox.Text = (Content.JobDto.Percentage*100).ToString() + "%";
|
---|
64 | this.percentageProgressBar.Value = Convert.ToInt32(Content.JobDto.Percentage * percentageProgressBar.Maximum);
|
---|
65 | this.dateCreatedTextBox.Text = Content.JobDto.DateCreated.ToString();
|
---|
66 | this.dateCalculatedText.Text = Content.JobDto.DateCalculated.ToString();
|
---|
67 | this.dateFinishedTextBox.Text = Content.JobDto.DateFinished.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.pluginsNeededTextBox.Text = string.Join(", ", Content.JobDto.PluginsNeeded.Select(x => x.Name + "-" + x.Version).ToArray());
|
---|
72 | this.projectTextBox.Text = Content.JobDto.Project != null ? Content.JobDto.Project.Name : "-";
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | void Content_LatestSnapshotChanged(object sender, EventArgs e) {
|
---|
77 | if (InvokeRequired) {
|
---|
78 | Invoke(new EventHandler(Content_LatestSnapshotChanged), sender, e);
|
---|
79 | } else {
|
---|
80 | if (Content.LatestSnapshot != null) {
|
---|
81 | snapshotStatusText.Text = Content.LatestSnapshot.StatusMessage;
|
---|
82 | snapshotTimeText.Text = Content.LatestSnapshotTime.ToString();
|
---|
83 | } else {
|
---|
84 | snapshotStatusText.Text = "";
|
---|
85 | snapshotTimeText.Text = "";
|
---|
86 | }
|
---|
87 | SetEnabledStateOfControls();
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | protected override void SetEnabledStateOfControls() {
|
---|
92 | base.SetEnabledStateOfControls();
|
---|
93 | openSnapshotButton.Enabled = Content != null && Content.LatestSnapshot != null;
|
---|
94 | this.stateTextBox.ReadOnly = this.ReadOnly;
|
---|
95 | this.userIdTextBox.ReadOnly = this.ReadOnly;
|
---|
96 | this.percentageTextBox.ReadOnly = this.ReadOnly;
|
---|
97 | this.dateCreatedTextBox.ReadOnly = this.ReadOnly;
|
---|
98 | this.dateCalculatedText.ReadOnly = this.ReadOnly;
|
---|
99 | this.dateFinishedTextBox.ReadOnly = this.ReadOnly;
|
---|
100 | this.priorityTextBox.ReadOnly = this.ReadOnly;
|
---|
101 | this.coresNeededTextBox.ReadOnly = this.ReadOnly;
|
---|
102 | this.memoryNeededTextBox.ReadOnly = this.ReadOnly;
|
---|
103 | this.pluginsNeededTextBox.ReadOnly = this.ReadOnly;
|
---|
104 | this.projectTextBox.ReadOnly = this.ReadOnly;
|
---|
105 | this.snapshotStatusText.ReadOnly = this.ReadOnly;
|
---|
106 | this.snapshotTimeText.ReadOnly = this.ReadOnly;
|
---|
107 | }
|
---|
108 |
|
---|
109 | private void openSnapshotButton_Click(object sender, EventArgs e) {
|
---|
110 | OptimizerJob job = XmlParser.Deserialize<OptimizerJob>(new MemoryStream(Content.LatestSnapshot.Obj.SerializedJobData));
|
---|
111 | MainFormManager.MainForm.ShowContent(job.Optimizer);
|
---|
112 | }
|
---|
113 | }
|
---|
114 | }
|
---|