Beispiel #1
0
        public static string GetTagStreamText(GDMTag tag, int level, bool debugWrite = true)
        {
            GEDCOMProvider.DebugWrite = debugWrite;

            string result;

            using (MemoryStream stm = new MemoryStream()) {
                using (StreamWriter fs = new StreamWriter(stm)) {
                    if (tag is GDMRecord)
                    {
                        GEDCOMProvider.WriteRecordEx(fs, (GDMRecord)tag);
                    }
                    else
                    {
                        if (tag is GDMPersonalName)
                        {
                            GEDCOMProvider.WritePersonalName(fs, 1, tag);
                        }
                        else if (tag is GDMMultimediaLink)
                        {
                            GEDCOMProvider.WriteMultimediaLink(fs, 1, tag);
                        }
                        else if (tag is GDMSourceCitation)
                        {
                            GEDCOMProvider.WriteSourceCitation(fs, 1, tag);
                        }
                        else if (tag is GDMSourceData)
                        {
                            GEDCOMProvider.WriteSourceData(fs, 1, tag);
                        }
                        else
                        {
                            GEDCOMProvider.WriteBaseTag(fs, level, tag);
                        }
                    }
                    fs.Flush();
                    result = Encoding.ASCII.GetString(stm.ToArray());
                }
            }
            return(result);
        }
Beispiel #2
0
        public void Test_SetTagStringsL()
        {
            var tag = GDMTag.Create(null, GEDCOMTagsTable.Lookup("TEST"), "");

            Assert.IsNotNull(tag);

            // very long string, 248"A" and " BBB BBBB"
            var strings = new GDMLines("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA BBB BBBB");

            GEDCOMUtils.SetTagStrings(null, strings);

            GEDCOMUtils.SetTagStrings(tag, strings);

            Assert.AreEqual(248, tag.StringValue.Length);

            var strList = GEDCOMUtils.GetTagStrings(tag);

            Assert.IsNotNull(strList);
            Assert.AreEqual(1, strList.Count);
            Assert.AreEqual(strings.Text, strList.Text);
        }
Beispiel #3
0
        private void ListModify(object sender, ModifyEventArgs eArgs)
        {
            GDMTag itemTag = eArgs.ItemData as GDMTag;

            if ((eArgs.Action == RecordAction.raEdit || eArgs.Action == RecordAction.raDelete) && (itemTag == null))
            {
                return;
            }

            if (sender == fPhonesList)
            {
                fController.DoPhonesAction(eArgs.Action, itemTag);
            }
            else if (sender == fMailsList)
            {
                fController.DoMailsAction(eArgs.Action, itemTag);
            }
            else if (sender == fWebsList)
            {
                fController.DoWebsAction(eArgs.Action, itemTag);
            }
        }
Beispiel #4
0
        protected override void LoadFromReader(Stream fileStream, StreamReader reader, string streamCharset = null)
        {
            fTree.State = GDMTreeState.osLoading;
            try {
                ProgressEventHandler progressHandler = fTree.OnProgress;

                long fileSize = fileStream.Length;
                int  progress = 0;

                GDMIndividualRecord lastIndividual = null;
                GDMTag        lastTag     = null;
                GEDCOMTagType lastTagType = GEDCOMTagType.Unknown;

                XmlReaderSettings settings = new XmlReaderSettings();
                settings.DtdProcessing = DtdProcessing.Ignore;
                using (XmlReader xr = XmlReader.Create(fileStream, settings)) {
                    while (xr.Read())
                    {
                        if (xr.NodeType == XmlNodeType.Element && !xr.IsEmptyElement)
                        {
                            if (xr.Name == "Person")
                            {
                                lastIndividual = fTree.CreateIndividual();
                                var persName = new GDMPersonalName(lastIndividual);
                                lastIndividual.AddPersonalName(persName);

                                lastIndividual.UID = xr.GetAttribute("Id");
                            }
                            else if (xr.Name == "Gender")
                            {
                                lastTagType = GEDCOMTagType.SEX;
                                lastTag     = null;
                            }
                            else if (xr.Name == "FirstName")
                            {
                                lastTagType = GEDCOMTagType.GIVN;
                                lastTag     = null;
                            }
                            else if (xr.Name == "LastName")
                            {
                                lastTagType = GEDCOMTagType.SURN;
                                lastTag     = null;
                            }
                        }
                        else if (xr.NodeType == XmlNodeType.Text)
                        {
                            string nodeValue = xr.Value;

                            if (lastTag != null)
                            {
                                lastTag = null;
                            }
                            else
                            {
                                switch (lastTagType)
                                {
                                case GEDCOMTagType.SEX:
                                    if (nodeValue == "Male")
                                    {
                                        lastIndividual.Sex = GDMSex.svMale;
                                    }
                                    else if (nodeValue == "Female")
                                    {
                                        lastIndividual.Sex = GDMSex.svFemale;
                                    }
                                    break;

                                case GEDCOMTagType.GIVN:
                                    lastIndividual.PersonalNames[0].FirstPart = nodeValue;
                                    break;

                                case GEDCOMTagType.SURN:
                                    lastIndividual.PersonalNames[0].Surname = nodeValue;
                                    break;
                                }
                                lastTagType = GEDCOMTagType.Unknown;
                            }
                        }

                        if (progressHandler != null)
                        {
                            int newProgress = (int)Math.Min(100, (fileStream.Position * 100.0f) / fileSize);
                            if (progress != newProgress)
                            {
                                progress = newProgress;
                                progressHandler(fTree, progress);
                            }
                        }
                    }
                }
            } finally {
                fTree.State = GDMTreeState.osReady;
            }
        }
