OperationExecutor.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Copyright 2010-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System.Threading;
  16. using System.Threading.Tasks;
  17. using MongoDB.Driver.Core.Bindings;
  18. using MongoDB.Driver.Core.Operations;
  19. namespace MongoDB.Driver
  20. {
  21. internal sealed class OperationExecutor : IOperationExecutor
  22. {
  23. private readonly MongoClient _client;
  24. public OperationExecutor(MongoClient client)
  25. {
  26. _client = client;
  27. }
  28. public TResult ExecuteReadOperation<TResult>(IReadBinding binding, IReadOperation<TResult> operation, CancellationToken cancellationToken)
  29. {
  30. return operation.Execute(binding, cancellationToken);
  31. }
  32. public async Task<TResult> ExecuteReadOperationAsync<TResult>(IReadBinding binding, IReadOperation<TResult> operation, CancellationToken cancellationToken)
  33. {
  34. return await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false);
  35. }
  36. public TResult ExecuteWriteOperation<TResult>(IWriteBinding binding, IWriteOperation<TResult> operation, CancellationToken cancellationToken)
  37. {
  38. return operation.Execute(binding, cancellationToken);
  39. }
  40. public async Task<TResult> ExecuteWriteOperationAsync<TResult>(IWriteBinding binding, IWriteOperation<TResult> operation, CancellationToken cancellationToken)
  41. {
  42. return await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false);
  43. }
  44. public IClientSessionHandle StartImplicitSession(CancellationToken cancellationToken)
  45. {
  46. return _client.StartImplicitSession(cancellationToken);
  47. }
  48. public Task<IClientSessionHandle> StartImplicitSessionAsync(CancellationToken cancellationToken)
  49. {
  50. return _client.StartImplicitSessionAsync(cancellationToken);
  51. }
  52. }
  53. }