public CosmosElement Visit(FeedRangePartitionKey feedRange) { return(CosmosObject.Create(new Dictionary <string, CosmosElement>() { { TypePropertyName, LogicalPartitionKeyCosmosElement }, { ValuePropertyName, CosmosString.Create(feedRange.PartitionKey.ToJsonString()) }, })); }
public static bool TryParse( JObject jObject, JsonSerializer serializer, out FeedRangeInternal feedRangeInternal) { if (FeedRangeEPK.TryParse(jObject, serializer, out feedRangeInternal)) { return(true); } if (FeedRangePartitionKey.TryParse(jObject, serializer, out feedRangeInternal)) { return(true); } if (FeedRangePartitionKeyRange.TryParse(jObject, serializer, out feedRangeInternal)) { return(true); } feedRangeInternal = null; return(false); }
public void Visit(FeedRangePartitionKey feedRange) { this.request.Headers.PartitionKey = feedRange.PartitionKey.ToJsonString(); }
public async Task <IReadOnlyList <Documents.Routing.Range <string> > > VisitAsync(FeedRangePartitionKey feedRange, CancellationToken cancellationToken = default) { Routing.PartitionKeyRangeCache partitionKeyRangeCache = await this.container.ClientContext.DocumentClient.GetPartitionKeyRangeCacheAsync(); PartitionKeyDefinition partitionKeyDefinition = await this.container.GetPartitionKeyDefinitionAsync(cancellationToken); return(await feedRange.GetEffectiveRangesAsync( partitionKeyRangeCache, await this.container.GetRIDAsync(cancellationToken), partitionKeyDefinition)); }
public static TryCatch <FeedRangeInternal> MonadicCreateFromCosmosElement(CosmosElement cosmosElement) { if (cosmosElement == null) { throw new ArgumentNullException(nameof(cosmosElement)); } if (!(cosmosElement is CosmosObject cosmosObject)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"Expected object for feed range: {cosmosElement}."))); } if (!cosmosObject.TryGetValue(TypePropertyName, out CosmosString typeProperty)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"expected string type property for feed range: {cosmosElement}."))); } if (!cosmosObject.TryGetValue(ValuePropertyName, out CosmosElement valueProperty)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"expected value property for feed range: {cosmosElement}."))); } FeedRangeInternal feedRange; switch (typeProperty.Value) { case LogicalPartitionKey: { if (!(valueProperty is CosmosString stringValueProperty)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"expected string value property for logical partition key feed range: {cosmosElement}."))); } if (!PartitionKey.TryParseJsonString(stringValueProperty.Value, out PartitionKey partitionKey)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"failed to parse logical partition key value: {stringValueProperty.Value}."))); } feedRange = new FeedRangePartitionKey(partitionKey); } break; case PhysicalPartitionKeyRangeId: { if (!(valueProperty is CosmosString stringValueProperty)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"expected string value property for physical partition key feed range: {cosmosElement}."))); } feedRange = new FeedRangePartitionKeyRange(stringValueProperty.Value); } break; case EffectivePartitionKeyRange: { if (!(valueProperty is CosmosObject objectValueProperty)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"expected object value property for effective partition key range feed range: {cosmosElement}."))); } if (!objectValueProperty.TryGetValue(MinPropertyName, out CosmosString minPartitionKeyValue)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"expected string value property for min effective partition key value: {cosmosElement}."))); } if (!objectValueProperty.TryGetValue(MaxPropertyName, out CosmosString maxPartitionKeyValue)) { return(TryCatch <FeedRangeInternal> .FromException( new FormatException($"expected string value property for max effective partition key value: {cosmosElement}."))); } feedRange = new FeedRangeEpk( new Documents.Routing.Range <string>( min: minPartitionKeyValue.Value, max: maxPartitionKeyValue.Value, isMinInclusive: true, isMaxInclusive: false)); } break; default: throw new InvalidOperationException($"unexpected feed range type: {typeProperty.Value}"); } return(TryCatch <FeedRangeInternal> .FromResult(feedRange)); }