Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Clients.Hive.Administrator/3.3/Views/SlaveView.cs @ 11147

Last change on this file since 11147 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

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