예제 #1
0
        public virtual int SetNumber(ISubEntity entity)
        {
            using (LogGroup logGroup = LogGroup.Start("Setting the number of the new sub entity.", NLog.LogLevel.Debug))
            {
                if (entity == null)
                {
                    throw new ArgumentNullException("entity");
                }

                if (entity.Parent == null)
                {
                    throw new Exception("No parent is assigned to this item.");
                }

                IEntity parent = entity.Parent;

                ActivateStrategy.New(parent).Activate(parent, entity.ItemsPropertyName);

                ISubEntity[] items = Collection <ISubEntity> .ConvertAll(EntitiesUtilities.GetPropertyValue(parent, entity.ItemsPropertyName));

                LogWriter.Debug("Existing items: " + items.Length.ToString());

                entity.Number = items.Length + 1;

                LogWriter.Debug("Entity number: " + entity.Number.ToString());
            }
            return(entity.Number);
        }
        public override void Delete(IEntity entity)
        {
            if (entity is ISubEntity)
            {
                ISubEntity subEntity = (ISubEntity)entity;

                if (subEntity.Parent == null)
                {
                    ActivateStrategy.New(subEntity, RequireAuthorisation).Activate(subEntity, subEntity.ParentPropertyName);
                }

                IEntity parent = subEntity.Parent;

                if (parent == null)
                {
                    throw new Exception("No parent assigned to sub entity.");
                }

                base.Delete(subEntity);

                RefreshNumbers(subEntity.Parent, subEntity.ItemsPropertyName);
            }
            else
            {
                throw new ArgumentException("entity must be ISubEntity");
            }
        }
예제 #3
0
        public virtual void AssignStrategies(IEntity entity)
        {
            if (entity != null)
            {
                // Assign an activation strategy
                entity.Activator = ActivateStrategy.New(entity);

                // Assign a validation strategy
                entity.Validator = ValidateStrategy.New(entity);
            }
        }
예제 #4
0
        public void CheckStrategies(IEntity entity)
        {
            if (entity.Validator == null)
            {
                entity.Validator = ValidateStrategy.New(entity);
            }

            if (entity.Activator == null)
            {
                entity.Activator = ActivateStrategy.New(entity);
            }
        }
        /// <summary>
        /// Refreshes the numbers of the sub entities on the specified items property of the provided parent entity.
        /// </summary>
        /// <param name="parentEntity">The parent entity containing the sub items.</param>
        /// <param name="itemsPropertyName">The name of the property containing the sub items.</param>
        public void Refresh(IEntity parentEntity, string itemsPropertyName)
        {
            if (parentEntity == null)
            {
                throw new ArgumentNullException("parentEntity");
            }

            if (itemsPropertyName == null)
            {
                throw new ArgumentNullException("itemsPropertyName");
            }

            if (itemsPropertyName == String.Empty)
            {
                throw new ArgumentException("An items property name must be provided.", "itemsPropertyName");
            }

            // Activate the items property
            ActivateStrategy.New(parentEntity).Activate(parentEntity, itemsPropertyName);

            // Get the items property
            PropertyInfo property = parentEntity.GetType().GetProperty(itemsPropertyName);

            if (property == null)
            {
                throw new ArgumentException("No property with the name '" + itemsPropertyName + "' found on the type '" + parentEntity.ShortTypeName + "'.");
            }

            // Get the value of the items property
            ISubEntity[] items = (ISubEntity[])Collection <ISubEntity> .ConvertAll(property.GetValue(parentEntity, null));

            string numberPropertyName = String.Empty;

            // If items were found
            if (items.Length > 0)
            {
                numberPropertyName = items[0].NumberPropertyName;

                if (numberPropertyName != null && numberPropertyName != String.Empty)
                {
                    // Sort by number
                    items = Collection <ISubEntity> .Sort(items, numberPropertyName + "Ascending");

                    // Refresh the numbers
                    Refresh(items, true);
                }
            }
        }
        public virtual void Refresh(ISubEntity[] items, bool updateModified)
        {
            Collection <ISubEntity> updated = new Collection <ISubEntity>();

            for (int i = 0; i < items.Length; i++)
            {
                int originalNumber = items[i].Number;

                items[i].Number = i + 1;               // +1 to change index (0 based) to number (1 based)

                if (originalNumber != items[i].Number)
                {
                    updated.Add(items[i]);
                }
            }

            foreach (ISubEntity item in updated)
            {
                ActivateStrategy.New(item, RequireAuthorisation).Activate(item);

                UpdateStrategy.New(item, RequireAuthorisation).Update(item);
            }
        }
        public override void React(SoftwareMonkeys.SiteStarter.Entities.IEntity entity)
        {
            ActivateStrategy.New(entity).Activate(entity, "Author");

            base.React(entity);
        }
예제 #8
0
 public virtual void AssignActivator(IEntity entity)
 {
     // Assign an activation strategy
     entity.Activator = ActivateStrategy.New(entity);
 }