/// <summary> /// Builds an array of persons to be placed in the ancestry tree. /// </summary> /// <param name="gx">The input model for which the array of persons will be parsed and analyzed.</param> /// <returns>An array of persons to be placed in the ancestry tree.</returns> protected List <Person> BuildArray(Gedcomx gx) { List <Person> ancestry = new List <Person>(); if (gx.Persons != null) { foreach (Person person in gx.Persons) { DisplayProperties display = person.DisplayExtension; if (display != null && display.AscendancyNumber != null) { try { int number = int.Parse(display.AscendancyNumber); while (ancestry.Count < number) { ancestry.Add(null); } ancestry[number - 1] = person; } catch (FormatException) { //fall through... } } } } return(ancestry); }
/// <summary> /// Builds an array of persons to be placed in the ancestry tree. /// </summary> /// <param name="gx">The input model for which the array of persons will be parsed and analyzed.</param> /// <returns>An array of persons to be placed in the ancestry tree.</returns> protected List<Person> BuildArray(Gedcomx gx) { List<Person> ancestry = new List<Person>(); if (gx.Persons != null) { foreach (Person person in gx.Persons) { DisplayProperties display = person.DisplayExtension; if (display != null && display.AscendancyNumber != null) { try { int number = int.Parse(display.AscendancyNumber); while (ancestry.Count < number) { ancestry.Add(null); } ancestry[number - 1] = person; } catch (FormatException) { //fall through... } } } } return ancestry; }
public override void VisitGedcomx(Gedcomx gx) { if (IsCensusRecord(gx)) { _parsingCensus = true; } _currentRecord = new SubRecord(); _subrecords = new List <SubRecord>(); base.VisitGedcomx(gx); if (_subrecords.Count > 0) { int max = _subrecords.Max(x => x.GetLevel()); // Only export "full" rows, since the subrecord chaining has some incomplete records (e.g., the parent records) foreach (SubRecord subrecord in _subrecords.Where(x => x.GetLevel() == max)) { _rows.Add(subrecord.ToRow()); } } else { //no subrecords; just add the record fields. _rows.Add(_currentRecord.ToRow()); } _parsingCensus = false; _currentRecord = null; _subrecords = null; }
/// <summary> /// Executes the specified links and embeds the response into the specified entity. /// </summary> /// <typeparam name="T">The type of the expected response. The raw response data will be parsed (from JSON or XML) and casted to this type.</typeparam> /// <param name="links">The links to call.</param> /// <param name="entity">The entity which shall have the data loaded into.</param> /// <param name="options">The options to apply before handling the REST API requests.</param> protected void Embed <T>(IEnumerable <Link> links, Gedcomx entity, params IStateTransitionOption[] options) where T : Gedcomx { foreach (Link link in links) { Embed <T>(link, entity, options); } }
/// <summary> /// Utility method used to determine whether the given record covers census data. /// </summary> /// <returns> /// <c>true</c> if the record covers any census data. /// </returns> /// <param name='record'> /// The record. /// </param> public static bool IsCensusRecord(Gedcomx record) { String uri = record.DescriptionRef; if (uri != null) { int hashIndex = uri.IndexOf('#'); if (hashIndex >= 0) { string id = uri.Substring(hashIndex); if (record.SourceDescriptions != null) { foreach (SourceDescription source in record.SourceDescriptions) { if (id.Equals(source.Id)) { if (source.Coverage != null) { foreach (Coverage coverage in source.Coverage) { if (coverage.KnownRecordType == RecordType.Census) { return(true); } } } } } } } } return(false); }
public CensusFieldGatheringVisitor(Gedcomx record) { VisitGedcomx(record); foreach (List <Field> fields in _fieldsByPerson.Values) { fields.AddRange(_commonFields); } }
/** * Build out this record set with a record. * @param record The record. * @return this. */ public RecordSet SetRecord(Gedcomx record) { if (this._records == null) { this._records = new List <Gedcomx>(); } this._records.Add(record); return(this); }
public static ExtensibleData Resolve(Uri @ref, Gedcomx document) { if ([email protected]().StartsWith("#")) { return(null); } return(Resolve(@ref.ToString().Substring(1), document)); }
public static ExtensibleData Resolve(ResourceReference @ref, Gedcomx document) { if (@ref.Resource == null) { return(null); } return(Resolve(@ref.Resource, document)); }
public static ExtensibleData Resolve(Uri @ref, Gedcomx document) { if ([email protected]().StartsWith("#")) { return null; } return Resolve(@ref.ToString().Substring(1), document); }
public static ExtensibleData Resolve(ResourceReference @ref, Gedcomx document) { if (@ref.Resource == null) { return null; } return Resolve(@ref.Resource, document); }
public static ExtensibleData Resolve(String resourceId, Gedcomx document) { if (resourceId == null) { return null; } FamilySearchPlatformLocalReferenceResolver visitor = new FamilySearchPlatformLocalReferenceResolver(resourceId); document.Accept(visitor); return visitor.Resource; }
public static ExtensibleData Resolve(String resourceId, Gedcomx document) { if (resourceId == null) { return(null); } FamilySearchPlatformLocalReferenceResolver visitor = new FamilySearchPlatformLocalReferenceResolver(resourceId); document.Accept(visitor); return(visitor.Resource); }
/// <summary> /// Reads the Gedcomx record. /// </summary> /// <param name="record">The Gedcomx record to read.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="RecordState"/> instance containing the REST API response. /// </returns> public RecordState ReadRecord(Gedcomx record, params IStateTransitionOption[] options) { Link link = record.GetLink(Rel.RECORD); if (link == null || link.Href == null) { return(null); } IRestRequest request = CreateAuthenticatedGedcomxRequest().Build(link.Href, Method.GET); return(this.stateFactory.NewRecordState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
public override void VisitGedcomx(Gedcomx gx) { base.VisitGedcomx(gx); this.contextStack.Push(gx); List <Discussion> discussions = gx.FindExtensionsOfType <Discussion>(); if (discussions != null) { foreach (Discussion discussion in discussions) { discussion.Accept(this); } } List <Merge> merges = gx.FindExtensionsOfType <Merge>(); if (merges != null) { foreach (Merge merge in merges) { merge.Accept(this); } } List <MergeAnalysis> mergeAnalyses = gx.FindExtensionsOfType <MergeAnalysis>(); if (mergeAnalyses != null) { foreach (MergeAnalysis merge in mergeAnalyses) { merge.Accept(this); } } List <ChildAndParentsRelationship> childAndParentsRelationships = gx.FindExtensionsOfType <ChildAndParentsRelationship>(); if (childAndParentsRelationships != null) { foreach (ChildAndParentsRelationship pcr in childAndParentsRelationships) { pcr.Accept(this); } } this.contextStack.Pop(); }
public override void VisitGedcomx(Gedcomx gx) { base.VisitGedcomx(gx); this.contextStack.Push(gx); List<Discussion> discussions = gx.FindExtensionsOfType<Discussion>(); if (discussions != null) { foreach (Discussion discussion in discussions) { discussion.Accept(this); } } List<Merge> merges = gx.FindExtensionsOfType<Merge>(); if (merges != null) { foreach (Merge merge in merges) { merge.Accept(this); } } List<MergeAnalysis> mergeAnalyses = gx.FindExtensionsOfType<MergeAnalysis>(); if (mergeAnalyses != null) { foreach (MergeAnalysis merge in mergeAnalyses) { merge.Accept(this); } } List<ChildAndParentsRelationship> childAndParentsRelationships = gx.FindExtensionsOfType<ChildAndParentsRelationship>(); if (childAndParentsRelationships != null) { foreach (ChildAndParentsRelationship pcr in childAndParentsRelationships) { pcr.Accept(this); } } this.contextStack.Pop(); }
/// <summary> /// Executes the specified link and embeds the response in the specified Gedcomx entity. /// </summary> /// <typeparam name="T">The type of the expected response. The raw response data will be parsed (from JSON or XML) and casted to this type.</typeparam> /// <param name="link">The link to execute.</param> /// <param name="entity">The entity which will embed the reponse data.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <exception cref="GedcomxApplicationException">Thrown when the server responds with HTTP status code >= 500 and < 600.</exception> protected void Embed <T>(Link link, Gedcomx entity, params IStateTransitionOption[] options) where T : Gedcomx { if (link.Href != null) { LastEmbeddedRequest = CreateRequestForEmbeddedResource(link.Rel).Build(link.Href, Method.GET); LastEmbeddedResponse = Invoke(LastEmbeddedRequest, options); if (LastEmbeddedResponse.StatusCode == HttpStatusCode.OK) { entity.Embed(LastEmbeddedResponse.ToIRestResponse <T>().Data); } else if (LastEmbeddedResponse.HasServerError()) { throw new GedcomxApplicationException(String.Format("Unable to load embedded resources: server says \"{0}\" at {1}.", LastEmbeddedResponse.StatusDescription, LastEmbeddedRequest.Resource), LastEmbeddedResponse); } else { //todo: log a warning? throw an error? } } }
/// <summary> /// Loads the list of links as specified in <see cref="EmbeddedLinkRels" /> from the specified <see cref="Gedcomx" />. /// </summary> /// <param name="entity">The <see cref="Gedcomx" /> entity from which links will be extracted. See remarks.</param> /// <returns></returns> /// <remarks> /// Not all objects with <see cref="C:Gedcomx.Model.SupportsLinks" /> will be evaluated. Only <see cref="P:Gedcomx.Perons" /> and /// <see cref="P:Gedcomx.Relationships" /> will be considered. /// </remarks> public IList <Link> LoadEmbeddedLinks(Gedcomx entity) { List <Link> embeddedLinks = new List <Link>(); ISet <String> embeddedRels = EmbeddedLinkRels; List <Person> persons = entity.Persons; if (persons != null) { foreach (Person person in persons) { foreach (String embeddedRel in embeddedRels) { Link link = person.Links.FirstOrDefault(x => x.Rel == embeddedRel); if (link != null) { embeddedLinks.Add(link); } } } } List <Relationship> relationships = entity.Relationships; if (relationships != null) { foreach (Relationship relationship in relationships) { foreach (String embeddedRel in embeddedRels) { Link link = relationship.Links.FirstOrDefault(x => x.Rel == embeddedRel); if (link != null) { embeddedLinks.Add(link); } } } } return(embeddedLinks); }
/// <summary> /// Loads the list of links as specified in <see cref="EmbeddedLinkRels" /> from the specified <see cref="Gedcomx" />. /// </summary> /// <param name="entity">The <see cref="Gedcomx" /> entity from which links will be extracted. See remarks.</param> /// <returns></returns> /// <remarks> /// Not all objects with <see cref="C:Gedcomx.Model.SupportsLinks" /> will be evaluated. Only <see cref="P:Gedcomx.Perons" /> and /// <see cref="P:Gedcomx.Relationships" /> will be considered. /// </remarks> public IList<Link> LoadEmbeddedLinks(Gedcomx entity) { List<Link> embeddedLinks = new List<Link>(); ISet<String> embeddedRels = EmbeddedLinkRels; List<Person> persons = entity.Persons; if (persons != null) { foreach (Person person in persons) { foreach (String embeddedRel in embeddedRels) { Link link = person.Links.FirstOrDefault(x => x.Rel == embeddedRel); if (link != null) { embeddedLinks.Add(link); } } } } List<Relationship> relationships = entity.Relationships; if (relationships != null) { foreach (Relationship relationship in relationships) { foreach (String embeddedRel in embeddedRels) { Link link = relationship.Links.FirstOrDefault(x => x.Rel == embeddedRel); if (link != null) { embeddedLinks.Add(link); } } } } return embeddedLinks; }
/// <summary> /// Enumerates the fields of a census record, aggregating them by the persons in the record. /// </summary> /// <returns> /// The census record fields. /// </returns> /// <param name='record'> /// The census record. /// </param> public static ICollection <List <Field> > EnumerateCensusRecordFields(Gedcomx record) { return(new CensusFieldGatheringVisitor(record).FieldsByPerson.Values); }
public override void VisitGedcomx(Gedcomx gx) { BindIfNeeded(gx); base.VisitGedcomx(gx); }
/// <summary> /// Initializes an id dictionary for the specified data set. /// </summary> /// <param name='gx'> /// The data set. /// </param> public GedcomxIdDictionary(Gedcomx gx) { VisitGedcomx(gx); }
/// <summary> /// Enumerates the fields of a record. Note that this method assumes the record is not a census record /// (which is usually stitched together from a set of person subrecords) and therefore will return all /// fields in the record. Consider using <see cref="RecordHelper.EnumerateCensusRecordFields"/> for /// census records. /// </summary> /// <returns> /// The fields. /// </returns> /// <param name='record'> /// The record. /// </param> public static List <Field> EnumerateFields(Gedcomx record) { return(new FieldGatheringVisitor(record).Fields); }
/// <summary> /// Enumerates the fields of a record. Note that this method assumes the record is not a census record /// (which is usually stitched together from a set of person subrecords) and therefore will return all /// fields in the record. Consider using <see cref="RecordHelper.EnumerateCensusRecordFields"/> for /// census records. /// </summary> /// <returns> /// The fields. /// </returns> /// <param name='record'> /// The record. /// </param> public static List<Field> EnumerateFields(Gedcomx record) { return new FieldGatheringVisitor(record).Fields; }
/// <summary> /// Utility method used to determine whether the given record covers census data. /// </summary> /// <returns> /// <c>true</c> if the record covers any census data. /// </returns> /// <param name='record'> /// The record. /// </param> public static bool IsCensusRecord(Gedcomx record) { String uri = record.DescriptionRef; if (uri != null) { int hashIndex = uri.IndexOf('#'); if (hashIndex >= 0) { string id = uri.Substring(hashIndex); if (record.SourceDescriptions != null) { foreach (SourceDescription source in record.SourceDescriptions) { if (id.Equals(source.Id)) { if (source.Coverage != null) { foreach (Coverage coverage in source.Coverage) { if (coverage.KnownRecordType == RecordType.Census) { return true; } } } } } } } } return false; }
/// <summary> /// Initializes a new instance of the <see cref="DescendancyTree"/> class. /// </summary> /// <param name="gx">The input model for which a descendancy model will be built.</param> public DescendancyTree(Gedcomx gx) { this.root = BuildTree(gx); }
public FieldGatheringVisitor(Gedcomx record) { VisitGedcomx(record); }
/// <summary> /// Builds an array of persons to be placed in the descendancy tree. /// </summary> /// <param name="gx">The input model for which the array of persons will be parsed and analyzed.</param> /// <returns>An array of persons to be placed in the descendancy tree.</returns> protected DescendancyNode BuildTree(Gedcomx gx) { DescendancyNode root = null; if (gx.Persons != null && gx.Persons.Count > 0) { List<DescendancyNode> rootArray = new List<DescendancyNode>(); foreach (Person person in gx.Persons) { if (person.DisplayExtension != null && person.DisplayExtension.DescendancyNumber != null) { String number = person.DisplayExtension.DescendancyNumber; bool spouse = number.EndsWith("-S") || number.EndsWith("-s"); if (spouse) { number = number.Substring(0, number.Length - 2); } int[] coordinates = ParseCoordinates(number); List<DescendancyNode> current = rootArray; int i = 0; DescendancyNode node = null; while (current != null) { int coordinate = coordinates[i]; while (current.Count < coordinate) { current.Add(null); } node = current[coordinate - 1]; if (node == null) { node = new DescendancyNode(); current[coordinate - 1] = node; } if (++i < coordinates.Length) { //if we still have another generation to descend, make sure the list is initialized. List<DescendancyNode> children = node.Children; if (children == null) { children = new List<DescendancyNode>(); node.Children = children; } current = children; } else { current = null; } } if (spouse) { node.Spouse = person; } else { node.Person = person; } } } if (rootArray.Count > 0) { root = rootArray[0]; } } return root; }
/// <summary> /// Initializes a new instance of the <see cref="AncestryTree"/> class. /// </summary> /// <param name="gx">The input model for which an ancestry model will be built.</param> public AncestryTree(Gedcomx gx) { this.ancestry = BuildArray(gx); }
/** * Build out this record set with metadata. * * @param metadata The metadata. * @return this. */ public RecordSet SetMetadata(Gedcomx metadata) { Metadata = metadata; return this; }
/// <summary> /// Visits the <see cref="Gx.Gedcomx"/> entity. /// </summary> /// <param name="gx">The <see cref="Gx.Gedcomx"/> to visit.</param> public virtual void VisitGedcomx(Gedcomx gx) { this.contextStack.Push(gx); if (gx.Persons != null) { foreach (Person person in gx.Persons) { if (person != null) { VisitPerson(person); } } } if (gx.Relationships != null) { foreach (Relationship relationship in gx.Relationships) { if (relationship != null) { VisitRelationship(relationship); } } } if (gx.SourceDescriptions != null) { foreach (SourceDescription sourceDescription in gx.SourceDescriptions) { if (sourceDescription != null) { VisitSourceDescription(sourceDescription); } } } if (gx.Agents != null) { foreach (Gx.Agent.Agent agent in gx.Agents) { if (agent != null) { VisitAgent(agent); } } } if (gx.Events != null) { foreach (Event e in gx.Events) { if (e != null) { VisitEvent(e); } } } if (gx.Places != null) { foreach (PlaceDescription place in gx.Places) { if (place != null) { VisitPlaceDescription(place); } } } if (gx.Documents != null) { foreach (Document document in gx.Documents) { if (document != null) { VisitDocument(document); } } } if (gx.Fields != null) { foreach (Field field in gx.Fields) { if (field != null) { VisitField(field); } } } if (gx.RecordDescriptors != null) { foreach (RecordDescriptor rd in gx.RecordDescriptors) { if (rd != null) { VisitRecordDescriptor(rd); } } } if (gx.Collections != null) { foreach (Collection collection in gx.Collections) { if (collection != null) { VisitCollection(collection); } } } this.contextStack.Pop(); }
/// <summary> /// Builds an array of persons to be placed in the descendancy tree. /// </summary> /// <param name="gx">The input model for which the array of persons will be parsed and analyzed.</param> /// <returns>An array of persons to be placed in the descendancy tree.</returns> protected DescendancyNode BuildTree(Gedcomx gx) { DescendancyNode root = null; if (gx.Persons != null && gx.Persons.Count > 0) { List <DescendancyNode> rootArray = new List <DescendancyNode>(); foreach (Person person in gx.Persons) { if (person.DisplayExtension != null && person.DisplayExtension.DescendancyNumber != null) { String number = person.DisplayExtension.DescendancyNumber; bool spouse = number.EndsWith("-S") || number.EndsWith("-s"); if (spouse) { number = number.Substring(0, number.Length - 2); } int[] coordinates = ParseCoordinates(number); List <DescendancyNode> current = rootArray; int i = 0; DescendancyNode node = null; while (current != null) { int coordinate = coordinates[i]; while (current.Count < coordinate) { current.Add(null); } node = current[coordinate - 1]; if (node == null) { node = new DescendancyNode(); current[coordinate - 1] = node; } if (++i < coordinates.Length) { //if we still have another generation to descend, make sure the list is initialized. List <DescendancyNode> children = node.Children; if (children == null) { children = new List <DescendancyNode>(); node.Children = children; } current = children; } else { current = null; } } if (spouse) { node.Spouse = person; } else { node.Person = person; } } } if (rootArray.Count > 0) { root = rootArray[0]; } } return(root); }
public override void VisitGedcomx(Gedcomx gx) { if (IsCensusRecord(gx)) { _parsingCensus = true; } _currentRecord = new SubRecord(); _subrecords = new List<SubRecord>(); base.VisitGedcomx(gx); if (_subrecords.Count > 0) { int max = _subrecords.Max(x => x.GetLevel()); // Only export "full" rows, since the subrecord chaining has some incomplete records (e.g., the parent records) foreach (SubRecord subrecord in _subrecords.Where(x => x.GetLevel() == max)) { _rows.Add(subrecord.ToRow()); } } else { //no subrecords; just add the record fields. _rows.Add(_currentRecord.ToRow()); } _parsingCensus = false; _currentRecord = null; _subrecords = null; }
public override void Embed(Gedcomx gedcomx) { FamilySearchPlatform value = gedcomx as FamilySearchPlatform; base.Embed(gedcomx); if (value != null) { List <ChildAndParentsRelationship> relationships = value.ChildAndParentsRelationships; if (relationships != null) { foreach (ChildAndParentsRelationship relationship in relationships) { bool found = false; if (relationship.Id != null) { if (ChildAndParentsRelationships != null) { foreach (ChildAndParentsRelationship target in ChildAndParentsRelationships) { if (relationship.Id.Equals(target.Id)) { target.EmbedInt(relationship); found = true; break; } } } } if (!found) { AddChildAndParentsRelationship(relationship); } } } List <Discussion> discussions = value.Discussions; if (discussions != null) { foreach (Discussion discussion in discussions) { bool found = false; if (discussion.Id != null) { if (Discussions != null) { foreach (Discussion target in Discussions) { if (discussion.Id.Equals(target.Id)) { target.EmbedInt(discussion); found = true; break; } } } } if (!found) { AddDiscussion(discussion); } } } } }
public CensusFieldGatheringVisitor(Gedcomx record) { VisitGedcomx(record); foreach (List<Field> fields in _fieldsByPerson.Values) { fields.AddRange(_commonFields); } }
/// <summary> /// Enumerates the fields of a census record, aggregating them by the persons in the record. /// </summary> /// <returns> /// The census record fields. /// </returns> /// <param name='record'> /// The census record. /// </param> public static ICollection<List<Field>> EnumerateCensusRecordFields(Gedcomx record) { return new CensusFieldGatheringVisitor(record).FieldsByPerson.Values; }
/** * Build out this record set with a record. * @param record The record. * @return this. */ public RecordSet SetRecord(Gedcomx record) { if (this._records == null) { this._records = new List<Gedcomx>(); } this._records.Add(record); return this; }
public override void Embed(Gedcomx gedcomx) { FamilySearchPlatform value = gedcomx as FamilySearchPlatform; base.Embed(gedcomx); if (value != null) { List<ChildAndParentsRelationship> relationships = value.ChildAndParentsRelationships; if (relationships != null) { foreach (ChildAndParentsRelationship relationship in relationships) { bool found = false; if (relationship.Id != null) { if (ChildAndParentsRelationships != null) { foreach (ChildAndParentsRelationship target in ChildAndParentsRelationships) { if (relationship.Id.Equals(target.Id)) { target.EmbedInt(relationship); found = true; break; } } } } if (!found) { AddChildAndParentsRelationship(relationship); } } } List<Discussion> discussions = value.Discussions; if (discussions != null) { foreach (Discussion discussion in discussions) { bool found = false; if (discussion.Id != null) { if (Discussions != null) { foreach (Discussion target in Discussions) { if (discussion.Id.Equals(target.Id)) { target.EmbedInt(discussion); found = true; break; } } } } if (!found) { AddDiscussion(discussion); } } } } }
/** * Build out this record set with metadata. * * @param metadata The metadata. * @return this. */ public RecordSet SetMetadata(Gedcomx metadata) { Metadata = metadata; return(this); }
/// <summary> /// Extracts embedded links from the specified entity, calls each one, and embeds the response into the specified entity. /// </summary> /// <typeparam name="T">The type of the expected response. The raw response data will be parsed (from JSON or XML) and casted to this type.</typeparam> /// <param name="entity">The entity with links and which shall have the data loaded into.</param> /// <param name="options">The options to apply before handling the REST API requests.</param> protected void IncludeEmbeddedResources <T>(Gedcomx entity, params IStateTransitionOption[] options) where T : Gedcomx { Embed <T>(EmbeddedLinkLoader.LoadEmbeddedLinks(entity), entity, options); }