Ejemplo n.º 1
0
        private static FilterBuilder <T> GetOrFilterForNumericRange <T>(ITypeSearch <T> query,
                                                                        IEnumerable <SelectableNumericRange> range,
                                                                        string fieldName,
                                                                        Type type)
        {
            // Appends type convention to field name (like "$$string")
            var client        = query.Client;
            var fullFieldName = client.GetFullFieldName(fieldName, type);

            var filters = new List <Filter>();

            foreach (var rangeItem in range)
            {
                var rangeFilter = RangeFilter.Create(fullFieldName,
                                                     rangeItem.From ?? 0,
                                                     rangeItem.To ?? double.MaxValue);
                rangeFilter.IncludeUpper = false;
                filters.Add(rangeFilter);
            }

            var orFilter      = new OrFilter(filters);
            var filterBuilder = new FilterBuilder <T>(client, orFilter);

            return(filterBuilder);
        }
Ejemplo n.º 2
0
        // Token: 0x06001240 RID: 4672 RVA: 0x00062F44 File Offset: 0x00061144
        public static QueryFilter BuildMessageClassFilter(IList <string> supportedIpmTypes)
        {
            QueryFilter result;

            switch (supportedIpmTypes.Count)
            {
            case 0:
                result = AirSyncXsoSchemaState.FalseFilterInstance;
                break;

            case 1:
                result = new TextFilter(StoreObjectSchema.ItemClass, supportedIpmTypes[0], MatchOptions.PrefixOnWords, MatchFlags.IgnoreCase);
                break;

            default:
            {
                QueryFilter[] array = new QueryFilter[supportedIpmTypes.Count];
                for (int i = 0; i < supportedIpmTypes.Count; i++)
                {
                    array[i] = new TextFilter(StoreObjectSchema.ItemClass, supportedIpmTypes[i], MatchOptions.PrefixOnWords, MatchFlags.IgnoreCase);
                }
                result = new OrFilter(array);
                break;
            }
            }
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="p"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public string VisitOrFilter(Hashtable p, OrFilter filter)
        {
            var l = filter.Left.Accept <String, Hashtable>(this, p);
            var r = filter.Right.Accept <String, Hashtable>(this, p);

            return(string.Format("{0} -or {1}", l, r));
        }
Ejemplo n.º 4
0
        public void ShouldBeComposableWithOthersFilters()
        {
            var aFalseFilter = new FakeFalseFilter();
            var sut          = new OrFilter(new Filter[] { new OrFilter(new Filter[] { aFalseFilter }), new FakeTrueFilter() });

            Assert.True(sut.Evaluate(null));
            Assert.True(aFalseFilter.Called);
        }
Ejemplo n.º 5
0
        public void ShouldFormat()
        {
            IOrFilter filter;

            filter = new OrFilter(JobTable.Description.IsEqualTo("test"), JobTable.Description.IsEqualTo("test"));
            Assert.AreEqual(2, filter.Members.Count());
            Assert.AreEqual("(C1 OR C2)", filter.Format(new string[] { "C1", "C2" }));
        }
Ejemplo n.º 6
0
        public void OrFilter_Constructor()
        {
            var filter = new OrFilter(new CategoryFilter("Dummy"), new CategoryFilter("Another"));

            Assert.False(filter.IsEmpty);
            Assert.That(filter.Match(dummyFixture));
            Assert.That(filter.Match(anotherFixture));
        }
        protected Dictionary <IFilter <IIdentifiedSpectrum>, string> GetFilterMap()
        {
            Dictionary <IFilter <IIdentifiedSpectrum>, string> map = new Dictionary <IFilter <IIdentifiedSpectrum>, string>();

            Regex reg = new Regex(@"\(([^()]+?)\:([^()]+?)\)");

            List <IFilter <IIdentifiedSpectrum> > matchedFilters = new List <IFilter <IIdentifiedSpectrum> >();

            string defaultTitle = null;

            Match match = reg.Match(modifiedAminoacids.Text);

            if (!match.Success)
            {
                throw new Exception("Couldn't recognize modification pattern, it should like \n" + DEFAULT_PATTERN);
            }

            while (match.Success)
            {
                if (match.Groups[1].Value.Trim().Equals("DEFAULT"))
                {
                    defaultTitle = match.Groups[2].Value.Trim();
                }
                else
                {
                    string title = match.Groups[2].Value.Trim();

                    string[] parts = Regex.Split(match.Groups[1].Value, @"\s+");

                    List <IFilter <IIdentifiedSpectrum> > filters = new List <IFilter <IIdentifiedSpectrum> >();

                    foreach (string part in parts)
                    {
                        if (part.Length > 0)
                        {
                            filters.Add(new IdentifiedSpectrumSequenceFilter(part));
                        }
                    }

                    OrFilter <IIdentifiedSpectrum> filter = new OrFilter <IIdentifiedSpectrum>(filters);

                    map[filter] = title;

                    matchedFilters.Add(filter);
                }
                match = match.NextMatch();
            }

            if (defaultTitle == null)
            {
                throw new Exception("No default name defined, the pattern should like \n" + DEFAULT_PATTERN);
            }

            NotFilter <IIdentifiedSpectrum> notFilter = new NotFilter <IIdentifiedSpectrum>(new OrFilter <IIdentifiedSpectrum>(matchedFilters));

            map[notFilter] = defaultTitle;
            return(map);
        }
Ejemplo n.º 8
0
        private static TestFilter FromXml(TNode node)
        {
            switch (node.Name)
            {
            case "filter":
            case "and":
                var andFilter = new AndFilter();
                foreach (var childNode in node.ChildNodes)
                {
                    andFilter.Add(FromXml(childNode));
                }
                return(andFilter);

            case "or":
                var orFilter = new OrFilter();
                foreach (var childNode in node.ChildNodes)
                {
                    orFilter.Add(FromXml(childNode));
                }
                return(orFilter);

            case "not":
                return(new NotFilter(FromXml(node.FirstChild)));

            case "id":
                var idFilter = new IdFilter();
                if (node.Value != null)
                {
                    foreach (string id in node.Value.Split(COMMA))
                    {
                        idFilter.Add(id);
                    }
                }
                return(idFilter);

            case "tests":
                var testFilter = new SimpleNameFilter();
                foreach (var childNode in node.SelectNodes("test"))
                {
                    testFilter.Add(childNode.Value);
                }
                return(testFilter);

            case "cat":
                var catFilter = new CategoryFilter();
                if (node.Value != null)
                {
                    foreach (string cat in node.Value.Split(COMMA))
                    {
                        catFilter.AddCategory(cat);
                    }
                }
                return(catFilter);

            default:
                throw new ArgumentException("Invalid filter element: " + node.Name, "xmlNode");
            }
        }
Ejemplo n.º 9
0
        public void TestSingleLine7()
        {
            var filter = new OrFilter(new[] { new SubstringFilter("foo", false), new SubstringFilter("bar", false) });

            filter.PassesFilter(new LogEntry(Core.Columns.RawContent)
            {
                RawContent = "FOOBAR"
            }).Should().BeFalse();
        }
Ejemplo n.º 10
0
        public void TestToString()
        {
            var filter = new OrFilter(new[] { new SubstringFilter("foo", true) });

            filter.ToString().Should().Be("message.Contains(foo, InvariantCultureIgnoreCase)");

            filter = new OrFilter(new ILogEntryFilter[] { new SubstringFilter("foo", true), new LevelFilter(LevelFlags.Info) });
            filter.ToString().Should().Be("message.Contains(foo, InvariantCultureIgnoreCase) || level == Info");
        }
Ejemplo n.º 11
0
        internal static IEnumerable <ExtendedOrganizationalUnit> FindSubTreeChildOrganizationalUnit(bool includeContainers, IConfigurationSession session, ADObjectId rootId, QueryFilter preFilter)
        {
            QueryFilter queryFilter = new OrFilter(new QueryFilter[]
            {
                new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ObjectCategory, ADOrganizationalUnit.MostDerivedClass),
                new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ObjectCategory, ADDomain.MostDerivedClass)
            });

            if (!ExtendedOrganizationalUnit.IsTenant(session))
            {
                IList <QueryFilter>    list       = new List <QueryFilter>();
                IList <QueryFilter>    list2      = new List <QueryFilter>();
                IEnumerable <ADDomain> enumerable = ADForest.GetLocalForest(session.DomainController).FindDomains();
                foreach (ADDomain addomain in enumerable)
                {
                    ExchangeOrganizationalUnit exchangeOrganizationalUnit = session.ResolveWellKnownGuid <ExchangeOrganizationalUnit>(WellKnownGuid.DomainControllersWkGuid, addomain.Id);
                    if (exchangeOrganizationalUnit != null)
                    {
                        list.Add(new ComparisonFilter(ComparisonOperator.NotEqual, ADObjectSchema.Id, exchangeOrganizationalUnit.Id));
                    }
                    ExchangeOrganizationalUnit exchangeOrganizationalUnit2 = session.ResolveWellKnownGuid <ExchangeOrganizationalUnit>(WellKnownGuid.UsersWkGuid, addomain.Id);
                    if (exchangeOrganizationalUnit2 != null)
                    {
                        list2.Add(new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Id, exchangeOrganizationalUnit2.Id));
                    }
                }
                foreach (QueryFilter queryFilter2 in list)
                {
                    queryFilter = new AndFilter(new QueryFilter[]
                    {
                        queryFilter,
                        queryFilter2
                    });
                }
                if (includeContainers)
                {
                    foreach (QueryFilter queryFilter3 in list2)
                    {
                        queryFilter = new OrFilter(new QueryFilter[]
                        {
                            queryFilter,
                            queryFilter3
                        });
                    }
                }
            }
            if (preFilter != null)
            {
                queryFilter = new AndFilter(new QueryFilter[]
                {
                    preFilter,
                    queryFilter
                });
            }
            return(session.FindPaged <ExtendedOrganizationalUnit>(rootId, QueryScope.SubTree, queryFilter, null, 0));
        }
