Ejemplo n.º 1
0
        public void Parse(IGraphBuilder builder)
        {
            var familyParser = new FamilyParser(builder);

            forEachNode(DEFAULT_INSTANCE).Do(familyParser.ParseDefaultElement);
            forEachNode(ADD_INSTANCE_NODE).Do(familyParser.ParseInstanceElement);

            ParseProfiles(builder);
        }
        public void SetUp()
        {
            var builder = new GraphBuilder(new Registry[0]);

            _graph = builder.PluginGraph;

            _parser =
                new FamilyParser(builder,
                                 new XmlMementoCreator(XmlMementoStyle.NodeNormalized, XmlConstants.TYPE_ATTRIBUTE,
                                                       XmlConstants.ATTRIBUTE_STYLE));

            _document = new XmlDocument();
            _document.LoadXml("<PluginFamily />");
            _familyElement = _document.DocumentElement;

            thePluginType = typeof(IGateway);

            TypePath.WriteTypePathToXmlElement(thePluginType, _familyElement);
        }
Ejemplo n.º 3
0
        public void Parse(ILineProvider lineProvider)
        {
            GedcomLine lastLine = default;

            var firstRawLine = lineProvider.ReadLine();

            if (firstRawLine == null)
            {
                throw new InvalidOperationException("File empty");
            }

            var firstLine = ParserHelper.ParseLine(firstRawLine);

            if (firstLine.Level != 0 && !ParserHelper.Equals(firstLine.GetFirstItem(), "HEAD"))
            {
                throw new InvalidOperationException("GEDCOM Header Not Found");
            }

            var gedcomHeaderParse = HeaderParser.Parse(firstLine, lineProvider);

            _headerCallback?.Invoke(gedcomHeaderParse.Result);

            var newLine = gedcomHeaderParse.Line;

            lastLine = newLine;

            while (newLine.LineContent.Length > 0)
            {
                var content = newLine.GetLineContent();
                if (content.Length == 0)
                {
                    var unrecognisedRawLine = lineProvider.ReadLine();
                    if (unrecognisedRawLine != null)
                    {
                        newLine  = ParserHelper.ParseLine(unrecognisedRawLine);
                        lastLine = newLine;
                    }
                    else
                    {
                        newLine = default;
                    }
                    continue;
                }

                var unknown = false;

                if (ParserHelper.Equals(content, "INDI"))
                {
                    var individualParseResult = IndividualParser.Parse(newLine, lineProvider);
                    _individualCallback?.Invoke(individualParseResult.Result);
                    newLine  = individualParseResult.Line;
                    lastLine = newLine;
                }
                else if (ParserHelper.Equals(content, "FAM"))
                {
                    var familyParseResult = FamilyParser.Parse(newLine, lineProvider);
                    _familyCallback?.Invoke(familyParseResult.Result);
                    newLine  = familyParseResult.Line;
                    lastLine = newLine;
                }
                else if (ParserHelper.Equals(content, "NOTE"))
                {
                    var noteParseResult = NoteParser.Parse(newLine, lineProvider);
                    _noteCallback?.Invoke(noteParseResult.Result);
                    newLine  = noteParseResult.Line;
                    lastLine = newLine;
                }
                else if (ParserHelper.Equals(content, "OBJE"))
                {
                    var objParserResult = ObjectParser.Parse(newLine, lineProvider);
                    _imageCallback?.Invoke(objParserResult.Result);
                    newLine  = objParserResult.Line;
                    lastLine = newLine;
                }
                else
                {
                    var unrecognisedRawLine = lineProvider.ReadLine();
                    if (unrecognisedRawLine != null)
                    {
                        newLine  = ParserHelper.ParseLine(unrecognisedRawLine);
                        lastLine = newLine;
                    }
                    else
                    {
                        newLine = default;
                    }
                    unknown = true;
                }

                if (unknown)
                {
                    continue;
                }
            }

            if (lastLine.LineContent.Length == 0)
            {
                throw new InvalidOperationException("file contains no content");
            }

            if (lastLine.Level != 0 || !ParserHelper.Equals(lastLine.GetFirstItem(), "TRLR"))
            {
                throw new InvalidOperationException("GEDCOM TRLR not found");
            }
        }