Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/SlaveView.cs @ 15412

Last change on this file since 15412 was 15412, checked in by jkarder, 7 years ago

#2839:

  • worked on resources and projects views
  • changed resource selector to be able to select projects and assigned resources
  • updated service clients
File size: 6.1 KB
RevLine 
[6976]1#region License Information
2/* HeuristicLab
[14185]3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6976]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;
[8051]24using HeuristicLab.Clients.Access;
[6976]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();
[7857]65        cbxDisposable.Checked = false;
[8051]66        cbxPublic.Checked = false;
[6976]67      } else {
68        if (Content.GetType() == typeof(Slave)) {
69          ShowSlaveUI(true);
70          Slave ct = (Slave)Content;
[8071]71          bool authorized = UserInformation.Instance.UserExists && (ct.OwnerUserId == UserInformation.Instance.User.Id || HiveRoles.CheckAdminUserPermissions());
[6976]72          txtName.Text = ct.Name;
73          txtHbIntervall.Text = ct.HbInterval.ToString();
[8051]74          cbxPublic.Enabled = authorized;
75          cbxPublic.CheckedChanged -= new EventHandler(cbxPublic_CheckedChanged);
76          cbxPublic.Checked = ct.OwnerUserId == null;
77          cbxPublic.CheckedChanged += new EventHandler(cbxPublic_CheckedChanged);
[6976]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();
[8051]86          cbxDisposable.Enabled = authorized;
87          cbxDisposable.Checked = ct.IsDisposable.GetValueOrDefault();
[6976]88        } else if (Content.GetType() == typeof(SlaveGroup)) {
89          SlaveGroup ct = (SlaveGroup)Content;
90          txtName.Text = ct.Name;
91          txtHbIntervall.Text = ct.HbInterval.ToString();
[8051]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);
[6976]96          ShowSlaveUI(false);
97        } else {
98          throw new Exception("Unknown Resource in SlaveView");
99        }
100      }
101    }
102
103    private void ShowSlaveUI(bool show) {
[7857]104      label1.Visible = show;
[6976]105      label2.Visible = show;
[7857]106      label4.Visible = show;
[6976]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;
[7857]122      cbxDisposable.Visible = show;
[6976]123    }
124
125    protected override void SetEnabledStateOfControls() {
126      base.SetEnabledStateOfControls();
[15412]127      bool enabled = Content != null;
128      txtName.Enabled = enabled;
129      txtHbIntervall.Enabled = enabled;
130      cbxPublic.Enabled = enabled;
[6976]131    }
132
133    private void txtName_TextChanged(object sender, EventArgs e) {
134      if (Content != null && Content is SlaveGroup) {
135        Content.Name = txtName.Text;
136      }
137    }
138
139    private void txtHbIntervall_TextChanged(object sender, EventArgs e) {
140      if (Content != null) {
141        if (txtHbIntervall.Text.Length > 0) {
142          try {
143            int interval = int.Parse(txtHbIntervall.Text);
144            Content.HbInterval = interval;
[15412]145          } catch (Exception) {
[6976]146            MessageBox.Show("Please enter a numeric value for the Heartbeat Interval.", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
147            txtHbIntervall.Text = "10";
148          }
149        }
150      }
151    }
[7857]152
[8051]153    private void cbxDisposable_CheckedChanged(object sender, EventArgs e) {
[7857]154      if (Content != null) {
155        ((Slave)Content).IsDisposable = cbxDisposable.Checked;
156      }
157    }
[8051]158
159    private void cbxPublic_CheckedChanged(object sender, EventArgs e) {
160      if (Content != null) {
161        Content.OwnerUserId = cbxPublic.Checked ? null : new Guid?(UserInformation.Instance.User.Id);
162      }
163    }
[6976]164  }
165}
Note: See TracBrowser for help on using the repository browser.