Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.ExternalEvaluation.Views/3.4/EvaluationProcessChannelView.cs @ 12006

Last change on this file since 12006 was 11171, checked in by ascheibe, 10 years ago

#2115 merged r11170 (copyright update) into trunk

File size: 4.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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.Windows.Forms;
24using HeuristicLab.Core.Views;
25using HeuristicLab.MainForm;
26
27namespace HeuristicLab.Problems.ExternalEvaluation.Views {
28  [View("Process-Channel View")]
29  [Content(typeof(EvaluationProcessChannel), IsDefaultView = true)]
30  public sealed partial class EvaluationProcessChannelView : NamedItemView {
31    public new EvaluationProcessChannel Content {
32      get { return (EvaluationProcessChannel)base.Content; }
33      set { base.Content = value; }
34    }
35
36    public EvaluationProcessChannelView() {
37      InitializeComponent();
38    }
39
40    protected override void DeregisterContentEvents() {
41      Content.ExecutableChanged -= new EventHandler(Content_ExecutableChanged);
42      Content.ArgumentsChanged -= new EventHandler(Content_ArgumentsChanged);
43      Content.ProcessStarted -= new EventHandler(Content_ProcessStarted);
44      Content.ProcessExited -= new EventHandler(Content_ProcessExited);
45      base.DeregisterContentEvents();
46    }
47
48    protected override void RegisterContentEvents() {
49      base.RegisterContentEvents();
50      Content.ExecutableChanged += new EventHandler(Content_ExecutableChanged);
51      Content.ArgumentsChanged += new EventHandler(Content_ArgumentsChanged);
52      Content.ProcessStarted += new EventHandler(Content_ProcessStarted);
53      Content.ProcessExited += new EventHandler(Content_ProcessExited);
54    }
55
56    #region Event Handlers (Content)
57    private void Content_ExecutableChanged(object sender, EventArgs e) {
58      executableTextBox.Text = Content.Executable;
59    }
60    private void Content_ArgumentsChanged(object sender, EventArgs e) {
61      argumentsTextBox.Text = Content.Arguments;
62    }
63    private void Content_ProcessStarted(object sender, EventArgs e) {
64      if (InvokeRequired) Invoke(new Action<object, EventArgs>(Content_ProcessStarted), sender, e);
65      else SetEnabledStateOfControls();
66    }
67    private void Content_ProcessExited(object sender, EventArgs e) {
68      if (InvokeRequired) Invoke(new Action<object, EventArgs>(Content_ProcessExited), sender, e);
69      else SetEnabledStateOfControls();
70    }
71    #endregion
72
73    protected override void OnContentChanged() {
74      base.OnContentChanged();
75      if (Content == null) {
76        executableTextBox.Text = String.Empty;
77        argumentsTextBox.Text = String.Empty;
78      } else {
79        executableTextBox.Text = Content.Executable;
80        argumentsTextBox.Text = Content.Arguments;
81      }
82    }
83
84    protected override void SetEnabledStateOfControls() {
85      base.SetEnabledStateOfControls();
86      bool readOnlyDriverNullOrStarted = ReadOnly || Content == null || Content.IsInitialized;
87      browseExecutableButton.Enabled = !readOnlyDriverNullOrStarted;
88      startButton.Enabled = !readOnlyDriverNullOrStarted;
89      terminateButton.Enabled = !ReadOnly && Content != null && Content.IsInitialized;
90      executableTextBox.Enabled = !readOnlyDriverNullOrStarted;
91      argumentsTextBox.Enabled = !readOnlyDriverNullOrStarted;
92    }
93
94    #region Event Handlers (child controls)
95    private void browseExecutableButton_Click(object sender, EventArgs e) {
96      if (openFileDialog.ShowDialog() == DialogResult.OK) {
97        try {
98          Content.Executable = openFileDialog.FileName;
99        } catch (InvalidOperationException ex) {
100          MessageBox.Show(ex.Message);
101        }
102      }
103    }
104    private void argumentsTextBox_Validated(object sender, EventArgs e) {
105      if (Content != null) {
106        Content.Arguments = argumentsTextBox.Text;
107      }
108    }
109    #endregion
110
111    private void startButton_Click(object sender, EventArgs e) {
112      try {
113        Content.Open();
114      } catch (InvalidOperationException ex) {
115        MessageBox.Show(ex.Message);
116      }
117    }
118
119    private void terminateButton_Click(object sender, EventArgs e) {
120      try {
121        Content.Close();
122      } catch (InvalidOperationException ex) {
123        MessageBox.Show(ex.Message);
124      }
125    }
126  }
127}
Note: See TracBrowser for help on using the repository browser.