Ejemplo n.º 12
0
        public void IsMatchCombinations(bool expectedMatch, bool[] states)
        {
            Filter<object>[] filters = GenericCollectionUtils.ConvertAllToArray<bool, Filter<object>>(states, delegate(bool state)
            {
                return state ? (Filter<object>)new AnyFilter<object>() : new NoneFilter<object>();
            });

            OrFilter<object> combinator = new OrFilter<object>(filters);
            Assert.AreEqual(expectedMatch, combinator.IsMatch(null));
        }
Ejemplo n.º 13
0
        internal static List <RetentionPolicyTag> FindRetentionPolicyTag(IConfigurationSession session, Guid tagGuid)
        {
            OrFilter filter = new OrFilter(new QueryFilter[]
            {
                new ComparisonFilter(ComparisonOperator.Equal, RetentionPolicyTagSchema.RetentionId, tagGuid),
                new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Guid, tagGuid)
            });

            return(ELCTaskHelper.FindElcObject <RetentionPolicyTag>(session, null, filter));
        }
Ejemplo n.º 14
0
        internal static QueryFilter MailboxPlanReleaseFilterBuilder(SinglePropertyFilter filter)
        {
            if (!(filter is ComparisonFilter))
            {
                throw new ADFilterException(DirectoryStrings.ExceptionUnsupportedFilterForProperty(filter.Property.Name, filter.GetType(), typeof(ComparisonFilter)));
            }
            ComparisonFilter comparisonFilter = (ComparisonFilter)filter;

            if (comparisonFilter.ComparisonOperator != ComparisonOperator.Equal && ComparisonOperator.NotEqual != comparisonFilter.ComparisonOperator)
            {
                throw new ADFilterException(DirectoryStrings.ExceptionUnsupportedOperatorForProperty(comparisonFilter.Property.Name, comparisonFilter.ComparisonOperator.ToString()));
            }
            if (!(comparisonFilter.PropertyValue is MailboxPlanRelease))
            {
                throw new ArgumentException("filter.PropertyValue");
            }
            MailboxPlanRelease mailboxPlanRelease = (MailboxPlanRelease)comparisonFilter.PropertyValue;

            if (mailboxPlanRelease != MailboxPlanRelease.AllReleases)
            {
                if (mailboxPlanRelease != MailboxPlanRelease.CurrentRelease)
                {
                    if (mailboxPlanRelease != MailboxPlanRelease.NonCurrentRelease)
                    {
                        throw new ArgumentException("filter.PropertyValue");
                    }
                    if (comparisonFilter.ComparisonOperator == ComparisonOperator.Equal)
                    {
                        return(Microsoft.Exchange.Data.Directory.Management.MailboxPlan.NonCurrentReleaseFilter);
                    }
                    return(new NotFilter(Microsoft.Exchange.Data.Directory.Management.MailboxPlan.NonCurrentReleaseFilter));
                }
                else
                {
                    if (comparisonFilter.ComparisonOperator == ComparisonOperator.Equal)
                    {
                        return(Microsoft.Exchange.Data.Directory.Management.MailboxPlan.CurrentReleaseFilter);
                    }
                    return(new NotFilter(Microsoft.Exchange.Data.Directory.Management.MailboxPlan.CurrentReleaseFilter));
                }
            }
            else
            {
                QueryFilter queryFilter = new OrFilter(new QueryFilter[]
                {
                    Microsoft.Exchange.Data.Directory.Management.MailboxPlan.CurrentReleaseFilter,
                    Microsoft.Exchange.Data.Directory.Management.MailboxPlan.NonCurrentReleaseFilter
                });
                if (ComparisonOperator.NotEqual == comparisonFilter.ComparisonOperator)
                {
                    return(queryFilter);
                }
                return(new NotFilter(queryFilter));
            }
        }
