Free cookie consent management tool by TermsFeed Policy Generator

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

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

syntax error fixed (#452)

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