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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Data;
|
---|
26 | using System.Drawing;
|
---|
27 | using System.Linq;
|
---|
28 | using System.Text;
|
---|
29 | using System.Windows.Forms;
|
---|
30 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
31 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
32 | using HeuristicLab.Hive.Contracts;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.Hive.Server.ServerConsole {
|
---|
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 | ListView lvClientDetails = null;
|
---|
48 |
|
---|
49 | Job currentJob = null;
|
---|
50 | ClientInfo currentClient = null;
|
---|
51 | User currentUser = null;
|
---|
52 |
|
---|
53 | public HiveServerManagementConsole() {
|
---|
54 | InitializeComponent();
|
---|
55 | AddClients();
|
---|
56 | AddJobs();
|
---|
57 | AddUsers();
|
---|
58 |
|
---|
59 | timerSyncronize.Tick += new EventHandler(TickSync);
|
---|
60 | timerSyncronize.Start();
|
---|
61 | }
|
---|
62 |
|
---|
63 | private void TickSync(object obj, EventArgs e) {
|
---|
64 | AddClients();
|
---|
65 | AddJobs();
|
---|
66 | AddUsers();
|
---|
67 | }
|
---|
68 |
|
---|
69 | private void AddClients() {
|
---|
70 | try {
|
---|
71 | IClientManager clientManager =
|
---|
72 | ServiceLocator.GetClientManager();
|
---|
73 |
|
---|
74 | clients = clientManager.GetAllClientGroups();
|
---|
75 |
|
---|
76 | lvClientControl.Items.Clear();
|
---|
77 | tvClientControl.Nodes.Clear();
|
---|
78 | int count = 0;
|
---|
79 | foreach (ClientGroup cg in clients.List) {
|
---|
80 | tvClientControl.Nodes.Add(cg.Name);
|
---|
81 | ListViewGroup lvg = new ListViewGroup(cg.Name, HorizontalAlignment.Left);
|
---|
82 | foreach (ClientInfo ci in clientManager.GetAllClients().List) {
|
---|
83 | tvClientControl.Nodes[tvClientControl.Nodes.Count - 1].Nodes.Add(ci.Name);
|
---|
84 | lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvg));
|
---|
85 | count = (count + 1) % 3;
|
---|
86 | }
|
---|
87 | lvClientControl.Groups.Add(lvg);
|
---|
88 | } // Groups
|
---|
89 |
|
---|
90 | clientInfo = clientManager.GetAllClients();
|
---|
91 | ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
|
---|
92 | foreach (ClientInfo ci in clientInfo.List) {
|
---|
93 | tvClientControl.Nodes.Add(ci.Name);
|
---|
94 | lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvunsorted));
|
---|
95 | count = (count + 1) % 3;
|
---|
96 | }
|
---|
97 | lvClientControl.Groups.Add(lvunsorted);
|
---|
98 | }
|
---|
99 | catch (Exception ex) {
|
---|
100 | closeFormEvent(true, true);
|
---|
101 | this.Close();
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | private void AddJobs() {
|
---|
106 | try {
|
---|
107 | IJobManager jobManager =
|
---|
108 | ServiceLocator.GetJobManager();
|
---|
109 | jobs = jobManager.GetAllJobs();
|
---|
110 |
|
---|
111 | lvJobControl.Items.Clear();
|
---|
112 | tvJobControl.Nodes.Clear();
|
---|
113 |
|
---|
114 | ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left);
|
---|
115 | ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left);
|
---|
116 | ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left);
|
---|
117 | tvJobControl.Nodes.Add("calculating");
|
---|
118 | tvJobControl.Nodes.Add("finished");
|
---|
119 | tvJobControl.Nodes.Add("pending");
|
---|
120 | foreach (Job job in jobs.List) {
|
---|
121 | if (job.State == State.calculating) {
|
---|
122 | tvJobControl.Nodes[0].Nodes.Add(job.Id.ToString());
|
---|
123 | lvJobControl.Items.Add(new ListViewItem(job.Id.ToString(), 0, lvJobCalculating));
|
---|
124 | } else if (job.State == State.finished) {
|
---|
125 | tvJobControl.Nodes[1].Nodes.Add(job.Id.ToString());
|
---|
126 | lvJobControl.Items.Add(new ListViewItem(job.Id.ToString(), 0, lvJobFinished));
|
---|
127 | } else if (job.State == State.offline) {
|
---|
128 | tvJobControl.Nodes[2].Nodes.Add(job.Id.ToString());
|
---|
129 | lvJobControl.Items.Add(new ListViewItem(job.Id.ToString(), 0, lvJobPending));
|
---|
130 | }
|
---|
131 | } // Jobs
|
---|
132 | lvJobControl.Groups.Add(lvJobCalculating);
|
---|
133 | lvJobControl.Groups.Add(lvJobFinished);
|
---|
134 | lvJobControl.Groups.Add(lvJobPending);
|
---|
135 | }
|
---|
136 | catch (Exception ex) {
|
---|
137 | closeFormEvent(true, true);
|
---|
138 | this.Close();
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | private void AddUsers() {
|
---|
143 | try {
|
---|
144 | IUserRoleManager userRoleManager =
|
---|
145 | ServiceLocator.GetUserRoleManager();
|
---|
146 |
|
---|
147 | userGroups = userRoleManager.GetAllUserGroups();
|
---|
148 |
|
---|
149 | lvUserControl.Items.Clear();
|
---|
150 | tvUserControl.Nodes.Clear();
|
---|
151 |
|
---|
152 | foreach (UserGroup ug in userGroups.List) {
|
---|
153 | tvUserControl.Nodes.Add(ug.Name);
|
---|
154 | ListViewGroup lvg = new ListViewGroup(ug.Name, HorizontalAlignment.Left);
|
---|
155 |
|
---|
156 | foreach (PermissionOwner permOwner in ug.Members) {
|
---|
157 | if (permOwner is User) {
|
---|
158 | User users = permOwner as User;
|
---|
159 | tvUserControl.Nodes[tvUserControl.Nodes.Count - 1].Nodes.Add(users.Name);
|
---|
160 | lvUserControl.Items.Add(new ListViewItem(users.Name, 0, lvg));
|
---|
161 | }
|
---|
162 | }
|
---|
163 | lvUserControl.Groups.Add(lvg);
|
---|
164 |
|
---|
165 | } // Users
|
---|
166 | usersList = userRoleManager.GetAllUsers();
|
---|
167 | ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
|
---|
168 | foreach (User u in usersList.List) {
|
---|
169 | tvUserControl.Nodes.Add(u.Name);
|
---|
170 | lvUserControl.Items.Add(new ListViewItem(u.Name, 0, lvunsorted));
|
---|
171 | }
|
---|
172 | lvUserControl.Groups.Add(lvunsorted);
|
---|
173 | }
|
---|
174 | catch (Exception ex) {
|
---|
175 | closeFormEvent(true, true);
|
---|
176 | this.Close();
|
---|
177 | }
|
---|
178 | }
|
---|
179 |
|
---|
180 | /// <summary>
|
---|
181 | /// Send event to Login-GUI when closing
|
---|
182 | /// </summary>
|
---|
183 | /// <param name="sender"></param>
|
---|
184 | /// <param name="e"></param>
|
---|
185 | private void Close_Click(object sender, EventArgs e) {
|
---|
186 | if (closeFormEvent != null) {
|
---|
187 | closeFormEvent(true, false);
|
---|
188 | }
|
---|
189 | this.Close();
|
---|
190 | }
|
---|
191 |
|
---|
192 | /// <summary>
|
---|
193 | /// Send evnt to Login-GUI when closing
|
---|
194 | /// </summary>
|
---|
195 | /// <param name="sender"></param>
|
---|
196 | /// <param name="e"></param>
|
---|
197 | private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
|
---|
198 | if (closeFormEvent != null) {
|
---|
199 | closeFormEvent(true, false);
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | private void JobToolStripMenuItem1_Click(object sender, EventArgs e) {
|
---|
204 | AddJobForm newForm = new AddJobForm();
|
---|
205 | newForm.Show();
|
---|
206 | }
|
---|
207 |
|
---|
208 | private void UserToolStripMenuItem1_Click(object sender, EventArgs e) {
|
---|
209 | AddUserForm newForm = new AddUserForm("User", false);
|
---|
210 | newForm.Show();
|
---|
211 | }
|
---|
212 |
|
---|
213 | private void GroupToolStripMenuItem2_Click(object sender, EventArgs e) {
|
---|
214 | AddUserForm newForm = new AddUserForm("User", true);
|
---|
215 | newForm.Show();
|
---|
216 |
|
---|
217 | }
|
---|
218 |
|
---|
219 | private void OnLVClientClicked(object sender, EventArgs e) {
|
---|
220 | currentClient = clientInfo.List[lvClientControl.SelectedItems[0].Index];
|
---|
221 | ClientClicked();
|
---|
222 | }
|
---|
223 |
|
---|
224 | private void OnTVClientClicked(object sender, EventArgs e) {
|
---|
225 | // currentClient = clientInfo.List[tvClientControl.SelectedNode.Index];
|
---|
226 | // ClientClicked();
|
---|
227 | }
|
---|
228 |
|
---|
229 | private void ClientClicked() {
|
---|
230 | scClientControl.Panel2.Controls.Clear();
|
---|
231 | scClientControl.Panel2.Controls.Add(plClientDetails);
|
---|
232 | pbClientControl.Image = ilClientControl.Images[0];
|
---|
233 | lblClientName.Text = currentClient.Name;
|
---|
234 | lblLogin.Text = currentClient.Login.ToString();
|
---|
235 | }
|
---|
236 |
|
---|
237 | private void btnClientClose_Click(object sender, EventArgs e) {
|
---|
238 | scClientControl.Panel2.Controls.Clear();
|
---|
239 | scClientControl.Panel2.Controls.Add(lvClientControl);
|
---|
240 | }
|
---|
241 |
|
---|
242 | private void OnLVJobControlClicked(object sender, EventArgs e) {
|
---|
243 | currentJob = jobs.List[lvJobControl.SelectedItems[0].Index];
|
---|
244 | JobClicked();
|
---|
245 |
|
---|
246 | }
|
---|
247 | private void JobClicked() {
|
---|
248 | scJobControl.Panel2.Controls.Clear();
|
---|
249 | scJobControl.Panel2.Controls.Add(plJobDetails);
|
---|
250 | pbJobControl.Image = ilJobControl.Images[0];
|
---|
251 | lblJobName.Text = currentJob.Id.ToString();
|
---|
252 | }
|
---|
253 |
|
---|
254 | private void btnJobDetailClose_Click(object sender, EventArgs e) {
|
---|
255 | scJobControl.Panel2.Controls.Clear();
|
---|
256 | scJobControl.Panel2.Controls.Add(lvJobControl);
|
---|
257 | }
|
---|
258 |
|
---|
259 | private void OnLVUserControlClicked(object sender, EventArgs e) {
|
---|
260 | currentUser = usersList.List[lvUserControl.SelectedItems[0].Index];
|
---|
261 | UserClicked();
|
---|
262 | }
|
---|
263 |
|
---|
264 | private void UserClicked() {
|
---|
265 | scUserControl.Panel2.Controls.Clear();
|
---|
266 | scUserControl.Panel2.Controls.Add(plUserDetails);
|
---|
267 | pbUserControl.Image = ilUserControl.Images[0];
|
---|
268 | lblUserName.Text = currentUser.Id.ToString();
|
---|
269 | }
|
---|
270 |
|
---|
271 | private void btnUserControlClose_Click(object sender, EventArgs e) {
|
---|
272 | scUserControl.Panel2.Controls.Clear();
|
---|
273 | scUserControl.Panel2.Controls.Add(lvUserControl);
|
---|
274 | }
|
---|
275 |
|
---|
276 | }
|
---|
277 | } |
---|