internal Scope(ODataReaderState state, ODataItem item, IEdmNavigationSource navigationSource, IEdmStructuredType expectedResourceType, ODataUri odataUri)
            {
                Debug.Assert(
                    state == ODataReaderState.Exception && item == null ||
                    state == ODataReaderState.ResourceStart && (item == null || item is ODataResource) ||
                    state == ODataReaderState.ResourceEnd && (item is ODataResource || item == null) ||
                    state == ODataReaderState.Primitive && (item == null || item is ODataPrimitiveValue) ||
                    state == ODataReaderState.ResourceSetStart && item is ODataResourceSet ||
                    state == ODataReaderState.ResourceSetEnd && item is ODataResourceSet ||
                    state == ODataReaderState.NestedResourceInfoStart && item is ODataNestedResourceInfo ||
                    state == ODataReaderState.NestedResourceInfoEnd && item is ODataNestedResourceInfo ||
                    state == ODataReaderState.EntityReferenceLink && item is ODataEntityReferenceLink ||
                    state == ODataReaderState.Start && item == null ||
                    state == ODataReaderState.Completed && item == null,
                    "Reader state and associated item do not match.");

                this.state            = state;
                this.item             = item;
                this.ResourceType     = expectedResourceType;
                this.NavigationSource = navigationSource;
                this.odataUri         = odataUri;
            }
Exemple #2
0
        /// <summary>
        /// Create contextUrlInfo for delta
        /// </summary>
        /// <param name="typeContext">The ODataResourceTypeContext to be used.</param>
        /// <param name="version">The OData version of the response.</param>
        /// <param name="kind">The delta kind.</param>
        /// <param name="odataUri">The odata uri info for current query.</param>
        /// <returns>The generated ODataContextUrlInfo.</returns>
        internal static ODataContextUrlInfo Create(ODataResourceTypeContext typeContext, ODataVersion version, ODataDeltaKind kind, ODataUri odataUri = null)
        {
            Debug.Assert(typeContext != null, "typeContext != null");

            ODataContextUrlInfo contextUriInfo = new ODataContextUrlInfo()
            {
                IsUnknownEntitySet          = typeContext.NavigationSourceKind == EdmNavigationSourceKind.UnknownEntitySet,
                NavigationSource            = typeContext.NavigationSourceName,
                TypeCast                    = typeContext.NavigationSourceEntityTypeName == typeContext.ExpectedResourceTypeName ? null : typeContext.ExpectedResourceTypeName,
                TypeName                    = typeContext.NavigationSourceEntityTypeName,
                IncludeFragmentItemSelector = kind == ODataDeltaKind.Resource && typeContext.NavigationSourceKind != EdmNavigationSourceKind.Singleton,
                DeltaKind                   = kind,
                NavigationPath              = ComputeNavigationPath(typeContext.NavigationSourceKind, null, typeContext.NavigationSourceName),
            };

            // Only use odata uri in with model case.
            if (typeContext is ODataResourceTypeContext.ODataResourceTypeContextWithModel)
            {
                contextUriInfo.NavigationPath = ComputeNavigationPath(typeContext.NavigationSourceKind, odataUri,
                                                                      typeContext.NavigationSourceName);
                contextUriInfo.ResourcePath = ComputeResourcePath(odataUri);
                contextUriInfo.QueryClause  = ComputeQueryClause(odataUri, version);
                contextUriInfo.IsUndeclared = ComputeIfIsUndeclared(odataUri);
            }

            return(contextUriInfo);
        }
Exemple #3
0
        /// <summary>
        /// Create ODataContextUrlInfo from ODataResourceTypeContext
        /// </summary>
        /// <param name="typeContext">The ODataResourceTypeContext to be used.</param>
        /// <param name="version">The OData Version of the response</param>
        /// <param name="isSingle">Whether target is single item.</param>
        /// <param name="odataUri">The odata uri info for current query.</param>
        /// <returns>The generated ODataContextUrlInfo.</returns>
        internal static ODataContextUrlInfo Create(ODataResourceTypeContext typeContext, ODataVersion version, bool isSingle, ODataUri odataUri = null)
        {
            Debug.Assert(typeContext != null, "typeContext != null");

            var hasNavigationSourceInfo = typeContext.NavigationSourceKind != EdmNavigationSourceKind.None ||
                                          !string.IsNullOrEmpty(typeContext.NavigationSourceName);

            var typeName = hasNavigationSourceInfo
                           ? typeContext.NavigationSourceFullTypeName
                           : typeContext.ExpectedResourceTypeName == null
                             ? null
                             : isSingle
                               ? typeContext.ExpectedResourceTypeName
                               : EdmLibraryExtensions.GetCollectionTypeName(typeContext.ExpectedResourceTypeName);

            return(new ODataContextUrlInfo()
            {
                HasNavigationSourceInfo = hasNavigationSourceInfo,
                IsUnknownEntitySet = typeContext.NavigationSourceKind == EdmNavigationSourceKind.UnknownEntitySet,
                NavigationSource = typeContext.NavigationSourceName,
                TypeCast = typeContext.NavigationSourceEntityTypeName == null ||
                           typeContext.ExpectedResourceTypeName == null ||
                           typeContext.ExpectedResourceType is IEdmComplexType ||
                           typeContext.NavigationSourceEntityTypeName == typeContext.ExpectedResourceTypeName
                           ? null : typeContext.ExpectedResourceTypeName,
                TypeName = typeName,
                IncludeFragmentItemSelector = isSingle && typeContext.NavigationSourceKind != EdmNavigationSourceKind.Singleton,
                NavigationPath = ComputeNavigationPath(typeContext.NavigationSourceKind, odataUri, typeContext.NavigationSourceName),
                ResourcePath = ComputeResourcePath(odataUri),
                QueryClause = ComputeQueryClause(odataUri, version),
                IsUndeclared = ComputeIfIsUndeclared(odataUri)
            });
        }
