internal async Task <CosmosOfferResult> ReplaceThroughputIfExistsAsync( string targetRID, int targetThroughput, CancellationToken cancellationToken = default(CancellationToken)) { try { Offer offer = await this.ReadOfferAsync(targetRID, cancellationToken); if (offer == null) { throw new ArgumentOutOfRangeException("Throughput is not configured"); } OfferV2 offerV2 = offer as OfferV2; if (offerV2 == null) { throw new NotImplementedException(); } OfferV2 newOffer = new OfferV2(offerV2, targetThroughput); Offer replacedOffer = await this.ReplaceOfferAsync(targetRID, newOffer, cancellationToken); offerV2 = replacedOffer as OfferV2; Debug.Assert(offerV2 != null); return(new CosmosOfferResult(offerV2.Content.OfferThroughput)); } catch (DocumentClientException dce) { return(new CosmosOfferResult( dce.StatusCode ?? HttpStatusCode.InternalServerError, new CosmosException( dce.Message?.Replace(Environment.NewLine, string.Empty), dce.StatusCode ?? HttpStatusCode.InternalServerError, (int)dce.GetSubStatus(), dce.ActivityId, dce.RequestCharge))); } catch (AggregateException ex) { CosmosOfferResult offerResult = CosmosOffers.TryToOfferResult(ex); if (offerResult != null) { return(offerResult); } throw; } }
internal async Task <CosmosOfferResult> ReadProvisionedThroughputIfExistsAsync( string targetRID, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(targetRID)) { throw new ArgumentNullException(targetRID); } try { Offer offer = await this.ReadOfferAsync(targetRID, cancellationToken); return(this.GetThroughputIfExists(offer)); } catch (DocumentClientException dce) { return(new CosmosOfferResult( dce.StatusCode ?? HttpStatusCode.InternalServerError, new CosmosException( dce.Message?.Replace(Environment.NewLine, string.Empty), dce.StatusCode ?? HttpStatusCode.InternalServerError, (int)dce.GetSubStatus(), dce.ActivityId, dce.RequestCharge))); } catch (AggregateException ex) { CosmosOfferResult offerResult = CosmosOffers.TryToOfferResult(ex); if (offerResult != null) { return(offerResult); } throw; } }