public override void Assign(object value, IGraphProcessingEnvironment procEnv)
        {
            IGraphElement elem        = (IGraphElement)GraphElementVar.GetVariableValue(procEnv);
            int           visitedFlag = VisitedFlagExpression != null ? (int)VisitedFlagExpression.Evaluate(procEnv) : 0;

            procEnv.Graph.SetVisited(elem, visitedFlag, (bool)value);
        }
        public override void Assign(object value, IGraphProcessingEnvironment procEnv)
        {
            object container = DestVar.GetVariableValue(procEnv);
            object key       = KeyExpression.Evaluate(procEnv);

            if (container is IList)
            {
                IList array = (IList)container;
                if (array.Count > (int)key)
                {
                    array[(int)key] = value;
                }
            }
            else if (container is IDeque)
            {
                IDeque deque = (IDeque)container;
                if (deque.Count > (int)key)
                {
                    deque[(int)key] = value;
                }
            }
            else
            {
                IDictionary map = (IDictionary)container;
                if (map.Contains(key))
                {
                    map[key] = value;
                }
            }
        }
Ejemplo n.º 3
0
        protected static EdgeType GetEdgeType(IGraphProcessingEnvironment procEnv, SequenceExpression edgeTypeExpr, string functionName)
        {
            EdgeType edgeType = null;

            if (edgeTypeExpr != null) // often incident edge
            {
                object tmp = edgeTypeExpr.Evaluate(procEnv);
                if (tmp is string)
                {
                    edgeType = procEnv.Graph.Model.EdgeModel.GetType((string)tmp);
                }
                else if (tmp is EdgeType)
                {
                    edgeType = (EdgeType)tmp;
                }
                if (edgeType == null)
                {
                    throw new Exception("edge type argument to " + functionName + " is not an edge type");
                }
            }
            else
            {
                edgeType = procEnv.Graph.Model.EdgeModel.RootType;
            }

            return(edgeType);
        }
Ejemplo n.º 4
0
        protected static NodeType GetNodeType(IGraphProcessingEnvironment procEnv, SequenceExpression nodeTypeExpr, string functionName)
        {
            NodeType nodeType = null;

            if (nodeTypeExpr != null) // often adjacent node
            {
                object tmp = nodeTypeExpr.Evaluate(procEnv);
                if (tmp is string)
                {
                    nodeType = procEnv.Graph.Model.NodeModel.GetType((string)tmp);
                }
                else if (tmp is NodeType)
                {
                    nodeType = (NodeType)tmp;
                }
                if (nodeType == null)
                {
                    throw new Exception("node type argument to " + functionName + " is not a node type");
                }
            }
            else
            {
                nodeType = procEnv.Graph.Model.NodeModel.RootType;
            }

            return(nodeType);
        }
Ejemplo n.º 5
0
        public override void Assign(object value, IGraphProcessingEnvironment procEnv)
        {
            IGraphElement elem = (IGraphElement)DestVar.GetVariableValue(procEnv);
            object container = elem.GetAttribute(AttributeName);
            object key = KeyExpression.Evaluate(procEnv);
            AttributeType attrType = elem.Type.GetAttributeType(AttributeName);

            BaseGraph.ChangingAttributeAssignElement(procEnv.Graph, elem, attrType, value, key);

            if(container is IList)
            {
                IList array = (IList)container;
                array[(int)key] = value;
            }
            else if(container is IDeque)
            {
                IDeque deque = (IDeque)container;
                deque[(int)key] = value;
            }
            else
            {
                IDictionary map = (IDictionary)container;
                map[key] = value;
            }

            BaseGraph.ChangedAttribute(procEnv.Graph, elem, attrType);
        }
