Beispiel #1
0
        private static List <StatementSyntax> HandleMap(string map, FieldNamesValidator fieldNamesValidator, MethodDetectorRewriter methodsDetector,
                                                        ref SyntaxList <MemberDeclarationSyntax> members)
        {
            try
            {
                map = NormalizeFunction(map);
                var expression = SyntaxFactory.ParseExpression(map).NormalizeWhitespace();

                fieldNamesValidator.Validate(map, expression);
                methodsDetector.Visit(expression);

                var queryExpression = expression as QueryExpressionSyntax;
                if (queryExpression != null)
                {
                    return(HandleSyntaxInMap(fieldNamesValidator, new MapFunctionProcessor(CollectionNameRetriever.QuerySyntax, SelectManyRewriter.QuerySyntax), queryExpression, ref members));
                }
                var invocationExpression = expression as InvocationExpressionSyntax;
                if (invocationExpression != null)
                {
                    return(HandleSyntaxInMap(fieldNamesValidator, new MapFunctionProcessor(CollectionNameRetriever.MethodSyntax, SelectManyRewriter.MethodSyntax), invocationExpression, ref members));
                }

                throw new InvalidOperationException("Not supported expression type.");
            }
            catch (Exception ex)
            {
                throw new IndexCompilationException(ex.Message, ex)
                      {
                          IndexDefinitionProperty = nameof(IndexDefinition.Maps),
                          ProblematicText         = map
                      };
            }
        }
        private static StatementSyntax HandleTransformResults(string transformResults, MethodDetectorRewriter methodsDetector)
        {
            try
            {
                transformResults = NormalizeFunction(transformResults);
                var expression = SyntaxFactory.ParseExpression(transformResults).NormalizeWhitespace();
                methodsDetector.Visit(expression);

                var queryExpression = expression as QueryExpressionSyntax;
                if (queryExpression != null)
                {
                    return(HandleSyntaxInTransformResults(new TransformFunctionProcessor(SelectManyRewriter.QuerySyntax), queryExpression));
                }

                var invocationExpression = expression as InvocationExpressionSyntax;
                if (invocationExpression != null)
                {
                    return(HandleSyntaxInTransformResults(new TransformFunctionProcessor(SelectManyRewriter.MethodSyntax), invocationExpression));
                }

                throw new InvalidOperationException("Not supported expression type.");
            }
            catch (Exception ex)
            {
                throw new IndexCompilationException(ex.Message, ex)
                      {
                          IndexDefinitionProperty = "TransformResults",
                          ProblematicText         = transformResults
                      };
            }
        }
Beispiel #3
0
        private static StatementSyntax HandleReduce(string reduce, FieldNamesValidator fieldNamesValidator, MethodDetectorRewriter methodsDetector, out string[] groupByFields)
        {
            try
            {
                reduce = NormalizeFunction(reduce);
                var expression = SyntaxFactory.ParseExpression(reduce).NormalizeWhitespace();
                fieldNamesValidator?.Validate(reduce, expression);
                methodsDetector.Visit(expression);

                StatementSyntax result;

                switch (expression)
                {
                case QueryExpressionSyntax queryExpression:
                    result = HandleSyntaxInReduce(
                        new ReduceFunctionProcessor(
                            ResultsVariableNameRewriter.QuerySyntax,
                            GroupByFieldsRetriever.QuerySyntax,
                            SelectManyRewriter.QuerySyntax),
                        MethodsInGroupByValidator.QuerySyntaxValidator,
                        queryExpression, out groupByFields);
                    break;

                case InvocationExpressionSyntax invocationExpression:
                    result = HandleSyntaxInReduce(
                        new ReduceFunctionProcessor(
                            ResultsVariableNameRewriter.MethodSyntax,
                            GroupByFieldsRetriever.MethodSyntax,
                            SelectManyRewriter.MethodSyntax),
                        MethodsInGroupByValidator.MethodSyntaxValidator,
                        invocationExpression, out groupByFields);
                    break;

                default:
                    throw new InvalidOperationException("Not supported expression type.");
                }

                foreach (var groupByField in groupByFields)
                {
                    if (fieldNamesValidator?.Fields.Contains(groupByField) == false)
                    {
                        throw new InvalidOperationException($"Group by field '{groupByField}' was not found on the list of index fields ({string.Join(", ",fieldNamesValidator.Fields)})");
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw new IndexCompilationException(ex.Message, ex)
                      {
                          IndexDefinitionProperty = nameof(IndexDefinition.Reduce),
                          ProblematicText         = reduce
                      };
            }
        }
Beispiel #4
0
        private static StatementSyntax HandleReduce(string reduce, FieldNamesValidator fieldNamesValidator, MethodDetectorRewriter methodsDetector, out string[] groupByFields)
        {
            try
            {
                reduce = NormalizeFunction(reduce);
                var expression = SyntaxFactory.ParseExpression(reduce).NormalizeWhitespace();
                fieldNamesValidator?.Validate(reduce, expression);
                methodsDetector.Visit(expression);
                var queryExpression = expression as QueryExpressionSyntax;
                if (queryExpression != null)
                {
                    return
                        HandleSyntaxInReduce(
                            new ReduceFunctionProcessor(
                                ResultsVariableNameRewriter.QuerySyntax,
                                GroupByFieldsRetriever.QuerySyntax,
                                SelectManyRewriter.QuerySyntax),
                            MethodsInGroupByValidator.QuerySyntaxValidator,
                            queryExpression, out groupByFields);
                }

                var invocationExpression = expression as InvocationExpressionSyntax;
                if (invocationExpression != null)
                {
                    return
                        HandleSyntaxInReduce(
                            new ReduceFunctionProcessor(
                                ResultsVariableNameRewriter.MethodSyntax,
                                GroupByFieldsRetriever.MethodSyntax,
                                SelectManyRewriter.MethodSyntax),
                            MethodsInGroupByValidator.MethodSyntaxValidator,
                            invocationExpression, out groupByFields);
                }

                throw new InvalidOperationException("Not supported expression type.");
            }
            catch (Exception ex)
            {
                throw new IndexCompilationException(ex.Message, ex)
                {
                    IndexDefinitionProperty = nameof(IndexDefinition.Reduce),
                    ProblematicText = reduce
                };
            }
        }