示例#1
0
        public static bool TryConvertToLatest(
            PipelineContinuationToken pipelinedContinuationToken,
            out PipelineContinuationTokenV1_1 pipelineContinuationTokenV1_1)
        {
            if (pipelinedContinuationToken == null)
            {
                throw new ArgumentNullException(nameof(pipelinedContinuationToken));
            }

            if (pipelinedContinuationToken is PipelineContinuationTokenV0 pipelineContinuationTokenV0)
            {
                pipelinedContinuationToken = new PipelineContinuationTokenV1(pipelineContinuationTokenV0.SourceContinuationToken);
            }

            if (pipelinedContinuationToken is PipelineContinuationTokenV1 pipelineContinuationTokenV1)
            {
                pipelinedContinuationToken = new PipelineContinuationTokenV1_1(
                    queryPlan: null,
                    sourceContinuationToken: pipelineContinuationTokenV1.SourceContinuationToken);
            }

            if (!(pipelinedContinuationToken is PipelineContinuationTokenV1_1 convertedPipelineContinuationTokenV1_1))
            {
                pipelineContinuationTokenV1_1 = default;
                return(false);
            }
示例#2
0
        public static bool TryParse(
            CosmosObject parsedContinuationToken,
            out PipelineContinuationTokenV1_1 pipelinedContinuationToken)
        {
            if (parsedContinuationToken == null)
            {
                throw new ArgumentNullException(nameof(parsedContinuationToken));
            }

            if (!PipelineContinuationToken.TryParseVersion(
                    parsedContinuationToken,
                    out Version version))
            {
                pipelinedContinuationToken = default;
                return(false);
            }

            if (version != PipelineContinuationTokenV1_1.VersionNumber)
            {
                pipelinedContinuationToken = default;
                return(false);
            }

            if (!PipelineContinuationTokenV1_1.TryParseQueryPlan(
                    parsedContinuationToken,
                    out PartitionedQueryExecutionInfo queryPlan))
            {
                pipelinedContinuationToken = default;
                return(false);
            }

            if (!PipelineContinuationTokenV1_1.TryParseSourceContinuationToken(
                    parsedContinuationToken,
                    out string sourceContinuationToken))
            {
                pipelinedContinuationToken = default;
                return(false);
            }

            pipelinedContinuationToken = new PipelineContinuationTokenV1_1(queryPlan, sourceContinuationToken);
            return(true);
        }
示例#3
0
        public static bool TryParse(
            string rawContinuationToken,
            out PipelineContinuationToken pipelineContinuationToken)
        {
            if (rawContinuationToken == null)
            {
                throw new ArgumentNullException(nameof(rawContinuationToken));
            }

            if (!CosmosElement.TryParse <CosmosObject>(
                    rawContinuationToken,
                    out CosmosObject parsedContinuationToken))
            {
                // Failed to parse so we need to assume it's a V0 token
                if (!PipelineContinuationTokenV0.TryParse(
                        rawContinuationToken,
                        out PipelineContinuationTokenV0 pipelineContinuationTokenV0))
                {
                    pipelineContinuationToken = default;
                    return(false);
                }

                pipelineContinuationToken = pipelineContinuationTokenV0;
                return(true);
            }

            if (!PipelineContinuationToken.TryParseVersion(
                    parsedContinuationToken,
                    out Version version))
            {
                pipelineContinuationToken = default;
                return(false);
            }

            if (version == PipelineContinuationTokenV0.VersionNumber)
            {
                if (!PipelineContinuationTokenV0.TryParse(
                        rawContinuationToken,
                        out PipelineContinuationTokenV0 pipelineContinuationTokenV0))
                {
                    pipelineContinuationToken = default;
                    return(false);
                }

                pipelineContinuationToken = pipelineContinuationTokenV0;
            }
            else if (version == PipelineContinuationTokenV1.VersionNumber)
            {
                if (!PipelineContinuationTokenV1.TryParse(
                        parsedContinuationToken,
                        out PipelineContinuationTokenV1 pipelineContinuationTokenV1))
                {
                    pipelineContinuationToken = default;
                    return(false);
                }

                pipelineContinuationToken = pipelineContinuationTokenV1;
            }
            else if (version == PipelineContinuationTokenV1_1.VersionNumber)
            {
                if (!PipelineContinuationTokenV1_1.TryParse(
                        parsedContinuationToken,
                        out PipelineContinuationTokenV1_1 pipelineContinuationTokenV1_1))
                {
                    pipelineContinuationToken = default;
                    return(false);
                }

                pipelineContinuationToken = pipelineContinuationTokenV1_1;
            }
            else
            {
                pipelineContinuationToken = default;
                return(false);
            }

            return(true);
        }
示例#4
0
        public static bool TryCreateFromCosmosElement(
            CosmosElement cosmosElement,
            out PipelineContinuationToken pipelineContinuationToken)
        {
            if (cosmosElement == null)
            {
                throw new ArgumentNullException(nameof(cosmosElement));
            }

            if (!(cosmosElement is CosmosObject cosmosObject))
            {
                // Not a CosmosObject, so it doesn't have a version number, so
                pipelineContinuationToken = new PipelineContinuationTokenV0(cosmosElement);
                return(true);
            }

            if (!PipelineContinuationToken.TryParseVersion(
                    cosmosObject,
                    out Version version))
            {
                pipelineContinuationToken = default;
                return(false);
            }

            if (version == PipelineContinuationTokenV0.VersionNumber)
            {
                if (!PipelineContinuationTokenV0.TryCreateFromCosmosElement(
                        cosmosElement,
                        out PipelineContinuationTokenV0 pipelineContinuationTokenV0))
                {
                    pipelineContinuationToken = default;
                    return(false);
                }

                pipelineContinuationToken = pipelineContinuationTokenV0;
            }
            else if (version == PipelineContinuationTokenV1.VersionNumber)
            {
                if (!PipelineContinuationTokenV1.TryCreateFromCosmosElement(
                        cosmosObject,
                        out PipelineContinuationTokenV1 pipelineContinuationTokenV1))
                {
                    pipelineContinuationToken = default;
                    return(false);
                }

                pipelineContinuationToken = pipelineContinuationTokenV1;
            }
            else if (version == PipelineContinuationTokenV1_1.VersionNumber)
            {
                if (!PipelineContinuationTokenV1_1.TryCreateFromCosmosElement(
                        cosmosObject,
                        out PipelineContinuationTokenV1_1 pipelineContinuationTokenV1_1))
                {
                    pipelineContinuationToken = default;
                    return(false);
                }

                pipelineContinuationToken = pipelineContinuationTokenV1_1;
            }
            else
            {
                pipelineContinuationToken = default;
                return(false);
            }

            return(true);
        }