public void MonitorStop() { if (!IsMonitorStarted) { return; } _monitorTimer.Stop(); IsMonitorStarted = false; MonitorStopped?.Invoke(this, Name); }
public void MonitorStop() { if (!IsMonitorStarted) { return; } _monitorTimer.Stop(); IsMonitorStarted = false; MonitorStopped?.Invoke(this, EventArgs.Empty); }
protected override void OnDoWork(DoWorkEventArgs e) { base.OnDoWork(e); MonitorStarted?.Invoke(this, new EventArgs()); bool _requestCancellation; var output = string.Empty; do { MonitorCycleStarted?.Invoke(this, new EventArgs()); #region Update Monitor Output var reader = new StreamReader( new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); while (!reader.EndOfStream) { liveLines.Enqueue(reader.ReadLine()); while (liveLines.Count > Properties.Settings.Default.MaxDisplayedLines) { liveLines.Dequeue(); } } var sb = new StringBuilder(); for (int i = 0; i < liveLines.Count; i++) { var line = liveLines.Dequeue(); sb.AppendLine(line); liveLines.Enqueue(line); } var formatted = sb.ToString(); if (output != formatted) { output = formatted; OutputUpdate?.Invoke(this, new OutputEventArgs(output)); } #endregion lock (this) _requestCancellation = requestCancellation; } while (!_requestCancellation); MonitorStopped?.Invoke(this, new EventArgs()); }
private void OnMonitorStopped() { MonitorStopped?.Invoke(this, EventArgs.Empty); }
private void MonitorTask(object state) { if (!reading) { reading = true; using (Stream stream = File.Open(logFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (StreamReader reader = new StreamReader(stream)) { stream.Seek(streamPosition, SeekOrigin.Begin); string line; while ((line = reader.ReadLine()) != null) { if (line.Length > 15) { var match = line.Substring(15); if (phrases["exit"].IsMatch(match)) { monitor.Change(Timeout.Infinite, monitorInterval); MonitorStopped?.Invoke(this, new EventArgs()); Notify("Game has exited."); lobbyState = LobbyState.CLOSED; } else { var peerNumber = 0; switch (lobbyState) { case LobbyState.CLOSED: if (phrases["visible"].IsMatch(match)) { Notify("Monitoring active lobby!"); lobbyState = LobbyState.OPEN; peers = 0; } break; case LobbyState.OPEN: if (phrases["start"].IsMatch(match)) { Notify("Game has started."); lobbyState = LobbyState.GAME; } else if (phrases["mapchange"].IsMatch(match)) { var result = phrases["mapchange"].Match(match); int.TryParse(result.Groups[1].Value, out maxPeers); Notify("Map has changed."); lobbyState = LobbyState.OPEN; } else if (phrases["join"].IsMatch(match)) { var result = phrases["join"].Match(match); int.TryParse(result.Groups[1].Value, out peerNumber); peers += 1; Notify("Player joined!"); if (peers >= maxPeers) { Notify("Lobby has filled!"); lobbyState = LobbyState.FULL; } else { lobbyState = LobbyState.OPEN; } } else if (phrases["leave"].IsMatch(match)) { var result = phrases["leave"].Match(match); int.TryParse(result.Groups[1].Value, out peerNumber); peers -= 1; Notify("Player left!"); } else if (phrases["stop"].IsMatch(match)) { Notify("Lobby closed."); lobbyState = LobbyState.CLOSED; } break; case LobbyState.FULL: if (phrases["start"].IsMatch(match)) { Notify("Game has started."); lobbyState = LobbyState.GAME; } else if (phrases["leave"].IsMatch(match)) { var result = phrases["leave"].Match(match); int.TryParse(result.Groups[1].Value, out peerNumber); peers -= 1; Notify("Player left!"); if (peers < maxPeers) { lobbyState = LobbyState.OPEN; } else { lobbyState = LobbyState.CLOSED; } } else if (phrases["stop"].IsMatch(match)) { Notify("Lobby closed."); lobbyState = LobbyState.CLOSED; } break; case LobbyState.GAME: if (phrases["stop"].IsMatch(match)) { Notify("Lobby closed."); lobbyState = LobbyState.CLOSED; } break; } } } streamPosition = stream.Position; } } } } reading = false; }
public void OnMonitorStopped() { MonitorStopped?.Invoke(this, new MonitorActivityEventArgs { Message = "Activity monitor stopped", Time = DateTime.Now }); }