예제 #1
0
        private static Relation ParseRelation(RelationDocument relationDocument, Layer layer, Graph graph)
        {
            Relation relation = new (relationDocument.id,
                                     relationDocument.name,
                                     new List <Entity>(),
                                     layer,
                                     new ());

            if (relationDocument.referenced_entities != null)
            {
                foreach (Guid refEntityGuid in relationDocument.referenced_entities)
                {
                    Entity?refEntity = graph.GetEntity(refEntityGuid);
                    if (refEntity != null)
                    {
                        relation.Entities.Add(refEntity);
                    }
                    else
                    {
                        Console.Error.WriteLine($"Could not find entity for guid: {refEntityGuid}");
                    }
                }
            }

            if (relationDocument.properties != null)
            {
                foreach (var propertyDocument in relationDocument.properties)
                {
                    var property = ParseProperty(propertyDocument);
                    relation.Properties.Add(property.Name, property);
                }
            }

            return(relation);
        }
예제 #2
0
        private static RelationDocument MakeRelationDocument(Relation relation)
        {
            var referencedEntities = relation.Entities.ConvertAll(entity => entity.ID);

            RelationDocument relationDocument = new RelationDocument()
            {
                id   = relation.ID,
                name = relation.Name,
                referenced_entities = referencedEntities,
                properties          = new List <PropertyDocument>(relation.Properties.Values.Select(MakeAttributeDocument)),
            };

            return(relationDocument);
        }