/// <summary> /// Parse the first line of the tace file /// </summary> /// <param name="traceFilePath"></param> /// <returns></returns> public static ObservableCollection <XdebugTraceItem> ReadTraceFile(string traceFilePath) { traceFile = File.OpenText(traceFilePath); var traces = new ObservableCollection <XdebugTraceItem>(); XdebugTraceItem firstTraceItem = null; var firstValidRecordNotFound = true; while (firstValidRecordNotFound) { var recordLine = traceFile.ReadLine(); var traceRecord = SplitRecord(ref recordLine); if (traceRecord == null) { return(traces); } if (traceRecord.Length == 0) { continue; } firstTraceItem = new XdebugTraceItem(ref traceRecord) { IsExpanded = true }; firstValidRecordNotFound = false; } traces.Add(firstTraceItem); ParseRemainingFileContent(ref traces); traceFile.Close(); return(traces); }
/// <summary> /// Parse all remaining lines of the trace file /// </summary> /// <param name="traces"></param> /// <returns></returns> private static string[] ParseRemainingFileContent(ref ObservableCollection <XdebugTraceItem> traces) { var record = new string[0]; var doLoop = true; while (doLoop) { if (record.Length <= 0) { string recordLine; doLoop = (recordLine = traceFile.ReadLine()) != null; if (!doLoop) { return(new string[0]); } record = SplitRecord(ref recordLine); if (record.Length == 0) { break; } } var traceCounter = traces.Count; if (int.Parse(record[0]) < traces[traceCounter - 1].Level) { return(record); } var traceItem = new XdebugTraceItem(ref record); if (traceItem.Level == traces[traceCounter - 1].Level) { switch (record[2]) { case "1": traces[traceCounter - 1].SetExecutionTime(ref record); record = new string[0]; continue; case "R": traces[traceCounter - 1].SetReturnValue(ref record); record = new string[0]; continue; } traces.Add(traceItem); record = new string[0]; continue; } var newSubElement = new ObservableCollection <XdebugTraceItem> { traceItem }; record = ParseRemainingFileContent(ref newSubElement); traces[traceCounter - 1].SubElements = newSubElement; } return(new string[0]); }