Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Client.Console/HiveClientConsole.cs @ 847

Last change on this file since 847 was 752, checked in by aleitner, 16 years ago

added reading logs into a ListBox in the Hive Client Console (#352)

File size: 3.0 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 System.Diagnostics;
31using System.Threading;
32
33namespace HeuristicLab.Hive.Client.Console {
34
35  delegate void UpdateTextDelegate(EventLog ev);
36
37  public partial class HiveClientConsole : Form {
38
39    int numEntries = 0;
40
41    public HiveClientConsole() {
42      InitializeComponent();
43      tbIp.Text = "010.020.053.006";
44      EventLog ev = new EventLog("Hive Client");
45      ev.Source = "Hive Client";
46      string str = ev.Entries[ev.Entries.Count - 1].Message;
47      foreach (System.Diagnostics.EventLogEntry entry in ev.Entries) {
48        lbEventLog.Items.Add(entry.TimeWritten + " -> " + entry.Message);
49      }
50      lbEventLog.SelectedIndex = lbEventLog.Items.Count - 1;
51      numEntries = ev.Entries.Count;
52      ev.EntryWritten += new EntryWrittenEventHandler(OnEntryWritten);
53      ev.EnableRaisingEvents = true;
54    }
55
56    private void UpdateText(EventLog ev) {
57      if (this.lbEventLog.InvokeRequired) {
58        this.lbEventLog.Invoke(new
59          UpdateTextDelegate(UpdateText), new object[] { ev });
60      } else {
61        string str = ev.Entries[numEntries].TimeWritten + " -> " + ev.Entries[numEntries].Message;
62        numEntries++;
63        lbEventLog.Items.Add(str);
64        lbEventLog.SelectedIndex = lbEventLog.Items.Count - 1;
65
66      }
67    }
68
69    private void tsmiExit_Click(object sender, EventArgs e) {
70      this.Close();
71    }
72
73    private void btnConnect_Click(object sender, EventArgs e) {
74      btnConnect.Enabled = false;
75      btnDisconnect.Enabled = true;
76      tbIp.Enabled = false;
77      tbPort.Enabled = false;
78      tbUuid.Enabled = false;
79      lbEventLog.Items.Add(tbIp.Text);
80    }
81
82    private void btnDisconnect_Click(object sender, EventArgs e) {
83      btnDisconnect.Enabled = false;
84      btnConnect.Enabled = true;
85      tbIp.Enabled = true;
86      tbPort.Enabled = true;
87      tbUuid.Enabled = true;
88    }
89
90    public void OnEntryWritten(object source, EntryWrittenEventArgs e) {
91      UpdateText((EventLog)source);
92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.