示例#1
0
        /// <summary>
        /// Gets the filter properties.
        /// </summary>
        /// <param name="context">The entity analysis context.</param>
        /// <returns>The filter properties.</returns>
        public virtual IList<PropertyInfo> GetProperties(EntityAnalysisContext context)
        {
            var filterProperties = new List<PropertyInfo>();

            // Find filter columns by FilterAttribute
            var allProperties = context.EntityType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            foreach (var property in allProperties)
            {
                if (property.GetCustomAttribute<FilterAttribute>() != null)
                {
                    filterProperties.Add(property);
                }
            }
            if (filterProperties.Count > 0)
            {
                return filterProperties;
            }

            // Find filter columns by characteristic
            string[] filterCharacteristic = new string[] { "Name", "Code" };
            var properties = EntityAnalysisHelper.GetCharacteristicPropertyInfo(context.EntityType, filterCharacteristic);

            foreach (var character in filterCharacteristic)
            {
                PropertyInfo property;
                if (properties.TryGetValue(character, out property))
                {
                    filterProperties.Add(property);
                }
            }

            return filterProperties;
        }
        /// <summary>
        /// Configure the specific property hidden value.
        /// * If the column name is "{EntityName}Id"
        /// * And this is self increment field.
        /// * Set the hidden as true.
        /// </summary>
        /// <param name="context"></param>
        public void Apply(EntityAnalysisContext context, DisplayPropertyInfo property)
        {
            if (EntityAnalysisHelper.IsCharacteristicProperty(context.EntityType,
                context.PropertyInfo,
                "id"))
            {
                property.IsHidden = true;
                return;
            }

            // TODO: refatory it as a plugin
            var databaseGeneratedAttribute = context.PropertyInfo.GetCustomAttribute<DatabaseGeneratedAttribute>();
            if (databaseGeneratedAttribute != null
                && databaseGeneratedAttribute.DatabaseGeneratedOption == DatabaseGeneratedOption.Identity)
            {
                property.IsHidden = true;
                return;
            }

            var timestampAttribute = context.PropertyInfo.GetCustomAttribute<TimestampAttribute>();
            if (timestampAttribute != null)
            {
                property.IsHidden = true;
                return;
            }
        }
示例#3
0
        /// <summary>
        /// Gets the default value for specific property.
        /// </summary>
        /// <param name="context">The entity analysis context.</param>
        /// <returns>The default value. If there is no default value, return null.</returns>
        public object GetDefaultValue(EntityAnalysisContext context)
        {
            //TODO support localization
            var defaultValueAttribute = context.PropertyInfo.GetCustomAttribute<DefaultValueAttribute>();
            if (defaultValueAttribute == null) return null;

            return defaultValueAttribute.Value;
        }
示例#4
0
        /// <summary>
        /// Gets the entity name.
        /// </summary>
        /// <param name="context">The entity analysis context.</param>
        /// <returns>The display entity name.</returns>
        public virtual String GetName(EntityAnalysisContext context)
        {
            Context = context;

            var modelAttribute = context.EntityType.GetCustomAttribute<ModelAttribute>();
            var name = GetEntityName(context.EntityType, modelAttribute);

            return name;
        }
示例#5
0
 /// <summary>
 /// Configure the specific property hidden value.
 /// * If the column name is "{EntityName}Id"
 /// * And this is self increment field.
 /// * Set the hidden as true.
 /// </summary>
 /// <param name="context"></param>
 public void Apply(EntityAnalysisContext context, DisplayPropertyInfo property)
 {
     string[] dateTypeColumnSuffixes = new string[] { "Date", "Day" };
     foreach (var suffix in dateTypeColumnSuffixes)
     {
         if (context.PropertyInfo.Name.EndsWith(suffix, StringComparison.OrdinalIgnoreCase))
         {
             property.LogicalDataType = LogicalDataType.Date;
             return;
         }
     }
 }
