public override IEntity Authorise(IEntity entity)
        {
            IEntity output = null;

            bool isAuthorised = false;

            using (LogGroup logGroup = LogGroup.StartDebug("Authorising the creation of references on the provided '" + entity.ShortTypeName + "' entity."))
            {
                foreach (PropertyInfo property in entity.GetType().GetProperties())
                {
                    if (EntitiesUtilities.IsReference(entity.GetType(), property))
                    {
                        IAuthoriseReferenceStrategy strategy = AuthoriseReferenceStrategy.New(entity, property);
                        // If the strategy is null then skip it because it means the reference property isn't set
                        if (strategy != null)
                        {
                            strategy.Authorise();
                        }
                    }
                }

                isAuthorised = IsAuthorised(entity);

                LogWriter.Debug("Is authorised: " + isAuthorised);

                if (isAuthorised)
                {
                    output = entity;
                }
            }

            return(output);
        }
Example #2
0
        public static IAuthoriseReferenceStrategy New(string entityTypeName, string propertyName, string referencedTypeName, string mirrorPropertyName)
        {
            IAuthoriseReferenceStrategy strategy = null;

            using (LogGroup logGroup = LogGroup.StartDebug("Instantiating a new AuthoriseReferenceStrategy for '" + entityTypeName + "' type to '" + referencedTypeName + "'."))
            {
                LogWriter.Debug("Entity type name: " + entityTypeName);
                LogWriter.Debug("Property name: " + propertyName);
                LogWriter.Debug("Referenced type name: " + referencedTypeName);
                LogWriter.Debug("Mirror property name: " + mirrorPropertyName);

                strategy = StrategyState.Strategies.Creator.NewReferenceAuthoriser(entityTypeName, propertyName, referencedTypeName, mirrorPropertyName);

                LogWriter.Debug("Strategy type: " + (strategy == null ? "[null]" : strategy.GetType().FullName));
            }

            return(strategy);
        }
Example #3
0
        public static IAuthoriseReferenceStrategy New(IEntity entity, PropertyInfo property)
        {
            IAuthoriseReferenceStrategy strategy = null;

            using (LogGroup logGroup = LogGroup.StartDebug("Instantiating a new AuthoriseReferenceStrategy for '" + property.Name + "' property on '" + entity.ShortTypeName + "' type."))
            {
                if (entity == null)
                {
                    throw new ArgumentNullException("entity");
                }

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

                Type referenceType = EntitiesUtilities.GetReferenceType(entity, property);

                // If the reference type is not null then continue
                if (referenceType != null)
                {
                    LogWriter.Debug("Referenced type: " + referenceType.FullName);

                    string mirrorPropertyName = EntitiesUtilities.GetMirrorPropertyName(entity, property);

                    LogWriter.Debug("Mirror property name: " + mirrorPropertyName);

                    strategy = New(entity.ShortTypeName, property.Name, referenceType.Name, mirrorPropertyName);

                    if (strategy != null)
                    {
                        strategy.SourceEntity   = entity;
                        strategy.SourceProperty = property.Name;
                    }
                }
                // Otherwise skip it because it means the property is not set
                else
                {
                    LogWriter.Debug("Reference type is null. Skipping.");
                }
            }
            return(strategy);
        }
        /// <summary>
        /// Creates a new authorise reference strategy.
        /// </summary>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public IAuthoriseReferenceStrategy NewReferenceAuthoriser(string typeName1, string propertyName1, string typeName2, string propertyName2)
        {
            IAuthoriseReferenceStrategy strategy = null;

            using (LogGroup logGroup = LogGroup.StartDebug("Creating a new authorise reference strategy."))
            {
                LogWriter.Debug("Type name 1: " + typeName1);
                LogWriter.Debug("Property name 1: " + propertyName1);
                LogWriter.Debug("Type name 2: " + typeName2);
                LogWriter.Debug("Property name 2: " + propertyName2);

                AuthoriseReferenceStrategyLocator locator = new AuthoriseReferenceStrategyLocator(StrategyState.Strategies);

                StrategyInfo strategyInfo = locator.Locate(typeName1, propertyName1, typeName2, propertyName2);

                if (strategyInfo != null)
                {
                    strategy = strategyInfo.New <IAuthoriseReferenceStrategy>();
                }
            }

            return(strategy);
        }