public void SetActive_2LevelCompositePredicateChildChanged_ActivePropertyChangedEittedOnce() { int count = 0; var childFilter = new Predicate <string> { Expression = (ev) => true }; // Arrange var filter = new OrPredicate <string> { new OrPredicate <string> { new Predicate <string> { Expression = (ev) => true }, childFilter, }, new OrPredicate <string> { new Predicate <string> { Expression = (ev) => true }, new Predicate <string> { Expression = (ev) => true }, } }; filter.PropertyChanged += (sender, e) => count++; childFilter.Active = false; Assert.AreEqual(1, count); }
public void TestAndContainingOr() { var filter = new OrPredicate <string> { new Predicate <string> { Expression = (ev) => true }, new Predicate <string> { Expression = (ev) => false }, }; var filter2 = new OrPredicate <string> { new Predicate <string> { Expression = (ev) => true }, new Predicate <string> { Expression = (ev) => false }, }; var container = new AndPredicate <string> (); container.Add(filter); container.Add(filter2); Assert.IsTrue(container.Filter("")); }
public string ConvertToString(TextPredicate predicate) { ContainsPhrase_Predicate contains = predicate as ContainsPhrase_Predicate; if (contains != null) { return(this.ConvertToString(contains)); } AndPredicate and = predicate as AndPredicate; if (and != null) { return(this.ConvertToString(and)); } OrPredicate or = predicate as OrPredicate; if (or != null) { return(this.ConvertToString(or)); } NotPredicate not = predicate as NotPredicate; if (not != null) { return(this.ConvertToString(not)); } throw new Exception("Unrecognized predicate: " + predicate); }
public void TestAndContainingOrSetActive() { // Arrange var filter = new OrPredicate <string> { new Predicate <string> { Expression = (ev) => true }, new Predicate <string> { Expression = (ev) => true }, }; var filter2 = new OrPredicate <string> { new Predicate <string> { Expression = (ev) => true }, new Predicate <string> { Expression = (ev) => true }, }; var container = new AndPredicate <string> (); container.Add(filter); container.Add(filter2); // Act filter2.Active = false; // Assert Assert.IsFalse(filter2 [0].Active); Assert.IsFalse(filter2 [1].Active); Assert.IsTrue(container.Filter("")); }
private static bool ContainsEmbed(string input) { IElementPredicate predicate = new OrPredicate(new BeginTagPredicate("embed"), new BeginTagPredicate("object")); HtmlExtractor ex = new HtmlExtractor(input); return(ex.Seek(predicate).Success); }
// OrExpression := AndExpression ('or' SS AndExpression)+ private State DoParseOrExpression1Rule(State _state, List <Result> _outResults) { State _start = _state; List <Result> results = new List <Result>(); _state = DoSequence(_state, results, delegate(State s, List <Result> r) { return(DoParse(s, r, "AndExpression")); }, delegate(State s, List <Result> r) { return(DoRepetition(s, r, 1, 2147483647, delegate(State s2, List <Result> r2) { return DoSequence(s2, r2, delegate(State s3, List <Result> r3) { return DoParseLiteral(s3, r3, "or"); }, delegate(State s3, List <Result> r3) { return DoParse(s3, r3, "SS"); }, delegate(State s3, List <Result> r3) { return DoParse(s3, r3, "AndExpression"); }); })); }); if (_state.Parsed) { Predicate value = results.Count > 0 ? results[0].Value : default(Predicate); value = new OrPredicate(from e in results where e.Value != null select e.Value); _outResults.Add(new Result(this, _start.Index, _state.Index - _start.Index, m_input, value)); } else { string expected; expected = "or expression"; if (expected != null) { _state = new State(_start.Index, false, ErrorSet.Combine(_start.Errors, new ErrorSet(_state.Errors.Index, expected))); } } return(_state); }
Size FindSizeAttribute(string input) { Size size = new Size(_width, _height); if (string.IsNullOrEmpty(input)) { return(size); } try { RequiredAttribute[] attrWidth = new RequiredAttribute[] { new RequiredAttribute("width"), new RequiredAttribute("height") }; IElementPredicate predicate = new OrPredicate(new BeginTagPredicate("embed", attrWidth), new BeginTagPredicate("object", attrWidth)); HtmlExtractor ex = new HtmlExtractor(input); if (ex.Seek(predicate).Success) { BeginTag tag = (BeginTag)ex.Element; size = new Size(Convert.ToInt32(tag.GetAttributeValue("width"), CultureInfo.InvariantCulture), Convert.ToInt32(tag.GetAttributeValue("height"), CultureInfo.InvariantCulture)); } } catch (Exception ex) { Trace.Fail("Exception thrown while trying to find video size: " + ex); } return(size); }
public void TestAndContainingInactiveOr() { var filter = new OrPredicate <string> { new Predicate <string> { Expression = (ev) => true }, new Predicate <string> { Expression = (ev) => false }, }; filter.Active = false; var filter2 = new OrPredicate <string> { new Predicate <string> { Expression = (ev) => true }, new Predicate <string> { Expression = (ev) => false }, }; var container = new AndPredicate <string> (); container.Add(filter); container.Add(filter2); Assert.IsFalse(filter.Elements [0].Active); Assert.IsFalse(filter.Elements [1].Active); Assert.IsFalse(filter.Filter("")); Assert.IsTrue(filter2.Filter("")); Assert.IsTrue(container.Filter("")); }
void UpdateTeamsPredicates() { Filters.IgnoreEvents = true; TeamsPredicate.Clear(); foreach (var team in new LMTeamVM [] { homeTeamVM, awayTeamVM }) { var teamPredicate = new OrPredicate <TimelineEventVM> { Name = team.Name, }; teamPredicate.Add(new Predicate { Name = Catalog.GetString("Team"), Expression = ev => (ev.Model as LMTimelineEvent).TaggedTeams.Contains(team.Model) }); foreach (var player in team) { teamPredicate.Add(new Predicate { Name = player.Model.Name, Expression = ev => (ev.Model as LMTimelineEvent).Players.Contains(player.Model) }); } TeamsPredicate.Add(teamPredicate); } Filters.IgnoreEvents = false; RaisePropertyChanged("Collection", this); }
public async Task OrPredicateExample() { var imposter = _client.CreateTcpImposter(4553, "OrPredicateExample"); var startsWithFields = new TcpPredicateFields { Data = "start" }; var startsWith = new StartsWithPredicate <TcpPredicateFields>(startsWithFields); var endsWithFields = new TcpPredicateFields { Data = "end\n" }; var endsWith = new EndsWithPredicate <TcpPredicateFields>(endsWithFields); var containsFields = new TcpPredicateFields { Data = "middle" }; var contains = new ContainsPredicate <TcpPredicateFields>(containsFields); var predicate = new OrPredicate(new List <PredicateBase> { startsWith, endsWith, contains }); imposter.AddStub().On(predicate) .ReturnsData("matches"); await _client.SubmitAsync(imposter); }
public override void ExitOrPredicate(MiniSqlParserParser.OrPredicateContext context) { var right = (Predicate)_stack.Pop(); var comments = this.GetComments(context.K_OR()); var left = (Predicate)_stack.Pop(); var node = new OrPredicate(left, right, comments); _stack.Push(node); }
public string ConvertToString(OrPredicate predicate) { StringBuilder content = new StringBuilder(); foreach (TextPredicate child in predicate.Children) { content.Append(this.ConvertToString(child)); } return(this.ConvertToString(content.ToString(), this.Or_Tag)); }
public IPredicate <T> Build() { var builders = from item in _predicates select item.Build(); var predicate = new OrPredicate <T>(); predicate.AddPredicate(builders.ToArray()); return(predicate); }
public OrPredicate Read_OrPredicate(XmlNode nodeRepresentation) { OrPredicate predicate = new OrPredicate(); foreach (XmlNode childNode in nodeRepresentation.ChildNodes) { TextPredicate child = this.ReadTextPredicate(childNode); predicate.AddChild(child); } return(predicate); }
public void OrPredicate_Constructor_SetsPredicateCollection() { var expectedPredicates = new List <PredicateBase> { new EqualsPredicate <TestPredicateFields>(null), new MatchesPredicate <TestPredicateFields>(null), }; var predicate = new OrPredicate(expectedPredicates); Assert.AreSame(expectedPredicates, predicate.Predicates); }
protected virtual void UpdateCommonTagsPredicates() { if (Project == null) { return; } bool oldIgnoreEvents = ViewModel.Filters.IgnoreEvents; ViewModel.Filters.IgnoreEvents = true; ViewModel.CommonTagsPredicate.Clear(); var tags = Project.Dashboard.Model.CommonTagsByGroup; var listPredicates = new List <IPredicate <TimelineEventVM> > (); Expression <Func <TimelineEventVM, bool> > noTagsExpression = ev => true; foreach (var tagGroup in tags) { var tagsPredicates = new List <IPredicate <TimelineEventVM> > (); noTagsExpression = noTagsExpression.And(ev => !tagGroup.Value.Intersect(ev.Model.Tags).Any()); Expression <Func <TimelineEventVM, bool> > tagGroupExpression = ev => ev.Model.Tags.Any(tag => tag.Group == tagGroup.Key); var tagGroupPredicate = new OrPredicate <TimelineEventVM> { Name = string.IsNullOrEmpty(tagGroup.Key) ? "General tags" : tagGroup.Key, DisplayName = string.IsNullOrEmpty(tagGroup.Key) ? Catalog.GetString("General tags") : tagGroup.Key, }; tagsPredicates.Add(new Predicate { Name = "None", DisplayName = Catalog.GetString("None"), Expression = ev => !ev.Model.Tags.Any(tag => tag.Group == tagGroup.Key) }); foreach (var tag in tagGroup.Value) { tagsPredicates.Add(new Predicate { Name = tag.Value, DisplayName = tag.Value, Expression = tagGroupExpression.And(ev => ev.Model.Tags.Contains(tag)) }); } tagGroupPredicate.AddRange(tagsPredicates); listPredicates.Add(tagGroupPredicate); } ViewModel.CommonTagsPredicate.AddRange(listPredicates); ViewModel.Filters.IgnoreEvents = oldIgnoreEvents; if (!ViewModel.Filters.IgnoreEvents) { ViewModel.Filters.EmitPredicateChanged(); } }
public void TestOrFalse() { var filter = new OrPredicate <string> { new Predicate <string> { Expression = (ev) => false }, new Predicate <string> { Expression = (ev) => false }, }; Assert.IsFalse(filter.Filter("")); }
private static bool ContainsEmbedOrObject(string html) { try { IElementPredicate predicate = new OrPredicate(new BeginTagPredicate("embed"), new BeginTagPredicate("object"), new BeginTagPredicate("iframe")); HtmlExtractor ex = new HtmlExtractor(html); return(ex.Seek(predicate).Success); } catch { return(false); } }
public OpenMediaReadyAction(IProtocol protocol) : base(protocol) { base.Request = RequestCancelNotReadyForMedia.Create("chat", null); OrPredicate <IMessage> filter = new OrPredicate <IMessage>( new MessageIdFilter(EventAck.MessageId), new MessageIdFilter(EventAgentAvailable.MessageId)); filter.AddPredicate(new AgentStatusFilter("chat", 1)); base.SuccessFilter = filter; base.FailureFilter = new MessageIdFilter(EventError.MessageId); }
protected override void UpdateTeamsPredicates() { bool oldIgnoreEvents = ViewModel.Filters.IgnoreEvents; ViewModel.Filters.IgnoreEvents = true; ViewModel.TeamsPredicate.Clear(); var teamsPredicates = new List <IPredicate <TimelineEventVM> > (); LMTimelineVM lmTimeline = (LMTimelineVM)ViewModel; LMTeamVM homeTeamVM = (LMTeamVM)lmTimeline.HomeTeamTimelineVM.Team; LMTeamVM awayTeamVM = (LMTeamVM)lmTimeline.AwayTeamTimelineVM.Team; teamsPredicates.Add(new Predicate { Name = Catalog.GetString("No team / player tagged"), Expression = ev => (!(ev.Model as LMTimelineEvent).Teams.Any() && !(ev.Model as LMTimelineEvent).Players.Any()) }); foreach (var team in new LMTeamVM [] { homeTeamVM, awayTeamVM }) { var playersPredicates = new List <IPredicate <TimelineEventVM> > (); var teamPredicate = new OrPredicate <TimelineEventVM> { Name = team.Name, }; playersPredicates.Add(new Predicate { Name = Catalog.GetString("Team tagged"), Expression = ev => (ev.Model as LMTimelineEvent).Teams.Contains(team.Model) }); foreach (var player in team) { playersPredicates.Add(new Predicate { Name = player.Model.Name, Expression = ev => (ev.Model as LMTimelineEvent).Players.Contains(player.Model) }); } teamPredicate.AddRange(playersPredicates); teamsPredicates.Add(teamPredicate); } ViewModel.TeamsPredicate.AddRange(teamsPredicates); ViewModel.Filters.IgnoreEvents = oldIgnoreEvents; if (!ViewModel.Filters.IgnoreEvents) { ViewModel.Filters.EmitPredicateChanged(); } }
private void OrButton_Clicked(object sender, EventArgs e) { OrPredicate or = new OrPredicate(); TextPredicate child = this.getPendingChildPredicate(); if (child != null) { or.AddChild(child); this.openPredicates.Add(or); } else { this.addChild(or); } this.updateLayout(); }
/// <summary> /// Parser for OrPredicate /// </summary> /// <returns>Parsed OrPredicate</returns> public OrPredicate ParseOrPredicate(Predicate parsedLeftPredicate) { OrPredicate orPredicate = new OrPredicate(); //Add left predicate orPredicate.SetLeftPredicate(parsedLeftPredicate); //Skip || tokens NextToken("|", "predicate || predicate", '|'); NextToken("|", "predicate || predicate", '|'); //Parse right predicate orPredicate.SetRightPredicate(ParsePredicate()); return(orPredicate); }
public void TestAndContainingEmptyOr() { var filter = new OrPredicate <string> { new Predicate <string> { Expression = PredicateBuilder.True <string>() }, }; // This OR doesn't have any active Predicate, thus it's ignored var filter2 = new OrPredicate <string> (); var container = new AndPredicate <string> (); container.Add(filter); container.Add(filter2); Assert.IsTrue(container.Filter("")); }
public void TestElementsEvents() { // Arrange string property = ""; int count = 0; int countElements = 0; var filter = new OrPredicate <string> { new Predicate <string> { Expression = (ev) => true }, new Predicate <string> { Expression = (ev) => false }, }; var filter2 = new OrPredicate <string> { new Predicate <string> { Expression = (ev) => true }, new Predicate <string> { Expression = (ev) => false }, }; var container = new AndPredicate <string> (); container.Elements.CollectionChanged += (sender, e) => { countElements++; }; container.PropertyChanged += (sender, e) => { property = e.PropertyName; count++; }; // Act container.Add(filter); container.Add(filter2); //Assert Assert.AreEqual("Collection_Elements", property); Assert.AreEqual(2, count); Assert.AreEqual(count, countElements); }
// add the given predicate as a child of the leafmost existing predicate private void addChild(TextPredicate predicate) { if (this.openPredicates.Count < 1) { // no predicates already exist, this one becomes the primary one this.openPredicates.Add(predicate); return; } TextPredicate last = this.openPredicates.Last(); OrPredicate or = last as OrPredicate; if (or != null) { // we have a pending 'or'; add it here or.AddChild(predicate); return; } AndPredicate and = last as AndPredicate; if (and != null) { // we have a pending 'and'; add it here and.AddChild(predicate); return; } NotPredicate not = last as NotPredicate; if (not != null) { // we have a pending 'not'; add it here not.Child = predicate; return; } if (last == null) { // We have an empty spot to add this predicate to // This user is expected to attach this to a parent later // If the user doesn't attach this to a parent later, we will for them this.openPredicates.RemoveAt(this.openPredicates.Count - 1); this.openPredicates.Add(predicate); return; } // error; do nothing }
public void TestAndOrEmpty() { // Arrange var filter = new OrPredicate <string> (); var filter2 = new OrPredicate <string> (); var container = new AndPredicate <string> (); container.Add(filter); container.Add(filter2); // Act // Assert Assert.IsFalse(filter.Active); Assert.IsFalse(filter2.Active); Assert.IsFalse(container.Active); Assert.IsTrue(container.Filter("")); }
public void SetActive_1LevelCompositePredicateActiveNotChanged_ActivePropertyChangedEittedOnce() { int count = 0; // Arrange var filter = new OrPredicate <string> { new Predicate <string> { Expression = (ev) => true }, new Predicate <string> { Expression = (ev) => true }, }; filter.PropertyChanged += (sender, e) => count++; filter.Active = true; Assert.AreEqual(0, count); }
public void TestOrEvents() { // Arrange string property = ""; int count = 0; var filter = new OrPredicate <string> (); filter.PropertyChanged += (sender, e) => { property = e.PropertyName; count++; }; // Act filter.Add(new Predicate <string> { Expression = (ev) => true }); //Assert Assert.AreEqual("Collection_Elements", property); Assert.AreEqual(1, count); }
public void ParseOrPredicateTest() { //Create parser PredicateParser predicateParser = new PredicateParser(Init("condition1 || condition2 || condition3")); Predicate parsedPredicate = predicateParser.ParsePredicate(); //Check Predicates Assert.AreEqual(typeof(OrPredicate), parsedPredicate.GetType()); //Check OrPredicate OrPredicate parsedOrPredicate = (OrPredicate)parsedPredicate; Assert.AreEqual(typeof(ExpressionPredicate), parsedOrPredicate.GetLeftPredicate().GetType()); Assert.AreEqual(typeof(OrPredicate), parsedOrPredicate.GetRightPredicate().GetType()); //Check nested OrPredicate OrPredicate parsedNestedOrPredicate = (OrPredicate)parsedOrPredicate.GetRightPredicate(); Assert.AreEqual(typeof(ExpressionPredicate), parsedNestedOrPredicate.GetLeftPredicate().GetType()); Assert.AreEqual(typeof(ExpressionPredicate), parsedNestedOrPredicate.GetRightPredicate().GetType()); }
public void TestActiveEvents() { // Arrange string property = ""; int count = 0; var filter = new OrPredicate <string> (); var predicate = new Predicate <string> { Expression = (ev) => true }; filter.Add(predicate); filter.PropertyChanged += (sender, e) => { property = e.PropertyName; count++; }; // Act predicate.Active = false; //Assert Assert.AreEqual("Active", property); Assert.AreEqual(1, count); }