Ejemplo n.º 15
0
        public void MulitpleTestCaseIdMatch()
        {
            OrFilter filter = new OrFilter(CreateIdFilter(_mock1), CreateIdFilter(_mock3));

            Assert.IsTrue(filter.Pass(_mock1), "Filter did not pass MockTest1");
            Assert.IsFalse(filter.Pass(_mock2), "Filter should not have passed MockTest2");
            Assert.IsTrue(filter.Pass(_mock3), "Filter did not pass MockTest3");
            Assert.IsFalse(filter.Pass(_explicitTest), "Filter should not have passed ExplicitlyRunTest");
            Assert.IsTrue(filter.Pass(_fixture), "Filter did not pass MockTestFixture");
            Assert.IsTrue(filter.Pass(_suite), "Filter did not pass TopLevelSuite");
        }
Ejemplo n.º 16
0
        public void TestMultiLine2()
        {
            var filter = new OrFilter(new[] { new SubstringFilter("foo", true) });
            var lines  = new[]
            {
                new LogLine(0, 0, "fo", LevelFlags.All),
                new LogLine(0, 0, "obar", LevelFlags.All)
            };

            filter.PassesFilter(lines).Should().BeFalse("because substring filters shouldn't be matched across lines");
        }
Ejemplo n.º 17
0
        public void TestMultiLine1()
        {
            var filter = new OrFilter(new[] { new SubstringFilter("foo", true) });
            var lines  = new[]
            {
                new LogLine(0, 0, "bar", LevelFlags.All),
                new LogLine(0, 0, "foo", LevelFlags.All)
            };

            filter.PassesFilter(lines).Should().BeTrue("because it should be enough to have a hit on one line of a multi line entry");
        }