Exemple #4
0
        /// <summary>
        /// Create ODataContextUrlInfo from basic information
        /// </summary>
        /// <param name="navigationSource">Navigation source for current element.</param>\
        /// <param name="expectedEntityTypeName">The expectedEntity for current element.</param>
        /// <param name="isSingle">Whether target is single item.</param>
        /// <param name="odataUri">The odata uri info for current query.</param>
        /// <param name="version">The OData Version of the response.</param>
        /// <returns>The generated ODataContextUrlInfo.</returns>
        internal static ODataContextUrlInfo Create(IEdmNavigationSource navigationSource, string expectedEntityTypeName, bool isSingle, ODataUri odataUri, ODataVersion version)
        {
            EdmNavigationSourceKind kind      = navigationSource.NavigationSourceKind();
            string navigationSourceEntityType = navigationSource.EntityType().FullName();

            return(new ODataContextUrlInfo()
            {
                IsUnknownEntitySet = kind == EdmNavigationSourceKind.UnknownEntitySet,
                NavigationSource = navigationSource.Name,
                TypeCast = navigationSourceEntityType == expectedEntityTypeName ? null : expectedEntityTypeName,
                TypeName = navigationSourceEntityType,
                IncludeFragmentItemSelector = isSingle && kind != EdmNavigationSourceKind.Singleton,
                NavigationPath = ComputeNavigationPath(kind, odataUri, navigationSource.Name),
                ResourcePath = ComputeResourcePath(odataUri),
                QueryClause = ComputeQueryClause(odataUri, version),
                IsUndeclared = ComputeIfIsUndeclared(odataUri)
            });
        }
Exemple #5
0
 /// <summary>
 /// Create ODataContextUrlInfo for OdataValue.
 /// </summary>
 /// <param name="value">The ODataValue to be used.</param>
 /// <param name="version">OData Version.</param>
 /// <param name="odataUri">The odata uri info for current query.</param>
 /// <param name="model">The model used to handle unsigned int conversions.</param>
 /// <returns>The generated ODataContextUrlInfo.</returns>
 internal static ODataContextUrlInfo Create(ODataValue value, ODataVersion version, ODataUri odataUri = null, IEdmModel model = null)
 {
     return(new ODataContextUrlInfo()
     {
         TypeName = GetTypeNameForValue(value, model),
         ResourcePath = ComputeResourcePath(odataUri),
         QueryClause = ComputeQueryClause(odataUri, version),
         IsUndeclared = ComputeIfIsUndeclared(odataUri)
     });
 }
Exemple #6
0
        /// <summary>
        /// Build ODataUri into a Uri, the result Uri's query options are URL encoded.
        /// </summary>
        /// <param name="odataUri">ODataUri which will be build to relative url</param>
        /// <param name="urlKeyDelimiter">Value from ODataUrlKeyDelimiter</param>
        /// <returns>Uri of the semantic tree</returns>
        public static Uri BuildUri(this ODataUri odataUri, ODataUrlKeyDelimiter urlKeyDelimiter)
        {
            NodeToStringBuilder nodeToStringBuilder = new NodeToStringBuilder();
            SelectExpandClauseToStringBuilder selectExpandClauseToStringBuilder = new SelectExpandClauseToStringBuilder();

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

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

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

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

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

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

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

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

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

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

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

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

            return(odataUri.ServiceRoot == null ? new Uri(res, UriKind.Relative) : new Uri(odataUri.ServiceRoot, new Uri(res, UriKind.Relative)));
        }
 /// <summary>
 /// Constructor creating a new reader scope.
 /// </summary>
 /// <param name="state">The reader state of this scope.</param>
 /// <param name="item">The item attached to this scope.</param>
 /// <param name="navigationSource">The navigation source we are going to read entities for.</param>
 /// <param name="expectedResourceType">The expected resource type for the scope.</param>
 /// <param name="odataUri">The odataUri parsed based on the context uri for current scope</param>
 internal StreamScope(ODataReaderState state, ODataItem item, IEdmNavigationSource navigationSource, IEdmTypeReference expectedResourceType, ODataUri odataUri)
     : base(state, item, navigationSource, expectedResourceType, odataUri)
 {
     this.StreamingState = StreamingState.None;
 }
 internal Scope(ODataReaderState state, ODataItem item, IEdmNavigationSource navigationSource, IEdmTypeReference expectedResourceTypeReference, ODataUri odataUri)
     : this(state, item, odataUri)
 {
     this.NavigationSource      = navigationSource;
     this.ResourceTypeReference = expectedResourceTypeReference;
 }