Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Clients.Hive.Slave.Views/3.3/SlaveCmdsBase.cs @ 6983

Last change on this file since 6983 was 6983, checked in by ascheibe, 12 years ago

#1672

  • added the Hive Services and Slave projects
  • added missing svn ignores
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;
23using System.Windows.Forms;
24using HeuristicLab.Common;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27
28
29namespace HeuristicLab.Clients.Hive.SlaveCore.Views {
30
31  [View("HeuristicLab Slave Cmds View")]
32  [Content(typeof(SlaveItem), IsDefaultView = false)]
33  public partial class SlaveCmdsBase : ItemView {
34    protected SlaveDisplayStat lastSlaveDisplayStat;
35
36    public new SlaveItem Content {
37      get { return (SlaveItem)base.Content; }
38      set {
39        if (base.Content != value) {
40          base.Content = value;
41        }
42      }
43    }
44
45    public SlaveCmdsBase() {
46      InitializeComponent();
47    }
48
49    #region Register Content Events
50    protected override void DeregisterContentEvents() {
51
52      Content.SlaveDisplayStateChanged -= new EventHandler<EventArgs<SlaveDisplayStat>>(Content_SlaveDisplayStateChanged);
53      Content.CoreConnectionChanged -= new EventHandler<EventArgs<CoreConnection>>(Content_CoreConnectionChanged);
54
55      base.DeregisterContentEvents();
56    }
57
58    protected override void RegisterContentEvents() {
59      base.RegisterContentEvents();
60
61      Content.SlaveDisplayStateChanged += new EventHandler<EventArgs<SlaveDisplayStat>>(Content_SlaveDisplayStateChanged);
62      Content.CoreConnectionChanged += new EventHandler<EventArgs<CoreConnection>>(Content_CoreConnectionChanged);
63    }
64    #endregion
65
66    protected override void OnContentChanged() {
67      base.OnContentChanged();
68      btnStart.Enabled = false;
69      btnStop.Enabled = false;
70    }
71
72    protected override void SetEnabledStateOfControls() {
73      base.SetEnabledStateOfControls();
74    }
75
76    #region Event Handlers
77    protected virtual void Content_SlaveDisplayStateChanged(object sender, EventArgs<SlaveDisplayStat> e) {
78      lastSlaveDisplayStat = e.Value;
79
80      if (e.Value == SlaveDisplayStat.Asleep || e.Value == SlaveDisplayStat.NoService) {
81        btnStart.Enabled = true;
82        btnStop.Enabled = false;
83      }
84
85      if (e.Value == SlaveDisplayStat.Busy || e.Value == SlaveDisplayStat.Idle || e.Value == SlaveDisplayStat.Offline) {
86        btnStart.Enabled = false;
87        btnStop.Enabled = true;
88      }
89    }
90
91    protected virtual void Content_CoreConnectionChanged(object sender, EventArgs<CoreConnection> e) {
92      if (e.Value == CoreConnection.Offline) {
93        btnStart.Enabled = false;
94        btnStop.Enabled = false;
95      }
96    }
97    #endregion
98
99    protected virtual void btnStop_Click(object sender, EventArgs e) {
100      if (Content != null) {
101        Content.Sleep();
102      }
103    }
104
105    protected virtual void btnStart_Click(object sender, EventArgs e) {
106      if (Content != null) {
107        if (lastSlaveDisplayStat == SlaveDisplayStat.Asleep) {
108          Content.RestartCore();
109        }
110      }
111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.