Пример #1
0
        public Func <TwitterStatus, bool> GetEvaluator()
        {
            var sourcesEvals = Sources.Select(s => s.GetEvaluator());
            var predEvals    = PredicateTreeRoot != null
                                ? PredicateTreeRoot.GetEvaluator()
                                : FilterExpressionBase.Contradiction;

            return(_ => sourcesEvals.Any(f => f(_)) && predEvals(_));
        }
Пример #2
0
 public void Deactivate()
 {
     Sources?.ForEach(s =>
     {
         s.InvalidateRequired -= RaiseInvalidateRequired;
         s.Deactivate();
     });
     if (PredicateTreeRoot != null)
     {
         PredicateTreeRoot.InvalidateRequested -= RaiseInvalidateRequired;
         PredicateTreeRoot.EndLifecycle();
     }
 }
Пример #3
0
 public void Activate()
 {
     Sources?.ForEach(s =>
     {
         s.Activate();
         s.InvalidateRequired += RaiseInvalidateRequired;
     });
     if (PredicateTreeRoot != null)
     {
         PredicateTreeRoot.BeginLifecycle();
         PredicateTreeRoot.InvalidateRequested += RaiseInvalidateRequired;
     }
 }
Пример #4
0
 public string ToQuery()
 {
     return("from " + Sources.GroupBy(s => s.FilterKey)
            .Select(g => g.Distinct(_ => _.FilterValue).ToArray()) // remove duplicated query
            .Select(fs =>
     {
         if (fs.Length == 1 && String.IsNullOrEmpty(fs[0].FilterValue))
         {
             // if filter value is not specified, return filter key only.
             return fs[0].FilterKey;
         }
         return fs[0].FilterKey + ": " +
         fs.Select(f => f.FilterValue.EscapeForQuery().Quote())
         .JoinString(", ");
     })
            .JoinString(", ") +
            " where " + PredicateTreeRoot.ToQuery());
 }
Пример #5
0
        public string GetSqlQuery()
        {
            var source =
                Sources.Guard()
                .Select(s => s.GetSqlQuery())
                .JoinString(" or ");
            var predicate = PredicateTreeRoot != null
                       ? PredicateTreeRoot.GetSqlQuery()
                       : String.Empty;

            if (!String.IsNullOrEmpty(source))
            {
                if (!String.IsNullOrEmpty(predicate))
                {
                    return("(" + source + ") and (" + predicate + ")");
                }
                return(source);
            }
            return(!String.IsNullOrEmpty(predicate)
                       ? predicate
                       : FilterExpressionBase.ContradictionSql);
        }