Esempio n. 1
0
 public void PerformAddOrUpdate(IReferenceByHiveId entity)
 {
     Mandate.ParameterNotNull(entity, "entity");
     if (!entity.Id.IsNullValueOrEmpty())
     {
         AddToCache(entity);
     }
 }
        /// <summary>
        /// Iterates through all identifiable items in the object graph and assigns Ids to entities that don't have an id assigned using the idGenerator.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="idGenerator"></param>
        public static void AssignIds(this IReferenceByHiveId obj, Func <HiveId> idGenerator)
        {
            //get all identifiable entities that don't have ids assigned
            var entities = (from all in obj.GetAllIdentifiableItems()
                            where all.Id.IsNullValueOrEmpty()
                            select all).ToArray();

            //now that we have a unique list of all new entities that reqiure ids, lets generate them
            foreach (var e in entities)
            {
                //ensure we're not re-creating an id for the same entity
                if (e.Id.IsNullValueOrEmpty())
                {
                    e.Id = idGenerator();
                }
            }
        }
Esempio n. 3
0
 private HiveId GetFromEntityOrEmpty(IReferenceByHiveId entity)
 {
     return(entity == null ? HiveId.Empty : entity.Id);
 }
        /// <summary>
        /// Returns a list of all associated IReferenceByHiveId entities associated with the entity type passed
        /// in. This will recusively find all entities attached to the item.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static IEnumerable <IReferenceByHiveId> GetAllIdentifiableItems(this IReferenceByHiveId item)
        {
            if (item == null)
            {
                yield break;
            }
            var type = item.GetType();

            yield return(item);

            if (TypeFinder.IsTypeAssignableFrom <TypedEntity>(type))
            {
                var casted = (TypedEntity)item;
                foreach (var allIdentifiableItem in casted.EntitySchema.GetAllIdentifiableItems())
                {
                    yield return(allIdentifiableItem);
                }
                foreach (var attribute in casted.Attributes)
                {
                    yield return(attribute);

                    foreach (var allIdentifiableItem in attribute.AttributeDefinition.GetAllIdentifiableItems())
                    {
                        yield return(allIdentifiableItem);
                    }
                }
            }
            if (TypeFinder.IsTypeAssignableFrom <EntitySchema>(type))
            {
                var casted = (EntitySchema)item;
                foreach (var attributeDefinition in casted.AttributeDefinitions)
                {
                    // Don't call back into GetAllIdentifiable items here, rather
                    // separately iterate through the types and groups explicitly set
                    // on the Schema to include those that aren't tied to an attribute definition
                    yield return(attributeDefinition);
                }
                foreach (var attributeType in casted.AttributeTypes)
                {
                    yield return(attributeType);
                }
                foreach (var attributeGroup in casted.AttributeGroups)
                {
                    yield return(attributeGroup);
                }
            }
            if (TypeFinder.IsTypeAssignableFrom <TypedAttribute>(type))
            {
                var casted = (TypedAttribute)item;
                foreach (var allIdentifiableItem in casted.AttributeDefinition.GetAllIdentifiableItems())
                {
                    yield return(allIdentifiableItem);
                }
            }
            if (TypeFinder.IsTypeAssignableFrom <AttributeDefinition>(type))
            {
                var casted = (AttributeDefinition)item;
                yield return(casted);

                yield return(casted.AttributeType);

                if (casted.AttributeGroup != null)
                {
                    yield return(casted.AttributeGroup);
                }
            }
        }