示例#6
0
        /// <summary>
        /// Gets format string for specific property.
        /// </summary>
        /// <param name="context">The entity analysis context.</param>
        /// <returns>The format string.</returns>
        public string GetFormatString(EntityAnalysisContext context)
        {
            string displayFormat = null;

            // Find sort columns from DisplayColumnAttributes
            var displayFormatAttribue = context.PropertyInfo.GetCustomAttribute<DisplayFormatAttribute>();
            if (displayFormatAttribue != null)
            {
                return displayFormatAttribue.DataFormatString;
            }

            return displayFormat;
        }
        public void Apply(EntityAnalysisContext context, DisplayPropertyInfo property)
        {
            var propertyName = property.PropertyName;
            int underscorePosition = propertyName.LastIndexOf('_');
            if (underscorePosition <= 0) return;

            var prefix = propertyName.Substring(0, underscorePosition);
            var suffix = propertyName.Substring(underscorePosition + 1);
            LogicalDependencyProperty logicalDependencyProperty;
            if (string.Equals(suffix, 
                                LogicalDependencyProperty.IsEnabled.ToString(),
                                StringComparison.OrdinalIgnoreCase))
            {
                logicalDependencyProperty = LogicalDependencyProperty.IsEnabled;
            }
            else if (string.Equals(suffix,
                                LogicalDependencyProperty.IsVisible.ToString(),
                                StringComparison.OrdinalIgnoreCase))
            {
                logicalDependencyProperty = LogicalDependencyProperty.IsReadOnly;
            }
            else if (string.Equals(suffix,
                                LogicalDependencyProperty.IsReadOnly.ToString(),
                                StringComparison.OrdinalIgnoreCase))
            {
                logicalDependencyProperty = LogicalDependencyProperty.IsReadOnly;
            }
            else
            {
                return;
            }

            
            var findProperty = context.EntityType.GetProperties(BindingFlags.Instance | BindingFlags.Public)
                .First<PropertyInfo>(
                    (p) => string.Equals(p.Name, prefix, StringComparison.OrdinalIgnoreCase));
            if (findProperty != null)
            {
                property.DependencyHostPropertyName = findProperty.Name;
                property.LogicalDependencyProperty = logicalDependencyProperty;
                property.IsDependencyProperty = true;
            }
        }
示例#8
0
        /// <summary>
        /// Gets the sort properties.
        /// </summary>
        /// <param name="context">The entity analysis context.</param>
        /// <returns>The sort properties.</returns>
        public virtual IList<SortPropertyInfo> GetProperties(EntityAnalysisContext context)
        {
            IList<SortPropertyInfo> sortProperties = new List<SortPropertyInfo>();

            // Find sort columns from DisplayColumnAttributes
            var displayColumnAttribute = context.EntityType.GetCustomAttribute<DisplayColumnAttribute>();
            if (displayColumnAttribute != null)
            {
                PropertyInfo sortProperty = context.EntityType.GetProperty(displayColumnAttribute.SortColumn);
                if (sortProperty != null)
                {
                    sortProperties.Add(new SortPropertyInfo
                    {
                        PropertyInfo = sortProperty,
                        SortDescending = displayColumnAttribute.SortDescending
                    });

                    // Return
                    return sortProperties;
                }
            }

            // Find sort columns by characteristic
            string[] sortCharacteristic = new string[] { "Order", "Name", "Code", "Id" };
            var properties = EntityAnalysisHelper.GetCharacteristicPropertyInfo(context.EntityType, sortCharacteristic);

            foreach (var character in sortCharacteristic)
            {
                PropertyInfo property;
                if (properties.TryGetValue(character, out property))
                {
                    sortProperties.Add(new SortPropertyInfo
                    {
                        PropertyInfo = property,
                    });
                }
            }

            return sortProperties;
        }
示例#9
0
        /// <summary>
        /// Gets the reference columns.
        /// </summary>
        /// <param name="context">The entity analysis context.</param>
        /// <returns>The reference columns.</returns>
        public virtual IList<PropertyInfo> GetProperties(EntityAnalysisContext context)
        {
            var displayProperties = new List<PropertyInfo>();

            // Find sort columns from DisplayColumnAttributes
            var displayColumnAttribute = context.EntityType.GetCustomAttribute<DisplayColumnAttribute>();
            if (displayColumnAttribute != null)
            {
                string[] displayColumns = displayColumnAttribute.DisplayColumn.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var column in displayColumns)
                {
                    var columnName = column.Trim();
                    PropertyInfo displayProperty = context.EntityType.GetProperty(columnName);
                    Debug.Assert(displayProperty != null);
                    displayProperties.Add(displayProperty);
                }

                if (displayProperties.Count > 0)
                {
                    // Return
                    return displayProperties;
                }
            }

            // Find display columns by characteristic
            string[] displayCharacteristic = new string[] { "Code", "Name" };
            var properties = EntityAnalysisHelper.GetCharacteristicPropertyInfo(context.EntityType, displayCharacteristic);

            foreach (var character in displayCharacteristic)
            {
                PropertyInfo property;
                if (properties.TryGetValue(character, out property))
                {
                    displayProperties.Add(property);
                }
            }

            return displayProperties;
        }