Пример #1
0
        private List <DebugVariable> TupleToVariables(MsgFrame frame)
        {
            var           variables = new List <DebugVariable>();
            NodeDebugInfo node      = null;
            RuleDebugInfo rule      = null;

            if (frame.NodeId != 0)
            {
                node = DebugInfo.Nodes[frame.NodeId];
                if (node.RuleId != 0)
                {
                    rule = DebugInfo.Rules[node.RuleId];
                }
            }

            for (var i = 0; i < frame.Tuple.Column.Count; i++)
            {
                var value    = frame.Tuple.Column[i];
                var variable = new DebugVariable
                {
                    Name = Formatter.TupleVariableIndexToName(rule, node, i),
                    // TODO type name!
                    Type       = value.TypeId.ToString(),
                    Value      = Formatter.ValueToString(value),
                    TypedValue = value
                };

                variables.Add(variable);
            }

            return(variables);
        }
Пример #2
0
        private NodeDebugInfo FromProtobuf(NodeDebugInfoMsg msg)
        {
            var debugInfo = new NodeDebugInfo
            {
                Id     = msg.Id,
                RuleId = msg.RuleId,
                Line   = (Int32)msg.Line,
                ColumnToVariableMaps = new Dictionary <int, int>(),
                DatabaseId           = msg.DatabaseId,
                Name         = msg.Name,
                Type         = (LSLib.LS.Story.Node.Type)msg.Type,
                ParentNodeId = msg.ParentNodeId
            };

            if (msg.FunctionName != "")
            {
                debugInfo.FunctionName = new FunctionNameAndArity(msg.FunctionName, (int)msg.FunctionArity);
            }

            foreach (var map in msg.ColumnMaps)
            {
                debugInfo.ColumnToVariableMaps.Add((Int32)map.Key, (Int32)map.Value);
            }

            return(debugInfo);
        }
Пример #3
0
        private void AddLineMapping(LineType type, GoalDebugInfo goal, NodeDebugInfo node, UInt32 index, UInt32 line)
        {
            GoalLineMap goalMap;

            if (!GoalMap.TryGetValue(goal.Name, out goalMap))
            {
                goalMap = new GoalLineMap
                {
                    Goal    = goal,
                    LineMap = new Dictionary <uint, LineDebugInfo>()
                };
                GoalMap.Add(goal.Name, goalMap);
            }

            var mapping = new LineDebugInfo
            {
                Type        = type,
                Goal        = goal,
                Node        = node,
                ActionIndex = index,
                Line        = line
            };

            goalMap.LineMap[line] = mapping;
        }
Пример #4
0
        public BenchmarkLhsExpression()
        {
            _nodeInfo = new NodeDebugInfo();
            Expression <Func <string, int, decimal, bool> > betaExpression = (s, i, d) => s.Length == i;
            var betaElement = Element.Condition(betaExpression);

            _lhsExpression      = ExpressionCompiler.CompileLhsTupleFactExpression <bool>(betaElement, betaElement.Imports.ToList());
            _lhsTupleExpression = ExpressionCompiler.CompileLhsTupleExpression <bool>(betaElement, betaElement.Imports.ToList());
            _tuple = ToTuple("abcd", 4, 1.0m);

            Expression <Func <string, bool> > alphaExpression = s => s.Length == 1;
            var alphaElement = Element.Condition(alphaExpression);

            _lhsFactExpression = ExpressionCompiler.CompileLhsFactExpression <bool>(alphaElement);
            _fact = new Fact("abcd");
        }
        static WorldGraph CreateTestGraph(out NodePerlinNoise2D perlinNode, out NodeDebugInfo debugNode)
        {
            var graph = GraphBuilder.NewGraph <WorldGraph>()
                        .NewNode(typeof(NodePerlinNoise2D), "perlin")
                        .NewNode(typeof(NodeDebugInfo), "debug")
                        .Link("perlin", "debug")
                        .Execute()
                        .GetGraph() as WorldGraph;

            perlinNode = graph.FindNodeByName <NodePerlinNoise2D>("perlin");
            debugNode  = graph.FindNodeByName <NodeDebugInfo>("debug");

            graph.chunkSize     = 64;
            graph.step          = .5f;
            graph.chunkPosition = new Vector3(10, 42, -7);
            graph.seed          = 123456789;

            return(graph as WorldGraph);
        }
Пример #6
0
        public static void PerlinNoiseToDebugNodeExecution()
        {
            string perlinNodeName = "perlin";
            string debugNodeName  = "debug";
            var    graph          = GraphBuilder.NewGraph <WorldGraph>()
                                    .NewNode <NodePerlinNoise2D>(perlinNodeName)
                                    .NewNode <NodeDebugInfo>(debugNodeName)
                                    .Link(perlinNodeName, debugNodeName)
                                    .Execute()
                                    .GetGraph();

            NodePerlinNoise2D perlinNode = graph.FindNodeByName(perlinNodeName) as NodePerlinNoise2D;
            NodeDebugInfo     debugNode  = graph.FindNodeByName(debugNodeName) as NodeDebugInfo;

            Assert.That(perlinNode != null, "Perlin node not found in the graph (using FindNodeByName)");
            Assert.That(debugNode != null, "Debug node not found in the graph (using FindNodeByName)");

            NodeLink link = perlinNode.GetOutputLinks().First();

            Assert.That(link != null, "Link can't be found in the graph");
            Assert.That(link.toNode == debugNode);
        }
