private static Uri GetNestedNextPageLink(ODataSerializerContext writeContext, int pageSize, object obj)
        {
            Contract.Assert(writeContext.ExpandedResource != null);
            IEdmNavigationSource sourceNavigationSource       = writeContext.ExpandedResource.NavigationSource;
            NavigationSourceLinkBuilderAnnotation linkBuilder = writeContext.Model.GetNavigationSourceLinkBuilder(sourceNavigationSource);
            Uri navigationLink =
                linkBuilder.BuildNavigationLink(writeContext.ExpandedResource, writeContext.NavigationProperty);
            Uri nestedNextLink = GenerateQueryFromExpandedItem(writeContext, navigationLink);
            SkipTokenHandler nextLinkGenerator = null;

            if (writeContext.QueryContext != null)
            {
                nextLinkGenerator = writeContext.QueryContext.GetSkipTokenHandler();
            }

            if (nestedNextLink != null)
            {
                if (nextLinkGenerator != null)
                {
                    return(nextLinkGenerator.GenerateNextPageLink(nestedNextLink, pageSize, obj, writeContext));
                }

                return(GetNextPageHelper.GetNextPageLink(nestedNextLink, pageSize));
            }

            return(null);
        }
        /// <summary>
        /// Creates a link for the next page of results; To be used as the value of @odata.nextLink.
        /// </summary>
        /// <param name="request">The request on which to base the next page link.</param>
        /// <param name="pageSize">The number of results allowed per page.</param>
        /// <param name="instance">The instance based on which the skiptoken value is generated. </param>
        /// <param name="objToSkipTokenValue">Function that extracts out the skiptoken value from the instance.</param>
        /// <returns>A next page link.</returns>
        public static Uri GetNextPageLink(this HttpRequestMessage request, int pageSize, object instance, Func <object, string> objToSkipTokenValue)
        {
            if (request == null || request.RequestUri == null)
            {
                throw Error.ArgumentNull("request");
            }

            return(GetNextPageHelper.GetNextPageLink(request.RequestUri, request.GetQueryNameValuePairs(), pageSize, instance, objToSkipTokenValue));
        }
        /// <summary>
        /// Returns the URI for NextPageLink
        /// </summary>
        /// <param name="baseUri">BaseUri for nextlink. It should be request URI for top level resource and navigation link for nested resource.</param>
        /// <param name="pageSize">Maximum number of records in the set of partial results for a resource.</param>
        /// <param name="instance">Instance based on which SkipToken value will be generated.</param>
        /// <param name="context">Serializer context</param>
        /// <returns>Returns the URI for NextPageLink. If a null object is passed for the instance, resorts to the default paging mechanism of using $skip and $top.</returns>
        public override Uri GenerateNextPageLink(Uri baseUri, int pageSize, Object instance, ODataSerializerContext context)
        {
            if (context == null)
            {
                return(null);
            }

            if (pageSize <= 0)
            {
                return(null);
            }

            Func <object, string>       skipTokenGenerator = null;
            IList <OrderByNode>         orderByNodes       = null;
            ExpandedReferenceSelectItem expandedItem       = context.CurrentSelectItem as ExpandedReferenceSelectItem;
            IEdmModel model = context.Model;

            DefaultQuerySettings settings = context.QueryContext.DefaultQuerySettings;

            if (settings.EnableSkipToken)
            {
                if (expandedItem != null)
                {
                    // Handle Delta resource; currently not value based.
                    if (DeltaHelper.IsDeltaOfT(context.ExpandedResource.GetType()))
                    {
                        return(GetNextPageHelper.GetNextPageLink(baseUri, pageSize));
                    }

                    if (expandedItem.OrderByOption != null)
                    {
                        orderByNodes = OrderByNode.CreateCollection(expandedItem.OrderByOption);
                    }

                    skipTokenGenerator = (obj) =>
                    {
                        return(GenerateSkipTokenValue(obj, model, orderByNodes));
                    };

                    return(GetNextPageHelper.GetNextPageLink(baseUri, pageSize, instance, skipTokenGenerator));
                }

                if (context.QueryOptions != null && context.QueryOptions.OrderBy != null)
                {
                    orderByNodes = context.QueryOptions.OrderBy.OrderByNodes;
                }

                skipTokenGenerator = (obj) =>
                {
                    return(GenerateSkipTokenValue(obj, model, orderByNodes));
                };
            }

            return(GetNextPageHelper.GetNextPageLink(baseUri, pageSize, instance, skipTokenGenerator));
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a link for the next page of results; To be used as the value of @odata.nextLink.
        /// </summary>
        /// <param name="request">The request on which to base the next page link.</param>
        /// <param name="pageSize">The number of results allowed per page.</param>
        /// <returns>A next page link.</returns>
        public static Uri GetNextPageLink(this HttpRequest request, int pageSize)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            UriBuilder uriBuilder = new UriBuilder(request.Scheme, request.Host.Host, request.Host.Port.HasValue ? request.Host.Port.Value : 80, (request.PathBase + request.Path).ToUriComponent());
            IEnumerable <KeyValuePair <string, string> > queryParameters = request.Query.SelectMany(kvp => kvp.Value, (kvp, value) => new KeyValuePair <string, string>(kvp.Key, value));

            return(GetNextPageHelper.GetNextPageLink(uriBuilder.Uri, queryParameters, pageSize));
        }
