Esempio n. 1
0
        protected static RequestOptions GetUpdatedBatchRequestOptions(
            RequestOptions batchOptions = null,
            bool isSchematized          = false,
            bool useEpk         = false,
            object partitionKey = null)
        {
            if (isSchematized)
            {
                if (batchOptions == null)
                {
                    batchOptions = new RequestOptions();
                }

                if (batchOptions.Properties == null)
                {
                    batchOptions.Properties = new Dictionary <string, object>();
                }

                batchOptions.Properties.Add(WFConstants.BackendHeaders.BinaryPassthroughRequest, bool.TrueString);

                if (useEpk)
                {
                    string epk = new Microsoft.Azure.Documents.PartitionKey(partitionKey)
                                 .InternalKey
                                 .GetEffectivePartitionKeyString(BatchTestBase.PartitionKeyDefinition);

                    batchOptions.Properties.Add(WFConstants.BackendHeaders.EffectivePartitionKeyString, epk);
                    batchOptions.Properties.Add(WFConstants.BackendHeaders.EffectivePartitionKey, BatchTestBase.HexStringToBytes(epk));
                    batchOptions.IsEffectivePartitionKeyRouting = true;
                }
            }

            return(batchOptions);
        }
Esempio n. 2
0
        private static bool PopulateRequestOptions(RequestOptions requestOptions, TestDoc doc, bool isSchematized, bool useEpk, int?ttlInSeconds)
        {
            if (isSchematized)
            {
                requestOptions.Properties.Add(WFConstants.BackendHeaders.BinaryId, Encoding.UTF8.GetBytes(doc.Id));

                if (ttlInSeconds.HasValue)
                {
                    requestOptions.Properties.Add(WFConstants.BackendHeaders.TimeToLiveInSeconds, ttlInSeconds.Value.ToString());
                }

                if (useEpk)
                {
                    string epk = new Microsoft.Azure.Documents.PartitionKey(doc.Status)
                                 .InternalKey
                                 .GetEffectivePartitionKeyString(BatchTestBase.PartitionKeyDefinition);

                    requestOptions.Properties.Add(WFConstants.BackendHeaders.EffectivePartitionKeyString, epk);
                    requestOptions.Properties.Add(WFConstants.BackendHeaders.EffectivePartitionKey, BatchTestBase.HexStringToBytes(epk));
                    requestOptions.IsEffectivePartitionKeyRouting = true;
                }

                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        protected static TransactionalBatchRequestOptions GetUpdatedBatchRequestOptions(
            TransactionalBatchRequestOptions batchOptions = null,
            bool isSchematized  = false,
            bool useEpk         = false,
            object partitionKey = null)
        {
            if (isSchematized)
            {
                if (batchOptions == null)
                {
                    batchOptions = new TransactionalBatchRequestOptions();
                }

                Dictionary <string, object> properties = new Dictionary <string, object>()
                {
                    { WFConstants.BackendHeaders.BinaryPassthroughRequest, bool.TrueString }
                };

                if (batchOptions.Properties != null)
                {
                    foreach (KeyValuePair <string, object> entry in batchOptions.Properties)
                    {
                        properties.Add(entry.Key, entry.Value);
                    }
                }

                if (useEpk)
                {
                    string epk = new Microsoft.Azure.Documents.PartitionKey(partitionKey)
                                 .InternalKey
                                 .GetEffectivePartitionKeyString(BatchTestBase.PartitionKeyDefinition);

                    properties.Add(WFConstants.BackendHeaders.EffectivePartitionKeyString, epk);
                    properties.Add(WFConstants.BackendHeaders.EffectivePartitionKey, BatchTestBase.HexStringToBytes(epk));
                    batchOptions.IsEffectivePartitionKeyRouting = true;
                }

                batchOptions.Properties = properties;
            }

            return(batchOptions);
        }