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

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

updated details panels, onclick methods on TreeView (#452)

File size: 15.1 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 string nameCurrentJob = "";
53    private string nameCurrentClient = "";
54    private string nameCurrentUser = "";
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      int i = 0;
219      while (clientInfo.List[i].Name != nameCurrentClient) {
220        i++;
221      }
222      currentClient = clientInfo.List[i];
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      lblState.Text = currentClient.State.ToString();
229    }
230
231    /// <summary>
232    /// if one job is clicked, a panel is opened with the details
233    /// </summary>
234    private void JobClicked() {
235      int i = 0;
236      while (jobs.List[i].Id.ToString() != nameCurrentJob) {
237        i++;
238      }
239      lvSnapshots.Enabled = false;
240      int yPos = 0;
241      currentJob = jobs.List[i];
242      scJobControl.Panel2.Controls.Clear();
243      scJobControl.Panel2.Controls.Add(plJobDetails);
244      pbJobControl.Image = ilJobControl.Images[0];
245      lblJobName.Text = currentJob.Id.ToString();
246      progressJob.Value = (int)(currentJob.Percentage * 100);
247      yPos = progressJob.Location.Y;
248      yPos += 20;
249      lblProgress.Location = new Point(
250        lblProgress.Location.X, yPos);
251      lblProgress.Text = (int)(currentJob.Percentage * 100) + "% calculated";
252      yPos += 20;
253      lblUserCreatedJob.Location = new Point(
254        lblUserCreatedJob.Location.X, yPos);
255      lblUserCreatedJob.Text = /* currentJob.User.Name + */ " created Job";
256      yPos += 20;
257      lblJobCreated.Location = new Point(
258        lblJobCreated.Location.X, yPos);
259      lblJobCreated.Text = "Created at "/* + currentJob.User.CreatedJob + */;
260      if (currentJob.ParentJob != null) {
261        yPos += 20;
262        lblParentJob.Location = new Point(
263          lblParentJob.Location.X, yPos);
264        lblParentJob.Text = currentJob.ParentJob.Id + " is parent job";
265      }
266      yPos += 20;
267      lblPriorityJob.Location = new Point(
268        lblPriorityJob.Location.X, yPos);
269      lblPriorityJob.Text = "Priority of job is " /* + currentJob.Priority */;
270      if (currentJob.Client != null) {
271        yPos += 20;
272        lblClientCalculating.Location = new Point(
273          lblClientCalculating.Location.X, yPos);
274        lblClientCalculating.Text = currentJob.Client.Name + " calculated Job";
275        yPos += 20;
276        lblJobCalculationBegin.Location = new Point(
277          lblJobCalculationBegin.Location.X, yPos);
278        lblJobCalculationBegin.Text = "Startet calculation at " /* + currentJob.User.CalculationBegin */;
279        yPos += 20;
280        lblJobCalculationEnd.Location = new Point(
281          lblJobCalculationEnd.Location.X, yPos);
282        lblJobCalculationEnd.Text = "Calculation ended at " /* + currentJob.User.CalculationEnd */;
283      }
284      if (currentJob.State != State.offline) {
285        yPos += 30;
286        lvSnapshots.Location = new Point(
287          lvSnapshots.Location.X, yPos);
288        lvSnapshots.Size = new Size(lvSnapshots.Size.Width,
289          plJobDetails.Size.Height - 10 - yPos);
290        lvSnapshots.Enabled = true;
291      }
292    }
293
294    /// <summary>
295    /// if one user is clicked, a panel is opened with the details
296    /// </summary>
297    private void UserClicked() {
298      int i = 0;
299      while (usersList.List[i].Name != nameCurrentUser) {
300        i++;
301      }
302      currentUser = usersList.List[i];
303      scUserControl.Panel2.Controls.Clear();
304      scUserControl.Panel2.Controls.Add(plUserDetails);
305      pbUserControl.Image = ilUserControl.Images[0];
306      lblUserName.Text = currentUser.Id.ToString();
307    }
308
309    #region Eventhandlers
310    /// <summary>
311    /// Send event to Login-GUI when closing
312    /// </summary>
313    /// <param name="sender"></param>
314    /// <param name="e"></param>
315    private void Close_Click(object sender, EventArgs e) {
316      if (closeFormEvent != null) {
317        closeFormEvent(true, false);
318      }
319      this.Close();
320    }
321
322    /// <summary>
323    /// Send evnt to Login-GUI when closing
324    /// </summary>
325    /// <param name="sender"></param>
326    /// <param name="e"></param>
327    private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
328      if (closeFormEvent != null) {
329        closeFormEvent(true, false);
330      }
331    }
332
333    private void AddJob_Click(object sender, EventArgs e) {
334      AddJobForm newForm = new AddJobForm();
335      newForm.Show();
336      newForm.addJobEvent += new addDelegate(Refresh);
337    }
338
339    private void Refresh() {
340      AddClients();
341      AddJobs();
342      AddUsers();
343    }
344
345    private void AddUser_Click(object sender, EventArgs e) {
346      AddUserForm newForm = new AddUserForm("User", false);
347      newForm.Show();
348      newForm.addUserEvent += new addDelegate(Refresh);
349    }
350
351    private void AddUserGroup_Click(object sender, EventArgs e) {
352      AddUserForm newForm = new AddUserForm("User", true);
353      newForm.Show();
354      newForm.addUserEvent += new addDelegate(Refresh);                                             
355    }
356
357    private void OnLVClientClicked(object sender, EventArgs e) {
358      nameCurrentClient = lvClientControl.SelectedItems[0].Text;
359      flagClient = true;
360      ClientClicked();
361    }
362
363    private void OnTVClientClicked(object sender, TreeViewEventArgs e) {
364      bool clientgroup = false;
365      foreach (ClientGroup cg in clients.List) {
366        if (tvClientControl.SelectedNode.Text == cg.Name) {
367          clientgroup = true;
368        }
369      }
370      if (clientgroup == false) {
371        nameCurrentClient = tvClientControl.SelectedNode.Text;
372        flagClient = true;
373        ClientClicked();
374      }
375
376    }
377
378    private void OnLVJobControlClicked(object sender, EventArgs e) {
379      nameCurrentJob = lvJobControl.SelectedItems[0].Text;
380      flagJob = true;
381      JobClicked();
382    }
383
384    private void OnTVJobControlClicked(object sender, TreeViewEventArgs e) {
385      try {
386        nameCurrentJob = Convert.ToInt32(tvJobControl.SelectedNode.Text).ToString();
387        flagJob = true;
388        JobClicked();
389      }
390      catch (Exception ex) { }
391
392    }
393
394    private void OnLVUserControlClicked(object sender, EventArgs e) {
395      nameCurrentUser = lvUserControl.SelectedItems[0].Text;
396      flagUser = true;
397      UserClicked();
398    }
399
400    private void OnTVUserControlClicked(object sender, TreeViewEventArgs e) {
401      bool usergroup = false;
402      foreach (UserGroup ug in userGroups.List) {
403        if (tvUserControl.SelectedNode.Text == ug.Name) {
404          usergroup = true;
405        }
406      }
407      if (usergroup == false) {
408        nameCurrentUser = tvUserControl.SelectedNode.Text;
409        flagUser = true;
410        UserClicked();
411      }
412
413    }
414
415
416    private void btnClientClose_Click(object sender, EventArgs e) {
417      scClientControl.Panel2.Controls.Clear();
418      scClientControl.Panel2.Controls.Add(lvClientControl);
419      flagClient = false;
420    }
421 
422    private void btnJobDetailClose_Click(object sender, EventArgs e) {
423      scJobControl.Panel2.Controls.Clear();
424      scJobControl.Panel2.Controls.Add(lvJobControl);
425      flagJob = false;
426    }
427
428    private void btnUserControlClose_Click(object sender, EventArgs e) {
429      scUserControl.Panel2.Controls.Clear();
430      scUserControl.Panel2.Controls.Add(lvUserControl);
431      flagUser = false;
432    }
433
434    private void lvJobControl_MouseMove(object sender, MouseEventArgs e) {
435      if ((lvJobControl.GetItemAt(e.X, e.Y) != null) &&
436        (lvJobControl.GetItemAt(e.X, e.Y).ToolTipText != null)) {
437        tt.SetToolTip(lvJobControl, lvJobControl.GetItemAt(e.X, e.Y).ToolTipText);
438      }
439    }
440    #endregion
441
442  }
443}
Note: See TracBrowser for help on using the repository browser.