[794] | 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;
|
---|
[831] | 30 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
| 31 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
[904] | 32 | using HeuristicLab.Hive.Contracts;
|
---|
[794] | 33 |
|
---|
[1089] | 34 | namespace HeuristicLab.Hive.Server.ServerConsole {
|
---|
[794] | 35 |
|
---|
[1030] | 36 | public delegate void closeForm(bool cf, bool error);
|
---|
[794] | 37 |
|
---|
| 38 | public partial class HiveServerManagementConsole : Form {
|
---|
| 39 |
|
---|
| 40 | public event closeForm closeFormEvent;
|
---|
| 41 |
|
---|
[1136] | 42 | #region private variables
|
---|
| 43 | private ResponseList<ClientGroup> clients = null;
|
---|
| 44 | private ResponseList<ClientInfo> clientInfo = null;
|
---|
| 45 | private ResponseList<Job> jobs = null;
|
---|
| 46 | private ResponseList<UserGroup> userGroups = null;
|
---|
| 47 | private ResponseList<User> usersList = null;
|
---|
[844] | 48 |
|
---|
[1136] | 49 | private Job currentJob = null;
|
---|
| 50 | private ClientInfo currentClient = null;
|
---|
| 51 | private User currentUser = null;
|
---|
[1148] | 52 | private string nameCurrentJob = "";
|
---|
| 53 | private string nameCurrentClient = "";
|
---|
| 54 | private string nameCurrentUser = "";
|
---|
[1136] | 55 | private bool flagJob = false;
|
---|
| 56 | private bool flagClient = false;
|
---|
| 57 | private bool flagUser = false;
|
---|
[1098] | 58 |
|
---|
[1136] | 59 | private ToolTip tt = new ToolTip();
|
---|
| 60 | #endregion
|
---|
| 61 |
|
---|
[794] | 62 | public HiveServerManagementConsole() {
|
---|
| 63 | InitializeComponent();
|
---|
[1037] | 64 | AddClients();
|
---|
| 65 | AddJobs();
|
---|
| 66 | AddUsers();
|
---|
[1018] | 67 | timerSyncronize.Start();
|
---|
[844] | 68 | }
|
---|
[831] | 69 |
|
---|
[1136] | 70 | /// <summary>
|
---|
| 71 | /// event on Ticker
|
---|
| 72 | /// </summary>
|
---|
| 73 | /// <param name="obj"></param>
|
---|
| 74 | /// <param name="e"></param>
|
---|
[1037] | 75 | private void TickSync(object obj, EventArgs e) {
|
---|
| 76 | AddClients();
|
---|
| 77 | AddJobs();
|
---|
| 78 | AddUsers();
|
---|
[1018] | 79 | }
|
---|
| 80 |
|
---|
[1136] | 81 | /// <summary>
|
---|
| 82 | /// Adds clients to ListView and TreeView
|
---|
| 83 | /// </summary>
|
---|
[1037] | 84 | private void AddClients() {
|
---|
[1030] | 85 | try {
|
---|
| 86 | IClientManager clientManager =
|
---|
| 87 | ServiceLocator.GetClientManager();
|
---|
[831] | 88 |
|
---|
[1030] | 89 | clients = clientManager.GetAllClientGroups();
|
---|
[978] | 90 |
|
---|
[1030] | 91 | lvClientControl.Items.Clear();
|
---|
| 92 | tvClientControl.Nodes.Clear();
|
---|
| 93 | int count = 0;
|
---|
| 94 | foreach (ClientGroup cg in clients.List) {
|
---|
| 95 | tvClientControl.Nodes.Add(cg.Name);
|
---|
| 96 | ListViewGroup lvg = new ListViewGroup(cg.Name, HorizontalAlignment.Left);
|
---|
| 97 | foreach (ClientInfo ci in clientManager.GetAllClients().List) {
|
---|
| 98 | tvClientControl.Nodes[tvClientControl.Nodes.Count - 1].Nodes.Add(ci.Name);
|
---|
| 99 | lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvg));
|
---|
| 100 | count = (count + 1) % 3;
|
---|
| 101 | }
|
---|
| 102 | lvClientControl.Groups.Add(lvg);
|
---|
| 103 | } // Groups
|
---|
| 104 |
|
---|
| 105 | clientInfo = clientManager.GetAllClients();
|
---|
| 106 | ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
|
---|
| 107 | foreach (ClientInfo ci in clientInfo.List) {
|
---|
| 108 | tvClientControl.Nodes.Add(ci.Name);
|
---|
| 109 | lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvunsorted));
|
---|
[844] | 110 | count = (count + 1) % 3;
|
---|
[831] | 111 | }
|
---|
[1030] | 112 | lvClientControl.Groups.Add(lvunsorted);
|
---|
[1136] | 113 | if (flagClient) {
|
---|
| 114 | ClientClicked();
|
---|
| 115 | }
|
---|
[1018] | 116 | }
|
---|
[1030] | 117 | catch (Exception ex) {
|
---|
| 118 | closeFormEvent(true, true);
|
---|
| 119 | this.Close();
|
---|
| 120 | }
|
---|
[1018] | 121 | }
|
---|
[956] | 122 |
|
---|
[1136] | 123 | /// <summary>
|
---|
| 124 | /// Adds jobs to ListView and TreeView
|
---|
| 125 | /// </summary>
|
---|
[1037] | 126 | private void AddJobs() {
|
---|
[1030] | 127 | try {
|
---|
| 128 | IJobManager jobManager =
|
---|
| 129 | ServiceLocator.GetJobManager();
|
---|
| 130 | jobs = jobManager.GetAllJobs();
|
---|
[1018] | 131 |
|
---|
[1030] | 132 | lvJobControl.Items.Clear();
|
---|
| 133 | tvJobControl.Nodes.Clear();
|
---|
[1018] | 134 |
|
---|
[1037] | 135 | ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left);
|
---|
[1030] | 136 | ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left);
|
---|
[1037] | 137 | ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left);
|
---|
| 138 | tvJobControl.Nodes.Add("calculating");
|
---|
[1030] | 139 | tvJobControl.Nodes.Add("finished");
|
---|
[1037] | 140 | tvJobControl.Nodes.Add("pending");
|
---|
[1030] | 141 | foreach (Job job in jobs.List) {
|
---|
[1037] | 142 | if (job.State == State.calculating) {
|
---|
[1126] | 143 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobCalculating);
|
---|
[1030] | 144 | tvJobControl.Nodes[0].Nodes.Add(job.Id.ToString());
|
---|
[1126] | 145 | lvJobControl.Items.Add(lvi);
|
---|
| 146 | lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated";
|
---|
[1037] | 147 | } else if (job.State == State.finished) {
|
---|
[1126] | 148 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobFinished);
|
---|
[1037] | 149 | tvJobControl.Nodes[1].Nodes.Add(job.Id.ToString());
|
---|
[1126] | 150 | lvJobControl.Items.Add(lvi);
|
---|
[1030] | 151 | } else if (job.State == State.offline) {
|
---|
[1126] | 152 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobPending);
|
---|
[1030] | 153 | tvJobControl.Nodes[2].Nodes.Add(job.Id.ToString());
|
---|
[1126] | 154 | lvJobControl.Items.Add(lvi);
|
---|
[1030] | 155 | }
|
---|
| 156 | } // Jobs
|
---|
[1037] | 157 | lvJobControl.Groups.Add(lvJobCalculating);
|
---|
[1030] | 158 | lvJobControl.Groups.Add(lvJobFinished);
|
---|
[1037] | 159 | lvJobControl.Groups.Add(lvJobPending);
|
---|
[1136] | 160 | if (flagJob) {
|
---|
| 161 | JobClicked();
|
---|
| 162 | }
|
---|
[1030] | 163 | }
|
---|
| 164 | catch (Exception ex) {
|
---|
| 165 | closeFormEvent(true, true);
|
---|
| 166 | this.Close();
|
---|
| 167 | }
|
---|
[1018] | 168 | }
|
---|
| 169 |
|
---|
[1136] | 170 | /// <summary>
|
---|
| 171 | /// Adds users to ListView and TreeView
|
---|
| 172 | /// </summary>
|
---|
[1037] | 173 | private void AddUsers() {
|
---|
[1030] | 174 | try {
|
---|
| 175 | IUserRoleManager userRoleManager =
|
---|
| 176 | ServiceLocator.GetUserRoleManager();
|
---|
[1018] | 177 |
|
---|
[1030] | 178 | userGroups = userRoleManager.GetAllUserGroups();
|
---|
[1018] | 179 |
|
---|
[1030] | 180 | lvUserControl.Items.Clear();
|
---|
| 181 | tvUserControl.Nodes.Clear();
|
---|
[1018] | 182 |
|
---|
[1030] | 183 | foreach (UserGroup ug in userGroups.List) {
|
---|
| 184 | tvUserControl.Nodes.Add(ug.Name);
|
---|
| 185 | ListViewGroup lvg = new ListViewGroup(ug.Name, HorizontalAlignment.Left);
|
---|
[956] | 186 |
|
---|
[1030] | 187 | foreach (PermissionOwner permOwner in ug.Members) {
|
---|
| 188 | if (permOwner is User) {
|
---|
| 189 | User users = permOwner as User;
|
---|
| 190 | tvUserControl.Nodes[tvUserControl.Nodes.Count - 1].Nodes.Add(users.Name);
|
---|
| 191 | lvUserControl.Items.Add(new ListViewItem(users.Name, 0, lvg));
|
---|
| 192 | }
|
---|
[1018] | 193 | }
|
---|
[1030] | 194 | lvUserControl.Groups.Add(lvg);
|
---|
| 195 |
|
---|
| 196 | } // Users
|
---|
| 197 | usersList = userRoleManager.GetAllUsers();
|
---|
| 198 | ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
|
---|
| 199 | foreach (User u in usersList.List) {
|
---|
| 200 | tvUserControl.Nodes.Add(u.Name);
|
---|
| 201 | lvUserControl.Items.Add(new ListViewItem(u.Name, 0, lvunsorted));
|
---|
[956] | 202 | }
|
---|
[1030] | 203 | lvUserControl.Groups.Add(lvunsorted);
|
---|
[1136] | 204 | if (flagUser) {
|
---|
| 205 | UserClicked();
|
---|
| 206 | }
|
---|
[1030] | 207 | }
|
---|
| 208 | catch (Exception ex) {
|
---|
| 209 | closeFormEvent(true, true);
|
---|
| 210 | this.Close();
|
---|
| 211 | }
|
---|
[794] | 212 | }
|
---|
| 213 |
|
---|
| 214 | /// <summary>
|
---|
[1136] | 215 | /// if one client is clicked, a panel is opened with the details
|
---|
| 216 | /// </summary>
|
---|
| 217 | private void ClientClicked() {
|
---|
[1148] | 218 | int i = 0;
|
---|
| 219 | while (usersList.List[i].Name != nameCurrentUser) {
|
---|
| 220 | i++;
|
---|
| 221 | }
|
---|
| 222 | currentClient = clientInfo.List[i];
|
---|
[1136] | 223 | scClientControl.Panel2.Controls.Clear();
|
---|
| 224 | scClientControl.Panel2.Controls.Add(plClientDetails);
|
---|
| 225 | pbClientControl.Image = ilClientControl.Images[0];
|
---|
| 226 | lblClientName.Text = currentClient.Name;
|
---|
| 227 | lblLogin.Text = currentClient.Login.ToString();
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | /// <summary>
|
---|
| 231 | /// if one job is clicked, a panel is opened with the details
|
---|
| 232 | /// </summary>
|
---|
| 233 | private void JobClicked() {
|
---|
[1148] | 234 | int i = 0;
|
---|
| 235 | while (jobs.List[i].Id.ToString() != nameCurrentJob) {
|
---|
| 236 | i++;
|
---|
| 237 | }
|
---|
| 238 | lvSnapshots.Enabled = false;
|
---|
[1136] | 239 | int yPos = 0;
|
---|
[1148] | 240 | currentJob = jobs.List[i];
|
---|
[1136] | 241 | scJobControl.Panel2.Controls.Clear();
|
---|
| 242 | scJobControl.Panel2.Controls.Add(plJobDetails);
|
---|
| 243 | pbJobControl.Image = ilJobControl.Images[0];
|
---|
| 244 | lblJobName.Text = currentJob.Id.ToString();
|
---|
| 245 | progressJob.Value = (int)(currentJob.Percentage * 100);
|
---|
| 246 | yPos = progressJob.Location.Y;
|
---|
| 247 | yPos += 20;
|
---|
| 248 | lblProgress.Location = new Point(
|
---|
| 249 | lblProgress.Location.X, yPos);
|
---|
| 250 | lblProgress.Text = (int)(currentJob.Percentage * 100) + "% calculated";
|
---|
| 251 | yPos += 20;
|
---|
| 252 | lblUserCreatedJob.Location = new Point(
|
---|
| 253 | lblUserCreatedJob.Location.X, yPos);
|
---|
| 254 | lblUserCreatedJob.Text = /* currentJob.User.Name + */ " created Job";
|
---|
| 255 | yPos += 20;
|
---|
| 256 | lblJobCreated.Location = new Point(
|
---|
| 257 | lblJobCreated.Location.X, yPos);
|
---|
| 258 | lblJobCreated.Text = "Created at "/* + currentJob.User.CreatedJob + */;
|
---|
| 259 | if (currentJob.ParentJob != null) {
|
---|
| 260 | yPos += 20;
|
---|
| 261 | lblParentJob.Location = new Point(
|
---|
| 262 | lblParentJob.Location.X, yPos);
|
---|
| 263 | lblParentJob.Text = currentJob.ParentJob.Id + " is parent job";
|
---|
| 264 | }
|
---|
| 265 | yPos += 20;
|
---|
| 266 | lblPriorityJob.Location = new Point(
|
---|
| 267 | lblPriorityJob.Location.X, yPos);
|
---|
| 268 | lblPriorityJob.Text = "Priority of job is " /* + currentJob.Priority */;
|
---|
| 269 | if (currentJob.Client != null) {
|
---|
| 270 | yPos += 20;
|
---|
| 271 | lblClientCalculating.Location = new Point(
|
---|
| 272 | lblClientCalculating.Location.X, yPos);
|
---|
| 273 | lblClientCalculating.Text = currentJob.Client.Name + " calculated Job";
|
---|
| 274 | yPos += 20;
|
---|
| 275 | lblJobCalculationBegin.Location = new Point(
|
---|
| 276 | lblJobCalculationBegin.Location.X, yPos);
|
---|
| 277 | lblJobCalculationBegin.Text = "Startet calculation at " /* + currentJob.User.CalculationBegin */;
|
---|
| 278 | yPos += 20;
|
---|
| 279 | lblJobCalculationEnd.Location = new Point(
|
---|
| 280 | lblJobCalculationEnd.Location.X, yPos);
|
---|
[1148] | 281 | lblJobCalculationEnd.Text = "Calculation ended at " /* + currentJob.User.CalculationEnd */;
|
---|
[1136] | 282 | }
|
---|
[1148] | 283 | if (currentJob.State != State.offline) {
|
---|
| 284 | yPos += 30;
|
---|
| 285 | lvSnapshots.Location = new Point(
|
---|
| 286 | lvSnapshots.Location.X, yPos);
|
---|
| 287 | lvSnapshots.Size = new Size(lvSnapshots.Size.Width,
|
---|
| 288 | plJobDetails.Size.Height - 10 - yPos);
|
---|
| 289 | lvSnapshots.Enabled = true;
|
---|
| 290 | }
|
---|
[1136] | 291 | }
|
---|
| 292 |
|
---|
| 293 | /// <summary>
|
---|
| 294 | /// if one user is clicked, a panel is opened with the details
|
---|
| 295 | /// </summary>
|
---|
| 296 | private void UserClicked() {
|
---|
[1148] | 297 | int i = 0;
|
---|
| 298 | while (usersList.List[i].Name != nameCurrentUser) {
|
---|
| 299 | i++;
|
---|
| 300 | }
|
---|
| 301 | currentUser = usersList.List[i];
|
---|
[1136] | 302 | scUserControl.Panel2.Controls.Clear();
|
---|
| 303 | scUserControl.Panel2.Controls.Add(plUserDetails);
|
---|
| 304 | pbUserControl.Image = ilUserControl.Images[0];
|
---|
| 305 | lblUserName.Text = currentUser.Id.ToString();
|
---|
| 306 | }
|
---|
| 307 |
|
---|
[1148] | 308 | #region Eventhandlers
|
---|
[1136] | 309 | /// <summary>
|
---|
[794] | 310 | /// Send event to Login-GUI when closing
|
---|
| 311 | /// </summary>
|
---|
| 312 | /// <param name="sender"></param>
|
---|
| 313 | /// <param name="e"></param>
|
---|
[1037] | 314 | private void Close_Click(object sender, EventArgs e) {
|
---|
[794] | 315 | if (closeFormEvent != null) {
|
---|
[1030] | 316 | closeFormEvent(true, false);
|
---|
[794] | 317 | }
|
---|
| 318 | this.Close();
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 | /// <summary>
|
---|
| 322 | /// Send evnt to Login-GUI when closing
|
---|
| 323 | /// </summary>
|
---|
| 324 | /// <param name="sender"></param>
|
---|
| 325 | /// <param name="e"></param>
|
---|
| 326 | private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
|
---|
| 327 | if (closeFormEvent != null) {
|
---|
[1030] | 328 | closeFormEvent(true, false);
|
---|
[794] | 329 | }
|
---|
| 330 | }
|
---|
[956] | 331 |
|
---|
[1136] | 332 | private void AddJob_Click(object sender, EventArgs e) {
|
---|
[1018] | 333 | AddJobForm newForm = new AddJobForm();
|
---|
[956] | 334 | newForm.Show();
|
---|
| 335 | }
|
---|
| 336 |
|
---|
[1136] | 337 | private void AddUser_Click(object sender, EventArgs e) {
|
---|
[1018] | 338 | AddUserForm newForm = new AddUserForm("User", false);
|
---|
[978] | 339 | newForm.Show();
|
---|
| 340 | }
|
---|
| 341 |
|
---|
[1136] | 342 | private void AddUserGroup_Click(object sender, EventArgs e) {
|
---|
[1018] | 343 | AddUserForm newForm = new AddUserForm("User", true);
|
---|
[978] | 344 | newForm.Show();
|
---|
| 345 | }
|
---|
| 346 |
|
---|
[1098] | 347 | private void OnLVClientClicked(object sender, EventArgs e) {
|
---|
[1148] | 348 | nameCurrentClient = lvClientControl.SelectedItems[0].Text;
|
---|
[1136] | 349 | flagClient = true;
|
---|
[1098] | 350 | ClientClicked();
|
---|
| 351 | }
|
---|
| 352 |
|
---|
[1136] | 353 | private void OnLVJobControlClicked(object sender, EventArgs e) {
|
---|
[1148] | 354 | nameCurrentJob = lvJobControl.SelectedItems[0].Text;
|
---|
[1136] | 355 | flagJob = true;
|
---|
| 356 | JobClicked();
|
---|
[1098] | 357 | }
|
---|
| 358 |
|
---|
[1148] | 359 | private void OnTVJobControlClicked(object sender, EventArgs e) {
|
---|
| 360 | try {
|
---|
| 361 | nameCurrentJob = Convert.ToInt32(tvJobControl.SelectedNode.Text).ToString();
|
---|
| 362 | flagJob = true;
|
---|
| 363 | JobClicked();
|
---|
| 364 | }
|
---|
| 365 | catch (Exception ex) { }
|
---|
| 366 |
|
---|
| 367 | }
|
---|
| 368 |
|
---|
[1136] | 369 | private void OnLVUserControlClicked(object sender, EventArgs e) {
|
---|
[1148] | 370 | nameCurrentUser = lvUserControl.SelectedItems[0].Name;
|
---|
[1136] | 371 | flagUser = true;
|
---|
| 372 | UserClicked();
|
---|
[1089] | 373 | }
|
---|
| 374 |
|
---|
[1098] | 375 | private void btnClientClose_Click(object sender, EventArgs e) {
|
---|
[1089] | 376 | scClientControl.Panel2.Controls.Clear();
|
---|
| 377 | scClientControl.Panel2.Controls.Add(lvClientControl);
|
---|
[1136] | 378 | flagClient = false;
|
---|
[1089] | 379 | }
|
---|
[1136] | 380 |
|
---|
[1098] | 381 | private void btnJobDetailClose_Click(object sender, EventArgs e) {
|
---|
| 382 | scJobControl.Panel2.Controls.Clear();
|
---|
| 383 | scJobControl.Panel2.Controls.Add(lvJobControl);
|
---|
[1136] | 384 | flagJob = false;
|
---|
[1098] | 385 | }
|
---|
| 386 |
|
---|
| 387 | private void btnUserControlClose_Click(object sender, EventArgs e) {
|
---|
| 388 | scUserControl.Panel2.Controls.Clear();
|
---|
| 389 | scUserControl.Panel2.Controls.Add(lvUserControl);
|
---|
[1136] | 390 | flagUser = false;
|
---|
[1098] | 391 | }
|
---|
| 392 |
|
---|
[1126] | 393 | private void lvJobControl_MouseMove(object sender, MouseEventArgs e) {
|
---|
| 394 | if ((lvJobControl.GetItemAt(e.X, e.Y) != null) &&
|
---|
| 395 | (lvJobControl.GetItemAt(e.X, e.Y).ToolTipText != null)) {
|
---|
| 396 | tt.SetToolTip(lvJobControl, lvJobControl.GetItemAt(e.X, e.Y).ToolTipText);
|
---|
| 397 | }
|
---|
| 398 | }
|
---|
[1136] | 399 | #endregion
|
---|
[794] | 400 | }
|
---|
[844] | 401 | } |
---|