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

Last change on this file since 1089 was 1089, checked in by aleitner, 13 years ago

panel for details which shows an image and a close button if details should be closed (#452)

File size: 7.9 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    ResponseList<ClientGroup> clients = null;
43    ResponseList<ClientInfo> clientInfo = null;
44    ResponseList<Job> jobs = null;
45    ResponseList<UserGroup> userGroups = null;
46    ResponseList<User> usersList = null;
47    ListView lvClientDetails = null;
48
49    public HiveServerManagementConsole() {
50      InitializeComponent();
51      AddClients();
52      AddJobs();
53      AddUsers();
54
55      timerSyncronize.Tick += new EventHandler(TickSync);
56      timerSyncronize.Start();
57    }
58
59    private void TickSync(object obj, EventArgs e) {
60      AddClients();
61      AddJobs();
62      AddUsers();
63    }
64
65    private void AddClients() {
66      try {
67        IClientManager clientManager =
68          ServiceLocator.GetClientManager();
69
70        clients = clientManager.GetAllClientGroups();
71
72        lvClientControl.Items.Clear();
73        tvClientControl.Nodes.Clear();
74        int count = 0;
75        foreach (ClientGroup cg in clients.List) {
76          tvClientControl.Nodes.Add(cg.Name);
77          ListViewGroup lvg = new ListViewGroup(cg.Name, HorizontalAlignment.Left);
78          foreach (ClientInfo ci in clientManager.GetAllClients().List) {
79            tvClientControl.Nodes[tvClientControl.Nodes.Count - 1].Nodes.Add(ci.Name);
80            lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvg));
81            count = (count + 1) % 3;
82          }
83          lvClientControl.Groups.Add(lvg);
84        } // Groups
85
86        clientInfo = clientManager.GetAllClients();
87        ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
88        foreach (ClientInfo ci in clientInfo.List) {
89          tvClientControl.Nodes.Add(ci.Name);
90          lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvunsorted));
91          count = (count + 1) % 3;
92        }
93        lvClientControl.Groups.Add(lvunsorted);
94        lvClientControl.Sorting = SortOrder.Ascending;
95      }
96      catch (Exception ex) {
97        closeFormEvent(true, true);
98        this.Close();
99      }
100    }
101
102    private void AddJobs() {
103      try {
104        IJobManager jobManager =
105          ServiceLocator.GetJobManager();
106        jobs = jobManager.GetAllJobs();
107
108        lvJobControl.Items.Clear();
109        tvJobControl.Nodes.Clear();
110
111        ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left);
112        ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left);
113        ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left);
114        tvJobControl.Nodes.Add("calculating");
115        tvJobControl.Nodes.Add("finished");
116        tvJobControl.Nodes.Add("pending");
117        foreach (Job job in jobs.List) {
118          if (job.State == State.calculating) {
119            tvJobControl.Nodes[0].Nodes.Add(job.Id.ToString());
120            lvJobControl.Items.Add(new ListViewItem(job.Id.ToString(), 0, lvJobCalculating));
121          } else if (job.State == State.finished) {
122            tvJobControl.Nodes[1].Nodes.Add(job.Id.ToString());
123            lvJobControl.Items.Add(new ListViewItem(job.Id.ToString(), 0, lvJobFinished));
124          } else if (job.State == State.offline) {
125            tvJobControl.Nodes[2].Nodes.Add(job.Id.ToString());
126            lvJobControl.Items.Add(new ListViewItem(job.Id.ToString(), 0, lvJobPending));
127          }
128        } // Jobs
129        lvJobControl.Groups.Add(lvJobCalculating);
130        lvJobControl.Groups.Add(lvJobFinished);
131        lvJobControl.Groups.Add(lvJobPending);
132      }
133      catch (Exception ex) {
134        closeFormEvent(true, true);
135        this.Close();
136      }
137    }
138
139    private void AddUsers() {
140      try {
141        IUserRoleManager userRoleManager =
142          ServiceLocator.GetUserRoleManager();
143
144        userGroups = userRoleManager.GetAllUserGroups();
145
146        lvUserControl.Items.Clear();
147        tvUserControl.Nodes.Clear();
148
149        foreach (UserGroup ug in userGroups.List) {
150          tvUserControl.Nodes.Add(ug.Name);
151          ListViewGroup lvg = new ListViewGroup(ug.Name, HorizontalAlignment.Left);
152
153          foreach (PermissionOwner permOwner in ug.Members) {
154            if (permOwner is User) {
155              User users = permOwner as User;
156              tvUserControl.Nodes[tvUserControl.Nodes.Count - 1].Nodes.Add(users.Name);
157              lvUserControl.Items.Add(new ListViewItem(users.Name, 0, lvg));
158            }
159          }
160          lvUserControl.Groups.Add(lvg);
161
162        } // Users
163        usersList = userRoleManager.GetAllUsers();
164        ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
165        foreach (User u in usersList.List) {
166          tvUserControl.Nodes.Add(u.Name);
167          lvUserControl.Items.Add(new ListViewItem(u.Name, 0, lvunsorted));
168        }
169        lvUserControl.Groups.Add(lvunsorted);
170      }
171      catch (Exception ex) {
172        closeFormEvent(true, true);
173        this.Close();
174      }
175    }
176
177    /// <summary>
178    /// Send event to Login-GUI when closing
179    /// </summary>
180    /// <param name="sender"></param>
181    /// <param name="e"></param>
182    private void Close_Click(object sender, EventArgs e) {
183      if (closeFormEvent != null) {
184        closeFormEvent(true, false);
185      }
186      this.Close();
187    }
188
189    /// <summary>
190    /// Send evnt to Login-GUI when closing
191    /// </summary>
192    /// <param name="sender"></param>
193    /// <param name="e"></param>
194    private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
195      if (closeFormEvent != null) {
196        closeFormEvent(true, false);
197      }
198    }
199
200    private void JobToolStripMenuItem1_Click(object sender, EventArgs e) {
201      AddJobForm newForm = new AddJobForm();
202      newForm.Show();
203    }
204
205    private void UserToolStripMenuItem1_Click(object sender, EventArgs e) {
206      AddUserForm newForm = new AddUserForm("User", false);
207      newForm.Show();
208    }
209
210    private void GroupToolStripMenuItem2_Click(object sender, EventArgs e) {
211      AddUserForm newForm = new AddUserForm("User", true);
212      newForm.Show();
213
214    }
215
216    private void OnClientClicked(object sender, EventArgs e) {
217      scClientControl.Panel2.Controls.Clear();
218      scClientControl.Panel2.Controls.Add(plClientDetails);
219      pbClientControl.Image = ilClientControl.Images[0];
220      lblClientName.Text = sender.ToString();
221
222     
223    }
224
225    private void btnClose_Click(object sender, EventArgs e) {
226      scClientControl.Panel2.Controls.Clear();
227      scClientControl.Panel2.Controls.Add(lvClientControl);
228    }
229
230
231
232  }
233}
Note: See TracBrowser for help on using the repository browser.