Ejemplo n.º 18
0
        public void TestSingleLine3()
        {
            var filter = new OrFilter(new[] { new SubstringFilter("foo", true) });
            var line   = new LogLine(0, 0, "bar", LevelFlags.All);

            filter.PassesFilter(line).Should().BeFalse();
            var matches = filter.Match(line);

            matches.Should().NotBeNull();
            matches.Should().BeEmpty();
        }
Ejemplo n.º 19
0
        public void IsMatchCombinations(bool expectedMatch, bool[] states)
        {
            Filter <object>[] filters = GenericCollectionUtils.ConvertAllToArray <bool, Filter <object> >(states, delegate(bool state)
            {
                return(state ? (Filter <object>) new AnyFilter <object>() : new NoneFilter <object>());
            });

            OrFilter <object> combinator = new OrFilter <object>(filters);

            Assert.AreEqual(expectedMatch, combinator.IsMatch(null));
        }
Ejemplo n.º 20
0
 private static bool EvaluateOrFilter(OrFilter filterOr, IReadOnlyPropertyBag propertyBag, bool shouldThrow)
 {
     foreach (QueryFilter filter in filterOr.Filters)
     {
         if (EvaluatableFilter.Evaluate(filter, propertyBag, shouldThrow))
         {
             return(true);
         }
     }
     return(false);
 }
        private static string CreateOrFilter(OrFilter orFilter, IList <Field> availableFields)
        {
            string result = null;

            if (orFilter.ChildFilters != null)
            {
                var childExpressions = orFilter.ChildFilters.Select(q => GetFilterExpressionRecursive(q, availableFields)).ToArray();
                result = AzureSearchHelper.JoinNonEmptyStrings(" or ", true, childExpressions);
            }

            return(result);
        }
