Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.Administrator/3.3/Views/SlaveView.cs @ 7317

Last change on this file since 7317 was 7270, checked in by spimming, 13 years ago

#1680:

  • merged changes from trunk into branch
File size: 4.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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;
26using HeuristicLab.MainForm.WindowsForms;
27
28namespace HeuristicLab.Clients.Hive.Administrator.Views {
29  [View("SlaveView")]
30  [Content(typeof(Resource), IsDefaultView = true)]
31  public partial class SlaveView : ItemView {
32    public new Resource Content {
33      get { return (Resource)base.Content; }
34      set { base.Content = value; }
35    }
36
37    public SlaveView() {
38      InitializeComponent();
39    }
40
41    #region Register Content Events
42    protected override void DeregisterContentEvents() {
43      base.DeregisterContentEvents();
44    }
45    protected override void RegisterContentEvents() {
46      base.RegisterContentEvents();
47    }
48    #endregion
49
50    protected override void OnContentChanged() {
51      base.OnContentChanged();
52      if (Content == null) {
53        ShowSlaveUI(true);
54        txtName.Clear();
55        txtCPU.Clear();
56        txtDetailsDescription.Clear();
57        txtMemory.Clear();
58        txtOS.Clear();
59        txtSlaveState.Clear();
60        txtLastHeartbeat.Clear();
61        txtFreeMemory.Clear();
62        txtId.Clear();
63        txtHbIntervall.Clear();
64      } else {
65        if (Content.GetType() == typeof(Slave)) {
66          ShowSlaveUI(true);
67          Slave ct = (Slave)Content;
68          txtName.Text = ct.Name;
69          txtHbIntervall.Text = ct.HbInterval.ToString();
70          txtCPU.Text = string.Format("{0} Cores @ {1} Mhz, Arch.: {2}", ct.Cores.ToString(), ct.CpuSpeed.ToString(), ct.CpuArchitecture.ToString());
71          txtDetailsDescription.Text = ct.Description;
72          txtMemory.Text = ct.Memory.ToString();
73          txtOS.Text = ct.OperatingSystem;
74          txtSlaveState.Text = ct.SlaveState.ToString();
75          txtLastHeartbeat.Text = ct.LastHeartbeat.ToString();
76          txtFreeMemory.Text = ct.FreeMemory.ToString();
77          txtId.Text = ct.Id.ToString();
78        } else if (Content.GetType() == typeof(SlaveGroup)) {
79          SlaveGroup ct = (SlaveGroup)Content;
80          txtName.Text = ct.Name;
81          txtHbIntervall.Text = ct.HbInterval.ToString();
82          ShowSlaveUI(false);
83        } else {
84          throw new Exception("Unknown Resource in SlaveView");
85        }
86      }
87    }
88
89    private void ShowSlaveUI(bool show) {
90      label2.Visible = show;
91      label1.Visible = show;
92      label10.Visible = show;
93      label11.Visible = show;
94      label12.Visible = show;
95      label13.Visible = show;
96      label14.Visible = show;
97      label15.Visible = show;
98      txtCPU.Visible = show;
99      txtDetailsDescription.Visible = show;
100      txtMemory.Visible = show;
101      txtOS.Visible = show;
102      txtSlaveState.Visible = show;
103      txtLastHeartbeat.Visible = show;
104      txtFreeMemory.Visible = show;
105      txtId.Visible = show;
106      txtName.Enabled = !show;
107    }
108
109    protected override void SetEnabledStateOfControls() {
110      base.SetEnabledStateOfControls();
111    }
112
113    private void txtName_TextChanged(object sender, EventArgs e) {
114      if (Content != null && Content is SlaveGroup) {
115        Content.Name = txtName.Text;
116      }
117    }
118
119    private void txtHbIntervall_TextChanged(object sender, EventArgs e) {
120      if (Content != null) {
121        if (txtHbIntervall.Text.Length > 0) {
122          try {
123            int interval = int.Parse(txtHbIntervall.Text);
124            Content.HbInterval = interval;
125          }
126          catch (Exception) {
127            MessageBox.Show("Please enter a numeric value for the Heartbeat Interval.", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
128            txtHbIntervall.Text = "10";
129          }
130        }
131      }
132    }
133  }
134}
Note: See TracBrowser for help on using the repository browser.