public void FirstTestName() { var route = new RouteNode<Uri>(new StubRoute<Uri>()); var joinNode = new JoinNode<Uri>(_id++, new ConstantNode<Uri>()); joinNode.Add(route); var alpha = new AlphaNode<Uri>(_id++); alpha.Add(joinNode); var equal = new EqualNode<Uri>(() => _id++); equal.Add("version", alpha); var segment = new SegmentNode<Uri>(1); segment.Add(equal); var engine = new MagnumRoutingEngine<Uri>(x => x); engine.Match<RootNode<Uri>>().Single().Add(segment); bool called = false; var uri = new Uri("http://localhost/version"); engine.Route(uri, x => { called = true; }); called.ShouldBeTrue(); }
protected virtual bool Visit <T>(AlphaNode <T> node) { IncreaseDepth(); node.Successors.Each(activation => Visit(activation)); DecreaseDepth(); return(true); }
public void AddActivation <TParent>(OdoyuleRulesEngine rulesEngine, AlphaNode <TParent> activation) where TParent : class { AlphaNode <T> alphaNode = rulesEngine.GetAlphaNode <T>(); RunLocator(activation, alphaNode); }
public void FirstTestName() { var route = new RouteNode <Uri>(new StubRoute <Uri>()); var joinNode = new JoinNode <Uri>(_id++, new ConstantNode <Uri>()); joinNode.Add(route); var alpha = new AlphaNode <Uri>(_id++); alpha.Add(joinNode); var equal = new EqualNode <Uri>(() => _id++); equal.Add("version", alpha); var segment = new SegmentNode <Uri>(1); segment.Add(equal); var engine = new MagnumRoutingEngine <Uri>(x => x); engine.Match <RootNode <Uri> >().Single().Add(segment); bool called = false; var uri = new Uri("http://localhost/version"); engine.Route(uri, x => { called = true; }); called.ShouldBeTrue(); }
public void Setup() { _called = null; var configurator = new RuntimeConfiguratorImpl(); var productionNode = new DelegateProductionNode <A>(16, (session, x) => _called = x); var constantNode = new ConstantNode <A>(42); var joinNode = configurator.CreateNode(id => new JoinNode <A>(id, constantNode)); var constantNode2 = new ConstantNode <A>(27); var joinNode2 = configurator.CreateNode(id => new JoinNode <A>(id, constantNode2)); joinNode2.AddActivation(productionNode); joinNode.AddActivation(joinNode2); var engine = new OdoyuleRulesEngine(configurator); AlphaNode <A> alphaNode = engine.GetAlphaNode <A>(); alphaNode.AddActivation(joinNode); using (StatefulSession session = engine.CreateSession()) { session.Add(new A()); session.Run(); } }
protected override bool Visit <T>(AlphaNode <T> node) { _current = GetVertex(node.GetHashCode(), () => "\u03B1", typeof(AlphaNode <>), typeof(T)); LinkFromParent(); return(WithVertex(() => base.Visit(node))); }
protected override void VisitAlphaNode(SchemaBuilder builder, AlphaNode node) { builder.AddLinks(node, node.ChildNodes); if (node.MemoryNode != null) { builder.AddLink(node, node.MemoryNode); } base.VisitAlphaNode(builder, node); }
public void Only_those_that_are_matched_should_be_called() { var junction = new JoinNode <Customer>(_constantNode); junction.AddSuccessor(_actionNode); var alphaNodeA = new AlphaNode <Customer>(); alphaNodeA.AddSuccessor(junction); var joinJunction = new JoinNode <Customer>(alphaNodeA); var alphaNodeB = new AlphaNode <Customer>(); alphaNodeB.AddSuccessor(joinJunction); var actionNode = new ActionNode <Customer>(x => _secondaryCalled.Complete(x.Element.Object)); var joinJunction2 = new JoinNode <Customer>(alphaNodeA); joinJunction2.AddSuccessor(actionNode); var alphaNodeC = new AlphaNode <Customer>(); alphaNodeC.AddSuccessor(joinJunction2); var tree = new TypeNode <Customer>(); var isPreferred = new ConditionNode <Customer>(x => x.Preferred); isPreferred.AddSuccessor(alphaNodeA); tree.AddSuccessor(isPreferred); tree.AddSuccessor(alphaNodeB); var isActive = new ConditionNode <Customer>(x => x.Active); isActive.AddSuccessor(alphaNodeC); tree.AddSuccessor(isActive); var visitor = new StringNodeVisitor(); tree.Visit(visitor); Trace.WriteLine(visitor.Result); tree.Activate(_context); _session.Run(); _primaryCalled.IsCompleted.ShouldBeTrue(); _secondaryCalled.IsCompleted.ShouldBeFalse(); }
protected virtual void VisitAlphaNode(TContext builder, AlphaNode node) { foreach (var childNode in node.ChildNodes) { Visit(builder, childNode); } if (node.MemoryNode != null) { Visit(builder, node.MemoryNode); } }
public override bool Visit <T>(AlphaNode <T> node, Func <RuntimeModelVisitor, bool> next) { _current = _vertices.Get(node.Id, id => new Vertex(typeof(AlphaNode <>), typeof(T), typeof(T).Tokens())); if (_stack.Count > 0) { _edges.Add(new Edge(_stack.Peek(), _current, _current.TargetType.Name)); } return(Next(() => base.Visit(node, next))); }
protected override bool Visit <TChannel>(AlphaNode <TChannel> node) { var match = node as AlphaNode <T>; if (match != null) { _alpha = match; return(false); } return(base.Visit(node)); }
public override bool Visit <TT>(AlphaNode <TT> node, Func <RuntimeModelVisitor, bool> next) { var locator = this as AlphaNodeSelector <TT>; if (locator != null) { locator._node = node; return(false); } return(base.Visit(node, next)); }
Activation CreateMissingAlphaNode <T>(Type type) where T : class { AlphaNode <T> alphaNode = _configurator.CreateNode(id => new AlphaNode <T>(id)); foreach (Type nestedType in GetActivationTypes(typeof(T))) { _initializers[nestedType].AddActivation(this, alphaNode); } return(alphaNode); }
public void Detach() { if (this.left != null) { this.left.right = null; } if (this.right != null) { this.right.left = null; } this.left = null; this.right = null; }
public void One_more_level_of_indirection() { var junction = new JoinNode<Customer>(_constantNode); junction.AddSuccessor(_actionNode); var alphaNode = new AlphaNode<Customer>(); alphaNode.AddSuccessor(junction); alphaNode.Activate(_context); _session.Run(); _primaryCalled.IsCompleted.ShouldBeTrue(); }
void Bind(Action <AlphaNode <T> > callback) { if (_alpha == null) { if (_root == null) { throw new InvalidOperationException("The root node was not found."); } _alpha = _root.GetAlphaNode <T>(); } callback(_alpha); }
public void AddRoutes(IEnumerable <string> paths) { foreach (string path in paths) { var route = new RouteNode <Uri>(new StubRoute <Uri>()); var joinNode = new JoinNode <Uri>(_id++, new ConstantNode <Uri>()); joinNode.Add(route); var alpha = new AlphaNode <Uri>(_id++); alpha.Add(joinNode); _equal.Add(path.Substring(1), alpha); } }
public void AddRoutes(IEnumerable<string> paths) { foreach (string path in paths) { var route = new RouteNode<Uri>(new StubRoute<Uri>()); var joinNode = new JoinNode<Uri>(_id++, new ConstantNode<Uri>()); joinNode.Add(route); var alpha = new AlphaNode<Uri>(_id++); alpha.Add(joinNode); _equal.Add(path.Substring(1), alpha); } }
public void testOneSlot() { Defclass dc = new Defclass(typeof(TestBean2)); Deftemplate dtemp = dc.createDeftemplate("testBean2"); TestBean2 bean = new TestBean2(); Slot[] slts = dtemp.AllSlots; ObjectTypeNode otn = new ObjectTypeNode(1, dtemp); AlphaNode an = new AlphaNode(1); slts[0].Value = ConversionUtils.convert(110); an.Operator = Constants.EQUAL; an.Slot = (slts[0]); Console.WriteLine("node::" + an.ToString()); Assert.IsNotNull(an.ToString(), "Should have a value."); }
void RunLocator <TParent>(AlphaNode <TParent> activation, AlphaNode <T> alphaNode) where TParent : class { Type type = typeof(WidenTypeNodeLocator <,>).MakeGenericType(typeof(TParent), typeof(T)); var locator = (NodeLocator)Activator.CreateInstance(type, activation, alphaNode); bool found = locator.Find(); if (!found) { throw new InternalRulesEngineException("Unable to widen type " + typeof(TParent).GetShortName() + " to type " + typeof(T).GetShortName()); } }
public void One_more_level_of_indirection() { var junction = new JoinNode <Customer>(_constantNode); junction.AddSuccessor(_actionNode); var alphaNode = new AlphaNode <Customer>(); alphaNode.AddSuccessor(junction); alphaNode.Activate(_context); _session.Run(); _primaryCalled.IsCompleted.ShouldBeTrue(); }
public void Only_those_that_are_matched_should_be_called() { var junction = new JoinNode<Customer>(_constantNode); junction.AddSuccessor(_actionNode); var alphaNodeA = new AlphaNode<Customer>(); alphaNodeA.AddSuccessor(junction); var joinJunction = new JoinNode<Customer>(alphaNodeA); var alphaNodeB = new AlphaNode<Customer>(); alphaNodeB.AddSuccessor(joinJunction); var actionNode = new ActionNode<Customer>(x => _secondaryCalled.Complete(x.Element.Object)); var joinJunction2 = new JoinNode<Customer>(alphaNodeA); joinJunction2.AddSuccessor(actionNode); var alphaNodeC = new AlphaNode<Customer>(); alphaNodeC.AddSuccessor(joinJunction2); var tree = new TypeNode<Customer>(); var isPreferred = new ConditionNode<Customer>(x => x.Preferred); isPreferred.AddSuccessor(alphaNodeA); tree.AddSuccessor(isPreferred); tree.AddSuccessor(alphaNodeB); var isActive = new ConditionNode<Customer>(x => x.Active); isActive.AddSuccessor(alphaNodeC); tree.AddSuccessor(isActive); var visitor = new StringNodeVisitor(); tree.Visit(visitor); Trace.WriteLine(visitor.Result); tree.Activate(_context); _session.Run(); _primaryCalled.IsCompleted.ShouldBeTrue(); _secondaryCalled.IsCompleted.ShouldBeFalse(); }
public void Pulling_an_element_through_two_memories_should_merge_properly() { var junction = new JoinNode <Customer>(_constantNode); junction.AddSuccessor(_actionNode); var alphaNodeA = new AlphaNode <Customer>(); alphaNodeA.AddSuccessor(junction); var joinJunction = new JoinNode <Customer>(alphaNodeA); var alphaNodeB = new AlphaNode <Customer>(); alphaNodeB.AddSuccessor(joinJunction); alphaNodeA.Activate(_context); alphaNodeB.Activate(_context); _session.Run(); }
public void Setup() { _called = null; var configurator = new RuntimeConfiguratorImpl(); var engine = configurator.RulesEngine; PropertyNode <A, decimal> propertyNode = configurator.Property <A, decimal>(x => x.Amount); ConditionNode <Token <A, decimal> > conditionNode = configurator.Condition <A, decimal>(x => x > 10000.0m); propertyNode.AddActivation(conditionNode); AlphaNode <Token <A, decimal> > edgeAlpha = configurator.Alpha <A, decimal>(); conditionNode.AddActivation(edgeAlpha); AlphaNode <A> alphaNode = configurator.GetAlphaNode <A>(); alphaNode.AddActivation(propertyNode); JoinNode <A> joinNode = configurator.Join(alphaNode); DelegateProductionNode <A> productionNode = configurator.Delegate <A>((session, x) => _called = x); joinNode.AddActivation(productionNode); LeftJoinNode <A, decimal> leftNode = configurator.Left <A, decimal>(alphaNode); leftNode.AddActivation(joinNode); edgeAlpha.AddActivation(leftNode); using (StatefulSession session = engine.CreateSession()) { session.Add(new A(10001.0m)); session.Run(); } }
public void Setup() { _called = null; var configurator = new OdoyuleRuntimeConfigurator(); var productionNode = new DelegateProductionNode <Tuple <A, B> >(16, (session, x) => _called = x); var constantNode = new ConstantNode <A>(42); JoinNode <A> joinNodeA = configurator.CreateNode(id => new JoinNode <A>(id, constantNode)); var constantNode2 = new ConstantNode <B>(27); JoinNode <B> joinNodeB = configurator.CreateNode(id => new JoinNode <B>(id, constantNode2)); OuterJoinNode <A, B> outerJoinNode = configurator.CreateNode(id => new OuterJoinNode <A, B>(id, joinNodeB)); outerJoinNode.AddActivation(productionNode); joinNodeA.AddActivation(outerJoinNode); var engine = new OdoyuleRulesEngine(configurator); AlphaNode <A> alphaNode = engine.GetAlphaNode <A>(); alphaNode.AddActivation(joinNodeA); AlphaNode <B> alphaNodeB = engine.GetAlphaNode <B>(); alphaNodeB.AddActivation(joinNodeB); using (Session session = engine.CreateSession()) { session.Add(new A()); session.Add(new B()); session.Run(); } }
public void Select <TNode>(MemoryNode <TNode> node) where TNode : class { _node = null; node.Accept(this); if (_node == null) { AlphaNode <T> alphaNode = _configurator.Alpha <T>(); var parentNode = node as MemoryNode <T>; if (parentNode == null) { throw new ArgumentException("Expected " + typeof(Node <T>).FullName + ", but was " + node.GetType().FullName); } parentNode.AddActivation(alphaNode); _node = alphaNode; } _next.Select(_node); }
public void Select <TNode>(Node <TNode> node) where TNode : class { _node = null; node.Accept(this); if (_node == null) { AlphaNode <T> alphaNode = _configurator.Alpha <T>(); var parentNode = node as Node <T>; if (parentNode == null) { throw new ArgumentException("Expected " + typeof(T).Tokens() + ", but was " + typeof(TNode).Tokens()); } parentNode.AddActivation(alphaNode); _node = alphaNode; } _next.Select(_node); }
public void Setup() { _called = null; var productionNode = new DelegateProductionNode <A>(16, (session, x) => _called = x); var constantNode = new ConstantNode <A>(42); var joinNode = new JoinNode <A>(69, constantNode); joinNode.AddActivation(productionNode); var engine = new OdoyuleRulesEngine(new OdoyuleRuntimeConfigurator()); AlphaNode <A> alphaNode = engine.GetAlphaNode <A>(); alphaNode.AddActivation(joinNode); using (Session session = engine.CreateSession()) { session.Add(new A()); session.Run(); } }
public void testTwoSlots() { Defclass dc = new Defclass(typeof(TestBean2)); Deftemplate dtemp = dc.createDeftemplate("testBean2"); TestBean2 bean = new TestBean2(); Slot[] slts = dtemp.AllSlots; ObjectTypeNode otn = new ObjectTypeNode(1, dtemp); AlphaNode an1 = new AlphaNode(1); AlphaNode an2 = new AlphaNode(1); slts[0].Value = ("testString"); slts[1].Value = (ConversionUtils.convert(999)); an1.Slot = (slts[0]); an1.Operator = (Constants.EQUAL); Console.WriteLine("node::" + an1.toPPString()); Assert.IsNotNull(an1.toPPString()); an2.Slot = (slts[1]); an2.Operator = (Constants.GREATER); Console.WriteLine("node::" + an2.toPPString()); Assert.IsNotNull(an2.toPPString()); }
public override bool Visit <T>(AlphaNode <T> node, Func <RuntimeVisitor, bool> next) { Append("AlphaNode[{0}]", Tokens <T>()); return(Indent(next)); }
public void Link(AlphaNode r) { this.right = r; r.left = this; }
void VisitAndBind(AlphaNode <T> alphaNode, Action <JoinNode <T> > callback) { Visit(alphaNode); Bind(callback); }
public MatchJoinNode(AlphaNode <T> alphaNode, Action <JoinNode <T> > callback) { _alphaNode = alphaNode; VisitAndBind(alphaNode, callback); }
public void Select() { AlphaNode <T> alphaNode = _configurator.GetAlphaNode <T>(); _next.Select(alphaNode); }
public void Pulling_an_element_through_two_memories_should_merge_properly() { var junction = new JoinNode<Customer>(_constantNode); junction.AddSuccessor(_actionNode); var alphaNodeA = new AlphaNode<Customer>(); alphaNodeA.AddSuccessor(junction); var joinJunction = new JoinNode<Customer>(alphaNodeA); var alphaNodeB = new AlphaNode<Customer>(); alphaNodeB.AddSuccessor(joinJunction); alphaNodeA.Activate(_context); alphaNodeB.Activate(_context); _session.Run(); }