Ejemplo n.º 22
0
        public Dictionary <string, object> VisitOrFilter(Hashtable p, OrFilter filter)
        {
            var dic = new Dictionary <String, Object>
            {
                { Not, false },
                { Left, filter.Left.Accept <Dictionary <String, Object>, Hashtable>(this, p) },
                { Right, filter.Right.Accept <Dictionary <String, Object>, Hashtable>(this, p) },
                { Operation, Or }
            };

            return(dic);
        }
        public void TestOrFilter()
        {
            ContainsFilter left1  = new ContainsFilter(ConnectorAttributeBuilder.Build("foo", "bar"));
            ContainsFilter right1 = new ContainsFilter(ConnectorAttributeBuilder.Build("foo2", "bar2"));
            OrFilter       v1     = new OrFilter(left1, right1);
            OrFilter       v2     = (OrFilter)CloneObject(v1);
            ContainsFilter left2  = (ContainsFilter)v2.Left;
            ContainsFilter right2 = (ContainsFilter)v2.Right;

            Assert.AreEqual(left1.GetAttribute(), left2.GetAttribute());
            Assert.AreEqual(right1.GetAttribute(), right2.GetAttribute());
        }
Ejemplo n.º 24
0
        private static Filter CreateOrFilter(OrFilter orFilter, ICollection <string> availableFields)
        {
            Filter result = null;

            if (orFilter?.ChildFilters != null)
            {
                var childFilters = orFilter.ChildFilters.Select(filter => GetFilterRecursive(filter, availableFields));
                result = JoinNonEmptyFilters(childFilters, Occur.SHOULD);
            }

            return(result);
        }