Beispiel #5
0
        private static string FindSubTagValue(GDMTag tag, string subTagName)
        {
            var subTag = tag.FindTag(subTagName, 0);

            return((subTag == null) ? string.Empty : subTag.StringValue);
        }
Beispiel #6
0
        protected override void LoadFromReader(Stream fileStream, StreamReader reader, string streamCharset = null)
        {
            fTree.State = GDMTreeState.osLoading;
            try {
                ProgressEventHandler progressHandler = fTree.OnProgress;

                long fileSize      = fileStream.Length;
                int  progress      = 0;
                var  invariantText = GEDCOMUtils.InvariantTextInfo;

                var    strTok    = new GEDCOMParser(false);
                GDMTag curRecord = null;
                GDMTag curTag    = null;
                var    stack     = new Stack <StackTuple>(9);

                XmlReaderSettings settings = new XmlReaderSettings();
                settings.DtdProcessing = DtdProcessing.Ignore;

                int    tagLevel = -1;
                string xrefPtr, tagName = null, tagValue = null, xrefId;
                int    tagId     = 0; // Unknown
                bool   tagOpened = false;

                using (XmlReader xr = XmlReader.Create(reader, settings)) {
                    while (xr.Read())
                    {
                        if (xr.NodeType == XmlNodeType.Element)
                        {
                            if (tagOpened)
                            {
                                curTag    = GEDCOMProvider.ProcessTag(stack, tagLevel, tagId, tagValue);
                                tagOpened = false;
                            }

                            tagName  = invariantText.ToUpper(xr.Name); // the name of the current element
                            tagId    = GEDCOMTagsTable.Lookup(tagName);
                            tagLevel = xr.Depth - 1;
                            // GEDML only has 2 attributes - REF and ID.
                            xrefPtr  = xr.GetAttribute("REF");
                            xrefId   = xr.GetAttribute("ID");
                            tagValue = string.Empty;

                            if (tagLevel == 0)
                            {
                                StackTuple stackTuple = GEDCOMProvider.AddTreeTag(fTree, tagLevel, tagId, string.Empty);
                                if (stackTuple != null)
                                {
                                    stack.Clear();
                                    stack.Push(stackTuple);

                                    curRecord = stackTuple.Tag;
                                    if (!string.IsNullOrEmpty(xrefId))
                                    {
                                        ((GDMRecord)curRecord).XRef = xrefId;
                                    }
                                }
                            }
                            else if (tagLevel > 0)
                            {
                                if (!string.IsNullOrEmpty(xrefPtr))
                                {
                                    // since the default method of the GEDCOM provider is used,
                                    // a standard character `@` is expected
                                    curTag = GEDCOMProvider.ProcessTag(stack, tagLevel, tagId, "@" + xrefPtr + "@");
                                }
                                else
                                {
                                    tagOpened = true;
                                }
                            }
                        }
                        else if (xr.NodeType == XmlNodeType.Text)
                        {
                            tagValue = xr.Value;

                            if (tagLevel > 0 && curRecord != null)
                            {
                                curTag = GEDCOMProvider.ProcessTag(stack, tagLevel, tagId, tagValue);
                            }
                        }

                        if (progressHandler != null)
                        {
                            int newProgress = (int)Math.Min(100, (fileStream.Position * 100.0f) / fileSize);
                            if (progress != newProgress)
                            {
                                progress = newProgress;
                                progressHandler(fTree, progress);
                            }
                        }
                    }
                }

                stack.Clear();
            } finally {
                fTree.State = GDMTreeState.osReady;
            }
        }