public static async Task <SingleKeyRelationship> ToData(CdmE2ERelationship instance, ResolveOptions resOpt, CopyOptions options) { var fromAttribute = new AttributeReference { EntityName = GetEntityName(instance.FromEntity), AttributeName = instance.FromEntityAttribute }; var toAttribute = new AttributeReference { EntityName = GetEntityName(instance.ToEntity), AttributeName = instance.ToEntityAttribute }; var result = new SingleKeyRelationship { Type = "SingleKeyRelationship", Description = instance.Explanation, Name = instance.Name, FromAttribute = fromAttribute, ToAttribute = toAttribute }; Utils.ProcessTraitsAndAnnotationsToData(instance.Ctx, result, instance.ExhibitsTraits); return(result); }
/// <summary> /// Creates an instance of <see cref="Model"/> with huge content. /// This is used to test the serializer performance. /// </summary> /// <param name="dimension">The dimension of the desired class. This actually controls the number of elements in the lists of the <see cref="Model"/></param> /// <returns>An instance of <see cref="Model"/> that contains many <see cref="SingleKeyRelationship"/> and <see cref="ReferenceModel"/>.</returns> private Model CreateHugeModel(int dimension) { var ret = new Model(); ret.Description = "The description of the Entity"; ret.LastChildFileModifiedTime = DateTimeOffset.Now; ret.LastFileStatusCheckTime = DateTimeOffset.Now; ret.Name = "The name of the entity"; ret.ReferenceModels = new List <ReferenceModel>(); for (int i = 0; i < dimension; i++) { var referenceModel = new ReferenceModel() { Id = "ReferenceModel Id no " + i, Location = "Location no" + i }; ret.ReferenceModels.Add(referenceModel); } ret.Relationships = new List <SingleKeyRelationship>(); for (int i = 0; i < dimension; i++) { var extensionFields = new JObject(); for (int j = 1; j < 3; j++) { extensionFields.TryAdd("extension " + j, "value of extension " + j + " for relationship " + i); } var relationship = new SingleKeyRelationship() { FromAttribute = new AttributeReference() { EntityName = "FromAttribute.EntityName no " + i, AttributeName = "FromAttribute.AttributeName no" + i }, ToAttribute = new AttributeReference() { EntityName = "ToAttribute.EntityName no" + i, AttributeName = "ToAttribute.AttributeName" + i }, Type = "Type of Realtionship no " + i, Name = "Name of Realtionship no " + i, Description = "Description of Relatioship no " + i, ExtensionFields = extensionFields }; ret.Relationships.Add(relationship); } return(ret); }
public static async Task <CdmE2ERelationship> FromData(CdmCorpusContext ctx, SingleKeyRelationship obj, Dictionary <string, string> entitySchemaByName) { // TODO: re-add this once Dan's serializer is merged. // The type attribute is not being set by the default serializer because of the Order property. // Since we just have one type for now this should be okay. /*if (obj.Type != "SingleKeyRelationship") * { * // We don't have any other type of a relationship yet! * return null; * }*/ if (!entitySchemaByName.ContainsKey(obj.FromAttribute.EntityName)) { Logger.Warning(ctx, Tag, nameof(FromData), null, CdmLogCode.WarnPersistRelUndefinedSourceEntity, obj.FromAttribute.EntityName); return(null); } if (!entitySchemaByName.ContainsKey(obj.ToAttribute.EntityName)) { Logger.Warning(ctx, Tag, nameof(FromData), null, CdmLogCode.WarnPersistRelUndefinedTargetEntity); return(null); } var relationship = ctx.Corpus.MakeObject <CdmE2ERelationship>(CdmObjectType.E2ERelationshipDef, obj.Name); await Utils.ProcessAnnotationsFromData(ctx, obj, relationship.ExhibitsTraits); relationship.Explanation = obj.Description; relationship.FromEntity = entitySchemaByName[obj.FromAttribute.EntityName]; relationship.ToEntity = entitySchemaByName[obj.ToAttribute.EntityName]; relationship.FromEntityAttribute = obj.FromAttribute.AttributeName; relationship.ToEntityAttribute = obj.ToAttribute.AttributeName; return(relationship); }