private void AndButtonClick(object sender, EventArgs e)
        {
            if (null != FiltersTreeView.SelectedNode)
            {
                if (null != FiltersTreeView.SelectedNode.Tag)
                {
                    TreeNode node = FiltersTreeView.SelectedNode;
                    IFilterable parent = (IFilterable) node.Tag;
                    Filter filter = new Filter();

                    if (parent.Filters.IsReadOnly)
                    {
                        parent.Filters = new List<IFilterable>(parent.Filters);
                    }

                    parent.Filters.Add(filter);
                    
                    node.Nodes.Add(TreeNodeMapper.MapFilter(filter));
                }
            }
            else
            {
                if (_filters.IsReadOnly)
                {
                    _filters = new List<IFilterable>(_filters);
                }

                Filter filter = new Filter();
                _filters.Add(filter);
                FiltersTreeView.Nodes.Add(TreeNodeMapper.MapFilter(filter));
            }
        }
        public void ExpectedFilterDefinition(IFilterable filterable, string filterName, string condition)
        {
            var fdef = GetFilterDefinition(filterName);

            if (string.IsNullOrEmpty(condition))
            {
                if (fdef != null)
                {
                    // where immediately available, apply the condition
                    condition = fdef.DefaultFilterCondition;
                }
            }
            if (string.IsNullOrEmpty(condition) && fdef == null)
            {
                log.Debug("Adding filter second pass [{0}]", filterName);
                filtersSecondPasses.Enqueue(new FilterSecondPassArgs(filterable, filterName));
            }
            else if (string.IsNullOrEmpty(condition) && fdef != null)
            {
                // Both sides does not have condition
                throw new MappingException("no filter condition found for filter: " + filterName);
            }

            if (fdef == null)
            {
                // if not available add an expected filter definition
                FilterDefinitions[filterName] = null;
            }
        }
Example #3
0
        public List <T> List(IFilterable <T> filtable, RepoOptions opts = null)
        {
            SQL <T>        sql   = null;
            IDbTransaction trans = null;

            if (opts != null)
            {
                sql   = opts.AllowedFields == null ? this.SqlBag.AllFieldsSql : this.SqlBag.GetSQLObject(opts.AllowedFields);
                trans = opts.DbTrans;
            }
            else
            {
                sql = this.SqlBag.AllFieldsSql;
            }

            if (trans != null)
            {
                System.Data.Common.DbConnection  conn   = trans?.DbConnection;
                System.Data.Common.DbTransaction dbTran = trans?.DbTransaction;

                return(sql.Select.Execute(filtable, conn, dbTran));
            }
            else
            {
                using (var conn = this.SqlBag.Database.CreateConnection())
                {
                    conn.Open();
                    return(sql.Select.Execute(filtable, conn, null));
                }
            }
        }
Example #4
0
        public static void Filter(IFilterable filterable)
        {
            var type = TypeHelper.GetItemType(filterable);

            filterable.FilterQuery.Parameters.Add(CreateTreeFilter(type));
            filterable.FilterQuery.Orders.Add(CreateTreeComparer(type));
        }
Example #5
0
        public IQueryable <TModel> Query <TEntity, TModel>(IFilterable <TEntity> searchModel)
            where TEntity : class
        {
            var query = _repository.Query <TEntity>();

            query = searchModel.Filter(query);
            return(query.AsQuery <TEntity, TModel>());
        }
Example #6
0
 private static QueryFilter MakeMatchFilter(IFilterable filterable, PropertyInfo property)
 {
     return(new MatchQueryFilter()
     {
         FieldName = property.Name.ToCamelCase(),
         Value = property.GetValue(filterable).ToString()
     });
 }
Example #7
0
        public static IEnumerable <QueryFilter> GetFilters(this IFilterable filterable)
        {
            var typeInfo          = filterable.GetType();
            var matchProperties   = typeInfo.GetProperties(new MatchFilterAttribute());
            var dateProperties    = typeInfo.GetProperties(new DateRangeFilterAttribute());
            var numericProperties = typeInfo.GetProperties(new NumericRangeFilterAttribute());

            return(MakeFilterFromProperties(filterable, matchProperties, dateProperties, numericProperties));
        }
        private bool MatchesFilter(T element)
        {
            if (element is IFilterable)
            {
                IFilterable f = element as IFilterable;
                return(filter.Execute(f.GetFilterDictionary(filterValues)));
            }

            return(false);
        }
