public PageTypePropertyDefinition(string name, Type propertyType, IPageType pageType, PageTypePropertyAttribute pageTypePropertyAttribute)
 {
     Name = name;
     PropertyType = propertyType;
     PageType = pageType;
     PageTypePropertyAttribute = pageTypePropertyAttribute;
 }
Пример #2
0
        protected internal virtual PageDefinitionType GetPageDefinitionType(
            string pageTypeName, string propertyName,
            Type propertyType, PageTypePropertyAttribute pageTypePropertyAttribute)
        {
            Type pagePropertyType = GetPropertyType(propertyType, pageTypePropertyAttribute);

            if (pagePropertyType == null)
            {
                string errorMessage = "Unable to find a valid EPiServer property type for the property {0} in the page type {1}";
                errorMessage = string.Format(CultureInfo.InvariantCulture, errorMessage, propertyName, pageTypeName);
                throw new UnmappablePropertyTypeException(errorMessage);
            }

            PageDefinitionType pageDefinitionType;

            if (TypeIsNativePropertyType(pagePropertyType))
            {
                int nativeTypeID = GetNativeTypeID(pagePropertyType);
                pageDefinitionType = PageDefinitionTypeFactory.GetPageDefinitionType(nativeTypeID);
            }
            else
            {
                string pageDefinitionTypeName = pagePropertyType.FullName;
                string assemblyName           = pagePropertyType.Assembly.GetName().Name;
                pageDefinitionType = PageDefinitionTypeFactory.GetPageDefinitionType(pageDefinitionTypeName, assemblyName);
            }
            return(pageDefinitionType);
        }
        protected internal virtual void ValidatePageTypeProperties(PageTypeDefinition definition)
        {
            List <PropertyInfo> propertiesForPageType = definition.Type.GetPageTypePropertiesOnClass().ToList();

            foreach (PropertyInfo propertyInfo in propertiesForPageType)
            {
                ValidatePageTypeProperty(propertyInfo);
            }

            // validate any page type property group propery defininitions
            foreach (PropertyInfo propertyGroupProperty in definition.Type.GetPageTypePropertyGroupProperties())
            {
                PropertyInfo[] propertyGroupProperties = propertyGroupProperty.PropertyType.GetPublicOrPrivateProperties();

                foreach (PropertyInfo property in propertyGroupProperties)
                {
                    PageTypePropertyAttribute attribute = property.GetCustomAttributes <PageTypePropertyAttribute>().FirstOrDefault();

                    if (attribute == null)
                    {
                        continue;
                    }

                    ValidatePageTypeProperty(property);
                }
            }
        }
        protected internal virtual void ValidatePageTypeAttributeTabProperty(PropertyInfo propertyInfo, PageTypePropertyAttribute attribute)
        {
            if (attribute.Tab == null)
                return;

            if (!typeof(Tab).IsAssignableFrom(attribute.Tab))
            {

                string errorMessage =
                    "{0} in {1} has a {2} with Tab property set to type that does not inherit from {3}.";
                errorMessage = string.Format(CultureInfo.InvariantCulture, errorMessage, propertyInfo.Name,
                                             propertyInfo.DeclaringType.Name, typeof(PageTypePropertyAttribute).Name,
                                             typeof(Tab));
                throw new PageTypeBuilderException(errorMessage);
            }

            if (attribute.Tab.IsAbstract)
            {
                string errorMessage =
                    "{0} in {1} has a {2} with Tab property set to a type that is abstract.";
                errorMessage = string.Format(CultureInfo.InvariantCulture, errorMessage, propertyInfo.Name,
                                             propertyInfo.DeclaringType.Name, typeof(PageTypePropertyAttribute).Name);
                throw new PageTypeBuilderException(errorMessage);
            }
        }
        protected internal virtual PageDefinitionType GetPageDefinitionType(
            string pageTypeName, string propertyName, 
            Type propertyType, PageTypePropertyAttribute pageTypePropertyAttribute)
        {
            Type pagePropertyType = GetPropertyType(propertyType, pageTypePropertyAttribute);

            if (pagePropertyType == null)
            {
                string errorMessage = "Unable to find a valid EPiServer property type for the property {0} in the page type {1}";
                errorMessage = string.Format(CultureInfo.InvariantCulture, errorMessage, propertyName, pageTypeName);
                throw new UnmappablePropertyTypeException(errorMessage);
            }

            PageDefinitionType pageDefinitionType;

            if (TypeIsNativePropertyType(pagePropertyType))
            {
                int nativeTypeID = GetNativeTypeID(pagePropertyType);
                pageDefinitionType = PageDefinitionTypeFactory.GetPageDefinitionType(nativeTypeID);
            }
            else
            {
                string pageDefinitionTypeName = pagePropertyType.FullName;
                string assemblyName = pagePropertyType.Assembly.GetName().Name;
                pageDefinitionType = PageDefinitionTypeFactory.GetPageDefinitionType(pageDefinitionTypeName, assemblyName);
            }
            return pageDefinitionType;
        }
