/// <summary>
        /// Translate an ExpandedNavigationSelectItem
        /// </summary>
        /// <param name="item">the item to Translate</param>
        /// <returns>Defined by the implementer</returns>
        public override string Translate(ExpandedNavigationSelectItem item)
        {
            NodeToStringBuilder nodeToStringBuilder = new NodeToStringBuilder();
            string currentExpandClause = String.Join("/", item.PathToNavigationProperty.WalkWith(PathSegmentToStringTranslator.Instance).ToArray());
            string res = string.Empty;

            if (item.FilterOption != null)
            {
                res += "$filter=" + nodeToStringBuilder.TranslateFilterClause(item.FilterOption);
            }

            if (item.OrderByOption != null)
            {
                res += string.IsNullOrEmpty(res) ? null : ";";
                res += "$orderby=" + nodeToStringBuilder.TranslateOrderByClause(item.OrderByOption);
            }

            if (item.SelectAndExpand != null)
            {
                string selectExpand = this.TranslateSelectExpandClause(item.SelectAndExpand, false);
                res = string.Concat(res, !string.IsNullOrEmpty(res) && !string.IsNullOrEmpty(selectExpand) ? ";" : null, selectExpand);
            }

            if (item.TopOption != null)
            {
                res += string.IsNullOrEmpty(res) ? null : ";";
                res += "$top=" + item.TopOption.ToString();
            }

            if (item.SkipOption != null)
            {
                res += string.IsNullOrEmpty(res) ? null : ";";
                res += "$skip=" + item.SkipOption.ToString();
            }

            if (item.CountOption != null)
            {
                res += string.IsNullOrEmpty(res) ? null : ";";
                res += "$count";
                res += ExpressionConstants.SymbolEqual;
                if (item.CountOption == true)
                {
                    res += ExpressionConstants.KeywordTrue;
                }
                else
                {
                    res += ExpressionConstants.KeywordFalse;
                }
            }

            if (item.SearchOption != null)
            {
                res += string.IsNullOrEmpty(res) ? null : ";";
                res += "$search";
                res += ExpressionConstants.SymbolEqual;
                res += nodeToStringBuilder.TranslateSearchClause(item.SearchOption);
            }

            return(string.Concat(currentExpandClause, string.IsNullOrEmpty(res) ? null : string.Concat(ExpressionConstants.SymbolOpenParen, res, ExpressionConstants.SymbolClosedParen)));
        }
Example #2
0
        /// <summary>
        /// Translate an ExpandedNavigationSelectItem
        /// </summary>
        /// <param name="item">the item to Translate</param>
        /// <returns>Defined by the implementer</returns>
        public override string Translate(ExpandedNavigationSelectItem item)
        {
            string res = string.Empty;

            if (item.SelectAndExpand != null)
            {
                string selectExpand = this.TranslateSelectExpandClause(item.SelectAndExpand, false);
                res = string.Concat(res, !string.IsNullOrEmpty(res) && !string.IsNullOrEmpty(selectExpand) ? ";" : null, selectExpand);
            }

            if (item.LevelsOption != null)
            {
                res += string.IsNullOrEmpty(res) ? null : ";";
                res += ExpressionConstants.QueryOptionLevels;
                res += ExpressionConstants.SymbolEqual;
                res += NodeToStringBuilder.TranslateLevelsClause(item.LevelsOption);
            }

            string currentExpandClause = Translate((ExpandedReferenceSelectItem)item);

            if (currentExpandClause.EndsWith(ExpressionConstants.SymbolClosedParen, StringComparison.Ordinal))
            {
                return(currentExpandClause.Insert(currentExpandClause.Length - 1, string.IsNullOrEmpty(res) ? string.Empty : ";" + res));
            }
            else
            {
                return(string.Concat(currentExpandClause, string.IsNullOrEmpty(res) ? null : string.Concat(ExpressionConstants.SymbolOpenParen, res, ExpressionConstants.SymbolClosedParen)));
            }
        }
        /// <summary>
        /// Translate a OperationImportSegment
        /// </summary>
        /// <param name="segment">the segment to Translate</param>
        /// <returns>Defined by the implementer.</returns>
        public override string Translate(OperationImportSegment segment)
        {
            Debug.Assert(segment != null, "segment != null");
            NodeToStringBuilder nodeToStringBuilder = new NodeToStringBuilder();
            string res = null;

            foreach (OperationSegmentParameter operationSegmentParameter in segment.Parameters)
            {
                string tmp = nodeToStringBuilder.TranslateNode((QueryNode)operationSegmentParameter.Value);
                res = String.Concat(res, String.IsNullOrEmpty(res) ? null : ExpressionConstants.SymbolComma, operationSegmentParameter.Name, ExpressionConstants.SymbolEqual, tmp);
            }

            return(String.IsNullOrEmpty(res) ? String.Concat("/", segment.Identifier) : String.Concat("/", segment.Identifier, ExpressionConstants.SymbolOpenParen, res, ExpressionConstants.SymbolClosedParen));
        }