Example #9
0
        private static QueryFilter MakeDateFilter(IFilterable filterable, PropertyInfo propertyInfo)
        {
            var borders = propertyInfo.GetValue(filterable).ToString().Split(',');

            return(new DateRangeQueryFilter()
            {
                FieldName = propertyInfo.Name.ToCamelCase(),
                Min = DateMath.FromString(borders[0]),
                Max = DateMath.FromString(borders[1])
            });
        }
Example #10
0
        private static QueryFilter MakeNumericFilter(IFilterable filterable, PropertyInfo propertyInfo)
        {
            var borders = propertyInfo.GetValue(filterable).ToString().Split(',');

            return(new NumericRangeQueryFilter()
            {
                FieldName = propertyInfo.Name.ToCamelCase(),
                Min = long.Parse(borders[0]),
                Max = long.Parse(borders[1])
            });
        }
Example #11
0
        private static IEnumerable <QueryFilter> MakeFilterFromProperties(IFilterable obj,
                                                                          IEnumerable <PropertyInfo> matchProperties,
                                                                          IEnumerable <PropertyInfo> dateProperties,
                                                                          IEnumerable <PropertyInfo> numericProperties)
        {
            var result = new List <QueryFilter>();

            result = result.Union(ExtractFilters(matchProperties, obj, MakeMatchFilter)).ToList();
            result = result.Union(ExtractFilters(dateProperties, obj, MakeDateFilter)).ToList();
            result = result.Union(ExtractFilters(numericProperties, obj, MakeNumericFilter)).ToList();
            return(result);
        }
 // this class is NH specific to solve problems generated by 'order of mapping-doc'
 // to assign the condition of a filter.
 public FilterSecondPassArgs(IFilterable filterable, string filterName)
 {
     if (filterable == null)
     {
         throw new ArgumentNullException("filterable");
     }
     if (string.IsNullOrEmpty(filterName))
     {
         throw new ArgumentNullException("filterName");
     }
     Filterable = filterable;
     FilterName = filterName;
 }
Example #13
0
 public GridFilter()
 {
     this.containsFilter        = new ContainsFilter <T>();
     this.notContainsFilter     = new NotContainsFilter <T>();
     this.startsWithFilter      = new StartsWithFilter <T>();
     this.endsWithFilter        = new EndsWithFilter <T>();
     this.equalFilter           = new EqualFilter <T>();
     this.notEqualFilter        = new NotEqualFilter <T>();
     this.greaterFilter         = new GreaterFilter <T>();
     this.greaterOrEqualsFilter = new GreaterOrEqualsFilter <T>();
     this.lessFilter            = new LessThanFilter <T>();
     this.lessOrEqualFilter     = new LessThanOrEqualsFilter <T>();
 }
Example #14
0
        public FilterForm(IFilterable filterable, IEnumerable <Type> knownTypes)
        {
            Filterable = filterable;

            using (var ms = new MemoryStream())
            {
                var serializer = new DataContractSerializer(typeof(IFilterable), knownTypes);
                serializer.WriteObject(ms, Filterable);
                ms.Position = 0;
                _filters    = ((IFilterable)serializer.ReadObject(ms)).Filters;
            }
            InitializeComponent();
        }
Example #15
0
        public IEnumerable <T> Search <T>(IFilterable filterable) where T : class
        {
            var filters   = filterable.GetFilters();
            var indexName = GetIndexName <T>();
            var query     = GenerateQueryDescriptor(filters);
            var response  = ElasticClientProvider.GetClient().Search <T>(s => s
                                                                         .Index(indexName)
                                                                         .Query(q => query)
                                                                         .Size(5000));

            response.Validate();
            return(GetDocuments(response));
        }
Example #16
0
        public virtual DbCommand BuildCommand(IFilterable <T> filterable, DbConnection conn, DbTransaction trans)
        {
            var cmd = conn.CreateCommand();

            cmd.Connection  = conn;
            cmd.Transaction = trans;
            cmd.CommandType = System.Data.CommandType.Text;
            var sql = GetSql(filterable, cmd);

            cmd.CommandText = sql;
            this.Sql.Database.Logger.DebugDetails(new ParametersLogSerializer(cmd.Parameters), "SQL executing:[{0}]", sql);
            return(cmd);
        }
		// this class is NH specific to solve problems generated by 'order of mapping-doc'
		// to assign the condition of a filter.
		public FilterSecondPassArgs(IFilterable filterable, string filterName)
		{
			if (filterable == null)
			{
				throw new ArgumentNullException("filterable");
			}
			if (string.IsNullOrEmpty(filterName))
			{
				throw new ArgumentNullException("filterName");
			}
			Filterable = filterable;
			FilterName = filterName;
		}