Пример #6
0
 public PageTypePropertyDefinition(string name, Type propertyType, IPageType pageType, PageTypePropertyAttribute pageTypePropertyAttribute)
 {
     Name         = name;
     PropertyType = propertyType;
     PageType     = pageType;
     PageTypePropertyAttribute = pageTypePropertyAttribute;
 }
 public static PageTypePropertyDefinition CreatePageTypePropertyDefinition()
 {
     string name = TestValueUtility.CreateRandomString();
     Type type = typeof(string);
     IPageType pageType = new NativePageType();
     PageTypePropertyAttribute attribute = new PageTypePropertyAttribute();
     return new PageTypePropertyDefinition(name, type, pageType, attribute);
 }
Пример #8
0
        public static PageTypePropertyDefinition CreatePageTypePropertyDefinition()
        {
            string    name     = TestValueUtility.CreateRandomString();
            Type      type     = typeof(string);
            IPageType pageType = new NativePageType();
            PageTypePropertyAttribute attribute = new PageTypePropertyAttribute();

            return(new PageTypePropertyDefinition(name, type, pageType, attribute));
        }
 protected internal virtual Type GetPropertyType(Type propertyType, PageTypePropertyAttribute pageTypePropertyAttribute)
 {
     Type pagePropertyType = pageTypePropertyAttribute.Type;
     if (pagePropertyType == null)
     {
         pagePropertyType = GetDefaultPropertyType(propertyType);
     }
     return pagePropertyType;
 }
Пример #10
0
        private void UpdateLongStringSettings(PageDefinition pageDefinition, PageTypePropertyAttribute propertyAttribute)
        {
            EditorToolOption longStringSettings = propertyAttribute.LongStringSettings;

            if (longStringSettings == default(EditorToolOption) && !propertyAttribute.ClearAllLongStringSettings)
            {
                longStringSettings = EditorToolOption.All;
            }
            pageDefinition.LongStringSettings = longStringSettings;
        }
        protected internal virtual Type GetPropertyType(Type propertyType, PageTypePropertyAttribute pageTypePropertyAttribute)
        {
            Type pagePropertyType = pageTypePropertyAttribute.Type;

            if (pagePropertyType == null)
            {
                pagePropertyType = GetDefaultPropertyType(propertyType);
            }
            return(pagePropertyType);
        }
Пример #12
0
        public void GivenType_Constructor_SetsPropertyTypeProperty()
        {
            PageTypePropertyAttribute attribute = new PageTypePropertyAttribute();
            string    name         = TestValueUtility.CreateRandomString();
            Type      propertyType = typeof(string);
            IPageType pageType     = new NativePageType();

            PageTypePropertyDefinition definition = new PageTypePropertyDefinition(name, propertyType, pageType, attribute);


            Assert.Equal <Type>(propertyType, definition.PropertyType);
        }
        public virtual PageDefinitionType GetPageDefinitionType(
            string pageTypeName, string propertyName, 
            Type propertyType, PageTypePropertyAttribute pageTypePropertyAttribute)
        {
            Type pagePropertyType = GetPropertyType(propertyType, pageTypePropertyAttribute);

            if (pagePropertyType == null)
            {
                ThrowUnmappablePropertyTypeException(propertyName, pageTypeName);
            }

            return GetPageDefinitionTypeImpl(pagePropertyType);
        }
        public virtual PageDefinitionType GetPageDefinitionType(
            string pageTypeName, string propertyName,
            Type propertyType, PageTypePropertyAttribute pageTypePropertyAttribute)
        {
            Type pagePropertyType = GetPropertyType(propertyType, pageTypePropertyAttribute);

            if (pagePropertyType == null)
            {
                ThrowUnmappablePropertyTypeException(propertyName, pageTypeName);
            }

            return(GetPageDefinitionTypeImpl(pagePropertyType));
        }
