/// <summary> /// Initializes a new instance of the <see cref="JsonEntity" /> class. /// </summary> /// <param name="entityRef">The entity reference.</param> /// <param name="context">The context.</param> public JsonEntity(EntityRef entityRef, JsonEntityQueryResult context) : this() { JsonEntityRef eid = context.GetEntityRef(entityRef); if (!string.IsNullOrEmpty(entityRef.Alias) && eid.Alias != entityRef.Alias) { EventLog.Application.WriteWarning("EntityRef with id {0} using different aliases \"{1}\" <> \"{2}\"", eid.Id, eid.Alias, entityRef.Alias); } Id = eid.Id; }
/// <summary> /// Initializes a new instance of the <see cref="JsonEntityData" /> class. /// </summary> /// <param name="entityData">The entity data.</param> /// <param name="context">The context.</param> public JsonEntityData(EntityData entityData, JsonEntityQueryResult context) { Id = 0; if (entityData == null) { return; } Id = entityData.Id.Id; JsonEntity jsonEntity = context.GetEntity(entityData.Id); jsonEntity.DataState = entityData.DataState; IEnumerable <EntityRef> newTypeIds = entityData.TypeIds.Where(p => !jsonEntity.TypeIds.Contains(p.Id)); jsonEntity.TypeIds.AddRange(newTypeIds.Select(p => context.GetEntityRef(p).Id)); foreach (FieldData f in entityData.Fields) { JsonFieldData existingField = jsonEntity.Fields.FirstOrDefault(p => p.FieldId == f.FieldId.Id); if (existingField == null) { var jsonField = new JsonFieldData(f, context); jsonEntity.Fields.Add(jsonField); } } foreach (RelationshipData r in entityData.Relationships) { JsonRelationshipData existing = jsonEntity.Relationships.FirstOrDefault(p => p.RelTypeId.Id == r.RelationshipTypeId.Id && p.RelTypeId.Alias == r.RelationshipTypeId.Alias && p.IsReverse == r.IsReverse); if (existing == null) { // need to stick a placeholder relationship in place before recursively calling to set up the related entity data var tempRel = new JsonRelationshipData(r, null); jsonEntity.Relationships.Add(tempRel); // add this var newRel = new JsonRelationshipData(r, context); // before doing this // now swap out the temp with the actual jsonEntity.Relationships.Remove(tempRel); jsonEntity.Relationships.Add(newRel); } else if (existing.Instances.Select(p => p.Entity).Except(r.Instances.Select(p => p.Entity.Id.Id)).Any( )) { //throw new InvalidOperationException("Wasn't expecting diff relationship instances for same rel type on a given object...."); EventLog.Application.WriteWarning("Wasn't expecting diff relationship instances for same rel type on a given object...."); } } }
/// <summary> /// Initializes a new instance of the <see cref="JsonFieldData" /> class. /// </summary> /// <param name="field">The field.</param> /// <param name="context">The context.</param> public JsonFieldData(FieldData field, JsonEntityQueryResult context) { FieldId = context.GetEntityRef(field.FieldId).Id; Value = field.Value.ValueString; TypeName = field.Value.Type.GetDisplayName( ); }