Example #18
0
 public static IFilterable <T> AndAlso <T>(this IFilterable <T> self, Expression <Func <T, bool> > criteria)
 {
     if (criteria == null)
     {
         return(self);
     }
     if (self.QueryExpression == null)
     {
         self.QueryExpression = criteria; return(self);
     }
     self.QueryExpression = Expression.Lambda <Func <T, bool> >(Expression.AndAlso(self.QueryExpression.Body, ReplaceParameter <T>(criteria.Body, criteria.Parameters[0])), self.QueryParameter);
     return(self);
 }
        public FilterForm(IFilterable filterable, IEnumerable<Type> knownTypes)
        {
            Filterable = filterable;

            using (var ms = new MemoryStream())
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(IFilterable), knownTypes);
                serializer.WriteObject(ms, Filterable);
                ms.Position = 0;
                _filters = ((IFilterable)serializer.ReadObject(ms)).Filters;
            }

            InitializeComponent();
        }
Example #20
0
        /// <summary>
        /// 关键字筛选。
        /// </summary>
        /// <typeparam name="TResult">筛选结果的类型。</typeparam>
        /// <param name="source">实现了 IFilterable 接口的类型实例。</param>
        /// <param name="keyWords">属性名与值组成的键值对。</param>
        /// <returns>筛选结果。</returns>
        public static IEnumerable <TResult> FilterAllTextByRegex <TResult>(this IFilterable source, String[] patterns, params String[] fields)
        {
            StringBuilder sb = new StringBuilder();

            if (patterns != null && patterns.Length != 0)
            {
                foreach (String pattern in patterns)
                {
                    sb.AppendFormat("AND RegexMatch('$XLYJson','${0}') ", pattern.Replace("{", "{{").Replace("}", "}}"));
                }
                sb = sb.Remove(0, 2);
            }
            return(source.Provider.Query <TResult>(Expression.Constant(sb.ToString())));
        }
Example #21
0
 public static IFilterable <T> Page <T>(this IFilterable <T> self, int index, int size = 10)
 {
     if (index <= 0)
     {
         index = 1;
     }
     if (size <= 2)
     {
         size = 2;
     }
     self.TakeCount = size;
     self.SkipCount = (index - 1) * size;
     return(self);
 }
Example #22
0
        /// <summary>
        /// 正则筛选。
        /// </summary>
        /// <typeparam name="TResult">筛选结果的类型。</typeparam>
        /// <param name="source">实现了 IFilterable 接口的类型实例。</param>
        /// <param name="pattern">正则表达式。</param>
        /// <returns>筛选结果。</returns>
        public static IEnumerable <TResult> FilterByRegex <TResult>(this IFilterable source, KeyValuePair <String, String>[] pattern, params String[] fields)
        {
            StringBuilder sb = new StringBuilder();

            if (pattern != null && pattern.Length != 0)
            {
                foreach (KeyValuePair <String, String> kv in pattern)
                {
                    sb.AppendFormat("AND RegexMatch('${0}','${1}') ", kv.Key, kv.Value.Replace("{", "{{").Replace("}", "}}"));
                }
                sb = sb.Remove(0, 2);
            }
            return(source.Provider.Query <TResult>(Expression.Constant(sb.ToString())));
        }
Example #23
0
        /// <summary>
        /// 关键字筛选。
        /// </summary>
        /// <typeparam name="TResult">筛选结果的类型。</typeparam>
        /// <param name="source">实现了 IFilterable 接口的类型实例。</param>
        /// <param name="keyWords">属性名与值组成的键值对。</param>
        /// <returns>筛选结果。</returns>
        public static IEnumerable <TResult> FilterAllTextByKeywords <TResult>(this IFilterable source, String[] keyWords, params String[] fields)
        {
            StringBuilder sb = new StringBuilder();

            if (keyWords != null && keyWords.Length != 0)
            {
                foreach (String keyWord in keyWords)
                {
                    sb.AppendFormat("AND XLYJson LIKE '%{0}%' ", keyWord);
                }
                sb = sb.Remove(0, 2);
            }
            return(source.Provider.Query <TResult>(Expression.Constant(sb.ToString())));
        }
