/// <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)); }
/// <summary> /// Build a segment representing $filter. /// </summary> /// <param name="expression">The filter expression - this should evaluate to a single boolean value.</param> /// <param name="rangeVariable">An expression that represents a single value from the collection.</param> /// <param name="navigationSource">The navigation source that this filter applies to.</param> /// <exception cref="System.ArgumentNullException">Throws if any input parameter is null.</exception> /// <remarks>$filter should not be applied on singletons or single entities.</remarks> public FilterSegment(SingleValueNode expression, RangeVariable rangeVariable, IEdmNavigationSource navigationSource) { ExceptionUtils.CheckArgumentNotNull(expression, "expression"); ExceptionUtils.CheckArgumentNotNull(rangeVariable, "rangeVariable"); ExceptionUtils.CheckArgumentNotNull(navigationSource, "navigationSource"); this.Identifier = UriQueryConstants.FilterSegment; this.SingleResult = false; this.TargetEdmNavigationSource = navigationSource; this.TargetKind = RequestTargetKind.Resource; this.TargetEdmType = rangeVariable.TypeReference.Definition; this.expression = expression; this.rangeVariable = rangeVariable; this.bindingType = navigationSource.Type; NodeToStringBuilder nodeToStringBuilder = new NodeToStringBuilder(); string expressionString = nodeToStringBuilder.TranslateNode(expression); this.literalText = UriQueryConstants.FilterSegment + ExpressionConstants.SymbolOpenParen + expressionString + ExpressionConstants.SymbolClosedParen; }
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)); }