private void ProcessSources()
        {
            Sources = new List <Source>();

            foreach (var gedcomRecord in _document.SourceRecords)
            {
                var sourceRecord = (GEDCOMSourceRecord)gedcomRecord;
                var source       = new Source
                {
                    Id        = sourceRecord.GetId(),
                    Author    = sourceRecord.Author,
                    Title     = sourceRecord.Title,
                    Publisher = sourceRecord.PublisherInfo,
                    TreeId    = DEFAULT_TREE_ID
                };
                if (sourceRecord.SourceRepository != null)
                {
                    source.RepositoryId = GEDCOMUtil.GetId(sourceRecord.SourceRepository.XRefId);
                }

                ProcessNotes(source, sourceRecord.Notes);

                Sources.Add(source);
            }
        }
        public void AddFamily(Family family)
        {
            Requires.NotNull("family", family);

            family.Id = _document.Records.GetNextId(GEDCOMTag.FAM).ToString();

            var record = new GEDCOMFamilyRecord(family.Id);

            if (!string.IsNullOrEmpty(family.HusbandId))
            {
                //Add HUSB
                record.AddHusband(GEDCOMUtil.CreateId("I", family.HusbandId));
            }

            if (!string.IsNullOrEmpty(family.WifeId))
            {
                //Add WIFE
                record.AddWife(GEDCOMUtil.CreateId("I", family.WifeId));
            }

            foreach (Individual child in family.Children)
            {
                //Add CHIL
                record.AddChild(GEDCOMUtil.CreateId("I", child.Id));
            }

            _document.AddRecord(record);
        }
        private static void RemoveIndividualFromFamilyRecord(Individual child, GEDCOMRecord familyRecord, GEDCOMTag tag)
        {
            var childRecord = (from GEDCOMRecord record in familyRecord.ChildRecords.GetLinesByTag(tag)
                               where record.XRefId == GEDCOMUtil.CreateId("I", child.Id)
                               select record).SingleOrDefault();

            if (childRecord != null)
            {
                familyRecord.ChildRecords.Remove(childRecord);
            }
        }
        public void UpdateFamily(Family family)
        {
            Requires.NotNull("family", family);

            GEDCOMFamilyRecord record = _document.SelectFamilyRecord(GEDCOMUtil.CreateId("F", family.Id));

            if (record == null)
            {
                //record not in repository
                throw new ArgumentOutOfRangeException();
            }
        }
        private GEDCOMFamilyRecord GetFamilyRecord(Individual individual)
        {
            string fatherId = individual.FatherId;
            string motherId = individual.MotherId;


            var familyRecord = !string.IsNullOrEmpty(fatherId)
                ? (!string.IsNullOrEmpty(motherId)
                    ? _document.SelectFamilyRecord(GEDCOMUtil.CreateId("I", fatherId), GEDCOMUtil.CreateId("I", motherId))
                    : _document.SelectHusbandsFamilyRecords(GEDCOMUtil.CreateId("I", fatherId)).FirstOrDefault())
                : _document.SelectWifesFamilyRecords(GEDCOMUtil.CreateId("I", motherId)).FirstOrDefault();

            return(familyRecord);
        }
        public void DeleteIndividual(Individual individual)
        {
            Requires.NotNull("individual", individual);

            string individualId = GEDCOMUtil.CreateId("I", individual.Id);

            //Remove from internal List
            Individuals.Remove(individual);

            GEDCOMIndividualRecord record = _document.SelectIndividualRecord(individualId);

            if (record == null)
            {
                //record not in repository
                throw new ArgumentOutOfRangeException();
            }

            _document.RemoveRecord(record);

            //see if individual is a child in a family
            var familyRecord = _document.SelectChildsFamilyRecord(individualId);

            if (familyRecord != null)
            {
                //remove child from family
                RemoveIndividualFromFamilyRecord(individual, familyRecord, GEDCOMTag.CHIL);
            }

            if (individual.Sex == Sex.Male)
            {
                //see if individual is a husband in a family
                foreach (GEDCOMFamilyRecord fRecord in _document.SelectHusbandsFamilyRecords(individualId))
                {
                    //remove husband from family
                    RemoveIndividualFromFamilyRecord(individual, fRecord, GEDCOMTag.HUSB);
                }
            }
            else
            {
                //see if individual is a wife in a family
                foreach (GEDCOMFamilyRecord fRecord in _document.SelectWifesFamilyRecords(individualId))
                {
                    //remove wife from family
                    RemoveIndividualFromFamilyRecord(individual, fRecord, GEDCOMTag.WIFE);
                }
            }
        }
        public void UpdateIndividual(Individual individual)
        {
            Requires.NotNull("individual", individual);

            GEDCOMIndividualRecord record = _document.SelectIndividualRecord(GEDCOMUtil.CreateId("I", individual.Id));

            if (record == null)
            {
                //record not in repository
                throw new ArgumentOutOfRangeException();
            }

            record.Name = new GEDCOMNameStructure(String.Format("{0} /{1}/", individual.FirstName, individual.LastName), record.Level + 1);
            record.Sex  = individual.Sex;

            //Update Family Info
            UpdateFamilyDetails(individual);
        }
        private void UpdateFamilyDetails(Individual individual)
        {
            var familyRecord = _document.SelectChildsFamilyRecord(GEDCOMUtil.CreateId("I", individual.Id));

            if (familyRecord != null)
            {
                if (individual.FatherId != GEDCOMUtil.GetId(familyRecord.Husband) || individual.MotherId != GEDCOMUtil.GetId(familyRecord.Wife))
                {
                    //remove child from current family
                    RemoveIndividualFromFamilyRecord(individual, familyRecord, GEDCOMTag.CHIL);

                    familyRecord = GetFamilyRecord(individual);

                    if (familyRecord != null)
                    {
                        //Add Individual as Child
                        familyRecord.AddChild(GEDCOMUtil.CreateId("I", individual.Id));
                    }
                    else
                    {
                        //new Family
                        CreateNewFamily(individual);
                    }
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(individual.FatherId) || !string.IsNullOrEmpty(individual.MotherId))
                {
                    familyRecord = GetFamilyRecord(individual);

                    if (familyRecord != null)
                    {
                        //Add Individual as Child
                        familyRecord.AddChild(GEDCOMUtil.CreateId("I", individual.Id));
                    }
                    else
                    {
                        //new Family
                        CreateNewFamily(individual);
                    }
                }
            }
        }
        private void ProcessCitations(Entity entity, List <GEDCOMSourceCitationStructure> citations)
        {
            foreach (var citationStructure in citations)
            {
                if (citationStructure == null)
                {
                    continue;
                }

                var newCitation = new Citation()
                {
                    Date      = citationStructure.Date,
                    Page      = citationStructure.Page,
                    Text      = citationStructure.Text,
                    SourceId  = GEDCOMUtil.GetId(citationStructure.XRefId),
                    OwnerId   = entity.Id,
                    OwnerType = (entity is Individual)
                                                        ? EntityType.Individual
                                                        :(entity is Fact)
                                                            ? EntityType.Fact
                                                            : EntityType.Family
                };

                var factEntity = entity as Fact;
                if (factEntity != null)
                {
                    factEntity.Citations.Add(newCitation);
                }
                else
                {
                    var ancestorEntity = entity as AncestorEntity;
                    if (ancestorEntity != null)
                    {
                        ancestorEntity.Citations.Add(newCitation);
                    }
                }

                ProcessMultimedia(entity, citationStructure.Multimedia);

                ProcessNotes(entity, citationStructure.Notes);
            }
        }
        private void ProcessFamilies()
        {
            Families = new List <Family>();

            foreach (var gedcomRecord in _document.FamilyRecords)
            {
                var familyRecord = (GEDCOMFamilyRecord)gedcomRecord;
                var family       = new Family
                {
                    Id        = familyRecord.GetId(),
                    HusbandId = GEDCOMUtil.GetId(familyRecord.Husband),
                    WifeId    = GEDCOMUtil.GetId(familyRecord.Wife),
                    TreeId    = DEFAULT_TREE_ID
                };

                ProcessFacts(family, familyRecord.Events);

                ProcessMultimedia(family, familyRecord.Multimedia);

                ProcessNotes(family, familyRecord.Notes);

                ProcessCitations(family, familyRecord.SourceCitations);

                foreach (string child in familyRecord.Children)
                {
                    var childId = GEDCOMUtil.GetId(child);
                    if (!string.IsNullOrEmpty(childId))
                    {
                        var individual = Individuals.SingleOrDefault(ind => ind.Id == childId);
                        if (individual != null)
                        {
                            individual.MotherId = family.WifeId;
                            individual.FatherId = family.HusbandId;
                        }
                    }
                }
                Families.Add(family);
            }
        }