Пример #15
0
        public void GivenPageType_Constructor_SetsPageTypeProperty()
        {
            PageTypePropertyAttribute attribute = new PageTypePropertyAttribute();
            string    name         = TestValueUtility.CreateRandomString();
            Type      propertyType = typeof(string);
            IPageType pageType     = new NativePageType();

            pageType.GUID = Guid.NewGuid();

            PageTypePropertyDefinition definition = new PageTypePropertyDefinition(name, propertyType, pageType, attribute);


            Assert.Equal <IPageType>(pageType, definition.PageType, new PageTypeComparer());
        }
        public void GivenAttributeWithTabPropertySetToAbstractSubClassOfTab_ValidatePageTypeAttributeTabProperty_ThrowsException()
        {
            PropertyInfo propertyInfo = typeof(TestPageType).GetProperty("PropertyWithTabSetAbstractTabSubClass");
            PageTypePropertyAttribute             attribute           = propertyInfo.GetCustomAttributes <PageTypePropertyAttribute>().First();
            PageTypeDefinitionPropertiesValidator propertiesValidator = new PageTypeDefinitionPropertiesValidator(null);


            Exception exception = Record.Exception(() =>
            {
                propertiesValidator.ValidatePageTypeAttributeTabProperty(propertyInfo, attribute);
            });

            Assert.NotNull(exception);
        }
        protected internal virtual void ValidatePageTypePropertyType(PropertyInfo propertyInfo)
        {
            PageTypePropertyAttribute pageTypePropertyAttribute =
                (PageTypePropertyAttribute)
                propertyInfo.GetCustomAttributes(typeof(PageTypePropertyAttribute), false).First();

            if (PageDefinitionTypeMapper.GetPageDefinitionType(
                    propertyInfo.DeclaringType.Name, propertyInfo.Name, propertyInfo.PropertyType, pageTypePropertyAttribute) == null)
            {
                string errorMessage = "Unable to map the type for the property {0} in {1} to a suitable EPiServer CMS property.";
                errorMessage = string.Format(CultureInfo.InvariantCulture, errorMessage, propertyInfo.Name, propertyInfo.DeclaringType.Name);
                throw new UnmappablePropertyTypeException(errorMessage);
            }
        }
        public void GivenAttributeWithValidTabProperty_ValidatePageTypeAttributeTabProperty_DoesNotThrowException()
        {
            PropertyInfo propertyInfo = typeof(TestPageType).GetProperty("PropertyWithValidTab");
            PageTypePropertyAttribute             attribute           = propertyInfo.GetCustomAttributes <PageTypePropertyAttribute>().First();
            PageTypeDefinitionPropertiesValidator propertiesValidator = new PageTypeDefinitionPropertiesValidator(null);


            Exception exception = Record.Exception(() =>
            {
                propertiesValidator.ValidatePageTypeAttributeTabProperty(propertyInfo, attribute);
            });

            Assert.Null(exception);
        }
        public void GivenAttributeWithNoTypeSpecifiedAndOfUnmappableType_ValidatePageTypePropertyType_ThrowsException()
        {
            PropertyInfo propertyInfo = typeof(TestPageType).GetProperty("PropertyWithInvalidTypeAndNoTypeSpecified");
            PageTypePropertyAttribute             attribute           = propertyInfo.GetCustomAttributes <PageTypePropertyAttribute>().First();
            PageTypeDefinitionPropertiesValidator propertiesValidator = new PageTypeDefinitionPropertiesValidator(new PageDefinitionTypeMapper(null, new NativePageDefinitionsMap()));

            Exception exception = Record.Exception(() =>
            {
                propertiesValidator.ValidatePageTypePropertyType(propertyInfo);
            });

            Assert.NotNull(exception);
            Assert.Equal <Type>(typeof(UnmappablePropertyTypeException), exception.GetType());
        }
        public void GivenPropertyInfo_ValidatePageTypePropertyAttribute_ValidatesPageTypeAttributeTabProperty()
        {
            PropertyInfo propertyInfo = typeof(TestPageType).GetProperty("StringTestProperty");
            PageTypePropertyAttribute             attribute           = propertyInfo.GetCustomAttributes <PageTypePropertyAttribute>().First();
            MockRepository                        fakes               = new MockRepository();
            PageTypeDefinitionPropertiesValidator propertiesValidator = fakes.PartialMock <PageTypeDefinitionPropertiesValidator>((PageDefinitionTypeMapper)null);

            propertiesValidator.Stub(validator =>
                                     validator.ValidatePageTypeAttributeTabProperty(Arg <PropertyInfo> .Is.NotNull, Arg <PageTypePropertyAttribute> .Is.NotNull));
            propertiesValidator.Replay();

            propertiesValidator.ValidatePageTypePropertyAttribute(propertyInfo);

            propertiesValidator.AssertWasCalled(validator =>
                                                validator.ValidatePageTypeAttributeTabProperty(propertyInfo, attribute));
        }
        private PageTypePropertyAttribute AdjustPropertyGroupAttributeProperties(PageTypePropertyAttribute attribute, PageTypePropertyGroupAttribute groupAttribute)
        {
            if (groupAttribute != null)
            {
                if (!string.IsNullOrEmpty(groupAttribute.EditCaptionPrefix))
                {
                    attribute.EditCaption = groupAttribute.EditCaptionPrefix + attribute.EditCaption;
                }

                if (groupAttribute.StartSortOrderFrom > 0)
                {
                    attribute.SortOrder = groupAttribute.StartSortOrderFrom + attribute.SortOrder;
                }
            }
            return(attribute);
        }
