Ejemplo n.º 1
0
        /// <summary>
        /// Adding nested sub-tags.
        /// </summary>
        /// <param name="tagName">A name of sub-tag.</param>
        /// <param name="tagValue">A string value of sub-tag.</param>
        /// <param name="tagConstructor">The default constructor of sub-tag.</param>
        /// <returns></returns>
        public virtual GEDCOMTag AddTag(string tagName, string tagValue, TagConstructor tagConstructor)
        {
            GEDCOMTag tag = null;

            try
            {
                if (tagConstructor != null)
                {
                    tag = tagConstructor(fOwner, this, tagName, tagValue);
                }
                else
                {
                    tag = GEDCOMFactory.GetInstance().CreateTag(fOwner, this, tagName, tagValue);
                    if (tag == null)
                    {
                        tag = new GEDCOMTag(fOwner, this, tagName, tagValue);
                    }
                }

                InsertTag(tag);
            }
            catch (Exception ex)
            {
                Logger.LogWrite("GEDCOMTag.AddTag(): " + ex.Message);
            }
            return(tag);
        }
Ejemplo n.º 2
0
        private GEDCOMTag CreateCopy(GEDCOMTag sourceTag)
        {
            GEDCOMTag result = (GEDCOMTag)Activator.CreateInstance(sourceTag.GetType(), new object[] { Owner, this, "", "" });

            result.Assign(sourceTag);
            return(result);
        }
