Ejemplo n.º 1
0
 public EntityPropertyFindContext(string path, T token, IEntityPropertyMetadata property, IEnumerable <IEntityMetadata> ancestors)
 {
     this.Path      = path;
     this.Token     = token;
     this.Property  = property;
     this.Ancestors = ancestors ?? System.Linq.Enumerable.Empty <IEntityMetadata>();
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     属性编辑器。
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="propertyMetadata">实体属性原始数据。</param>
        /// <param name="entityDto">实体数据传输对象。</param>
        /// <returns></returns>
        public static MvcHtmlString PropertyEditor(this HtmlHelper helper, IEntityPropertyMetadata propertyMetadata,
                                                   object entityDto)
        {
            if (helper == null)
            {
                throw new ArgumentNullException(nameof(helper));
            }
            if (propertyMetadata == null)
            {
                throw new ArgumentNullException(nameof(propertyMetadata));
            }
            if (entityDto == null)
            {
                throw new ArgumentNullException(nameof(entityDto));
            }

            var model = new PropertyEditModel(propertyMetadata, entityDto);

            if (propertyMetadata.DataType == DataType.CustomDataType)
            {
                return(helper.Partial(propertyMetadata.PartialViewPath + propertyMetadata.CustomDataType + "Editor",
                                      model));
            }

            return(helper.Partial(propertyMetadata.PartialViewPath + propertyMetadata.DataType + "Editor", model));
        }
Ejemplo n.º 3
0
 public ReduceContext(string path, ISource source, IEntityPropertyMetadata property, IEnumerable <IEntityMetadata> ancestors)
 {
     this.Path      = path;
     this.Source    = source;
     this.Property  = property;
     this.Ancestors = ancestors ?? System.Linq.Enumerable.Empty <IEntityMetadata>();
 }
Ejemplo n.º 4
0
        /// <summary>
        ///     更新属性。
        /// </summary>
        /// <param name="targetEntity">目标实体。</param>
        /// <param name="sourceEntity">源实体。</param>
        /// <param name="metadata">属性元数据。</param>
        /// <returns></returns>
        public virtual Task <bool> UpdateProperty(TEntity targetEntity, TEntity sourceEntity,
                                                  IEntityPropertyMetadata metadata)
        {
            var entityProperty = typeof(TEntity).GetProperty(metadata.PropertyName);

            entityProperty.SetValue(targetEntity, entityProperty.GetValue(sourceEntity));
            return(Task.FromResult(true));
        }
Ejemplo n.º 5
0
 /// <summary>
 ///     应用属性元数据感知属性。
 /// </summary>
 /// <param name="attributes"></param>
 /// <param name="metadata"></param>
 protected virtual void ApplyPropertyMetadataAwareAttributes(IEnumerable <Attribute> attributes,
                                                             IEntityPropertyMetadata metadata)
 {
     foreach (var attribute in attributes.OfType <IPropertyMetadataAware>())
     {
         attribute.OnPropertyMetadataCreating(metadata);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        ///		<para>查找属性集合中指定成员路径对应的属性。</para>
        ///		<para>注:查找范围包括父实体的属性集。</para>
        /// </summary>
        /// <param name="properties">指定要查找的属性集合。</param>
        /// <param name="path">指定要查找的成员路径,支持多级导航属性路径。</param>
        /// <param name="match">属性匹配成功后的回调函数。</param>
        /// <returns>返回找到的属性,如果没有指定指定成员路径的属性则返回空(null)。</returns>
        public static EntityPropertyFindResult <T> Find <T>(this IEntityPropertyMetadataCollection properties, string path, T token, Func <EntityPropertyFindContext <T>, T> match = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(EntityPropertyFindResult <T> .Failure(token));
            }

            Queue <IEntityMetadata> ancestors = null;
            IEntityPropertyMetadata property  = null;
            var parts = path.Split('.');

            for (int i = 0; i < parts.Length; i++)
            {
                if (properties == null)
                {
                    return(EntityPropertyFindResult <T> .Failure(token));
                }

                //如果当前属性集合中不包含指定的属性,则尝试从父实体中查找
                if (!properties.TryGet(parts[i], out property))
                {
                    //尝试从父实体中查找指定的属性
                    property = FindBaseProperty(ref properties, parts[i], ref ancestors);

                    //如果父实体中也不含指定的属性则返回失败
                    if (property == null)
                    {
                        return(EntityPropertyFindResult <T> .Failure(token));
                    }
                }

                //如果回调函数不为空,则调用匹配回调函数
                //注意:将回调函数返回的结果作为下一次的用户数据保存起来
                if (match != null)
                {
                    token = match(new EntityPropertyFindContext <T>(string.Join(".", parts, 0, i), token, property, ancestors));
                }

                //清空继承实体链
                if (ancestors != null)
                {
                    ancestors.Clear();
                }

                if (property.IsSimplex)
                {
                    break;
                }
                else
                {
                    properties = GetAssociatedProperties((IEntityComplexPropertyMetadata)property, ref ancestors);
                }
            }

            //返回查找到的结果
            return(new EntityPropertyFindResult <T>(token, property));
        }
Ejemplo n.º 7
0
        public void OnPropertyMetadataCreating(IEntityPropertyMetadata runtimeProperty)
        {
            if (runtimeProperty == null)
            {
                throw new ArgumentNullException(nameof(runtimeProperty));
            }

            runtimeProperty.Roles = Roles;
            runtimeProperty.Users = Users;
        }
Ejemplo n.º 8
0
 /// <summary>
 ///     将设置复制到实体元数据对象中。
 /// </summary>
 /// <param name="runtimeProperty">实体元数据</param>
 public void OnPropertyMetadataCreating(IEntityPropertyMetadata runtimeProperty)
 {
     if (runtimeProperty == null)
     {
         throw new ArgumentNullException(nameof(runtimeProperty));
     }
     runtimeProperty.DataType        = DataType;
     runtimeProperty.CustomDataType  = CustomDataType;
     runtimeProperty.PartialViewPath = PartialViewPath;
 }
Ejemplo n.º 9
0
        public void OnPropertyMetadataCreating(IEntityPropertyMetadata runtimeProperty)
        {
            if (runtimeProperty == null)
            {
                throw new ArgumentNullException(nameof(runtimeProperty));
            }

            runtimeProperty.Step = this.Step;
            runtimeProperty.Max  = this.Max;
            runtimeProperty.Min  = this.Min;
        }
Ejemplo n.º 10
0
        public FieldIdentifier CreateField(IEntityPropertyMetadata property)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            return(new FieldIdentifier(this, property.GetFieldName(out var alias), alias)
            {
                Token = new EntityPropertyToken(property)
            });
Ejemplo n.º 11
0
 public void OnPropertyMetadataCreating(IEntityPropertyMetadata runtimeProperty)
 {
     if (runtimeProperty == null)
     {
         throw new ArgumentNullException(nameof(runtimeProperty));
     }
     runtimeProperty.IsHiddenOnCreate = IsHiddenOnCreate;
     runtimeProperty.IsHiddenOnDetail = IsHiddenOnDetail;
     runtimeProperty.IsHiddenOnView   = IsHiddenOnView;
     runtimeProperty.IsHiddenOnEdit   = IsHiddenOnEdit;
 }
Ejemplo n.º 12
0
 /// <summary>
 ///     将设置复制到实体元数据对象中。
 /// </summary>
 /// <param name="runtimeProperty">实体元数据</param>
 public void OnPropertyMetadataCreating(IEntityPropertyMetadata runtimeProperty)
 {
     if (runtimeProperty == null)
     {
         throw new ArgumentNullException(nameof(runtimeProperty));
     }
     runtimeProperty.Width             = Width;
     runtimeProperty.Align             = Align;
     runtimeProperty.FormatterScript   = FormatterScript;
     runtimeProperty.UnFormatterScript = UnFormatterScript;
     runtimeProperty.Sortable          = Sortable;
     runtimeProperty.CssClass          = CssClass;
 }
Ejemplo n.º 13
0
        private void UpdateForeign()
        {
            var index = this.Role.IndexOf(':');

            if (index < 0)
            {
                _foreign = this.Entity.Metadata.Manager.Entities.Get(this.Role);
            }
            else
            {
                _foreign         = this.Entity.Metadata.Manager.Entities.Get(this.Role.Substring(0, index));
                _foreignProperty = _foreign.Properties.Get(this.Role.Substring(index + 1));
            }
        }
Ejemplo n.º 14
0
 public void SetRuntimeProperty(IEntityPropertyMetadata runtimeProperty)
 {
     if (runtimeProperty == null)
     {
         throw new ArgumentNullException(nameof(runtimeProperty));
     }
     runtimeProperty.Width             = Width;
     runtimeProperty.Align             = Align;
     runtimeProperty.FormatterScript   = FormatterScript;
     runtimeProperty.UnFormatterScript = UnFormatterScript;
     runtimeProperty.Sortable          = Sortable;
     runtimeProperty.CssClass          = CssClass;
     runtimeProperty.ColModelIndex     = Index;
     runtimeProperty.ColModelName      = Name;
     runtimeProperty.Hidden            = Hidden;
 }
Ejemplo n.º 15
0
        /// <summary>
        ///     生成供页面Jqgrid初始化使用的ColModel信息。
        ///     返回租户可查看实体的属性信息,即实体属性元数据中IsHiddenOnView=true的属性。
        /// </summary>
        /// <returns></returns>
        public virtual string GetColModel()
        {
            var sb = new StringBuilder();

            sb.Append("[");
            IEntityPropertyMetadata item = null;
            var viewProMetadatas         = EntityMetadata.ViewPropertyMetadatas;
            var length = viewProMetadatas.Length;

            for (var i = 0; i < length; i++)
            {
                item = viewProMetadatas[i];
                sb.Append("{");

                sb.Append($"name:'{item.PropertyInfo.Name}'" +
                          $",index:'{item.PropertyInfo.Name}'" +
                          $",width: {item.Width}" +
                          $",align: '{item.Align.ToString().ToLower()}'" +
                          $",sortable: {item.Sortable.ToString().ToLower()}");
                if (item.IsKey)
                {
                    sb.Append(",hidedlg: true,key: true");
                }
                if (!string.IsNullOrWhiteSpace(item.CssClass))
                {
                    sb.Append($",classes: '{item.CssClass}'");
                }
                if (!string.IsNullOrWhiteSpace(item.FormatterScript))
                {
                    sb.Append($",formatter: {item.FormatterScript}");
                }
                if (!string.IsNullOrWhiteSpace(item.UnFormatterScript))
                {
                    sb.Append($",unformatter: {item.UnFormatterScript}");
                }

                sb.Append("}");
                if (i != length - 1)
                {
                    sb.Append(",");
                }
            }
            sb.Append("]");
            return(sb.ToString());
        }
        /// <summary>
        /// 获取指定实体属性对应的字段名以及返回的别名。
        /// </summary>
        /// <param name="property">当前的实体属性。</param>
        /// <param name="alias">输出参数,对应的返回别名。详细说明请参考该方法的备注说明。</param>
        /// <returns>当前属性对应的字段名。</returns>
        /// <remarks>
        ///		<para>注意:如果当前实体属性的字段名不同于属性名,则<paramref name="alias"/>输出参数值即为属性名,必须确保查询返回的字段标识都为对应的属性名,以便后续实体组装时进行字段与属性的匹配。</para>
        /// </remarks>
        public static string GetFieldName(this IEntityPropertyMetadata property, out string alias)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            if (string.IsNullOrEmpty(property.Alias))
            {
                alias = null;
                return(property.Name);
            }
            else
            {
                alias = property.Name;
                return(property.Alias);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        ///     获取ColNames.
        /// </summary>
        /// <returns></returns>
        public virtual string GetColNames()
        {
            var sb = new StringBuilder();

            sb.Append("[");
            IEntityPropertyMetadata item = null;
            var length = EntityMetadata.ViewPropertyMetadatas.Length;

            for (var i = 0; i < length; i++)
            {
                item = EntityMetadata.ViewPropertyMetadatas[i];
                sb.Append($"'{item.DisplayName}'");
                if (i != length - 1)
                {
                    sb.Append(",");
                }
            }
            sb.Append("]");
            return(sb.ToString());
        }
Ejemplo n.º 18
0
 public EntityPropertyFindResult(T token, IEntityPropertyMetadata property)
 {
     this.Token    = token;
     this.Property = property;
 }
Ejemplo n.º 19
0
 /// <summary>
 ///     初始化一个<see cref="PropertyViewModel"/>对象。
 /// </summary>
 /// <param name="propertyMetadata">实体属性元数据。</param>
 /// <param name="entityDto">数据传输对象。</param>
 public PropertyViewModel(IEntityPropertyMetadata propertyMetadata, object entityDto)
 {
     this.EntityProperty = propertyMetadata;
     this.EntityDto      = entityDto;
 }
Ejemplo n.º 20
0
 public FieldIdentifier CreateField(IEntityPropertyMetadata property)
 {
     return(new FieldIdentifier(this, property.GetFieldName(out var alias), alias)
     {
         Token = new EntityPropertyToken(property)
     });
Ejemplo n.º 21
0
 internal SchemaMember(IEntityPropertyMetadata property, IEnumerable <IEntityMetadata> ancestors = null)
 {
     this.Token     = new EntityPropertyToken(property);
     this.Ancestors = ancestors;
 }
Ejemplo n.º 22
0
        /// <summary>
        ///		<para>从指定的表标识对应的实体开始进行路径展开。</para>
        ///		<para>注:展开过程包括对父实体的属性集的搜索。</para>
        /// </summary>
        /// <param name="table">指定的进行展开的起点。</param>
        /// <param name="path">指定要展开的成员路径,支持多级导航属性路径。</param>
        /// <param name="step">指定路径中每个属性的展开回调函数。</param>
        /// <returns>返回找到的结果。</returns>
        public static ReduceResult Reduce(this TableIdentifier table, string path, Func <ReduceContext, ISource> step = null)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            if (table.Entity == null)
            {
                throw new DataException($"The '{table}' table cannot be expanded.");
            }

            if (string.IsNullOrEmpty(path))
            {
                return(ReduceResult.Failure(table));
            }

            ICollection <IEntityMetadata> ancestors = null;
            IEntityPropertyMetadata       property  = null;
            ISource token      = table;
            var     parts      = path.Split('.');
            var     properties = table.Entity.Properties;

            for (int i = 0; i < parts.Length; i++)
            {
                if (properties == null)
                {
                    return(ReduceResult.Failure(token));
                }

                //如果当前属性集合中不包含指定的属性,则尝试从父实体中查找
                if (!properties.TryGet(parts[i], out property))
                {
                    //尝试从父实体中查找指定的属性
                    property = FindBaseProperty(ref properties, parts[i], ref ancestors);

                    //如果父实体中也不含指定的属性则返回失败
                    if (property == null)
                    {
                        return(ReduceResult.Failure(token));
                    }
                }

                //如果回调函数不为空,则调用匹配回调函数
                //注意:将回调函数返回的结果作为下一次的用户数据保存起来
                if (step != null)
                {
                    token = step(new ReduceContext(string.Join(".", parts, 0, i), token, property, ancestors));
                }

                //清空继承实体链
                if (ancestors != null)
                {
                    ancestors.Clear();
                }

                if (property.IsSimplex)
                {
                    break;
                }
                else
                {
                    properties = GetAssociatedProperties((IEntityComplexPropertyMetadata)property, ref ancestors);
                }
            }

            //返回查找到的结果
            return(new ReduceResult(token, property));
        }
Ejemplo n.º 23
0
 public ReduceResult(ISource source, IEntityPropertyMetadata property)
 {
     this.Source   = source;
     this.Property = property;
 }
Ejemplo n.º 24
0
 public static ISource From(this IStatement statement, string memberPath, out IEntityPropertyMetadata property)
 {
     return(From(statement, statement.Table, memberPath, out property));
 }
Ejemplo n.º 25
0
 /// <summary>
 ///     初始化一个<see cref="PropertyEditModel" />对象。
 /// </summary>
 /// <param name="propertyMetadata">实体属性元数据。</param>
 /// <param name="entityDto">数据传输对象。</param>
 public PropertyEditModel(IEntityPropertyMetadata propertyMetadata, object entityDto)
 {
     EntityProperty = propertyMetadata;
     EntityDto      = entityDto;
 }
Ejemplo n.º 26
0
        public static ISource From(this IStatement statement, TableIdentifier origin, string memberPath, out IEntityPropertyMetadata property)
        {
            var found = origin.Reduce(memberPath, ctx =>
            {
                var source = ctx.Source;

                if (ctx.Ancestors != null)
                {
                    foreach (var ancestor in ctx.Ancestors)
                    {
                        source = statement.Join(source, ancestor, ctx.Path);
                    }
                }

                if (ctx.Property.IsComplex)
                {
                    var complex = (IEntityComplexPropertyMetadata)ctx.Property;

                    if (complex.Multiplicity == AssociationMultiplicity.Many)
                    {
                        throw new DataException($"The specified '{ctx.FullPath}' member is a one-to-many composite(navigation) property that cannot appear in the sorting and condition clauses.");
                    }

                    source = statement.Join(source, complex, ctx.FullPath);
                }

                return(source);
            });

            if (found.IsFailed)
            {
                throw new DataException($"The specified '{memberPath}' member does not exist in the '{origin.Entity?.Name}' entity and it's inherits.");
            }

            //输出找到的属性元素
            property = found.Property;

            //返回找到的源
            return(found.Source);
        }
Ejemplo n.º 27
0
 public EntityPropertyToken(IEntityPropertyMetadata property, MemberInfo member = null)
 {
     this.Property = property;
     this.Member   = member;
 }