Ejemplo n.º 11
0
        internal static GEDCOMRecord Create(GEDCOMRecord record)
        {
            switch (record.TagName)
            {
            case GEDCOMTag.ADDR:
                return(CreateAddressStructure(record));

            case GEDCOMTag.ASSO:
                return(CreateAssociationStructure(record));

            case GEDCOMTag.CHAN:
                return(CreateChangeDateStructure(record));

            case GEDCOMTag.CALN:
                return(CreateCallNumberStructure(record));

            case GEDCOMTag.AFN:
            case GEDCOMTag.RIN:
            case GEDCOMTag.RFN:
            case GEDCOMTag.REFN:
                return(CreateExternalIDStructure(record));

            case GEDCOMTag.FAM:
                return(CreateFamilyRecord(record));

            case GEDCOMTag.FAMC:
            case GEDCOMTag.FAMS:
                return(CreateLinkStructure(record));

            case GEDCOMTag.HEAD:
                return(CreateHeaderRecord(record));

            case GEDCOMTag.INDI:
                return(CreateIndividualRecord(record));

            case GEDCOMTag.OBJE:
                if (record.Level == 0)
                {
                    return(CreateMultimediaRecord(record));
                }

                return(CreateMultimediaStructure(record));

            case GEDCOMTag.NAME:
                return(CreateNameStructure(record));

            case GEDCOMTag.NOTE:
                if (record.Level == 0)
                {
                    return(CreateNoteRecord(record));
                }

                return(CreateNoteStructure(record));

            case GEDCOMTag.PLAC:
                return(CreatePlaceStructure(record));

            case GEDCOMTag.REPO:
                if (record.Level == 0)
                {
                    return(CreateRepositoryRecord(record));
                }

                return(CreateSourceRepositoryStructure(record));

            case GEDCOMTag.SOUR:
                if (record.Level == 0)
                {
                    return(CreateSourceRecord(record));
                }

                if (String.IsNullOrEmpty(record.XRefId))
                {
                    return(CreateHeaderSourceStructure(record));
                }

                return(CreateSourceStructure(record));

            case GEDCOMTag.SUBM:
                return(CreateSubmitterRecord(record));

            case GEDCOMTag.SUBN:
                return(CreateSubmissionRecord(record));

            default:
                //Check if the tag is an Fact type tag
                EventClass eventClass = GEDCOMUtil.GetEventClass(record.Tag);
                if (eventClass != EventClass.Unknown)
                {
                    return(CreateEventStructure(record, eventClass));
                }

                return(record);
            }
        }
Ejemplo n.º 12
0
 public string GetId()
 {
     return(GEDCOMUtil.GetId(Id));
 }
Ejemplo n.º 13
0
 /// <summary>
 ///   Parse parses the text and creates a GEDCOMRecord object
 /// </summary>
 /// <param name = "text">The text to parse</param>
 /// <returns>A flag that indicates whther the record was parsed</returns>
 private bool Parse(string text)
 {
     return(GEDCOMUtil.ParseGEDCOM(text, this));
 }
Ejemplo n.º 14
0
 public int GetId()
 {
     return(GEDCOMUtil.GetId(Id));
 }