Ejemplo n.º 3
0
        public string GetTagStringValue(string tagName)
        {
            GEDCOMTag tag    = FindTag(tagName, 0);
            string    result = ((tag == null) ? "" : tag.StringValue);

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This function compares dates only by chronological year.
        /// Month and day are not taken into account, the year is compared with the calendar.
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="matchParams"></param>
        /// <returns></returns>
        public override float IsMatch(GEDCOMTag tag, MatchParams matchParams)
        {
            if (tag == null)
            {
                return(0.0f);
            }
            GEDCOMDateValue date = (GEDCOMDateValue)tag;

            if (IsEmpty() || date.IsEmpty())
            {
                return(0.0f);
            }

            int absVal1 = this.GetChronologicalYear();
            int absVal2 = date.GetChronologicalYear();

            float match   = 0.0f;
            float matches = 0.0f;

            if (absVal1 != 0 && absVal2 != 0)
            {
                matches += 1.0f;
                if (Math.Abs(absVal1 - absVal2) <= matchParams.YearsInaccuracy)
                {
                    match += 100.0f;
                }
            }

            return(match / matches);
        }
Ejemplo n.º 5
0
        protected virtual void SaveTagsToStream(StreamWriter stream)
        {
            if (Count <= 0)
            {
                return;
            }

            StringList savedTags = new StringList();

            try
            {
                savedTags.DuplicateSolve = DuplicateSolve.Ignore;
                savedTags.Sorted         = true;

                int num = Count;
                for (int i = 0; i < num; i++)
                {
                    savedTags.Add(this[i].Name);
                }

                if (savedTags.IndexOf("CONC") >= 0 || savedTags.IndexOf("CONT") >= 0)
                {
                    int num2 = Count;
                    for (int i = 0; i < num2; i++)
                    {
                        GEDCOMTag tmp = this[i];

                        if (tmp.Name == "CONC" || tmp.Name == "CONT")
                        {
                            tmp.SaveToStream(stream);
                        }
                    }

                    if (savedTags.IndexOf("CONC") >= 0)
                    {
                        savedTags.Delete(savedTags.IndexOf("CONC"));
                    }
                    if (savedTags.IndexOf("CONT") >= 0)
                    {
                        savedTags.Delete(savedTags.IndexOf("CONT"));
                    }
                }

                int num3 = Count;
                for (int i = 0; i < num3; i++)
                {
                    GEDCOMTag tmp = this[i];

                    if (tmp.Name != "CONT" && tmp.Name != "CONC")
                    {
                        tmp.SaveToStream(stream);
                    }
                }
            }
            finally
            {
                savedTags.Dispose();
            }
        }
Ejemplo n.º 6
0
 protected void AssignList(GEDCOMList <GEDCOMTag> srcList, GEDCOMList <GEDCOMTag> destList)
 {
     foreach (GEDCOMTag sourceTag in srcList)
     {
         GEDCOMTag copy = CreateCopy(sourceTag);
         destList.Add(copy);
     }
 }
Ejemplo n.º 7
0
        public void testCreate()
        {
            const string tagName = "BLAH";
            GEDCOMTag    result  = GEDCOMDate.Create(null, null, tagName, "");

            Assert.IsNotNull(result);
            Assert.AreEqual(tagName, result.Name);
        }
Ejemplo n.º 8
0
        public void testAssign()
        {
            GEDCOMPersonalName instance = new GEDCOMPersonalName(null, null, "", "");

            GEDCOMTag source = null;

            Assert.Throws(typeof(ArgumentException), () => {
                instance.Assign(source);
            });
        }
Ejemplo n.º 9
0
        public void testIsMatch()
        {
            var              matchParams = new MatchParams();
            GEDCOMTag        other       = GEDCOMAddress.Create(null, null, "", "");
            GEDCOMNoteRecord instance    = (GEDCOMNoteRecord)GEDCOMNoteRecord.Create(null, null, "", "");
            float            expResult   = 0.0F;
            float            result      = instance.IsMatch(other, matchParams); // TODO matchParams is not used

            Assert.AreEqual(expResult, result, 0.0);
        }
Ejemplo n.º 10
0
        public void Test_AddTag()
        {
            const string   tagName        = "BABA";
            const string   tagValue       = "YAGA";
            TagConstructor tagConstructor = null;
            GEDCOMAddress  instance       = (GEDCOMAddress)GEDCOMAddress.Create(null, null, "", "");
            GEDCOMTag      result         = instance.AddTag(tagName, tagValue, tagConstructor);

            Assert.IsNotNull(instance.FindTag(tagName, 0));
        }
Ejemplo n.º 11
0
        public void testCreate()
        {
            GEDCOMTree   owner     = null;
            GEDCOMObject parent    = null;
            string       tagName   = "";
            string       tagValue  = "";
            GEDCOMTag    expResult = null;
            GEDCOMTag    result    = GEDCOMPersonalName.Create(owner, parent, tagName, tagValue);

            Assert.IsNotNull(result);
        }
Ejemplo n.º 12
0
        public void testAssign()
        {
            // TODO review the generated test code and remove the default call to fail.
            GEDCOMDate instance = new GEDCOMDate(null, null, "", "");

            GEDCOMTag source = null;

            //Assert.Throws(typeof(ArgumentNullException), () => {
            instance.Assign(source);
            //});
        }
Ejemplo n.º 13
0
        public GEDCOMTag TagClass(string tagName, TagConstructor tagConstructor)
        {
            GEDCOMTag result = FindTag(tagName, 0);

            if (result == null)
            {
                result = AddTag(tagName, "", tagConstructor);
            }

            return(result);
        }
Ejemplo n.º 14
0
        public void Test_Assign()
        {
            GEDCOMTag     source   = null;
            GEDCOMAddress instance = (GEDCOMAddress)GEDCOMAddress.Create(null, null, "", "");

            Assert.Throws(typeof(ArgumentException), () => {
                instance.Assign(source);
            });

            source = (GEDCOMAddress)GEDCOMAddress.Create(null, null, "", "");
            instance.Assign(source);
        }
Ejemplo n.º 15
0
        public void testCreate()
        {
            GEDCOMTree   owner     = null;
            GEDCOMObject parent    = null;
            string       tagName   = "BLAH";
            string       tagValue  = "";
            GEDCOMTag    expResult = null;
            GEDCOMTag    result    = GEDCOMDate.Create(owner, parent, tagName, tagValue);

            Assert.IsNotNull(result);
            Assert.AreEqual(tagName, result.Name);
        }
Ejemplo n.º 16
0
        public void DeleteTag(string tagName)
        {
            GEDCOMTag tag = FindTag(tagName, 0);

            while (tag != null)
            {
                int idx = fTags.IndexOf(tag);
                fTags.DeleteAt(idx);

                tag = FindTag(tagName, idx);
            }
        }
Ejemplo n.º 17
0
        public virtual void MoveTo(GEDCOMRecord targetRecord, bool clearDest)
        {
            if (clearDest)
            {
                targetRecord.Clear();
            }

            if (fTags != null)
            {
                while (fTags.Count > 0)
                {
                    GEDCOMTag tag = fTags.Extract(0);
                    if (tag.Name == "CHAN" && !clearDest)
                    {
                        tag.Dispose();
                    }
                    else
                    {
                        tag.ResetParent(targetRecord);
                        targetRecord.InsertTag(tag);
                    }
                }
            }

            while (fNotes.Count > 0)
            {
                GEDCOMTag tag = fNotes.Extract(0);
                tag.ResetParent(targetRecord);
                targetRecord.Notes.Add((GEDCOMNotes)tag);
            }

            while (fMultimediaLinks.Count > 0)
            {
                GEDCOMTag tag = fMultimediaLinks.Extract(0);
                tag.ResetParent(targetRecord);
                targetRecord.MultimediaLinks.Add((GEDCOMMultimediaLink)tag);
            }

            while (fSourceCitations.Count > 0)
            {
                GEDCOMTag tag = fSourceCitations.Extract(0);
                tag.ResetParent(targetRecord);
                targetRecord.SourceCitations.Add((GEDCOMSourceCitation)tag);
            }

            while (fUserReferences.Count > 0)
            {
                GEDCOMTag tag = fUserReferences.Extract(0);
                tag.ResetParent(targetRecord);
                targetRecord.UserReferences.Add((GEDCOMUserReference)tag);
            }
        }
Ejemplo n.º 18
0
        public void SetTagStringValue(string tagName, string value)
        {
            string su = tagName;

            GEDCOMTag P = FindTag(su, 0);

            if (P != null)
            {
                P.StringValue = value;
            }
            else
            {
                GEDCOMTag O = this;
                while (su != "")
                {
                    string S;

                    int index = su.IndexOf('\\');
                    if (index >= 0)
                    {
                        S  = su.Substring(0, index);
                        su = su.Substring(index + 1);
                    }
                    else
                    {
                        S  = su;
                        su = "";
                    }

                    P = O.FindTag(S, 0);
                    if (P == null)
                    {
                        if (su == "")
                        {
                            P = O.AddTag(S, value, null);
                        }
                        else
                        {
                            P = O.AddTag(S, "", null);
                        }
                    }
                    else
                    {
                        if (su == "")
                        {
                            P.StringValue = value;
                        }
                    }
                    O = P;
                }
            }
        }
Ejemplo n.º 19
0
        public static void SetTagStrings(GEDCOMTag tag, string[] strings)
        {
            if (tag == null)
            {
                return;
            }

            tag.StringValue = "";
            for (int i = tag.Count - 1; i >= 0; i--)
            {
                string subtag = tag[i].Name;
                if (subtag == "CONT" || subtag == "CONC")
                {
                    tag.Delete(i);
                }
            }

            if (strings != null)
            {
                bool isRecordTag = (tag is GEDCOMRecord);

                int num = strings.Length;
                for (int i = 0; i < num; i++)
                {
                    string str = strings[i];

                    int    len = ((str.Length > MAX_LINE_LENGTH) ? MAX_LINE_LENGTH : str.Length);
                    string sub = str.Substring(0, len);
                    str = str.Remove(0, len);

                    if (i == 0 && !isRecordTag)
                    {
                        tag.StringValue = sub;
                    }
                    else
                    {
                        tag.AddTag("CONT", sub, null);
                    }

                    while (str.Length > 0)
                    {
                        len = ((str.Length > MAX_LINE_LENGTH) ? MAX_LINE_LENGTH : str.Length);
                        tag.AddTag("CONC", str.Substring(0, len), null);
                        str = str.Remove(0, len);
                    }
                }
            }
        }
Ejemplo n.º 20
0
        public override void Assign(GEDCOMTag source)
        {
            GEDCOMAddress otherAddr = source as GEDCOMAddress;

            if (otherAddr == null)
            {
                throw new ArgumentException(@"Argument is null or wrong type", "source");
            }

            base.Assign(source);

            AssignList(otherAddr.fPhoneList, fPhoneList);
            AssignList(otherAddr.fEmailList, fEmailList);
            AssignList(otherAddr.fFaxList, fFaxList);
            AssignList(otherAddr.fWWWList, fWWWList);
        }
Ejemplo n.º 21
0
 public void SetTagYNValue(string tagName, bool value)
 {
     if (value)
     {
         GEDCOMTag tag = FindTag(tagName, 0);
         if (tag == null)
         {
             tag = AddTag(tagName, "", null);
         }
         tag.StringValue = "Y";
     }
     else
     {
         DeleteTag(tagName);
     }
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Copying the sub-tags from the source to the current tag.
        /// </summary>
        /// <param name="source">A source tag.</param>
        public virtual void Assign(GEDCOMTag source /*, string[] skipList = null*/)
        {
            if (source == null)
            {
                return;
            }

            SetName(source.Name);
            SetStringValue(source.StringValue);

            foreach (GEDCOMTag sourceTag in source.fTags)
            {
                GEDCOMTag copy = CreateCopy(sourceTag);
                InsertTag(copy);
            }
        }
Ejemplo n.º 23
0
        public IList <GEDCOMTag> FindTags(string tagName)
        {
            IList <GEDCOMTag> result = new List <GEDCOMTag>();

            GEDCOMTag tag = FindTag(tagName, 0);

            while (tag != null)
            {
                int idx = fTags.IndexOf(tag);
                result.Add(tag);

                tag = FindTag(tagName, idx + 1);
            }

            return(result);
        }
Ejemplo n.º 24
0
        public GEDCOMTag FindTag(string tagName, int startIndex)
        {
            string su = tagName.ToUpperInvariant();

            int    pos = su.IndexOf('\\');
            string S   = ((pos >= 0) ? su.Substring(0, pos) : su);

            GEDCOMTag tempTag = this;

            while (true)
            {
                int index = ((S == su) ? startIndex : 0);

                while (index < tempTag.Count && tempTag[index].Name != S)
                {
                    index++;
                }

                if (index >= tempTag.Count)
                {
                    break;
                }

                GEDCOMTag resultTag = tempTag[index];
                tempTag = resultTag;

                pos = su.IndexOf('\\');
                if (pos >= 0)
                {
                    su = su.Substring(pos + 1);

                    pos = su.IndexOf('\\');
                    S   = ((pos >= 0) ? su.Substring(0, pos) : su);
                }
                else
                {
                    su = "";
                }

                if (su == "")
                {
                    return(resultTag);
                }
            }

            return(null);
        }
Ejemplo n.º 25
0
        public override void Assign(GEDCOMTag source)
        {
            GEDCOMPersonalName otherName = (source as GEDCOMPersonalName);

            if (otherName == null)
            {
                throw new ArgumentException(@"Argument is null or wrong type", "source");
            }

            base.Assign(otherName);

            fFirstPart = otherName.fFirstPart;
            fSurname   = otherName.fSurname;
            fLastPart  = otherName.fLastPart;

            fPieces.Assign(otherName.Pieces);
        }
Ejemplo n.º 26
0
        protected virtual void CreateObj(GEDCOMTree owner, GEDCOMObject parent)
        {
            fOwner       = owner;
            fParent      = parent;
            fTags        = new GEDCOMList <GEDCOMTag>(this);
            fStringValue = "";

            GEDCOMTag parentTag = parent as GEDCOMTag;

            if (parentTag != null)
            {
                fLevel = parentTag.Level + 1;
            }
            else
            {
                fLevel = 0;
            }
        }
Ejemplo n.º 27
0
        public override float IsMatch(GEDCOMTag tag, MatchParams matchParams)
        {
            GEDCOMSourceRecord otherSource = tag as GEDCOMSourceRecord;

            if (otherSource == null)
            {
                return(0.0f);
            }

            float match = 0.0f;

            if (string.Compare(FiledByEntry, otherSource.FiledByEntry, true) == 0)
            {
                match = 100.0f;
            }

            return(match);
        }
Ejemplo n.º 28
0
        public override void Assign(GEDCOMTag source)
        {
            GEDCOMRecordWithEvents sourceRec = source as GEDCOMRecordWithEvents;

            if (sourceRec == null)
            {
                throw new ArgumentException(@"Argument is null or wrong type", "source");
            }

            base.Assign(source);

            foreach (GEDCOMCustomEvent sourceEvent in sourceRec.fEvents)
            {
                GEDCOMCustomEvent copy = (GEDCOMCustomEvent)Activator.CreateInstance(sourceEvent.GetType(), new object[] { Owner, this, "", "" });
                copy.Assign(sourceEvent);
                AddEvent(copy);
            }
        }
Ejemplo n.º 29
0
        public override float IsMatch(GEDCOMTag tag, MatchParams matchParams)
        {
            GEDCOMNoteRecord note = tag as GEDCOMNoteRecord;

            if (note == null)
            {
                return(0.0f);
            }

            float match = 0.0f;

            if (string.Compare(Note.Text, note.Note.Text, true) == 0)
            {
                match = 100.0f;
            }

            return(match);
        }
Ejemplo n.º 30
0
        public override void Assign(GEDCOMTag source)
        {
            GEDCOMIndividualRecord sourceRec = source as GEDCOMIndividualRecord;

            if (sourceRec == null)
            {
                throw new ArgumentException(@"Argument is null or wrong type", "source");
            }

            base.Assign(source);

            foreach (GEDCOMPersonalName srcName in sourceRec.fPersonalNames)
            {
                GEDCOMPersonalName copyName = (GEDCOMPersonalName)GEDCOMPersonalName.Create(Owner, this, "", "");
                copyName.Assign(srcName);
                AddPersonalName(copyName);
            }
        }