Beispiel #1
0
        /// <summary>
        /// 根据前台传递的参数,对"字典"数据进行分页,搜索
        /// </summary>
        /// <param name="pageNumber">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="number">返回的total总数</param>
        /// <param name="sort">排序字段</param>
        /// <param name="sortOrder">排序标识asc或desc</param>
        /// <param name="search">搜索的字符串</param>
        /// <returns></returns>
        public List <T_Sys_Dict> GetDictPages(int pageNumber, int pageSize, out long number, string sort = null, string sortOrder = null, string search = null)
        {
            //List < T_Sys_Dict > dicts =dao.GetPageList<T_Sys_Dict>(pageNumber,pageSize,out number).ToList();
            //创建谓词
            IFieldPredicate predicate = null;

            if (!string.IsNullOrEmpty(search))
            {
                predicate = Predicates.Field <T_Sys_Dict>(f => f.DICT_NAME, Operator.Like, "%" + search + "%");
            }
            IList <ISort> sorts = new List <ISort>();

            //创建排序
            if (sort == null)
            {
                sorts.Add(new Sort {
                    PropertyName = "DICT_CODE", Ascending = sortOrder == "asc" ? true : false
                });
            }
            else
            {
                sorts.Add(new Sort {
                    PropertyName = sort, Ascending = sortOrder == "asc"?true:false
                });
            }
            List <T_Sys_Dict> dicts = dao.GetPageList <T_Sys_Dict>(pageNumber, pageSize, out number, predicate, sorts).ToList();

            return(dicts);
        }
Beispiel #2
0
        private string GetSql(IFieldPredicate predicate, IDictionary <string, object> parameters)
        {
            var columnName = _sqlBuilder.GetColumnName(predicate.EntityType, predicate.PropertyName, false);

            if (predicate.Value == null)
            {
                return($"({columnName} IS {(predicate.Negate ? "NOT " : string.Empty)}NULL)");
            }

            if (predicate.Value is IEnumerable enumerable && !(enumerable is string))
            {
                if (predicate.Operator != Operator.Eq)
                {
                    throw new ArgumentException("Operator must be set to Eq for Enumerable types");
                }

                var @params = new List <string>();
                foreach (var value in enumerable)
                {
                    var valueParameterName = parameters.SetParameterName(predicate.PropertyName, value, _sqlBuilder.Dialect.ParameterPrefix);
                    @params.Add(valueParameterName);
                }

                var paramStrings = @params.Aggregate(new StringBuilder(), (sb, s) => sb.Append((sb.Length != 0 ? ", " : string.Empty) + s), sb => sb.ToString());
                return($"({columnName} {(predicate.Negate ? "NOT " : string.Empty)}IN ({paramStrings}))");
            }

            var parameterName = parameters.SetParameterName(predicate.PropertyName, predicate.Value, _sqlBuilder.Dialect.ParameterPrefix);

            return($"({columnName} {GetOperatorString(predicate)} {parameterName})");
        }
        private IPredicate GetEntityPredicate(IClassMapper classMap, object entity)
        {
            Type predicateType            = typeof(FieldPredicate <>).MakeGenericType(classMap.EntityType);
            IList <IPredicate> predicates = new List <IPredicate>();

            foreach (KeyValuePair <string, object> kvp in ReflectionHelper.GetObjectValues(entity, classMap.Properties))
            {
                IFieldPredicate fieldPredicate = Activator.CreateInstance(predicateType) as IFieldPredicate;
                if (fieldPredicate == null)
                {
                    throw new NullReferenceException("Unable to create instance of IFieldPredicate");
                }

                fieldPredicate.Not          = false;
                fieldPredicate.Operator     = Operator.Eq;
                fieldPredicate.PropertyName = kvp.Key;
                fieldPredicate.Value        = kvp.Value;
                predicates.Add(fieldPredicate);
            }

            return(predicates.Count == 1
                       ? predicates[0]
                       : new PredicateGroup
            {
                Operator = GroupOperator.And,
                Predicates = predicates
            });
        }
        public StatusValuePair <List <ArchiveEntities> > GetListArchiveElements()
        {
            IFieldPredicate p = Predicates.Field <ArchiveEntities>(f => f.IsArchiveElement, Operator.Eq, true);
            StatusValuePair <List <ArchiveEntities> > result = GetList <ArchiveEntities>(p);

            return(result);
        }
