public void ObjectDecodeStart(String objectName, GedcomLineObject gedcomLineObject) { if (!trace.Switch.Level.HasFlag(SourceLevels.Information)) { return; } if (objectName != null) { trace.TraceInformation(objectName + ":start ==============================================="); } for (int i = 0; i < gedcomLineObject.gedcomLines.Count; i++) { GedcomLineData lineData = gedcomLineObject.gedcomLines[i]; if (lineData.xrefIdString.Length > 0) { trace.TraceInformation(" xref: " + lineData.xrefIdString + " "); } //trace.TraceInformation(" individual-line: " + lineData.level + " " + lineData.tagString + " " + lineData.valueString + " "); trace.TraceInformation(lineData.lineNo + " " + lineData.tagString + " " + lineData.valueString + " "); if (lineData.child != null) { ObjectDecodeStart(null, lineData.child); } } if (objectName != null) { trace.TraceInformation(objectName + ":end ==============================================="); } }
public GedcomLineData DecodeLine() { int parsePos = 0; bool failure = false; if (linePos == 0) { lineNo++; return(null); } //trace.TraceInformation("DecodeLine start"); lineData = new GedcomLineData(); if (trace.Switch.Level.HasFlag(SourceLevels.Information)) { DebugStringAdd("Line:" + lineNo + " [line start]"); for (int i = 0; i < linePos; i++) { DebugStringAdd(lineBuffer[i].ToString()); } DebugStringAdd(""); DebugStringAdd("[line end]"); } tempString = ""; while (parser.IsBlankChar(lineBuffer[parsePos])) { parsePos++; } while (!parser.IsBlankChar(lineBuffer[parsePos])) { tempString += lineBuffer[parsePos++]; } lineData.level = DecodeLevelString(tempString, ref failure); while (parser.IsBlankChar(lineBuffer[parsePos])) { parsePos++; } if (lineBuffer[parsePos] == '@') { tempString = ""; while (!parser.IsBlankChar(lineBuffer[parsePos])) { tempString += lineBuffer[parsePos++]; } if (!DecodeXrefString(tempString)) { DebugStringAdd("Line:" + lineNo + " invalid xref id string!"); failure = true; } while (parser.IsBlankChar(lineBuffer[parsePos])) { parsePos++; } } tempString = ""; while (!parser.IsBlankChar(lineBuffer[parsePos]) && (parsePos < linePos)) { tempString += lineBuffer[parsePos++]; } if (!DecodeTagString(tempString) && !failure) { DebugStringAdd("Line:" + lineNo + " invalid tag!"); failure = true; } tempString = ""; // Only eat first blank character in value part. if (parser.IsBlankChar(lineBuffer[parsePos])) { parsePos++; } while (parsePos < linePos) { tempString += lineBuffer[parsePos++]; } if (!DecodeValueString(tempString) && !failure) { DebugStringAdd("Line:" + lineNo + " invalid value!"); failure = true; } if ((lineData.tagString.Length < 3) && !failure) { DebugStringAdd("Line:" + lineNo + " invalid tag: " + lineData.tagString); failure = true; } if (!failure) { lineData.valid = true; } lineData.lineNo = lineNo; linePos = 0; lineNo++; if (trace.Switch.Level.HasFlag(SourceLevels.Information)) { lineData.Print(); } return(lineData); }
private void Parse(ref GedcomImportResult importResult) { bool bomFound = false; GedcomLineObject rootLineObject = new GedcomLineObject(0); GedcomParserProgress progress = new GedcomParserProgress(fileBuffer.GetBuffer(), fileBuffer.GetSize()); double lastPrintPercent = 0.0; double printPercent; GedcomLineObject currentLineObject = rootLineObject; GedcomLineData prevLineData = null; int lineDiff = 0; uint lineLength; //string importResult = ""; bomFound = CheckBomMark(ref progress, ref importResult); GedcomTreeDecoderClass treeDecoder = new GedcomTreeDecoderClass(ref familyTree, ref importResult); treeDecoder.SetCharacterSet(characterSet); while (!progress.IsEndOfFile()) { GedcomLineData lineData; line.SetDebugString(importResult); lineLength = line.ReadLine(ref progress); lineData = line.DecodeLine(); importResult = line.GetDebugString(); parsedLines++; if ((lineData != null) && lineData.valid) { if (lineData.level == (currentLineObject.GetLevel() + 1)) { GedcomLineObject subLineObject = new GedcomLineObject(lineData.level); subLineObject.parent = currentLineObject; if (prevLineData != null) { prevLineData.child = subLineObject; } currentLineObject = subLineObject; } /*else if (currentLineObject.GetLevel() == lineData.level) * { * }*/ else if (lineData.level < currentLineObject.GetLevel()) { bool decodeDone = false; printPercent = 100.0 * (double)progress.position / (double)progress.size; if ((printPercent - lastPrintPercent) > 0.10) { if (backgroundWorker != null) { backgroundWorker.ReportProgress((int)printPercent, "Working..."); } lastPrintPercent = printPercent; if (trace.Switch.Level.HasFlag(SourceLevels.Information)) { trace.TraceInformation("Decode position 1 " + progress.position + " (" + progress.size + ") " + DateTime.Now.ToString()); trace.TraceInformation("Lines " + parsedLines + " (" + treeDecoder.GetDecodedLines() + ") " + printPercent.ToString("F") + "%"); familyTree.PrintShort(); } } do { if (currentLineObject.parent != null) { currentLineObject = currentLineObject.parent; if ((currentLineObject.GetLevel() == 0) && (parsedLines > 0)) { treeDecoder.DecodeObject(currentLineObject); currentLineObject.Clear(); if (treeDecoder.GetCharacterSet() != characterSet) { if (bomFound) { treeDecoder.DebugStringAdd("Warning! BOM and character set in Gedcom part mismatches! " + treeDecoder.GetCharacterSet() + "," + characterSet); } SetCharacterSet(treeDecoder.GetCharacterSet()); } } } else { if ((parsedLines - 1) - treeDecoder.GetDecodedLines() - 1 > lineDiff) { treeDecoder.DebugStringAdd("Decode position " + progress.position + " (" + progress.size + ")"); treeDecoder.DebugStringAdd("Lines " + parsedLines + " (" + treeDecoder.GetDecodedLines() + "," + lineDiff + ")"); treeDecoder.DebugStringAdd("New undecoded lines: " + (parsedLines - treeDecoder.GetDecodedLines() - lineDiff) + "!"); lineDiff = parsedLines - treeDecoder.GetDecodedLines(); } if (trace.Switch.Level.HasFlag(SourceLevels.Information)) { trace.TraceInformation("Decode position 2 " + progress.position + " (" + progress.size + ")"); trace.TraceInformation("Lines " + parsedLines + " (" + treeDecoder.GetDecodedLines() + ")"); familyTree.PrintShort(); } currentLineObject.gedcomLines.Clear(); decodeDone = true; } } while ((currentLineObject.GetLevel() > lineData.level) && !decodeDone); } prevLineData = lineData; currentLineObject.gedcomLines.Add(lineData); } else { if (lineData != null) { treeDecoder.DebugStringAdd("Line:" + lineData.lineNo + " Error bad gedcom line [" + lineData + "]"); } else { treeDecoder.DebugStringAdd("Line: " + parsedLines + ": Error bad gedcom line:no data found "); } } if (progress.IsEndOfFile()) { treeDecoder.DecodeObject(currentLineObject); if (treeDecoder.GetCharacterSet() != characterSet) { if (bomFound) { treeDecoder.DebugStringAdd("Warning! BOM and character set in Gedcom part mismatches! " + treeDecoder.GetCharacterSet() + "," + characterSet); } SetCharacterSet(treeDecoder.GetCharacterSet()); } treeDecoder.DebugStringAdd("Line:" + lineData.lineNo + " end of file " + parsedLines); if (lineData.level != 0) { treeDecoder.DebugStringAdd("Line:" + lineData.lineNo + "Error: The Gedcom file did not end correctly! Was it inomplete? = " + currentLineObject.gedcomLines.Count); } if (!treeDecoder.DecodingCompleted()) { treeDecoder.DebugStringAdd("Line:" + lineData.lineNo + "Error: The Gedcom file did not end correctly! No trailer detected = " + currentLineObject.gedcomLines.Count); } treeDecoder.ShowUnknownTags(); } } backgroundWorker = null; treeDecoder.DebugStringAdd("Gedcom file parsing finished at " + currentLineObject.gedcomLines.Count); importResult = treeDecoder.GetImportResult(); }