Exemple #1
0
            private static Result WriteDoc(ref RowWriter writer, TypeArgument typeArg, TestDoc doc)
            {
                Result r = writer.WriteString("Id", doc.Id);

                if (r != Result.Success)
                {
                    return(r);
                }

                r = writer.WriteInt32("Cost", doc.Cost);
                if (r != Result.Success)
                {
                    return(r);
                }

                r = writer.WriteString("Status", doc.Status);
                if (r != Result.Success)
                {
                    return(r);
                }

                r = writer.WriteString("Description", doc.Description);
                if (r != Result.Success)
                {
                    return(r);
                }

                return(Result.Success);
            }
Exemple #2
0
        private static Result WriteResult(ref RowWriter writer, TypeArgument typeArg, TransactionalBatchOperationResult result)
        {
            Result r = writer.WriteInt32("statusCode", (int)result.StatusCode);

            if (r != Result.Success)
            {
                return(r);
            }

            if (result.SubStatusCode != SubStatusCodes.Unknown)
            {
                r = writer.WriteInt32("subStatusCode", (int)result.SubStatusCode);
                if (r != Result.Success)
                {
                    return(r);
                }
            }

            if (result.ETag != null)
            {
                r = writer.WriteString("eTag", result.ETag);
                if (r != Result.Success)
                {
                    return(r);
                }
            }

            if (result.ResourceStream != null)
            {
                r = writer.WriteBinary("resourceBody", BatchResponsePayloadWriter.StreamToBytes(result.ResourceStream));
                if (r != Result.Success)
                {
                    return(r);
                }
            }

            if (result.RetryAfter != null)
            {
                r = writer.WriteUInt32("retryAfterMilliseconds", (uint)result.RetryAfter.TotalMilliseconds);
                if (r != Result.Success)
                {
                    return(r);
                }
            }

            r = writer.WriteFloat64("requestCharge", result.RequestCharge);
            if (r != Result.Success)
            {
                return(r);
            }

            return(Result.Success);
        }
Exemple #3
0
        internal virtual Result WriteRequestProperties(ref RowWriter writer, bool pkWritten)
        {
            if (this.Properties == null)
            {
                return(Result.Success);
            }

            if (this.Properties.TryGetValue(WFConstants.BackendHeaders.BinaryId, out object binaryIdObj) &&
                binaryIdObj is byte[] binaryId)
            {
                Result r = writer.WriteBinary("binaryId", binaryId);
                if (r != Result.Success)
                {
                    return(r);
                }
            }

            if (this.Properties.TryGetValue(WFConstants.BackendHeaders.EffectivePartitionKey, out object epkObj) &&
                epkObj is byte[] epk)
            {
                Result r = writer.WriteBinary("effectivePartitionKey", epk);
                if (r != Result.Success)
                {
                    return(r);
                }
            }

            if (!pkWritten && this.Properties.TryGetValue(HttpConstants.HttpHeaders.PartitionKey, out object pkStrObj) &&
                pkStrObj is string pkString)
            {
                Result r = writer.WriteString("partitionKey", pkString);
                if (r != Result.Success)
                {
                    return(r);
                }
            }

            if (this.Properties.TryGetValue(WFConstants.BackendHeaders.TimeToLiveInSeconds, out object ttlObj) &&
                ttlObj is string ttlStr && int.TryParse(ttlStr, out int ttl))
            {
                Result r = writer.WriteInt32("timeToLiveInSeconds", ttl);
                if (r != Result.Success)
                {
                    return(r);
                }
            }

            return(Result.Success);
        }
Exemple #4
0
        internal static Result WriteOperation(ref RowWriter writer, TypeArgument typeArg, ItemBatchOperation operation)
        {
            bool   pkWritten = false;
            Result r         = writer.WriteInt32("operationType", (int)operation.OperationType);

            if (r != Result.Success)
            {
                return(r);
            }

            r = writer.WriteInt32("resourceType", (int)ResourceType.Document);
            if (r != Result.Success)
            {
                return(r);
            }

            if (operation.PartitionKeyJson != null)
            {
                r = writer.WriteString("partitionKey", operation.PartitionKeyJson);
                if (r != Result.Success)
                {
                    return(r);
                }

                pkWritten = true;
            }

            if (operation.Id != null)
            {
                r = writer.WriteString("id", operation.Id);
                if (r != Result.Success)
                {
                    return(r);
                }
            }

            if (!operation.ResourceBody.IsEmpty)
            {
                r = writer.WriteBinary("resourceBody", operation.ResourceBody.Span);
                if (r != Result.Success)
                {
                    return(r);
                }
            }

            if (operation.RequestOptions != null)
            {
                TransactionalBatchItemRequestOptions options = operation.RequestOptions;
                if (options.IndexingDirective.HasValue)
                {
                    string indexingDirectiveString = IndexingDirectiveStrings.FromIndexingDirective(options.IndexingDirective.Value);
                    r = writer.WriteString("indexingDirective", indexingDirectiveString);
                    if (r != Result.Success)
                    {
                        return(r);
                    }
                }

                if (options.IfMatchEtag != null)
                {
                    r = writer.WriteString("ifMatch", options.IfMatchEtag);
                    if (r != Result.Success)
                    {
                        return(r);
                    }
                }
                else if (options.IfNoneMatchEtag != null)
                {
                    r = writer.WriteString("ifNoneMatch", options.IfNoneMatchEtag);
                    if (r != Result.Success)
                    {
                        return(r);
                    }
                }

                if (options.Properties != null)
                {
                    if (options.Properties.TryGetValue(WFConstants.BackendHeaders.BinaryId, out object binaryIdObj))
                    {
                        byte[] binaryId = binaryIdObj as byte[];
                        if (binaryId != null)
                        {
                            r = writer.WriteBinary("binaryId", binaryId);
                            if (r != Result.Success)
                            {
                                return(r);
                            }
                        }
                    }

                    if (options.Properties.TryGetValue(WFConstants.BackendHeaders.EffectivePartitionKey, out object epkObj))
                    {
                        byte[] epk = epkObj as byte[];
                        if (epk != null)
                        {
                            r = writer.WriteBinary("effectivePartitionKey", epk);
                            if (r != Result.Success)
                            {
                                return(r);
                            }
                        }
                    }

                    if (!pkWritten && options.Properties.TryGetValue(
                            HttpConstants.HttpHeaders.PartitionKey,
                            out object pkStrObj))
                    {
                        string pkString = pkStrObj as string;
                        if (pkString != null)
                        {
                            r = writer.WriteString("partitionKey", pkString);
                            if (r != Result.Success)
                            {
                                return(r);
                            }
                        }
                    }

                    if (options.Properties.TryGetValue(WFConstants.BackendHeaders.TimeToLiveInSeconds, out object ttlObj))
                    {
                        string ttlStr = ttlObj as string;
                        if (ttlStr != null && int.TryParse(ttlStr, out int ttl))
                        {
                            r = writer.WriteInt32("timeToLiveInSeconds", ttl);
                            if (r != Result.Success)
                            {
                                return(r);
                            }
                        }
                    }
                }
            }

            return(Result.Success);
        }