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

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

updated job-detail panel (#452)

File size: 13.0 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.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    #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;
48
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;
58
59    private ToolTip tt = new ToolTip();
60    #endregion
61
62    public HiveServerManagementConsole() {
63      InitializeComponent();
64      AddClients();
65      AddJobs();
66      AddUsers();
67      timerSyncronize.Start();
68    }
69
70    /// <summary>
71    /// event on Ticker
72    /// </summary>
73    /// <param name="obj"></param>
74    /// <param name="e"></param>
75    private void TickSync(object obj, EventArgs e) {
76      AddClients();
77      AddJobs();
78      AddUsers();
79    }
80
81    /// <summary>
82    /// Adds clients to ListView and TreeView
83    /// </summary>
84    private void AddClients() {
85      try {
86        IClientManager clientManager =
87          ServiceLocator.GetClientManager();
88
89        clients = clientManager.GetAllClientGroups();
90
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));
110          count = (count + 1) % 3;
111        }
112        lvClientControl.Groups.Add(lvunsorted);
113        if (flagClient) {
114          ClientClicked();
115        }
116      }
117      catch (Exception ex) {
118        closeFormEvent(true, true);
119        this.Close();
120      }
121    }
122
123    /// <summary>
124    /// Adds jobs to ListView and TreeView
125    /// </summary>
126    private void AddJobs() {
127      try {
128        IJobManager jobManager =
129          ServiceLocator.GetJobManager();
130        jobs = jobManager.GetAllJobs();
131
132        lvJobControl.Items.Clear();
133        tvJobControl.Nodes.Clear();
134
135        ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left);
136        ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left);
137        ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left);
138        tvJobControl.Nodes.Add("calculating");
139        tvJobControl.Nodes.Add("finished");
140        tvJobControl.Nodes.Add("pending");
141        foreach (Job job in jobs.List) {
142          if (job.State == State.calculating) {
143            ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobCalculating);
144            tvJobControl.Nodes[0].Nodes.Add(job.Id.ToString());
145            lvJobControl.Items.Add(lvi);
146            lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated";
147          } else if (job.State == State.finished) {
148            ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobFinished);
149            tvJobControl.Nodes[1].Nodes.Add(job.Id.ToString());
150            lvJobControl.Items.Add(lvi);
151          } else if (job.State == State.offline) {
152            ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobPending);
153            tvJobControl.Nodes[2].Nodes.Add(job.Id.ToString());
154            lvJobControl.Items.Add(lvi);
155          }
156        } // Jobs
157        lvJobControl.Groups.Add(lvJobCalculating);
158        lvJobControl.Groups.Add(lvJobFinished);
159        lvJobControl.Groups.Add(lvJobPending);
160        if (flagJob) {
161          JobClicked();
162        }
163      }
164      catch (Exception ex) {
165        closeFormEvent(true, true);
166        this.Close();
167      }
168    }
169
170    /// <summary>
171    /// Adds users to ListView and TreeView
172    /// </summary>
173    private void AddUsers() {
174      try {
175        IUserRoleManager userRoleManager =
176          ServiceLocator.GetUserRoleManager();
177
178        userGroups = userRoleManager.GetAllUserGroups();
179
180        lvUserControl.Items.Clear();
181        tvUserControl.Nodes.Clear();
182
183        foreach (UserGroup ug in userGroups.List) {
184          tvUserControl.Nodes.Add(ug.Name);
185          ListViewGroup lvg = new ListViewGroup(ug.Name, HorizontalAlignment.Left);
186
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            }
193          }
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));
202        }
203        lvUserControl.Groups.Add(lvunsorted);
204        if (flagUser) {
205          UserClicked();
206        }
207      }
208      catch (Exception ex) {
209        closeFormEvent(true, true);
210        this.Close();
211      }
212    }
213
214    /// <summary>
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>
289    /// Send event to Login-GUI when closing
290    /// </summary>
291    /// <param name="sender"></param>
292    /// <param name="e"></param>
293    private void Close_Click(object sender, EventArgs e) {
294      if (closeFormEvent != null) {
295        closeFormEvent(true, false);
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) {
307        closeFormEvent(true, false);
308      }
309    }
310
311    private void AddJob_Click(object sender, EventArgs e) {
312      AddJobForm newForm = new AddJobForm();
313      newForm.Show();
314    }
315
316    private void AddUser_Click(object sender, EventArgs e) {
317      AddUserForm newForm = new AddUserForm("User", false);
318      newForm.Show();
319    }
320
321    private void AddUserGroup_Click(object sender, EventArgs e) {
322      AddUserForm newForm = new AddUserForm("User", true);
323      newForm.Show();
324    }
325
326    private void OnLVClientClicked(object sender, EventArgs e) {
327      idxCurrentClient = lvClientControl.SelectedItems[0].Index;
328      flagClient = true;
329      ClientClicked();
330    }
331
332    private void OnLVJobControlClicked(object sender, EventArgs e) {
333      idxCurrentJob = lvJobControl.SelectedItems[0].Index;
334      flagJob = true;
335      JobClicked();
336    }
337
338    private void OnLVUserControlClicked(object sender, EventArgs e) {
339      idxCurrentUser = lvUserControl.SelectedItems[0].Index;
340      flagUser = true;
341      UserClicked();
342    }
343
344    private void btnClientClose_Click(object sender, EventArgs e) {
345      scClientControl.Panel2.Controls.Clear();
346      scClientControl.Panel2.Controls.Add(lvClientControl);
347      flagClient = false;
348    }
349 
350    private void btnJobDetailClose_Click(object sender, EventArgs e) {
351      scJobControl.Panel2.Controls.Clear();
352      scJobControl.Panel2.Controls.Add(lvJobControl);
353      flagJob = false;
354    }
355
356    private void btnUserControlClose_Click(object sender, EventArgs e) {
357      scUserControl.Panel2.Controls.Clear();
358      scUserControl.Panel2.Controls.Add(lvUserControl);
359      flagUser = false;
360    }
361
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    }
368    #endregion
369  }
370}
Note: See TracBrowser for help on using the repository browser.