private void MessageQueueLogger() { bool wasLockTaken = false; try { Monitor.TryEnter(Intercepted, ref wasLockTaken); if (!wasLockTaken) { return; } while (Intercepted.Count > 0) { DataInterceptedEventArgs args = Intercepted.Dequeue(); bool isOutgoing = (args.Packet.Destination == HDestination.Server); if (!IsLoggingAuthorized(args, isOutgoing)) { continue; } WritePacketLog(args, isOutgoing); WriteHighlight("--------------------\r\n", SpecialHighlight); RefreshLog(); } } finally { if (wasLockTaken) { Monitor.Exit(Intercepted); Application.DoEvents(); } } }
private void PushToQueue(InterceptedEventArgs e) { Intercepted.Enqueue(e); if (_readQueueTask != null && _readQueueTask.IsCompleted) { _readQueueTask = Task.Factory.StartNew( RunDisplayQueueLoop, TaskCreationOptions.LongRunning); } }
protected override void OnFormClosing(FormClosingEventArgs e) { e.Cancel = IsHalted = true; Intercepted.Clear(); LoggerTxt.Clear(); base.OnFormClosing(e); WindowState = FormWindowState.Minimized; }
protected override void OnFormClosing(FormClosingEventArgs e) { IsLoaded = false; e.Cancel = IsHalted = true; WindowState = FormWindowState.Minimized; Intercepted.Clear(); _readQueueTask?.Wait(); LoggerTxt.Clear(); }
private void PushToQueue(DataInterceptedEventArgs e) { lock (_pushToQueueLock) { if (IsLoggingAuthorized(e)) { Intercepted.Enqueue(e); LogMessageQueue(); } } }
private void PushToQueue(DataInterceptedEventArgs e) { if (IsHalted) { return; } lock (_pushToQueueLock) { Intercepted.Enqueue(e); LogMessageQueue(); } }
protected override void OnFormClosing(FormClosingEventArgs e) { IsReceiving = false; e.Cancel = true; Intercepted.Clear(); LoggerTxt.Clear(); WindowState = FormWindowState.Minimized; base.OnFormClosing(e); }
protected override void OnFormClosing(FormClosingEventArgs e) { e.Cancel = IsHalted = true; Intercepted.Clear(); IsHandlingOutgoing = IsHandlingIncoming = false; LoggerTxt.Clear(); WindowState = FormWindowState.Minimized; base.OnFormClosing(e); }
private void PushToQueue(object sender, InterceptedEventArgs e) { if (e.IsBlocked && !DisplayBlocked) { return; } Intercepted.Enqueue(e); if (!_isReadingQueue) { _readQueueTask = Task.Factory.StartNew( RunDisplayQueueLoop, TaskCreationOptions.LongRunning); } }
private void RunDisplayQueueLoop() { if (!_isReadingQueue && Monitor.TryEnter(Intercepted)) { _isReadingQueue = true; try { while (Intercepted.Count > 0) { InterceptedEventArgs e = Intercepted.Dequeue(); bool toServer = (e.Packet.Destination == HDestination.Server); if (toServer && !ViewOutgoing) { continue; } if (!toServer && !ViewIncoming) { continue; } if (e.IsBlocked && !DisplayBlocked) { continue; } while (!IsLoaded) { Thread.Sleep(100); } Write(e); } } finally { Monitor.Exit(Intercepted); _isReadingQueue = false; } } else { return; } }
private void RunDisplayQueueLoop() { if (Monitor.TryEnter(Intercepted)) { try { while (Intercepted.Count > 0) { InterceptedEventArgs args = Intercepted.Dequeue(); bool toServer = (args.Packet.Destination == HDestination.Server); if (args.IsBlocked && !DisplayBlocked) { continue; } if (toServer && !IsHandlingOutgoing) { continue; } if (!toServer && !IsHandlingIncoming) { continue; } string packetLog = ExtractPacketLog(args.Replacement, toServer); Color packetLogHighlight = (toServer ? OutgoingHighlight : IncomingHighlight); if (args.IsBlocked) { WriteHighlight("Blocked ", BlockHighlight); } else if (args.WasReplaced) { WriteHighlight("Replaced ", ReplaceHighlight); } WriteHighlight(packetLog + "\r\n", packetLogHighlight); if (DisplayStructures) { string structureLog = ExtractStructureLog(args.Replacement, toServer); if (!string.IsNullOrWhiteSpace(structureLog)) { WriteHighlight(structureLog + "\r\n", PacketStructHighlight); } } if (args.Executions.Count > 0) { WriteHighlight("\r\n", BackColor); for (int i = 0; i < args.Executions.Count; i++) { HMessage packet = args.Executions[i]; WriteHighlight(ExtractPacketLog(packet, toServer) + "\r\n", packetLogHighlight); } } WriteHighlight("--------------------\r\n", packetLogHighlight); RefreshLog(); } } finally { Monitor.Exit(Intercepted); Application.DoEvents(); } } }
/// <summary> /// Используется внутренне в WebViewJsInterceptor. Вызывать это не нужно. /// </summary> /// <param name="interceptedDataJson"></param> public void InvokeEvent(Func <string> getInterceptedDataJson) { Intercepted?.Invoke(this, getInterceptedDataJson); }
private void SynthesizerIntercepter_Intercepted(object sender, InterceptedEventArgs e) { Intercepted?.Invoke(this, e); }