Esempio n. 1
0
        private ResponseViewModel[] SearchInternal(object source)
        {
            var result = (IEnumerable <ResponseViewModel>)source;

            if (SearchFromSelectedParts)
            {
                result = result.Where(r => Parts.Any(p => p == r.PartNumber));
            }
            if (SearchFromSelectedPeople)
            {
                result = result.Where(r => People.Any(p => p == r.Tag));
            }
            if (SearchFromSelectedDate && (StartDate != null || EndDate != null))
            {
                var start = StartDate ?? DateTime.MinValue;
                var end   = EndDate == null?DateTime.MaxValue:EndDate.Value.Date.Add(new TimeSpan(23, 59, 59));
                result = result.Where(r => r.Date >= start && r.Date <= end);
            }
            var buffer = new StringBuilder(1000);

            return(result.Where(r =>
            {
                CharWidthNormalizer.NormalizeFast(r.Text, buffer);
                return Condition.IsMatch(CharWidthNormalizer.Normalize(buffer.ToString()));
            }).ToArray());
        }
Esempio n. 2
0
        //public static ConditionExpression Parse(string str)
        //{
        //	var quoting=0;
        //	var literal=false;
        //	var words=new List<string>();
        //	str=str.Trim();
        //	var startIndex=0;
        //	for(int i=0;i<str.Length;++i){
        //		if(quoting==0&&!literal){
        //			if(!char.IsWhiteSpace(str[i])){
        //				startIndex=i;
        //				literal=true;
        //				if(str[i]=='"'){
        //					++quoting;
        //					++startIndex;
        //				}
        //			}
        //		}else if(literal){
        //			if(quoting>0&&str[i]=='"'&&char.IsWhiteSpace(str[i+1])){

        //				quoting=false;
        //				literal=false;
        //				words.Add(str.Substring(startIndex,i-startIndex-1);
        //			}else if(char.IsWhiteSpace(str[i])){
        //				literal=false;
        //			}
        //		}

        //		if(str[i]=='"'&&((quoting&&char.IsWhiteSpace(str[i+1]))||!quoting)){
        //			quoting=!quoting;
        //		}
        //	}
        //}

        public static ConditionExpression Create(string str)
        {
            var literal = false;
            var words   = new List <string>();

            str = str.Trim();
            if (str == "")
            {
                return(new DummyExpression(true));
            }
            var startIndex = 0;

            for (int i = 0; i < str.Length; ++i)
            {
                if (!literal && !char.IsWhiteSpace(str[i]))
                {
                    literal    = true;
                    startIndex = i;
                }
                else if (literal && char.IsWhiteSpace(str[i]))
                {
                    words.Add(str.Substring(startIndex, i - startIndex));
                    literal = false;
                }
            }
            if (literal)
            {
                words.Add(str.Substring(startIndex, str.Length - startIndex));
            }
            words = words.Select(w => CharWidthNormalizer.Normalize(w)).ToList();
            ConditionExpression root = null;

            if (words.Count == 1)
            {
                root = new LiteralExpression(words.First());
            }
            else
            {
                var last = new AndOperatorExpression(null, null);
                root = last;
                for (int i = 0; i < words.Count; ++i)
                {
                    last.Operand1 = new LiteralExpression(words[i]);
                    if (words.Count == i + 2)
                    {
                        last.Operand2 = new LiteralExpression(words[i + 1]);
                        ++i;
                    }
                    else
                    {
                        var newExpr = new AndOperatorExpression(null, null);
                        last.Operand2 = newExpr;
                        last          = newExpr;
                    }
                }
            }
            return(root);
        }