/// <summary> /// Sets the visible packet. /// </summary> /// <param name="index">The index.</param> /// <param name="packetInfo">The packet info.</param> public void SetVisiblePacket(int index, PacketInfo packetInfo) { m_packetTextLocations.SetVisiblePacket(index, packetInfo); }
private void UpdateLogDataTab() { try { string newTabName = "Log data"; if (FilterManager.FiltersCount > 0) { newTabName += " (filtered)"; } logDataTab.Text = newTabName; if (logDataDisableUpdatesCheckBox.Checked) return; if (LogManager == null) { logDataText.Clear(); return; } PacketLocation selectedPacket = PacketLocation.UNKNOWN; if (logDataText.TextLength > 0) { selectedPacket = LogManager.FindPacketInfoByTextIndex(logDataText.SelectionStart).PacketLocation; } // Clear current log data before new memory is allocated this.logDataText.SuspendLayout(); logDataText.Clear(); logDataText.Rtf = null; GC.Collect(); bool timeDiff = packetTimeDiffMenuItem.Checked; bool showPacketSequence = mnuPacketSequence.Checked; TimeSpan baseTime = TimeSpan.Zero; LogDataStatistics stats = LogDataStatistics.Zero; // // Calculate the size of string buffer // IList<PacketLog> logs = LogManager.Logs; int visiblePacketsCount = 0; int logSize = 0; const string NEW_LINE = "\n"; FilterManager.LogFilteringStarted(this); try { MemoryStream ms = new MemoryStream(); using (StreamWriter text = new CustomStreamWriter(ms)) { // Use the same new line char as in rich text box text.NewLine = NEW_LINE; // Count text only if checkbox enabled, but need to count packets all the time StreamWriter textImpl = (logDataCountLogDataSizeheckBox.Checked ? text : null); foreach (PacketLog log in logs) { foreach (Packet pak in log) { #warning TODO: Sum of bytes here is not equal to what is shown in text box? if (!FilterManager.IsPacketIgnored(pak)) { visiblePacketsCount++; if (null != textImpl) { AppendPacketData(textImpl, pak, ref stats, showPacketSequence, ref baseTime, timeDiff); text.Flush(); logSize += (int) ms.Position; ms.Position = 0; } } } } } } finally { FilterManager.LogFilteringStopped(this); } // Reset variables after log data size is counted stats = LogDataStatistics.Zero; baseTime = TimeSpan.Zero; // Notify filter manager that log filtering starts FilterManager.LogFilteringStarted(this); // Decide which initial buffer size is used int capacity = 0; if (logDataCountLogDataSizeheckBox.Checked) { capacity = logSize; } // Update count of visible packets LogManager.SetVisiblePacketsCount(visiblePacketsCount); try { MemoryStream ms = new MemoryStream(capacity); using (StreamWriter text = new CustomStreamWriter(ms)) { // Use the same new line char as in rich text box text.NewLine = NEW_LINE; int packetIndex = 0; for (int logIndex = 0; logs.Count > logIndex; logIndex++) { PacketLog log = logs[logIndex]; log.LogSelected = true; for (int logPacketIndex = 0; log.Count > logPacketIndex; logPacketIndex++) { Packet pak = log[logPacketIndex]; if (!FilterManager.IsPacketIgnored(pak)) { log.LogSelected = false; AppendPacketData(text, pak, ref stats, showPacketSequence, ref baseTime, timeDiff); text.Flush(); int index = (int)ms.Position; // Store visible packet info PacketInfo packetInfo = new PacketInfo(pak, index, new PacketLocation(logIndex, logPacketIndex)); LogManager.SetVisiblePacket(packetIndex++, packetInfo); } } } newTabName = string.Format("{0} ({1}{2:N0} packets)", newTabName, (timeDiff ? "time diff, " : ""), stats.PacketsCount); logDataTab.Text = newTabName; // Load text to richbox from the very beginning ms.Position = 0; logDataText.SelectionIndent = 4; logDataText.LoadFile(ms, RichTextBoxStreamType.PlainText); } ms = null; GC.Collect(); } finally { // Notify filter manager that filtering is finished FilterManager.LogFilteringStopped(this); // need this really ? // this.logDataText.ResumeLayout(); // it need really ? this.openLogsDataGridView.Invalidate(); } // Restore previously selected packet if it is visible int restoreIndex = -1; if (PacketLocation.UNKNOWN != selectedPacket && logs.Count > selectedPacket.LogIndex && logs[selectedPacket.LogIndex].Count > selectedPacket.PacketIndex) { Packet restorePacket = LogManager.GetPacket(selectedPacket); if (null != restorePacket) { restoreIndex = LogManager.FindTextIndexByPacket(restorePacket); } } if (restoreIndex >= 0) { logDataText.SelectionStart = restoreIndex; } } catch (Exception e) { Log.Error("updating data tab", e); } }