Пример #22
0
        protected virtual int GetFieldOrder(PageDefinition pageDefinition, PageTypePropertyAttribute propertyAttribute)
        {
            int fieldOrder = propertyAttribute.SortOrder;

            if (fieldOrder == PageTypePropertyAttribute.SortOrderNoValue)
            {
                fieldOrder = 0;

                if (pageDefinition.FieldOrder != 0)
                {
                    fieldOrder = pageDefinition.FieldOrder;
                }
            }

            return(fieldOrder);
        }
        public void GivenPageTypeWithPropertyAndCorrespondingPropertyDefition_GetExistingPropertyDefinition_ReturnsPageDefinition()
        {
            PageTypePropertyUpdater utility = PageTypePropertyUpdaterFactory.Create();
            IPageType pageType = new NativePageType();
            string name = TestValueUtility.CreateRandomString();
            Type type = typeof(string);
            PageTypePropertyAttribute attribute = new PageTypePropertyAttribute();
            PageTypePropertyDefinition pageTypePropertyDefinition = new PageTypePropertyDefinition(name, type, pageType, attribute);
            PageDefinition pageDefinition = new PageDefinition();
            pageDefinition.Name = name;
            pageType.Definitions.Add(pageDefinition);

            PageDefinition returnedPageDefinition = utility.GetExistingPageDefinition(pageType, pageTypePropertyDefinition);

            Assert.Equal<PageDefinition>(pageDefinition, returnedPageDefinition);
        }
Пример #24
0
        public void GivenPageTypeWithPropertyAndCorrespondingPropertyDefition_GetExistingPropertyDefinition_ReturnsPageDefinition()
        {
            PageTypePropertyUpdater utility = PageTypePropertyUpdaterFactory.Create();
            IPageType pageType = new NativePageType();
            string    name     = TestValueUtility.CreateRandomString();
            Type      type     = typeof(string);
            PageTypePropertyAttribute  attribute = new PageTypePropertyAttribute();
            PageTypePropertyDefinition pageTypePropertyDefinition = new PageTypePropertyDefinition(name, type, pageType, attribute);
            PageDefinition             pageDefinition             = new PageDefinition();

            pageDefinition.Name = name;
            pageType.Definitions.Add(pageDefinition);

            PageDefinition returnedPageDefinition = utility.GetExistingPageDefinition(pageType, pageTypePropertyDefinition);

            Assert.Equal <PageDefinition>(pageDefinition, returnedPageDefinition);
        }