Beispiel #5
0
        public static Expression <Func <T, bool> > Parse(IPredicate predicate)
        {
            IFieldPredicate     fieldPredicate      = (IFieldPredicate)predicate;
            ParameterExpression parameterExpression = Expression.Parameter(typeof(T), "p");
            MemberExpression    memberExpression    = Expression.PropertyOrField(parameterExpression, fieldPredicate.PropertyName);
            UnaryExpression     propertyValue       = Expression.Convert(Expression.Constant(fieldPredicate.Value), memberExpression.Type);

            var operatorMatrix = new Dictionary <KeyValuePair <Operator, bool>, Func <Expression> >
            {
                { new KeyValuePair <Operator, bool>(Operator.Like, false), () => LikeExpression.Like(memberExpression, propertyValue) },
                { new KeyValuePair <Operator, bool>(Operator.Eq, false), () => Expression.Equal(memberExpression, propertyValue) },
                { new KeyValuePair <Operator, bool>(Operator.Gt, false), () => Expression.GreaterThan(memberExpression, propertyValue) },
                { new KeyValuePair <Operator, bool>(Operator.Ge, false), () => Expression.GreaterThanOrEqual(memberExpression, propertyValue) },
                { new KeyValuePair <Operator, bool>(Operator.Lt, false), () => Expression.LessThan(memberExpression, propertyValue) },
                { new KeyValuePair <Operator, bool>(Operator.Le, false), () => Expression.LessThanOrEqual(memberExpression, propertyValue) },
                { new KeyValuePair <Operator, bool>(Operator.Like, true), () => LikeExpression.NotLike(memberExpression, propertyValue) },
                { new KeyValuePair <Operator, bool>(Operator.Eq, true), () => Expression.NotEqual(memberExpression, propertyValue) },
                { new KeyValuePair <Operator, bool>(Operator.Gt, true), () => Expression.LessThan(memberExpression, propertyValue) },
                { new KeyValuePair <Operator, bool>(Operator.Ge, true), () => Expression.LessThanOrEqual(memberExpression, propertyValue) },
                { new KeyValuePair <Operator, bool>(Operator.Lt, true), () => Expression.GreaterThan(memberExpression, propertyValue) },
                { new KeyValuePair <Operator, bool>(Operator.Le, true), () => Expression.GreaterThanOrEqual(memberExpression, propertyValue) },
            };

            var body = operatorMatrix[new KeyValuePair <Operator, bool>(fieldPredicate.Operator, fieldPredicate.Not)].Invoke();

            return(Expression.Lambda <Func <T, bool> >(body, parameterExpression));
        }
Beispiel #6
0
        protected override Expression VisitBinary(BinaryExpression node)
        {
            Expressions.Add(node);

            ExpressionType nt = node.NodeType;

            if (nt == ExpressionType.OrElse || nt == ExpressionType.AndAlso)
            {
                var pg = new PredicateGroup
                {
                    Predicates = new List <IPredicate>(),
                    Operator   = nt == ExpressionType.OrElse ? GroupOperator.Or : GroupOperator.And
                };

                _pg.Predicates.Add(pg);
            }

            Visit(node.Left);

            if (node.Left is MemberExpression)
            {
                IFieldPredicate field = GetLastField();
                field.Operator = DetermineOperator(node);

                if (nt == ExpressionType.NotEqual)
                {
                    field.Not = true;
                }
            }

            Visit(node.Right);

            return(node);
        }