Пример #7
0
        private void BuildLineMap(NodeDebugInfo node)
        {
            if (node.RuleId != 0)
            {
                var rule = DebugInfo.Rules[node.RuleId];
                var goal = DebugInfo.Goals[rule.GoalId];

                if (node.Line != 0 &&
                    node.Type != LSLib.LS.Story.Node.Type.Rule)
                {
                    AddLineMapping(LineType.NodeLine, goal, node, 0, (UInt32)node.Line);
                }

                if (node.Type == LSLib.LS.Story.Node.Type.Rule)
                {
                    for (var index = 0; index < rule.Actions.Count; index++)
                    {
                        AddLineMapping(LineType.RuleActionLine, goal, node, (UInt32)index, rule.Actions[index].Line);
                    }
                }
            }
        }
        private NodeDebugInfoMsg ToProtobuf(NodeDebugInfo debugInfo)
        {
            var msg = new NodeDebugInfoMsg
            {
                Id            = debugInfo.Id,
                RuleId        = debugInfo.RuleId,
                Line          = (UInt32)debugInfo.Line,
                DatabaseId    = debugInfo.DatabaseId,
                Name          = debugInfo.Name,
                Type          = (NodeDebugInfoMsg.Types.NodeType)debugInfo.Type,
                ParentNodeId  = debugInfo.ParentNodeId,
                FunctionName  = debugInfo.FunctionName != null ? debugInfo.FunctionName.Name : "",
                FunctionArity = debugInfo.FunctionName != null ? (uint)debugInfo.FunctionName.Arity : 0
            };

            foreach (var map in debugInfo.ColumnToVariableMaps)
            {
                msg.ColumnMaps.Add((UInt32)map.Key, (UInt32)map.Value);
            }

            return(msg);
        }
 public String TupleVariableIndexToName(RuleDebugInfo rule, NodeDebugInfo node, int index)
 {
     if (rule == null)
     {
         return("#" + index.ToString());
     }
     else if (node != null)
     {
         if (index < node.ColumnToVariableMaps.Count)
         {
             var mappedColumnIdx = node.ColumnToVariableMaps[index];
             if (mappedColumnIdx < rule.Variables.Count)
             {
                 return(rule.Variables[mappedColumnIdx].Name);
             }
             else
             {
                 return(String.Format("(Bad Variable Idx #{0})", index));
             }
         }
         else
         {
             return(String.Format("(Unknown #{0})", index));
         }
     }
     else
     {
         if (index < rule.Variables.Count)
         {
             return(rule.Variables[index].Name);
         }
         else
         {
             return(String.Format("(Bad Variable Idx #{0})", index));
         }
     }
 }
Пример #10
0
 internal AggregationContext(IExecutionContext executionContext, NodeDebugInfo nodeInfo)
 {
     ExecutionContext = executionContext;
     NodeInfo         = nodeInfo;
 }
Пример #11
0
        public void RaiseLhsExpressionFailed(ISession session, Exception exception, Expression expression, IArgumentMap argumentMap, Tuple tuple, Fact fact, NodeDebugInfo nodeInfo, ref bool isHandled)
        {
            var handler = LhsExpressionFailedEvent;

            if (handler != null)
            {
                var arguments = new LhsExpressionArguments(argumentMap, tuple, fact);
                var @event    = new LhsExpressionErrorEventArgs(expression, exception, arguments, tuple, fact, nodeInfo.Rules);
                handler(session, @event);
                isHandled |= @event.IsHandled;
            }
            _parent?.RaiseLhsExpressionFailed(session, exception, expression, argumentMap, tuple, fact, nodeInfo, ref isHandled);
        }
Пример #12
0
        public void RaiseLhsExpressionEvaluated(ISession session, Exception exception, Expression expression, IArgumentMap argumentMap, object result, Tuple tuple, Fact fact, NodeDebugInfo nodeInfo)
        {
            var handler = LhsExpressionEvaluatedEvent;

            if (handler != null)
            {
                var arguments = new LhsExpressionArguments(argumentMap, tuple, fact);
                var @event    = new LhsExpressionEventArgs(expression, exception, arguments, result, tuple, fact, nodeInfo.Rules);
                handler(session, @event);
            }
            _parent?.RaiseLhsExpressionEvaluated(session, exception, expression, argumentMap, result, tuple, fact, nodeInfo);
        }
Пример #13
0
 internal AggregationContext(ISessionInternal session, IEventAggregator eventAggregator, NodeDebugInfo nodeInfo)
 {
     Session         = session;
     EventAggregator = eventAggregator;
     NodeInfo        = nodeInfo;
 }
 public override void OnNodeEnable()
 {
     node = target as NodeDebugInfo;
 }