Пример #25
0
        protected internal virtual void UpdatePageDefinitionValues(PageDefinition pageDefinition, PageTypePropertyDefinition pageTypePropertyDefinition)
        {
            PageTypePropertyAttribute propertyAttribute = pageTypePropertyDefinition.PageTypePropertyAttribute;

            pageDefinition.EditCaption  = pageTypePropertyDefinition.GetEditCaptionOrName();
            pageDefinition.HelpText     = propertyAttribute.HelpText ?? string.Empty;
            pageDefinition.Required     = propertyAttribute.Required;
            pageDefinition.Searchable   = propertyAttribute.Searchable;
            pageDefinition.DefaultValue = propertyAttribute.DefaultValue != null?propertyAttribute.DefaultValue.ToString() : string.Empty;

            pageDefinition.DefaultValueType = propertyAttribute.DefaultValueType;
            pageDefinition.LanguageSpecific = propertyAttribute.UniqueValuePerLanguage;
            pageDefinition.DisplayEditUI    = propertyAttribute.DisplayInEditMode;
            pageDefinition.FieldOrder       = propertyAttribute.SortOrder;
            UpdateLongStringSettings(pageDefinition, propertyAttribute);
            UpdatePageDefinitionTab(pageDefinition, propertyAttribute);
        }
        public virtual IEnumerable <PageTypePropertyDefinition> GetPageTypePropertyDefinitions(IPageType pageType, Type pageTypeType)
        {
            var properties = pageTypeType.GetAllValidPageTypePropertiesFromClassAndImplementedInterfaces();

            List <PageTypePropertyDefinition> pageTypePropertyDefinitions = new List <PageTypePropertyDefinition>();

            foreach (PropertyInfo property in properties)
            {
                PageTypePropertyAttribute attribute = GetPageTypePropertyAttribute(property);

                if (attribute == null)
                {
                    continue;
                }

                pageTypePropertyDefinitions.Add(new PageTypePropertyDefinition(property.Name, property.PropertyType, pageType, attribute));
            }
            return(pageTypePropertyDefinitions);
        }
        public void GivenAttributeWithMappableTypeSpecified_ValidatePageTypePropertyType_DoesNotThrowException()
        {
            PropertyInfo propertyInfo = typeof(TestPageType).GetProperty("PropertyWithValidTypeSpecified");
            PageTypePropertyAttribute    attribute = propertyInfo.GetCustomAttributes <PageTypePropertyAttribute>().First();
            MockRepository               fakes     = new MockRepository();
            PageDefinitionTypeRepository pageDefinitionTypeRepository = fakes.Stub <PageDefinitionTypeRepository>();

            pageDefinitionTypeRepository.Stub(factory =>
                                              factory.GetPageDefinitionType("EPiServer.SpecializedProperties.PropertyXhtmlString", "EPiServer")).Return(new PageDefinitionType());
            pageDefinitionTypeRepository.Replay();
            PageTypeDefinitionPropertiesValidator propertiesValidator =
                new PageTypeDefinitionPropertiesValidator(new PageDefinitionTypeMapper(pageDefinitionTypeRepository, new NativePageDefinitionsMap()));

            Exception exception = Record.Exception(() =>
            {
                propertiesValidator.ValidatePageTypePropertyType(propertyInfo);
            });

            Assert.Null(exception);
        }
        private IEnumerable <PageTypePropertyDefinition> GetPropertyGroupPropertyDefinitions(IPageType pageType, PropertyInfo propertyGroupProperty)
        {
            PageTypePropertyGroupAttribute groupAttribute = GetPropertyAttribute <PageTypePropertyGroupAttribute>(propertyGroupProperty);

            PropertyInfo[] propertyGroupProperties = propertyGroupProperty.PropertyType.GetPublicOrPrivateProperties();

            foreach (PropertyInfo property in propertyGroupProperties)
            {
                PageTypePropertyAttribute attribute = GetPropertyAttribute <PageTypePropertyAttribute>(property);

                if (attribute == null)
                {
                    continue;
                }

                string resolvedPropertyName = PageTypePropertyGroupHierarchy.ResolvePropertyName(propertyGroupProperty.Name, property.Name);
                attribute = AdjustPropertyGroupAttributeProperties(attribute, groupAttribute);

                yield return(new PageTypePropertyDefinition(resolvedPropertyName, property.PropertyType, pageType, attribute));
            }
        }
        public void GivenAttributeWithMappableTypeAndUnmappableTypeSpecified_ValidatePageTypePropertyType_ThrowsException()
        {
            PropertyInfo propertyInfo = typeof(TestPageType).GetProperty("PropertyWithInvalidTypeSpecified");
            PageTypePropertyAttribute    attribute = propertyInfo.GetCustomAttributes <PageTypePropertyAttribute>().First();
            MockRepository               fakes     = new MockRepository();
            PageDefinitionTypeRepository pageDefinitionTypeRepository = fakes.Stub <PageDefinitionTypeRepository>();

            pageDefinitionTypeRepository.Stub(factory =>
                                              factory.GetPageDefinitionType("System.Text.StringBuilder", "mscorlib")).Return(null);
            pageDefinitionTypeRepository.Replay();
            PageTypeDefinitionPropertiesValidator propertiesValidator =
                new PageTypeDefinitionPropertiesValidator(new PageDefinitionTypeMapper(pageDefinitionTypeRepository, new NativePageDefinitionsMap()));


            Exception exception = Record.Exception(() =>
            {
                propertiesValidator.ValidatePageTypePropertyType(propertyInfo);
            });

            Assert.NotNull(exception);
            Assert.Equal <Type>(typeof(UnmappablePropertyTypeException), exception.GetType());
        }
        public virtual IEnumerable <PageTypePropertyDefinition> GetPageTypePropertyDefinitions(IPageType pageType, Type pageTypeType)
        {
            var properties = pageTypeType.GetPageTypePropertiesOnClass();

            List <PageTypePropertyDefinition> pageTypePropertyDefinitions = new List <PageTypePropertyDefinition>();

            foreach (PropertyInfo property in properties)
            {
                PageTypePropertyAttribute attribute = GetPageTypePropertyAttribute(property);

                if (attribute == null)
                {
                    continue;
                }

                pageTypePropertyDefinitions.Add(new PageTypePropertyDefinition(property.Name, property.PropertyType, pageType, attribute));
            }

            // add all page type group property definitions
            properties = pageTypeType.GetPageTypePropertyGroupProperties();

            foreach (PropertyInfo property in properties.Where(property => property.PropertyType.BaseType == typeof(PageTypePropertyGroup)))
            {
                PageTypePropertyGroupAttribute    pageTypePropertyGroupAttribute = GetPropertyAttribute <PageTypePropertyGroupAttribute>(property);
                List <PageTypePropertyDefinition> definitions = GetPropertyGroupPropertyDefinitions(pageType, property).ToList();


                for (int i = 0; i < definitions.Count; i++)
                {
                    definitions[i].PageTypePropertyAttribute.Tab = pageTypePropertyGroupAttribute.Tab;
                }

                pageTypePropertyDefinitions.AddRange(definitions);
            }

            return(pageTypePropertyDefinitions);
        }