Esempio n. 5
0
        private static Uri GetNestedNextPageLink(ODataSerializerContext writeContext, int pageSize)
        {
            Contract.Assert(writeContext.ExpandedResource != null);

            IEdmNavigationSource sourceNavigationSource       = writeContext.ExpandedResource.NavigationSource;
            NavigationSourceLinkBuilderAnnotation linkBuilder = writeContext.Model.GetNavigationSourceLinkBuilder(sourceNavigationSource);
            Uri navigationLink =
                linkBuilder.BuildNavigationLink(writeContext.ExpandedResource, writeContext.NavigationProperty);

            if (navigationLink != null)
            {
                return(GetNextPageHelper.GetNextPageLink(navigationLink, pageSize));
            }

            return(null);
        }
        /// <summary>
        /// Creates a link for the next page of results; To be used as the value of @odata.nextLink.
        /// </summary>
        /// <param name="request">The request on which to base the next page link.</param>
        /// <param name="pageSize">The number of results allowed per page.</param>
        /// <returns>A next page link.</returns>
        public static Uri GetNextPageLink(this HttpRequestMessage request, int pageSize)
        {
            if (request == null || request.RequestUri == null)
            {
                throw Error.ArgumentNull("request");
            }

            Uri requestUri = request.RequestUri;

            if (!requestUri.IsAbsoluteUri)
            {
                throw Error.ArgumentUriNotAbsolute("request", requestUri);
            }

            return(GetNextPageHelper.GetNextPageLink(requestUri, request.GetQueryNameValuePairs(), pageSize));
        }
Esempio n. 7
0
        private static Uri GetNestedNextPageLink(ODataSerializerContext writeContext, int pageSize, object obj)
        {
            Contract.Assert(writeContext.ExpandedResource != null);
            Uri navigationLink;
            IEdmNavigationSource sourceNavigationSource       = writeContext.ExpandedResource.NavigationSource;
            NavigationSourceLinkBuilderAnnotation linkBuilder = writeContext.Model.GetNavigationSourceLinkBuilder(sourceNavigationSource);

            // In Contained Navigation, we don't have navigation property binding,
            // Hence we cannot get the NavigationLink from the NavigationLinkBuilder
            if (writeContext.NavigationSource.NavigationSourceKind() == EdmNavigationSourceKind.ContainedEntitySet)
            {
                // Contained navigation.
                Uri idlink = linkBuilder.BuildIdLink(writeContext.ExpandedResource);

                var link = idlink.ToString() + "/" + writeContext.NavigationProperty.Name;
                navigationLink = new Uri(link);
            }
            else
            {
                // Non-Contained navigation.
                navigationLink =
                    linkBuilder.BuildNavigationLink(writeContext.ExpandedResource, writeContext.NavigationProperty);
            }

            Uri nestedNextLink = GenerateQueryFromExpandedItem(writeContext, navigationLink);

            SkipTokenHandler nextLinkGenerator = null;

            if (writeContext.QueryContext != null)
            {
                nextLinkGenerator = writeContext.QueryContext.GetSkipTokenHandler();
            }

            if (nestedNextLink != null)
            {
                if (nextLinkGenerator != null)
                {
                    return(nextLinkGenerator.GenerateNextPageLink(nestedNextLink, pageSize, obj, writeContext));
                }

                return(GetNextPageHelper.GetNextPageLink(nestedNextLink, pageSize));
            }

            return(null);
        }
        /// <summary>
        /// Creates a link for the next page of results; To be used as the value of @odata.nextLink.
        /// </summary>
        /// <param name="request">The request on which to base the next page link.</param>
        /// <param name="pageSize">The number of results allowed per page.</param>
        /// <param name="instance">Object which can be used to generate the skiptoken value.</param>
        /// <param name="objectToSkipTokenValue">Function that takes in the last object and returns the skiptoken value string.</param>
        /// <returns>A next page link.</returns>
        public static Uri GetNextPageLink(this HttpRequest request, int pageSize, object instance, Func <object, string> objectToSkipTokenValue)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            UriBuilder uriBuilder = new UriBuilder(request.Scheme, request.Host.Host)
            {
                Path = (request.PathBase + request.Path).ToUriComponent()
            };

            if (request.Host.Port.HasValue)
            {
                uriBuilder.Port = request.Host.Port.Value;
            }

            CompatibilityOptions compatibilityOptions = request.GetCompatibilityOptions();

            IEnumerable <KeyValuePair <string, string> > queryParameters = request.Query.SelectMany(kvp => kvp.Value, (kvp, value) => new KeyValuePair <string, string>(kvp.Key, value));

            return(GetNextPageHelper.GetNextPageLink(uriBuilder.Uri, queryParameters, pageSize, instance, objectToSkipTokenValue, compatibilityOptions));
        }