protected static void FillReturnVariablesFromValues(SequenceVariable[] ReturnVars, IAction Action, IGraphProcessingEnvironment procEnv, List <object[]> retElemsList) { IList[] returnVars = null; if (ReturnVars.Length > 0) { returnVars = new IList[ReturnVars.Length]; for (int i = 0; i < ReturnVars.Length; ++i) { returnVars[i] = ReturnVars[i].GetVariableValue(procEnv) as IList; if (returnVars[i] == null) { string returnType = TypesHelper.DotNetTypeToXgrsType(Action.RulePattern.Outputs[i]); Type valueType = TypesHelper.GetType(returnType, procEnv.Graph.Model); returnVars[i] = ContainerHelper.NewList(valueType); ReturnVars[i].SetVariableValue(returnVars[i], procEnv); } else { returnVars[i].Clear(); } } } for (int curRetElemNum = 0; curRetElemNum < retElemsList.Count; ++curRetElemNum) { object[] retElems = retElemsList[curRetElemNum]; for (int i = 0; i < ReturnVars.Length; ++i) { returnVars[i].Add(retElems[i]); } } }
public static IDeque FillDeque(IDeque dequeToCopyTo, string valueTypeName, IDeque dequeToCopy, IGraphModel model) { NodeType nodeType = TypesHelper.GetNodeType(valueTypeName, model); if (nodeType != null) { FillDequeWithNode(dequeToCopyTo, nodeType, dequeToCopy); } else { EdgeType edgeType = TypesHelper.GetEdgeType(valueTypeName, model); if (edgeType != null) { FillDequeWithEdge(dequeToCopyTo, edgeType, dequeToCopy); } else { Type varType = TypesHelper.GetType(valueTypeName, model); FillDequeWithVar(dequeToCopyTo, varType, dequeToCopy); } } return(dequeToCopyTo); }
public static IDictionary FillMapWithKeyVar(IDictionary mapToCopyTo, Type keyVarType, string valueTypeName, IDictionary mapToCopy, IGraphModel model) { NodeType nodeType = TypesHelper.GetNodeType(valueTypeName, model); if (nodeType != null) { FillMapWithKeyVarValueNode(mapToCopyTo, keyVarType, nodeType, mapToCopy); } else { EdgeType edgeType = TypesHelper.GetEdgeType(valueTypeName, model); if (edgeType != null) { FillMapWithKeyVarValueEdge(mapToCopyTo, keyVarType, edgeType, mapToCopy); } else { Type valueType = TypesHelper.GetType(valueTypeName, model); FillMapWithKeyVarValueVar(mapToCopyTo, keyVarType, valueType, mapToCopy); } } return(mapToCopyTo); }
public static Dictionary <K, V> FillMap <K, V>(Dictionary <K, V> mapToCopyTo, string keyTypeName, string valueTypeName, IDictionary mapToCopy, IGraphModel model) { NodeType nodeType = TypesHelper.GetNodeType(keyTypeName, model); if (nodeType != null) { FillMapWithKeyNode(mapToCopyTo, nodeType, valueTypeName, mapToCopy, model); } else { EdgeType edgeType = TypesHelper.GetEdgeType(keyTypeName, model); if (edgeType != null) { FillMapWithKeyEdge(mapToCopyTo, edgeType, valueTypeName, mapToCopy, model); } else { Type varType = TypesHelper.GetType(keyTypeName, model); FillMapWithKeyVar(mapToCopyTo, varType, valueTypeName, mapToCopy, model); } } return(mapToCopyTo); }
public static Dictionary <K, SetValueType> FillSet <K>(Dictionary <K, SetValueType> setToCopyTo, string valueTypeName, IDictionary setToCopy, IGraphModel model) { NodeType nodeType = TypesHelper.GetNodeType(valueTypeName, model); if (nodeType != null) { FillSetWithNode(setToCopyTo, nodeType, setToCopy); } else { EdgeType edgeType = TypesHelper.GetEdgeType(valueTypeName, model); if (edgeType != null) { FillSetWithEdge(setToCopyTo, edgeType, setToCopy); } else { Type varType = TypesHelper.GetType(valueTypeName, model); FillSetWithVar(setToCopyTo, varType, setToCopy); } } return(setToCopyTo); }
public static IList FillArray(IList arrayToCopyTo, string valueTypeName, IList arrayToCopy, IGraphModel model) { NodeType nodeType = TypesHelper.GetNodeType(valueTypeName, model); if (nodeType != null) { FillArrayWithNode(arrayToCopyTo, nodeType, arrayToCopy); } else { EdgeType edgeType = TypesHelper.GetEdgeType(valueTypeName, model); if (edgeType != null) { FillArrayWithEdge(arrayToCopyTo, edgeType, arrayToCopy); } else { Type varType = TypesHelper.GetType(valueTypeName, model); FillArrayWithVar(arrayToCopyTo, varType, arrayToCopy); } } return(arrayToCopyTo); }
public static IList Extract(object container, string memberOrAttribute, IGraphProcessingEnvironment procEnv) { IList array = (IList)container; string arrayType = TypesHelper.DotNetTypeToXgrsType(array.GetType()); string arrayValueType = TypesHelper.ExtractSrc(arrayType); if (arrayValueType.StartsWith("match<")) { if (arrayValueType == "match<>") { if (array.Count > 0) { IMatch match = (IMatch)array[0]; object matchElement = match.GetMember(memberOrAttribute); Type matchElementType; if (matchElement is IGraphElement) { matchElementType = TypesHelper.GetType(((IGraphElement)matchElement).Type, procEnv.Graph.Model); } else { matchElementType = matchElement.GetType(); } Type listType = typeof(List <>).MakeGenericType(matchElementType); IList extractedArray = (IList)Activator.CreateInstance(listType); ExtractMatchMember(array, memberOrAttribute, extractedArray); return(extractedArray); } else { return(new List <object>()); } } else { if (arrayValueType.StartsWith("match<class ")) { MatchClassFilterer matchClass = procEnv.Actions.GetMatchClass(TypesHelper.GetMatchClassName(arrayValueType)); IPatternElement element = matchClass.info.GetPatternElement(memberOrAttribute); GrGenType elementType = element.Type; Type listType = typeof(List <>).MakeGenericType(TypesHelper.GetType(elementType, procEnv.Graph.Model)); IList extractedArray = (IList)Activator.CreateInstance(listType); ExtractMatchMember(array, memberOrAttribute, extractedArray); return(extractedArray); } else { IAction action = procEnv.Actions.GetAction(TypesHelper.GetRuleName(arrayValueType)); IPatternElement element = action.RulePattern.PatternGraph.GetPatternElement(memberOrAttribute); GrGenType elementType = element.Type; Type listType = typeof(List <>).MakeGenericType(TypesHelper.GetType(elementType, procEnv.Graph.Model)); IList extractedArray = (IList)Activator.CreateInstance(listType); ExtractMatchMember(array, memberOrAttribute, extractedArray); return(extractedArray); } } } else { GrGenType graphElementType = TypesHelper.GetNodeOrEdgeType(arrayValueType, procEnv.Graph.Model); if (graphElementType != null) { AttributeType attributeType = graphElementType.GetAttributeType(memberOrAttribute); Type listType = typeof(List <>).MakeGenericType(attributeType.Type); IList extractedArray = (IList)Activator.CreateInstance(listType); ExtractAttribute(array, memberOrAttribute, extractedArray); return(extractedArray); } else { if (array.Count > 0) { IGraphElement graphElement = (IGraphElement)array[0]; object element = graphElement.GetAttribute(memberOrAttribute); Type elementType; if (element is IGraphElement) { elementType = TypesHelper.GetType(((IGraphElement)element).Type, procEnv.Graph.Model); } else { elementType = element.GetType(); } Type listType = typeof(List <>).MakeGenericType(elementType); IList extractedArray = (IList)Activator.CreateInstance(listType); ExtractAttribute(array, memberOrAttribute, extractedArray); return(extractedArray); } else { return(new List <object>()); } } } }