Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1463 was 1449, checked in by svonolfe, 15 years ago

Refactored DAL (now using GUIDs as IDs instead of longs) (#527)

File size: 13.3 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
47    private Dictionary<Guid, ListViewGroup> clientObjects;
48    private Dictionary<Guid, ListViewItem> clientInfoObjects;
49    private Dictionary<Guid, ListViewItem> jobObjects;
50    private Dictionary<Guid, ListViewGroup> userGroupsObjects;
51    private Dictionary<Guid, ListViewItem> userListObjects;
52
53    private Job currentJob = null;
54    private ClientInfo currentClient = null;
55    private string nameCurrentJob = "";
56    private string nameCurrentClient = "";
57    private string nameCurrentUser = "";
58    private bool flagJob = false;
59    private bool flagClient = false;
60    private bool flagUser = false;
61
62    private ToolTip tt = new ToolTip();
63    #endregion
64
65    public HiveServerManagementConsole() {
66      InitializeComponent();
67      AddClients();
68      AddJobs();
69      timerSyncronize.Start();
70    }
71
72    /// <summary>
73    /// event on Ticker
74    /// </summary>
75    /// <param name="obj"></param>
76    /// <param name="e"></param>
77    private void TickSync(object obj, EventArgs e) {
78      Refresh();
79      //updaterWoker.RunWorkerAsync();
80    }
81
82    /// <summary>
83    /// Adds clients to ListView and TreeView
84    /// </summary>
85    private void AddClients() {
86      try {
87        clientObjects = new Dictionary<Guid, ListViewGroup>();
88        clientInfoObjects = new Dictionary<Guid, ListViewItem>();
89        IClientManager clientManager =
90          ServiceLocator.GetClientManager();
91
92        clients = clientManager.GetAllClientGroups();
93        lvClientControl.Items.Clear();
94        tvClientControl.Nodes.Clear();
95        int count = 0;
96        foreach (ClientGroup cg in clients.List) {
97          tvClientControl.Nodes.Add(cg.Name);
98          ListViewGroup lvg = new ListViewGroup(cg.Name, HorizontalAlignment.Left);
99          foreach (ClientInfo ci in clientManager.GetAllClients().List) {
100            tvClientControl.Nodes[tvClientControl.Nodes.Count - 1].Nodes.Add(ci.Name);
101            ListViewItem item = new ListViewItem(ci.Name, count, lvg);
102            lvClientControl.Items.Add(item);
103            clientInfoObjects.Add(ci.Id, item);
104            count = (count + 1) % 3;
105          }
106          lvClientControl.Groups.Add(lvg);
107          clientObjects.Add(cg.Id, lvg);
108        } // Groups
109
110        clientInfo = clientManager.GetAllClients();
111        ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left);
112        foreach (ClientInfo ci in clientInfo.List) {
113          tvClientControl.Nodes.Add(ci.Name);
114          lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvunsorted));
115          count = (count + 1) % 3;
116        }
117        lvClientControl.Groups.Add(lvunsorted);
118        if (flagClient) {
119          ClientClicked();
120        }
121      }
122      catch (Exception ex) {
123        closeFormEvent(true, true);
124        this.Close();
125      }
126    }
127
128    /// <summary>
129    /// Adds jobs to ListView and TreeView
130    /// </summary>
131    private void AddJobs() {
132      try {
133        jobObjects = new Dictionary<Guid, ListViewItem>();
134        IJobManager jobManager =
135          ServiceLocator.GetJobManager();
136        jobs = jobManager.GetAllJobs();
137
138        lvJobControl.Items.Clear();
139        tvJobControl.Nodes.Clear();
140
141        ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left);
142        ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left);
143        ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left);
144        tvJobControl.Nodes.Add("calculating");
145        tvJobControl.Nodes.Add("finished");
146        tvJobControl.Nodes.Add("pending");
147        foreach (Job job in jobs.List) {
148          if (job.State == State.calculating) {
149            ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobCalculating);
150            jobObjects.Add(job.Id, lvi);
151            tvJobControl.Nodes[0].Nodes.Add(job.Id.ToString());
152            lvJobControl.Items.Add(lvi);
153            lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated";
154          } else if (job.State == State.finished) {
155            ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobFinished);
156            jobObjects.Add(job.Id, lvi);
157            tvJobControl.Nodes[1].Nodes.Add(job.Id.ToString());
158            lvJobControl.Items.Add(lvi);
159          } else if (job.State == State.offline) {
160            ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobPending);
161            jobObjects.Add(job.Id, lvi);
162            tvJobControl.Nodes[2].Nodes.Add(job.Id.ToString());
163            lvJobControl.Items.Add(lvi);
164          }
165        } // Jobs
166        lvJobControl.Groups.Add(lvJobCalculating);
167        lvJobControl.Groups.Add(lvJobFinished);
168        lvJobControl.Groups.Add(lvJobPending);
169        if (flagJob) {
170          JobClicked();
171        }
172      }
173      catch (Exception ex) {
174        closeFormEvent(true, true);
175        this.Close();
176      }
177    }
178
179    /// <summary>
180    /// if one client is clicked, a panel is opened with the details
181    /// </summary>
182    private void ClientClicked() {
183      int i = 0;
184      while (clientInfo.List[i].Name != nameCurrentClient) {
185        i++;
186      }
187      currentClient = clientInfo.List[i];
188      scClientControl.Panel2.Controls.Clear();
189      scClientControl.Panel2.Controls.Add(plClientDetails);
190      pbClientControl.Image = ilClientControl.Images[0];
191      lblClientName.Text = currentClient.Name;
192      lblLogin.Text = currentClient.Login.ToString();
193      lblState.Text = currentClient.State.ToString();
194    }
195
196    /// <summary>
197    /// if one job is clicked, a panel is opened with the details
198    /// </summary>
199    private void JobClicked() {
200      int i = 0;
201      while (jobs.List[i].Id.ToString() != nameCurrentJob) {
202        i++;
203      }
204      lvSnapshots.Enabled = false;
205      int yPos = 0;
206      currentJob = jobs.List[i];
207      scJobControl.Panel2.Controls.Clear();
208      scJobControl.Panel2.Controls.Add(plJobDetails);
209      pbJobControl.Image = ilJobControl.Images[0];
210      lblJobName.Text = currentJob.Id.ToString();
211      progressJob.Value = (int)(currentJob.Percentage * 100);
212      yPos = progressJob.Location.Y;
213      yPos += 20;
214      lblProgress.Location = new Point(
215        lblProgress.Location.X, yPos);
216      lblProgress.Text = (int)(currentJob.Percentage * 100) + "% calculated";
217      yPos += 20;
218      lblUserCreatedJob.Location = new Point(
219        lblUserCreatedJob.Location.X, yPos);
220      lblUserCreatedJob.Text = /* currentJob.User.Name + */ " created Job";
221      yPos += 20;
222      lblJobCreated.Location = new Point(
223        lblJobCreated.Location.X, yPos);
224      lblJobCreated.Text = "Created at " + currentJob.DateCreated;
225      if (currentJob.ParentJob != null) {
226        yPos += 20;
227        lblParentJob.Location = new Point(
228          lblParentJob.Location.X, yPos);
229        lblParentJob.Text = currentJob.ParentJob.Id + " is parent job";
230      }
231      yPos += 20;
232      lblPriorityJob.Location = new Point(
233        lblPriorityJob.Location.X, yPos);
234      lblPriorityJob.Text = "Priority of job is " + currentJob.Priority;
235      if (currentJob.Client != null) {
236        yPos += 20;
237        lblClientCalculating.Location = new Point(
238          lblClientCalculating.Location.X, yPos);
239        lblClientCalculating.Text = currentJob.Client.Name + " calculated Job";
240        yPos += 20;
241        lblJobCalculationBegin.Location = new Point(
242          lblJobCalculationBegin.Location.X, yPos);
243        lblJobCalculationBegin.Text = "Startet calculation at " + currentJob.DateCalculated ;
244       
245        if (currentJob.State == State.finished) {
246          yPos += 20;
247          lblJobCalculationEnd.Location = new Point(
248            lblJobCalculationEnd.Location.X, yPos);
249
250          IJobManager jobManager =
251            ServiceLocator.GetJobManager();
252
253          ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id);
254
255         
256          lblJobCalculationEnd.Text = "Calculation ended at " + jobRes.Obj.DateFinished;
257        }
258      }                       
259      if (currentJob.State != State.offline) {
260        yPos += 20;
261        lvSnapshots.Location = new Point(
262          lvSnapshots.Location.X, yPos);
263        lvSnapshots.Size = new Size(lvSnapshots.Size.Width,
264          plJobDetails.Size.Height - 10 - yPos);
265        lvSnapshots.Enabled = true;
266      }
267    }
268
269    #region Eventhandlers
270    /// <summary>
271    /// Send event to Login-GUI when closing
272    /// </summary>
273    /// <param name="sender"></param>
274    /// <param name="e"></param>
275    private void Close_Click(object sender, EventArgs e) {
276      if (closeFormEvent != null) {
277        closeFormEvent(true, false);
278      }
279      this.Close();
280    }
281
282    /// <summary>
283    /// Send evnt to Login-GUI when closing
284    /// </summary>
285    /// <param name="sender"></param>
286    /// <param name="e"></param>
287    private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
288      if (closeFormEvent != null) {
289        closeFormEvent(true, false);
290      }
291    }
292
293    private void AddJob_Click(object sender, EventArgs e) {
294      AddJobForm newForm = new AddJobForm();
295      newForm.Show();
296      newForm.addJobEvent += new addDelegate(Refresh);
297    }
298
299    private void Refresh() {
300      AddClients();
301      AddJobs();
302    }
303
304    private void OnLVClientClicked(object sender, EventArgs e) {
305      nameCurrentClient = lvClientControl.SelectedItems[0].Text;
306      flagClient = true;
307      ClientClicked();
308    }
309
310    private void OnTVClientClicked(object sender, TreeViewEventArgs e) {
311      bool clientgroup = false;
312      foreach (ClientGroup cg in clients.List) {
313        if (tvClientControl.SelectedNode.Text == cg.Name) {
314          clientgroup = true;
315        }
316      }
317      if (clientgroup == false) {
318        nameCurrentClient = tvClientControl.SelectedNode.Text;
319        flagClient = true;
320        ClientClicked();
321      }
322
323    }
324
325    private void OnLVJobControlClicked(object sender, EventArgs e) {
326      nameCurrentJob = lvJobControl.SelectedItems[0].Text;
327      flagJob = true;
328      JobClicked();
329    }
330
331    private void OnTVJobControlClicked(object sender, TreeViewEventArgs e) {
332      try {
333        nameCurrentJob = Convert.ToInt32(tvJobControl.SelectedNode.Text).ToString();
334        flagJob = true;
335        JobClicked();
336      }
337      catch (Exception ex) { }
338
339    }
340
341    private void btnClientClose_Click(object sender, EventArgs e) {
342      scClientControl.Panel2.Controls.Clear();
343      scClientControl.Panel2.Controls.Add(lvClientControl);
344      flagClient = false;
345    }
346 
347    private void btnJobDetailClose_Click(object sender, EventArgs e) {
348      scJobControl.Panel2.Controls.Clear();
349      scJobControl.Panel2.Controls.Add(lvJobControl);
350      flagJob = false;
351    }
352
353    private void btnUserControlClose_Click(object sender, EventArgs e) {
354      scUserControl.Panel2.Controls.Clear();
355      scUserControl.Panel2.Controls.Add(lvUserControl);
356      flagUser = false;
357    }
358
359    private void lvJobControl_MouseMove(object sender, MouseEventArgs e) {
360      if ((lvJobControl.GetItemAt(e.X, e.Y) != null) &&
361        (lvJobControl.GetItemAt(e.X, e.Y).ToolTipText != null)) {
362        tt.SetToolTip(lvJobControl, lvJobControl.GetItemAt(e.X, e.Y).ToolTipText);
363      }
364    }
365
366    private void updaterWoker_DoWork(object sender, DoWorkEventArgs e) {
367      ResponseList<ClientInfo> clientInfoOld = clientInfo;
368      IClientManager clientManager =
369          ServiceLocator.GetClientManager();
370      clientInfo = clientManager.GetAllClients();
371      foreach (ClientInfo ci in clientInfo.List) {
372        foreach (ClientInfo cio in clientInfoOld.List) {
373          ci.Id.Equals(cio.Id);
374        }
375      }
376     
377    }
378    #endregion
379  }
380}
Note: See TracBrowser for help on using the repository browser.