Beispiel #7
0
        protected IPredicate GetEntityPredicate(IClassMapper classMap, object entity)
        {
            Type predicateType               = typeof(FieldPredicate <>).MakeGenericType(classMap.EntityType);
            IList <IPredicate> predicates    = new List <IPredicate>();
            var notIgnoredColumns            = classMap.Properties.Where(p => !p.Ignored);
            IDictionary <string, object> kvp = new Dictionary <string, object>();

            if (entity.GetType() == typeof(IDictionary <string, object>) || entity.GetType() == typeof(Dictionary <string, object>))
            {
                kvp = (IDictionary <string, object>)entity;
            }
            else
            {
                kvp = ReflectionHelper.GetObjectValues(entity);
            }
            foreach (var kv in kvp.Where(property => notIgnoredColumns.Any(c => c.Name.Equals(property.Key, StringComparison.OrdinalIgnoreCase))))
            {
                IFieldPredicate fieldPredicate = Activator.CreateInstance(predicateType) as IFieldPredicate;
                string          keyName        = notIgnoredColumns.FirstOrDefault(s => s.Name.Equals(kv.Key, StringComparison.OrdinalIgnoreCase)).Name;
                fieldPredicate.Not          = false;
                fieldPredicate.Operator     = Operator.Eq;
                fieldPredicate.PropertyName = keyName;
                fieldPredicate.Value        = kv.Value;
                predicates.Add(fieldPredicate);
            }
            return(predicates.Count == 1
                       ? predicates[0]
                       : new PredicateGroup
            {
                Operator = GroupOperator.And,
                Predicates = predicates
            });
        }
Beispiel #8
0
            private IPredicate ParseUnaryNot(UnaryExpression expression)
            {
                if (expression.NodeType != ExpressionType.Not)
                {
                    throw new InvalidOperationException();
                }

                var predicate = this.Parse(expression.Operand);

                return(VisitPredicateTree(predicate, p =>
                {
                    PredicateGroup g = p as PredicateGroup;
                    if (g != null)
                    {
                        g.Operator = g.Operator == GroupOperator.And ? GroupOperator.Or : GroupOperator.And;
                        return true;
                    }

                    IFieldPredicate f = p as IFieldPredicate;
                    if (f != null)
                    {
                        f.Not = !f.Not;
                        return false;
                    }

                    throw new NotImplementedException();
                }));
            }
        public FiatSitecoreSerializationProvider(IPredicate predicate, IFieldPredicate fieldPredicate, IFiatDeserializerLogger logger, string rootPath = null, string logName = "UnicornItemSerialization")
            : base(predicate, rootPath, logName)
        {
            Assert.ArgumentNotNull(logger, "logger");

            _deserializer = new FiatDeserializer(logger, fieldPredicate);
        }
        public FiatRemotedSerializationProvider(IPredicate predicate, IFieldPredicate fieldPredicate, IFiatDeserializerLogger logger, string remoteUrl = null, string rootPath = null, string logName = "UnicornItemSerialization")
            : base(predicate, fieldPredicate, logger, rootPath, logName)
        {
            Assert.ArgumentNotNull(remoteUrl, "remoteUrl");

            RemoteUrl = remoteUrl;
        }
Beispiel #11
0
        protected override Expression VisitConstant(ConstantExpression node)
        {
            IFieldPredicate field = GetCurrentField();

            field.Value = node.Value;
            return(node);
        }
Beispiel #12
0
 public virtual bool Delete(IFieldPredicate predicate)
 {
     using (var con = connectionFactory.Connection)
     {
         return(con.Delete <TModel>(predicate));
     }
 }
Beispiel #13
0
        public StatusValuePair <List <ManyToManyEntities> > SearchRight(long rId)
        {
            IFieldPredicate p = Predicates.Field <ManyToManyEntities>(entity => entity.RightId, Operator.Eq, rId);
            StatusValuePair <List <ManyToManyEntities> > result = this.GetList <ManyToManyEntities>(p);

            return(result);
        }
        public FiatSitecoreSerializationProvider(IPredicate predicate, IFieldPredicate fieldPredicate, IFiatDeserializerLogger logger, string rootPath = null, string logName = "UnicornItemSerialization")
            : base(predicate, rootPath, logName)
        {
            Assert.ArgumentNotNull(logger, "logger");

            _deserializer = new FiatDeserializer(logger, fieldPredicate);
        }
Beispiel #15
0
 public virtual IEnumerable <TModel> GetAll(IFieldPredicate predicate)
 {
     using (var con = connectionFactory.Connection)
     {
         return(con.GetList <TModel>(predicate));
     }
 }