Ejemplo n.º 25
0
        private static TestFilter FromXml(XmlNode xmlNode)
        {
            switch (xmlNode.Name)
            {
            case "filter":
            case "and":
                var andFilter = new AndFilter();
                foreach (XmlNode childNode in xmlNode.ChildNodes)
                {
                    andFilter.Add(FromXml(childNode));
                }
                return(andFilter);

            case "or":
                var orFilter = new OrFilter();
                foreach (System.Xml.XmlNode childNode in xmlNode.ChildNodes)
                {
                    orFilter.Add(FromXml(childNode));
                }
                return(orFilter);

            case "not":
                return(new NotFilter(FromXml(xmlNode.FirstChild)));

            case "id":
                var idFilter = new IdFilter();
                foreach (string id in xmlNode.InnerText.Split(COMMA))
                {
                    idFilter.Add(int.Parse(id));
                }
                return(idFilter);

            case "tests":
                var testFilter = new SimpleNameFilter();
                foreach (XmlNode childNode in xmlNode.SelectNodes("test"))
                {
                    testFilter.Add(childNode.InnerText);
                }
                return(testFilter);

            case "cat":
                var catFilter = new CategoryFilter();
                foreach (string cat in xmlNode.InnerText.Split(COMMA))
                {
                    catFilter.AddCategory(cat);
                }
                return(catFilter);

            default:
                throw new ArgumentException("Invalid filter element: " + xmlNode.Name, "xmlNode");
            }
        }
Ejemplo n.º 26
0
        public void OrAndMinusCombined()
        {
            CategoryExpression expr     = new CategoryExpression("A|B-C-D|E");
            OrFilter           orFilter = (OrFilter)expr.Filter;

            Assert.AreEqual(orFilter.Filters.Length, 3);
            AndFilter andFilter = (AndFilter)orFilter.Filters[1];

            Assert.AreEqual(andFilter.Filters.Length, 3);
            Assert.AreEqual(andFilter.Filters[0], typeof(CategoryFilter));
            Assert.AreEqual(andFilter.Filters[1], typeof(NotFilter));
            Assert.AreEqual(andFilter.Filters[2], typeof(NotFilter));
        }
Ejemplo n.º 27
0
        public void OrAndMinusCombined()
        {
            CategoryExpression expr     = new CategoryExpression("A|B-C-D|E");
            OrFilter           orFilter = (OrFilter)expr.Filter;

            Assert.That(orFilter.Filters.Length, Is.EqualTo(3));
            AndFilter andFilter = (AndFilter)orFilter.Filters[1];

            Assert.That(andFilter.Filters.Length, Is.EqualTo(3));
            Assert.That(andFilter.Filters[0], Is.TypeOf(typeof(CategoryFilter)));
            Assert.That(andFilter.Filters[1], Is.TypeOf(typeof(NotFilter)));
            Assert.That(andFilter.Filters[2], Is.TypeOf(typeof(NotFilter)));
        }
Ejemplo n.º 28
0
        private static QueryContainer CreateOrFilter(OrFilter orFilter, Properties <IProperties> availableFields)
        {
            QueryContainer result = null;

            if (orFilter?.ChildFilters != null)
            {
                foreach (var childQuery in orFilter.ChildFilters)
                {
                    result |= GetFilterQueryRecursive(childQuery, availableFields);
                }
            }

            return(result);
        }
Ejemplo n.º 29
0
        public void TestSingleLine3()
        {
            var filter = new OrFilter(new[] { new SubstringFilter("foo", true) });
            var line   = new LogEntry(Core.Columns.RawContent)
            {
                RawContent = "bar"
            };

            filter.PassesFilter(line).Should().BeFalse();
            var matches = filter.Match(line);

            matches.Should().NotBeNull();
            matches.Should().BeEmpty();
        }
Ejemplo n.º 30
0
        public void CanParseMultipleAlternatives()
        {
            CategoryExpression expr     = new CategoryExpression("One|Two|Three");
            OrFilter           orFilter = (OrFilter)expr.Filter;

            Assert.AreEqual(orFilter.Filters.Length, 3);
            CategoryFilter catFilter = (CategoryFilter)orFilter.Filters[0];

            Assert.AreEqual(catFilter.Categories, new string[] { "One" });
            catFilter = (CategoryFilter)orFilter.Filters[1];
            Assert.AreEqual(catFilter.Categories, new string[] { "Two" });
            catFilter = (CategoryFilter)orFilter.Filters[2];
            Assert.AreEqual(catFilter.Categories, new string[] { "Three" });
        }
