Esempio n. 1
0
        private bool TryApplySelectClause(SelectClause clause, QueryCommand cmd)
        {
            if (cmd.Columns.Any())
                return false;

            cmd.Columns.AddRange(clause.Columns);
            return true;
        }
Esempio n. 2
0
        private bool TryApplyOrderByClause(OrderByClause clause, QueryCommand cmd)
        {
            if (cmd.SkipCount.HasValue || cmd.TakeCount.HasValue)
                return false;

            cmd.Order.Add(new SimpleOrderByItem(clause.Reference, clause.Direction));
            return true;
        }
Esempio n. 3
0
        public QueryCommand BuildCommand(SimpleQuery query)
        {
            var cmd = new QueryCommand();

            var unprocessedClauses = new Queue<SimpleQueryClauseBase>(query.Clauses);
            Func<SimpleQueryClauseBase, QueryCommand, bool> processor;
            while (unprocessedClauses.Count > 0)
            {
                var clause = unprocessedClauses.Peek();
                var clauseType = clause.GetType();

                if (!_processors.TryGetValue(clauseType, out processor) || !processor(clause, cmd))
                    break;

                cmd.ProcessedClauses.Push(unprocessedClauses.Dequeue());
            }

            cmd.TablePath = query.TableName;
            cmd.UnprocessedClauses = unprocessedClauses;
            return cmd;
        }
Esempio n. 4
0
        private QueryCommand ParseQuery(SimpleQuery query)
        {
            var cmd = new QueryCommand();

            var unprocessedClauses = new Queue <SimpleQueryClauseBase>(query.Clauses);
            Func <SimpleQueryClauseBase, QueryCommand, bool> processor;

            while (unprocessedClauses.Count > 0)
            {
                var clause     = unprocessedClauses.Peek();
                var clauseType = clause.GetType();

                if (!_processors.TryGetValue(clauseType, out processor) || !processor(clause, cmd))
                {
                    break;
                }

                cmd.ProcessedClauses.Push(unprocessedClauses.Dequeue());
            }

            cmd.UnprocessedClauses = unprocessedClauses;
            return(cmd);
        }
Esempio n. 5
0
 private bool TryApplyWithClause(WithClause clause, QueryCommand cmd)
 {
     cmd.Expand.Add(clause.ObjectReference.GetName());
     return true;
 }
Esempio n. 6
0
        private IFluentClient <IDictionary <string, object> > GetODataClientCommand(QueryCommand cmd)
        {
            var linkNames = cmd.TablePath.Split('.');
            var client    = GetODataClient();

            var tableName     = linkNames.First();
            var baseTable     = GetBaseTable(tableName);
            var derivedTable  = GetAsDerivedTable(tableName);
            var clientCommand = derivedTable != null
                ? client.For(baseTable.ActualName).As(derivedTable.ActualName)
                : client.For(tableName);

            if (cmd.NamedKeyValues != null && cmd.NamedKeyValues.Count > 0)
            {
                clientCommand = clientCommand.Key(cmd.NamedKeyValues);
            }
            else if (cmd.KeyValues != null && cmd.KeyValues.Count > 0)
            {
                clientCommand = clientCommand.Key(cmd.KeyValues);
            }

            if (!ReferenceEquals(cmd.FilterExpression, null))
            {
                clientCommand = clientCommand.Filter(cmd.FilterExpression);
            }

            if (cmd.Expand.Count > 0)
            {
                clientCommand = clientCommand.Expand(cmd.Expand);
            }

            if (cmd.SkipCount.HasValue)
            {
                clientCommand = clientCommand.Skip(cmd.SkipCount.Value);
            }

            if (cmd.TakeCount.HasValue)
            {
                clientCommand = clientCommand.Top(cmd.TakeCount.Value);
            }

            if (cmd.Order.Count > 0)
            {
                clientCommand = clientCommand.OrderBy(
                    cmd.Order.Select(x =>
                                     new KeyValuePair <string, bool>(x.Reference.GetAliasOrName(),
                                                                     x.Direction == OrderByDirection.Descending)));
            }

            if (cmd.Columns.Count == 1 && cmd.Columns.First().GetType() == typeof(CountSpecialReference))
            {
                clientCommand      = clientCommand.Count();
                cmd.IsScalarResult = true;
            }
            else if (cmd.Columns.Count > 0)
            {
                clientCommand = clientCommand.Select(cmd.Columns.Select(x => x.GetAliasOrName()));
            }

            linkNames.Skip(1).ToList().ForEach(x => clientCommand = clientCommand.NavigateTo(x));

            return(clientCommand);
        }
Esempio n. 7
0
 private bool TryApplyWithCountClause(WithCountClause clause, QueryCommand cmd)
 {
     cmd.SetTotalCount = clause.SetCount;
     return true;
 }
Esempio n. 8
0
 private string FormatWhereClause(Table table, QueryCommand cmd)
 {
     if (cmd.Criteria != null)
     {
         return FormatFilter(_expressionFormatter.Format(cmd.Criteria));
     }
     return null;
 }
