Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4/SlaveView.cs @ 5315

Last change on this file since 5315 was 5315, checked in by ascheibe, 13 years ago

#1233 added buttons to gui for slave control

File size: 3.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Windows.Forms;
23using HeuristicLab.Common;
24using HeuristicLab.Core.Views;
25using HeuristicLab.MainForm;
26
27
28namespace HeuristicLab.Clients.Hive.Slave.Views {
29
30  [View("HeuristicLab Slave View")]
31  [Content(typeof(SlaveItem), IsDefaultView = true)]
32  public partial class SlaveView : ItemView {
33
34    public new SlaveItem Content {
35      get { return (SlaveItem)base.Content; }
36      set { base.Content = value; }
37    }
38
39    public SlaveView() {
40      InitializeComponent();
41    }
42
43    #region Register Content Events
44    protected override void DeregisterContentEvents() {
45      base.DeregisterContentEvents();
46
47      Content.SlaveMessageLogged -= new System.EventHandler<EventArgs<string>>(Content_SlaveMessageLogged);
48      Content.SlaveShutdown -= new System.EventHandler(Content_SlaveShutdown);
49      Content.SlaveStatusChanged -= new System.EventHandler<EventArgs<StatusCommons>>(Content_SlaveStatusChanged);
50    }
51
52    protected override void RegisterContentEvents() {
53      base.RegisterContentEvents();
54
55      Content.SlaveMessageLogged += new System.EventHandler<EventArgs<string>>(Content_SlaveMessageLogged);
56      Content.SlaveShutdown += new System.EventHandler(Content_SlaveShutdown);
57      Content.SlaveStatusChanged += new System.EventHandler<EventArgs<StatusCommons>>(Content_SlaveStatusChanged);
58    }
59    #endregion
60
61    protected override void OnContentChanged() {
62      base.OnContentChanged();
63      if (Content == null) {
64        // TODO: Put code here when content is null
65      } else {
66        //try to establish a connection to the slave service
67        if (base.Content != null && ((SlaveItem)base.Content).isClosed()) {
68          RegisterContentEvents();
69          ((SlaveItem)base.Content).Open();
70        }
71      }
72    }
73
74    protected override void SetEnabledStateOfControls() {
75      base.SetEnabledStateOfControls();
76      //do nothing at the moment, we have nothing editable
77    }
78
79    #region Event Handlers
80    void Content_SlaveStatusChanged(object sender, EventArgs<StatusCommons> e) {
81      txtLog.AppendText("got a status changed object from slave\n");
82    }
83
84    void Content_SlaveShutdown(object sender, System.EventArgs e) {
85      txtLog.AppendText("Slave did shutdown\n");
86    }
87
88    void Content_SlaveMessageLogged(object sender, EventArgs<string> e) {
89      txtLog.AppendText(e.Value + "\n");
90    }
91    #endregion
92
93    private void btnSoftPause_Click(object sender, System.EventArgs e) {
94      if (Content != null)
95        Content.SoftPauseCore();
96    }
97
98    private void btnHardPause_Click(object sender, System.EventArgs e) {
99      if (Content != null)
100        Content.HardPauseCore();
101    }
102
103    private void btnRestart_Click(object sender, System.EventArgs e) {
104      if (Content != null)
105        Content.RestartCore();
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.