Example #4
0
        public Uri BuildUri()
        {
            NodeToStringBuilder nodeToStringBuilder = new NodeToStringBuilder();
            SelectExpandClauseToStringBuilder selectExpandClauseToStringBuilder = new SelectExpandClauseToStringBuilder();

            String queryOptions     = String.Empty;
            bool   writeQueryPrefix = true;

            if (this.odataUri.Filter != null)
            {
                queryOptions     = WriteQueryPrefixOrSeparator(writeQueryPrefix, queryOptions);
                writeQueryPrefix = false;
                queryOptions     = string.Concat(queryOptions, "$filter", ExpressionConstants.SymbolEqual, Uri.EscapeDataString(nodeToStringBuilder.TranslateFilterClause(this.odataUri.Filter)));
            }

            if (this.odataUri.SelectAndExpand != null)
            {
                string result = selectExpandClauseToStringBuilder.TranslateSelectExpandClause(this.odataUri.SelectAndExpand, true);
                if (!string.IsNullOrEmpty(result))
                {
                    queryOptions     = WriteQueryPrefixOrSeparator(writeQueryPrefix, queryOptions);
                    writeQueryPrefix = false;
                    queryOptions     = string.Concat(queryOptions, result);
                }
            }

            if (this.odataUri.OrderBy != null)
            {
                queryOptions     = WriteQueryPrefixOrSeparator(writeQueryPrefix, queryOptions);
                writeQueryPrefix = false;
                queryOptions     = string.Concat(queryOptions, "$orderby", ExpressionConstants.SymbolEqual, Uri.EscapeDataString(nodeToStringBuilder.TranslateOrderByClause(this.odataUri.OrderBy)));
            }

            if (this.odataUri.Top != null)
            {
                queryOptions     = WriteQueryPrefixOrSeparator(writeQueryPrefix, queryOptions);
                writeQueryPrefix = false;
                queryOptions     = string.Concat(queryOptions, "$top", ExpressionConstants.SymbolEqual, Uri.EscapeDataString(this.odataUri.Top.ToString()));
            }

            if (this.odataUri.Skip != null)
            {
                queryOptions     = WriteQueryPrefixOrSeparator(writeQueryPrefix, queryOptions);
                writeQueryPrefix = false;
                queryOptions     = string.Concat(queryOptions, "$skip", ExpressionConstants.SymbolEqual, Uri.EscapeDataString(this.odataUri.Skip.ToString()));
            }

            if (this.odataUri.QueryCount != null)
            {
                queryOptions     = WriteQueryPrefixOrSeparator(writeQueryPrefix, queryOptions);
                writeQueryPrefix = false;
                queryOptions     = string.Concat(queryOptions, "$count", ExpressionConstants.SymbolEqual, Uri.EscapeDataString(this.odataUri.QueryCount == true ? ExpressionConstants.KeywordTrue : ExpressionConstants.KeywordFalse));
            }

            if (this.odataUri.Search != null)
            {
                queryOptions     = WriteQueryPrefixOrSeparator(writeQueryPrefix, queryOptions);
                writeQueryPrefix = false;
                queryOptions     = string.Concat(queryOptions, "$search", ExpressionConstants.SymbolEqual, Uri.EscapeDataString(nodeToStringBuilder.TranslateSearchClause(this.odataUri.Search)));
            }

            if (this.odataUri.ParameterAliasNodes != null && this.odataUri.ParameterAliasNodes.Count > 0)
            {
                string aliasNode = nodeToStringBuilder.TranslateParameterAliasNodes(this.odataUri.ParameterAliasNodes);
                queryOptions     = String.IsNullOrEmpty(aliasNode) ? queryOptions : String.Concat(WriteQueryPrefixOrSeparator(writeQueryPrefix, queryOptions), aliasNode);
                writeQueryPrefix = false;
            }

            string res = String.Concat(this.odataUri.Path.ToResourcePathString(urlConventions), queryOptions);

            return(this.odataUri.ServiceRoot == null ? new Uri(res, UriKind.Relative) : new Uri(this.odataUri.ServiceRoot, new Uri(res, UriKind.Relative)));
        }