Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Console/3.3/LogServiceReader.cs @ 4772

Last change on this file since 4772 was 4772, checked in by cneumuel, 13 years ago

#1260

  • added LogServiceReader to display log for slave without writing to local files
  • aborted jobs with childjobs now got back to state WaitForChildJob (instead of Offline)
  • lifecyclemanager now knows about available plugins (does not yet work perfectly)
File size: 1.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Forms;
6using HeuristicLab.Core;
7
8namespace HeuristicLab.Hive.Slave.Console {
9  internal class LogServiceReader : ILogReader {
10
11    private SlaveConsoleService.SlaveConsoleCommunicatorClient slaveCommunicator;
12    private Timer timer;
13    private int messageCount = 0;
14
15    public LogServiceReader(SlaveConsoleService.SlaveConsoleCommunicatorClient slaveCommunicator) {
16      this.slaveCommunicator = slaveCommunicator;
17    }
18
19    public void Start() {
20      timer = new Timer();
21      timer.Interval = 2000;
22      timer.Tick += new EventHandler(timer_Tick);
23      timer.Start();
24    }
25
26    void timer_Tick(object sender, EventArgs e) {
27      try {
28        var messages = slaveCommunicator.GetLogMessages();
29        var newMessages = messages.GetRange(messageCount, messages.Count - messageCount);
30        messageCount = messages.Count;
31        OnMoreData(newMessages);
32      }
33      catch { }
34    }
35
36    public void Stop() {
37      timer.Stop();
38    }
39
40    public event MoreDataHandler MoreData;
41    private void OnMoreData(IEnumerable<string> newMessages) {
42      var handler = MoreData;
43      var newData = string.Join(Environment.NewLine, newMessages.ToArray());
44      if(newMessages.Count() > 0) newData += Environment.NewLine;
45      if (handler != null) MoreData(this, newData);
46    }
47  }
48}
Note: See TracBrowser for help on using the repository browser.