Пример #31
0
        protected virtual void UpdatePageDefinitionValues(PageDefinition pageDefinition, PageTypePropertyDefinition pageTypePropertyDefinition)
        {
            pageDefinition.Name = pageTypePropertyDefinition.Name;

            PageTypePropertyAttribute propertyAttribute = pageTypePropertyDefinition.PageTypePropertyAttribute;

            var specifiedType = GetPageDefinitionType(pageTypePropertyDefinition);
            var currentType   = pageDefinition.Type;

            if (specifiedType.DataType == currentType.DataType)
            {
                pageDefinition.Type = specifiedType;
            }

            if (CanModifyProperty(pageDefinition, propertyAttribute.EditCaptionSet))
            {
                pageDefinition.EditCaption = pageTypePropertyDefinition.GetEditCaptionOrName();
            }
            else if (!propertyAttribute.EditCaptionSet && string.IsNullOrEmpty(pageDefinition.EditCaption))
            {
                pageDefinition.EditCaption = pageTypePropertyDefinition.GetEditCaptionOrName();
            }

            if (CanModifyProperty(pageDefinition, propertyAttribute.HelpTextSet))
            {
                pageDefinition.HelpText = propertyAttribute.HelpText ?? string.Empty;
            }

            if (CanModifyProperty(pageDefinition, propertyAttribute.RequiredSet))
            {
                pageDefinition.Required = propertyAttribute.Required;
            }

            if (CanModifyProperty(pageDefinition, propertyAttribute.SearchableSet))
            {
                pageDefinition.Searchable = propertyAttribute.Searchable;
            }

            if (CanModifyProperty(pageDefinition, propertyAttribute.DefaultValueSet))
            {
                pageDefinition.DefaultValue = propertyAttribute.DefaultValue != null?propertyAttribute.DefaultValue.ToString() : string.Empty;
            }

            if (CanModifyProperty(pageDefinition, propertyAttribute.DefaultValueTypeSet))
            {
                pageDefinition.DefaultValueType = propertyAttribute.DefaultValueType;
            }

            if (CanModifyProperty(pageDefinition, propertyAttribute.UniqueValuePerLanguageSet))
            {
                pageDefinition.LanguageSpecific = propertyAttribute.UniqueValuePerLanguage;
            }

            if (CanModifyProperty(pageDefinition, propertyAttribute.DisplayInEditModeSet))
            {
                pageDefinition.DisplayEditUI = propertyAttribute.DisplayInEditMode;
            }

            if (CanModifyProperty(pageDefinition, propertyAttribute.SortOrderSet))
            {
                pageDefinition.FieldOrder = GetFieldOrder(pageDefinition, propertyAttribute);
            }

            if (CanModifyProperty(pageDefinition, propertyAttribute.TabSet))
            {
                UpdatePageDefinitionTab(pageDefinition, propertyAttribute);
            }
        }
