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 @ 5544

Last change on this file since 5544 was 5451, checked in by ascheibe, 14 years ago

#1233

  • added Sleep cmd
  • adapted gui for new cmds
File size: 3.8 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 {
37        if (base.Content != value) {
38          base.Content = value;
39        }
40      }
41    }
42
43    public SlaveView() {
44      InitializeComponent();
45    }
46
47    #region Register Content Events
48    protected override void DeregisterContentEvents() {
49      Content.SlaveMessageLogged -= new System.EventHandler<EventArgs<string>>(Content_SlaveMessageLogged);
50      Content.SlaveShutdown -= new System.EventHandler(Content_SlaveShutdown);
51      Content.SlaveStatusChanged -= new System.EventHandler<EventArgs<StatusCommons>>(Content_SlaveStatusChanged);
52
53      base.DeregisterContentEvents();
54    }
55
56    protected override void RegisterContentEvents() {
57      base.RegisterContentEvents();
58
59      Content.SlaveMessageLogged += new System.EventHandler<EventArgs<string>>(Content_SlaveMessageLogged);
60      Content.SlaveShutdown += new System.EventHandler(Content_SlaveShutdown);
61      Content.SlaveStatusChanged += new System.EventHandler<EventArgs<StatusCommons>>(Content_SlaveStatusChanged);
62    }
63    #endregion
64
65    protected override void OnContentChanged() {
66      base.OnContentChanged();
67      if (Content == null) {
68        //nothing to do...       
69      } else {
70        //try to establish a connection to the slave service
71        if (base.Content != null && ((SlaveItem)base.Content).isClosed()) {
72          ((SlaveItem)base.Content).Open();
73        }
74      }
75    }
76
77    protected override void SetEnabledStateOfControls() {
78      base.SetEnabledStateOfControls();
79      //do nothing at the moment, we have nothing editable
80    }
81
82    #region Event Handlers
83    void Content_SlaveStatusChanged(object sender, EventArgs<StatusCommons> e) {
84      txtLog.AppendText("got a status changed object from slave\n");
85    }
86
87    void Content_SlaveShutdown(object sender, System.EventArgs e) {
88      txtLog.AppendText("Slave did shutdown\n");
89    }
90
91    void Content_SlaveMessageLogged(object sender, EventArgs<string> e) {
92      txtLog.AppendText(e.Value + "\n");
93    }
94    #endregion
95
96    private void btnSoftPause_Click(object sender, System.EventArgs e) {
97      if (Content != null)
98        Content.PauseAll();
99    }
100
101    private void btnHardPause_Click(object sender, System.EventArgs e) {
102      if (Content != null)
103        Content.StopAll();
104    }
105
106    private void btnRestart_Click(object sender, System.EventArgs e) {
107      if (Content != null)
108        Content.RestartCore();
109    }
110
111    private void btnSleep_Click(object sender, System.EventArgs e) {
112      if (Content != null)
113        Content.Sleep();
114    }
115  }
116}
Note: See TracBrowser for help on using the repository browser.