Beispiel #16
0
        /// <summary>
        /// 流程业务记录分页方法
        /// </summary>
        /// <param name="query"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public List <AppFlowEntity> GetPaged(AppFlowQuery query, out int count)
        {
            List <AppFlowEntity> list = null;
            var conn = SessionFactory.CreateConnection();

            try
            {
                var sortList = new List <DapperExtensions.ISort>();
                sortList.Add(new DapperExtensions.Sort {
                    PropertyName = "ID", Ascending = false
                });

                IFieldPredicate predicate = null;
                if (!string.IsNullOrEmpty(query.AppInstanceID))
                {
                    predicate = Predicates.Field <AppFlowEntity>(f => f.AppInstanceID, DapperExtensions.Operator.Eq, query.AppInstanceID);
                }

                count = QuickRepository.Count <AppFlowEntity>(conn, predicate);
                list  = QuickRepository.GetPaged <AppFlowEntity>(conn, query.PageIndex, query.PageSize,
                                                                 predicate, sortList, false).ToList();

                return(list);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
        }
		public FiatRemotedSerializationProvider(IPredicate predicate, IFieldPredicate fieldPredicate, IFiatDeserializerLogger logger, string remoteUrl = null, string rootPath = null, string logName = "UnicornItemSerialization")
			: base(predicate, fieldPredicate, logger, rootPath, logName)
		{
			Assert.ArgumentNotNull(remoteUrl, "remoteUrl");

			RemoteUrl = remoteUrl;
		}
Beispiel #18
0
        public FiatSitecoreSerializationFormatter(IFiatFormatterLogger logger, IFieldPredicate fieldPredicate)
        {
            Assert.ArgumentNotNull(logger, "logger");
            Assert.ArgumentNotNull(fieldPredicate, "fieldPredicate");

            _logger         = logger;
            _fieldPredicate = fieldPredicate;
        }
Beispiel #19
0
        public SerializedAsMasterEvaluator(ISerializedAsMasterEvaluatorLogger logger, IFieldPredicate fieldPredicate)
        {
            Assert.ArgumentNotNull(logger, "logger");
            Assert.ArgumentNotNull(fieldPredicate, "fieldPredicate");

            _logger         = logger;
            _fieldPredicate = fieldPredicate;
        }
Beispiel #20
0
        public FiatDeserializer(IFiatDeserializerLogger logger, IFieldPredicate fieldPredicate)
        {
            Assert.ArgumentNotNull(logger, "logger");
            Assert.ArgumentNotNull(fieldPredicate, "fieldPredicate");

            _logger = logger;
            _fieldPredicate = fieldPredicate;
        }
        public FiatSitecoreSerializationFormatter(IFiatFormatterLogger logger, IFieldPredicate fieldPredicate)
        {
            Assert.ArgumentNotNull(logger, "logger");
            Assert.ArgumentNotNull(fieldPredicate, "fieldPredicate");

            _logger = logger;
            _fieldPredicate = fieldPredicate;
        }
Beispiel #22
0
        public FiatDeserializer(IFiatDeserializerLogger logger, IFieldPredicate fieldPredicate)
        {
            Assert.ArgumentNotNull(logger, "logger");
            Assert.ArgumentNotNull(fieldPredicate, "fieldPredicate");

            _logger         = logger;
            _fieldPredicate = fieldPredicate;
        }
Beispiel #23
0
 /// <summary>
 /// Counts the specified predicate.
 /// </summary>
 /// <param name="predicate">The predicate.</param>
 /// <returns>A count.</returns>
 /// <example>
 /// Example:
 /// var predicate = Predicates.Field&lt;Task&gt;(f => f.DateCreated, Operator.Lt, DateTime.UtcNow.AddDays(-5));
 /// int count = cn.Count&lt;Task&gt;(predicate);
 /// https://github.com/tmsmith/Dapper-Extensions
 /// .
 /// </example>
 public int Count(IFieldPredicate predicate)
 {
     using (var con = this._connection.Create())
     {
         con.Open();
         return con.Count<Task>(predicate);
     }
 }
Beispiel #24
0
 public virtual IEnumerable <Quote> AllQuotesAfter(DateTime afterDate)
 {
     using (DbConnection connection = Db.CreateConnection())
     {
         connection.Open();
         IFieldPredicate predicate = Predicates.Field <Quote>(x => x.CreateDate, Operator.Gt, afterDate);
         return(connection.GetList <Quote>(predicate));
     }
 }
        public IFieldPredicate ExecuteFilter <TEntity, TPrimaryKey>() where TEntity : class, IEntity <TPrimaryKey>
        {
            IFieldPredicate predicate = null;

            if (typeof(IMustHaveTenant).IsAssignableFrom(typeof(TEntity)) && IsEnabled)
            {
                predicate = Predicates.Field <TEntity>(f => (f as IMustHaveTenant).TenantId, Operator.Eq, TenantId);
            }
            return(predicate);
        }
Beispiel #26
0
        public IFieldPredicate ExecuteFilter <TEntity, TPrimaryKey>() where TEntity : class, IEntity <TPrimaryKey>
        {
            IFieldPredicate predicate = null;

            if (typeof(TEntity).IsInheritsOrImplements(typeof(IMayHaveTenant)) && IsEnabled)
            {
                predicate = Predicates.Field <TEntity>(f => (f as IMayHaveTenant).TenantId, Operator.Eq, TenantId);
            }
            return(predicate);
        }
Beispiel #27
0
        public IFieldPredicate ExecuteFilter <TEntity>() where TEntity : class
        {
            IFieldPredicate predicate = null;

            if (IsFilterable <TEntity>())
            {
                predicate = Predicates.Field <TEntity>(f => (f as ISoftDelete).IsDeleted, Operator.Eq, IsDeleted);
            }

            return(predicate);
        }
        /// <summary>
        /// 分页查询列表
        /// </summary>
        public async Task <IEnumerable <Message> > GetPageAsync(int page = 1, int pageSize = 10)
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                IFieldPredicate predicate = null;
                var             result    = await connection.GetPageAsync <Message>(predicate, page : page, resultsPerPage : pageSize);

                return(result);
            }
        }