Пример #32
0
        protected virtual void UpdatePageDefinitionTab(PageDefinition pageDefinition, PageTypePropertyAttribute propertyAttribute)
        {
            var tab = tabDefinitionRepository.List().First();

            if (propertyAttribute.Tab != null)
            {
                Tab definedTab = (Tab)Activator.CreateInstance(propertyAttribute.Tab);
                tab = tabDefinitionRepository.GetTabDefinition(definedTab.Name);
            }
            pageDefinition.Tab = tab;
        }
 private void UpdateLongStringSettings(PageDefinition pageDefinition, PageTypePropertyAttribute propertyAttribute)
 {
     EditorToolOption longStringSettings = propertyAttribute.LongStringSettings;
     if (longStringSettings == default(EditorToolOption) && !propertyAttribute.ClearAllLongStringSettings)
     {
         longStringSettings = EditorToolOption.All;
     }
     pageDefinition.LongStringSettings = longStringSettings;
 }
 protected internal virtual void UpdatePageDefinitionTab(PageDefinition pageDefinition, PageTypePropertyAttribute propertyAttribute)
 {
     TabDefinition tab = _tabFactory.List().First();
     if (propertyAttribute.Tab != null)
     {
         Tab definedTab = (Tab) Activator.CreateInstance(propertyAttribute.Tab);
         tab = _tabFactory.GetTabDefinition(definedTab.Name);
     }
     pageDefinition.Tab = tab;
 }
 protected virtual int GetFieldOrder(PageDefinition pageDefinition, PageTypePropertyAttribute propertyAttribute)
 {
     int fieldOrder = propertyAttribute.SortOrder;
     if(fieldOrder == PageTypePropertyAttribute.SortOrderNoValue)
     {
         fieldOrder = 0;
         if(pageDefinition.FieldOrder != 0)
         {
             fieldOrder = pageDefinition.FieldOrder;
         }
     }
     return fieldOrder;
 }
        protected internal virtual void ValidatePageTypePropertyAttribute(PropertyInfo propertyInfo)
        {
            PageTypePropertyAttribute propertyAttribute = propertyInfo.GetCustomAttributes <PageTypePropertyAttribute>().First();

            ValidatePageTypeAttributeTabProperty(propertyInfo, propertyAttribute);
        }
        protected internal virtual void ValidatePageTypeAttributeTabProperty(PropertyInfo propertyInfo, PageTypePropertyAttribute attribute)
        {
            if (attribute.Tab == null)
            {
                return;
            }

            if (!typeof(Tab).IsAssignableFrom(attribute.Tab))
            {
                string errorMessage =
                    "{0} in {1} has a {2} with Tab property set to type that does not inherit from {3}.";
                errorMessage = string.Format(CultureInfo.InvariantCulture, errorMessage, propertyInfo.Name,
                                             propertyInfo.DeclaringType.Name, typeof(PageTypePropertyAttribute).Name,
                                             typeof(Tab));
                throw new PageTypeBuilderException(errorMessage);
            }

            if (attribute.Tab.IsAbstract)
            {
                string errorMessage =
                    "{0} in {1} has a {2} with Tab property set to a type that is abstract.";
                errorMessage = string.Format(CultureInfo.InvariantCulture, errorMessage, propertyInfo.Name,
                                             propertyInfo.DeclaringType.Name, typeof(PageTypePropertyAttribute).Name);
                throw new PageTypeBuilderException(errorMessage);
            }
        }