|
| 1 | +//------------------------------------------------------------ |
| 2 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +//------------------------------------------------------------ |
| 4 | + |
| 5 | +namespace Microsoft.Azure.Cosmos |
| 6 | +{ |
| 7 | + using System; |
| 8 | + using System.IO; |
| 9 | + using System.Linq; |
| 10 | + using System.Threading; |
| 11 | + using System.Threading.Tasks; |
| 12 | + |
| 13 | + // This class acts as a wrapper for environments that use SynchronizationContext. |
| 14 | + internal sealed partial class ContainerInlineCore : Container |
| 15 | + { |
| 16 | + private readonly ContainerCore container; |
| 17 | + |
| 18 | + public override string Id => this.container.Id; |
| 19 | + |
| 20 | + public override Conflicts Conflicts => this.container.Conflicts; |
| 21 | + |
| 22 | + public override Scripts.Scripts Scripts => this.container.Scripts; |
| 23 | + |
| 24 | + internal CosmosClientContext ClientContext => this.container.ClientContext; |
| 25 | + |
| 26 | + internal Uri LinkUri => this.container.LinkUri; |
| 27 | + |
| 28 | + internal ContainerInlineCore(ContainerCore container) |
| 29 | + { |
| 30 | + if (container == null) |
| 31 | + { |
| 32 | + throw new ArgumentNullException(nameof(container)); |
| 33 | + } |
| 34 | + |
| 35 | + this.container = container; |
| 36 | + } |
| 37 | + |
| 38 | + public override Task<ContainerResponse> ReadContainerAsync( |
| 39 | + ContainerRequestOptions requestOptions = null, |
| 40 | + CancellationToken cancellationToken = default) |
| 41 | + { |
| 42 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReadContainerAsync(requestOptions, cancellationToken)); |
| 43 | + } |
| 44 | + |
| 45 | + public override Task<ResponseMessage> ReadContainerStreamAsync( |
| 46 | + ContainerRequestOptions requestOptions = null, |
| 47 | + CancellationToken cancellationToken = default) |
| 48 | + { |
| 49 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReadContainerStreamAsync(requestOptions, cancellationToken)); |
| 50 | + } |
| 51 | + |
| 52 | + public override Task<ContainerResponse> ReplaceContainerAsync( |
| 53 | + ContainerProperties containerProperties, |
| 54 | + ContainerRequestOptions requestOptions = null, |
| 55 | + CancellationToken cancellationToken = default) |
| 56 | + { |
| 57 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReplaceContainerAsync(containerProperties, requestOptions, cancellationToken)); |
| 58 | + } |
| 59 | + |
| 60 | + public override Task<ResponseMessage> ReplaceContainerStreamAsync( |
| 61 | + ContainerProperties containerProperties, |
| 62 | + ContainerRequestOptions requestOptions = null, |
| 63 | + CancellationToken cancellationToken = default) |
| 64 | + { |
| 65 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReplaceContainerStreamAsync(containerProperties, requestOptions, cancellationToken)); |
| 66 | + } |
| 67 | + |
| 68 | + public override Task<ContainerResponse> DeleteContainerAsync( |
| 69 | + ContainerRequestOptions requestOptions = null, |
| 70 | + CancellationToken cancellationToken = default) |
| 71 | + { |
| 72 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.DeleteContainerAsync(requestOptions, cancellationToken)); |
| 73 | + } |
| 74 | + |
| 75 | + public override Task<ResponseMessage> DeleteContainerStreamAsync( |
| 76 | + ContainerRequestOptions requestOptions = null, |
| 77 | + CancellationToken cancellationToken = default) |
| 78 | + { |
| 79 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.DeleteContainerStreamAsync(requestOptions, cancellationToken)); |
| 80 | + } |
| 81 | + |
| 82 | + public override Task<int?> ReadThroughputAsync(CancellationToken cancellationToken = default) |
| 83 | + { |
| 84 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReadThroughputAsync(cancellationToken)); |
| 85 | + } |
| 86 | + |
| 87 | + public override Task<ThroughputResponse> ReadThroughputAsync( |
| 88 | + RequestOptions requestOptions, |
| 89 | + CancellationToken cancellationToken = default) |
| 90 | + { |
| 91 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReadThroughputAsync(requestOptions, cancellationToken)); |
| 92 | + } |
| 93 | + |
| 94 | + public override Task<ThroughputResponse> ReplaceThroughputAsync( |
| 95 | + int throughput, |
| 96 | + RequestOptions requestOptions = null, |
| 97 | + CancellationToken cancellationToken = default) |
| 98 | + { |
| 99 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReplaceThroughputAsync(throughput, requestOptions, cancellationToken)); |
| 100 | + } |
| 101 | + |
| 102 | + public override Task<ResponseMessage> CreateItemStreamAsync( |
| 103 | + Stream streamPayload, |
| 104 | + PartitionKey partitionKey, |
| 105 | + ItemRequestOptions requestOptions = null, |
| 106 | + CancellationToken cancellationToken = default) |
| 107 | + { |
| 108 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.CreateItemStreamAsync(streamPayload, partitionKey, requestOptions, cancellationToken)); |
| 109 | + } |
| 110 | + |
| 111 | + public override Task<ItemResponse<T>> CreateItemAsync<T>(T item, |
| 112 | + PartitionKey? partitionKey = null, |
| 113 | + ItemRequestOptions requestOptions = null, |
| 114 | + CancellationToken cancellationToken = default) |
| 115 | + { |
| 116 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.CreateItemAsync<T>(item, partitionKey, requestOptions, cancellationToken)); |
| 117 | + } |
| 118 | + |
| 119 | + public override Task<ResponseMessage> ReadItemStreamAsync( |
| 120 | + string id, |
| 121 | + PartitionKey partitionKey, |
| 122 | + ItemRequestOptions requestOptions = null, |
| 123 | + CancellationToken cancellationToken = default) |
| 124 | + { |
| 125 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReadItemStreamAsync(id, partitionKey, requestOptions, cancellationToken)); |
| 126 | + } |
| 127 | + |
| 128 | + public override Task<ItemResponse<T>> ReadItemAsync<T>( |
| 129 | + string id, |
| 130 | + PartitionKey partitionKey, |
| 131 | + ItemRequestOptions requestOptions = null, |
| 132 | + CancellationToken cancellationToken = default) |
| 133 | + { |
| 134 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReadItemAsync<T>(id, partitionKey, requestOptions, cancellationToken)); |
| 135 | + } |
| 136 | + |
| 137 | + public override Task<ResponseMessage> UpsertItemStreamAsync( |
| 138 | + Stream streamPayload, |
| 139 | + PartitionKey partitionKey, |
| 140 | + ItemRequestOptions requestOptions = null, |
| 141 | + CancellationToken cancellationToken = default) |
| 142 | + { |
| 143 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.UpsertItemStreamAsync(streamPayload, partitionKey, requestOptions, cancellationToken)); |
| 144 | + } |
| 145 | + |
| 146 | + public override Task<ItemResponse<T>> UpsertItemAsync<T>( |
| 147 | + T item, |
| 148 | + PartitionKey? partitionKey = null, |
| 149 | + ItemRequestOptions requestOptions = null, |
| 150 | + CancellationToken cancellationToken = default) |
| 151 | + { |
| 152 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.UpsertItemAsync<T>(item, partitionKey, requestOptions, cancellationToken)); |
| 153 | + } |
| 154 | + |
| 155 | + public override Task<ResponseMessage> ReplaceItemStreamAsync( |
| 156 | + Stream streamPayload, |
| 157 | + string id, |
| 158 | + PartitionKey partitionKey, |
| 159 | + ItemRequestOptions requestOptions = null, |
| 160 | + CancellationToken cancellationToken = default) |
| 161 | + { |
| 162 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReplaceItemStreamAsync(streamPayload, id, partitionKey, requestOptions, cancellationToken)); |
| 163 | + } |
| 164 | + |
| 165 | + public override Task<ItemResponse<T>> ReplaceItemAsync<T>( |
| 166 | + T item, |
| 167 | + string id, |
| 168 | + PartitionKey? partitionKey = null, |
| 169 | + ItemRequestOptions requestOptions = null, |
| 170 | + CancellationToken cancellationToken = default) |
| 171 | + { |
| 172 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReplaceItemAsync<T>(item, id, partitionKey, requestOptions, cancellationToken)); |
| 173 | + } |
| 174 | + |
| 175 | + public override Task<ResponseMessage> DeleteItemStreamAsync( |
| 176 | + string id, |
| 177 | + PartitionKey partitionKey, |
| 178 | + ItemRequestOptions requestOptions = null, |
| 179 | + CancellationToken cancellationToken = default) |
| 180 | + { |
| 181 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.DeleteItemStreamAsync(id, partitionKey, requestOptions, cancellationToken)); |
| 182 | + } |
| 183 | + |
| 184 | + public override Task<ItemResponse<T>> DeleteItemAsync<T>( |
| 185 | + string id, |
| 186 | + PartitionKey partitionKey, |
| 187 | + ItemRequestOptions requestOptions = null, |
| 188 | + CancellationToken cancellationToken = default) |
| 189 | + { |
| 190 | + return TaskHelper.RunInlineIfNeededAsync(() => this.container.DeleteItemAsync<T>(id, partitionKey, requestOptions, cancellationToken)); |
| 191 | + } |
| 192 | + |
| 193 | + public override FeedIterator GetItemQueryStreamIterator( |
| 194 | + QueryDefinition queryDefinition, |
| 195 | + string continuationToken = null, |
| 196 | + QueryRequestOptions requestOptions = null) |
| 197 | + { |
| 198 | + return this.container.GetItemQueryStreamIterator(queryDefinition, continuationToken, requestOptions); |
| 199 | + } |
| 200 | + |
| 201 | + public override FeedIterator<T> GetItemQueryIterator<T>( |
| 202 | + QueryDefinition queryDefinition, |
| 203 | + string continuationToken = null, |
| 204 | + QueryRequestOptions requestOptions = null) |
| 205 | + { |
| 206 | + return this.container.GetItemQueryIterator<T>(queryDefinition, continuationToken, requestOptions); |
| 207 | + } |
| 208 | + |
| 209 | + public override FeedIterator GetItemQueryStreamIterator(string queryText = null, |
| 210 | + string continuationToken = null, |
| 211 | + QueryRequestOptions requestOptions = null) |
| 212 | + { |
| 213 | + return this.container.GetItemQueryStreamIterator(queryText, continuationToken, requestOptions); |
| 214 | + } |
| 215 | + |
| 216 | + public override FeedIterator<T> GetItemQueryIterator<T>( |
| 217 | + string queryText = null, |
| 218 | + string continuationToken = null, |
| 219 | + QueryRequestOptions requestOptions = null) |
| 220 | + { |
| 221 | + return this.container.GetItemQueryIterator<T>(queryText, continuationToken, requestOptions); |
| 222 | + } |
| 223 | + |
| 224 | + public override IOrderedQueryable<T> GetItemLinqQueryable<T>(bool allowSynchronousQueryExecution = false, |
| 225 | + string continuationToken = null, |
| 226 | + QueryRequestOptions requestOptions = null) |
| 227 | + { |
| 228 | + return this.container.GetItemLinqQueryable<T>(allowSynchronousQueryExecution, continuationToken, requestOptions); |
| 229 | + } |
| 230 | + |
| 231 | + public override ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilder<T>( |
| 232 | + string processorName, |
| 233 | + ChangesHandler<T> onChangesDelegate) |
| 234 | + { |
| 235 | + return this.container.GetChangeFeedProcessorBuilder<T>(processorName, onChangesDelegate); |
| 236 | + } |
| 237 | + |
| 238 | + public override ChangeFeedProcessorBuilder GetChangeFeedEstimatorBuilder(string processorName, |
| 239 | + ChangesEstimationHandler estimationDelegate, |
| 240 | + TimeSpan? estimationPeriod = null) |
| 241 | + { |
| 242 | + return this.container.GetChangeFeedEstimatorBuilder(processorName, estimationDelegate, estimationPeriod); |
| 243 | + } |
| 244 | + |
| 245 | + public override TransactionalBatch CreateTransactionalBatch(PartitionKey partitionKey) |
| 246 | + { |
| 247 | + return this.container.CreateTransactionalBatch(partitionKey); |
| 248 | + } |
| 249 | + |
| 250 | + public static implicit operator ContainerCore(ContainerInlineCore containerInlineCore) => containerInlineCore.container; |
| 251 | + } |
| 252 | +} |
0 commit comments