Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1136 was 1136, checked in by aleitner, 15 years ago

updated job-detail panel (#452)

File size: 13.0 KB
RevLine 
[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
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;
[831]30using HeuristicLab.Hive.Contracts.Interfaces;
31using HeuristicLab.Hive.Contracts.BusinessObjects;
[904]32using HeuristicLab.Hive.Contracts;
[794]33
[1089]34namespace 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;
52    private int idxCurrentJob = 0;
53    private int idxCurrentClient = 0;
54    private int idxCurrentUser = 0;
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() {
218      currentClient = clientInfo.List[idxCurrentClient];
219      scClientControl.Panel2.Controls.Clear();
220      scClientControl.Panel2.Controls.Add(plClientDetails);
221      pbClientControl.Image = ilClientControl.Images[0];
222      lblClientName.Text = currentClient.Name;
223      lblLogin.Text = currentClient.Login.ToString();
224    }
225
226    /// <summary>
227    /// if one job is clicked, a panel is opened with the details
228    /// </summary>
229    private void JobClicked() {
230      int yPos = 0;
231      currentJob = jobs.List[idxCurrentJob];
232      scJobControl.Panel2.Controls.Clear();
233      scJobControl.Panel2.Controls.Add(plJobDetails);
234      pbJobControl.Image = ilJobControl.Images[0];
235      lblJobName.Text = currentJob.Id.ToString();
236      progressJob.Value = (int)(currentJob.Percentage * 100);
237      yPos = progressJob.Location.Y;
238      yPos += 20;
239      lblProgress.Location = new Point(
240        lblProgress.Location.X, yPos);
241      lblProgress.Text = (int)(currentJob.Percentage * 100) + "% calculated";
242      yPos += 20;
243      lblUserCreatedJob.Location = new Point(
244        lblUserCreatedJob.Location.X, yPos);
245      lblUserCreatedJob.Text = /* currentJob.User.Name + */ " created Job";
246      yPos += 20;
247      lblJobCreated.Location = new Point(
248        lblJobCreated.Location.X, yPos);
249      lblJobCreated.Text = "Created at "/* + currentJob.User.CreatedJob + */;
250      if (currentJob.ParentJob != null) {
251        yPos += 20;
252        lblParentJob.Location = new Point(
253          lblParentJob.Location.X, yPos);
254        lblParentJob.Text = currentJob.ParentJob.Id + " is parent job";
255      }
256      yPos += 20;
257      lblPriorityJob.Location = new Point(
258        lblPriorityJob.Location.X, yPos);
259      lblPriorityJob.Text = "Priority of job is " /* + currentJob.Priority */;
260      if (currentJob.Client != null) {
261        yPos += 20;
262        lblClientCalculating.Location = new Point(
263          lblClientCalculating.Location.X, yPos);
264        lblClientCalculating.Text = currentJob.Client.Name + " calculated Job";
265        yPos += 20;
266        lblJobCalculationBegin.Location = new Point(
267          lblJobCalculationBegin.Location.X, yPos);
268        lblJobCalculationBegin.Text = "Startet calculation at " /* + currentJob.User.CalculationBegin */;
269        yPos += 20;
270        lblJobCalculationEnd.Location = new Point(
271          lblJobCalculationEnd.Location.X, yPos);
272        lblJobCalculationEnd.Text = "Calculation endet at " /* + currentJob.User.CalculationEnd */;
273      }
274    }
275
276    /// <summary>
277    /// if one user is clicked, a panel is opened with the details
278    /// </summary>
279    private void UserClicked() {
280      currentUser = usersList.List[idxCurrentUser];
281      scUserControl.Panel2.Controls.Clear();
282      scUserControl.Panel2.Controls.Add(plUserDetails);
283      pbUserControl.Image = ilUserControl.Images[0];
284      lblUserName.Text = currentUser.Id.ToString();
285    }
286
287    #region Eventhandler
288    /// <summary>
[794]289    /// Send event to Login-GUI when closing
290    /// </summary>
291    /// <param name="sender"></param>
292    /// <param name="e"></param>
[1037]293    private void Close_Click(object sender, EventArgs e) {
[794]294      if (closeFormEvent != null) {
[1030]295        closeFormEvent(true, false);
[794]296      }
297      this.Close();
298    }
299
300    /// <summary>
301    /// Send evnt to Login-GUI when closing
302    /// </summary>
303    /// <param name="sender"></param>
304    /// <param name="e"></param>
305    private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
306      if (closeFormEvent != null) {
[1030]307        closeFormEvent(true, false);
[794]308      }
309    }
[956]310
[1136]311    private void AddJob_Click(object sender, EventArgs e) {
[1018]312      AddJobForm newForm = new AddJobForm();
[956]313      newForm.Show();
314    }
315
[1136]316    private void AddUser_Click(object sender, EventArgs e) {
[1018]317      AddUserForm newForm = new AddUserForm("User", false);
[978]318      newForm.Show();
319    }
320
[1136]321    private void AddUserGroup_Click(object sender, EventArgs e) {
[1018]322      AddUserForm newForm = new AddUserForm("User", true);
[978]323      newForm.Show();
324    }
325
[1098]326    private void OnLVClientClicked(object sender, EventArgs e) {
[1136]327      idxCurrentClient = lvClientControl.SelectedItems[0].Index;
328      flagClient = true;
[1098]329      ClientClicked();
330    }
331
[1136]332    private void OnLVJobControlClicked(object sender, EventArgs e) {
333      idxCurrentJob = lvJobControl.SelectedItems[0].Index;
334      flagJob = true;
335      JobClicked();
[1098]336    }
337
[1136]338    private void OnLVUserControlClicked(object sender, EventArgs e) {
339      idxCurrentUser = lvUserControl.SelectedItems[0].Index;
340      flagUser = true;
341      UserClicked();
[1089]342    }
343
[1098]344    private void btnClientClose_Click(object sender, EventArgs e) {
[1089]345      scClientControl.Panel2.Controls.Clear();
346      scClientControl.Panel2.Controls.Add(lvClientControl);
[1136]347      flagClient = false;
[1089]348    }
[1136]349 
[1098]350    private void btnJobDetailClose_Click(object sender, EventArgs e) {
351      scJobControl.Panel2.Controls.Clear();
352      scJobControl.Panel2.Controls.Add(lvJobControl);
[1136]353      flagJob = false;
[1098]354    }
355
356    private void btnUserControlClose_Click(object sender, EventArgs e) {
357      scUserControl.Panel2.Controls.Clear();
358      scUserControl.Panel2.Controls.Add(lvUserControl);
[1136]359      flagUser = false;
[1098]360    }
361
[1126]362    private void lvJobControl_MouseMove(object sender, MouseEventArgs e) {
363      if ((lvJobControl.GetItemAt(e.X, e.Y) != null) &&
364        (lvJobControl.GetItemAt(e.X, e.Y).ToolTipText != null)) {
365        tt.SetToolTip(lvJobControl, lvJobControl.GetItemAt(e.X, e.Y).ToolTipText);
366      }
367    }
[1136]368    #endregion
[794]369  }
[844]370}
Note: See TracBrowser for help on using the repository browser.