Exemplo n.º 1
0
        public TypedEntity()
        {
            //v2: create the relation proxy collection
            RelationProxies = new RelationProxyCollection(this);

            //create the attributes
            Func <TypedAttribute, bool> validateAdd = x =>
            {
                //if (FixedAttributeDefinitionAliases.AllAliases.Contains(x.AttributeDefinition.Alias))
                //    return true;
                // TODO: Better validation here
                if (EntitySchema == null)
                {
                    return(true);
                }

                var composite = EntitySchema as CompositeEntitySchema;
                if (composite != null)
                {
                    return(composite.AllAttributeDefinitions.Any(y => y.Alias == x.AttributeDefinition.Alias));
                }

                return(EntitySchema.AttributeDefinitions.Any(y => y.Alias == x.AttributeDefinition.Alias));
            };

            Attributes = new TypedAttributeCollection(validateAdd);
            Attributes.CollectionChanged += AttributesCollectionChanged;
        }
Exemplo n.º 2
0
        public static bool TrySetValue(this TypedAttributeCollection attributeCollection, string attributeName, string value)
        {
            var attribute = attributeCollection.SingleOrDefault(x => x.AttributeDefinition.Alias == attributeName);

            if (attribute == null)
            {
                return(false);
            }
            attribute.DynamicValue = value;
            return(true);
        }
Exemplo n.º 3
0
        private static void Add(this TypedAttributeCollection attributeCollection, TypedAttribute typedAttribute)
        {
            //NOTE: Here we need to generate an id for this item.
            // Though Id generation should generally be performed by Hive providers, a TypedAttribute can exist without an
            // id in the repository when a AttributeDefinition is created on the Schema and there are no TypeEntity revisions
            // for that schema with the updated AttributeDefinition.
            if (typedAttribute.Id.IsNullValueOrEmpty())
            {
                typedAttribute.Id = new HiveId(Guid.NewGuid());
            }

            attributeCollection.Add(typedAttribute);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets
        /// </summary>
        /// <param name="attributeCollection"></param>
        /// <param name="typedAttribute"></param>
        public static void SetValueOrAdd(this TypedAttributeCollection attributeCollection, TypedAttribute typedAttribute)
        {
            var attribute = attributeCollection.SingleOrDefault(x => x.AttributeDefinition.Alias == typedAttribute.AttributeDefinition.Alias);

            if (attribute == null)
            {
                attributeCollection.Add(typedAttribute);
            }
            else
            {
                attribute.Values.Clear();
                typedAttribute.Values.ForEach(attribute.Values.Add);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a property to the collection if it doesn't exist and returns true, otherwise returns false
        /// </summary>
        /// <param name="attributeCollection"></param>
        /// <param name="typedAttribute"></param>
        /// <returns></returns>
        public static bool TryAdd(this TypedAttributeCollection attributeCollection, TypedAttribute typedAttribute)
        {
            // First try to find an existing attribute by alias
            var existing = attributeCollection.FirstOrDefault(x => x.AttributeDefinition.Alias == typedAttribute.AttributeDefinition.Alias);

            // If it's null, add it
            if (existing == null)
            {
                Add(attributeCollection, typedAttribute);
                return(true);
            }

            // If the attribute exists, but its definition doesn't have an id, but the incoming one does, we should replace it
            // This is for scenarios where, for example, an entity has been "setup" from a schema that didn't have ids set, and is then
            // later re-setup from a schema that had ids for its definitions
            if (existing.AttributeDefinition.Id == HiveId.Empty && typedAttribute.AttributeDefinition.Id != HiveId.Empty)
            {
                existing.AttributeDefinition = typedAttribute.AttributeDefinition;
            }

            return(false);
        }
Exemplo n.º 6
0
        public TypedEntity()
        {
            //v2: create the relation proxy collection
            RelationProxies = new RelationProxyCollection(this);

            //create the attributes
            Func<TypedAttribute, bool> validateAdd = x =>
            {
                //if (FixedAttributeDefinitionAliases.AllAliases.Contains(x.AttributeDefinition.Alias))
                //    return true;
                // TODO: Better validation here
                if (EntitySchema == null) return true;

                var composite = EntitySchema as CompositeEntitySchema;
                if (composite != null)
                {
                    return composite.AllAttributeDefinitions.Any(y => y.Alias == x.AttributeDefinition.Alias);
                }

                return EntitySchema.AttributeDefinitions.Any(y => y.Alias == x.AttributeDefinition.Alias);
            };

            Attributes = new TypedAttributeCollection(validateAdd);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Determines whether the specified attributes contains key.
 /// </summary>
 /// <param name="attributes">The attributes.</param>
 /// <param name="key">The key.</param>
 /// <returns>
 ///   <c>true</c> if the specified attributes contains key; otherwise, <c>false</c>.
 /// </returns>
 public static bool ContainsKey(this TypedAttributeCollection attributes, string key)
 {
     //dont' worry about casing..
     return(attributes.Any(x => x.AttributeDefinition.Alias.InvariantEquals(key)));
 }