Beispiel #29
0
        /// <summary>
        /// 查询列表
        /// </summary>
        public async Task <IEnumerable <User> > GetListAsync()
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                IFieldPredicate predicate = null;
                var             result    = await connection.GetListAsync <User>(predicate);

                return(result);
            }
        }
Beispiel #30
0
        private void AddField(MemberExpression exp, Operator op = Operator.Eq, object value = null, bool not = false)
        {
            PredicateGroup pg = CurrentGroup;

            // need convert from Expression<Func<T, bool>> to Expression<Func<T, object>> as this is what Predicates.Field() requires
            Expression <Func <T, object> > fieldExp = Expression.Lambda <Func <T, object> >(Expression.Convert(exp, typeof(object)), exp.Expression as ParameterExpression);

            IFieldPredicate field = Predicates.Field(fieldExp, op, value, not);

            pg.Predicates.Add(field);
        }
Beispiel #31
0
        private void AddField(MemberExpression exp, Operator op = Operator.Eq, object value = null, bool not = false)
        {
            PredicateGroup pg = _currentGroup;

            //需要从表达式<func<t,bool>>转换为表达式<func<t,object>>,因为这是谓词.field()所需的
            Expression <Func <TEntity, object> > fieldExp = Expression.Lambda <Func <TEntity, object> >(Expression.Convert(exp, typeof(object)), exp.Expression as ParameterExpression);

            IFieldPredicate field = Predicates.Field(fieldExp, op, value, not);

            pg.Predicates.Add(field);
        }
