Exemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of the specified type of entity.
        /// </summary>
        /// <param name="shortTypeName">The short name of the type of entity to create an instance of.</param>
        public virtual IEntity Create()
        {
            Type type = EntityState.GetType(TypeName);

            if (RequireAuthorisation)
            {
                AuthoriseCreateStrategy.New(TypeName).EnsureAuthorised(TypeName);
            }

            IEntity entity = (IEntity)Activator.CreateInstance(type);

            if (entity == null)
            {
                throw new Exception("Failed to create instance of '" + type.Name + "'.");
            }

            if (RequireAuthorisation)
            {
                AuthoriseCreateStrategy.New(TypeName).EnsureAuthorised(entity);
            }

            AssignValidator(entity);

            AssignActivator(entity);

            React(entity);

            return(entity);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new instance of the specified type of entity.
        /// </summary>
        /// <param name="shortTypeName">The short name of the type of entity to create an instance of.</param>
        public override IEntity Create()
        {
            // TODO: Check if needed. Should be unnecessary

            ISubEntity entity = null;

            using (LogGroup logGroup = LogGroup.Start("Creating a new entity of type '" + TypeName + "'.", NLog.LogLevel.Debug))
            {
                if (!EntityState.IsType(TypeName))
                {
                    throw new InvalidOperationException("The TypeName property needs to be set to the type of an entity. Invalid type: " + TypeName);
                }

                Type type = EntityState.GetType(TypeName);

                LogWriter.Debug("Authorisation required: " + RequireAuthorisation.ToString());

                if (RequireAuthorisation)
                {
                    AuthoriseCreateStrategy.New(TypeName).EnsureAuthorised(TypeName);
                }

                entity    = (ISubEntity)base.Create();
                entity.ID = Guid.NewGuid();
            }
            return(entity);
        }
        /// <summary>
        /// Creates a new instance of the specified type of entity.
        /// </summary>
        /// <param name="shortTypeName">The short name of the type of entity to create an instance of.</param>
        public override IEntity Create()
        {
            Type type = EntityState.GetType(TypeName);

            if (RequireAuthorisation)
            {
                AuthoriseCreateStrategy.New(TypeName).EnsureAuthorised(TypeName);
            }

            User user = (User)base.Create();

            user.IsApproved = Config.Application.Settings.GetBool("AutoApproveNewUsers");

            return(user);
        }