Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Console/HiveServerManagementConsole.cs @ 1085

Last change on this file since 1085 was 1037, checked in by aleitner, 16 years ago

Refactoring Tab-order, renaming (#380)

File size: 7.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Collections.Generic;
24using System.ComponentModel;
25using System.Data;
26using System.Drawing;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.Hive.Contracts.Interfaces;
31using HeuristicLab.Hive.Contracts.BusinessObjects;
32using HeuristicLab.Hive.Contracts;
33
34namespace HeuristicLab.Hive.Server.Console {
35
36  public delegate void closeForm(bool cf, bool error);
37
38  public partial class HiveServerManagementConsole : Form {
39
40    public event closeForm closeFormEvent;
41
42    ResponseList<ClientGroup> clients = null;
43    ResponseList<ClientInfo> clientInfo = null;
44    ResponseList<Job> jobs = null;
45    ResponseList<UserGroup> userGroups = null;
46    ResponseList<User> usersList = null;
47
48    public HiveServerManagementConsole() {
49      InitializeComponent();
50      AddClients();
51      AddJobs();
52      AddUsers();
53
54      timerSyncronize.Tick += new EventHandler(TickSync);
55      timerSyncronize.Start();
56    }
57
58    private void TickSync(object obj, EventArgs e) {
59      AddClients();
60      AddJobs();
61      AddUsers();
62    }
63
64    private void AddClients() {
65      try {
66        IClientManager clientManager =
67          ServiceLocator.GetClientManager();
68
69        clients = clientManager.GetAllClientGroups();
70
71        lvClientControl.Items.Clear();
72        tvClientControl.Nodes.Clear();
73        int count = 0;
74        foreach (ClientGroup cg in clients.List) {
75          tvClientControl.Nodes.Add(cg.Name);
76          ListViewGroup lvg = new ListViewGroup(cg.Name, HorizontalAlignment.Left);
77          foreach (ClientInfo ci in clientManager.GetAllClients().List) {
78            tvClientControl.Nodes[tvClientControl.Nodes.Count - 1].Nodes.Add(ci.Name);
79            lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvg));
80            count = (count + 1) % 3;
81          }
82          lvClientControl.Groups.Add(lvg);
83        } // Groups
84
85        clientInfo = clientManager.GetAllClients();
86        ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
87        foreach (ClientInfo ci in clientInfo.List) {
88          tvClientControl.Nodes.Add(ci.Name);
89          lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvunsorted));
90          count = (count + 1) % 3;
91        }
92        lvClientControl.Groups.Add(lvunsorted);
93      }
94      catch (Exception ex) {
95        closeFormEvent(true, true);
96        this.Close();
97      }
98    }
99
100    private void AddJobs() {
101      try {
102        IJobManager jobManager =
103          ServiceLocator.GetJobManager();
104        jobs = jobManager.GetAllJobs();
105
106        lvJobControl.Items.Clear();
107        tvJobControl.Nodes.Clear();
108
109        ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left);
110        ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left);
111        ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left);
112        tvJobControl.Nodes.Add("calculating");
113        tvJobControl.Nodes.Add("finished");
114        tvJobControl.Nodes.Add("pending");
115        foreach (Job job in jobs.List) {
116          if (job.State == State.calculating) {
117            tvJobControl.Nodes[0].Nodes.Add(job.Id.ToString());
118            lvJobControl.Items.Add(new ListViewItem(job.Id.ToString(), 0, lvJobCalculating));
119          } else if (job.State == State.finished) {
120            tvJobControl.Nodes[1].Nodes.Add(job.Id.ToString());
121            lvJobControl.Items.Add(new ListViewItem(job.Id.ToString(), 0, lvJobFinished));
122          } else if (job.State == State.offline) {
123            tvJobControl.Nodes[2].Nodes.Add(job.Id.ToString());
124            lvJobControl.Items.Add(new ListViewItem(job.Id.ToString(), 0, lvJobPending));
125          }
126        } // Jobs
127        lvJobControl.Groups.Add(lvJobCalculating);
128        lvJobControl.Groups.Add(lvJobFinished);
129        lvJobControl.Groups.Add(lvJobPending);
130      }
131      catch (Exception ex) {
132        closeFormEvent(true, true);
133        this.Close();
134      }
135    }
136
137    private void AddUsers() {
138      try {
139        IUserRoleManager userRoleManager =
140          ServiceLocator.GetUserRoleManager();
141
142        userGroups = userRoleManager.GetAllUserGroups();
143
144        lvUserControl.Items.Clear();
145        tvUserControl.Nodes.Clear();
146
147        foreach (UserGroup ug in userGroups.List) {
148          tvUserControl.Nodes.Add(ug.Name);
149          ListViewGroup lvg = new ListViewGroup(ug.Name, HorizontalAlignment.Left);
150
151          foreach (PermissionOwner permOwner in ug.Members) {
152            if (permOwner is User) {
153              User users = permOwner as User;
154              tvUserControl.Nodes[tvUserControl.Nodes.Count - 1].Nodes.Add(users.Name);
155              lvUserControl.Items.Add(new ListViewItem(users.Name, 0, lvg));
156            }
157          }
158          lvUserControl.Groups.Add(lvg);
159
160        } // Users
161        usersList = userRoleManager.GetAllUsers();
162        ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
163        foreach (User u in usersList.List) {
164          tvUserControl.Nodes.Add(u.Name);
165          lvUserControl.Items.Add(new ListViewItem(u.Name, 0, lvunsorted));
166        }
167        lvUserControl.Groups.Add(lvunsorted);
168      }
169      catch (Exception ex) {
170        closeFormEvent(true, true);
171        this.Close();
172      }
173
174    }
175
176    /// <summary>
177    /// Send event to Login-GUI when closing
178    /// </summary>
179    /// <param name="sender"></param>
180    /// <param name="e"></param>
181    private void Close_Click(object sender, EventArgs e) {
182      if (closeFormEvent != null) {
183        closeFormEvent(true, false);
184      }
185      this.Close();
186    }
187
188    /// <summary>
189    /// Send evnt to Login-GUI when closing
190    /// </summary>
191    /// <param name="sender"></param>
192    /// <param name="e"></param>
193    private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
194      if (closeFormEvent != null) {
195        closeFormEvent(true, false);
196      }
197
198    }
199
200    private void JobToolStripMenuItem1_Click(object sender, EventArgs e) {
201      AddJobForm newForm = new AddJobForm();
202      newForm.Show();
203    }
204
205    private void UserToolStripMenuItem1_Click(object sender, EventArgs e) {
206      AddUserForm newForm = new AddUserForm("User", false);
207      newForm.Show();
208    }
209
210    private void GroupToolStripMenuItem2_Click(object sender, EventArgs e) {
211      AddUserForm newForm = new AddUserForm("User", true);
212      newForm.Show();
213
214    }
215
216  }
217}
Note: See TracBrowser for help on using the repository browser.