Ejemplo n.º 31
0
        private void wrapIntoAnySubfiltersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (FilterTree.Nodes.Count == 0)
            {
                return;
            }

            TreeNode selected_node = FilterTree.SelectedNode;

            if (selected_node == null)
            {
                return;
            }

            OrFilter fl      = new OrFilter();
            TreeNode or_node = new TreeNode()
            {
                Text = fl.ToString(), Tag = fl
            };

            // check if the node is the root
            if (selected_node.Parent == null)
            {
                FilterTree.Nodes.Clear();
                FilterTree.Nodes.Add(or_node);
                SearchFilter = fl;
            }
            else
            {
                TreeNode pt = selected_node.Parent;
                pt.Nodes.Insert(pt.Nodes.IndexOf(selected_node), or_node);
                pt.Nodes.Remove(selected_node);

                if (pt.Tag is OrFilter)
                {
                    ((OrFilter)pt.Tag).Filters.Add(fl);
                    ((OrFilter)pt.Tag).Filters.Remove((BaseFilter)selected_node.Tag);
                }
                else if (pt.Tag is AndFilter)
                {
                    ((AndFilter)pt.Tag).Filters.Add(fl);
                    ((AndFilter)pt.Tag).Filters.Remove((BaseFilter)selected_node.Tag);
                }
            }
            fl.Filters.Add((BaseFilter)selected_node.Tag);
            or_node.Nodes.Add(selected_node);
            FilterTree.SelectedNode = selected_node;

            ShowFilterProperties((BaseFilter)selected_node.Tag);
        }
Ejemplo n.º 32
0
 public void TestOrFilter()
 {
     ContainsFilter left1 = new ContainsFilter(ConnectorAttributeBuilder.Build("foo", "bar"));
     ContainsFilter right1 = new ContainsFilter(ConnectorAttributeBuilder.Build("foo2", "bar2"));
     OrFilter v1 = new OrFilter(left1, right1);
     OrFilter v2 = (OrFilter)CloneObject(v1);
     ContainsFilter left2 = (ContainsFilter)v2.Left;
     ContainsFilter right2 = (ContainsFilter)v2.Right;
     Assert.AreEqual(left1.GetAttribute(), left2.GetAttribute());
     Assert.AreEqual(right1.GetAttribute(), right2.GetAttribute());
 }
Ejemplo n.º 33
0
        static ItemFilter ParseCategory(string category)
        {
            string[] filters = category.Split(',');
            var itemFilters = new ItemFilter[filters.Length];
            for (int i = 0; i < filters.Length; i++)
            {
                string[] orParts = filters[i].Split('|');
                ItemFilter orFilter = null;
                for (int j = 0; j < orParts.Length; j++)
                {
                    ItemFilter filter;
                    if (orParts[j].StartsWith("$$"))
                    {
                        filter = ParseSpecialCategory(orParts[j]);
                    }
                    else if (orParts[j].StartsWith("!"))
                    {
                        filter = new NotFilter(Identifier.Get(orParts[j].Substring(1)));
                    }
                    else
                    {
                        filter = new CategoryFilter(Identifier.Get(orParts[j]));
                    }

                    if (orFilter == null)
                    {
                        orFilter = filter;
                    }
                    else
                    {
                        orFilter = new OrFilter(orFilter, filter);
                    }
                }

                itemFilters[i] = orFilter;
            }

            if (itemFilters.Length == 1)
            {
                return itemFilters[0];
            }
            else
            {
                return new AndFilter(itemFilters);
            }
        }