public static bool IsCollectionPropertyType(Type type, ReferenceAttribute referenceAttribute) { PropertyInfo propertyInfo = type.GetProperty(referenceAttribute.RefencedPropertyName); // return propertyInfo.PropertyType.IsAssignableFrom(typeof(IEnumerable)); return(typeof(IEnumerable).IsAssignableFrom(propertyInfo.PropertyType)); }
//public static string GetReferencedId(ReferenceAttribute referenceAttribute) //{ // return referenceAttribute.RefencedPropertyName + "Id"; //} public static PropertyInfo GetReferencedPropertyId(BaseEntity baseEntity, ReferenceAttribute referenceAttribute) { PropertyInfo propertyInfo = baseEntity.GetType().GetProperty(referenceAttribute.RefencedPropertyName); ForeignKeyAttribute foreignKeyAttribute = propertyInfo.GetCustomAttribute <ForeignKeyAttribute>(); return(baseEntity.GetType().GetProperty(foreignKeyAttribute.Name)); //return referenceAttribute.RefencedPropertyName + "Id"; }
public ReferenceExpression(ReferenceAttribute referrerProperty, Expression expression) { if (expression == null) throw new ArgumentNullException("expression"); _referrerProperty = new PropertyLiteral((NodeAttribute)referrerProperty); _expression = expression; //_existenceOnly = false; }
private IReferenceConverter GetReferenceConverter(ReferenceAttribute referenceAttribute, Type sourceEntityType, Type referencedEntityType) { //if (ReferenceConversionUtils.IsCollectionPropertyType(sourceEntityType, referenceAttribute)) //{ // return CreateReferenceConverter(typeof(MultiReferenceAttributeEntityToDtoConverter<,>), sourceEntityType, referencedEntityType); //} return(CreateReferenceConverter(typeof(MultiListReferenceAttributeEntityToDtoConverter <,>), sourceEntityType, referencedEntityType)); }
private IReferenceConverter GetReferenceConverter(ReferenceAttribute referenceAttribute, Type sourceEntityType, Type referencedEntityType) { if (ReferenceConversionUtils.IsCollectionPropertyType(sourceEntityType, referenceAttribute)) { return(CreateReferenceConverter(typeof(MultiReferenceAttributeDtoToEntityConverter <,>), sourceEntityType, referencedEntityType)); } return(CreateReferenceConverter(typeof(SingleReferenceAttributeDtoToEntityConverter <,>), sourceEntityType, referencedEntityType)); }
public override void Convert(Connection connection, T entity, U dto, PropertyInfo sourcePropertyInfo) { ReferenceAttribute referenceAttribute = sourcePropertyInfo.GetCustomAttribute <ReferenceAttribute>(); ReferenceString referenceString = sourcePropertyInfo.GetValue(dto) as ReferenceString; Type referencedEntityType = GetReferencedEntityType(entity, referenceAttribute); IReferenceConverter referenceConverter = GetReferenceConverter(referenceAttribute, typeof(T), referencedEntityType); referenceConverter.Convert(connection, entity, dto, sourcePropertyInfo, referenceAttribute, referenceString); }
public ReferenceExpression(ReferenceAttribute referrerProperty, Expression expression) { if (expression == null) { throw new ArgumentNullException("expression"); } _referrerProperty = new PropertyLiteral((NodeAttribute)referrerProperty); _expression = expression; }
public override void Convert(IUnitOfWork unitOfWork, T dto, U entity, PropertyInfo sourcePropertyInfo) { ReferenceAttribute referenceAttribute = sourcePropertyInfo.GetCustomAttribute <ReferenceAttribute>(); ReferenceString referenceString = sourcePropertyInfo.GetValue(dto) as ReferenceString; Type referencedEntityType = GetReferencedEntityType(entity, referenceAttribute); IReferenceConverter referenceConverter = GetReferenceConverter(referenceAttribute, typeof(U), referencedEntityType); referenceConverter.Convert(unitOfWork, entity, dto, sourcePropertyInfo, referenceAttribute, referenceString); }
private Reference(IEntityInfo entityInfo, PropertyInfo prop, ReferenceAttribute referenceAttribute) : base(entityInfo, prop, null) { _type = typeof(IList).IsAssignableFrom(prop.PropertyType) ? ReferenceType.OneToMany : ReferenceType.ManyToOne; ReferenceEntityType = referenceAttribute.ReferenceEntityType; LocalReferenceField = referenceAttribute.LocalReferenceField; ForeignReferenceField = referenceAttribute.ForeignReferenceField; }
/// <summary> /// Gets the type of the referenced entity. If it is multiple reference the type is got from the generic type of the collection. /// </summary> /// <param name="entity">The source entity</param> /// <param name="referencedAttribute">The referenced attribute of the DTO property</param> /// <returns>The type of the referenced entity</returns> protected Type GetReferencedEntityType(BaseEntity entity, ReferenceAttribute referenceAttribute) { PropertyInfo referencePropertyInfo = entity.GetType().GetProperty(referenceAttribute.RefencedPropertyName); if (ReferenceConversionUtils.IsCollectionPropertyType(entity.GetType(), referenceAttribute)) { return(GetReferencedTargetPropertyGenericType(referencePropertyInfo)); } return(referencePropertyInfo.PropertyType); }
private void TreatReference(PropertyInfo prop, ReferenceAttribute referenceAttribute) { if (referenceAttribute == null) { return; } var reference = Reference.Create(this, prop, referenceAttribute); References.Add(reference); }
public ElementReferenceProperty(IServiceProvider serviceProvider, ElementLookup lookup, ElementViewModel parent, PropertyDescriptor declaringProperty, IEnumerable <Attribute> additionalAttributes) : base(serviceProvider, parent, declaringProperty, additionalAttributes.Union(new Attribute[] { new ValidationAttribute(typeof(ElementReferenceValidator)) })) { if (declaringProperty.PropertyType != typeof(string)) { throw new ArgumentException(Resources.ReferencePropertyInvalidType); } this.lookup = lookup; this.changeScopePropertyWatcher = new ChangeScopePropertyWatcher(); this.changeScopePropertyWatcher.ChangeScopePropertyChanged += new EventHandler(ChangeScopePropertyWatcherChangeScopePropertyChanged); referenceAttribute = base.Attributes.OfType <ReferenceAttribute>().FirstOrDefault(); Debug.Assert(referenceAttribute != null); ((INotifyCollectionChanged)ValidationResults).CollectionChanged += ValidationCollectionChanged; }
public static NodeAttribute GetNodeAttribute(ReferenceAttribute attr) { switch (attr) { case ReferenceAttribute.Parent: return(NodeAttribute.Parent); case ReferenceAttribute.LockedBy: return(NodeAttribute.LockedBy); case ReferenceAttribute.CreatedBy: return(NodeAttribute.CreatedBy); case ReferenceAttribute.ModifiedBy: return(NodeAttribute.ModifiedBy); default: throw new NotImplementedException("Unknown ReferenceAttribute"); } }
public DeferredElementScope(ReferenceAttribute referenceAttribute, ElementViewModel baseDeclaringElement, ElementLookup lookup) { this.referenceAttribute = referenceAttribute; this.lookup = lookup; if (referenceAttribute.ScopeIsDeclaringElement) { CreateElementScope(baseDeclaringElement); } else { if (!TryCreateScopeElement()) { scopeChangeScope = lookup.CreateChangeScope(x => x.ConfigurationType.IsAssignableFrom(referenceAttribute.ScopeType)); scopeChangeScope.CollectionChanged += ScopeChangedHandler; } } }
void UpdateText() { Text = kNoneText; if (Value.IsNotNone()) { var lookup = IoC.Get <ProtoData.IProtoDataObjectLookup>(ReferenceAttribute.GetExportContractName()); if (lookup == null) { Text = "INTERNAL ERROR"; Debug.Trace.PhxStudio.TraceDataSansId(System.Diagnostics.TraceEventType.Error, "Failed to resolve ObjectLookup", ReferenceAttribute.GetExportContractName(), base.Name); return; } var provider = lookup.SourceObjectDatabase.Provider; var list = provider.GetNamesInterface(lookup.SourceObjectDatabaseKindId); Text = list.TryGetMemberName(this.Value); } }
public SearchOrder(ReferenceAttribute propertyToOrder, OrderDirection direction) : this((NodeAttribute)propertyToOrder, direction) { }
public ReferenceExpression(ReferenceAttribute referrerProperty, Node referencedNode) { _referrerProperty = new PropertyLiteral((NodeAttribute)referrerProperty); _referencedNode = referencedNode; //_existenceOnly = false; }
public void Convert(IUnitOfWork unitOfWork, BaseEntity sourceEntity, BaseDto targetDto, PropertyInfo sourcePropertyInfo, ReferenceAttribute referenceAttribute, ReferenceString referenceString) { PropertyInfo referencedEntityPropertyInfo = sourceEntity.GetType().GetProperty(referenceAttribute.RefencedPropertyName); PropertyInfo referencedEntityIdPropertyInfo = ReferenceConversionUtils.GetReferencedPropertyId(sourceEntity, referenceAttribute); //sourceEntity.GetType().GetProperty(ReferenceConversionUtils.GetReferencedId(referenceAttribute)); U referencedEntity = (U)referencedEntityPropertyInfo.GetValue(sourceEntity, null); if (referencedEntity != null) { sourcePropertyInfo.SetValue(targetDto, new ReferenceString(referencedEntity.Id, referencedEntity.ToString())); } }
public void AddReference(Type referenceType, string referenceField, bool isArray, ReferenceType refType) { if (this.Registered & !this.AllowRuntimeChanges) throw new InvalidOperationException("The Entity is already registered, it cannot be modified"); var attr = new ReferenceAttribute(referenceType, referenceField); attr.ReferenceType = ReferenceType.OneToMany; if (refType == ReferenceType.ManyToMany) attr.ReferenceType = refType; attr.IsArray = isArray; attr.IsList = !isArray; this.References.Add(attr); if (this.Registered && EntityDefinitionChanged != null) EntityDefinitionChanged.Invoke(this, new EntityTypeChangedArgs(this, attr)); }
public void Convert(IUnitOfWork unitOfWork, BaseEntity sourceEntity, BaseDto dto, PropertyInfo sourcePropertyInfo, ReferenceAttribute referenceAttribute, ReferenceString referenceString) { PropertyInfo targetProperty = sourceEntity.GetType().GetProperty(referenceAttribute.RefencedPropertyName); // TODO ??? //if(referenceString == null || referenceString.Value == null) //{ // return; //} List <Guid> referencedIds = new List <Guid>(); if (referenceString != null && referenceString.Value != null) { referencedIds = referenceString.GetIds(); } ICollection <U> referencedEntities = (ICollection <U>)targetProperty.GetValue(sourceEntity); if (IsReferenciesCreated(referencedIds, referencedEntities)) { CreateMultiReferences(unitOfWork, sourceEntity, targetProperty, referencedIds, referencedEntities); } else { UpdateMultiReference(unitOfWork, sourceEntity, targetProperty, referencedIds, referencedEntities); } }
public ReferenceExpression(ReferenceAttribute referrerProperty) { _referrerProperty = new PropertyLiteral((NodeAttribute)referrerProperty); _existenceOnly = true; }
public void Convert(IUnitOfWork unitOfWork, BaseEntity sourceEntity, BaseDto dto, PropertyInfo sourcePropertyInfo, ReferenceAttribute referenceAttribute, ReferenceString referenceString) { //PropertyInfo targetProperty = sourceEntity.GetType().GetProperty(ReferenceConversionUtils.GetReferencedId(referenceAttribute)); PropertyInfo targetProperty = ReferenceConversionUtils.GetReferencedPropertyId(sourceEntity, referenceAttribute); if (referenceString == null || string.IsNullOrEmpty(referenceString.Value)) { targetProperty.SetValue(sourceEntity, null); } else { targetProperty.SetValue(sourceEntity, referenceString.GetId()); } }
public void Convert(Connection connection, BaseEntity sourceEntity, BaseDto dto, PropertyInfo sourcePropertyInfo, ReferenceAttribute referenceAttribute, ReferenceString referenceString) { if (referenceString == null) { return; } PropertyInfo targetProperty = sourceEntity.GetType().GetProperty(referenceAttribute.RefencedPropertyName); List <Guid> referencedIds = referenceString.GetIds(); ICollection <U> referencedEntities = (ICollection <U>)targetProperty.GetValue(sourceEntity); if (IsReferenciesCreated(referencedIds, referencedEntities)) { CreateMultiReferences(connection, sourceEntity, targetProperty, referencedIds, referencedEntities); } else { UpdateMultiReference(connection, sourceEntity, targetProperty, referencedIds, referencedEntities); } }
public bool SetCountProperty(IEntity entity, string referencePropertyName, Guid referencedEntityID) { bool wasChanged = false; using (LogGroup logGroup = LogGroup.StartDebug("Setting the specified reference count property.")) { if (entity == null) { throw new ArgumentNullException("entity"); } LogWriter.Debug("Entity type: " + entity.GetType().FullName); LogWriter.Debug("Reference property name: " + referencePropertyName); LogWriter.Debug("Referenced entity ID: " + referencedEntityID); ReferenceAttribute attribute = EntitiesUtilities.GetReferenceAttribute(entity, referencePropertyName); Type referencedType = EntitiesUtilities.GetReferenceType(entity, referencePropertyName); // If the referenced entity type is not null then set the corresponding count property // otherwise skip it be cause a null referenced entity type means its a dynamically type reference property which hasn't been set if (referencedType != null) { LogWriter.Debug("Referenced type: " + referencedType.FullName); if (attribute.CountPropertyName != String.Empty) { LogWriter.Debug("Count property name: " + attribute.CountPropertyName); string mirrorPropertyName = EntitiesUtilities.GetMirrorPropertyName(entity, referencePropertyName); PropertyInfo property = entity.GetType().GetProperty(attribute.CountPropertyName); // Get the original reference count int originalCount = (int)property.GetValue(entity, null); LogWriter.Debug("Original count: " + originalCount); if (property == null) { throw new Exception("'" + attribute.CountPropertyName + "' count property not found on type '" + entity.ShortTypeName + "'."); } // Get the latest reference count int count = Provider.Counter.CountEntitiesWithReference( entity.GetType(), entity.ID, referencePropertyName, referencedType, mirrorPropertyName ); LogWriter.Debug("Count: " + count.ToString()); // If the new count is not the same as the old one then update the property // otherwise skip if (count != originalCount) { wasChanged = true; property.SetValue(entity, count, null); } } else { LogWriter.Debug("No count property specified on the reference attribute."); } } } return(wasChanged); }
public static string GetReferencedId(ReferenceAttribute referenceAttribute) { return(referenceAttribute.RefencedPropertyName + "Id"); }
public SearchOrder(ReferenceAttribute propertyToOrder) : this(propertyToOrder, OrderDirection.Asc) { }
private IReferenceConverter GetReferenceConverter(ReferenceAttribute referenceAttribute, Type sourceEntityType, Type referencedEntityType) { return(CreateReferenceConverter(typeof(MultiReferenceAttributeDtoToEntityConverter <,>), sourceEntityType, referencedEntityType)); }
public static Reference Create(EntityInfo entityInfo, PropertyInfo prop, ReferenceAttribute referenceAttribute) { return(new Reference(entityInfo, prop, referenceAttribute)); }
internal EntityTypeChangedArgs(EntityInfo info, ReferenceAttribute reference) { EntityInfo = info; ReferenceAttribute = reference; FieldAttribute = null; TableCreated = false; }
public static NodeAttribute GetNodeAttribute(ReferenceAttribute attr) { switch (attr) { case ReferenceAttribute.Parent: return NodeAttribute.Parent; case ReferenceAttribute.LockedBy: return NodeAttribute.LockedBy; case ReferenceAttribute.CreatedBy: return NodeAttribute.CreatedBy; case ReferenceAttribute.ModifiedBy: return NodeAttribute.ModifiedBy; default: throw new NotImplementedException("Unknown ReferenceAttribute"); } }
private static Expression ParseReferenceExpression(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema) { XmlAttribute attr; bool existenceOnly = false; attr = node.Attributes["existenceOnly"]; if (attr != null) { existenceOnly = attr.Value == "yes"; } object leftValue = ParseLeftValue(node, nsmgr, schema); PropertyType leftProp = leftValue as PropertyType; Node referencedNode = null; attr = node.Attributes["referencedNodeId"]; if (attr != null) { int referencedNodeId = XmlConvert.ToInt32(attr.Value); referencedNode = Node.LoadNode(referencedNodeId); if (referencedNode == null) { throw new ApplicationException(String.Concat("Referred node is not found: ", referencedNodeId)); } if (leftProp != null) { return(new ReferenceExpression(leftProp, referencedNode)); } ReferenceAttribute leftAttr = (ReferenceAttribute)leftValue; return(new ReferenceExpression(leftAttr, referencedNode)); } if (node.SelectSingleNode("x:*[1]", nsmgr) == null) { if (leftProp != null) { if (existenceOnly) { return(new ReferenceExpression(leftProp)); } return(new ReferenceExpression(leftProp, (Node)null)); } ReferenceAttribute leftAttr = (ReferenceAttribute)leftValue; if (existenceOnly) { return(new ReferenceExpression(leftAttr)); } return(new ReferenceExpression(leftAttr, (Node)null)); } object rightValue = ParseRightValue(node, nsmgr, schema); Expression rightExpr = rightValue as Expression; if (leftProp != null) { if (rightExpr != null) { return(new ReferenceExpression(leftProp, rightExpr)); } } else { ReferenceAttribute leftAttr = (ReferenceAttribute)leftValue; if (rightExpr != null) { return(new ReferenceExpression(leftAttr, rightExpr)); } } throw new ApplicationException(String.Concat("Unrecognized Reference expression: ", node.OuterXml)); }
public void Convert(Connection connection, BaseEntity sourceEntity, BaseDto dto, PropertyInfo sourcePropertyInfo, ReferenceAttribute referenceAttribute, ReferenceString referenceString) { PropertyInfo referencedEntityPropertyInfo = sourceEntity.GetType().GetProperty(referenceAttribute.RefencedPropertyName); IEnumerable <U> referencedEntities = (IEnumerable <U>)referencedEntityPropertyInfo.GetValue(sourceEntity, null); if (referencedEntities == null) { return; } ReferenceString referencedString = new ReferenceString(string.Empty); foreach (U referencedEntity in referencedEntities) { referencedString.Append(referencedEntity.Id, referencedEntity.ToString()); } sourcePropertyInfo.SetValue(dto, referencedString); }