Esempio n. 9
0
        private IFluentClient<IDictionary<string, object>> GetODataClientCommand(QueryCommand cmd)
        {
            var linkNames = cmd.TablePath.Split('.');
            var client = GetODataClient();

            var tableName = linkNames.First();
            var baseTable = GetBaseTable(tableName);
            var derivedTable = GetAsDerivedTable(tableName);
            var clientCommand = derivedTable != null
                ? client.For(baseTable.ActualName).As(derivedTable.ActualName)
                : client.For(tableName);

            if (cmd.NamedKeyValues != null && cmd.NamedKeyValues.Count > 0)
                clientCommand = clientCommand.Key(cmd.NamedKeyValues);
            else if (cmd.KeyValues != null && cmd.KeyValues.Count > 0)
                clientCommand = clientCommand.Key(cmd.KeyValues);

            if (!ReferenceEquals(cmd.FilterExpression, null))
                clientCommand = clientCommand.Filter(cmd.FilterExpression);

            if (cmd.Expand.Count > 0)
                clientCommand = clientCommand.Expand(cmd.Expand);

            if (cmd.SkipCount.HasValue)
                clientCommand = clientCommand.Skip(cmd.SkipCount.Value);

            if (cmd.TakeCount.HasValue)
                clientCommand = clientCommand.Top(cmd.TakeCount.Value);

            if (cmd.Order.Count > 0)
                clientCommand = clientCommand.OrderBy(
                    cmd.Order.Select(x =>
                        new KeyValuePair<string, bool>(x.Reference.GetAliasOrName(),
                        x.Direction == OrderByDirection.Descending)));

            if (cmd.Columns.Count == 1 && cmd.Columns.First().GetType() == typeof(CountSpecialReference))
            {
                clientCommand = clientCommand.Count();
                cmd.IsScalarResult = true;
            }
            else if (cmd.Columns.Count > 0)
            {
                clientCommand = clientCommand.Select(cmd.Columns.Select(x => x.GetAliasOrName()));
            }

            linkNames.Skip(1).ToList().ForEach(x => clientCommand = clientCommand.NavigateTo(x));

            return clientCommand;
        }
Esempio n. 10
0
        private bool TryApplyWhereClause(WhereClause clause, QueryCommand cmd)
        {
            if (cmd.SkipCount.HasValue || cmd.TakeCount.HasValue)
                return false;

            cmd.Criteria = cmd.Criteria == null
                ? clause.Criteria
                : new SimpleExpression(cmd.Criteria, clause.Criteria, SimpleExpressionType.And);

            cmd.FilterExpression = new ExpressionConverter(_excludeResourceTypeExpressions).ConvertExpression(cmd.Criteria);

            return true;
        }
Esempio n. 11
0
 private bool TryApplyWithClause(WithClause clause, QueryCommand cmd)
 {
     cmd.Expand.Add(clause.ObjectReference.GetName());
     return(true);
 }
Esempio n. 12
0
 private bool TryApplyWithCountClause(WithCountClause clause, QueryCommand cmd)
 {
     cmd.SetTotalCount = clause.SetCount;
     return(true);
 }
Esempio n. 13
0
 private string FormatWithClause(Table table, QueryCommand cmd)
 {
     if (cmd.Expand.Any())
     {
         var expansion = string.Join(",", cmd.Expand);
         return "$expand=" + expansion;
     }
     return null;
 }
Esempio n. 14
0
 private string FormatSpecialClause(Table table, QueryCommand cmd)
 {
     if (cmd.Columns != null && cmd.Columns.Count() == 1 && cmd.Columns.First() is SpecialReference)
     {
         var specialColumn = cmd.Columns.First();
         cmd.Columns.Clear();
         return FormatSpecialReference((SpecialReference)specialColumn);
     }
     return null;
 }
Esempio n. 15
0
 private string FormatCountClause(Table table, QueryCommand cmd)
 {
     if (cmd.SetTotalCount != null)
     {
         return "$inlinecount=allpages";
     }
     return null;
 }
Esempio n. 16
0
 private string FormatSelectClause(Table table, QueryCommand cmd)
 {
     if (cmd.Columns != null && cmd.Columns.Count() > 0)
     {
         var items = cmd.Columns.Select(x => FormatSelectItem(table, x));
         return "$select=" + string.Join(",", items);
     }
     return null;
 }
Esempio n. 17
0
 private string FormatTakeClause(Table table, QueryCommand cmd)
 {
     if (cmd.TakeCount > 0)
     {
         return "$top=" + cmd.TakeCount.ToString();
     }
     return null;
 }
Esempio n. 18
0
 private string FormatSkipClause(Table table, QueryCommand cmd)
 {
     if (cmd.SkipCount > 0)
     {
         return "$skip=" + cmd.SkipCount.ToString();
     }
     return null;
 }
Esempio n. 19
0
 private string FormatOrderClause(Table table, QueryCommand cmd)
 {
     if (cmd.Order.Any())
     {
         var items = cmd.Order.Select(x => FormatOrderByItem(table, x));
         return "$orderby=" + string.Join(",", items);
     }
     return null;
 }
Esempio n. 20
0
        private bool TryApplyTakeClause(TakeClause clause, QueryCommand cmd)
        {
            if (cmd.TakeCount.HasValue)
                return false;

            cmd.TakeCount = clause.Count;
            return true;
        }
Esempio n. 21
0
        private bool TryApplyWhereClause(WhereClause clause, QueryCommand cmd)
        {
            if (cmd.SkipCount.HasValue || cmd.TakeCount.HasValue)
                return false;

            cmd.Criteria = cmd.Criteria == null
                ? clause.Criteria
                : new SimpleExpression(cmd.Criteria, clause.Criteria, SimpleExpressionType.And);
            return true;
        }