IGridFSBucketExtensions.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Copyright 2016-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 MongoDB.Bson.IO;
  16. using MongoDB.Driver.Core.WireProtocol.Messages.Encoders;
  17. namespace MongoDB.Driver.GridFS
  18. {
  19. internal static class IGridFSBucketExtensions
  20. {
  21. internal static CollectionNamespace GetChunksCollectionNamespace<TFileId>(this IGridFSBucket<TFileId> bucket)
  22. {
  23. var databaseNamespace = bucket.Database.DatabaseNamespace;
  24. var collectionName = bucket.Options.BucketName + ".chunks";
  25. return new CollectionNamespace(databaseNamespace, collectionName);
  26. }
  27. internal static CollectionNamespace GetFilesCollectionNamespace<TFileId>(this IGridFSBucket<TFileId> bucket)
  28. {
  29. var databaseNamespace = bucket.Database.DatabaseNamespace;
  30. var collectionName = bucket.Options.BucketName + ".files";
  31. return new CollectionNamespace(databaseNamespace, collectionName);
  32. }
  33. internal static MessageEncoderSettings GetMessageEncoderSettings<TFileId>(this IGridFSBucket<TFileId> bucket)
  34. {
  35. var databaseSettings = bucket.Database.Settings;
  36. return new MessageEncoderSettings
  37. {
  38. { MessageEncoderSettingsName.GuidRepresentation, databaseSettings.GuidRepresentation },
  39. { MessageEncoderSettingsName.ReadEncoding, databaseSettings.ReadEncoding ?? Utf8Encodings.Strict },
  40. { MessageEncoderSettingsName.WriteEncoding, databaseSettings.WriteEncoding ?? Utf8Encodings.Strict }
  41. };
  42. }
  43. }
  44. }