Example #24
0
        /// <summary>
        /// 关键字筛选。
        /// </summary>
        /// <typeparam name="TResult">筛选结果的类型。</typeparam>
        /// <param name="source">实现了 IFilterable 接口的类型实例。</param>
        /// <param name="keyWords">属性名与值组成的键值对。</param>
        /// <returns>筛选结果。</returns>
        public static IEnumerable <TResult> FilterByKeywords <TResult>(this IFilterable source, KeyValuePair <String, String>[] keyWords, params String[] fields)
        {
            StringBuilder sb = new StringBuilder();

            if (keyWords != null && keyWords.Length != 0)
            {
                foreach (KeyValuePair <String, String> kv in keyWords)
                {
                    sb.AppendFormat("AND {0} LIKE '%{1}%' ", kv.Key, kv.Value);
                }
                sb = sb.Remove(0, 2);
            }
            return(source.Provider.Query <TResult>(Expression.Constant(sb.ToString())));
        }
Example #25
0
        public IFilterBuilder AddParameter(string parameterName, string parameterValue)
        {
            var         name = typeof(T).GetCustomAttributesData();
            IFilterable f    = (T)Activator.CreateInstance(typeof(T));

            if (f.FilteredFields.Contains(parameterName))
            {
                _parameters.Add(parameterName, parameterValue);

                return(this);
            }
            else
            {
                throw new ArgumentException($"{parameterName} is not a valid filter parameter");
            }
        }
Example #26
0
        public async Task <List <T> > ExecuteAsync(IFilterable <T> filterable, DbConnection conn, DbTransaction trans)
        {
            var cmd = BuildCommand(filterable, conn, trans);

            var result = new List <T>();

            using (var reader = await cmd.ExecuteReaderAsync())
            {
                while (await reader.ReadAsync())
                {
                    var entity = FillEntity(reader);
                    result.Add(entity);
                }
            }
            return(result);
        }
Example #27
0
        public List <T> Execute(IFilterable <T> filterable, DbConnection conn, DbTransaction trans)
        {
            var cmd = BuildCommand(filterable, conn, trans);

            var result = new List <T>();

            using (var reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    var entity = FillEntity(reader);
                    result.Add(entity);
                }
            }
            return(result);
        }
Example #28
0
        public IndexViewModel(IFilterable <Period> filterable, string queryText)
            : this()
        {
            this.QueryText = queryText;
            this.Periods   =
                new StaticFilterable <PeriodViewModel>(
                    filterable.Select(period => new PeriodViewModel(period)),
                    filterable.Filters,
                    filterable.PageNumber,
                    filterable.ItemCountPerPage,
                    filterable.TotalItemCount);

            this.PageNumber       = filterable.PageNumber;
            this.ItemCountPerPage = filterable.ItemCountPerPage;

            this.ItemCountPerPageList = new SelectList(Constants.ItemCountPerPageValues, filterable.ItemCountPerPage);
        }
Example #29
0
        public static TreeNode MapFilter(IFilterable filterable)
        {
            var node = new TreeNode();

            if (filterable is Filter)
            {
                Filter filter     = (Filter)filterable;
                string filterText = string.Format("{0} {1} {2}", filter.On, filter.Operator, filter.Value);
                node.Name = filterText;
                node.Text = filterText;
                node.Tag  = filterable;

                node.Nodes.AddRange(MapFilters(filterable.Filters));
            }

            return(node);
        }
Example #30
0
        private void FilterEntryChanged(object sender, EventArgs e)
        {
            var         entry = (TextEntry)sender;
            IFilterable list  = listSource as IFilterable;

            list.FilterQuery.Parameters.Clear();

            if (entry.Text?.Length != 0)
            {
                TreeMode = false;
                list.FilterQuery.Parameters.Add(typeof(Node), LogicType.And, nameof(Node.FullPath), CompareType.Like, entry.Text);
            }
            else
            {
                TreeMode = true;
            }
            list.UpdateFilter();
        }
