Exemplo n.º 1
0
 public override string TypeOfMemberOrAttribute(string matchOrGraphElementType, string memberOrAttribute)
 {
     if (matchOrGraphElementType.StartsWith("match<class "))
     {
         MatchClassFilterer matchClass = actions.GetMatchClass(TypesHelper.GetMatchClassName(matchOrGraphElementType));
         IPatternElement    element    = matchClass.info.GetPatternElement(memberOrAttribute);
         if (element == null)
         {
             throw new SequenceParserException(memberOrAttribute, SequenceParserError.UnknownMatchMember);
         }
         GrGenType elementType = element.Type;
         return(TypesHelper.DotNetTypeToXgrsType(elementType));
     }
     else if (matchOrGraphElementType.StartsWith("match<"))
     {
         IAction         action  = actions.GetAction(TypesHelper.GetRuleName(matchOrGraphElementType));
         IPatternElement element = action.RulePattern.PatternGraph.GetPatternElement(memberOrAttribute);
         if (element == null)
         {
             throw new SequenceParserException(memberOrAttribute, SequenceParserError.UnknownMatchMember);
         }
         GrGenType elementType = element.Type;
         return(TypesHelper.DotNetTypeToXgrsType(elementType));
     }
     else
     {
         GrGenType     graphElementType = TypesHelper.GetNodeOrEdgeType(matchOrGraphElementType, Model);
         AttributeType attributeType    = graphElementType.GetAttributeType(memberOrAttribute);
         if (attributeType == null)
         {
             throw new SequenceParserException(memberOrAttribute, SequenceParserError.UnknownAttribute);
         }
         return(TypesHelper.AttributeTypeToXgrsType(attributeType));
     }
 }
Exemplo n.º 2
0
 public override string TypeOfMemberOrAttribute(string matchOrGraphElementType, string memberOrAttribute)
 {
     if (matchOrGraphElementType.StartsWith("match<class "))
     {
         String          matchClassName = TypesHelper.GetMatchClassName(matchOrGraphElementType);
         IMatchClass     matchClass     = actionsTypeInformation.matchClasses[matchClassName];
         IPatternElement element        = matchClass.GetPatternElement(memberOrAttribute);
         if (element == null)
         {
             throw new SequenceParserException(memberOrAttribute, SequenceParserError.UnknownMatchMember);
         }
         GrGenType elementType = element.Type;
         return(TypesHelper.DotNetTypeToXgrsType(elementType));
     }
     else if (matchOrGraphElementType.StartsWith("match<"))
     {
         String ruleName = TypesHelper.GetRuleName(matchOrGraphElementType);
         if (!actionsTypeInformation.rulesToTopLevelEntities[ruleName].Contains(memberOrAttribute))
         {
             throw new SequenceParserException(memberOrAttribute, SequenceParserError.UnknownMatchMember);
         }
         int indexOfEntity = actionsTypeInformation.rulesToTopLevelEntities[ruleName].IndexOf(memberOrAttribute);
         return(actionsTypeInformation.rulesToTopLevelEntityTypes[ruleName][indexOfEntity]);
     }
     else
     {
         GrGenType     graphElementType = TypesHelper.GetNodeOrEdgeType(matchOrGraphElementType, Model);
         AttributeType attributeType    = graphElementType.GetAttributeType(memberOrAttribute);
         if (attributeType == null)
         {
             throw new SequenceParserException(memberOrAttribute, SequenceParserError.UnknownAttribute);
         }
         return(TypesHelper.AttributeTypeToXgrsType(attributeType));
     }
 }
Exemplo n.º 3
0
 public PatternComprehension(
     IPatternElement patternElement,
     Where?where,
     Expression?expression)
 {
     PatternElement = patternElement;
     Where          = where;
     Expression     = expression;
 }
Exemplo n.º 4
0
        public static FunctionInvocation Create(
            FunctionDefinition definition,
            IPatternElement pattern)
        {
            Ensure.IsNotNull(
                pattern,
                $"The pattern for {definition.ImplementationName}() is required.");

            return(new FunctionInvocation(definition.ImplementationName, new Pattern(pattern)));
        }
Exemplo n.º 5
0
 public PatternComprehension(IPatternElement patternElement)
 {
     PatternElement = patternElement;
     Where          = null;
     Expression     = null;
 }
Exemplo n.º 6
0
 public PatternComprehension(IPatternElement patternElement, Expression?expression)
 {
     PatternElement = patternElement;
     Where          = null;
     Expression     = expression;
 }
Exemplo n.º 7
0
 public OldCommand([Key("old")] IValueProvider provider, IPatternElement element, ConstantValueProvider constant)
 {
     this.provider = provider;
     this.element = element;
     this.constant = constant;
 }
Exemplo n.º 8
0
 public NewValueProvider(IPatternElement element)
 {
 }
Exemplo n.º 9
0
        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>());
                    }
                }
            }
        }