Beispiel #32
0
 public IEnumerable <T> GetPage(IFieldPredicate predicate, IList <ISort> sort, int page, int resultsPerPage)
 {
     try
     {
         using (Db)
             return(Db.GetPage <T>(predicate, sort, page, resultsPerPage));
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #33
0
 public IEnumerable <T> GetAll(IFieldPredicate predicate)
 {
     try
     {
         //using (Db)
         return(Db.GetList <T>(predicate));
     }
     catch (Exception)
     {
         throw;
     }
 }
        public StatusValuePair <ArchiveEntities> GetByBarcode(string barcode)
        {
            if (string.IsNullOrWhiteSpace(barcode) || barcode == default(int).ToString(CultureInfo.InvariantCulture))
            {
                return(new StatusValuePair <ArchiveEntities>(null, ErrorCode.UnknownError));
            }

            IFieldPredicate p = Predicates.Field <ArchiveEntities>(f => f.Barcode, Operator.Eq, barcode);
            StatusValuePair <ArchiveEntities> result = GetSingle <ArchiveEntities>(p);

            return(result);
        }
        public UnicornDataProvider(ISerializationProvider serializationProvider, IPredicate predicate, IFieldPredicate fieldPredicate, IUnicornDataProviderLogger logger)
        {
            Assert.ArgumentNotNull(serializationProvider, "serializationProvider");
            Assert.ArgumentNotNull(predicate, "predicate");
            Assert.ArgumentNotNull(fieldPredicate, "fieldPredicate");
            Assert.ArgumentNotNull(logger, "logger");

            _logger = logger;
            _predicate = predicate;
            _fieldPredicate = fieldPredicate;
            _serializationProvider = serializationProvider;
        }
        public UnicornDataProvider(ISerializationProvider serializationProvider, IPredicate predicate, IFieldPredicate fieldPredicate, IUnicornDataProviderLogger logger)
        {
            Assert.ArgumentNotNull(serializationProvider, "serializationProvider");
            Assert.ArgumentNotNull(predicate, "predicate");
            Assert.ArgumentNotNull(fieldPredicate, "fieldPredicate");
            Assert.ArgumentNotNull(logger, "logger");

            _logger                = logger;
            _predicate             = predicate;
            _fieldPredicate        = fieldPredicate;
            _serializationProvider = serializationProvider;
        }
        private IList<FieldDesynchronization> GetFieldSyncStatus(SitecoreSourceItem item, ISerializedItem serializedItem, IFieldPredicate fieldPredicate)
        {
            var desyncs = new List<FieldDesynchronization>();

            var serializedVersion = serializedItem.Versions.FirstOrDefault(x => x.VersionNumber == item.InnerItem.Version.Number && x.Language == item.InnerItem.Language.Name);

            if (serializedVersion == null)
            {
                desyncs.Add(new FieldDesynchronization("Version"));
                return desyncs;
            }

            item.InnerItem.Fields.ReadAll();

            foreach (Field field in item.InnerItem.Fields)
            {
                if (field.ID == FieldIDs.Revision ||
                    field.ID == FieldIDs.Updated ||
                    field.ID == FieldIDs.Created ||
                    field.ID == FieldIDs.CreatedBy ||
                    field.ID == FieldIDs.UpdatedBy ||
                    field.Type.Equals("attachment", StringComparison.OrdinalIgnoreCase) ||
                    !fieldPredicate.Includes(field.ID).IsIncluded) continue;
                // we're doing a data comparison here - revision, created (by), updated (by) don't matter
                // skipping these fields allows us to ignore spurious saves the template builder makes to unchanged items being conflicts

                // find the field in the serialized item in either versioned or shared fields
                string serializedField;

                if(!serializedVersion.Fields.TryGetValue(field.ID.ToString(), out serializedField))
                    serializedItem.SharedFields.TryGetValue(field.ID.ToString(), out serializedField);

                // we ignore if the field doesn't exist in the serialized item. This is because if you added a field to a template,
                // that does not immediately re-serialize all items based on that template so it's likely innocuous - we're not overwriting anything.
                if (serializedField == null) continue;

                if (!serializedField.Equals(field.Value, StringComparison.Ordinal))
                {
                    desyncs.Add(new FieldDesynchronization(field.Name));
                }
            }

            return desyncs;
        }
Beispiel #38
0
 /// <summary>
 /// Lists the specified predicate.
 /// </summary>
 /// <param name="predicate">The predicate.</param>
 /// <returns>A list.</returns>
 /// <example>
 /// Example:
 /// var predicate = Predicates.Field&lt;Task&gt;(f => f.Active, Operator.Eq, true);
 /// IEnumerable&lt;Task&gt; list = repository.List&lt;Task&gt;(predicate);
 /// https://github.com/tmsmith/Dapper-Extensions/wiki/Predicates
 /// .
 /// </example>
 public IEnumerable<Task> GetList(IFieldPredicate predicate)
 {
     using (var con = this._connection.Create())
     {
         con.Open();
         return con.GetList<Task>(predicate).ToList();
     }
 }