ConnectionMode.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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;
  16. using MongoDB.Driver.Core.Clusters;
  17. namespace MongoDB.Driver
  18. {
  19. /// <summary>
  20. /// Server connection mode.
  21. /// </summary>
  22. #if NET452
  23. [Serializable]
  24. #endif
  25. public enum ConnectionMode
  26. {
  27. /// <summary>
  28. /// Automatically determine how to connect.
  29. /// </summary>
  30. Automatic,
  31. /// <summary>
  32. /// Connect directly to a server.
  33. /// </summary>
  34. Direct,
  35. /// <summary>
  36. /// Connect to a replica set.
  37. /// </summary>
  38. ReplicaSet,
  39. /// <summary>
  40. /// Connect to one or more shard routers.
  41. /// </summary>
  42. ShardRouter,
  43. /// <summary>
  44. /// Connect to a standalone server.
  45. /// </summary>
  46. Standalone
  47. }
  48. internal static class ConnectionModeExtensionMethods
  49. {
  50. public static ClusterConnectionMode ToCore(this ConnectionMode value)
  51. {
  52. switch (value)
  53. {
  54. case ConnectionMode.Automatic: return ClusterConnectionMode.Automatic;
  55. case ConnectionMode.Direct: return ClusterConnectionMode.Direct;
  56. case ConnectionMode.ReplicaSet: return ClusterConnectionMode.ReplicaSet;
  57. case ConnectionMode.ShardRouter: return ClusterConnectionMode.Sharded;
  58. case ConnectionMode.Standalone: return ClusterConnectionMode.Standalone;
  59. default: throw new ArgumentException("Invalid ConnectionMode.", "value");
  60. }
  61. }
  62. }
  63. }