Example #31
0
        public static TreeNode MapFilter(IFilterable filterable)
        {
            var node = new TreeNode();

            if (!(filterable is Filter filter))
            {
                return(node);
            }

            string filterText = $"{filter.On} {filter.Operator} {filter.Value}";

            node.Name = filterText;
            node.Text = filterText;
            node.Tag  = filterable;

            node.Nodes.AddRange(MapFilters(filter.Filters));

            return(node);
        }
Example #32
0
        private void setFilter(Filter f)
        {
            filter = FilterFabrica.createFilter(f);
            hideAllElsFilter();
            if (string.IsNullOrEmpty(filter.getFirstParamName()))
            {
                return;
            }
            setText(aTextBox, aLabel, filter.getFirstParamName());


            if (string.IsNullOrEmpty(filter.getSecondParamName()))
            {
                return;
            }
            setText(bTextBox, bLabel, filter.getSecondParamName());

            darkCheckBox.Visible = filter.hasDarknessParam();
        }
		public void ExpectedFilterDefinition(IFilterable filterable, string filterName, string condition)
		{
			var fdef = GetFilterDefinition(filterName);
			if (string.IsNullOrEmpty(condition))
			{
				if (fdef != null)
				{
					// where immediately available, apply the condition
					condition = fdef.DefaultFilterCondition;
				}
			}
			if (string.IsNullOrEmpty(condition) && fdef == null)
			{
				log.Debug(string.Format("Adding filter second pass [{0}]", filterName));
				filtersSecondPasses.Enqueue(new FilterSecondPassArgs(filterable, filterName));
			}
			else if (string.IsNullOrEmpty(condition) && fdef != null)
			{
				// Both sides does not have condition
				throw new MappingException("no filter condition found for filter: " + filterName);
			}

			if (fdef == null)
			{
				// if not available add an expected filter definition
				FilterDefinitions[filterName] = null;
			}
		}
Example #34
0
		protected void ParseFilter(XmlNode filterElement, IFilterable filterable)
		{
			string name = GetPropertyName(filterElement);
			if(name.IndexOf('.') > -1)
				throw new MappingException("Filter name can't contain the character '.'(point): " + name);
			string condition = filterElement.InnerText;
			if (condition == null || StringHelper.IsEmpty(condition.Trim()))
				if (filterElement.Attributes != null)
				{
					XmlAttribute propertyNameNode = filterElement.Attributes["condition"];
					condition = (propertyNameNode == null) ? null : propertyNameNode.Value;
				}

			if (StringHelper.IsEmpty(condition))
			{
				var fdef = mappings.GetFilterDefinition(name);
				if (fdef != null)
				{
					// where immediately available, apply the condition
					condition = fdef.DefaultFilterCondition;
				}
			}

			mappings.ExpectedFilterDefinition(filterable, name, condition);

			log.Debug(string.Format("Applying filter [{0}] as [{1}]", name, condition));
			filterable.AddFilter(name, condition);
		}
 public SearchViewExpandListener(IFilterable adapter)
 {
     adapter_groc = adapter;
 }
		public FiltersBinder(IFilterable filterable, Mappings mappings) : base(mappings)
		{
			this.filterable = filterable;
		}
        protected void ParseFilter(XmlNode filterElement, IFilterable filterable)
        {
            string name = GetPropertyName(filterElement);
            if(name.IndexOf('.') > -1)
                throw new MappingException("Filter name can't contain the character '.'(point): " + name);
            string condition = filterElement.InnerText;
            if (condition == null || StringHelper.IsEmpty(condition.Trim()))
                if (filterElement.Attributes != null)
                {
                    XmlAttribute propertyNameNode = filterElement.Attributes["condition"];
                    condition = (propertyNameNode == null) ? null : propertyNameNode.Value;
                }

            //TODO: bad implementation, cos it depends upon ordering of mapping doc
            //      fixing this requires that Collection/PersistentClass gain access
            //      to the Mappings reference from Configuration (or the filterDefinitions
            //      map directly) sometime during Configuration.buildSessionFactory
            //      (after all the types/filter-defs are known and before building
            //      persisters).
            if (StringHelper.IsEmpty(condition))
                condition = mappings.GetFilterDefinition(name).DefaultFilterCondition;
            if (condition == null)
                throw new MappingException("no filter condition found for filter: " + name);
            log.Debug("Applying filter [" + name + "] as [" + condition + "]");
            filterable.AddFilter(name, condition);
        }
 public SearchViewExpandListener(IFilterable adapter)
 {
     _adapter = adapter;
 }