Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1360 was 1267, checked in by aleitner, 16 years ago

base for the asynchronous server managment console (#508)

File size: 16.8 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
[1261]49    private Dictionary<long, ListViewGroup> clientObjects;
50    private Dictionary<long, ListViewItem> clientInfoObjects;
51    private Dictionary<long, ListViewItem> jobObjects;
52    private Dictionary<long, ListViewGroup> userGroupsObjects;
53    private Dictionary<long, ListViewItem> userListObjects;
54
[1136]55    private Job currentJob = null;
56    private ClientInfo currentClient = null;
57    private User currentUser = null;
[1148]58    private string nameCurrentJob = "";
59    private string nameCurrentClient = "";
60    private string nameCurrentUser = "";
[1136]61    private bool flagJob = false;
62    private bool flagClient = false;
63    private bool flagUser = false;
[1098]64
[1136]65    private ToolTip tt = new ToolTip();
66    #endregion
67
[794]68    public HiveServerManagementConsole() {
69      InitializeComponent();
[1037]70      AddClients();
71      AddJobs();
72      AddUsers();
[1018]73      timerSyncronize.Start();
[844]74    }
[831]75
[1136]76    /// <summary>
77    /// event on Ticker
78    /// </summary>
79    /// <param name="obj"></param>
80    /// <param name="e"></param>
[1267]81    private void TickSync(object obj, EventArgs e) {
82      Refresh();
83      //updaterWoker.RunWorkerAsync();
[1018]84    }
85
[1136]86    /// <summary>
87    /// Adds clients to ListView and TreeView
88    /// </summary>
[1037]89    private void AddClients() {
[1030]90      try {
[1261]91        clientObjects = new Dictionary<long, ListViewGroup>();
92        clientInfoObjects = new Dictionary<long, ListViewItem>();
[1030]93        IClientManager clientManager =
94          ServiceLocator.GetClientManager();
[831]95
[1030]96        clients = clientManager.GetAllClientGroups();
97        lvClientControl.Items.Clear();
98        tvClientControl.Nodes.Clear();
99        int count = 0;
100        foreach (ClientGroup cg in clients.List) {
101          tvClientControl.Nodes.Add(cg.Name);
102          ListViewGroup lvg = new ListViewGroup(cg.Name, HorizontalAlignment.Left);
103          foreach (ClientInfo ci in clientManager.GetAllClients().List) {
104            tvClientControl.Nodes[tvClientControl.Nodes.Count - 1].Nodes.Add(ci.Name);
[1261]105            ListViewItem item = new ListViewItem(ci.Name, count, lvg);
106            lvClientControl.Items.Add(item);
107            clientInfoObjects.Add(ci.Id, item);
[1030]108            count = (count + 1) % 3;
109          }
110          lvClientControl.Groups.Add(lvg);
[1261]111          clientObjects.Add(cg.Id, lvg);
[1030]112        } // Groups
113
114        clientInfo = clientManager.GetAllClients();
115        ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
116        foreach (ClientInfo ci in clientInfo.List) {
117          tvClientControl.Nodes.Add(ci.Name);
118          lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvunsorted));
[844]119          count = (count + 1) % 3;
[831]120        }
[1030]121        lvClientControl.Groups.Add(lvunsorted);
[1136]122        if (flagClient) {
123          ClientClicked();
124        }
[1018]125      }
[1030]126      catch (Exception ex) {
127        closeFormEvent(true, true);
128        this.Close();
129      }
[1018]130    }
[956]131
[1136]132    /// <summary>
133    /// Adds jobs to ListView and TreeView
134    /// </summary>
[1037]135    private void AddJobs() {
[1030]136      try {
[1261]137        jobObjects = new Dictionary<long, ListViewItem>();
[1030]138        IJobManager jobManager =
139          ServiceLocator.GetJobManager();
140        jobs = jobManager.GetAllJobs();
[1018]141
[1030]142        lvJobControl.Items.Clear();
143        tvJobControl.Nodes.Clear();
[1018]144
[1037]145        ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left);
[1030]146        ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left);
[1037]147        ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left);
148        tvJobControl.Nodes.Add("calculating");
[1030]149        tvJobControl.Nodes.Add("finished");
[1037]150        tvJobControl.Nodes.Add("pending");
[1030]151        foreach (Job job in jobs.List) {
[1037]152          if (job.State == State.calculating) {
[1126]153            ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobCalculating);
[1261]154            jobObjects.Add(job.Id, lvi);
[1030]155            tvJobControl.Nodes[0].Nodes.Add(job.Id.ToString());
[1126]156            lvJobControl.Items.Add(lvi);
157            lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated";
[1037]158          } else if (job.State == State.finished) {
[1126]159            ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobFinished);
[1261]160            jobObjects.Add(job.Id, lvi);
[1037]161            tvJobControl.Nodes[1].Nodes.Add(job.Id.ToString());
[1126]162            lvJobControl.Items.Add(lvi);
[1030]163          } else if (job.State == State.offline) {
[1126]164            ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobPending);
[1261]165            jobObjects.Add(job.Id, lvi);
[1030]166            tvJobControl.Nodes[2].Nodes.Add(job.Id.ToString());
[1126]167            lvJobControl.Items.Add(lvi);
[1030]168          }
169        } // Jobs
[1037]170        lvJobControl.Groups.Add(lvJobCalculating);
[1030]171        lvJobControl.Groups.Add(lvJobFinished);
[1037]172        lvJobControl.Groups.Add(lvJobPending);
[1136]173        if (flagJob) {
174          JobClicked();
175        }
[1030]176      }
177      catch (Exception ex) {
178        closeFormEvent(true, true);
179        this.Close();
180      }
[1018]181    }
182
[1136]183    /// <summary>
184    /// Adds users to ListView and TreeView
185    /// </summary>
[1037]186    private void AddUsers() {
[1030]187      try {
[1261]188        userGroupsObjects = new Dictionary<long, ListViewGroup>();
189        userListObjects = new Dictionary<long, ListViewItem>();
[1030]190        IUserRoleManager userRoleManager =
191          ServiceLocator.GetUserRoleManager();
[1018]192
[1030]193        userGroups = userRoleManager.GetAllUserGroups();
[1018]194
[1030]195        lvUserControl.Items.Clear();
196        tvUserControl.Nodes.Clear();
[1018]197
[1030]198        foreach (UserGroup ug in userGroups.List) {
199          tvUserControl.Nodes.Add(ug.Name);
200          ListViewGroup lvg = new ListViewGroup(ug.Name, HorizontalAlignment.Left);
[956]201
[1030]202          foreach (PermissionOwner permOwner in ug.Members) {
203            if (permOwner is User) {
204              User users = permOwner as User;
205              tvUserControl.Nodes[tvUserControl.Nodes.Count - 1].Nodes.Add(users.Name);
[1261]206              ListViewItem item = new ListViewItem(users.Name, 0, lvg);
207              lvUserControl.Items.Add(item);
208              userListObjects.Add(users.Id, item);
[1030]209            }
[1018]210          }
[1030]211          lvUserControl.Groups.Add(lvg);
[1261]212          userGroupsObjects.Add(ug.Id, lvg);
[1030]213
214        } // Users
215        usersList = userRoleManager.GetAllUsers();
216        ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
217        foreach (User u in usersList.List) {
218          tvUserControl.Nodes.Add(u.Name);
219          lvUserControl.Items.Add(new ListViewItem(u.Name, 0, lvunsorted));
[956]220        }
[1030]221        lvUserControl.Groups.Add(lvunsorted);
[1136]222        if (flagUser) {
223          UserClicked();
224        }
[1030]225      }
226      catch (Exception ex) {
227        closeFormEvent(true, true);
228        this.Close();
229      }
[794]230    }
231
232    /// <summary>
[1136]233    /// if one client is clicked, a panel is opened with the details
234    /// </summary>
235    private void ClientClicked() {
[1148]236      int i = 0;
[1164]237      while (clientInfo.List[i].Name != nameCurrentClient) {
[1148]238        i++;
239      }
240      currentClient = clientInfo.List[i];
[1136]241      scClientControl.Panel2.Controls.Clear();
242      scClientControl.Panel2.Controls.Add(plClientDetails);
243      pbClientControl.Image = ilClientControl.Images[0];
244      lblClientName.Text = currentClient.Name;
245      lblLogin.Text = currentClient.Login.ToString();
[1164]246      lblState.Text = currentClient.State.ToString();
[1136]247    }
248
249    /// <summary>
250    /// if one job is clicked, a panel is opened with the details
251    /// </summary>
252    private void JobClicked() {
[1148]253      int i = 0;
254      while (jobs.List[i].Id.ToString() != nameCurrentJob) {
255        i++;
256      }
257      lvSnapshots.Enabled = false;
[1136]258      int yPos = 0;
[1148]259      currentJob = jobs.List[i];
[1136]260      scJobControl.Panel2.Controls.Clear();
261      scJobControl.Panel2.Controls.Add(plJobDetails);
262      pbJobControl.Image = ilJobControl.Images[0];
263      lblJobName.Text = currentJob.Id.ToString();
264      progressJob.Value = (int)(currentJob.Percentage * 100);
265      yPos = progressJob.Location.Y;
266      yPos += 20;
267      lblProgress.Location = new Point(
268        lblProgress.Location.X, yPos);
269      lblProgress.Text = (int)(currentJob.Percentage * 100) + "% calculated";
270      yPos += 20;
271      lblUserCreatedJob.Location = new Point(
272        lblUserCreatedJob.Location.X, yPos);
273      lblUserCreatedJob.Text = /* currentJob.User.Name + */ " created Job";
274      yPos += 20;
275      lblJobCreated.Location = new Point(
276        lblJobCreated.Location.X, yPos);
[1173]277      lblJobCreated.Text = "Created at " + currentJob.DateCreated;
[1136]278      if (currentJob.ParentJob != null) {
279        yPos += 20;
280        lblParentJob.Location = new Point(
281          lblParentJob.Location.X, yPos);
282        lblParentJob.Text = currentJob.ParentJob.Id + " is parent job";
283      }
284      yPos += 20;
285      lblPriorityJob.Location = new Point(
286        lblPriorityJob.Location.X, yPos);
[1173]287      lblPriorityJob.Text = "Priority of job is " + currentJob.Priority;
[1136]288      if (currentJob.Client != null) {
289        yPos += 20;
290        lblClientCalculating.Location = new Point(
291          lblClientCalculating.Location.X, yPos);
292        lblClientCalculating.Text = currentJob.Client.Name + " calculated Job";
293        yPos += 20;
294        lblJobCalculationBegin.Location = new Point(
295          lblJobCalculationBegin.Location.X, yPos);
[1173]296        lblJobCalculationBegin.Text = "Startet calculation at " + currentJob.DateCalculated ;
297       
298        if (currentJob.State == State.finished) {
299          yPos += 20;
300          lblJobCalculationEnd.Location = new Point(
301            lblJobCalculationEnd.Location.X, yPos);
302
303          IJobManager jobManager =
304            ServiceLocator.GetJobManager();
305
[1174]306          ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id);
[1173]307
308         
309          lblJobCalculationEnd.Text = "Calculation ended at " + jobRes.Obj.DateFinished;
310        }
311      }                       
312      if (currentJob.State != State.offline) {
[1136]313        yPos += 20;
[1148]314        lvSnapshots.Location = new Point(
315          lvSnapshots.Location.X, yPos);
316        lvSnapshots.Size = new Size(lvSnapshots.Size.Width,
317          plJobDetails.Size.Height - 10 - yPos);
318        lvSnapshots.Enabled = true;
319      }
[1136]320    }
321
322    /// <summary>
323    /// if one user is clicked, a panel is opened with the details
324    /// </summary>
325    private void UserClicked() {
[1148]326      int i = 0;
327      while (usersList.List[i].Name != nameCurrentUser) {
328        i++;
329      }
330      currentUser = usersList.List[i];
[1136]331      scUserControl.Panel2.Controls.Clear();
332      scUserControl.Panel2.Controls.Add(plUserDetails);
333      pbUserControl.Image = ilUserControl.Images[0];
334      lblUserName.Text = currentUser.Id.ToString();
335    }
336
[1148]337    #region Eventhandlers
[1136]338    /// <summary>
[794]339    /// Send event to Login-GUI when closing
340    /// </summary>
341    /// <param name="sender"></param>
342    /// <param name="e"></param>
[1037]343    private void Close_Click(object sender, EventArgs e) {
[794]344      if (closeFormEvent != null) {
[1030]345        closeFormEvent(true, false);
[794]346      }
347      this.Close();
348    }
349
350    /// <summary>
351    /// Send evnt to Login-GUI when closing
352    /// </summary>
353    /// <param name="sender"></param>
354    /// <param name="e"></param>
355    private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
356      if (closeFormEvent != null) {
[1030]357        closeFormEvent(true, false);
[794]358      }
359    }
[956]360
[1136]361    private void AddJob_Click(object sender, EventArgs e) {
[1018]362      AddJobForm newForm = new AddJobForm();
[956]363      newForm.Show();
[1164]364      newForm.addJobEvent += new addDelegate(Refresh);
[956]365    }
366
[1164]367    private void Refresh() {
368      AddClients();
369      AddJobs();
370      AddUsers();
371    }
372
[1136]373    private void AddUser_Click(object sender, EventArgs e) {
[1018]374      AddUserForm newForm = new AddUserForm("User", false);
[978]375      newForm.Show();
[1164]376      newForm.addUserEvent += new addDelegate(Refresh);
[978]377    }
378
[1136]379    private void AddUserGroup_Click(object sender, EventArgs e) {
[1018]380      AddUserForm newForm = new AddUserForm("User", true);
[978]381      newForm.Show();
[1164]382      newForm.addUserEvent += new addDelegate(Refresh);                                             
[978]383    }
384
[1098]385    private void OnLVClientClicked(object sender, EventArgs e) {
[1148]386      nameCurrentClient = lvClientControl.SelectedItems[0].Text;
[1136]387      flagClient = true;
[1098]388      ClientClicked();
389    }
390
[1164]391    private void OnTVClientClicked(object sender, TreeViewEventArgs e) {
392      bool clientgroup = false;
393      foreach (ClientGroup cg in clients.List) {
394        if (tvClientControl.SelectedNode.Text == cg.Name) {
395          clientgroup = true;
396        }
397      }
398      if (clientgroup == false) {
399        nameCurrentClient = tvClientControl.SelectedNode.Text;
400        flagClient = true;
401        ClientClicked();
402      }
403
404    }
405
[1136]406    private void OnLVJobControlClicked(object sender, EventArgs e) {
[1148]407      nameCurrentJob = lvJobControl.SelectedItems[0].Text;
[1136]408      flagJob = true;
409      JobClicked();
[1098]410    }
411
[1164]412    private void OnTVJobControlClicked(object sender, TreeViewEventArgs e) {
[1148]413      try {
414        nameCurrentJob = Convert.ToInt32(tvJobControl.SelectedNode.Text).ToString();
415        flagJob = true;
416        JobClicked();
417      }
418      catch (Exception ex) { }
419
420    }
421
[1136]422    private void OnLVUserControlClicked(object sender, EventArgs e) {
[1164]423      nameCurrentUser = lvUserControl.SelectedItems[0].Text;
[1136]424      flagUser = true;
425      UserClicked();
[1089]426    }
427
[1164]428    private void OnTVUserControlClicked(object sender, TreeViewEventArgs e) {
429      bool usergroup = false;
430      foreach (UserGroup ug in userGroups.List) {
431        if (tvUserControl.SelectedNode.Text == ug.Name) {
432          usergroup = true;
433        }
434      }
435      if (usergroup == false) {
436        nameCurrentUser = tvUserControl.SelectedNode.Text;
437        flagUser = true;
438        UserClicked();
439      }
440
441    }
442
443
[1098]444    private void btnClientClose_Click(object sender, EventArgs e) {
[1089]445      scClientControl.Panel2.Controls.Clear();
446      scClientControl.Panel2.Controls.Add(lvClientControl);
[1136]447      flagClient = false;
[1089]448    }
[1136]449 
[1098]450    private void btnJobDetailClose_Click(object sender, EventArgs e) {
451      scJobControl.Panel2.Controls.Clear();
452      scJobControl.Panel2.Controls.Add(lvJobControl);
[1136]453      flagJob = false;
[1098]454    }
455
456    private void btnUserControlClose_Click(object sender, EventArgs e) {
457      scUserControl.Panel2.Controls.Clear();
458      scUserControl.Panel2.Controls.Add(lvUserControl);
[1136]459      flagUser = false;
[1098]460    }
461
[1126]462    private void lvJobControl_MouseMove(object sender, MouseEventArgs e) {
463      if ((lvJobControl.GetItemAt(e.X, e.Y) != null) &&
464        (lvJobControl.GetItemAt(e.X, e.Y).ToolTipText != null)) {
465        tt.SetToolTip(lvJobControl, lvJobControl.GetItemAt(e.X, e.Y).ToolTipText);
466      }
467    }
[1261]468
469    private void updaterWoker_DoWork(object sender, DoWorkEventArgs e) {
470      ResponseList<ClientInfo> clientInfoOld = clientInfo;
471      IClientManager clientManager =
472          ServiceLocator.GetClientManager();
473      clientInfo = clientManager.GetAllClients();
474      foreach (ClientInfo ci in clientInfo.List) {
475        foreach (ClientInfo cio in clientInfoOld.List) {
476          ci.Id.Equals(cio.Id);
477        }
478      }
479     
480    }
[1136]481    #endregion
[794]482  }
[844]483}
Note: See TracBrowser for help on using the repository browser.