Ejemplo n.º 6
0
        public object EvaluateGraphRewriteSequenceExpression(SequenceExpression sequenceExpression)
        {
            PerformanceInfo.Start();

            object res = sequenceExpression.Evaluate(this);

            PerformanceInfo.Stop();
            return(res);
        }
 public override void Assign(object value, IGraphProcessingEnvironment procEnv)
 {
     ContainerHelper.AssignAttributeIndexed(DestVar.GetVariableValue(procEnv), KeyExpression.Evaluate(procEnv),
                                            value, AttributeName, procEnv.Graph);
 }
Ejemplo n.º 8
0
        public SubruleDebuggingDecision Decide(SubruleDebuggingEvent sde, object data, IGraphProcessingEnvironment procEnv)
        {
            if (!enabled)
            {
                return(SubruleDebuggingDecision.Undefined);
            }
            if (debuggingEvent != sde)
            {
                return(SubruleDebuggingDecision.Undefined);
            }

            switch (sde)
            {
            case SubruleDebuggingEvent.Add:
            case SubruleDebuggingEvent.Rem:
            case SubruleDebuggingEvent.Emit:
            case SubruleDebuggingEvent.Halt:
            case SubruleDebuggingEvent.Highlight:
            {
                string message = (string)data;
                switch (messageMatchingMode)
                {
                case SubruleMesssageMatchingMode.Equals:
                    if (message == messageToMatch)
                    {
                        return(decisionOnMatch);
                    }
                    break;

                case SubruleMesssageMatchingMode.StartsWith:
                    if (message.StartsWith(messageToMatch))
                    {
                        return(decisionOnMatch);
                    }
                    break;

                case SubruleMesssageMatchingMode.EndsWith:
                    if (message.EndsWith(messageToMatch))
                    {
                        return(decisionOnMatch);
                    }
                    break;

                case SubruleMesssageMatchingMode.Contains:
                    if (message.Contains(messageToMatch))
                    {
                        return(decisionOnMatch);
                    }
                    break;

                default:
                    throw new Exception("INTERNAL FAILURE: unkonwn message matching mode");
                }
            }
                return(SubruleDebuggingDecision.Undefined);

            case SubruleDebuggingEvent.Match:
            {
                IMatches matches = (IMatches)data;
                if (matches.Producer == actionToMatch)
                {
                    if (ifClause != null)
                    {
                        object oldThis = procEnv.GetVariableValue("this");
                        bool   result  = false;
                        foreach (IMatch match in matches)
                        {
                            procEnv.SetVariableValue("this", match);
                            if ((bool)ifClause.Evaluate(procEnv))
                            {
                                result = true;
                                break;
                            }
                        }
                        procEnv.SetVariableValue("this", oldThis);
                        if (result)
                        {
                            return(decisionOnMatch);
                        }
                    }
                    else
                    {
                        return(decisionOnMatch);
                    }
                }
                return(SubruleDebuggingDecision.Undefined);
            }

            case SubruleDebuggingEvent.New:
            case SubruleDebuggingEvent.Delete:
            case SubruleDebuggingEvent.Retype:
            case SubruleDebuggingEvent.SetAttributes:
            {
                IGraphElement elem = (IGraphElement)data;
                if (nameToMatch != null)
                {
                    if (procEnv.NamedGraph.GetElementName(elem) == nameToMatch)
                    {
                        if (If(elem, procEnv))
                        {
                            return(decisionOnMatch);
                        }
                    }
                }
                if (typeToMatch != null)
                {
                    if (elem.Type is NodeType && typeToMatch is NodeType && elem.Type.IsA(typeToMatch) ||
                        elem.Type is EdgeType && typeToMatch is EdgeType && elem.Type.IsA(typeToMatch))
                    {
                        if (onlyThisType)
                        {
                            if (typeToMatch.IsA(elem.Type))
                            {
                                if (If(elem, procEnv))
                                {
                                    return(decisionOnMatch);
                                }
                            }
                        }
                        else
                        {
                            if (If(elem, procEnv))
                            {
                                return(decisionOnMatch);
                            }
                        }
                    }
                }
                return(SubruleDebuggingDecision.Undefined);
            }

            default:
                return(SubruleDebuggingDecision.Undefined);
            }
        }