ソースを参照

1.服务端警告当错误,修复所有编译错误
2.服务端mongodb使用nuget,客户端准备去除mongodb,方便以后热更,客户端会引入litjson

tanghai 5 年 前
コミット
0218cf218e
100 ファイル変更25 行追加22716 行削除
  1. BIN
      Proto/Proto2CS.dll
  2. BIN
      Proto/Proto2CS.pdb
  3. 4 2
      Server/App/Server.App.csproj
  4. 2 0
      Server/Hotfix/Demo/Actor_TransferHandler.cs
  5. 2 0
      Server/Hotfix/Demo/UnitPathComponentSystem.cs
  6. 2 0
      Server/Hotfix/Handler/C2M_ReloadHandler.cs
  7. 2 0
      Server/Hotfix/Module/ActorLocation/ObjectLockRequestHandler.cs
  8. 3 3
      Server/Hotfix/Module/DB/DBComponentSystem.cs
  9. 1 0
      Server/Hotfix/Module/Message/InnerMessageDispatcherHelper.cs
  10. 1 0
      Server/Hotfix/Scene/SceneFactory.cs
  11. 4 5
      Server/Hotfix/Server.Hotfix.csproj
  12. 4 7
      Server/Model/Server.Model.csproj
  13. 0 61
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/BsonConstants.cs
  14. 0 105
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/BsonDefaults.cs
  15. 0 246
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/BsonExtensionMethods.cs
  16. 0 265
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/BsonUtils.cs
  17. 0 81
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/Exceptions/BsonException.cs
  18. 0 71
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/Exceptions/BsonInternalException.cs
  19. 0 71
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/Exceptions/BsonSerializationException.cs
  20. 0 62
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/Exceptions/DuplicateBsonMemberMapAttributeException.cs
  21. 0 71
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/Exceptions/TruncationException.cs
  22. 0 125
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ArrayElementNameAccelerator.cs
  23. 0 825
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonBinaryReader.cs
  24. 0 52
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonBinaryReaderBookmark.cs
  25. 0 87
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonBinaryReaderContext.cs
  26. 0 148
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonBinaryReaderSettings.cs
  27. 0 775
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonBinaryWriter.cs
  28. 0 59
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonBinaryWriterContext.cs
  29. 0 134
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonBinaryWriterSettings.cs
  30. 0 259
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonChunkPool.cs
  31. 0 562
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonDocumentReader.cs
  32. 0 52
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonDocumentReaderBookmark.cs
  33. 0 128
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonDocumentReaderContext.cs
  34. 0 90
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonDocumentReaderSettings.cs
  35. 0 551
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonDocumentWriter.cs
  36. 0 91
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonDocumentWriterContext.cs
  37. 0 91
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonDocumentWriterSettings.cs
  38. 0 440
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonReader.cs
  39. 0 67
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonReaderBookmark.cs
  40. 0 123
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonReaderSettings.cs
  41. 0 60
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonReaderState.cs
  42. 0 140
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonStream.cs
  43. 0 567
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonStreamAdapter.cs
  44. 0 315
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonStreamExtensions.cs
  45. 0 354
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonTrie.cs
  46. 0 473
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonWriter.cs
  47. 0 137
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonWriterSettings.cs
  48. 0 48
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonWriterState.cs
  49. 0 294
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ByteArrayBuffer.cs
  50. 0 111
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ByteArrayChunk.cs
  51. 0 75
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ByteBufferFactory.cs
  52. 0 235
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ByteBufferSlice.cs
  53. 0 727
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ByteBufferStream.cs
  54. 0 76
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/CStringUtf8Encoding.cs
  55. 0 44
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ContextType.cs
  56. 0 84
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ElementAppendingBsonWriter.cs
  57. 0 39
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IBsonChunk.cs
  58. 0 33
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IBsonChunkSource.cs
  59. 0 235
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IBsonReader.cs
  60. 0 361
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IBsonReaderExtensions.cs
  61. 0 234
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IBsonWriter.cs
  62. 0 293
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IBsonWriterExtensions.cs
  63. 0 122
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IByteBuffer.cs
  64. 0 38
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IElementNameValidator.cs
  65. 0 43
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/INameDecoder.cs
  66. 0 174
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/InputBufferChunkSource.cs
  67. 0 204
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonBuffer.cs
  68. 0 299
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonConvert.cs
  69. 0 47
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonOutputMode.cs
  70. 0 1926
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonReader.cs
  71. 0 76
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonReaderBookmark.cs
  72. 0 57
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonReaderContext.cs
  73. 0 81
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonReaderSettings.cs
  74. 0 523
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonScanner.cs
  75. 0 496
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonToken.cs
  76. 0 907
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonWriter.cs
  77. 0 56
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonWriterContext.cs
  78. 0 178
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonWriterSettings.cs
  79. 0 452
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/MultiChunkBuffer.cs
  80. 0 60
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/NoOpElementNameValidator.cs
  81. 0 176
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/OutputBufferChunkSource.cs
  82. 0 283
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/SingleChunkBuffer.cs
  83. 0 105
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/TrieNameDecoder.cs
  84. 0 46
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/Utf8Encodings.cs
  85. 0 67
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/Utf8Helper.cs
  86. 0 64
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/Utf8NameDecoder.cs
  87. 0 361
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/WrappingBsonWriter.cs
  88. 0 755
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonArray.cs
  89. 0 362
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonBinaryData.cs
  90. 0 58
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonBinarySubType.cs
  91. 0 312
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonBoolean.cs
  92. 0 284
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonDateTime.cs
  93. 0 350
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonDecimal128.cs
  94. 0 1313
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonDocument.cs
  95. 0 195
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonDocumentWrapper.cs
  96. 0 374
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonDouble.cs
  97. 0 178
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonElement.cs
  98. 0 457
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonInt32.cs
  99. 0 411
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonInt64.cs
  100. 0 182
      Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonJavaScript.cs

BIN
Proto/Proto2CS.dll


BIN
Proto/Proto2CS.pdb


+ 4 - 2
Server/App/Server.App.csproj

@@ -13,13 +13,15 @@
   </PropertyGroup>
 
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
-    <DefineConstants>TRACE;DEBUG;NETCOREAPP2_0;SERVER</DefineConstants>
+    <DefineConstants>TRACE2_0;SERVER;NOT_CLIENT</DefineConstants>
     <OutputPath>..\..\Bin\</OutputPath>
+    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
   </PropertyGroup>
 
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
-    <DefineConstants>TRACE;RELEASE;NETCOREAPP2_0;SERVER</DefineConstants>
+    <DefineConstants>TRACE2_0;SERVER;NOT_CLIENT</DefineConstants>
     <OutputPath>..\..\Bin\</OutputPath>
+    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
   </PropertyGroup>
 
   <ItemGroup>

+ 2 - 0
Server/Hotfix/Demo/Actor_TransferHandler.cs

@@ -37,6 +37,8 @@ namespace ET
 			//await Game.Scene.GetComponent<LocationProxyComponent>().UnLock(unitId, instanceId, m2m_TrasferUnitResponse.InstanceId);
 
 			reply();
+			
+			await ETTask.CompletedTask;
 		}
 	}
 }

+ 2 - 0
Server/Hotfix/Demo/UnitPathComponentSystem.cs

@@ -22,6 +22,7 @@ namespace ET
                 Vector3 v3 = path[i];
                 //await self.Parent.GetComponent<MoveComponent>().MoveToAsync(v3, self.CancellationToken);
             }
+            await ETTask.CompletedTask;
         }
         
         public static async ETVoid MoveTo(this UnitPathComponent self, Vector3 target)
@@ -42,6 +43,7 @@ namespace ET
             m2CPathfindingResult.Z = unit.Position.z;
             m2CPathfindingResult.Id = unit.Id;
             MessageHelper.Broadcast(unit, m2CPathfindingResult);
+            await ETTask.CompletedTask;
         }
 
         // 从index找接下来3个点,广播

+ 2 - 0
Server/Hotfix/Handler/C2M_ReloadHandler.cs

@@ -22,6 +22,8 @@ namespace ET
 			//	await serverSession.Call(new M2A_Reload());
 			//}
 			reply();
+			
+			await ETTask.CompletedTask;
 		}
 	}
 }

+ 2 - 0
Server/Hotfix/Module/ActorLocation/ObjectLockRequestHandler.cs

@@ -10,6 +10,8 @@ namespace ET
 		{
 			scene.GetComponent<LocationComponent>().Lock(request.Key, request.InstanceId, request.Time).Coroutine();
 			reply();
+			
+			await ETTask.CompletedTask;
 		}
 	}
 }

+ 3 - 3
Server/Hotfix/Module/DB/DBComponentSystem.cs

@@ -157,7 +157,7 @@ namespace ET
 
 		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, entity.Id % DBComponent.TaskCount))
 		    {
-			    await self.GetCollection(collection).ReplaceOneAsync(d => d.Id == entity.Id, entity, new UpdateOptions { IsUpsert = true });
+			    await self.GetCollection(collection).ReplaceOneAsync(d => d.Id == entity.Id, entity, new ReplaceOptions { IsUpsert = true });
 		    }
 	    }
 
@@ -177,7 +177,7 @@ namespace ET
 
 		    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
 		    {
-			    await self.GetCollection(collection).ReplaceOneAsync(d => d.Id == entity.Id, entity, new UpdateOptions { IsUpsert = true });
+			    await self.GetCollection(collection).ReplaceOneAsync(d => d.Id == entity.Id, entity, new ReplaceOptions { IsUpsert = true });
 		    }
 	    }
 
@@ -199,7 +199,7 @@ namespace ET
 				    }
 
 				    await self.GetCollection(entity.GetType().Name)
-						    .ReplaceOneAsync(d => d.Id == entity.Id, entity, new UpdateOptions { IsUpsert = true });
+						    .ReplaceOneAsync(d => d.Id == entity.Id, entity, new ReplaceOptions { IsUpsert = true });
 			    }
 		    }
 	    }

+ 1 - 0
Server/Hotfix/Module/Message/InnerMessageDispatcherHelper.cs

@@ -7,6 +7,7 @@
         public static async ETVoid HandleIActorResponse(Session session, IActorResponse iActorResponse)
 		{
 			ActorMessageSenderComponent.Instance.RunMessage(iActorResponse);
+			await ETTask.CompletedTask;
 		}
 
 		public static async ETVoid HandleIActorRequest(Session session, IActorRequest iActorRequest)

+ 1 - 0
Server/Hotfix/Scene/SceneFactory.cs

@@ -12,6 +12,7 @@ namespace ET
         
         public static async ETTask<Scene> Create(Entity parent, long id, int zone, string name, SceneType sceneType, StartSceneConfig startSceneConfig = null)
         {
+            await ETTask.CompletedTask;
             Scene scene = EntitySceneFactory.CreateScene(id, zone, sceneType, name);
             scene.Parent = parent;
 

+ 4 - 5
Server/Hotfix/Server.Hotfix.csproj

@@ -9,12 +9,14 @@
     <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
-    <DefineConstants>TRACE;DEBUG;NETCOREAPP2_0;SERVER</DefineConstants>
+    <DefineConstants>TRACE2_0;SERVER;NOT_CLIENT</DefineConstants>
     <OutputPath>..\..\Bin\</OutputPath>
+    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
-    <DefineConstants>TRACE;RELEASE;NETCOREAPP2_0;SERVER</DefineConstants>
+    <DefineConstants>TRACE2_0;SERVER;NOT_CLIENT</DefineConstants>
     <OutputPath>..\..\Bin\</OutputPath>
+    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
   </PropertyGroup>
   <ItemGroup>
     <Compile Remove="Other\**" />
@@ -33,7 +35,4 @@
   <ItemGroup>
     <ProjectReference Include="..\Model\Server.Model.csproj" />
   </ItemGroup>
-  <ItemGroup>
-    <Folder Include="Helper" />
-  </ItemGroup>
 </Project>

+ 4 - 7
Server/Model/Server.Model.csproj

@@ -9,14 +9,16 @@
     <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
-    <DefineConstants>TRACE;DEBUG;NETCOREAPP2_0;SERVER</DefineConstants>
+    <DefineConstants>TRACE2_0;SERVER;NOT_CLIENT</DefineConstants>
     <OutputPath>..\..\Bin\</OutputPath>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
-    <DefineConstants>TRACE;RELEASE;NETCOREAPP2_0;SERVER</DefineConstants>
+    <DefineConstants>TRACE2_0;SERVER;NOT_CLIENT</DefineConstants>
     <OutputPath>..\..\Bin\</OutputPath>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
   </PropertyGroup>
   <ItemGroup>
     <Compile Remove="Libs\**" />
@@ -280,9 +282,4 @@
     <Folder Include="Module\Message\Network\KCP\" />
     <Folder Include="Module\Message\Network\TCP\" />
   </ItemGroup>
-  <ItemGroup>
-    <Reference Include="Pathfinding.Ionic.Zip.Reduced, Version=1.9.1.9000, Culture=neutral, PublicKeyToken=null">
-      <HintPath>..\ThirdParty\Pathfinding.Ionic.Zip.Reduced.dll</HintPath>
-    </Reference>
-  </ItemGroup>
 </Project>

+ 0 - 61
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/BsonConstants.cs

@@ -1,61 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// A static class containing BSON constants.
-    /// </summary>
-    public static class BsonConstants
-    {
-        // private static fields
-        private static readonly long __dateTimeMaxValueMillisecondsSinceEpoch;
-        private static readonly long __dateTimeMinValueMillisecondsSinceEpoch;
-        private static readonly DateTime __unixEpoch;
-
-        // static constructor
-        static BsonConstants()
-        {
-            // unixEpoch has to be initialized first
-            __unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
-            __dateTimeMaxValueMillisecondsSinceEpoch = (DateTime.MaxValue - __unixEpoch).Ticks / 10000;
-            __dateTimeMinValueMillisecondsSinceEpoch = (DateTime.MinValue - __unixEpoch).Ticks / 10000;
-        }
-
-        // public static properties
-        /// <summary>
-        /// Gets the number of milliseconds since the Unix epoch for DateTime.MaxValue.
-        /// </summary>
-        public static long DateTimeMaxValueMillisecondsSinceEpoch
-        {
-            get { return __dateTimeMaxValueMillisecondsSinceEpoch; }
-        }
-
-        /// <summary>
-        /// Gets the number of milliseconds since the Unix epoch for DateTime.MinValue.
-        /// </summary>
-        public static long DateTimeMinValueMillisecondsSinceEpoch
-        {
-            get { return __dateTimeMinValueMillisecondsSinceEpoch; }
-        }
-
-        /// <summary>
-        /// Gets the Unix Epoch for BSON DateTimes (1970-01-01).
-        /// </summary>
-        public static DateTime UnixEpoch { get { return __unixEpoch; } }
-    }
-}

+ 0 - 105
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/BsonDefaults.cs

@@ -1,105 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System.Collections.Generic;
-using System.Dynamic;
-using MongoDB.Bson.Serialization;
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// A static helper class containing BSON defaults.
-    /// </summary>
-    public static class BsonDefaults
-    {
-        // private static fields
-        private static bool __dynamicArraySerializerWasSet;
-        private static IBsonSerializer __dynamicArraySerializer;
-        private static bool __dynamicDocumentSerializerWasSet;
-        private static IBsonSerializer __dynamicDocumentSerializer; 
-        private static GuidRepresentation __guidRepresentation = GuidRepresentation.CSharpLegacy;
-        private static int __maxDocumentSize = int.MaxValue;
-        private static int __maxSerializationDepth = 100;
-
-        // public static properties
-        /// <summary>
-        /// Gets or sets the dynamic array serializer.
-        /// </summary>
-        public static IBsonSerializer DynamicArraySerializer
-        {
-            get
-            {
-                if (!__dynamicArraySerializerWasSet)
-                {
-                    __dynamicArraySerializer = BsonSerializer.LookupSerializer<List<object>>();
-                }
-                return __dynamicArraySerializer;
-            }
-            set 
-            {
-                __dynamicArraySerializerWasSet = true;
-                __dynamicArraySerializer = value; 
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets the dynamic document serializer.
-        /// </summary>
-        public static IBsonSerializer DynamicDocumentSerializer
-        {
-            get 
-            {
-                if (!__dynamicDocumentSerializerWasSet)
-                {
-                    __dynamicDocumentSerializer = BsonSerializer.LookupSerializer<ExpandoObject>();
-                }
-                return __dynamicDocumentSerializer; 
-            }
-            set 
-            {
-                __dynamicDocumentSerializerWasSet = true;
-                __dynamicDocumentSerializer = value; 
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets the default representation to be used in serialization of 
-        /// Guids to the database. 
-        /// <seealso cref="MongoDB.Bson.GuidRepresentation"/> 
-        /// </summary>
-        public static GuidRepresentation GuidRepresentation
-        {
-            get { return __guidRepresentation; }
-            set { __guidRepresentation = value; }
-        }
-
-        /// <summary>
-        /// Gets or sets the default max document size. The default is 4MiB.
-        /// </summary>
-        public static int MaxDocumentSize
-        {
-            get { return __maxDocumentSize; }
-            set { __maxDocumentSize = value; }
-        }
-
-        /// <summary>
-        /// Gets or sets the default max serialization depth (used to detect circular references during serialization). The default is 100.
-        /// </summary>
-        public static int MaxSerializationDepth
-        {
-            get { return __maxSerializationDepth; }
-            set { __maxSerializationDepth = value; }
-        }
-    }
-}

+ 0 - 246
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/BsonExtensionMethods.cs

@@ -1,246 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-using MongoDB.Bson.IO;
-using MongoDB.Bson.Serialization;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// A static class containing BSON extension methods.
-    /// </summary>
-    public static class BsonExtensionMethods
-    {
-        /// <summary>
-        /// Serializes an object to a BSON byte array.
-        /// </summary>
-        /// <typeparam name="TNominalType">The nominal type of the object.</typeparam>
-        /// <param name="obj">The object.</param>
-        /// <param name="serializer">The serializer.</param>
-        /// <param name="writerSettings">The writer settings.</param>
-        /// <param name="configurator">The serialization context configurator.</param>
-        /// <param name="args">The serialization args.</param>
-        /// <returns>A BSON byte array.</returns>
-        public static byte[] ToBson<TNominalType>(
-            this TNominalType obj,
-            IBsonSerializer<TNominalType> serializer = null,
-            BsonBinaryWriterSettings writerSettings = null,
-            Action<BsonSerializationContext.Builder> configurator = null,
-            BsonSerializationArgs args = default(BsonSerializationArgs)
-            )
-        {
-            return ToBson(obj, typeof(TNominalType), writerSettings, serializer, configurator, args);
-        }
-
-        /// <summary>
-        /// Serializes an object to a BSON byte array.
-        /// </summary>
-        /// <param name="obj">The object.</param>
-        /// <param name="nominalType">The nominal type of the object..</param>
-        /// <param name="writerSettings">The writer settings.</param>
-        /// <param name="serializer">The serializer.</param>
-        /// <param name="configurator">The serialization context configurator.</param>
-        /// <param name="args">The serialization args.</param>
-        /// <returns>A BSON byte array.</returns>
-        /// <exception cref="System.ArgumentNullException">nominalType</exception>
-        /// <exception cref="System.ArgumentException">serializer</exception>
-        public static byte[] ToBson(
-            this object obj,
-            Type nominalType,
-            BsonBinaryWriterSettings writerSettings = null,
-            IBsonSerializer serializer = null,
-            Action<BsonSerializationContext.Builder> configurator = null,
-            BsonSerializationArgs args = default(BsonSerializationArgs))
-        {
-            if (nominalType == null)
-            {
-                throw new ArgumentNullException("nominalType");
-            }
-
-            if (serializer == null)
-            {
-                serializer = BsonSerializer.LookupSerializer(nominalType);
-            }
-            if (serializer.ValueType != nominalType)
-            {
-                var message = string.Format("Serializer type {0} value type does not match document types {1}.", serializer.GetType().FullName, nominalType.FullName);
-                throw new ArgumentException(message, "serializer");
-            }
-
-            using (var memoryStream = new MemoryStream())
-            {
-                using (var bsonWriter = new BsonBinaryWriter(memoryStream, writerSettings ?? BsonBinaryWriterSettings.Defaults))
-                {
-                    var context = BsonSerializationContext.CreateRoot(bsonWriter, configurator);
-                    args.NominalType = nominalType;
-                    serializer.Serialize(context, args, obj);
-                }
-                return memoryStream.ToArray();
-            }
-        }
-
-        /// <summary>
-        /// Serializes an object to a BsonDocument.
-        /// </summary>
-        /// <typeparam name="TNominalType">The nominal type of the object.</typeparam>
-        /// <param name="obj">The object.</param>
-        /// <param name="serializer">The serializer.</param>
-        /// <param name="configurator">The serialization context configurator.</param>
-        /// <param name="args">The serialization args.</param>
-        /// <returns>A BsonDocument.</returns>
-        public static BsonDocument ToBsonDocument<TNominalType>(
-            this TNominalType obj, 
-            IBsonSerializer<TNominalType> serializer = null,
-            Action<BsonSerializationContext.Builder> configurator = null,
-            BsonSerializationArgs args = default(BsonSerializationArgs))
-        {
-            return ToBsonDocument(obj, typeof(TNominalType), serializer, configurator, args);
-        }
-
-        /// <summary>
-        /// Serializes an object to a BsonDocument.
-        /// </summary>
-        /// <param name="obj">The object.</param>
-        /// <param name="nominalType">The nominal type of the object.</param>
-        /// <param name="serializer">The serializer.</param>
-        /// <param name="configurator">The serialization context configurator.</param>
-        /// <param name="args">The serialization args.</param>
-        /// <returns>A BsonDocument.</returns>
-        /// <exception cref="System.ArgumentNullException">nominalType</exception>
-        /// <exception cref="System.ArgumentException">serializer</exception>
-        public static BsonDocument ToBsonDocument(
-            this object obj,
-            Type nominalType,
-            IBsonSerializer serializer = null,
-            Action<BsonSerializationContext.Builder> configurator = null,
-            BsonSerializationArgs args = default(BsonSerializationArgs))
-        {
-            if (nominalType == null)
-            {
-                throw new ArgumentNullException("nominalType");
-            }
-
-            if (obj == null)
-            {
-                return null;
-            }
-
-            if (serializer == null)
-            {
-                var bsonDocument = obj as BsonDocument;
-                if (bsonDocument != null)
-                {
-                    return bsonDocument; // it's already a BsonDocument
-                }
-
-                var convertibleToBsonDocument = obj as IConvertibleToBsonDocument;
-                if (convertibleToBsonDocument != null)
-                {
-                    return convertibleToBsonDocument.ToBsonDocument(); // use the provided ToBsonDocument method
-                }
-
-                serializer = BsonSerializer.LookupSerializer(nominalType);
-            }
-            if (serializer.ValueType != nominalType)
-            {
-                var message = string.Format("Serializer type {0} value type does not match document types {1}.", serializer.GetType().FullName, nominalType.FullName);
-                throw new ArgumentException(message, "serializer");
-            }
-
-            // otherwise serialize into a new BsonDocument
-            var document = new BsonDocument();
-            using (var bsonWriter = new BsonDocumentWriter(document))
-            {
-                var context = BsonSerializationContext.CreateRoot(bsonWriter, configurator);
-                args.NominalType = nominalType;
-                serializer.Serialize(context, args, obj);
-            }
-            return document;
-        }
-
-        /// <summary>
-        /// Serializes an object to a JSON string.
-        /// </summary>
-        /// <typeparam name="TNominalType">The nominal type of the object.</typeparam>
-        /// <param name="obj">The object.</param>
-        /// <param name="writerSettings">The JsonWriter settings.</param>
-        /// <param name="serializer">The serializer.</param>
-        /// <param name="configurator">The serializastion context configurator.</param>
-        /// <param name="args">The serialization args.</param>
-        /// <returns>
-        /// A JSON string.
-        /// </returns>
-        public static string ToJson<TNominalType>(
-            this TNominalType obj, 
-            JsonWriterSettings writerSettings = null,
-            IBsonSerializer<TNominalType> serializer = null, 
-            Action<BsonSerializationContext.Builder> configurator = null,
-            BsonSerializationArgs args = default(BsonSerializationArgs))
-        {
-            return ToJson(obj, typeof(TNominalType), writerSettings, serializer, configurator, args);
-        }
-
-        /// <summary>
-        /// Serializes an object to a JSON string.
-        /// </summary>
-        /// <param name="obj">The object.</param>
-        /// <param name="nominalType">The nominal type of the objectt.</param>
-        /// <param name="writerSettings">The JsonWriter settings.</param>
-        /// <param name="serializer">The serializer.</param>
-        /// <param name="configurator">The serialization context configurator.</param>
-        /// <param name="args">The serialization args.</param>
-        /// <returns>
-        /// A JSON string.
-        /// </returns>
-        /// <exception cref="System.ArgumentNullException">nominalType</exception>
-        /// <exception cref="System.ArgumentException">serializer</exception>
-        public static string ToJson(
-            this object obj,
-            Type nominalType,
-            JsonWriterSettings writerSettings = null,
-            IBsonSerializer serializer = null,
-            Action<BsonSerializationContext.Builder> configurator = null,
-            BsonSerializationArgs args = default(BsonSerializationArgs))
-        {
-            if (nominalType == null)
-            {
-                throw new ArgumentNullException("nominalType");
-            }
-
-            if (serializer == null)
-            {
-                serializer = BsonSerializer.LookupSerializer(nominalType);
-            }
-            if (serializer.ValueType != nominalType)
-            {
-                var message = string.Format("Serializer type {0} value type does not match document types {1}.", serializer.GetType().FullName, nominalType.FullName);
-                throw new ArgumentException(message, "serializer");
-            }
-
-            using (var stringWriter = new StringWriter())
-            {
-                using (var bsonWriter = new JsonWriter(stringWriter, writerSettings ?? JsonWriterSettings.Defaults))
-                {
-                    var context = BsonSerializationContext.CreateRoot(bsonWriter, configurator);
-                    args.NominalType = nominalType;
-                    serializer.Serialize(context, args, obj);
-                }
-                return stringWriter.ToString();
-            }
-        }
-    }
-}

+ 0 - 265
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/BsonUtils.cs

@@ -1,265 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Reflection;
-using System.Text;
-using System.Text.RegularExpressions;
-
-namespace MongoDB.Bson
-{
-
-    /// <summary>
-    /// A static class containing BSON utility methods.
-    /// </summary>
-    public static class BsonUtils
-    {
-        // public static methods
-        /// <summary>
-        /// Gets a friendly class name suitable for use in error messages.
-        /// </summary>
-        /// <param name="type">The type.</param>
-        /// <returns>A friendly class name.</returns>
-        public static string GetFriendlyTypeName(Type type)
-        {
-            var typeInfo = type.GetTypeInfo();
-            if (!typeInfo.IsGenericType)
-            {
-                return type.Name;
-            }
-
-            var sb = new StringBuilder();
-            sb.AppendFormat("{0}<", Regex.Replace(type.Name, @"\`\d+$", ""));
-            foreach (var typeParameter in type.GetTypeInfo().GetGenericArguments())
-            {
-                sb.AppendFormat("{0}, ", GetFriendlyTypeName(typeParameter));
-            }
-            sb.Remove(sb.Length - 2, 2);
-            sb.Append(">");
-            return sb.ToString();
-        }
-
-        /// <summary>
-        /// Parses a hex string into its equivalent byte array.
-        /// </summary>
-        /// <param name="s">The hex string to parse.</param>
-        /// <returns>The byte equivalent of the hex string.</returns>
-        public static byte[] ParseHexString(string s)
-        {
-            if (s == null)
-            {
-                throw new ArgumentNullException(nameof(s));
-            }
-
-            byte[] bytes;
-            if (!TryParseHexString(s, out bytes))
-            {
-                throw new FormatException("String should contain only hexadecimal digits.");
-            }
-
-            return bytes;
-        }
-
-        /// <summary>
-        /// Converts from number of milliseconds since Unix epoch to DateTime.
-        /// </summary>
-        /// <param name="millisecondsSinceEpoch">The number of milliseconds since Unix epoch.</param>
-        /// <returns>A DateTime.</returns>
-        public static DateTime ToDateTimeFromMillisecondsSinceEpoch(long millisecondsSinceEpoch)
-        {
-            if (millisecondsSinceEpoch < BsonConstants.DateTimeMinValueMillisecondsSinceEpoch ||
-                millisecondsSinceEpoch > BsonConstants.DateTimeMaxValueMillisecondsSinceEpoch)
-            {
-                var message = string.Format(
-                    "The value {0} for the BsonDateTime MillisecondsSinceEpoch is outside the"+
-                    "range that can be converted to a .NET DateTime.",
-                    millisecondsSinceEpoch);
-                throw new ArgumentOutOfRangeException("millisecondsSinceEpoch", message);
-            }
-
-            // MaxValue has to be handled specially to avoid rounding errors
-            if (millisecondsSinceEpoch == BsonConstants.DateTimeMaxValueMillisecondsSinceEpoch)
-            {
-                return DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc);
-            }
-            else
-            {
-                return BsonConstants.UnixEpoch.AddTicks(millisecondsSinceEpoch * 10000);
-            }
-        }
-
-        /// <summary>
-        /// Converts a value to a hex character.
-        /// </summary>
-        /// <param name="value">The value (assumed to be between 0 and 15).</param>
-        /// <returns>The hex character.</returns>
-        public static char ToHexChar(int value)
-        {
-            return (char)(value + (value < 10 ? '0' : 'a' - 10));
-        }
-
-        /// <summary>
-        /// Converts a byte array to a hex string.
-        /// </summary>
-        /// <param name="bytes">The byte array.</param>
-        /// <returns>A hex string.</returns>
-        public static string ToHexString(byte[] bytes)
-        {
-            if (bytes == null)
-            {
-                throw new ArgumentNullException("bytes");
-            }
-
-            var length = bytes.Length;
-            var c = new char[length * 2];
-
-            for (int i = 0, j = 0; i < length; i++)
-            {
-                var b = bytes[i];
-                c[j++] = ToHexChar(b >> 4);
-                c[j++] = ToHexChar(b & 0x0f);
-            }
-
-            return new string(c);
-        }
-
-        /// <summary>
-        /// Converts a DateTime to local time (with special handling for MinValue and MaxValue).
-        /// </summary>
-        /// <param name="dateTime">A DateTime.</param>
-        /// <returns>The DateTime in local time.</returns>
-        public static DateTime ToLocalTime(DateTime dateTime)
-        {
-            if (dateTime == DateTime.MinValue)
-            {
-                return DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Local);
-            }
-            else if (dateTime == DateTime.MaxValue)
-            {
-                return DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Local);
-            }
-            else
-            {
-                return dateTime.ToLocalTime();
-            }
-        }
-
-        /// <summary>
-        /// Converts a DateTime to number of milliseconds since Unix epoch.
-        /// </summary>
-        /// <param name="dateTime">A DateTime.</param>
-        /// <returns>Number of seconds since Unix epoch.</returns>
-        public static long ToMillisecondsSinceEpoch(DateTime dateTime)
-        {
-            var utcDateTime = ToUniversalTime(dateTime);
-            return (utcDateTime - BsonConstants.UnixEpoch).Ticks / 10000;
-        }
-
-        /// <summary>
-        /// Converts a DateTime to UTC (with special handling for MinValue and MaxValue).
-        /// </summary>
-        /// <param name="dateTime">A DateTime.</param>
-        /// <returns>The DateTime in UTC.</returns>
-        public static DateTime ToUniversalTime(DateTime dateTime)
-        {
-            if (dateTime == DateTime.MinValue)
-            {
-                return DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc);
-            }
-            else if (dateTime == DateTime.MaxValue)
-            {
-                return DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc);
-            }
-            else
-            {
-                return dateTime.ToUniversalTime();
-            }
-        }
-
-        /// <summary>
-        /// Tries to parse a hex string to a byte array.
-        /// </summary>
-        /// <param name="s">The hex string.</param>
-        /// <param name="bytes">A byte array.</param>
-        /// <returns>True if the hex string was successfully parsed.</returns>
-        public static bool TryParseHexString(string s, out byte[] bytes)
-        {
-            bytes = null;
-
-            if (s == null)
-            {
-                return false;
-            }
-
-            var buffer = new byte[(s.Length + 1) / 2];
-
-            var i = 0;
-            var j = 0;
-
-            if ((s.Length % 2) == 1)
-            {
-                // if s has an odd length assume an implied leading "0"
-                int y;
-                if (!TryParseHexChar(s[i++], out y))
-                {
-                    return false;
-                }
-                buffer[j++] = (byte)y;
-            }
-
-            while (i < s.Length)
-            {
-                int x, y;
-                if (!TryParseHexChar(s[i++], out x))
-                {
-                    return false;
-                }
-                if (!TryParseHexChar(s[i++], out y))
-                {
-                    return false;
-                }
-                buffer[j++] = (byte)((x << 4) | y);
-            }
-
-            bytes = buffer;
-            return true;
-        }
-
-        // private static methods
-        private static bool TryParseHexChar(char c, out int value)
-        {
-            if (c >= '0' && c <= '9')
-            {
-                value = c - '0';
-                return true;
-            }
-
-            if (c >= 'a' && c <= 'f')
-            {
-                value = 10 + (c - 'a');
-                return true;
-            }
-
-            if (c >= 'A' && c <= 'F')
-            {
-                value = 10 + (c - 'A');
-                return true;
-            }
-
-            value = 0;
-            return false;
-        }
-    }
-}

+ 0 - 81
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/Exceptions/BsonException.cs

@@ -1,81 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-#if NET452
-using System.Runtime.Serialization;
-#endif
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents a BSON exception.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonException : Exception
-    {
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonException class.
-        /// </summary>
-        public BsonException()
-            : base()
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonException class.
-        /// </summary>
-        /// <param name="message">The error message.</param>
-        public BsonException(string message)
-            : base(message)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonException class.
-        /// </summary>
-        /// <param name="message">The error message.</param>
-        /// <param name="innerException">The inner exception.</param>
-        public BsonException(string message, Exception innerException)
-            : base(message, innerException)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonException class.
-        /// </summary>
-        /// <param name="format">The error message format string.</param>
-        /// <param name="args">One or more args for the error message.</param>
-        public BsonException(string format, params object[] args)
-            : base(string.Format(format, args))
-        {
-        }
-
-#if NET452
-        /// <summary>
-        /// Initializes a new instance of the BsonException class (this overload used by deserialization).
-        /// </summary>
-        /// <param name="info">The SerializationInfo.</param>
-        /// <param name="context">The StreamingContext.</param>
-        public BsonException(SerializationInfo info, StreamingContext context)
-            : base(info, context)
-        {
-        }
-#endif
-    }
-}

+ 0 - 71
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/Exceptions/BsonInternalException.cs

@@ -1,71 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-#if NET452
-using System.Runtime.Serialization;
-#endif
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents a BSON internal exception (almost surely the result of a bug).
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonInternalException : BsonException
-    {
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonInternalException class.
-        /// </summary>
-        public BsonInternalException()
-            : base()
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonInternalException class.
-        /// </summary>
-        /// <param name="message">The error message.</param>
-        public BsonInternalException(string message)
-            : base(message)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonInternalException class.
-        /// </summary>
-        /// <param name="message">The error message.</param>
-        /// <param name="innerException">The inner exception.</param>
-        public BsonInternalException(string message, Exception innerException)
-            : base(message, innerException)
-        {
-        }
-
-#if NET452
-        /// <summary>
-        /// Initializes a new instance of the BsonInternalException class (this overload used by deserialization).
-        /// </summary>
-        /// <param name="info">The SerializationInfo.</param>
-        /// <param name="context">The StreamingContext.</param>
-        public BsonInternalException(SerializationInfo info, StreamingContext context)
-            : base(info, context)
-        {
-        }
-#endif
-    }
-}

+ 0 - 71
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/Exceptions/BsonSerializationException.cs

@@ -1,71 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-#if NET452
-using System.Runtime.Serialization;
-#endif
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents a BSON serialization exception.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonSerializationException : BsonException
-    {
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonSerializationException class.
-        /// </summary>
-        public BsonSerializationException()
-            : base()
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonSerializationException class.
-        /// </summary>
-        /// <param name="message">The error message.</param>
-        public BsonSerializationException(string message)
-            : base(message)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonSerializationException class.
-        /// </summary>
-        /// <param name="message">The error message.</param>
-        /// <param name="innerException">The inner exception.</param>
-        public BsonSerializationException(string message, Exception innerException)
-            : base(message, innerException)
-        {
-        }
-
-#if NET452
-        /// <summary>
-        /// Initializes a new instance of the BsonSerializationException class (this overload used by deserialization).
-        /// </summary>
-        /// <param name="info">The SerializationInfo.</param>
-        /// <param name="context">The StreamingContext.</param>
-        public BsonSerializationException(SerializationInfo info, StreamingContext context)
-            : base(info, context)
-        {
-        }
-#endif
-    }
-}

+ 0 - 62
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/Exceptions/DuplicateBsonMemberMapAttributeException.cs

@@ -1,62 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Indicates that an attribute restricted to one member has been applied to multiple members.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class DuplicateBsonMemberMapAttributeException : BsonException
-    {
-        // constructors 
-        /// <summary>
-        /// Initializes a new instance of the <see cref="DuplicateBsonMemberMapAttributeException" /> class.
-        /// </summary>
-        /// <param name="message">The message.</param>
-        public DuplicateBsonMemberMapAttributeException(string message)
-            : base(message)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="DuplicateBsonMemberMapAttributeException" /> class.
-        /// </summary>
-        /// <param name="message">The message.</param>
-        /// <param name="inner">The inner.</param>
-        public DuplicateBsonMemberMapAttributeException(string message, Exception inner)
-            : base(message, inner)
-        {
-        }
-
-#if NET452
-        /// <summary>
-        /// Initializes a new instance of the <see cref="DuplicateBsonMemberMapAttributeException" /> class.
-        /// </summary>
-        /// <param name="info">The info.</param>
-        /// <param name="context">The context.</param>
-        protected DuplicateBsonMemberMapAttributeException(
-          System.Runtime.Serialization.SerializationInfo info,
-          System.Runtime.Serialization.StreamingContext context)
-            : base(info, context)
-        {
-        }
-#endif
-    }
-}

+ 0 - 71
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/Exceptions/TruncationException.cs

@@ -1,71 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-#if NET452
-using System.Runtime.Serialization;
-#endif
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents a truncation exception.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class TruncationException : BsonException
-    {
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the TruncationException class.
-        /// </summary>
-        public TruncationException()
-            : this("Truncation resulted in data loss.")
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the TruncationException class.
-        /// </summary>
-        /// <param name="message">The error message.</param>
-        public TruncationException(string message)
-            : base(message)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the TruncationException class.
-        /// </summary>
-        /// <param name="message">The error message.</param>
-        /// <param name="innerException">The inner exception.</param>
-        public TruncationException(string message, Exception innerException)
-            : base(message, innerException)
-        {
-        }
-
-#if NET452
-        /// <summary>
-        /// Initializes a new instance of the TruncationException class (this overload used by deserialization).
-        /// </summary>
-        /// <param name="info">The SerializationInfo.</param>
-        /// <param name="context">The StreamingContext.</param>
-        public TruncationException(SerializationInfo info, StreamingContext context)
-            : base(info, context)
-        {
-        }
-#endif
-    }
-}

+ 0 - 125
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ArrayElementNameAccelerator.cs

@@ -1,125 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a fast converter from integer indexes to UTF8 BSON array element names.
-    /// </summary>
-    internal interface IArrayElementNameAccelerator
-    {
-        /// <summary>
-        /// Gets the element name bytes.
-        /// </summary>
-        /// <param name="index">The index.</param>
-        /// <returns>The element name bytes.</returns>
-        byte[] GetElementNameBytes(int index);
-    }
-
-    /// <summary>
-    /// Represents a fast converter from integer indexes to UTF8 BSON array element names.
-    /// </summary>
-    internal class ArrayElementNameAccelerator : IArrayElementNameAccelerator
-    {
-        #region static
-        // static fields
-        private static IArrayElementNameAccelerator __default = new ArrayElementNameAccelerator(1000);
-
-        // static properties
-        /// <summary>
-        /// Gets or sets the default array element name accelerator.
-        /// </summary>
-        public static IArrayElementNameAccelerator Default
-        {
-            get { return __default; }
-            set { __default = value; }
-        }
-        #endregion
-
-        // fields
-        private readonly byte[][] _cachedElementNames;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="ArrayElementNameAccelerator"/> class.
-        /// </summary>
-        /// <param name="numberOfCachedElementNames">The number of cached element names.</param>
-        public ArrayElementNameAccelerator(int numberOfCachedElementNames)
-        {
-            _cachedElementNames = new byte[numberOfCachedElementNames][];
-            for (int index = 0; index < numberOfCachedElementNames; index++)
-            {
-                _cachedElementNames[index] = CreateElementNameBytes(index);
-            }
-        }
-
-        // methods
-        private byte[] CreateElementNameBytes(int index)
-        {
-            // unrolled loop optimized for index values >= 1000 and < 10,000
-
-            const int asciiZero = 48;
-
-            var n = index;
-            var a = (byte)(asciiZero + n % 10);
-            n = n / 10;
-            var b = (byte)(asciiZero + n % 10);
-            n = n / 10;
-            var c = (byte)(asciiZero + n % 10);
-            n = n / 10;
-            var d = (byte)(asciiZero + n % 10);
-            n = n / 10;
-
-            if (n == 0)
-            {
-                if (d != (byte)asciiZero) { return new[] { d, c, b, a }; }
-                if (c != (byte)asciiZero) { return new[] { c, b, a }; }
-                if (b != (byte)asciiZero) { return new[] { b, a }; }
-                return new[] { a };
-            }
-
-            var e = (byte)(asciiZero + n % 10);
-            n = n / 10;
-            if (n == 0) { return new[] { e, d, c, b, a }; }
-
-            // really large indexes should be extremely rare and not worth optimizing further
-            return Utf8Encodings.Strict.GetBytes(index.ToString());
-        }
-
-        /// <summary>
-        /// Gets the element name bytes.
-        /// </summary>
-        /// <param name="index">The index.</param>
-        /// <returns>
-        /// The element name bytes.
-        /// </returns>
-        public byte[] GetElementNameBytes(int index)
-        {
-            if (index < 0)
-            {
-                throw new ArgumentOutOfRangeException("index", "index is negative.");
-            }
-
-            if (index < _cachedElementNames.Length)
-            {
-                return  _cachedElementNames[index];
-            }
-
-            return CreateElementNameBytes(index);
-        }
-    }
-}

+ 0 - 825
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonBinaryReader.cs

@@ -1,825 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Globalization;
-using System.IO;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a BSON reader for a binary BSON byte array.
-    /// </summary>
-    public class BsonBinaryReader : BsonReader
-    {
-        // private fields
-        private readonly Stream _baseStream;
-        private readonly BsonStream _bsonStream;
-        private readonly BsonBinaryReaderSettings _settings; // same value as in base class just declared as derived class
-        private BsonBinaryReaderContext _context;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonBinaryReader class.
-        /// </summary>
-        /// <param name="stream">A stream (BsonBinary does not own the stream and will not Dispose it).</param>
-        public BsonBinaryReader(Stream stream)
-            : this(stream, BsonBinaryReaderSettings.Defaults)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonBinaryReader class.
-        /// </summary>
-        /// <param name="stream">A stream (BsonBinary does not own the stream and will not Dispose it).</param>
-        /// <param name="settings">A BsonBinaryReaderSettings.</param>
-        public BsonBinaryReader(Stream stream, BsonBinaryReaderSettings settings)
-            : base(settings)
-        {
-            if (stream == null)
-            {
-                throw new ArgumentNullException("stream");
-            }
-            if (!stream.CanSeek)
-            {
-                throw new ArgumentException("The stream must be capable of seeking.", "stream");
-            }
-
-            _baseStream = stream;
-            _bsonStream = (stream as BsonStream) ?? new BsonStreamAdapter(stream);
-            _settings = settings; // already frozen by base class
-
-            _context = new BsonBinaryReaderContext(null, ContextType.TopLevel, 0, 0);
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the base stream.
-        /// </summary>
-        /// <value>
-        /// The base stream.
-        /// </value>
-        public Stream BaseStream
-        {
-            get { return _baseStream; }
-        }
-
-        /// <summary>
-        /// Gets the BSON stream.
-        /// </summary>
-        /// <value>
-        /// The BSON stream.
-        /// </value>
-        public BsonStream BsonStream
-        {
-            get { return _bsonStream; }
-        }
-
-        // public methods
-        /// <summary>
-        /// Closes the reader.
-        /// </summary>
-        public override void Close()
-        {
-            // Close can be called on Disposed objects
-            State = BsonReaderState.Closed;
-        }
-
-        /// <summary>
-        /// Gets a bookmark to the reader's current position and state.
-        /// </summary>
-        /// <returns>A bookmark.</returns>
-        public override BsonReaderBookmark GetBookmark()
-        {
-            return new BsonBinaryReaderBookmark(State, CurrentBsonType, CurrentName, _context, _bsonStream.Position);
-        }
-
-        /// <summary>
-        /// Determines whether this reader is at end of file.
-        /// </summary>
-        /// <returns>
-        /// Whether this reader is at end of file.
-        /// </returns>
-        public override bool IsAtEndOfFile()
-        {
-            return _bsonStream.Position >= _bsonStream.Length;
-        }
-
-        /// <summary>
-        /// Reads BSON binary data from the reader.
-        /// </summary>
-        /// <returns>A BsonBinaryData.</returns>
-#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
-        public override BsonBinaryData ReadBinaryData()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadBinaryData", BsonType.Binary);
-
-            int size = ReadSize();
-
-            var subType = _bsonStream.ReadBinarySubType();
-            if (subType == BsonBinarySubType.OldBinary)
-            {
-                // sub type OldBinary has two sizes (for historical reasons)
-                int size2 = ReadSize();
-                if (size2 != size - 4)
-                {
-                    throw new FormatException("Binary sub type OldBinary has inconsistent sizes");
-                }
-                size = size2;
-
-                if (_settings.FixOldBinarySubTypeOnInput)
-                {
-                    subType = BsonBinarySubType.Binary; // replace obsolete OldBinary with new Binary sub type
-                }
-            }
-
-            var bytes = _bsonStream.ReadBytes(size);
-
-            GuidRepresentation guidRepresentation;
-            switch (subType)
-            {
-                case BsonBinarySubType.UuidLegacy: guidRepresentation = _settings.GuidRepresentation; break;
-                case BsonBinarySubType.UuidStandard: guidRepresentation = GuidRepresentation.Standard; break;
-                default: guidRepresentation = GuidRepresentation.Unspecified; break;
-            }
-
-            State = GetNextState();
-            return new BsonBinaryData(bytes, subType, guidRepresentation);
-        }
-#pragma warning restore 618
-
-        /// <summary>
-        /// Reads a BSON boolean from the reader.
-        /// </summary>
-        /// <returns>A Boolean.</returns>
-        public override bool ReadBoolean()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadBoolean", BsonType.Boolean);
-            State = GetNextState();
-            return _bsonStream.ReadBoolean();
-        }
-
-        /// <summary>
-        /// Reads a BsonType from the reader.
-        /// </summary>
-        /// <returns>A BsonType.</returns>
-        public override BsonType ReadBsonType()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (State == BsonReaderState.Initial || State == BsonReaderState.ScopeDocument)
-            {
-                // there is an implied type of Document for the top level and for scope documents
-                CurrentBsonType = BsonType.Document;
-                State = BsonReaderState.Value;
-                return CurrentBsonType;
-            }
-            if (State != BsonReaderState.Type)
-            {
-                ThrowInvalidState("ReadBsonType", BsonReaderState.Type);
-            }
-
-            if (_context.ContextType == ContextType.Array)
-            {
-                _context.CurrentArrayIndex++;
-            }
-
-            try
-            {
-
-                CurrentBsonType = _bsonStream.ReadBsonType();
-            }
-            catch (FormatException ex)
-            {
-                if (ex.Message.StartsWith("Detected unknown BSON type"))
-                {
-                    // insert the element name into the error message
-                    var periodIndex = ex.Message.IndexOf('.');
-                    var dottedElementName = GenerateDottedElementName();
-                    var message = ex.Message.Substring(0, periodIndex) + $" for fieldname \"{dottedElementName}\"" + ex.Message.Substring(periodIndex);
-                    throw new FormatException(message);
-                }
-                throw;
-            }
-
-            if (CurrentBsonType == BsonType.EndOfDocument)
-            {
-                switch (_context.ContextType)
-                {
-                    case ContextType.Array:
-                        State = BsonReaderState.EndOfArray;
-                        return BsonType.EndOfDocument;
-                    case ContextType.Document:
-                    case ContextType.ScopeDocument:
-                        State = BsonReaderState.EndOfDocument;
-                        return BsonType.EndOfDocument;
-                    default:
-                        var message = string.Format("BsonType EndOfDocument is not valid when ContextType is {0}.", _context.ContextType);
-                        throw new FormatException(message);
-                }
-            }
-            else
-            {
-                switch (_context.ContextType)
-                {
-                    case ContextType.Array:
-                        _bsonStream.SkipCString(); // ignore array element names
-                        State = BsonReaderState.Value;
-                        break;
-                    case ContextType.Document:
-                    case ContextType.ScopeDocument:
-                        State = BsonReaderState.Name;
-                        break;
-                    default:
-                        throw new BsonInternalException("Unexpected ContextType.");
-                }
-
-                return CurrentBsonType;
-            }
-        }
-
-        /// <summary>
-        /// Reads BSON binary data from the reader.
-        /// </summary>
-        /// <returns>A byte array.</returns>
-#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
-        public override byte[] ReadBytes()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadBytes", BsonType.Binary);
-
-            int size = ReadSize();
-
-            var subType = _bsonStream.ReadBinarySubType();
-            if (subType != BsonBinarySubType.Binary && subType != BsonBinarySubType.OldBinary)
-            {
-                var message = string.Format("ReadBytes requires the binary sub type to be Binary, not {0}.", subType);
-                throw new FormatException(message);
-            }
-
-            State = GetNextState();
-            return _bsonStream.ReadBytes(size);
-        }
-#pragma warning restore 618
-
-        /// <summary>
-        /// Reads a BSON DateTime from the reader.
-        /// </summary>
-        /// <returns>The number of milliseconds since the Unix epoch.</returns>
-        public override long ReadDateTime()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadDateTime", BsonType.DateTime);
-            State = GetNextState();
-            var value = _bsonStream.ReadInt64();
-            if (value == BsonConstants.DateTimeMaxValueMillisecondsSinceEpoch + 1)
-            {
-                if (_settings.FixOldDateTimeMaxValueOnInput)
-                {
-                    value = BsonConstants.DateTimeMaxValueMillisecondsSinceEpoch;
-                }
-            }
-            return value;
-        }
-
-        /// <inheritdoc />
-        public override Decimal128 ReadDecimal128()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType(nameof(ReadDecimal128), BsonType.Decimal128);
-            State = GetNextState();
-            return _bsonStream.ReadDecimal128();
-        }
-
-        /// <summary>
-        /// Reads a BSON Double from the reader.
-        /// </summary>
-        /// <returns>A Double.</returns>
-        public override double ReadDouble()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadDouble", BsonType.Double);
-            State = GetNextState();
-            return _bsonStream.ReadDouble();
-        }
-
-        /// <summary>
-        /// Reads the end of a BSON array from the reader.
-        /// </summary>
-        public override void ReadEndArray()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (_context.ContextType != ContextType.Array)
-            {
-                ThrowInvalidContextType("ReadEndArray", _context.ContextType, ContextType.Array);
-            }
-            if (State == BsonReaderState.Type)
-            {
-                ReadBsonType(); // will set state to EndOfArray if at end of array
-            }
-            if (State != BsonReaderState.EndOfArray)
-            {
-                ThrowInvalidState("ReadEndArray", BsonReaderState.EndOfArray);
-            }
-
-            _context = _context.PopContext(_bsonStream.Position);
-            switch (_context.ContextType)
-            {
-                case ContextType.Array: State = BsonReaderState.Type; break;
-                case ContextType.Document: State = BsonReaderState.Type; break;
-                case ContextType.TopLevel: State = BsonReaderState.Initial; break;
-                default: throw new BsonInternalException("Unexpected ContextType.");
-            }
-        }
-
-        /// <summary>
-        /// Reads the end of a BSON document from the reader.
-        /// </summary>
-        public override void ReadEndDocument()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (_context.ContextType != ContextType.Document && _context.ContextType != ContextType.ScopeDocument)
-            {
-                ThrowInvalidContextType("ReadEndDocument", _context.ContextType, ContextType.Document, ContextType.ScopeDocument);
-            }
-            if (State == BsonReaderState.Type)
-            {
-                ReadBsonType(); // will set state to EndOfDocument if at end of document
-            }
-            if (State != BsonReaderState.EndOfDocument)
-            {
-                ThrowInvalidState("ReadEndDocument", BsonReaderState.EndOfDocument);
-            }
-
-            _context = _context.PopContext(_bsonStream.Position);
-            if (_context.ContextType == ContextType.JavaScriptWithScope)
-            {
-                _context = _context.PopContext(_bsonStream.Position); // JavaScriptWithScope
-            }
-            switch (_context.ContextType)
-            {
-                case ContextType.Array: State = BsonReaderState.Type; break;
-                case ContextType.Document: State = BsonReaderState.Type; break;
-                case ContextType.TopLevel: State = BsonReaderState.Initial; break;
-                default: throw new BsonInternalException("Unexpected ContextType.");
-            }
-        }
-
-        /// <summary>
-        /// Reads a BSON Int32 from the reader.
-        /// </summary>
-        /// <returns>An Int32.</returns>
-        public override int ReadInt32()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadInt32", BsonType.Int32);
-            State = GetNextState();
-            return _bsonStream.ReadInt32();
-        }
-
-        /// <summary>
-        /// Reads a BSON Int64 from the reader.
-        /// </summary>
-        /// <returns>An Int64.</returns>
-        public override long ReadInt64()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadInt64", BsonType.Int64);
-            State = GetNextState();
-            return _bsonStream.ReadInt64();
-        }
-
-        /// <summary>
-        /// Reads a BSON JavaScript from the reader.
-        /// </summary>
-        /// <returns>A string.</returns>
-        public override string ReadJavaScript()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadJavaScript", BsonType.JavaScript);
-            State = GetNextState();
-            return _bsonStream.ReadString(_settings.Encoding);
-        }
-
-        /// <summary>
-        /// Reads a BSON JavaScript with scope from the reader (call ReadStartDocument next to read the scope).
-        /// </summary>
-        /// <returns>A string.</returns>
-        public override string ReadJavaScriptWithScope()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadJavaScriptWithScope", BsonType.JavaScriptWithScope);
-
-            var startPosition = _bsonStream.Position; // position of size field
-            var size = ReadSize();
-            _context = new BsonBinaryReaderContext(_context, ContextType.JavaScriptWithScope, startPosition, size);
-            var code = _bsonStream.ReadString(_settings.Encoding);
-
-            State = BsonReaderState.ScopeDocument;
-            return code;
-        }
-
-        /// <summary>
-        /// Reads a BSON MaxKey from the reader.
-        /// </summary>
-        public override void ReadMaxKey()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadMaxKey", BsonType.MaxKey);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Reads a BSON MinKey from the reader.
-        /// </summary>
-        public override void ReadMinKey()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadMinKey", BsonType.MinKey);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Reads the name of an element from the reader.
-        /// </summary>
-        /// <param name="nameDecoder">The name decoder.</param>
-        /// <returns>The name of the element.</returns>
-        public override string ReadName(INameDecoder nameDecoder)
-        {
-            if (nameDecoder == null)
-            {
-                throw new ArgumentNullException("nameDecoder");
-            }
-
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (State == BsonReaderState.Type)
-            {
-                ReadBsonType();
-            }
-            if (State != BsonReaderState.Name)
-            {
-                ThrowInvalidState("ReadName", BsonReaderState.Name);
-            }
-
-            CurrentName = nameDecoder.Decode(_bsonStream, _settings.Encoding);
-            State = BsonReaderState.Value;
-
-            if (_context.ContextType == ContextType.Document)
-            {
-                _context.CurrentElementName = CurrentName;
-            }
-
-            return CurrentName;
-        }
-
-        /// <summary>
-        /// Reads a BSON null from the reader.
-        /// </summary>
-        public override void ReadNull()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadNull", BsonType.Null);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Reads a BSON ObjectId from the reader.
-        /// </summary>
-        /// <returns>An ObjectId.</returns>
-        public override ObjectId ReadObjectId()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadObjectId", BsonType.ObjectId);
-            State = GetNextState();
-            return _bsonStream.ReadObjectId();
-        }
-
-        /// <summary>
-        /// Reads a raw BSON array.
-        /// </summary>
-        /// <returns>
-        /// The raw BSON array.
-        /// </returns>
-        public override IByteBuffer ReadRawBsonArray()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadRawBsonArray", BsonType.Array);
-
-            var slice = _bsonStream.ReadSlice();
-
-            switch (_context.ContextType)
-            {
-                case ContextType.Array: State = BsonReaderState.Type; break;
-                case ContextType.Document: State = BsonReaderState.Type; break;
-                case ContextType.TopLevel: State = BsonReaderState.Initial; break;
-                default: throw new BsonInternalException("Unexpected ContextType.");
-            }
-
-            return slice;
-        }
-
-        /// <summary>
-        /// Reads a raw BSON document.
-        /// </summary>
-        /// <returns>
-        /// The raw BSON document.
-        /// </returns>
-        public override IByteBuffer ReadRawBsonDocument()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadRawBsonDocument", BsonType.Document);
-
-            var slice = _bsonStream.ReadSlice();
-
-            if (_context.ContextType == ContextType.JavaScriptWithScope)
-            {
-                _context = _context.PopContext(_bsonStream.Position); // JavaScriptWithScope
-            }
-            switch (_context.ContextType)
-            {
-                case ContextType.Array: State = BsonReaderState.Type; break;
-                case ContextType.Document: State = BsonReaderState.Type; break;
-                case ContextType.TopLevel: State = BsonReaderState.Initial; break;
-                default: throw new BsonInternalException("Unexpected ContextType.");
-            }
-
-            return slice;
-        }
-
-        /// <summary>
-        /// Reads a BSON regular expression from the reader.
-        /// </summary>
-        /// <returns>A BsonRegularExpression.</returns>
-        public override BsonRegularExpression ReadRegularExpression()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadRegularExpression", BsonType.RegularExpression);
-            State = GetNextState();
-            var pattern = _bsonStream.ReadCString(_settings.Encoding);
-            var options = _bsonStream.ReadCString(_settings.Encoding);
-            return new BsonRegularExpression(pattern, options);
-        }
-
-        /// <summary>
-        /// Reads the start of a BSON array.
-        /// </summary>
-        public override void ReadStartArray()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadStartArray", BsonType.Array);
-
-            var startPosition = _bsonStream.Position; // position of size field
-            var size = ReadSize();
-            _context = new BsonBinaryReaderContext(_context, ContextType.Array, startPosition, size);
-            State = BsonReaderState.Type;
-        }
-
-        /// <summary>
-        /// Reads the start of a BSON document.
-        /// </summary>
-        public override void ReadStartDocument()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadStartDocument", BsonType.Document);
-
-            var contextType = (State == BsonReaderState.ScopeDocument) ? ContextType.ScopeDocument : ContextType.Document;
-            var startPosition = _bsonStream.Position; // position of size field
-            var size = ReadSize();
-            _context = new BsonBinaryReaderContext(_context, contextType, startPosition, size);
-            State = BsonReaderState.Type;
-        }
-
-        /// <summary>
-        /// Reads a BSON string from the reader.
-        /// </summary>
-        /// <returns>A String.</returns>
-        public override string ReadString()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadString", BsonType.String);
-            State = GetNextState();
-            return _bsonStream.ReadString(_settings.Encoding);
-        }
-
-        /// <summary>
-        /// Reads a BSON symbol from the reader.
-        /// </summary>
-        /// <returns>A string.</returns>
-        public override string ReadSymbol()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadSymbol", BsonType.Symbol);
-            State = GetNextState();
-            return _bsonStream.ReadString(_settings.Encoding);
-        }
-
-        /// <summary>
-        /// Reads a BSON timestamp from the reader.
-        /// </summary>
-        /// <returns>The combined timestamp/increment.</returns>
-        public override long ReadTimestamp()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadTimestamp", BsonType.Timestamp);
-            State = GetNextState();
-            return _bsonStream.ReadInt64();
-        }
-
-        /// <summary>
-        /// Reads a BSON undefined from the reader.
-        /// </summary>
-        public override void ReadUndefined()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadUndefined", BsonType.Undefined);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Returns the reader to previously bookmarked position and state.
-        /// </summary>
-        /// <param name="bookmark">The bookmark.</param>
-        public override void ReturnToBookmark(BsonReaderBookmark bookmark)
-        {
-            var binaryReaderBookmark = (BsonBinaryReaderBookmark)bookmark;
-            State = binaryReaderBookmark.State;
-            CurrentBsonType = binaryReaderBookmark.CurrentBsonType;
-            CurrentName = binaryReaderBookmark.CurrentName;
-            _context = binaryReaderBookmark.CloneContext();
-            _bsonStream.Position = binaryReaderBookmark.Position;
-        }
-
-        /// <summary>
-        /// Skips the name (reader must be positioned on a name).
-        /// </summary>
-        public override void SkipName()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (State != BsonReaderState.Name)
-            {
-                ThrowInvalidState("SkipName", BsonReaderState.Name);
-            }
-
-            _bsonStream.SkipCString();
-            CurrentName = null;
-            State = BsonReaderState.Value;
-
-            if (_context.ContextType == ContextType.Document)
-            {
-                _context.CurrentElementName = CurrentName;
-            }
-        }
-
-        /// <summary>
-        /// Skips the value (reader must be positioned on a value).
-        /// </summary>
-        public override void SkipValue()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (State != BsonReaderState.Value)
-            {
-                ThrowInvalidState("SkipValue", BsonReaderState.Value);
-            }
-
-            int skip;
-            switch (CurrentBsonType)
-            {
-                case BsonType.Array: skip = ReadSize() - 4; break;
-                case BsonType.Binary: skip = ReadSize() + 1; break;
-                case BsonType.Boolean: skip = 1; break;
-                case BsonType.DateTime: skip = 8; break;
-                case BsonType.Document: skip = ReadSize() - 4; break;
-                case BsonType.Decimal128: skip = 16; break;
-                case BsonType.Double: skip = 8; break;
-                case BsonType.Int32: skip = 4; break;
-                case BsonType.Int64: skip = 8; break;
-                case BsonType.JavaScript: skip = ReadSize(); break;
-                case BsonType.JavaScriptWithScope: skip = ReadSize() - 4; break;
-                case BsonType.MaxKey: skip = 0; break;
-                case BsonType.MinKey: skip = 0; break;
-                case BsonType.Null: skip = 0; break;
-                case BsonType.ObjectId: skip = 12; break;
-                case BsonType.RegularExpression: _bsonStream.SkipCString(); _bsonStream.SkipCString(); skip = 0; break;
-                case BsonType.String: skip = ReadSize(); break;
-                case BsonType.Symbol: skip = ReadSize(); break;
-                case BsonType.Timestamp: skip = 8; break;
-                case BsonType.Undefined: skip = 0; break;
-                default: throw new BsonInternalException("Unexpected BsonType.");
-            }
-            _bsonStream.Seek(skip, SeekOrigin.Current);
-
-            State = BsonReaderState.Type;
-        }
-
-        // protected methods
-        /// <summary>
-        /// Disposes of any resources used by the reader.
-        /// </summary>
-        /// <param name="disposing">True if called from Dispose.</param>
-        protected override void Dispose(bool disposing)
-        {
-            // don't Dispose the _stream because we don't own it
-            if (disposing)
-            {
-                try
-                {
-                    Close();
-                }
-                catch { } // ignore exceptions
-            }
-            base.Dispose(disposing);
-        }
-
-        // private methods
-        private string GenerateDottedElementName()
-        {
-            string elementName;
-            if (_context.ContextType == ContextType.Document)
-            {
-                try
-                {
-                    elementName = _bsonStream.ReadCString(Utf8Encodings.Lenient);
-                }
-                catch
-                {
-                    elementName = "?"; // ignore exception
-                }
-            }
-            else if (_context.ContextType == ContextType.Array)
-            {
-                elementName = _context.CurrentArrayIndex.ToString(NumberFormatInfo.InvariantInfo);
-            }
-            else
-            {
-                elementName = "?";
-            }
-
-            return GenerateDottedElementName(_context.ParentContext, elementName);
-        }
-
-        private string GenerateDottedElementName(BsonBinaryReaderContext context, string elementName)
-        {
-            if (context.ContextType == ContextType.Document)
-            {
-                return GenerateDottedElementName(context.ParentContext, (context.CurrentElementName ?? "?") + "." + elementName);
-            }
-            else if (context.ContextType == ContextType.Array)
-            {
-                var indexElementName = context.CurrentArrayIndex.ToString(NumberFormatInfo.InvariantInfo);
-                return GenerateDottedElementName(context.ParentContext, indexElementName + "." + elementName);
-            }
-            else if (context.ParentContext != null)
-            {
-                return GenerateDottedElementName(context.ParentContext, "?." + elementName);
-            }
-            else
-            {
-                return elementName;
-            }
-        }
-
-        private BsonReaderState GetNextState()
-        {
-            switch (_context.ContextType)
-            {
-                case ContextType.Array:
-                case ContextType.Document:
-                case ContextType.ScopeDocument:
-                    return BsonReaderState.Type;
-                case ContextType.TopLevel:
-                    return BsonReaderState.Initial;
-                default:
-                    throw new BsonInternalException("Unexpected ContextType.");
-            }
-        }
-
-        private int ReadSize()
-        {
-            int size = _bsonStream.ReadInt32();
-            if (size < 0)
-            {
-                var message = string.Format("Size {0} is not valid because it is negative.", size);
-                throw new FormatException(message);
-            }
-            if (size > _settings.MaxDocumentSize)
-            {
-                var message = string.Format("Size {0} is not valid because it is larger than MaxDocumentSize {1}.", size, _settings.MaxDocumentSize);
-                throw new FormatException(message);
-            }
-            return size;
-        }
-    }
-}

+ 0 - 52
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonBinaryReaderBookmark.cs

@@ -1,52 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a bookmark that can be used to return a reader to the current position and state.
-    /// </summary>
-    public class BsonBinaryReaderBookmark : BsonReaderBookmark
-    {
-        // private fields
-        private BsonBinaryReaderContext _context;
-        private long _position;
-
-        // constructors
-        internal BsonBinaryReaderBookmark(
-            BsonReaderState state,
-            BsonType currentBsonType,
-            string currentName,
-            BsonBinaryReaderContext context,
-            long position)
-            : base(state, currentBsonType, currentName)
-        {
-            _context = context.Clone();
-            _position = position;
-        }
-
-        // internal properties
-        internal long Position
-        {
-            get { return _position; }
-        }
-
-        // internal methods
-        internal BsonBinaryReaderContext CloneContext()
-        {
-            return _context.Clone();
-        }
-    }
-}

+ 0 - 87
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonBinaryReaderContext.cs

@@ -1,87 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    internal class BsonBinaryReaderContext
-    {
-        // private fields
-        private readonly BsonBinaryReaderContext _parentContext;
-        private readonly ContextType _contextType;
-        private readonly long _startPosition;
-        private readonly long _size;
-        private string _currentElementName;
-        private int _currentArrayIndex = -1;
-
-        // constructors
-        internal BsonBinaryReaderContext(
-            BsonBinaryReaderContext parentContext,
-            ContextType contextType,
-            long startPosition,
-            long size)
-        {
-            _parentContext = parentContext;
-            _contextType = contextType;
-            _startPosition = startPosition;
-            _size = size;
-        }
-
-        // public properties
-        public ContextType ContextType
-        {
-            get { return _contextType; }
-        }
-
-        public int CurrentArrayIndex
-        {
-            get { return _currentArrayIndex; }
-            set { _currentArrayIndex = value; }
-        }
-
-        public string CurrentElementName
-        {
-            get { return _currentElementName; }
-            set { _currentElementName = value; }
-        }
-
-        public BsonBinaryReaderContext ParentContext
-        {
-            get { return _parentContext; }
-        }
-
-        // public methods
-        /// <summary>
-        /// Creates a clone of the context.
-        /// </summary>
-        /// <returns>A clone of the context.</returns>
-        public BsonBinaryReaderContext Clone()
-        {
-            return new BsonBinaryReaderContext(_parentContext, _contextType, _startPosition, _size);
-        }
-
-        public BsonBinaryReaderContext PopContext(long position)
-        {
-            var actualSize = position - _startPosition;
-            if (actualSize != _size)
-            {
-                var message = string.Format("Expected size to be {0}, not {1}.", _size, actualSize);
-                throw new FormatException(message);
-            }
-            return _parentContext;
-        }
-    }
-}

+ 0 - 148
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonBinaryReaderSettings.cs

@@ -1,148 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Text;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents settings for a BsonBinaryReader.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonBinaryReaderSettings : BsonReaderSettings
-    {
-        // private static fields
-        private static BsonBinaryReaderSettings __defaults = null; // delay creation to pick up the latest default values
-
-        // private fields
-        private UTF8Encoding _encoding = Utf8Encodings.Strict;
-        private bool _fixOldBinarySubTypeOnInput = true;
-        private bool _fixOldDateTimeMaxValueOnInput = true;
-        private int _maxDocumentSize = BsonDefaults.MaxDocumentSize;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonBinaryReaderSettings class.
-        /// </summary>
-        public BsonBinaryReaderSettings()
-        {
-        }
-
-        // public static properties
-        /// <summary>
-        /// Gets or sets the default settings for a BsonBinaryReader.
-        /// </summary>
-        public static BsonBinaryReaderSettings Defaults
-        {
-            get
-            {
-                if (__defaults == null)
-                {
-                    __defaults = new BsonBinaryReaderSettings();
-                }
-                return __defaults;
-            }
-            set { __defaults = value; }
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets or sets the Encoding.
-        /// </summary>
-        public UTF8Encoding Encoding
-        {
-            get { return _encoding; }
-            set
-            {
-                if (value == null)
-                {
-                    throw new ArgumentNullException("value");
-                }
-                if (IsFrozen) { throw new InvalidOperationException("BsonBinaryReaderSettings is frozen."); }
-                _encoding = value;
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets whether to fix occurrences of the old binary subtype on input. 
-        /// </summary>
-        public bool FixOldBinarySubTypeOnInput
-        {
-            get { return _fixOldBinarySubTypeOnInput; }
-            set
-            {
-                if (IsFrozen) { throw new InvalidOperationException("BsonBinaryReaderSettings is frozen."); }
-                _fixOldBinarySubTypeOnInput = value;
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets whether to fix occurrences of the old representation of DateTime.MaxValue on input. 
-        /// </summary>
-        public bool FixOldDateTimeMaxValueOnInput
-        {
-            get { return _fixOldDateTimeMaxValueOnInput; }
-            set
-            {
-                if (IsFrozen) { throw new InvalidOperationException("BsonBinaryReaderSettings is frozen."); }
-                _fixOldDateTimeMaxValueOnInput = value;
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets the max document size.
-        /// </summary>
-        public int MaxDocumentSize
-        {
-            get { return _maxDocumentSize; }
-            set
-            {
-                if (IsFrozen) { throw new InvalidOperationException("BsonBinaryReaderSettings is frozen."); }
-                _maxDocumentSize = value;
-            }
-        }
-
-        // public methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        public new BsonBinaryReaderSettings Clone()
-        {
-            return (BsonBinaryReaderSettings)CloneImplementation();
-        }
-
-        // protected methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        protected override BsonReaderSettings CloneImplementation()
-        {
-            var clone = new BsonBinaryReaderSettings
-            {
-                Encoding = _encoding,
-                FixOldBinarySubTypeOnInput = _fixOldBinarySubTypeOnInput,
-                FixOldDateTimeMaxValueOnInput = _fixOldDateTimeMaxValueOnInput,
-                GuidRepresentation = GuidRepresentation,
-                MaxDocumentSize = _maxDocumentSize
-            };
-            return clone;
-        }
-    }
-}

+ 0 - 775
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonBinaryWriter.cs

@@ -1,775 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a BSON writer to a BSON Stream.
-    /// </summary>
-    public class BsonBinaryWriter : BsonWriter
-    {
-        // private fields
-        private readonly Stream _baseStream;
-        private readonly BsonStream _bsonStream;
-        private BsonBinaryWriterContext _context;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonBinaryWriter class.
-        /// </summary>
-        /// <param name="stream">A stream. The BsonBinaryWriter does not own the stream and will not Dispose it.</param>
-        public BsonBinaryWriter(Stream stream)
-            : this(stream, BsonBinaryWriterSettings.Defaults)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonBinaryWriter class.
-        /// </summary>
-        /// <param name="stream">A stream. The BsonBinaryWriter does not own the stream and will not Dispose it.</param>
-        /// <param name="settings">The BsonBinaryWriter settings.</param>
-        public BsonBinaryWriter(Stream stream, BsonBinaryWriterSettings settings)
-            : base(settings)
-        {
-            if (stream == null)
-            {
-                throw new ArgumentNullException("stream");
-            }
-            if (!stream.CanSeek)
-            {
-                throw new ArgumentException("The stream must be capable of seeking.", "stream");
-            }
-
-            _baseStream = stream;
-            _bsonStream = (stream as BsonStream) ?? new BsonStreamAdapter(stream);
-
-            _context = null;
-            State = BsonWriterState.Initial;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the base stream.
-        /// </summary>
-        /// <value>
-        /// The base stream.
-        /// </value>
-        public Stream BaseStream
-        {
-            get { return _baseStream; }
-        }
-
-        /// <summary>
-        /// Gets the BSON stream.
-        /// </summary>
-        /// <value>
-        /// The BSON stream.
-        /// </value>
-        public BsonStream BsonStream
-        {
-            get { return _bsonStream; }
-        }
-
-        /// <inheritdoc />
-        public override long Position
-        {
-            get { return _baseStream.Position; }
-        }
-
-        /// <summary>
-        /// Gets the settings of the writer.
-        /// </summary>
-        public new BsonBinaryWriterSettings Settings
-        {
-            get {  return (BsonBinaryWriterSettings)base.Settings; }
-        }
-
-        // public methods
-        /// <summary>
-        /// Closes the writer. Also closes the base stream.
-        /// </summary>
-        public override void Close()
-        {
-            // Close can be called on Disposed objects
-            if (State != BsonWriterState.Closed)
-            {
-                if (State == BsonWriterState.Done)
-                {
-                    Flush();
-                }
-                _context = null;
-                State = BsonWriterState.Closed;
-            }
-        }
-
-        /// <summary>
-        /// Flushes any pending data to the output destination.
-        /// </summary>
-        public override void Flush()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State == BsonWriterState.Closed)
-            {
-                throw new InvalidOperationException("Flush called on closed BsonWriter.");
-            }
-            if (State != BsonWriterState.Done)
-            {
-                throw new InvalidOperationException("Flush called before BsonBinaryWriter was finished writing to buffer.");
-            }
-            _bsonStream.Flush();
-        }
-
-        /// <summary>
-        /// Pops the max document size stack, restoring the previous max document size.
-        /// </summary>
-        [Obsolete("Use PopSettings instead.")]
-        public void PopMaxDocumentSize()
-        {
-            PopSettings();
-        }
-
-        /// <summary>
-        /// Pushes a new max document size onto the max document size stack.
-        /// </summary>
-        /// <param name="maxDocumentSize">The maximum size of the document.</param>
-        [Obsolete("Use PushSettings instead.")]
-        public void PushMaxDocumentSize(int maxDocumentSize)
-        {
-            PushSettings(s => ((BsonBinaryWriterSettings)s).MaxDocumentSize = maxDocumentSize);
-        }
-
-#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
-        /// <summary>
-        /// Writes BSON binary data to the writer.
-        /// </summary>
-        /// <param name="binaryData">The binary data.</param>
-        public override void WriteBinaryData(BsonBinaryData binaryData)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteBinaryData", BsonWriterState.Value);
-            }
-
-            var bytes = binaryData.Bytes;
-            var subType = binaryData.SubType;
-            var guidRepresentation = binaryData.GuidRepresentation;
-            switch (subType)
-            {
-                case BsonBinarySubType.OldBinary:
-                    if (Settings.FixOldBinarySubTypeOnOutput)
-                    {
-                        subType = BsonBinarySubType.Binary; // replace obsolete OldBinary with new Binary sub type
-                    }
-                    break;
-                case BsonBinarySubType.UuidLegacy:
-                case BsonBinarySubType.UuidStandard:
-                    if (Settings.GuidRepresentation != GuidRepresentation.Unspecified)
-                    {
-                        var expectedSubType = (Settings.GuidRepresentation == GuidRepresentation.Standard) ? BsonBinarySubType.UuidStandard : BsonBinarySubType.UuidLegacy;
-                        if (subType != expectedSubType)
-                        {
-                            var message = string.Format(
-                                "The GuidRepresentation for the writer is {0}, which requires the subType argument to be {1}, not {2}.",
-                                Settings.GuidRepresentation, expectedSubType, subType);
-                            throw new BsonSerializationException(message);
-                        }
-                        if (guidRepresentation != Settings.GuidRepresentation)
-                        {
-                            var message = string.Format(
-                                "The GuidRepresentation for the writer is {0}, which requires the the guidRepresentation argument to also be {0}, not {1}.",
-                                Settings.GuidRepresentation, guidRepresentation);
-                            throw new BsonSerializationException(message);
-                        }
-                    }
-                    break;
-            }
-
-            _bsonStream.WriteBsonType(BsonType.Binary);
-            WriteNameHelper();
-            if (subType == BsonBinarySubType.OldBinary)
-            {
-                // sub type OldBinary has two sizes (for historical reasons)
-                _bsonStream.WriteInt32(bytes.Length + 4);
-                _bsonStream.WriteBinarySubType(subType);
-                _bsonStream.WriteInt32(bytes.Length);
-            }
-            else
-            {
-                _bsonStream.WriteInt32(bytes.Length);
-                _bsonStream.WriteBinarySubType(subType);
-            }
-            _bsonStream.WriteBytes(bytes, 0, bytes.Length);
-
-            State = GetNextState();
-        }
-#pragma warning restore 618
-
-        /// <summary>
-        /// Writes a BSON Boolean to the writer.
-        /// </summary>
-        /// <param name="value">The Boolean value.</param>
-        public override void WriteBoolean(bool value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteBoolean", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.Boolean);
-            WriteNameHelper();
-            _bsonStream.WriteBoolean(value);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes BSON binary data to the writer.
-        /// </summary>
-        /// <param name="bytes">The bytes.</param>
-        public override void WriteBytes(byte[] bytes)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteBytes", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.Binary);
-            WriteNameHelper();
-            _bsonStream.WriteInt32(bytes.Length);
-            _bsonStream.WriteBinarySubType(BsonBinarySubType.Binary);
-            _bsonStream.WriteBytes(bytes, 0, bytes.Length);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON DateTime to the writer.
-        /// </summary>
-        /// <param name="value">The number of milliseconds since the Unix epoch.</param>
-        public override void WriteDateTime(long value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteDateTime", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.DateTime);
-            WriteNameHelper();
-            _bsonStream.WriteInt64(value);
-
-            State = GetNextState();
-        }
-
-        /// <inheritdoc />
-        public override void WriteDecimal128(Decimal128 value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState(nameof(WriteDecimal128), BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.Decimal128);
-            WriteNameHelper();
-            _bsonStream.WriteDecimal128(value);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON Double to the writer.
-        /// </summary>
-        /// <param name="value">The Double value.</param>
-        public override void WriteDouble(double value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteDouble", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.Double);
-            WriteNameHelper();
-            _bsonStream.WriteDouble(value);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes the end of a BSON array to the writer.
-        /// </summary>
-        public override void WriteEndArray()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteEndArray", BsonWriterState.Value);
-            }
-            if (_context.ContextType != ContextType.Array)
-            {
-                ThrowInvalidContextType("WriteEndArray", _context.ContextType, ContextType.Array);
-            }
-
-            base.WriteEndArray();
-            _bsonStream.WriteByte(0);
-            BackpatchSize(); // size of document
-
-            _context = _context.ParentContext;
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes the end of a BSON document to the writer.
-        /// </summary>
-        public override void WriteEndDocument()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Name)
-            {
-                ThrowInvalidState("WriteEndDocument", BsonWriterState.Name);
-            }
-            if (_context.ContextType != ContextType.Document && _context.ContextType != ContextType.ScopeDocument)
-            {
-                ThrowInvalidContextType("WriteEndDocument", _context.ContextType, ContextType.Document, ContextType.ScopeDocument);
-            }
-
-            base.WriteEndDocument();
-            _bsonStream.WriteByte(0);
-            BackpatchSize(); // size of document
-
-            _context = _context.ParentContext;
-            if (_context == null)
-            {
-                State = BsonWriterState.Done;
-            }
-            else
-            {
-                if (_context.ContextType == ContextType.JavaScriptWithScope)
-                {
-                    BackpatchSize(); // size of the JavaScript with scope value
-                    _context = _context.ParentContext;
-                }
-                State = GetNextState();
-            }
-        }
-
-        /// <summary>
-        /// Writes a BSON Int32 to the writer.
-        /// </summary>
-        /// <param name="value">The Int32 value.</param>
-        public override void WriteInt32(int value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteInt32", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.Int32);
-            WriteNameHelper();
-            _bsonStream.WriteInt32(value);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON Int64 to the writer.
-        /// </summary>
-        /// <param name="value">The Int64 value.</param>
-        public override void WriteInt64(long value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteInt64", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.Int64);
-            WriteNameHelper();
-            _bsonStream.WriteInt64(value);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON JavaScript to the writer.
-        /// </summary>
-        /// <param name="code">The JavaScript code.</param>
-        public override void WriteJavaScript(string code)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteJavaScript", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.JavaScript);
-            WriteNameHelper();
-            _bsonStream.WriteString(code, Settings.Encoding);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON JavaScript to the writer (call WriteStartDocument to start writing the scope).
-        /// </summary>
-        /// <param name="code">The JavaScript code.</param>
-        public override void WriteJavaScriptWithScope(string code)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteJavaScriptWithScope", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.JavaScriptWithScope);
-            WriteNameHelper();
-            _context = new BsonBinaryWriterContext(_context, ContextType.JavaScriptWithScope, _bsonStream.Position);
-            _bsonStream.WriteInt32(0); // reserve space for size of JavaScript with scope value
-            _bsonStream.WriteString(code, Settings.Encoding);
-
-            State = BsonWriterState.ScopeDocument;
-        }
-
-        /// <summary>
-        /// Writes a BSON MaxKey to the writer.
-        /// </summary>
-        public override void WriteMaxKey()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteMaxKey", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.MaxKey);
-            WriteNameHelper();
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON MinKey to the writer.
-        /// </summary>
-        public override void WriteMinKey()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteMinKey", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.MinKey);
-            WriteNameHelper();
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON null to the writer.
-        /// </summary>
-        public override void WriteNull()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteNull", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.Null);
-            WriteNameHelper();
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON ObjectId to the writer.
-        /// </summary>
-        /// <param name="objectId">The ObjectId.</param>
-        public override void WriteObjectId(ObjectId objectId)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteObjectId", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.ObjectId);
-            WriteNameHelper();
-            _bsonStream.WriteObjectId(objectId);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a raw BSON array.
-        /// </summary>
-        /// <param name="slice">The byte buffer containing the raw BSON array.</param>
-        public override void WriteRawBsonArray(IByteBuffer slice)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteRawBsonArray", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.Array);
-            WriteNameHelper();
-            _bsonStream.WriteSlice(slice); // assumes slice is a valid raw BSON array
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a raw BSON document.
-        /// </summary>
-        /// <param name="slice">The byte buffer containing the raw BSON document.</param>
-        public override void WriteRawBsonDocument(IByteBuffer slice)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Initial && State != BsonWriterState.Value && State != BsonWriterState.ScopeDocument && State != BsonWriterState.Done)
-            {
-                ThrowInvalidState("WriteRawBsonDocument", BsonWriterState.Initial, BsonWriterState.Value, BsonWriterState.ScopeDocument, BsonWriterState.Done);
-            }
-
-            if (State == BsonWriterState.Value)
-            {
-                _bsonStream.WriteBsonType(BsonType.Document);
-                WriteNameHelper();
-            }
-            _bsonStream.WriteSlice(slice); // assumes byteBuffer is a valid raw BSON document
-
-            if (_context == null)
-            {
-                State = BsonWriterState.Done;
-            }
-            else
-            {
-                if (_context.ContextType == ContextType.JavaScriptWithScope)
-                {
-                    BackpatchSize(); // size of the JavaScript with scope value
-                    _context = _context.ParentContext;
-                }
-                State = GetNextState();
-            }
-        }
-
-        /// <summary>
-        /// Writes a BSON regular expression to the writer.
-        /// </summary>
-        /// <param name="regex">A BsonRegularExpression.</param>
-        public override void WriteRegularExpression(BsonRegularExpression regex)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteRegularExpression", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.RegularExpression);
-            WriteNameHelper();
-            _bsonStream.WriteCString(regex.Pattern);
-            _bsonStream.WriteCString(regex.Options);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes the start of a BSON array to the writer.
-        /// </summary>
-        public override void WriteStartArray()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteStartArray", BsonWriterState.Value);
-            }
-
-            base.WriteStartArray();
-            _bsonStream.WriteBsonType(BsonType.Array);
-            WriteNameHelper();
-            _context = new BsonBinaryWriterContext(_context, ContextType.Array, _bsonStream.Position);
-            _bsonStream.WriteInt32(0); // reserve space for size
-
-            State = BsonWriterState.Value;
-        }
-
-        /// <summary>
-        /// Writes the start of a BSON document to the writer.
-        /// </summary>
-        public override void WriteStartDocument()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Initial && State != BsonWriterState.Value && State != BsonWriterState.ScopeDocument && State != BsonWriterState.Done)
-            {
-                ThrowInvalidState("WriteStartDocument", BsonWriterState.Initial, BsonWriterState.Value, BsonWriterState.ScopeDocument, BsonWriterState.Done);
-            }
-
-            base.WriteStartDocument();
-            if (State == BsonWriterState.Value)
-            {
-                _bsonStream.WriteBsonType(BsonType.Document);
-                WriteNameHelper();
-            }
-            var contextType = (State == BsonWriterState.ScopeDocument) ? ContextType.ScopeDocument : ContextType.Document;
-            _context = new BsonBinaryWriterContext(_context, contextType, _bsonStream.Position);
-            _bsonStream.WriteInt32(0); // reserve space for size
-
-            State = BsonWriterState.Name;
-        }
-
-        /// <summary>
-        /// Writes a BSON String to the writer.
-        /// </summary>
-        /// <param name="value">The String value.</param>
-        public override void WriteString(string value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteString", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.String);
-            WriteNameHelper();
-            _bsonStream.WriteString(value, Settings.Encoding);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON Symbol to the writer.
-        /// </summary>
-        /// <param name="value">The symbol.</param>
-        public override void WriteSymbol(string value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteSymbol", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.Symbol);
-            WriteNameHelper();
-            _bsonStream.WriteString(value, Settings.Encoding);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON timestamp to the writer.
-        /// </summary>
-        /// <param name="value">The combined timestamp/increment value.</param>
-        public override void WriteTimestamp(long value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteTimestamp", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.Timestamp);
-            WriteNameHelper();
-            _bsonStream.WriteInt64(value);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON undefined to the writer.
-        /// </summary>
-        public override void WriteUndefined()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteUndefined", BsonWriterState.Value);
-            }
-
-            _bsonStream.WriteBsonType(BsonType.Undefined);
-            WriteNameHelper();
-
-            State = GetNextState();
-        }
-
-        // protected methods
-        /// <summary>
-        /// Disposes of any resources used by the writer.
-        /// </summary>
-        /// <param name="disposing">True if called from Dispose.</param>
-        protected override void Dispose(bool disposing)
-        {
-            if (disposing)
-            {
-                try
-                {
-                    Close();
-                }
-                catch { } // ignore exceptions
-            }
-            base.Dispose(disposing);
-        }
-
-        // private methods
-        private void BackpatchSize()
-        {
-            var size = _bsonStream.Position - _context.StartPosition;
-            if (size > Settings.MaxDocumentSize)
-            {
-                var message = string.Format("Size {0} is larger than MaxDocumentSize {1}.", size, Settings.MaxDocumentSize);
-                throw new FormatException(message);
-            }
-
-            var currentPosition = _bsonStream.Position;
-            _bsonStream.Position = _context.StartPosition;
-            _bsonStream.WriteInt32((int)size);
-            _bsonStream.Position = currentPosition;
-        }
-
-        private BsonWriterState GetNextState()
-        {
-            if (_context.ContextType == ContextType.Array)
-            {
-                return BsonWriterState.Value;
-            }
-            else
-            {
-                return BsonWriterState.Name;
-            }
-        }
-
-        private void WriteNameHelper()
-        {
-            if (_context.ContextType == ContextType.Array)
-            {
-                var index = _context.Index++;
-                var nameBytes = ArrayElementNameAccelerator.Default.GetElementNameBytes(index);
-                _bsonStream.WriteCStringBytes(nameBytes);
-            }
-            else
-            {
-                _bsonStream.WriteCString(Name);
-            }
-        }
-    }
-}

+ 0 - 59
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonBinaryWriterContext.cs

@@ -1,59 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace MongoDB.Bson.IO
-{
-    internal class BsonBinaryWriterContext
-    {
-        // private fields
-        private BsonBinaryWriterContext _parentContext;
-        private ContextType _contextType;
-        private long _startPosition;
-        private int _index; // used when contextType is Array
-
-        // constructors
-        internal BsonBinaryWriterContext(
-            BsonBinaryWriterContext parentContext,
-            ContextType contextType,
-            long startPosition)
-        {
-            _parentContext = parentContext;
-            _contextType = contextType;
-            _startPosition = startPosition;
-        }
-
-        // internal properties
-        internal BsonBinaryWriterContext ParentContext
-        {
-            get { return _parentContext; }
-        }
-
-        internal ContextType ContextType
-        {
-            get { return _contextType; }
-        }
-
-        internal long StartPosition
-        {
-            get { return _startPosition; }
-        }
-
-        internal int Index
-        {
-            get { return _index; }
-            set { _index = value; }
-        }
-    }
-}

+ 0 - 134
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonBinaryWriterSettings.cs

@@ -1,134 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Text;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents settings for a BsonBinaryWriter.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonBinaryWriterSettings : BsonWriterSettings
-    {
-        // private static fields
-        private static BsonBinaryWriterSettings __defaults = null; // delay creation to pick up the latest default values
-
-        // private fields
-        private UTF8Encoding _encoding = Utf8Encodings.Strict;
-        private bool _fixOldBinarySubTypeOnOutput = true;
-        private int _maxDocumentSize = BsonDefaults.MaxDocumentSize;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonBinaryWriterSettings class.
-        /// </summary>
-        public BsonBinaryWriterSettings()
-        {
-        }
-
-        // public static properties
-        /// <summary>
-        /// Gets or sets the default BsonBinaryWriter settings.
-        /// </summary>
-        public static BsonBinaryWriterSettings Defaults
-        {
-            get
-            {
-                if (__defaults == null)
-                {
-                    __defaults = new BsonBinaryWriterSettings();
-                }
-                return __defaults;
-            }
-            set { __defaults = value; }
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets or sets the Encoding.
-        /// </summary>
-        public UTF8Encoding Encoding
-        {
-            get { return _encoding; }
-            set
-            {
-                if (value == null)
-                {
-                    throw new ArgumentNullException("value");
-                }
-                if (IsFrozen) { throw new InvalidOperationException("BsonBinaryWriterSettings is frozen."); }
-                _encoding = value;
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets whether to fix the old binary data subtype on output.
-        /// </summary>
-        public bool FixOldBinarySubTypeOnOutput
-        {
-            get { return _fixOldBinarySubTypeOnOutput; }
-            set
-            {
-                if (IsFrozen) { throw new InvalidOperationException("BsonBinaryWriterSettings is frozen."); }
-                _fixOldBinarySubTypeOnOutput = value;
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets the max document size.
-        /// </summary>
-        public int MaxDocumentSize
-        {
-            get { return _maxDocumentSize; }
-            set
-            {
-                if (IsFrozen) { throw new InvalidOperationException("BsonBinaryWriterSettings is frozen."); }
-                _maxDocumentSize = value;
-            }
-        }
-
-        // public methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        public new BsonBinaryWriterSettings Clone()
-        {
-            return (BsonBinaryWriterSettings)CloneImplementation();
-        }
-
-        // protected methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        protected override BsonWriterSettings CloneImplementation()
-        {
-            var clone = new BsonBinaryWriterSettings
-            {
-                Encoding = _encoding,
-                FixOldBinarySubTypeOnOutput = _fixOldBinarySubTypeOnOutput,
-                GuidRepresentation = GuidRepresentation,
-                MaxDocumentSize = _maxDocumentSize,
-                MaxSerializationDepth = MaxSerializationDepth
-            };
-            return clone;
-        }
-    }
-}

+ 0 - 259
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonChunkPool.cs

@@ -1,259 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.Threading;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a pool of chunks.
-    /// </summary>
-    public sealed class BsonChunkPool : IBsonChunkSource
-    {
-        #region static
-        // static fields
-        private static BsonChunkPool __default = new BsonChunkPool(8192, 64 * 1024); // 512MiB of 64KiB chunks
-
-        // static properties
-        /// <summary>
-        /// Gets or sets the default chunk pool.
-        /// </summary>
-        /// <value>
-        /// The default chunk pool.
-        /// </value>
-        public static BsonChunkPool Default
-        {
-            get { return __default; }
-            set
-            {
-                if (value == null)
-                {
-                    throw new ArgumentNullException("value");
-                }
-                __default = value;
-            }
-        }
-        #endregion
-
-        // private fields
-        private Stack<ReferenceCountedChunk> _chunks = new Stack<ReferenceCountedChunk>();
-        private readonly int _chunkSize;
-        private bool _disposed;
-        private readonly object _lock = new object();
-        private readonly int _maxChunkCount;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BsonChunkPool"/> class.
-        /// </summary>
-        /// <param name="maxChunkCount">The maximum number of chunks to keep in the pool.</param>
-        /// <param name="chunkSize">The size of each chunk.</param>
-        public BsonChunkPool(int maxChunkCount, int chunkSize)
-        {
-            if (maxChunkCount < 0)
-            {
-                throw new ArgumentOutOfRangeException("maxChunkCount");
-            }
-            if (chunkSize <= 0)
-            {
-                throw new ArgumentOutOfRangeException("chunkSize");
-            }
-
-            _maxChunkCount = maxChunkCount;
-            _chunkSize = chunkSize;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the chunk size.
-        /// </summary>
-        /// <value>
-        /// The chunk size.
-        /// </value>
-        public int ChunkSize
-        {
-            get { return _chunkSize; }
-        }
-
-        /// <summary>
-        /// Gets the maximum size of the pool.
-        /// </summary>
-        /// <value>
-        /// The maximum size of the pool.
-        /// </value>
-        public int MaxChunkCount
-        {
-            get { return _maxChunkCount; }
-        }
-
-        /// <summary>
-        /// Gets the size of the pool.
-        /// </summary>
-        /// <value>
-        /// The size of the pool.
-        /// </value>
-        public int ChunkCount
-        {
-            get
-            {
-                lock (_lock)
-                {
-                    return _chunks.Count;
-                }
-            }
-        }
-
-        // public methods
-        /// <inheritdoc/>
-        public void Dispose()
-        {
-            if (!_disposed)
-            {
-                _disposed = true;
-                _chunks = null;
-            }
-        }
-
-        /// <inheritdoc/>
-        public IBsonChunk GetChunk(int requestedSize)
-        {
-            ThrowIfDisposed();
-
-            ReferenceCountedChunk referenceCountedChunk = null;
-            lock (_lock)
-            {
-                if (_chunks.Count > 0)
-                {
-                    referenceCountedChunk = _chunks.Pop();
-                }
-            }
-
-            if (referenceCountedChunk == null)
-            {
-                var chunk = new byte[_chunkSize];
-                referenceCountedChunk = new ReferenceCountedChunk(chunk, this);
-            }
-
-            return new DisposableChunk(referenceCountedChunk);
-        }
-
-        // private methods
-        private void ReleaseChunk(ReferenceCountedChunk chunk)
-        {
-            if (!_disposed)
-            {
-                lock (_lock)
-                {
-                    if (_chunks.Count < _maxChunkCount)
-                    {
-                        _chunks.Push(chunk);
-                    }
-                    // otherwise just let it get garbage collected
-                }
-            }
-        }
-
-        private void ThrowIfDisposed()
-        {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException(GetType().Name);
-            }
-        }
-
-        // nested types
-        private sealed class DisposableChunk : IBsonChunk
-        {
-            // fields
-            private bool _disposed;
-            private readonly ReferenceCountedChunk _referenceCountedChunk;
-
-            // constructors
-            public DisposableChunk(ReferenceCountedChunk referenceCountedChunk)
-            {
-                _referenceCountedChunk = referenceCountedChunk;
-                _referenceCountedChunk.IncrementReferenceCount();
-            }
-
-            // properties
-            public ArraySegment<byte> Bytes
-            {
-                get
-                {
-                    ThrowIfDisposed();
-                    return new ArraySegment<byte>(_referenceCountedChunk.Chunk);
-                }
-            }
-
-            // methods
-            public void Dispose()
-            {
-                if (!_disposed)
-                {
-                    _disposed = true;
-                    _referenceCountedChunk.DecrementReferenceCount();
-                }
-            }
-
-            public IBsonChunk Fork()
-            {
-                ThrowIfDisposed();
-                return new DisposableChunk(_referenceCountedChunk);
-            }
-
-            // private methods
-            private void ThrowIfDisposed()
-            {
-                if (_disposed)
-                {
-                    throw new ObjectDisposedException(GetType().Name);
-                }
-            }
-        }
-
-        private sealed class ReferenceCountedChunk
-        {
-            private byte[] _chunk;
-            private BsonChunkPool _pool;
-            private int _referenceCount;
-
-            public ReferenceCountedChunk(byte[] chunk, BsonChunkPool pool)
-            {
-                _chunk = chunk;
-                _pool = pool;
-            }
-
-            public byte[] Chunk
-            {
-                get { return _chunk; }
-            }
-
-            public void DecrementReferenceCount()
-            {
-                if (Interlocked.Decrement(ref _referenceCount) == 0)
-                {
-                    _pool.ReleaseChunk(this);
-                }
-            }
-
-            public void IncrementReferenceCount()
-            {
-                Interlocked.Increment(ref _referenceCount);
-            }
-        }
-    }
-}

+ 0 - 562
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonDocumentReader.cs

@@ -1,562 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a BSON reader for a BsonDocument.
-    /// </summary>
-    public class BsonDocumentReader : BsonReader
-    {
-        // private fields
-        private BsonDocumentReaderContext _context;
-        private BsonValue _currentValue;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonDocumentReader class.
-        /// </summary>
-        /// <param name="document">A BsonDocument.</param>
-        public BsonDocumentReader(BsonDocument document)
-            : this(document, BsonDocumentReaderSettings.Defaults)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocumentReader class.
-        /// </summary>
-        /// <param name="document">A BsonDocument.</param>
-        /// <param name="settings">The reader settings.</param>
-        public BsonDocumentReader(BsonDocument document, BsonDocumentReaderSettings settings)
-            : base(settings)
-        {
-            if (document == null)
-            {
-                throw new ArgumentNullException("document");
-            }
-
-            _context = new BsonDocumentReaderContext(null, ContextType.TopLevel, document);
-            _currentValue = document;
-        }
-
-        // public methods
-        /// <summary>
-        /// Closes the reader.
-        /// </summary>
-        public override void Close()
-        {
-            // Close can be called on Disposed objects
-            State = BsonReaderState.Closed;
-        }
-
-        /// <summary>
-        /// Gets a bookmark to the reader's current position and state.
-        /// </summary>
-        /// <returns>A bookmark.</returns>
-        public override BsonReaderBookmark GetBookmark()
-        {
-            return new BsonDocumentReaderBookmark(State, CurrentBsonType, CurrentName, _context, _currentValue);
-        }
-
-        /// <summary>
-        /// Determines whether this reader is at end of file.
-        /// </summary>
-        /// <returns>
-        /// Whether this reader is at end of file.
-        /// </returns>
-        public override bool IsAtEndOfFile()
-        {
-            return State == BsonReaderState.Done;
-        }
-
-        /// <summary>
-        /// Reads BSON binary data from the reader.
-        /// </summary>
-        /// <returns>A BsonBinaryData.</returns>
-        public override BsonBinaryData ReadBinaryData()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadBinaryData", BsonType.Binary);
-
-            State = GetNextState();
-            return _currentValue.AsBsonBinaryData;
-        }
-
-        /// <summary>
-        /// Reads a BSON boolean from the reader.
-        /// </summary>
-        /// <returns>A Boolean.</returns>
-        public override bool ReadBoolean()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadBoolean", BsonType.Boolean);
-            State = GetNextState();
-            return _currentValue.AsBoolean;
-        }
-
-        /// <summary>
-        /// Reads a BsonType from the reader.
-        /// </summary>
-        /// <returns>A BsonType.</returns>
-        public override BsonType ReadBsonType()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (State == BsonReaderState.Initial || State == BsonReaderState.ScopeDocument)
-            {
-                // there is an implied type of Document for the top level and for scope documents
-                CurrentBsonType = BsonType.Document;
-                State = BsonReaderState.Value;
-                return CurrentBsonType;
-            }
-            if (State != BsonReaderState.Type)
-            {
-                ThrowInvalidState("ReadBsonType", BsonReaderState.Type);
-            }
-
-            switch (_context.ContextType)
-            {
-                case ContextType.Array:
-                    if (!_context.TryGetNextValue(out _currentValue))
-                    {
-                        State = BsonReaderState.EndOfArray;
-                        return BsonType.EndOfDocument;
-                    }
-                    State = BsonReaderState.Value;
-                    break;
-                case ContextType.Document:
-                    BsonElement currentElement;
-                    if (!_context.TryGetNextElement(out currentElement))
-                    {
-                        State = BsonReaderState.EndOfDocument;
-                        return BsonType.EndOfDocument;
-                    }
-                    CurrentName = currentElement.Name;
-                    _currentValue = currentElement.Value;
-                    State = BsonReaderState.Name;
-                    break;
-                default:
-                    throw new BsonInternalException("Invalid ContextType.");
-            }
-
-            CurrentBsonType = _currentValue.BsonType;
-            return CurrentBsonType;
-        }
-
-        /// <summary>
-        /// Reads BSON binary data from the reader.
-        /// </summary>
-        /// <returns>A byte array.</returns>
-#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
-        public override byte[] ReadBytes()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadBytes", BsonType.Binary);
-
-            State = GetNextState();
-            var binaryData = _currentValue.AsBsonBinaryData;
-
-            var subType = binaryData.SubType;
-            if (subType != BsonBinarySubType.Binary && subType != BsonBinarySubType.OldBinary)
-            {
-                var message = string.Format("ReadBytes requires the binary sub type to be Binary, not {0}.", subType);
-                throw new FormatException(message);
-            }
-
-            return binaryData.Bytes;
-        }
-#pragma warning restore 618
-
-        /// <summary>
-        /// Reads a BSON DateTime from the reader.
-        /// </summary>
-        /// <returns>The number of milliseconds since the Unix epoch.</returns>
-        public override long ReadDateTime()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadDateTime", BsonType.DateTime);
-            State = GetNextState();
-            return _currentValue.AsBsonDateTime.MillisecondsSinceEpoch;
-        }
-
-        /// <inheritdoc />
-        public override Decimal128 ReadDecimal128()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType(nameof(ReadDecimal128), BsonType.Decimal128);
-            State = GetNextState();
-            return _currentValue.AsDecimal128;
-        }
-
-        /// <summary>
-        /// Reads a BSON Double from the reader.
-        /// </summary>
-        /// <returns>A Double.</returns>
-        public override double ReadDouble()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadDouble", BsonType.Double);
-            State = GetNextState();
-            return _currentValue.AsDouble;
-        }
-
-        /// <summary>
-        /// Reads the end of a BSON array from the reader.
-        /// </summary>
-        public override void ReadEndArray()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (_context.ContextType != ContextType.Array)
-            {
-                ThrowInvalidContextType("ReadEndArray", _context.ContextType, ContextType.Array);
-            }
-            if (State == BsonReaderState.Type)
-            {
-                ReadBsonType(); // will set state to EndOfArray if at end of array
-            }
-            if (State != BsonReaderState.EndOfArray)
-            {
-                ThrowInvalidState("ReadEndArray", BsonReaderState.EndOfArray);
-            }
-
-            _context = _context.PopContext();
-            switch (_context.ContextType)
-            {
-                case ContextType.Array: State = BsonReaderState.Type; break;
-                case ContextType.Document: State = BsonReaderState.Type; break;
-                case ContextType.TopLevel: State = BsonReaderState.Done; break;
-                default: throw new BsonInternalException("Unexpected ContextType.");
-            }
-        }
-
-        /// <summary>
-        /// Reads the end of a BSON document from the reader.
-        /// </summary>
-        public override void ReadEndDocument()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (_context.ContextType != ContextType.Document && _context.ContextType != ContextType.ScopeDocument)
-            {
-                ThrowInvalidContextType("ReadEndDocument", _context.ContextType, ContextType.Document, ContextType.ScopeDocument);
-            }
-            if (State == BsonReaderState.Type)
-            {
-                ReadBsonType(); // will set state to EndOfDocument if at end of document
-            }
-            if (State != BsonReaderState.EndOfDocument)
-            {
-                ThrowInvalidState("ReadEndDocument", BsonReaderState.EndOfDocument);
-            }
-
-            _context = _context.PopContext();
-            switch (_context.ContextType)
-            {
-                case ContextType.Array: State = BsonReaderState.Type; break;
-                case ContextType.Document: State = BsonReaderState.Type; break;
-                case ContextType.TopLevel: State = BsonReaderState.Done; break;
-                default: throw new BsonInternalException("Unexpected ContextType.");
-            }
-        }
-
-        /// <summary>
-        /// Reads a BSON Int32 from the reader.
-        /// </summary>
-        /// <returns>An Int32.</returns>
-        public override int ReadInt32()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadInt32", BsonType.Int32);
-            State = GetNextState();
-            return _currentValue.AsInt32;
-        }
-
-        /// <summary>
-        /// Reads a BSON Int64 from the reader.
-        /// </summary>
-        /// <returns>An Int64.</returns>
-        public override long ReadInt64()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadInt64", BsonType.Int64);
-            State = GetNextState();
-            return _currentValue.AsInt64;
-        }
-
-        /// <summary>
-        /// Reads a BSON JavaScript from the reader.
-        /// </summary>
-        /// <returns>A string.</returns>
-        public override string ReadJavaScript()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadJavaScript", BsonType.JavaScript);
-            State = GetNextState();
-            return _currentValue.AsBsonJavaScript.Code;
-        }
-
-        /// <summary>
-        /// Reads a BSON JavaScript with scope from the reader (call ReadStartDocument next to read the scope).
-        /// </summary>
-        /// <returns>A string.</returns>
-        public override string ReadJavaScriptWithScope()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadJavaScriptWithScope", BsonType.JavaScriptWithScope);
-
-            State = BsonReaderState.ScopeDocument;
-            return _currentValue.AsBsonJavaScriptWithScope.Code;
-        }
-
-        /// <summary>
-        /// Reads a BSON MaxKey from the reader.
-        /// </summary>
-        public override void ReadMaxKey()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadMaxKey", BsonType.MaxKey);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Reads a BSON MinKey from the reader.
-        /// </summary>
-        public override void ReadMinKey()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadMinKey", BsonType.MinKey);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Reads the name of an element from the reader.
-        /// </summary>
-        /// <param name="nameDecoder">The name decoder.</param>
-        /// <returns>
-        /// The name of the element.
-        /// </returns>
-        public override string ReadName(INameDecoder nameDecoder)
-        {
-            if (nameDecoder == null)
-            {
-                throw new ArgumentNullException("nameDecoder");
-            }
-
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (State == BsonReaderState.Type)
-            {
-                ReadBsonType();
-            }
-            if (State != BsonReaderState.Name)
-            {
-                ThrowInvalidState("ReadName", BsonReaderState.Name);
-            }
-
-            nameDecoder.Inform(CurrentName);
-            State = BsonReaderState.Value;
-            return CurrentName;
-        }
-
-        /// <summary>
-        /// Reads a BSON null from the reader.
-        /// </summary>
-        public override void ReadNull()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadNull", BsonType.Null);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Reads a BSON ObjectId from the reader.
-        /// </summary>
-        /// <returns>An ObjectId.</returns>
-        public override ObjectId ReadObjectId()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadObjectId", BsonType.ObjectId);
-            State = GetNextState();
-            return _currentValue.AsObjectId;
-        }
-
-        /// <summary>
-        /// Reads a BSON regular expression from the reader.
-        /// </summary>
-        /// <returns>A BsonRegularExpression.</returns>
-        public override BsonRegularExpression ReadRegularExpression()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadRegularExpression", BsonType.RegularExpression);
-            State = GetNextState();
-            return _currentValue.AsBsonRegularExpression;
-        }
-
-        /// <summary>
-        /// Reads the start of a BSON array.
-        /// </summary>
-        public override void ReadStartArray()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadStartArray", BsonType.Array);
-
-            var array = _currentValue.AsBsonArray;
-            _context = new BsonDocumentReaderContext(_context, ContextType.Array, array);
-            State = BsonReaderState.Type;
-        }
-
-        /// <summary>
-        /// Reads the start of a BSON document.
-        /// </summary>
-        public override void ReadStartDocument()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadStartDocument", BsonType.Document);
-
-            BsonDocument document;
-            var script = _currentValue as BsonJavaScriptWithScope;
-            if (script != null)
-            {
-                document = script.Scope;
-            }
-            else
-            {
-                document = _currentValue.AsBsonDocument;
-            }
-            _context = new BsonDocumentReaderContext(_context, ContextType.Document, document);
-            State = BsonReaderState.Type;
-        }
-
-        /// <summary>
-        /// Reads a BSON string from the reader.
-        /// </summary>
-        /// <returns>A String.</returns>
-        public override string ReadString()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadString", BsonType.String);
-            State = GetNextState();
-            return _currentValue.AsString;
-        }
-
-        /// <summary>
-        /// Reads a BSON symbol from the reader.
-        /// </summary>
-        /// <returns>A string.</returns>
-        public override string ReadSymbol()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadSymbol", BsonType.Symbol);
-            State = GetNextState();
-            return _currentValue.AsBsonSymbol.Name;
-        }
-
-        /// <summary>
-        /// Reads a BSON timestamp from the reader.
-        /// </summary>
-        /// <returns>The combined timestamp/increment.</returns>
-        public override long ReadTimestamp()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadTimestamp", BsonType.Timestamp);
-            State = GetNextState();
-            return _currentValue.AsBsonTimestamp.Value;
-        }
-
-        /// <summary>
-        /// Reads a BSON undefined from the reader.
-        /// </summary>
-        public override void ReadUndefined()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadUndefined", BsonType.Undefined);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Returns the reader to previously bookmarked position and state.
-        /// </summary>
-        /// <param name="bookmark">The bookmark.</param>
-        public override void ReturnToBookmark(BsonReaderBookmark bookmark)
-        {
-            var documentReaderBookmark = (BsonDocumentReaderBookmark)bookmark;
-            State = documentReaderBookmark.State;
-            CurrentBsonType = documentReaderBookmark.CurrentBsonType;
-            CurrentName = documentReaderBookmark.CurrentName;
-            _context = documentReaderBookmark.CloneContext();
-            _currentValue = documentReaderBookmark.CurrentValue;
-        }
-
-        /// <summary>
-        /// Skips the name (reader must be positioned on a name).
-        /// </summary>
-        public override void SkipName()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (State != BsonReaderState.Name)
-            {
-                ThrowInvalidState("SkipName", BsonReaderState.Name);
-            }
-
-            State = BsonReaderState.Value;
-        }
-
-        /// <summary>
-        /// Skips the value (reader must be positioned on a value).
-        /// </summary>
-        public override void SkipValue()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (State != BsonReaderState.Value)
-            {
-                ThrowInvalidState("SkipValue", BsonReaderState.Value);
-            }
-            State = BsonReaderState.Type;
-        }
-
-        // protected methods
-        /// <summary>
-        /// Disposes of any resources used by the reader.
-        /// </summary>
-        /// <param name="disposing">True if called from Dispose.</param>
-        protected override void Dispose(bool disposing)
-        {
-            if (disposing)
-            {
-                try
-                {
-                    Close();
-                }
-                catch { } // ignore exceptions
-            }
-            base.Dispose(disposing);
-        }
-
-        // private methods
-        private BsonReaderState GetNextState()
-        {
-            switch (_context.ContextType)
-            {
-                case ContextType.Array:
-                case ContextType.Document:
-                    return BsonReaderState.Type;
-                case ContextType.TopLevel:
-                    return BsonReaderState.Done;
-                default:
-                    throw new BsonInternalException("Unexpected ContextType.");
-            }
-        }
-    }
-}

+ 0 - 52
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonDocumentReaderBookmark.cs

@@ -1,52 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a bookmark that can be used to return a reader to the current position and state.
-    /// </summary>
-    public class BsonDocumentReaderBookmark : BsonReaderBookmark
-    {
-        // private fields
-        private BsonDocumentReaderContext _context;
-        private BsonValue _currentValue;
-
-        // constructors
-        internal BsonDocumentReaderBookmark(
-            BsonReaderState state,
-            BsonType currentBsonType,
-            string currentName,
-            BsonDocumentReaderContext context,
-            BsonValue currentValue)
-            : base(state, currentBsonType, currentName)
-        {
-            _context = context.Clone();
-            _currentValue = currentValue;
-        }
-
-        // internal properties
-        internal BsonValue CurrentValue
-        {
-            get { return _currentValue; }
-        }
-
-        // internal methods
-        internal BsonDocumentReaderContext CloneContext()
-        {
-            return _context.Clone();
-        }
-    }
-}

+ 0 - 128
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonDocumentReaderContext.cs

@@ -1,128 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace MongoDB.Bson.IO
-{
-    internal class BsonDocumentReaderContext
-    {
-        // private fields
-        private BsonDocumentReaderContext _parentContext;
-        private ContextType _contextType;
-        private BsonDocument _document;
-        private BsonArray _array;
-        private int _index;
-
-        // constructors
-        internal BsonDocumentReaderContext(
-            BsonDocumentReaderContext parentContext,
-            ContextType contextType,
-            BsonArray array)
-        {
-            _parentContext = parentContext;
-            _contextType = contextType;
-            _array = array;
-        }
-
-        internal BsonDocumentReaderContext(
-            BsonDocumentReaderContext parentContext,
-            ContextType contextType,
-            BsonDocument document)
-        {
-            _parentContext = parentContext;
-            _contextType = contextType;
-            _document = document;
-        }
-
-        // used by Clone
-        private BsonDocumentReaderContext(
-            BsonDocumentReaderContext parentContext,
-            ContextType contextType,
-            BsonDocument document,
-            BsonArray array,
-            int index)
-        {
-            _parentContext = parentContext;
-            _contextType = contextType;
-            _document = document;
-            _array = array;
-            _index = index;
-        }
-
-        // internal properties
-        internal BsonArray Array
-        {
-            get { return _array; }
-        }
-
-        internal ContextType ContextType
-        {
-            get { return _contextType; }
-        }
-
-        internal BsonDocument Document
-        {
-            get { return _document; }
-        }
-
-        internal int Index
-        {
-            get { return _index; }
-            set { _index = value; }
-        }
-
-        // public methods
-        /// <summary>
-        /// Creates a clone of the context.
-        /// </summary>
-        /// <returns>A clone of the context.</returns>
-        public BsonDocumentReaderContext Clone()
-        {
-            return new BsonDocumentReaderContext(_parentContext, _contextType, _document, _array, _index);
-        }
-
-        public bool TryGetNextElement(out BsonElement element)
-        {
-            if (_index < _document.ElementCount)
-            {
-                element = _document.GetElement(_index++);
-                return true;
-            }
-            else
-            {
-                element = default(BsonElement);
-                return false;
-            }
-        }
-
-        public bool TryGetNextValue(out BsonValue value)
-        {
-            if (_index < _array.Count)
-            {
-                value = _array[_index++];
-                return true;
-            }
-            else
-            {
-                value = null;
-                return false;
-            }
-        }
-
-        public BsonDocumentReaderContext PopContext()
-        {
-            return _parentContext;
-        }
-    }
-}

+ 0 - 90
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonDocumentReaderSettings.cs

@@ -1,90 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents settings for a BsonDocumentReader.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonDocumentReaderSettings : BsonReaderSettings
-    {
-        // private static fields
-        private static BsonDocumentReaderSettings __defaults = null; // delay creation to pick up the latest default values
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonDocumentReaderSettings class.
-        /// </summary>
-        public BsonDocumentReaderSettings()
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocumentReaderSettings class.
-        /// </summary>
-        /// <param name="guidRepresentation">The representation for Guids.</param>
-        [Obsolete("Use the no-argument constructor instead and set the properties.")]
-        public BsonDocumentReaderSettings(GuidRepresentation guidRepresentation)
-            : base(guidRepresentation)
-        {
-        }
-
-        // public static properties
-        /// <summary>
-        /// Gets or sets the default settings for a BsonDocumentReader.
-        /// </summary>
-        public static BsonDocumentReaderSettings Defaults
-        {
-            get
-            {
-                if (__defaults == null)
-                {
-                    __defaults = new BsonDocumentReaderSettings();
-                }
-                return __defaults;
-            }
-            set { __defaults = value; }
-        }
-
-        // public methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        public new BsonDocumentReaderSettings Clone()
-        {
-            return (BsonDocumentReaderSettings)CloneImplementation();
-        }
-
-        // protected methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        protected override BsonReaderSettings CloneImplementation()
-        {
-            var clone = new BsonDocumentReaderSettings
-            {
-                GuidRepresentation = GuidRepresentation
-            };
-            return clone;
-        }
-    }
-}

+ 0 - 551
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonDocumentWriter.cs

@@ -1,551 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a BSON writer to a BsonDocument.
-    /// </summary>
-    public class BsonDocumentWriter : BsonWriter
-    {
-        // private fields
-        private BsonDocument _document;
-        private BsonDocumentWriterContext _context;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonDocumentWriter class.
-        /// </summary>
-        /// <param name="document">The document to write to (normally starts out as an empty document).</param>
-        public BsonDocumentWriter(BsonDocument document)
-            : this(document, BsonDocumentWriterSettings.Defaults)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocumentWriter class.
-        /// </summary>
-        /// <param name="document">The document to write to (normally starts out as an empty document).</param>
-        /// <param name="settings">The settings.</param>
-        public BsonDocumentWriter(BsonDocument document, BsonDocumentWriterSettings settings)
-            : base(settings)
-        {
-            if (document == null)
-            {
-                throw new ArgumentNullException("document");
-            }
-
-            _document = document;
-            _context = null;
-            State = BsonWriterState.Initial;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the BsonDocument being written to.
-        /// </summary>
-        public BsonDocument Document
-        {
-            get { return _document; }
-        }
-
-        /// <inheritdoc />
-        public override long Position => 0L;
-
-        // public methods
-        /// <summary>
-        /// Closes the writer.
-        /// </summary>
-        public override void Close()
-        {
-            // Close can be called on Disposed objects
-            _context = null;
-            State = BsonWriterState.Closed;
-        }
-
-        /// <summary>
-        /// Flushes any pending data to the output destination.
-        /// </summary>
-        public override void Flush()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-        }
-
-        /// <summary>
-        /// Writes BSON binary data to the writer.
-        /// </summary>
-        /// <param name="binaryData">The binary data.</param>
-        public override void WriteBinaryData(BsonBinaryData binaryData)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteBinaryData", BsonWriterState.Value);
-            }
-
-            WriteValue(binaryData);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON Boolean to the writer.
-        /// </summary>
-        /// <param name="value">The Boolean value.</param>
-        public override void WriteBoolean(bool value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteBoolean", BsonWriterState.Value);
-            }
-
-            WriteValue(value);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes BSON binary data to the writer.
-        /// </summary>
-        /// <param name="bytes">The bytes.</param>
-        public override void WriteBytes(byte[] bytes)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteBytes", BsonWriterState.Value);
-            }
-
-            WriteValue(new BsonBinaryData(bytes, BsonBinarySubType.Binary));
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON DateTime to the writer.
-        /// </summary>
-        /// <param name="value">The number of milliseconds since the Unix epoch.</param>
-        public override void WriteDateTime(long value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteDateTime", BsonWriterState.Value);
-            }
-
-            WriteValue(new BsonDateTime(value));
-            State = GetNextState();
-        }
-
-        /// <inheritdoc />
-        public override void WriteDecimal128(Decimal128 value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState(nameof(WriteDecimal128), BsonWriterState.Value);
-            }
-
-            WriteValue(new BsonDecimal128(value));
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON Double to the writer.
-        /// </summary>
-        /// <param name="value">The Double value.</param>
-        public override void WriteDouble(double value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteDouble", BsonWriterState.Value);
-            }
-
-            WriteValue(value);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes the end of a BSON array to the writer.
-        /// </summary>
-        public override void WriteEndArray()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteEndArray", BsonWriterState.Value);
-            }
-            if (_context.ContextType != ContextType.Array)
-            {
-                ThrowInvalidContextType("WriteEndArray", _context.ContextType, ContextType.Array);
-            }
-
-            base.WriteEndArray();
-            var array = _context.Array;
-            _context = _context.ParentContext;
-            WriteValue(array);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes the end of a BSON document to the writer.
-        /// </summary>
-        public override void WriteEndDocument()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Name)
-            {
-                ThrowInvalidState("WriteEndDocument", BsonWriterState.Name);
-            }
-            if (_context.ContextType != ContextType.Document && _context.ContextType != ContextType.ScopeDocument)
-            {
-                ThrowInvalidContextType("WriteEndDocument", _context.ContextType, ContextType.Document, ContextType.ScopeDocument);
-            }
-
-            base.WriteEndDocument();
-            if (_context.ContextType == ContextType.ScopeDocument)
-            {
-                var scope = _context.Document;
-                _context = _context.ParentContext;
-                var code = _context.Code;
-                _context = _context.ParentContext;
-                WriteValue(new BsonJavaScriptWithScope(code, scope));
-            }
-            else
-            {
-                var document = _context.Document;
-                _context = _context.ParentContext;
-                if (_context != null)
-                {
-                    WriteValue(document);
-                }
-            }
-
-            if (_context == null)
-            {
-                State = BsonWriterState.Done;
-            }
-            else
-            {
-                State = GetNextState();
-            }
-        }
-
-        /// <summary>
-        /// Writes a BSON Int32 to the writer.
-        /// </summary>
-        /// <param name="value">The Int32 value.</param>
-        public override void WriteInt32(int value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteInt32", BsonWriterState.Value);
-            }
-
-            WriteValue(value);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON Int64 to the writer.
-        /// </summary>
-        /// <param name="value">The Int64 value.</param>
-        public override void WriteInt64(long value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteInt64", BsonWriterState.Value);
-            }
-
-            WriteValue(value);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON JavaScript to the writer.
-        /// </summary>
-        /// <param name="code">The JavaScript code.</param>
-        public override void WriteJavaScript(string code)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteJavaScript", BsonWriterState.Value);
-            }
-
-            WriteValue(new BsonJavaScript(code));
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON JavaScript to the writer (call WriteStartDocument to start writing the scope).
-        /// </summary>
-        /// <param name="code">The JavaScript code.</param>
-        public override void WriteJavaScriptWithScope(string code)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteJavaScriptWithScope", BsonWriterState.Value);
-            }
-
-            _context = new BsonDocumentWriterContext(_context, ContextType.JavaScriptWithScope, code);
-            State = BsonWriterState.ScopeDocument;
-        }
-
-        /// <summary>
-        /// Writes a BSON MaxKey to the writer.
-        /// </summary>
-        public override void WriteMaxKey()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteMaxKey", BsonWriterState.Value);
-            }
-
-            WriteValue(BsonMaxKey.Value);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON MinKey to the writer.
-        /// </summary>
-        public override void WriteMinKey()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteMinKey", BsonWriterState.Value);
-            }
-
-            WriteValue(BsonMinKey.Value);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes the name of an element to the writer.
-        /// </summary>
-        /// <param name="name">The name of the element.</param>
-        public override void WriteName(string name)
-        {
-            base.WriteName(name);
-            _context.Name = name;
-        }
-
-        /// <summary>
-        /// Writes a BSON null to the writer.
-        /// </summary>
-        public override void WriteNull()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteNull", BsonWriterState.Value);
-            }
-
-            WriteValue(BsonNull.Value);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON ObjectId to the writer.
-        /// </summary>
-        /// <param name="objectId">The ObjectId.</param>
-        public override void WriteObjectId(ObjectId objectId)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteObjectId", BsonWriterState.Value);
-            }
-
-            WriteValue(objectId);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON regular expression to the writer.
-        /// </summary>
-        /// <param name="regex">A BsonRegularExpression.</param>
-        public override void WriteRegularExpression(BsonRegularExpression regex)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteRegularExpression", BsonWriterState.Value);
-            }
-
-            WriteValue(regex);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes the start of a BSON array to the writer.
-        /// </summary>
-        public override void WriteStartArray()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteStartArray", BsonWriterState.Value);
-            }
-
-            base.WriteStartArray();
-            _context = new BsonDocumentWriterContext(_context, ContextType.Array, new BsonArray());
-            State = BsonWriterState.Value;
-        }
-
-        /// <summary>
-        /// Writes the start of a BSON document to the writer.
-        /// </summary>
-        public override void WriteStartDocument()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Initial && State != BsonWriterState.Value && State != BsonWriterState.ScopeDocument && State != BsonWriterState.Done)
-            {
-                ThrowInvalidState("WriteStartDocument", BsonWriterState.Initial, BsonWriterState.Value, BsonWriterState.ScopeDocument, BsonWriterState.Done);
-            }
-
-            base.WriteStartDocument();
-            switch (State)
-            {
-                case BsonWriterState.Initial:
-                case BsonWriterState.Done:
-                    _context = new BsonDocumentWriterContext(null, ContextType.Document, _document);
-                    break;
-                case BsonWriterState.Value:
-                    _context = new BsonDocumentWriterContext(_context, ContextType.Document, new BsonDocument());
-                    break;
-                case BsonWriterState.ScopeDocument:
-                    _context = new BsonDocumentWriterContext(_context, ContextType.ScopeDocument, new BsonDocument());
-                    break;
-                default:
-                    throw new BsonInternalException("Unexpected state.");
-            }
-
-            State = BsonWriterState.Name;
-        }
-
-        /// <summary>
-        /// Writes a BSON String to the writer.
-        /// </summary>
-        /// <param name="value">The String value.</param>
-        public override void WriteString(string value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteString", BsonWriterState.Value);
-            }
-
-            WriteValue(value);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON Symbol to the writer.
-        /// </summary>
-        /// <param name="value">The symbol.</param>
-        public override void WriteSymbol(string value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteSymbol", BsonWriterState.Value);
-            }
-
-            WriteValue(BsonSymbolTable.Lookup(value));
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON timestamp to the writer.
-        /// </summary>
-        /// <param name="value">The combined timestamp/increment value.</param>
-        public override void WriteTimestamp(long value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteTimestamp", BsonWriterState.Value);
-            }
-
-            WriteValue(new BsonTimestamp(value));
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON undefined to the writer.
-        /// </summary>
-        public override void WriteUndefined()
-        {
-            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteUndefined", BsonWriterState.Value);
-            }
-
-            WriteValue(BsonUndefined.Value);
-            State = GetNextState();
-        }
-
-        // protected methods
-        /// <summary>
-        /// Disposes of any resources used by the writer.
-        /// </summary>
-        /// <param name="disposing">True if called from Dispose.</param>
-        protected override void Dispose(bool disposing)
-        {
-            if (disposing)
-            {
-                try
-                {
-                    Close();
-                }
-                catch { } // ignore exceptions
-            }
-            base.Dispose(disposing);
-        }
-
-        // private methods
-        private BsonWriterState GetNextState()
-        {
-            if (_context.ContextType == ContextType.Array)
-            {
-                return BsonWriterState.Value;
-            }
-            else
-            {
-                return BsonWriterState.Name;
-            }
-        }
-
-        private void WriteValue(BsonValue value)
-        {
-            if (_context.ContextType == ContextType.Array)
-            {
-                _context.Array.Add(value);
-            }
-            else
-            {
-                _context.Document.Add(_context.Name, value);
-            }
-        }
-    }
-}

+ 0 - 91
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonDocumentWriterContext.cs

@@ -1,91 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace MongoDB.Bson.IO
-{
-    internal class BsonDocumentWriterContext
-    {
-        // private fields
-        private BsonDocumentWriterContext _parentContext;
-        private ContextType _contextType;
-        private BsonDocument _document;
-        private BsonArray _array;
-        private string _code;
-        private string _name;
-
-        // constructors
-        internal BsonDocumentWriterContext(
-            BsonDocumentWriterContext parentContext,
-            ContextType contextType,
-            BsonDocument document)
-        {
-            _parentContext = parentContext;
-            _contextType = contextType;
-            _document = document;
-        }
-
-        internal BsonDocumentWriterContext(
-            BsonDocumentWriterContext parentContext,
-            ContextType contextType,
-            BsonArray array)
-        {
-            _parentContext = parentContext;
-            _contextType = contextType;
-            _array = array;
-        }
-
-        internal BsonDocumentWriterContext(
-            BsonDocumentWriterContext parentContext,
-            ContextType contextType,
-            string code)
-        {
-            _parentContext = parentContext;
-            _contextType = contextType;
-            _code = code;
-        }
-
-        // internal properties
-        internal BsonDocumentWriterContext ParentContext
-        {
-            get { return _parentContext; }
-        }
-
-        internal string Name
-        {
-            get { return _name; }
-            set { _name = value; }
-        }
-
-        internal ContextType ContextType
-        {
-            get { return _contextType; }
-        }
-
-        internal BsonDocument Document
-        {
-            get { return _document; }
-        }
-
-        internal BsonArray Array
-        {
-            get { return _array; }
-        }
-
-        internal string Code
-        {
-            get { return _code; }
-        }
-    }
-}

+ 0 - 91
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonDocumentWriterSettings.cs

@@ -1,91 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents settings for a BsonDocumentWriter.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonDocumentWriterSettings : BsonWriterSettings
-    {
-        // private static fields
-        private static BsonDocumentWriterSettings __defaults = null; // delay creation to pick up the latest default values
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonDocumentWriterSettings class.
-        /// </summary>
-        public BsonDocumentWriterSettings()
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocumentWriterSettings class.
-        /// </summary>
-        /// <param name="guidRepresentation">The representation for Guids.</param>
-        [Obsolete("Use the no-argument constructor instead and set the properties.")]
-        public BsonDocumentWriterSettings(GuidRepresentation guidRepresentation)
-            : base(guidRepresentation)
-        {
-        }
-
-        // public static properties
-        /// <summary>
-        /// Gets or sets the default BsonDocumentWriter settings.
-        /// </summary>
-        public static BsonDocumentWriterSettings Defaults
-        {
-            get
-            {
-                if (__defaults == null)
-                {
-                    __defaults = new BsonDocumentWriterSettings();
-                }
-                return __defaults;
-            }
-            set { __defaults = value; }
-        }
-
-        // public methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        public new BsonDocumentWriterSettings Clone()
-        {
-            return (BsonDocumentWriterSettings)CloneImplementation();
-        }
-
-        // protected methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        protected override BsonWriterSettings CloneImplementation()
-        {
-            var clone = new BsonDocumentWriterSettings
-            {
-                GuidRepresentation = GuidRepresentation,
-                MaxSerializationDepth = MaxSerializationDepth
-            };
-            return clone;
-        }
-    }
-}

+ 0 - 440
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonReader.cs

@@ -1,440 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-using System.Linq;
-using MongoDB.Bson.Serialization;
-using MongoDB.Bson.Serialization.Serializers;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a BSON reader for some external format (see subclasses).
-    /// </summary>
-    public abstract class BsonReader : IBsonReader
-    {
-        // private fields
-        private bool _disposed = false;
-        private BsonReaderSettings _settings;
-        private BsonReaderState _state;
-        private BsonType _currentBsonType;
-        private string _currentName;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonReader class.
-        /// </summary>
-        /// <param name="settings">The reader settings.</param>
-        protected BsonReader(BsonReaderSettings settings)
-        {
-            if (settings == null)
-            {
-                throw new ArgumentNullException("settings");
-            }
-
-            _settings = settings.FrozenCopy();
-            _state = BsonReaderState.Initial;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the current BsonType.
-        /// </summary>
-        public BsonType CurrentBsonType
-        {
-            get { return _currentBsonType; }
-            protected set { _currentBsonType = value; }
-        }
-
-        /// <summary>
-        /// Gets the settings of the reader.
-        /// </summary>
-        public BsonReaderSettings Settings
-        {
-            get { return _settings; }
-        }
-
-        /// <summary>
-        /// Gets the current state of the reader.
-        /// </summary>
-        public BsonReaderState State
-        {
-            get { return _state; }
-            protected set { _state = value; }
-        }
-
-        // protected properties
-        /// <summary>
-        /// Gets the current name.
-        /// </summary>
-        protected string CurrentName
-        {
-            get { return _currentName; }
-            set { _currentName = value; }
-        }
-
-        /// <summary>
-        /// Gets whether the BsonReader has been disposed.
-        /// </summary>
-        protected bool Disposed
-        {
-            get { return _disposed; }
-        }
-
-        // public methods
-        /// <summary>
-        /// Closes the reader.
-        /// </summary>
-        public abstract void Close();
-
-        /// <summary>
-        /// Disposes of any resources used by the reader.
-        /// </summary>
-        public void Dispose()
-        {
-            if (!_disposed)
-            {
-                Dispose(true);
-                _disposed = true;
-            }
-        }
-
-        /// <summary>
-        /// Gets a bookmark to the reader's current position and state.
-        /// </summary>
-        /// <returns>A bookmark.</returns>
-        public abstract BsonReaderBookmark GetBookmark();
-
-        /// <summary>
-        /// Gets the current BsonType (calls ReadBsonType if necessary).
-        /// </summary>
-        /// <returns>The current BsonType.</returns>
-        public BsonType GetCurrentBsonType()
-        {
-            if (_state == BsonReaderState.Initial || _state == BsonReaderState.ScopeDocument || _state == BsonReaderState.Type)
-            {
-                ReadBsonType();
-            }
-            if (_state != BsonReaderState.Value)
-            {
-                ThrowInvalidState("GetCurrentBsonType", BsonReaderState.Value);
-            }
-            return _currentBsonType;
-        }
-
-        /// <summary>
-        /// Determines whether this reader is at end of file.
-        /// </summary>
-        /// <returns>
-        /// Whether this reader is at end of file.
-        /// </returns>
-        public abstract bool IsAtEndOfFile();
-
-        /// <summary>
-        /// Reads BSON binary data from the reader.
-        /// </summary>
-        /// <returns>A BsonBinaryData.</returns>
-        public abstract BsonBinaryData ReadBinaryData();
-
-        /// <summary>
-        /// Reads a BSON boolean from the reader.
-        /// </summary>
-        /// <returns>A Boolean.</returns>
-        public abstract bool ReadBoolean();
-
-        /// <summary>
-        /// Reads a BsonType from the reader.
-        /// </summary>
-        /// <returns>A BsonType.</returns>
-        public abstract BsonType ReadBsonType();
-
-        /// <summary>
-        /// Reads BSON binary data from the reader.
-        /// </summary>
-        /// <returns>A byte array.</returns>
-        public abstract byte[] ReadBytes();
-
-        /// <summary>
-        /// Reads a BSON DateTime from the reader.
-        /// </summary>
-        /// <returns>The number of milliseconds since the Unix epoch.</returns>
-        public abstract long ReadDateTime();
-
-        /// <inheritdoc />
-        public abstract Decimal128 ReadDecimal128();
-
-        /// <summary>
-        /// Reads a BSON Double from the reader.
-        /// </summary>
-        /// <returns>A Double.</returns>
-        public abstract double ReadDouble();
-
-        /// <summary>
-        /// Reads the end of a BSON array from the reader.
-        /// </summary>
-        public abstract void ReadEndArray();
-
-        /// <summary>
-        /// Reads the end of a BSON document from the reader.
-        /// </summary>
-        public abstract void ReadEndDocument();
-
-        /// <summary>
-        /// Reads a BSON Int32 from the reader.
-        /// </summary>
-        /// <returns>An Int32.</returns>
-        public abstract int ReadInt32();
-
-        /// <summary>
-        /// Reads a BSON Int64 from the reader.
-        /// </summary>
-        /// <returns>An Int64.</returns>
-        public abstract long ReadInt64();
-
-        /// <summary>
-        /// Reads a BSON JavaScript from the reader.
-        /// </summary>
-        /// <returns>A string.</returns>
-        public abstract string ReadJavaScript();
-
-        /// <summary>
-        /// Reads a BSON JavaScript with scope from the reader (call ReadStartDocument next to read the scope).
-        /// </summary>
-        /// <returns>A string.</returns>
-        public abstract string ReadJavaScriptWithScope();
-
-        /// <summary>
-        /// Reads a BSON MaxKey from the reader.
-        /// </summary>
-        public abstract void ReadMaxKey();
-
-        /// <summary>
-        /// Reads a BSON MinKey from the reader.
-        /// </summary>
-        public abstract void ReadMinKey();
-
-        /// <summary>
-        /// Reads the name of an element from the reader.
-        /// </summary>
-        /// <returns>The name of the element.</returns>
-        public virtual string ReadName()
-        {
-            return ReadName(Utf8NameDecoder.Instance);
-        }
-
-        /// <summary>
-        /// Reads the name of an element from the reader (using the provided name decoder).
-        /// </summary>
-        /// <param name="nameDecoder">The name decoder.</param>
-        /// <returns>
-        /// The name of the element.
-        /// </returns>
-        public abstract string ReadName(INameDecoder nameDecoder);
-
-        /// <summary>
-        /// Reads a BSON null from the reader.
-        /// </summary>
-        public abstract void ReadNull();
-
-        /// <summary>
-        /// Reads a BSON ObjectId from the reader.
-        /// </summary>
-        /// <returns>An ObjectId.</returns>
-        public abstract ObjectId ReadObjectId();
-
-        /// <summary>
-        /// Reads a raw BSON array.
-        /// </summary>
-        /// <returns>The raw BSON array.</returns>
-        public virtual IByteBuffer ReadRawBsonArray()
-        {
-            // overridden in BsonBinaryReader to read the raw bytes from the stream
-            // for all other streams, deserialize the array and reserialize it using a BsonBinaryWriter to get the raw bytes
-
-            var deserializationContext = BsonDeserializationContext.CreateRoot(this);
-            var array = BsonArraySerializer.Instance.Deserialize(deserializationContext);
-
-            using (var memoryStream = new MemoryStream())
-            using (var bsonWriter = new BsonBinaryWriter(memoryStream, BsonBinaryWriterSettings.Defaults))
-            {
-                var serializationContext = BsonSerializationContext.CreateRoot(bsonWriter);
-                bsonWriter.WriteStartDocument();
-                var startPosition = memoryStream.Position + 3; // just past BsonType, "x" and null byte
-                bsonWriter.WriteName("x");
-                BsonArraySerializer.Instance.Serialize(serializationContext, array);
-                var endPosition = memoryStream.Position;
-                bsonWriter.WriteEndDocument();
-
-                byte[] memoryStreamBuffer;
-#if NETSTANDARD1_5 || NETSTANDARD1_6 || NETCOREAPP
-                memoryStreamBuffer = memoryStream.ToArray();
-#else
-                memoryStreamBuffer = memoryStream.GetBuffer();
-#endif
-                var buffer = new ByteArrayBuffer(memoryStreamBuffer, (int)memoryStream.Length, isReadOnly: true);
-                return new ByteBufferSlice(buffer, (int)startPosition, (int)(endPosition - startPosition));
-            }
-        }
-
-        /// <summary>
-        /// Reads a raw BSON document.
-        /// </summary>
-        /// <returns>The raw BSON document.</returns>
-        public virtual IByteBuffer ReadRawBsonDocument()
-        {
-            // overridden in BsonBinaryReader to read the raw bytes from the stream
-            // for all other streams, deserialize the document and use ToBson to get the raw bytes
-
-            var deserializationContext = BsonDeserializationContext.CreateRoot(this);
-            var document = BsonDocumentSerializer.Instance.Deserialize(deserializationContext);
-            var bytes = document.ToBson();
-            return new ByteArrayBuffer(bytes, isReadOnly: true);
-        }
-
-        /// <summary>
-        /// Reads a BSON regular expression from the reader.
-        /// </summary>
-        /// <returns>A BsonRegularExpression.</returns>
-        public abstract BsonRegularExpression ReadRegularExpression();
-
-        /// <summary>
-        /// Reads the start of a BSON array.
-        /// </summary>
-        public abstract void ReadStartArray();
-
-        /// <summary>
-        /// Reads the start of a BSON document.
-        /// </summary>
-        public abstract void ReadStartDocument();
-
-        /// <summary>
-        /// Reads a BSON string from the reader.
-        /// </summary>
-        /// <returns>A String.</returns>
-        public abstract string ReadString();
-
-        /// <summary>
-        /// Reads a BSON symbol from the reader.
-        /// </summary>
-        /// <returns>A string.</returns>
-        public abstract string ReadSymbol();
-
-        /// <summary>
-        /// Reads a BSON timestamp from the reader.
-        /// </summary>
-        /// <returns>The combined timestamp/increment.</returns>
-        public abstract long ReadTimestamp();
-
-        /// <summary>
-        /// Reads a BSON undefined from the reader.
-        /// </summary>
-        public abstract void ReadUndefined();
-
-        /// <summary>
-        /// Returns the reader to previously bookmarked position and state.
-        /// </summary>
-        /// <param name="bookmark">The bookmark.</param>
-        public abstract void ReturnToBookmark(BsonReaderBookmark bookmark);
-
-        /// <summary>
-        /// Skips the name (reader must be positioned on a name).
-        /// </summary>
-        public abstract void SkipName();
-
-        /// <summary>
-        /// Skips the value (reader must be positioned on a value).
-        /// </summary>
-        public abstract void SkipValue();
-
-        // protected methods
-        /// <summary>
-        /// Disposes of any resources used by the reader.
-        /// </summary>
-        /// <param name="disposing">True if called from Dispose.</param>
-        protected virtual void Dispose(bool disposing)
-        {
-        }
-
-        /// <summary>
-        /// Throws an InvalidOperationException when the method called is not valid for the current ContextType.
-        /// </summary>
-        /// <param name="methodName">The name of the method.</param>
-        /// <param name="actualContextType">The actual ContextType.</param>
-        /// <param name="validContextTypes">The valid ContextTypes.</param>
-        protected void ThrowInvalidContextType(
-            string methodName,
-            ContextType actualContextType,
-            params ContextType[] validContextTypes)
-        {
-            var validContextTypesString = string.Join(" or ", validContextTypes.Select(c => c.ToString()).ToArray());
-            var message = string.Format(
-                "{0} can only be called when ContextType is {1}, not when ContextType is {2}.",
-                methodName, validContextTypesString, actualContextType);
-            throw new InvalidOperationException(message);
-        }
-
-        /// <summary>
-        /// Throws an InvalidOperationException when the method called is not valid for the current state.
-        /// </summary>
-        /// <param name="methodName">The name of the method.</param>
-        /// <param name="validStates">The valid states.</param>
-        protected void ThrowInvalidState(string methodName, params BsonReaderState[] validStates)
-        {
-            var validStatesString = string.Join(" or ", validStates.Select(s => s.ToString()).ToArray());
-            var message = string.Format(
-                "{0} can only be called when State is {1}, not when State is {2}.",
-                methodName, validStatesString, _state);
-            throw new InvalidOperationException(message);
-        }
-
-        /// <summary>
-        /// Throws an ObjectDisposedException.
-        /// </summary>
-        protected void ThrowObjectDisposedException()
-        {
-            throw new ObjectDisposedException(this.GetType().Name);
-        }
-
-        /// <summary>
-        /// Verifies the current state and BsonType of the reader.
-        /// </summary>
-        /// <param name="methodName">The name of the method calling this one.</param>
-        /// <param name="requiredBsonType">The required BSON type.</param>
-        protected void VerifyBsonType(string methodName, BsonType requiredBsonType)
-        {
-            if (_state == BsonReaderState.Initial || _state == BsonReaderState.ScopeDocument || _state == BsonReaderState.Type)
-            {
-                ReadBsonType();
-            }
-            if (_state == BsonReaderState.Name)
-            {
-                // ignore name
-                SkipName();
-            }
-            if (_state != BsonReaderState.Value)
-            {
-                ThrowInvalidState(methodName, BsonReaderState.Value);
-            }
-            if (_currentBsonType != requiredBsonType)
-            {
-                var message = string.Format(
-                    "{0} can only be called when CurrentBsonType is {1}, not when CurrentBsonType is {2}.",
-                    methodName, requiredBsonType, _currentBsonType);
-                throw new InvalidOperationException(message);
-            }
-        }
-    }
-}

+ 0 - 67
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonReaderBookmark.cs

@@ -1,67 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a bookmark that can be used to return a reader to the current position and state.
-    /// </summary>
-    public abstract class BsonReaderBookmark
-    {
-        // private fields
-        private BsonReaderState _state;
-        private BsonType _currentBsonType;
-        private string _currentName;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonReaderBookmark class.
-        /// </summary>
-        /// <param name="state">The state of the reader.</param>
-        /// <param name="currentBsonType">The current BSON type.</param>
-        /// <param name="currentName">The name of the current element.</param>
-        protected BsonReaderBookmark(BsonReaderState state, BsonType currentBsonType, string currentName)
-        {
-            _state = state;
-            _currentBsonType = currentBsonType;
-            _currentName = currentName;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the current state of the reader.
-        /// </summary>
-        public BsonReaderState State
-        {
-            get { return _state; }
-        }
-
-        /// <summary>
-        /// Gets the current BsonType;
-        /// </summary>
-        public BsonType CurrentBsonType
-        {
-            get { return _currentBsonType; }
-        }
-
-        /// <summary>
-        /// Gets the name of the current element.
-        /// </summary>
-        public string CurrentName
-        {
-            get { return _currentName; }
-        }
-    }
-}

+ 0 - 123
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonReaderSettings.cs

@@ -1,123 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents settings for a BsonReader.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public abstract class BsonReaderSettings
-    {
-        // private fields
-        private GuidRepresentation _guidRepresentation = BsonDefaults.GuidRepresentation;
-        private bool _isFrozen;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonReaderSettings class.
-        /// </summary>
-        protected BsonReaderSettings()
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonReaderSettings class.
-        /// </summary>
-        /// <param name="guidRepresentation">The representation for Guids.</param>
-        protected BsonReaderSettings(GuidRepresentation guidRepresentation)
-        {
-            _guidRepresentation = guidRepresentation;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets or sets the representation for Guids.
-        /// </summary>
-        public GuidRepresentation GuidRepresentation
-        {
-            get { return _guidRepresentation; }
-            set
-            {
-                if (_isFrozen) { ThrowFrozenException(); }
-                _guidRepresentation = value;
-            }
-        }
-
-        /// <summary>
-        /// Gets whether the settings are frozen.
-        /// </summary>
-        public bool IsFrozen
-        {
-            get { return _isFrozen; }
-        }
-
-        // public methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        public BsonReaderSettings Clone()
-        {
-            return CloneImplementation();
-        }
-
-        /// <summary>
-        /// Freezes the settings.
-        /// </summary>
-        /// <returns>The frozen settings.</returns>
-        public BsonReaderSettings Freeze()
-        {
-            _isFrozen = true;
-            return this;
-        }
-
-        /// <summary>
-        /// Returns a frozen copy of the settings.
-        /// </summary>
-        /// <returns>A frozen copy of the settings.</returns>
-        public BsonReaderSettings FrozenCopy()
-        {
-            if (_isFrozen)
-            {
-                return this;
-            }
-            else
-            {
-                return Clone().Freeze();
-            }
-        }
-
-        // protected methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        protected abstract BsonReaderSettings CloneImplementation();
-
-        /// <summary>
-        /// Throws an InvalidOperationException when an attempt is made to change a setting after the settings are frozen.
-        /// </summary>
-        protected void ThrowFrozenException()
-        {
-            var message = string.Format("{0} is frozen.", this.GetType().Name);
-            throw new InvalidOperationException(message);
-        }
-    }
-}

+ 0 - 60
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonReaderState.cs

@@ -1,60 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents the state of a reader.
-    /// </summary>
-    public enum BsonReaderState
-    {
-        /// <summary>
-        /// The initial state.
-        /// </summary>
-        Initial,
-        /// <summary>
-        /// The reader is positioned at the type of an element or value.
-        /// </summary>
-        Type,
-        /// <summary>
-        /// The reader is positioned at the name of an element.
-        /// </summary>
-        Name,
-        /// <summary>
-        /// The reader is positioned at a value.
-        /// </summary>
-        Value,
-        /// <summary>
-        /// The reader is positioned at a scope document.
-        /// </summary>
-        ScopeDocument,
-        /// <summary>
-        /// The reader is positioned at the end of a document.
-        /// </summary>
-        EndOfDocument,
-        /// <summary>
-        /// The reader is positioned at the end of an array.
-        /// </summary>
-        EndOfArray,
-        /// <summary>
-        /// The reader has finished reading a document.
-        /// </summary>
-        Done,
-        /// <summary>
-        /// The reader is closed.
-        /// </summary>
-        Closed
-    }
-}

+ 0 - 140
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonStream.cs

@@ -1,140 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a Stream has additional methods to suport reading and writing BSON values.
-    /// </summary>
-    public abstract class BsonStream : Stream
-    {
-        /// <summary>
-        /// Reads a BSON CString from the stream.
-        /// </summary>
-        /// <param name="encoding">The encoding.</param>
-        /// <returns>A string.</returns>
-        public abstract string ReadCString(UTF8Encoding encoding);
-
-        /// <summary>
-        /// Reads a BSON CString from the stream.
-        /// </summary>
-        /// <returns>An ArraySegment containing the CString bytes (without the null byte).</returns>
-        public abstract ArraySegment<byte> ReadCStringBytes();
-
-        /// <summary>
-        /// Reads a BSON Decimal128 from the stream.
-        /// </summary>
-        /// <returns>A <see cref="Decimal128"/>.</returns>
-        public abstract Decimal128 ReadDecimal128();
-
-        /// <summary>
-        /// Reads a BSON double from the stream.
-        /// </summary>
-        /// <returns>A double.</returns>
-        public abstract double ReadDouble();
-
-        /// <summary>
-        /// Reads a 32-bit BSON integer from the stream.
-        /// </summary>
-        /// <returns>An int.</returns>
-        public abstract int ReadInt32();
-
-        /// <summary>
-        /// Reads a 64-bit BSON integer from the stream.
-        /// </summary>
-        /// <returns>A long.</returns>
-        public abstract long ReadInt64();
-
-        /// <summary>
-        /// Reads a BSON ObjectId from the stream.
-        /// </summary>
-        /// <returns>An ObjectId.</returns>
-        public abstract ObjectId ReadObjectId();
-
-        /// <summary>
-        /// Reads a raw length prefixed slice from the stream.
-        /// </summary>
-        /// <returns>A slice.</returns>
-        public abstract IByteBuffer ReadSlice();
-
-        /// <summary>
-        /// Reads a BSON string from the stream.
-        /// </summary>
-        /// <param name="encoding">The encoding.</param>
-        /// <returns>A string.</returns>
-        public abstract string ReadString(UTF8Encoding encoding);
-
-        /// <summary>
-        /// Skips over a BSON CString leaving the stream positioned just after the terminating null byte.
-        /// </summary>
-        public abstract void SkipCString();
-
-        /// <summary>
-        /// Writes a BSON CString to the stream.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        public abstract void WriteCString(string value);
-
-        /// <summary>
-        /// Writes the CString bytes to the stream.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        public abstract void WriteCStringBytes(byte[] value);
-
-        /// <summary>
-        /// Writes a BSON Decimal128 to the stream.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        public abstract void WriteDecimal128(Decimal128 value);
-
-        /// <summary>
-        /// Writes a BSON double to the stream.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        public abstract void WriteDouble(double value);
-
-        /// <summary>
-        /// Writes a 32-bit BSON integer to the stream.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        public abstract void WriteInt32(int value);
-
-        /// <summary>
-        /// Writes a 64-bit BSON integer to the stream.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        public abstract void WriteInt64(long value);
-
-        /// <summary>
-        /// Writes a BSON ObjectId to the stream.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        public abstract void WriteObjectId(ObjectId value);
-
-        /// <summary>
-        /// Writes a BSON string to the stream.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <param name="encoding">The encoding.</param>
-        public abstract void WriteString(string value, UTF8Encoding encoding);
-    }
-}

+ 0 - 567
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonStreamAdapter.cs

@@ -1,567 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// A Stream that wraps another Stream while implementing the BsonStream abstract methods.
-    /// </summary>
-    public sealed class BsonStreamAdapter : BsonStream
-    {
-        // fields
-        private bool _disposed;
-        private bool _ownsStream;
-        private readonly Stream _stream;
-        private readonly byte[] _temp = new byte[12];
-        private readonly byte[] _tempUtf8 = new byte[128];
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BsonStreamAdapter"/> class.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <param name="ownsStream">if set to <c>true</c> [owns stream].</param>
-        /// <exception cref="System.ArgumentNullException">stream</exception>
-        public BsonStreamAdapter(Stream stream, bool ownsStream = false)
-        {
-            if (stream == null)
-            {
-                throw new ArgumentNullException("stream");
-            }
-
-            _stream = stream;
-            _ownsStream = ownsStream;
-        }
-
-        // properties        
-        /// <summary>
-        /// Gets the base stream.
-        /// </summary>
-        /// <value>
-        /// The base stream.
-        /// </value>
-        public Stream BaseStream
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _stream;
-            }
-        }
-
-        /// <inheritdoc/>
-        public override bool CanRead
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _stream.CanRead;
-            }
-        }
-
-        /// <inheritdoc/>
-        public override bool CanSeek
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _stream.CanSeek;
-            }
-        }
-
-        /// <inheritdoc/>
-        public override bool CanTimeout
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _stream.CanTimeout;
-            }
-        }
-
-        /// <inheritdoc/>
-        public override bool CanWrite
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _stream.CanWrite;
-            }
-        }
-
-        /// <inheritdoc/>
-        public override long Length
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _stream.Length;
-            }
-        }
-
-        /// <inheritdoc/>
-        public override long Position
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _stream.Position;
-            }
-            set
-            {
-                ThrowIfDisposed();
-                _stream.Position = value;
-            }
-        }
-
-        /// <inheritdoc/>
-        public override int ReadTimeout
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _stream.ReadTimeout;
-            }
-            set
-            {
-                ThrowIfDisposed();
-                _stream.ReadTimeout = value;
-            }
-        }
-
-        /// <inheritdoc/>
-        public override int WriteTimeout
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _stream.WriteTimeout;
-            }
-            set
-            {
-                ThrowIfDisposed();
-                _stream.WriteTimeout = value;
-            }
-        }
-
-        // methods
-#if NET452
-        /// <inheritdoc/>
-        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
-        {
-            ThrowIfDisposed();
-            return _stream.BeginRead(buffer, offset, count, callback, state);
-        }
-#endif
-
-#if NET452
-        /// <inheritdoc/>
-        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
-        {
-            ThrowIfDisposed();
-            return _stream.BeginWrite(buffer, offset, count, callback, state);
-        }
-#endif
-
-#if NET452
-        /// <inheritdoc/>
-        public override void Close()
-        {
-            base.Close(); // base class will call Dispose
-        }
-#endif
-
-        /// <inheritdoc/>
-        public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
-        {
-            ThrowIfDisposed();
-            return _stream.CopyToAsync(destination, bufferSize, cancellationToken);
-        }
-
-        /// <inheritdoc/>
-        protected override void Dispose(bool disposing)
-        {
-            if (!_disposed)
-            {
-                if (disposing)
-                {
-                    if (_ownsStream)
-                    {
-                        _stream.Dispose();
-                    }
-                }
-                _disposed = true;
-            }
-            base.Dispose(disposing);
-        }
-
-#if NET452
-        /// <inheritdoc/>
-        public override int EndRead(IAsyncResult asyncResult)
-        {
-            ThrowIfDisposed();
-            return _stream.EndRead(asyncResult);
-        }
-#endif
-
-#if NET452
-        /// <inheritdoc/>
-        public override void EndWrite(IAsyncResult asyncResult)
-        {
-            ThrowIfDisposed();
-            _stream.EndWrite(asyncResult);
-        }
-#endif
-
-        /// <inheritdoc/>
-        public override void Flush()
-        {
-            ThrowIfDisposed();
-            _stream.Flush();
-        }
-
-        /// <inheritdoc/>
-        public override Task FlushAsync(CancellationToken cancellationToken)
-        {
-            ThrowIfDisposed();
-            return _stream.FlushAsync(cancellationToken);
-        }
-
-        /// <inheritdoc/>
-        public override int Read(byte[] buffer, int offset, int count)
-        {
-            ThrowIfDisposed();
-            return _stream.Read(buffer, offset, count);
-        }
-
-        /// <inheritdoc/>
-        public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
-        {
-            ThrowIfDisposed();
-            return _stream.ReadAsync(buffer, offset, count, cancellationToken);
-        }
-
-        /// <inheritdoc/>
-        public override int ReadByte()
-        {
-            ThrowIfDisposed();
-            return _stream.ReadByte();
-        }
-
-        /// <inheritdoc/>
-        public override string ReadCString(UTF8Encoding encoding)
-        {
-            if (encoding == null)
-            {
-                throw new ArgumentNullException("encoding");
-            }
-            ThrowIfDisposed();
-
-            var bytes = ReadCStringBytes();
-            return Utf8Helper.DecodeUtf8String(bytes.Array, 0, bytes.Count, encoding);
-        }
-
-        /// <inheritdoc/>
-        public override ArraySegment<byte> ReadCStringBytes()
-        {
-            ThrowIfDisposed();
-
-            var memoryStream = new MemoryStream(32);
-
-            while (true)
-            {
-                var b = _stream.ReadByte();
-                if (b == -1)
-                {
-                    throw new EndOfStreamException();
-                }
-                if (b == 0)
-                {
-                    byte[] memoryStreamBuffer;
-#if NETSTANDARD1_5 || NETSTANDARD1_6 || NETCOREAPP
-                    memoryStreamBuffer = memoryStream.ToArray();
-#else
-                    memoryStreamBuffer = memoryStream.GetBuffer();
-#endif
-                    return new ArraySegment<byte>(memoryStreamBuffer, 0, (int)memoryStream.Length);
-                }
-
-                memoryStream.WriteByte((byte)b);
-            }
-        }
-
-        /// <inheritdoc/>
-        public override Decimal128 ReadDecimal128()
-        {
-            ThrowIfDisposed();
-            var lowBits = (ulong)ReadInt64();
-            var highBits = (ulong)ReadInt64();
-            return Decimal128.FromIEEEBits(highBits, lowBits);
-        }
-
-        /// <inheritdoc/>
-        public override double ReadDouble()
-        {
-            ThrowIfDisposed();
-            this.ReadBytes(_temp, 0, 8);
-            return BitConverter.ToDouble(_temp, 0);
-        }
-
-        /// <inheritdoc/>
-        public override int ReadInt32()
-        {
-            ThrowIfDisposed();
-            this.ReadBytes(_temp, 0, 4);
-            return _temp[0] | (_temp[1] << 8) | (_temp[2] << 16) | (_temp[3] << 24);
-        }
-
-        /// <inheritdoc/>
-        public override long ReadInt64()
-        {
-            ThrowIfDisposed();
-            this.ReadBytes(_temp, 0, 8);
-            return BitConverter.ToInt64(_temp, 0);
-        }
-
-        /// <inheritdoc/>
-        public override ObjectId ReadObjectId()
-        {
-            ThrowIfDisposed();
-            this.ReadBytes(_temp, 0, 12);
-            return new ObjectId(_temp, 0);
-        }
-
-        /// <inheritdoc/>
-        public override IByteBuffer ReadSlice()
-        {
-            ThrowIfDisposed();
-            var position = _stream.Position;
-            var length = ReadInt32();
-            var bytes = new byte[length];
-            _stream.Position = position;
-            this.ReadBytes(bytes, 0, length);
-            return new ByteArrayBuffer(bytes, isReadOnly: true);
-        }
-
-        /// <inheritdoc/>
-        public override string ReadString(UTF8Encoding encoding)
-        {
-            if (encoding == null)
-            {
-                throw new ArgumentNullException("encoding");
-            }
-            ThrowIfDisposed();
-
-            var length = ReadInt32();
-            var bytes = length <= _tempUtf8.Length ? _tempUtf8 : new byte[length];
-            this.ReadBytes(bytes, 0, length);
-            if (bytes[length - 1] != 0)
-            {
-                throw new FormatException("String is missing terminating null byte.");
-            }
-
-            return encoding.GetString(bytes, 0, length - 1);
-        }
-
-        /// <inheritdoc/>
-        public override long Seek(long offset, SeekOrigin origin)
-        {
-            ThrowIfDisposed();
-            return _stream.Seek(offset, origin);
-        }
-
-        /// <inheritdoc/>
-        public override void SetLength(long value)
-        {
-            ThrowIfDisposed();
-            _stream.SetLength(value);
-        }
-
-        /// <inheritdoc/>
-        public override void SkipCString()
-        {
-            ThrowIfDisposed();
-
-            while (true)
-            {
-                var b = _stream.ReadByte();
-                if (b == -1)
-                {
-                    throw new EndOfStreamException();
-                }
-                if (b == 0)
-                {
-                    return;
-                }
-            }
-        }
-
-        /// <inheritdoc/>
-        private void ThrowIfDisposed()
-        {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException(GetType().Name);
-            }
-        }
-
-        /// <inheritdoc/>
-        public override void Write(byte[] buffer, int offset, int count)
-        {
-            ThrowIfDisposed();
-            _stream.Write(buffer, offset, count);
-        }
-
-        /// <inheritdoc/>
-        public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
-        {
-            ThrowIfDisposed();
-            return _stream.WriteAsync(buffer, offset, count, cancellationToken);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteByte(byte value)
-        {
-            ThrowIfDisposed();
-            _stream.WriteByte(value);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteCString(string value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-            ThrowIfDisposed();
-
-            byte[] bytes;
-            int length;
-
-            if (CStringUtf8Encoding.GetMaxByteCount(value.Length) <= _tempUtf8.Length)
-            {
-                bytes = _tempUtf8;
-                length = CStringUtf8Encoding.GetBytes(value, _tempUtf8, 0, Utf8Encodings.Strict);
-            }
-            else
-            {
-                bytes = Utf8Encodings.Strict.GetBytes(value);
-                if (Array.IndexOf<byte>(bytes, 0) != -1)
-                {
-                    throw new ArgumentException("A CString cannot contain null bytes.", "value");
-                }
-                length = bytes.Length;
-            }
-
-            _stream.Write(bytes, 0, length);
-            _stream.WriteByte(0);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteCStringBytes(byte[] value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-            ThrowIfDisposed();
-
-            this.WriteBytes(value, 0, value.Length);
-            WriteByte(0);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteDecimal128(Decimal128 value)
-        {
-            ThrowIfDisposed();
-            WriteInt64((long)value.GetIEEELowBits());
-            WriteInt64((long)value.GetIEEEHighBits());
-        }
-
-        /// <inheritdoc/>
-        public override void WriteDouble(double value)
-        {
-            ThrowIfDisposed();
-            var bytes = BitConverter.GetBytes(value);
-            _stream.Write(bytes, 0, 8);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteInt32(int value)
-        {
-            ThrowIfDisposed();
-            _temp[0] = (byte)(value);
-            _temp[1] = (byte)(value >> 8);
-            _temp[2] = (byte)(value >> 16);
-            _temp[3] = (byte)(value >> 24);
-            _stream.Write(_temp, 0, 4);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteInt64(long value)
-        {
-            ThrowIfDisposed();
-            var bytes = BitConverter.GetBytes(value);
-            _stream.Write(bytes, 0, 8);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteObjectId(ObjectId value)
-        {
-            ThrowIfDisposed();
-            value.ToByteArray(_temp, 0);
-            _stream.Write(_temp, 0, 12);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteString(string value, UTF8Encoding encoding)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-            if (encoding == null)
-            {
-                throw new ArgumentNullException("encoding");
-            }
-            ThrowIfDisposed();
-
-            byte[] bytes;
-            int length;
-
-            if (encoding.GetMaxByteCount(value.Length) <= _tempUtf8.Length)
-            {
-                bytes = _tempUtf8;
-                length = encoding.GetBytes(value, 0, value.Length, _tempUtf8, 0);
-            }
-            else
-            {
-                bytes = encoding.GetBytes(value);
-                length = bytes.Length;
-            }
-
-            WriteInt32(length + 1);
-            _stream.Write(bytes, 0, length);
-            _stream.WriteByte(0);
-        }
-    }
-}

+ 0 - 315
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonStreamExtensions.cs

@@ -1,315 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents extension methods on BsonStream.
-    /// </summary>
-    public static class BsonStreamExtensions
-    {
-        // static fields
-        private static readonly bool[] __validBsonTypes = new bool[256];
-
-        // static constructor
-        static BsonStreamExtensions()
-        {
-            foreach (BsonType bsonType in Enum.GetValues(typeof(BsonType)))
-            {
-                __validBsonTypes[(byte)bsonType] = true;
-            }
-        }
-
-        // static methods
-        /// <summary>
-        /// Backpatches the size.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <param name="startPosition">The start position.</param>
-        public static void BackpatchSize(this BsonStream stream, long startPosition)
-        {
-            if (stream == null)
-            {
-                throw new ArgumentNullException("stream");
-            }
-            if (startPosition < 0 || startPosition > stream.Length)
-            {
-                throw new ArgumentOutOfRangeException("startPosition");
-            }
-
-            var size = stream.Position - startPosition;
-            if (size > int.MaxValue)
-            {
-                var message = string.Format("Size {0} is larger than {1} (Int32.MaxValue).", size, int.MaxValue);
-                throw new FormatException(message);
-            }
-
-            var endPosition = stream.Position;
-            stream.Position = startPosition;
-            stream.WriteInt32((int)size);
-            stream.Position = endPosition;
-        }
-
-        /// <summary>
-        /// Reads the binary sub type.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <returns>The binary sub type.</returns>
-        public static BsonBinarySubType ReadBinarySubType(this BsonStream stream)
-        {
-            if (stream == null)
-            {
-                throw new ArgumentNullException("stream");
-            }
-            
-            var b = stream.ReadByte();
-            if (b == -1)
-            {
-                throw new EndOfStreamException();
-            }
-            return (BsonBinarySubType)b;
-        }
-
-        /// <summary>
-        /// Reads a boolean from the stream.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <returns>A boolean.</returns>
-        public static bool ReadBoolean(this BsonStream stream)
-        {
-            if (stream == null)
-            {
-                throw new ArgumentNullException("stream");
-            }
-            
-            var b = stream.ReadByte();
-            if (b == -1)
-            {
-                throw new EndOfStreamException();
-            }
-            return b != 0;
-        }
-
-        /// <summary>
-        /// Reads the BSON type.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <returns>The BSON type.</returns>
-        public static BsonType ReadBsonType(this BsonStream stream)
-        {
-            if (stream == null)
-            {
-                throw new ArgumentNullException("stream");
-            }
-
-            var b = stream.ReadByte();
-            if (b == -1)
-            {
-                throw new EndOfStreamException();
-            }
-            if (!__validBsonTypes[b])
-            {
-                var message = string.Format("Detected unknown BSON type \"\\x{0:x2}\". Are you using the latest driver version?", b);
-                throw new FormatException(message);
-            }
-            return (BsonType)b;
-        }
-
-        /// <summary>
-        /// Reads bytes from the stream.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <param name="buffer">The buffer.</param>
-        /// <param name="offset">The offset.</param>
-        /// <param name="count">The count.</param>
-        public static void ReadBytes(this BsonStream stream, byte[] buffer, int offset, int count)
-        {
-            if (stream == null)
-            {
-                throw new ArgumentNullException("stream");
-            }
-            if (buffer == null)
-            {
-                throw new ArgumentNullException("buffer");
-            }
-            if (offset < 0 || offset > buffer.Length)
-            {
-                throw new ArgumentOutOfRangeException("offset");
-            }
-            if (count < 0 || offset + count > buffer.Length)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-
-            if (count == 1)
-            {
-                var b = stream.ReadByte();
-                if (b == -1)
-                {
-                    throw new EndOfStreamException();
-                }
-                buffer[offset] = (byte)b;
-            }
-            else
-            {
-                while (count > 0)
-                {
-                    var bytesRead = stream.Read(buffer, offset, count);
-                    if (bytesRead == 0)
-                    {
-                        throw new EndOfStreamException();
-                    }
-                    offset += bytesRead;
-                    count -= bytesRead;
-                }
-            }
-        }
-
-        /// <summary>
-        /// Reads bytes from the stream.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <param name="count">The count.</param>
-        /// <returns>The bytes.</returns>
-        public static byte[] ReadBytes(this BsonStream stream, int count)
-        {
-            if (stream == null)
-            {
-                throw new ArgumentNullException("stream");
-            }
-            if (count < 0)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-
-            var bytes = new byte[count];
-            stream.ReadBytes(bytes, 0, count);
-            return bytes;
-        }
-
-        /// <summary>
-        /// Writes a binary sub type to the stream.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <param name="value">The value.</param>
-        public static void WriteBinarySubType(this BsonStream stream, BsonBinarySubType value)
-        {
-            if (stream == null)
-            {
-                throw new ArgumentNullException("stream");
-            }
-            
-            stream.WriteByte((byte)value);
-        }
-
-        /// <summary>
-        /// Writes a boolean to the stream.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <param name="value">The value.</param>
-        public static void WriteBoolean(this BsonStream stream, bool value)
-        {
-            if (stream == null)
-            {
-                throw new ArgumentNullException("stream");
-            }
-            
-            stream.WriteByte(value ? (byte)1 : (byte)0);
-        }
-
-        /// <summary>
-        /// Writes a BsonType to the stream.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <param name="value">The value.</param>
-        public static void WriteBsonType(this BsonStream stream, BsonType value)
-        {
-            if (stream == null)
-            {
-                throw new ArgumentNullException("stream");
-            }
-            
-            stream.WriteByte((byte)value);
-        }
-
-        /// <summary>
-        /// Writes bytes to the stream.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <param name="buffer">The buffer.</param>
-        /// <param name="offset">The offset.</param>
-        /// <param name="count">The count.</param>
-        public static void WriteBytes(this BsonStream stream, byte[] buffer, int offset, int count)
-        {
-            if (stream == null)
-            {
-                throw new ArgumentNullException("stream");
-            }
-            if (buffer == null)
-            {
-                throw new ArgumentNullException("buffer");
-            }
-            if (offset < 0 || offset > buffer.Length)
-            {
-                throw new ArgumentOutOfRangeException("offset");
-            }
-            if (count < 0 || offset + count > buffer.Length)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-
-            if (count == 1)
-            {
-                stream.WriteByte(buffer[offset]);
-            }
-            else
-            {
-                stream.Write(buffer, offset, count);
-            }
-        }
-
-        /// <summary>
-        /// Writes a slice to the stream.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <param name="slice">The slice.</param>
-        public static void WriteSlice(this BsonStream stream, IByteBuffer slice)
-        {
-            if (stream == null)
-            {
-                throw new ArgumentNullException("stream");
-            }
-            if (slice == null)
-            {
-                throw new ArgumentNullException("slice");
-            }
-
-            var position = 0;
-            var count = slice.Length;
-
-            while (count > 0)
-            {
-                var segment = slice.AccessBackingBytes(position);
-                var partialCount = Math.Min(count, segment.Count);
-                stream.WriteBytes(segment.Array, segment.Offset, partialCount);
-                position += partialCount;
-                count -= partialCount;
-            }
-        }
-    }
-}

+ 0 - 354
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonTrie.cs

@@ -1,354 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-using System.Text;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a mapping from a set of UTF8 encoded strings to a set of elementName/value pairs, implemented as a trie.
-    /// </summary>
-    /// <typeparam name="TValue">The type of the BsonTrie values.</typeparam>
-    public class BsonTrie<TValue>
-    {
-        // private fields
-        private readonly BsonTrieNode<TValue> _root;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonTrie class.
-        /// </summary>
-        public BsonTrie()
-        {
-            _root = new BsonTrieNode<TValue>(0);
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the root node.
-        /// </summary>
-        public BsonTrieNode<TValue> Root
-        {
-            get
-            {
-                return _root;
-            }
-        }
-
-        // public methods
-        /// <summary>
-        /// Adds the specified elementName (after encoding as a UTF8 byte sequence) and value to the trie.
-        /// </summary>
-        /// <param name="elementName">The element name to add.</param>
-        /// <param name="value">The value to add. The value can be null for reference types.</param>
-        public void Add(string elementName, TValue value)
-        {
-            var utf8 = Utf8Encodings.Strict.GetBytes(elementName);
-
-            var node = _root;
-            foreach (var keyByte in utf8)
-            {
-                var child = node.GetChild(keyByte);
-                if (child == null)
-                {
-                    child = new BsonTrieNode<TValue>(keyByte);
-                    node.AddChild(child);
-                }
-                node = child;
-            }
-
-            node.SetValue(elementName, value);
-        }
-
-        /// <summary>
-        /// Gets the node associated with the specified element name.
-        /// </summary>
-        /// <param name="utf8">The element name.</param>
-        /// <param name="node">
-        /// When this method returns, contains the node associated with the specified element name, if the key is found;
-        /// otherwise, null. This parameter is passed unitialized.
-        /// </param>
-        /// <returns>True if the node was found; otherwise, false.</returns>
-        public bool TryGetNode(ArraySegment<byte> utf8, out BsonTrieNode<TValue> node)
-        {
-            node = _root;
-            for (var i = 0; node != null && i < utf8.Count; i++)
-            {
-                var keyByte = utf8.Array[utf8.Offset + i];
-                node = node.GetChild(keyByte);
-            }
-
-            return node != null;
-        }
-
-        /// <summary>
-        /// Tries to get the node associated with a name read from a stream.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <param name="node">The node.</param>
-        /// <returns>
-        /// True if the node was found.
-        /// If the node was found the stream is advanced over the name, otherwise
-        /// the stream is repositioned to the beginning of the name.
-        /// </returns>
-        public bool TryGetNode(BsonStream stream, out BsonTrieNode<TValue> node)
-        {
-            var position = stream.Position;
-            var utf8 = stream.ReadCStringBytes();
-
-            if (TryGetNode(utf8, out node))
-            {
-                return true;
-            }
-
-            stream.Position = position;
-            return false;
-        }
-
-        /// <summary>
-        /// Gets the value associated with the specified element name.
-        /// </summary>
-        /// <param name="utf8">The element name.</param>
-        /// <param name="value">
-        /// When this method returns, contains the value associated with the specified element name, if the key is found;
-        /// otherwise, the default value for the type of the value parameter. This parameter is passed unitialized.
-        /// </param>
-        /// <returns>True if the value was found; otherwise, false.</returns>
-        public bool TryGetValue(ArraySegment<byte> utf8, out TValue value)
-        {
-            BsonTrieNode<TValue> node;
-            if (TryGetNode(utf8, out node) && node.HasValue)
-            {
-                value = node.Value;
-                return true;
-            }
-
-            value = default(TValue);
-            return false;
-        }
-
-        /// <summary>
-        /// Gets the value associated with the specified element name.
-        /// </summary>
-        /// <param name="elementName">The element name.</param>
-        /// <param name="value">
-        /// When this method returns, contains the value associated with the specified element name, if the key is found;
-        /// otherwise, the default value for the type of the value parameter. This parameter is passed unitialized.
-        /// </param>
-        /// <returns>True if the value was found; otherwise, false.</returns>
-        public bool TryGetValue(string elementName, out TValue value)
-        {
-            var bytes = Utf8Encodings.Strict.GetBytes(elementName);
-            var utf8 = new ArraySegment<byte>(bytes, 0, bytes.Length);
-            return TryGetValue(utf8, out value);
-        }
-    }
-
-    /// <summary>
-    /// Represents a node in a BsonTrie.
-    /// </summary>
-    /// <typeparam name="TValue">The type of the BsonTrie values.</typeparam>
-    public sealed class BsonTrieNode<TValue>
-    {
-        // private fields
-        private readonly byte _keyByte;
-        private string _elementName;
-        private TValue _value;
-        private BsonTrieNode<TValue> _onlyChild; // used when there is only one child
-        private BsonTrieNode<TValue>[] _children; // used when there are two or more children
-        private byte[] _childrenIndexes; // maps key bytes into indexes into the _children array
-        private byte _minChildKeyByte; // key byte value of first element in _childrenIndexes
-
-        // constructors
-        internal BsonTrieNode(byte keyByte)
-        {
-            _keyByte = keyByte;
-        }
-
-        /// <summary>
-        /// Gets whether this node has a value.
-        /// </summary>
-        public bool HasValue
-        {
-            get
-            {
-                return _elementName != null;
-            }
-        }
-
-        /// <summary>
-        /// Gets the element name for this node.
-        /// </summary>
-        public string ElementName
-        {
-            get
-            {
-                if (_elementName == null)
-                {
-                    throw new InvalidOperationException("BsonTrieNode doesn't have a value.");
-                }
-
-                return _elementName;
-            }
-        }
-
-        /// <summary>
-        /// Gets the value for this node.
-        /// </summary>
-        public TValue Value
-        {
-            get
-            {
-                if (_elementName == null)
-                {
-                    throw new InvalidOperationException("BsonTrieNode doesn't have a value.");
-                }
-
-                return _value;
-            }
-        }
-
-        // public methods
-        /// <summary>
-        /// Gets the child of this node for a given key byte.
-        /// </summary>
-        /// <param name="keyByte">The key byte.</param>
-        /// <returns>The child node if it exists; otherwise, null.</returns>
-        public BsonTrieNode<TValue> GetChild(byte keyByte)
-        {
-            if (_onlyChild != null)
-            {
-                // optimization for nodes that have only one child
-                if (_onlyChild._keyByte == keyByte)
-                {
-                    return _onlyChild;
-                }
-            }
-            else if (_children != null)
-            {
-                var index = (uint)((int)keyByte - _minChildKeyByte);
-                if (index < _childrenIndexes.Length)
-                {
-                    index = _childrenIndexes[index];
-                    if (index < _children.Length)
-                    {
-                        return _children[index];
-                    }
-                }
-            }
-            return null;
-        }
-
-        // internal methods
-        internal void AddChild(BsonTrieNode<TValue> child)
-        {
-            if (GetChild(child._keyByte) != null)
-            {
-                throw new ArgumentException("BsonTrieNode already contains a child with the same keyByte.");
-            }
-
-            if (_children != null)
-            {
-                // add a new child to the existing _children
-                var children = new BsonTrieNode<TValue>[_children.Length + 1];
-                Array.Copy(_children, children, _children.Length);
-                children[children.Length - 1] = child;
-
-                var childrenIndexes = _childrenIndexes;
-                var minChildKeyByte = _minChildKeyByte;
-                var maxChildKeyByte = _minChildKeyByte + _childrenIndexes.Length - 1;
-
-                // if new keyByte doesn't fall within existing min/max range expand the range
-                if (child._keyByte < minChildKeyByte)
-                {
-                    // grow the indexes on the min side
-                    minChildKeyByte = child._keyByte;
-                    childrenIndexes = new byte[maxChildKeyByte - minChildKeyByte + 1];
-                    var sizeDelta = childrenIndexes.Length - _childrenIndexes.Length;
-                    for (var i = 0; i < sizeDelta; i++)
-                    {
-                        childrenIndexes[i] = 255;
-                    }
-                    Array.Copy(_childrenIndexes, 0, childrenIndexes, sizeDelta, _childrenIndexes.Length);
-                }
-                else if (child._keyByte > maxChildKeyByte)
-                {
-                    // grow the indexes on the max side
-                    maxChildKeyByte = child._keyByte;
-                    childrenIndexes = new byte[maxChildKeyByte - minChildKeyByte + 1];
-                    Array.Copy(_childrenIndexes, 0, childrenIndexes, 0, _childrenIndexes.Length);
-                    for (var i = _childrenIndexes.Length; i < childrenIndexes.Length; i++)
-                    {
-                        childrenIndexes[i] = 255;
-                    }
-                }
-                childrenIndexes[child._keyByte - minChildKeyByte] = (byte)(children.Length - 1);
-
-                _children = children;
-                _childrenIndexes = childrenIndexes;
-                _minChildKeyByte = minChildKeyByte;
-            }
-            else if (_onlyChild != null)
-            {
-                // switch from having an _onlyChild to having two _children
-                var children = new BsonTrieNode<TValue>[2];
-                children[0] = _onlyChild;
-                children[1] = child;
-
-                var minChildKeyByte = _onlyChild._keyByte;
-                var maxChildKeyByte = child._keyByte;
-                if (minChildKeyByte > maxChildKeyByte)
-                {
-                    minChildKeyByte = child._keyByte;
-                    maxChildKeyByte = _onlyChild._keyByte;
-                }
-
-                var childrenIndexes = new byte[maxChildKeyByte - minChildKeyByte + 1];
-                for (var i = 0; i < childrenIndexes.Length; i++)
-                {
-                    childrenIndexes[i] = 255;
-                }
-                childrenIndexes[_onlyChild._keyByte - minChildKeyByte] = 0;
-                childrenIndexes[child._keyByte - minChildKeyByte] = 1;
-
-                _onlyChild = null;
-                _children = children;
-                _childrenIndexes = childrenIndexes;
-                _minChildKeyByte = minChildKeyByte;
-            }
-            else
-            {
-                _onlyChild = child;
-            }
-        }
-
-        internal void SetValue(string elementName, TValue value)
-        {
-            if (elementName == null)
-            {
-                throw new ArgumentNullException("elementName");
-            }
-            if (_elementName != null)
-            {
-                throw new InvalidOperationException("BsonTrieNode already has a value.");
-            }
-
-            _elementName = elementName;
-            _value = value;
-        }
-    }
-}

+ 0 - 473
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonWriter.cs

@@ -1,473 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using MongoDB.Bson.Serialization;
-using MongoDB.Bson.Serialization.Serializers;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a BSON writer for some external format (see subclasses).
-    /// </summary>
-    public abstract class BsonWriter : IBsonWriter
-    {
-        // private fields
-        private Func<IElementNameValidator> _childElementNameValidatorFactory = () => NoOpElementNameValidator.Instance;
-        private bool _disposed = false;
-        private IElementNameValidator _elementNameValidator = NoOpElementNameValidator.Instance;
-        private Stack<IElementNameValidator> _elementNameValidatorStack = new Stack<IElementNameValidator>();
-        private BsonWriterSettings _settings;
-        private Stack<BsonWriterSettings> _settingsStack = new Stack<BsonWriterSettings>();
-        private BsonWriterState _state;
-        private string _name;
-        private int _serializationDepth;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonWriter class.
-        /// </summary>
-        /// <param name="settings">The writer settings.</param>
-        protected BsonWriter(BsonWriterSettings settings)
-        {
-            if (settings == null)
-            {
-                throw new ArgumentNullException("settings");
-            }
-
-            _settings = settings.FrozenCopy();
-            _state = BsonWriterState.Initial;
-        }
-
-        // public properties
-        /// <inheritdoc />
-        public abstract long Position { get; }
-
-        /// <summary>
-        /// Gets the current serialization depth.
-        /// </summary>
-        public int SerializationDepth
-        {
-            get { return _serializationDepth; }
-        }
-
-        /// <summary>
-        /// Gets the settings of the writer.
-        /// </summary>
-        public BsonWriterSettings Settings
-        {
-            get { return _settings; }
-        }
-
-        /// <summary>
-        /// Gets the current state of the writer.
-        /// </summary>
-        public BsonWriterState State
-        {
-            get { return _state; }
-            protected set { _state = value; }
-        }
-
-        // protected properties
-        /// <summary>
-        /// Gets whether the BsonWriter has been disposed.
-        /// </summary>
-        public bool Disposed
-        {
-            get { return _disposed; }
-        }
-
-        // protected properties
-        /// <summary>
-        /// Gets the name of the element being written.
-        /// </summary>
-        protected string Name
-        {
-            get { return _name; }
-        }
-
-        // public static methods
-        // public methods
-        /// <summary>
-        /// Closes the writer.
-        /// </summary>
-        public abstract void Close();
-
-        /// <summary>
-        /// Disposes of any resources used by the writer.
-        /// </summary>
-        public void Dispose()
-        {
-            if (!_disposed)
-            {
-                Dispose(true);
-                _disposed = true;
-            }
-        }
-
-        /// <summary>
-        /// Flushes any pending data to the output destination.
-        /// </summary>
-        public abstract void Flush();
-
-        /// <summary>
-        /// Pops the element name validator.
-        /// </summary>
-        /// <returns>The popped element validator.</returns>
-        public void PopElementNameValidator()
-        {
-            _elementNameValidator = _elementNameValidatorStack.Pop();
-            _childElementNameValidatorFactory = () => _elementNameValidator;
-        }
-
-        /// <inheritdoc />
-        public void PopSettings()
-        {
-            _settings = _settingsStack.Pop();
-        }
-
-        /// <summary>
-        /// Pushes the element name validator.
-        /// </summary>
-        /// <param name="validator">The validator.</param>
-        public void PushElementNameValidator(IElementNameValidator validator)
-        {
-            if (validator == null)
-            {
-                throw new ArgumentNullException("validator");
-            }
-
-            _elementNameValidatorStack.Push(_elementNameValidator);
-            _elementNameValidator = validator;
-            _childElementNameValidatorFactory = () => _elementNameValidator;
-        }
-
-        /// <inheritdoc />
-        public void PushSettings(Action<BsonWriterSettings> configurator)
-        {
-            var newSettings = _settings.Clone();
-            configurator(newSettings);
-            newSettings.Freeze();
-            _settingsStack.Push(_settings);
-            _settings = newSettings;
-        }
-
-        /// <summary>
-        /// Writes BSON binary data to the writer.
-        /// </summary>
-        /// <param name="binaryData">The binary data.</param>
-        public abstract void WriteBinaryData(BsonBinaryData binaryData);
-
-        /// <summary>
-        /// Writes a BSON Boolean to the writer.
-        /// </summary>
-        /// <param name="value">The Boolean value.</param>
-        public abstract void WriteBoolean(bool value);
-
-        /// <summary>
-        /// Writes BSON binary data to the writer.
-        /// </summary>
-        /// <param name="bytes">The bytes.</param>
-        public abstract void WriteBytes(byte[] bytes);
-
-        /// <summary>
-        /// Writes a BSON DateTime to the writer.
-        /// </summary>
-        /// <param name="value">The number of milliseconds since the Unix epoch.</param>
-        public abstract void WriteDateTime(long value);
-
-        /// <inheritdoc />
-        public abstract void WriteDecimal128(Decimal128 value);
-
-        /// <summary>
-        /// Writes a BSON Double to the writer.
-        /// </summary>
-        /// <param name="value">The Double value.</param>
-        public abstract void WriteDouble(double value);
-
-        /// <summary>
-        /// Writes the end of a BSON array to the writer.
-        /// </summary>
-        public virtual void WriteEndArray()
-        {
-            _serializationDepth--;
-        }
-
-        /// <summary>
-        /// Writes the end of a BSON document to the writer.
-        /// </summary>
-        public virtual void WriteEndDocument()
-        {
-            _serializationDepth--;
-
-            PopElementNameValidator();
-        }
-
-        /// <summary>
-        /// Writes a BSON Int32 to the writer.
-        /// </summary>
-        /// <param name="value">The Int32 value.</param>
-        public abstract void WriteInt32(int value);
-
-        /// <summary>
-        /// Writes a BSON Int64 to the writer.
-        /// </summary>
-        /// <param name="value">The Int64 value.</param>
-        public abstract void WriteInt64(long value);
-
-        /// <summary>
-        /// Writes a BSON JavaScript to the writer.
-        /// </summary>
-        /// <param name="code">The JavaScript code.</param>
-        public abstract void WriteJavaScript(string code);
-
-        /// <summary>
-        /// Writes a BSON JavaScript to the writer (call WriteStartDocument to start writing the scope).
-        /// </summary>
-        /// <param name="code">The JavaScript code.</param>
-        public abstract void WriteJavaScriptWithScope(string code);
-
-        /// <summary>
-        /// Writes a BSON MaxKey to the writer.
-        /// </summary>
-        public abstract void WriteMaxKey();
-
-        /// <summary>
-        /// Writes a BSON MinKey to the writer.
-        /// </summary>
-        public abstract void WriteMinKey();
-
-        /// <summary>
-        /// Writes the name of an element to the writer.
-        /// </summary>
-        /// <param name="name">The name of the element.</param>
-        public virtual void WriteName(string name)
-        {
-            if (name == null)
-            {
-                throw new ArgumentNullException("name");
-            }
-            if (name.IndexOf('\0') != -1)
-            {
-                throw new BsonSerializationException("Element names cannot contain nulls.");
-            }
-            if (_disposed) { throw new ObjectDisposedException(this.GetType().Name); }
-            if (_state != BsonWriterState.Name)
-            {
-                ThrowInvalidState("WriteName", BsonWriterState.Name);
-            }
-
-            if (!_elementNameValidator.IsValidElementName(name))
-            {
-                var message = string.Format("Element name '{0}' is not valid'.", name);
-                throw new BsonSerializationException(message);
-            }
-            _childElementNameValidatorFactory = () => _elementNameValidator.GetValidatorForChildContent(name);
-
-            _name = name;
-            _state = BsonWriterState.Value;
-        }
-
-        /// <summary>
-        /// Writes a BSON null to the writer.
-        /// </summary>
-        public abstract void WriteNull();
-
-        /// <summary>
-        /// Writes a BSON ObjectId to the writer.
-        /// </summary>
-        /// <param name="objectId">The ObjectId.</param>
-        public abstract void WriteObjectId(ObjectId objectId);
-
-        /// <summary>
-        /// Writes a raw BSON array.
-        /// </summary>
-        /// <param name="slice">The byte buffer containing the raw BSON array.</param>
-        public virtual void WriteRawBsonArray(IByteBuffer slice)
-        {
-            // overridden in BsonBinaryWriter to write the raw bytes to the stream
-            // for all other streams, deserialize the raw bytes and serialize the resulting array instead
-
-            using (var chunkSource = new InputBufferChunkSource(BsonChunkPool.Default))
-            using (var buffer = new MultiChunkBuffer(chunkSource))
-            using (var stream = new ByteBufferStream(buffer))
-            {
-                // wrap the array in a fake document so we can deserialize it
-                var documentLength = slice.Length + 8;
-                buffer.EnsureCapacity(documentLength);
-                stream.WriteInt32(documentLength);
-                stream.WriteBsonType(BsonType.Array);
-                stream.WriteByte((byte)'x');
-                stream.WriteByte(0);
-                stream.WriteSlice(slice);
-                stream.WriteByte(0);
-                buffer.MakeReadOnly();
-
-                stream.Position = 0;
-                using (var reader = new BsonBinaryReader(stream, BsonBinaryReaderSettings.Defaults))
-                {
-                    var deserializationContext = BsonDeserializationContext.CreateRoot(reader);
-                    reader.ReadStartDocument();
-                    reader.ReadName("x");
-                    var array = BsonArraySerializer.Instance.Deserialize(deserializationContext);
-                    reader.ReadEndDocument();
-
-                    var serializationContext = BsonSerializationContext.CreateRoot(this);
-                    BsonArraySerializer.Instance.Serialize(serializationContext, array);
-                }
-            }
-        }
-
-        /// <summary>
-        /// Writes a raw BSON document.
-        /// </summary>
-        /// <param name="slice">The byte buffer containing the raw BSON document.</param>
-        public virtual void WriteRawBsonDocument(IByteBuffer slice)
-        {
-            // overridden in BsonBinaryWriter to write the raw bytes to the stream
-            // for all other streams, deserialize the raw bytes and serialize the resulting document instead
-
-            using (var stream = new ByteBufferStream(slice, ownsBuffer: false))
-            using (var bsonReader = new BsonBinaryReader(stream, BsonBinaryReaderSettings.Defaults))
-            {
-                var deserializationContext = BsonDeserializationContext.CreateRoot(bsonReader);
-                var document = BsonDocumentSerializer.Instance.Deserialize(deserializationContext);
-
-                var serializationContext = BsonSerializationContext.CreateRoot(this);
-                BsonDocumentSerializer.Instance.Serialize(serializationContext, document);
-            }
-        }
-
-        /// <summary>
-        /// Writes a BSON regular expression to the writer.
-        /// </summary>
-        /// <param name="regex">A BsonRegularExpression.</param>
-        public abstract void WriteRegularExpression(BsonRegularExpression regex);
-
-        /// <summary>
-        /// Writes the start of a BSON array to the writer.
-        /// </summary>
-        public virtual void WriteStartArray()
-        {
-            _serializationDepth++;
-            if (_serializationDepth > _settings.MaxSerializationDepth)
-            {
-                throw new BsonSerializationException("Maximum serialization depth exceeded (does the object being serialized have a circular reference?).");
-            }
-        }
-
-        /// <summary>
-        /// Writes the start of a BSON document to the writer.
-        /// </summary>
-        public virtual void WriteStartDocument()
-        {
-            _serializationDepth++;
-            if (_serializationDepth > _settings.MaxSerializationDepth)
-            {
-                throw new BsonSerializationException("Maximum serialization depth exceeded (does the object being serialized have a circular reference?).");
-            }
-
-            PushElementNameValidator(_childElementNameValidatorFactory());
-        }
-
-        /// <summary>
-        /// Writes a BSON String to the writer.
-        /// </summary>
-        /// <param name="value">The String value.</param>
-        public abstract void WriteString(string value);
-
-        /// <summary>
-        /// Writes a BSON Symbol to the writer.
-        /// </summary>
-        /// <param name="value">The symbol.</param>
-        public abstract void WriteSymbol(string value);
-
-        /// <summary>
-        /// Writes a BSON timestamp to the writer.
-        /// </summary>
-        /// <param name="value">The combined timestamp/increment value.</param>
-        public abstract void WriteTimestamp(long value);
-
-        /// <summary>
-        /// Writes a BSON undefined to the writer.
-        /// </summary>
-        public abstract void WriteUndefined();
-
-        // protected methods
-        /// <summary>
-        /// Disposes of any resources used by the writer.
-        /// </summary>
-        /// <param name="disposing">True if called from Dispose.</param>
-        protected virtual void Dispose(bool disposing)
-        {
-        }
-
-        /// <summary>
-        /// Throws an InvalidOperationException when the method called is not valid for the current ContextType.
-        /// </summary>
-        /// <param name="methodName">The name of the method.</param>
-        /// <param name="actualContextType">The actual ContextType.</param>
-        /// <param name="validContextTypes">The valid ContextTypes.</param>
-        protected void ThrowInvalidContextType(
-            string methodName,
-            ContextType actualContextType,
-            params ContextType[] validContextTypes)
-        {
-            var validContextTypesString = string.Join(" or ", validContextTypes.Select(c => c.ToString()).ToArray());
-            var message = string.Format(
-                "{0} can only be called when ContextType is {1}, not when ContextType is {2}.",
-                methodName, validContextTypesString, actualContextType);
-            throw new InvalidOperationException(message);
-        }
-
-        /// <summary>
-        /// Throws an InvalidOperationException when the method called is not valid for the current state.
-        /// </summary>
-        /// <param name="methodName">The name of the method.</param>
-        /// <param name="validStates">The valid states.</param>
-        protected void ThrowInvalidState(string methodName, params BsonWriterState[] validStates)
-        {
-            string message;
-            if (_state == BsonWriterState.Initial || _state == BsonWriterState.ScopeDocument || _state == BsonWriterState.Done)
-            {
-                if (!methodName.StartsWith("End", StringComparison.Ordinal) && methodName != "WriteName")
-                {
-                    var typeName = methodName.Substring(5);
-                    if (typeName.StartsWith("Start", StringComparison.Ordinal))
-                    {
-                        typeName = typeName.Substring(5);
-                    }
-                    var article = "A";
-                    if (new char[] { 'A', 'E', 'I', 'O', 'U' }.Contains(typeName[0]))
-                    {
-                        article = "An";
-                    }
-                    message = string.Format(
-                        "{0} {1} value cannot be written to the root level of a BSON document.",
-                        article, typeName);
-                    throw new InvalidOperationException(message);
-                }
-            }
-
-            var validStatesString = string.Join(" or ", validStates.Select(s => s.ToString()).ToArray());
-            message = string.Format(
-                "{0} can only be called when State is {1}, not when State is {2}",
-                methodName, validStatesString, _state);
-            throw new InvalidOperationException(message);
-        }
-    }
-}

+ 0 - 137
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonWriterSettings.cs

@@ -1,137 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents settings for a BsonWriter.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public abstract class BsonWriterSettings
-    {
-        // private fields
-        private GuidRepresentation _guidRepresentation = BsonDefaults.GuidRepresentation;
-        private bool _isFrozen;
-        private int _maxSerializationDepth = BsonDefaults.MaxSerializationDepth;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonWriterSettings class.
-        /// </summary>
-        protected BsonWriterSettings()
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonWriterSettings class.
-        /// </summary>
-        /// <param name="guidRepresentation">The representation for Guids.</param>
-        protected BsonWriterSettings(GuidRepresentation guidRepresentation)
-        {
-            _guidRepresentation = guidRepresentation;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets or sets the representation for Guids.
-        /// </summary>
-        public GuidRepresentation GuidRepresentation
-        {
-            get { return _guidRepresentation; }
-            set
-            {
-                if (_isFrozen) { ThrowFrozenException(); }
-                _guidRepresentation = value;
-            }
-        }
-
-        /// <summary>
-        /// Gets whether the settings are frozen.
-        /// </summary>
-        public bool IsFrozen
-        {
-            get { return _isFrozen; }
-        }
-
-        /// <summary>
-        /// Gets or sets the max serialization depth allowed (used to detect circular references).
-        /// </summary>
-        public int MaxSerializationDepth
-        {
-            get { return _maxSerializationDepth; }
-            set
-            {
-                if (_isFrozen) { ThrowFrozenException(); }
-                _maxSerializationDepth = value;
-            }
-        }
-
-        // public methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        public BsonWriterSettings Clone()
-        {
-            return CloneImplementation();
-        }
-
-        /// <summary>
-        /// Freezes the settings.
-        /// </summary>
-        /// <returns>The frozen settings.</returns>
-        public BsonWriterSettings Freeze()
-        {
-            _isFrozen = true;
-            return this;
-        }
-
-        /// <summary>
-        /// Returns a frozen copy of the settings.
-        /// </summary>
-        /// <returns>A frozen copy of the settings.</returns>
-        public BsonWriterSettings FrozenCopy()
-        {
-            if (_isFrozen)
-            {
-                return this;
-            }
-            else
-            {
-                return Clone().Freeze();
-            }
-        }
-
-        // protected methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        protected abstract BsonWriterSettings CloneImplementation();
-
-        /// <summary>
-        /// Throws an InvalidOperationException when an attempt is made to change a setting after the settings are frozen.
-        /// </summary>
-        protected void ThrowFrozenException()
-        {
-            var message = string.Format("{0} is frozen.", this.GetType().Name);
-            throw new InvalidOperationException(message);
-        }
-    }
-}

+ 0 - 48
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/BsonWriterState.cs

@@ -1,48 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents the state of a BsonWriter.
-    /// </summary>
-    public enum BsonWriterState
-    {
-        /// <summary>
-        /// The initial state.
-        /// </summary>
-        Initial,
-        /// <summary>
-        /// The writer is positioned to write a name.
-        /// </summary>
-        Name,
-        /// <summary>
-        /// The writer is positioned to write a value.
-        /// </summary>
-        Value,
-        /// <summary>
-        /// The writer is positioned to write a scope document (call WriteStartDocument to start writing the scope document).
-        /// </summary>
-        ScopeDocument,
-        /// <summary>
-        /// The writer is done.
-        /// </summary>
-        Done,
-        /// <summary>
-        /// The writer is closed.
-        /// </summary>
-        Closed
-    }
-}

+ 0 - 294
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ByteArrayBuffer.cs

@@ -1,294 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// An IByteBuffer that is backed by a contiguous byte array.
-    /// </summary>
-    public sealed class ByteArrayBuffer : IByteBuffer
-    {
-        // private fields
-        private byte[] _bytes;
-        private bool _disposed;
-        private bool _isReadOnly;
-        private int _length;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="ByteArrayBuffer"/> class.
-        /// </summary>
-        /// <param name="bytes">The bytes.</param>
-        /// <param name="isReadOnly">Whether the buffer is read only.</param>
-        public ByteArrayBuffer(byte[] bytes, bool isReadOnly = false)
-            : this(bytes, bytes == null ? 0 : bytes.Length, isReadOnly)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="ByteArrayBuffer"/> class.
-        /// </summary>
-        /// <param name="bytes">The bytes.</param>
-        /// <param name="length">The length.</param>
-        /// <param name="isReadOnly">Whether the buffer is read only.</param>
-        public ByteArrayBuffer(byte[] bytes, int length, bool isReadOnly = false)
-        {
-            if (bytes == null)
-            {
-                throw new ArgumentNullException("bytes");
-            }
-            if (length < 0 || length > bytes.Length)
-            {
-                throw new ArgumentOutOfRangeException("length");
-            }
-
-            _length = length;
-            _bytes = bytes;
-            _isReadOnly = isReadOnly;
-        }
-
-        // public properties
-        /// <inheritdoc/>
-        public int Capacity
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _isReadOnly ? _length : _bytes.Length;
-            }
-        }
-
-        /// <inheritdoc/>
-        public bool IsReadOnly
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _isReadOnly;
-            }
-        }
-
-        /// <inheritdoc/>
-        public int Length
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _length;
-            }
-            set
-            {
-                ThrowIfDisposed();
-                if (value < 0 || value > _bytes.Length)
-                {
-                    throw new ArgumentOutOfRangeException("value");
-                }
-                EnsureIsWritable();
-
-                _length = value;
-            }
-        }
-
-        // public methods
-        /// <inheritdoc/>
-        public ArraySegment<byte> AccessBackingBytes(int position)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-
-            return new ArraySegment<byte>(_bytes, position, _length - position);
-        }
-
-        /// <inheritdoc/>
-        public void Clear(int position, int count)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            if (count < 0 || position + count > _length)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-            EnsureIsWritable();
-
-            Array.Clear(_bytes, position, count);
-        }
-
-        /// <inheritdoc/>
-        public void Dispose()
-        {
-            _disposed = true;
-            GC.SuppressFinalize(this);
-        }
-
-        /// <inheritdoc/>
-        public void EnsureCapacity(int minimumCapacity)
-        {
-            if (minimumCapacity < 0)
-            {
-                throw new ArgumentOutOfRangeException("minimumCapacity");
-            }
-            ThrowIfDisposed();
-            EnsureIsWritable();
-
-            if (minimumCapacity > _bytes.Length)
-            {
-                var powerOf2 = Math.Max(32, PowerOf2.RoundUpToPowerOf2(minimumCapacity));
-                SetCapacity(powerOf2);
-            }
-        }
-
-        /// <inheritdoc/>
-        public byte GetByte(int position)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-
-            return _bytes[position];
-        }
-
-        /// <inheritdoc/>
-        public void GetBytes(int position, byte[] destination, int offset, int count)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            if (destination == null)
-            {
-                throw new ArgumentNullException("destination");
-            }
-            if (offset < 0 || offset > destination.Length)
-            {
-                throw new ArgumentOutOfRangeException("offset");
-            }
-            if (count < 0 || position + count > _length || offset + count > destination.Length)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-
-            Buffer.BlockCopy(_bytes, position, destination, offset, count);
-        }
-
-        /// <inheritdoc/>
-        public IByteBuffer GetSlice(int position, int length)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            if (length < 0 || position + length > _length)
-            {
-                throw new ArgumentOutOfRangeException("length");
-            }
-            EnsureIsReadOnly();
-
-            var forkedBuffer = new ByteArrayBuffer(_bytes, _length, isReadOnly: true);
-            return new ByteBufferSlice(forkedBuffer, position, length);
-        }
-
-        /// <inheritdoc/>
-        public void MakeReadOnly()
-        {
-            ThrowIfDisposed();
-            _isReadOnly = true;
-        }
-
-        /// <inheritdoc/>
-        public void SetByte(int position, byte value)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            EnsureIsWritable();
-
-            _bytes[position] = value;
-        }
-
-        /// <inheritdoc/>
-        public void SetBytes(int position, byte[] source, int offset, int count)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            if (source == null)
-            {
-                throw new ArgumentNullException("source");
-            }
-            if (offset < 0 || offset > source.Length)
-            {
-                throw new ArgumentOutOfRangeException("offset");
-            }
-            if (count < 0 || position + count > _length || offset + count > source.Length)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-            EnsureIsWritable();
-
-            Buffer.BlockCopy(source, offset, _bytes, position, count);
-        }
-
-        // private methods
-        private void EnsureIsReadOnly()
-        {
-            if (!_isReadOnly)
-            {
-                var message = string.Format("{0} is not read only.", GetType().Name);
-                throw new InvalidOperationException(message);
-            }
-        }
-
-        private void EnsureIsWritable()
-        {
-            if (_isReadOnly)
-            {
-                var message = string.Format("{0} is not writable.", GetType().Name);
-                throw new InvalidOperationException(message);
-            }
-        }
-
-        private void SetCapacity(int capacity)
-        {
-            var oldBytes = _bytes;
-            _bytes = new byte[capacity];
-            var bytesToCopy = capacity < oldBytes.Length ? capacity : oldBytes.Length;
-            Buffer.BlockCopy(oldBytes, 0, _bytes, 0, bytesToCopy);
-        }
-
-        private void ThrowIfDisposed()
-        {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException(GetType().Name);
-            }
-        }
-    }
-}

+ 0 - 111
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ByteArrayChunk.cs

@@ -1,111 +0,0 @@
-/* Copyright 2013-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a chunk backed by a byte array.
-    /// </summary>
-    public class ByteArrayChunk : IBsonChunk
-    {
-        #region static
-        private static byte[] CreateByteArray(int size)
-        {
-            if (size < 0)
-            {
-                throw new ArgumentOutOfRangeException("size");
-            }
-            return new byte[size];
-        }
-        #endregion
-
-        // fields
-        private byte[] _bytes;
-        private bool _disposed;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="ByteArrayChunk"/> class.
-        /// </summary>
-        /// <param name="size">The size.</param>
-        public ByteArrayChunk(int size)
-            : this(CreateByteArray(size))
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="ByteArrayChunk"/> class.
-        /// </summary>
-        /// <param name="bytes">The bytes.</param>
-        /// <exception cref="System.ArgumentNullException">bytes</exception>
-        public ByteArrayChunk(byte[] bytes)
-        {
-            if (bytes == null)
-            {
-                throw new ArgumentNullException("bytes");
-            }
-            _bytes = bytes;
-        }
-
-        // properties
-        /// <inheritdoc/>
-        public ArraySegment<byte> Bytes
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return new ArraySegment<byte>(_bytes);
-            }
-        }
-
-        // methods
-        /// <inheritdoc/>
-        public void Dispose()
-        {
-            Dispose(true);
-            GC.SuppressFinalize(this);
-        }
-
-        /// <inheritdoc/>
-        public IBsonChunk Fork()
-        {
-            ThrowIfDisposed();
-            return new ByteArrayChunk(_bytes);
-        }
-
-        /// <summary>
-        /// Releases unmanaged and - optionally - managed resources.
-        /// </summary>
-        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
-        protected virtual void Dispose(bool disposing)
-        {
-            if (disposing)
-            {
-                _bytes = null;
-            }
-            _disposed = true;
-        }
-
-        private void ThrowIfDisposed()
-        {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException(GetType().Name);
-            }
-        }
-    }
-}

+ 0 - 75
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ByteBufferFactory.cs

@@ -1,75 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a factory for IBsonBuffers.
-    /// </summary>
-    public static class ByteBufferFactory
-    {
-        /// <summary>
-        /// Creates a buffer of the specified length. Depending on the length, either a SingleChunkBuffer or a MultiChunkBuffer will be created.
-        /// </summary>
-        /// <param name="chunkSource">The chunk pool.</param>
-        /// <param name="minimumCapacity">The minimum capacity.</param>
-        /// <returns>A buffer with at least the minimum capacity.</returns>
-        public static IByteBuffer Create(IBsonChunkSource chunkSource, int minimumCapacity)
-        {
-            if (chunkSource == null)
-            {
-                throw new ArgumentNullException("chunkSource");
-            }
-            if (minimumCapacity <= 0)
-            {
-                throw new ArgumentOutOfRangeException("minimumCapacity");
-            }
-
-            var capacity = 0;
-            var chunks = new List<IBsonChunk>();
-            while (capacity < minimumCapacity)
-            {
-                var chunk = chunkSource.GetChunk(minimumCapacity - capacity);
-                chunks.Add(chunk);
-                capacity += chunk.Bytes.Count;
-            }
-
-            if (chunks.Count == 1)
-            {
-                var chunk = chunks[0];
-
-                ByteArrayChunk byteArrayChunk;
-                if ((byteArrayChunk = chunk as ByteArrayChunk) != null)
-                {
-                    var segment = byteArrayChunk.Bytes;
-                    if (segment.Offset == 0)
-                    {
-                        return new ByteArrayBuffer(segment.Array, segment.Count, isReadOnly: false);
-                    }
-                }
-
-                return new SingleChunkBuffer(chunk, 0, isReadOnly: false);
-            }
-            else
-            {
-                return new MultiChunkBuffer(chunks, 0, isReadOnly: false);
-            }
-        }
-    }
-}

+ 0 - 235
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ByteBufferSlice.cs

@@ -1,235 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a slice of a byte buffer.
-    /// </summary>
-    public class ByteBufferSlice : IByteBuffer
-    {
-        private readonly IByteBuffer _buffer;
-        private bool _disposed;
-        private readonly int _length;
-        private readonly int _offset;
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="ByteBufferSlice"/> class.
-        /// </summary>
-        /// <param name="buffer">The byte buffer.</param>
-        /// <param name="offset">The offset of the slice.</param>
-        /// <param name="length">The length of the slice.</param>
-        public ByteBufferSlice(IByteBuffer buffer, int offset, int length)
-        {
-            if (buffer == null)
-            {
-                throw new ArgumentNullException("buffer");
-            }
-            if (!buffer.IsReadOnly)
-            {
-                throw new ArgumentException("The buffer is not read only.", "buffer");
-            }
-            if (offset < 0 || offset > buffer.Length)
-            {
-                throw new ArgumentOutOfRangeException("offset");
-            }
-            if (length < 0 || offset + length > buffer.Length)
-            {
-                throw new ArgumentOutOfRangeException("length");
-            }
-
-            _buffer = buffer;
-            _offset = offset;
-            _length = length;
-        }
-
-        /// <summary>
-        /// Gets the buffer.
-        /// </summary>
-        /// <value>
-        /// The buffer.
-        /// </value>
-        public IByteBuffer Buffer
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _buffer;
-            }
-        }
-
-        /// <inheritdoc/>
-        public int Capacity
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _length;
-            }
-        }
-
-        /// <inheritdoc/>
-        public bool IsReadOnly
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return true;
-            }
-        }
-
-        /// <inheritdoc/>
-        public int Length
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _length;
-            }
-            set
-            {
-                throw new NotSupportedException();
-            }
-        }
-
-        /// <inheritdoc/>
-        public ArraySegment<byte> AccessBackingBytes(int position)
-        {
-            EnsureValidPosition(position);
-            ThrowIfDisposed();
-
-            var segment = _buffer.AccessBackingBytes(position + _offset);
-            var count = Math.Min(segment.Count, _length - position);
-            return new ArraySegment<byte>(segment.Array, segment.Offset, count);
-        }
-
-        /// <inheritdoc/>
-        public void Clear(int position, int count)
-        {
-            EnsureValidPositionAndCount(position, count);
-            ThrowIfDisposed();
-
-            _buffer.Clear(position + _offset, count);
-        }
-
-        /// <inheritdoc/>
-        public void Dispose()
-        {
-            Dispose(true);
-            GC.SuppressFinalize(this);
-        }
-
-        /// <inheritdoc/>
-        public void EnsureCapacity(int minimumCapacity)
-        {
-            throw new NotSupportedException();
-        }
-
-        /// <inheritdoc/>
-        public byte GetByte(int position)
-        {
-            EnsureValidPosition(position);
-            ThrowIfDisposed();
-
-            return _buffer.GetByte(position + _offset);
-        }
-
-        /// <inheritdoc/>
-        public void GetBytes(int position, byte[] destination, int offset, int count)
-        {
-            EnsureValidPositionAndCount(position, count);
-            ThrowIfDisposed();
-
-            _buffer.GetBytes(position + _offset, destination, offset, count);
-        }
-
-        /// <inheritdoc/>
-        public IByteBuffer GetSlice(int position, int length)
-        {
-            EnsureValidPositionAndLength(position, length);
-            ThrowIfDisposed();
-
-            return _buffer.GetSlice(position + _offset, length);
-        }
-
-        /// <inheritdoc/>
-        public void MakeReadOnly()
-        {
-            ThrowIfDisposed();
-        }
-
-        /// <inheritdoc/>
-        public void SetByte(int position, byte value)
-        {
-            throw new NotSupportedException();
-        }
-
-        /// <inheritdoc/>
-        public void SetBytes(int position, byte[] source, int offset, int count)
-        {
-            throw new NotSupportedException();
-        }
-
-        /// <summary>
-        /// Releases unmanaged and - optionally - managed resources.
-        /// </summary>
-        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
-        protected virtual void Dispose(bool disposing)
-        {
-            if (disposing && !_disposed)
-            {
-                _buffer.Dispose();
-            }
-            _disposed = true;
-        }
-
-        private void EnsureValidPosition(int position)
-        {
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-        }
-
-        private void EnsureValidPositionAndCount(int position, int count)
-        {
-            EnsureValidPosition(position);
-            if (count < 0 || position + count > _length)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-        }
-
-        private void EnsureValidPositionAndLength(int position, int length)
-        {
-            EnsureValidPosition(position);
-            if (length < 0 || position + length > _length)
-            {
-                throw new ArgumentOutOfRangeException("length");
-            }
-        }
-
-        private void ThrowIfDisposed()
-        {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException(GetType().Name);
-            }
-        }
-    }
-}

+ 0 - 727
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ByteBufferStream.cs

@@ -1,727 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-using System.Text;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a Stream backed by an IByteBuffer. Similar to MemoryStream but backed by an IByteBuffer
-    /// instead of a byte array and also implements the BsonStream interface for higher performance BSON I/O.
-    /// </summary>
-    public class ByteBufferStream : BsonStream
-    {
-        // private fields
-        private IByteBuffer _buffer;
-        private bool _disposed;
-        private int _length;
-        private readonly bool _ownsBuffer;
-        private int _position;
-        private readonly byte[] _temp = new byte[12];
-        private readonly byte[] _tempUtf8 = new byte[128];
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="ByteBufferStream"/> class.
-        /// </summary>
-        /// <param name="buffer">The buffer.</param>
-        /// <param name="ownsBuffer">Whether the stream owns the buffer and should Dispose it when done.</param>
-        public ByteBufferStream(IByteBuffer buffer, bool ownsBuffer = false)
-        {
-            if (buffer == null)
-            {
-                throw new ArgumentNullException("buffer");
-            }
-
-            _buffer = buffer;
-            _ownsBuffer = ownsBuffer;
-            _length = buffer.Length;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the buffer.
-        /// </summary>
-        /// <value>
-        /// The buffer.
-        /// </value>
-        public IByteBuffer Buffer
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _buffer;
-            }
-        }
-
-        /// <inheritdoc/>
-        public override bool CanRead
-        {
-            get { return !_disposed; }
-        }
-
-        /// <inheritdoc/>
-        public override bool CanSeek
-        {
-            get { return !_disposed; }
-        }
-
-        /// <inheritdoc/>
-        public override bool CanTimeout
-        {
-            get { return false; }
-        }
-
-        /// <inheritdoc/>
-        public override bool CanWrite
-        {
-            get { return !_disposed && !_buffer.IsReadOnly; }
-        }
-
-        /// <inheritdoc/>
-        public override long Length
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _length;
-            }
-        }
-
-        /// <inheritdoc/>
-        public override long Position
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _position;
-            }
-            set
-            {
-                if (value < 0 || value > int.MaxValue)
-                {
-                    throw new ArgumentOutOfRangeException("value");
-                }
-                ThrowIfDisposed();
-                _position = (int)value;
-            }
-        }
-
-        // public methods
-        /// <inheritdoc/>
-        public override void Flush()
-        {
-            ThrowIfDisposed();
-            // do nothing
-        }
-
-        /// <inheritdoc/>
-        public override int Read(byte[] buffer, int offset, int count)
-        {
-            if (buffer == null)
-            {
-                throw new ArgumentNullException("buffer");
-            }
-            if (offset < 0 || offset > buffer.Length)
-            {
-                throw new ArgumentOutOfRangeException("offset");
-            }
-            if (count < 0 || offset + count > buffer.Length)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-            ThrowIfDisposed();
-
-            if (_position >= _length)
-            {
-                return 0;
-            }
-
-            var available = _length - _position;
-            if (count > available)
-            {
-                count = available;
-            }
-
-            _buffer.GetBytes(_position, buffer, offset, count);
-            _position += count;
-
-            return count;
-        }
-
-        /// <inheritdoc/>
-        public override int ReadByte()
-        {
-            ThrowIfDisposed();
-            if (_position >= _length)
-            {
-                return -1;
-            }
-            return _buffer.GetByte(_position++);
-        }
-
-        /// <inheritdoc/>
-        public override long Seek(long offset, SeekOrigin origin)
-        {
-            ThrowIfDisposed();
-
-            long position;
-            switch (origin)
-            {
-                case SeekOrigin.Begin: position = offset; break;
-                case SeekOrigin.Current: position = _position + offset; break;
-                case SeekOrigin.End: position = _length + offset; break;
-                default: throw new ArgumentException("Invalid origin.", "origin");
-            }
-            if (position < 0)
-            {
-                throw new IOException("Attempted to seek before the beginning of the stream.");
-            }
-            if (position > int.MaxValue)
-            {
-                throw new IOException("Attempted to seek beyond the maximum value that can be represented using 32 bits.");
-            }
-
-            _position = (int)position;
-            return position;
-        }
-
-        /// <inheritdoc/>
-        public override void SetLength(long value)
-        {
-            if (value < 0 || value > int.MaxValue)
-            {
-                throw new ArgumentOutOfRangeException("value");
-            }
-            ThrowIfDisposed();
-            EnsureWriteable();
-
-            _buffer.EnsureCapacity((int)value);
-            _length = (int)value;
-            if (_position > _length)
-            {
-                _position = _length;
-            }
-        }
-
-        /// <inheritdoc/>
-        public override void Write(byte[] buffer, int offset, int count)
-        {
-            if (buffer == null)
-            {
-                throw new ArgumentNullException("buffer");
-            }
-            if (offset < 0 || offset > buffer.Length)
-            {
-                throw new ArgumentOutOfRangeException("offset");
-            }
-            if (count < 0 || offset + count > buffer.Length)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-            ThrowIfDisposed();
-            EnsureWriteable();
-
-            PrepareToWrite(count);
-            _buffer.SetBytes(_position, buffer, offset, count);
-            SetPositionAfterWrite(_position + count);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteByte(byte value)
-        {
-            ThrowIfDisposed();
-            PrepareToWrite(1);
-            _buffer.SetByte(_position, value);
-            SetPositionAfterWrite(_position + 1);
-        }
-
-        // protected methods
-        /// <inheritdoc/>
-        protected override void Dispose(bool disposing)
-        {
-            if (!_disposed)
-            {
-                if (_ownsBuffer)
-                {
-                    _buffer.Dispose();
-                }
-                _disposed = true;
-            }
-            base.Dispose(disposing);
-        }
-
-        // private methods
-        private void EnsureWriteable()
-        {
-            if (!CanWrite)
-            {
-                throw new NotSupportedException("Stream is not writeable.");
-            }
-        }
-
-        private int FindNullByte()
-        {
-            var position = _position;
-            while (position < _length)
-            {
-                var segment = _buffer.AccessBackingBytes(position);
-                var endOfSegmentIndex = segment.Offset + segment.Count;
-                for (var index = segment.Offset; index < endOfSegmentIndex; index++)
-                {
-                    if (segment.Array[index] == 0)
-                    {
-                        return position + (index - segment.Offset);
-                    }
-                }
-                position += segment.Count;
-            }
-
-            throw new EndOfStreamException();
-        }
-
-        private void PrepareToWrite(int count)
-        {
-            var minimumCapacity = (long)_position + (long)count;
-            if (minimumCapacity > int.MaxValue)
-            {
-                throw new IOException("Stream was too long.");
-            }
-
-            _buffer.EnsureCapacity((int)minimumCapacity);
-            _buffer.Length = _buffer.Capacity;
-            if (_length < _position)
-            {
-                _buffer.Clear(_length, _position - _length);
-            }
-        }
-
-        private byte[] ReadBytes(int count)
-        {
-            ThrowIfEndOfStream(count);
-            var bytes = new byte[count];
-            _buffer.GetBytes(_position, bytes, 0, count);
-            _position += count;
-            return bytes;
-        }
-
-        private void SetPositionAfterWrite(int position)
-        {
-            _position = position;
-            if (_length < position)
-            {
-                _length = position;
-            }
-        }
-
-        private void ThrowIfDisposed()
-        {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException("ByteBufferStream");
-            }
-        }
-
-        private void ThrowIfEndOfStream(int count)
-        {
-            var minimumLength = (long)_position + (long)count;
-            if (_length < minimumLength)
-            {
-                if (_position < _length)
-                {
-                    _position = _length;
-                }
-                throw new EndOfStreamException();
-            }
-        }
-
-        /// <inheritdoc/>
-        public override string ReadCString(UTF8Encoding encoding)
-        {
-            if (encoding == null)
-            {
-                throw new ArgumentNullException("encoding");
-            }
-            ThrowIfDisposed();
-
-            var bytes = ReadCStringBytes();
-            return Utf8Helper.DecodeUtf8String(bytes.Array, bytes.Offset, bytes.Count, encoding);
-        }
-
-        /// <inheritdoc/>
-        public override ArraySegment<byte> ReadCStringBytes()
-        {
-            ThrowIfDisposed();
-            ThrowIfEndOfStream(1);
-
-            var segment = _buffer.AccessBackingBytes(_position);
-            var index = Array.IndexOf<byte>(segment.Array, 0, segment.Offset, segment.Count);
-            if (index != -1)
-            {
-                var length = index - segment.Offset;
-                _position += length + 1; // advance over the null byte
-                return new ArraySegment<byte>(segment.Array, segment.Offset, length); // without the null byte
-            }
-            else
-            {
-                var nullPosition = FindNullByte();
-                var length = nullPosition - _position;
-                var cstring = ReadBytes(length + 1); // advance over the null byte
-                return new ArraySegment<byte>(cstring, 0, length); // without the null byte
-            }
-        }
-
-        /// <inheritdoc/>
-        public override Decimal128 ReadDecimal128()
-        {
-            ThrowIfDisposed();
-            ThrowIfEndOfStream(16);
-
-            var lowBits = (ulong)ReadInt64();
-            var highBits = (ulong)ReadInt64();
-            return Decimal128.FromIEEEBits(highBits, lowBits);
-        }
-
-        /// <inheritdoc/>
-        public override double ReadDouble()
-        {
-            ThrowIfDisposed();
-            ThrowIfEndOfStream(8);
-
-            var segment = _buffer.AccessBackingBytes(_position);
-            if (segment.Count >= 8)
-            {
-                _position += 8;
-                return BitConverter.ToDouble(segment.Array, segment.Offset);
-            }
-            else
-            {
-                this.ReadBytes(_temp, 0, 8);
-                return BitConverter.ToDouble(_temp, 0);
-            }
-        }
-
-        /// <inheritdoc/>
-        public override int ReadInt32()
-        {
-            ThrowIfDisposed();
-            ThrowIfEndOfStream(4);
-
-            var segment = _buffer.AccessBackingBytes(_position);
-            if (segment.Count >= 4)
-            {
-                _position += 4;
-                var bytes = segment.Array;
-                var offset = segment.Offset;
-                return bytes[offset] | (bytes[offset + 1] << 8) | (bytes[offset + 2] << 16) | (bytes[offset + 3] << 24);
-            }
-            else
-            {
-                this.ReadBytes(_temp, 0, 4);
-                return _temp[0] | (_temp[1] << 8) | (_temp[2] << 16) | (_temp[3] << 24);
-            }
-        }
-
-        /// <inheritdoc/>
-        public override long ReadInt64()
-        {
-            ThrowIfDisposed();
-            ThrowIfEndOfStream(8);
-
-            var segment = _buffer.AccessBackingBytes(_position);
-            if (segment.Count >= 8)
-            {
-                _position += 8;
-                return BitConverter.ToInt64(segment.Array, segment.Offset);
-            }
-            else
-            {
-                this.ReadBytes(_temp, 0, 8);
-                return BitConverter.ToInt64(_temp, 0);
-            }
-        }
-
-        /// <inheritdoc/>
-        public override ObjectId ReadObjectId()
-        {
-            ThrowIfDisposed();
-            ThrowIfEndOfStream(12);
-
-            var segment = _buffer.AccessBackingBytes(_position);
-            if (segment.Count >= 12)
-            {
-                _position += 12;
-                return new ObjectId(segment.Array, segment.Offset);
-            }
-            else
-            {
-                this.ReadBytes(_temp, 0, 12);
-                return new ObjectId(_temp, 0);
-            }
-        }
-
-        /// <inheritdoc/>
-        public override IByteBuffer ReadSlice()
-        {
-            ThrowIfDisposed();
-
-            var position = _position;
-            var length = ReadInt32();
-            ThrowIfEndOfStream(length - 4);
-            Position = position + length;
-
-            return _buffer.GetSlice(position, length);
-        }
-
-        /// <inheritdoc/>
-        public override string ReadString(UTF8Encoding encoding)
-        {
-            if (encoding == null)
-            {
-                throw new ArgumentNullException("encoding");
-            }
-            ThrowIfDisposed();
-
-            var length = ReadInt32();
-            if (length <= 0)
-            {
-                var message = string.Format("Invalid string length: {0}.", length);
-                throw new FormatException(message);
-            }
-
-            var segment = _buffer.AccessBackingBytes(_position);
-            if (segment.Count >= length)
-            {
-                ThrowIfEndOfStream(length);
-                if (segment.Array[segment.Offset + length - 1] != 0)
-                {
-                    throw new FormatException("String is missing terminating null byte.");
-                }
-                _position += length;
-                return Utf8Helper.DecodeUtf8String(segment.Array, segment.Offset, length - 1, encoding);
-            }
-            else
-            {
-                var bytes = length <= _tempUtf8.Length ? _tempUtf8 : new byte[length];
-                this.ReadBytes(bytes, 0, length);
-                if (bytes[length - 1] != 0)
-                {
-                    throw new FormatException("String is missing terminating null byte.");
-                }
-                return Utf8Helper.DecodeUtf8String(bytes, 0, length - 1, encoding);
-            }
-        }
-
-        /// <inheritdoc/>
-        public override void SkipCString()
-        {
-            ThrowIfDisposed();
-            var nullPosition = FindNullByte();
-            _position = nullPosition + 1;
-        }
-
-        /// <inheritdoc/>
-        public override void WriteCString(string value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-            ThrowIfDisposed();
-
-            var maxLength = CStringUtf8Encoding.GetMaxByteCount(value.Length) + 1;
-            PrepareToWrite(maxLength);
-
-            int actualLength;
-            var segment = _buffer.AccessBackingBytes(_position);
-            if (segment.Count >= maxLength)
-            {
-                actualLength = CStringUtf8Encoding.GetBytes(value, segment.Array, segment.Offset, Utf8Encodings.Strict);
-                segment.Array[segment.Offset + actualLength] = 0;
-            }
-            else
-            {
-                byte[] bytes;
-                if (maxLength <= _tempUtf8.Length)
-                {
-                    bytes = _tempUtf8;
-                    actualLength = CStringUtf8Encoding.GetBytes(value, bytes, 0, Utf8Encodings.Strict);
-                }
-                else
-                {
-                    bytes = Utf8Encodings.Strict.GetBytes(value);
-                    if (Array.IndexOf<byte>(bytes, 0) != -1)
-                    {
-                        throw new ArgumentException("A CString cannot contain null bytes.", "value");
-                    }
-                    actualLength = bytes.Length;
-                }
-
-                _buffer.SetBytes(_position, bytes, 0, actualLength);
-                _buffer.SetByte(_position + actualLength, 0);
-            }
-
-            SetPositionAfterWrite(_position + actualLength + 1);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteCStringBytes(byte[] value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-            ThrowIfDisposed();
-
-            var length = value.Length;
-
-            PrepareToWrite(length + 1);
-
-            _buffer.SetBytes(_position, value, 0, length);
-            _buffer.SetByte(_position + length, 0);
-
-            SetPositionAfterWrite(_position + length + 1);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteDecimal128(Decimal128 value)
-        {
-            ThrowIfDisposed();
-            WriteInt64((long)value.GetIEEELowBits());
-            WriteInt64((long)value.GetIEEEHighBits());
-        }
-
-        /// <inheritdoc/>
-        public override void WriteDouble(double value)
-        {
-            ThrowIfDisposed();
-
-            PrepareToWrite(8);
-
-            var bytes = BitConverter.GetBytes(value);
-            _buffer.SetBytes(_position, bytes, 0, 8);
-
-            SetPositionAfterWrite(_position + 8);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteInt32(int value)
-        {
-            ThrowIfDisposed();
-
-            PrepareToWrite(4);
-
-            var segment = _buffer.AccessBackingBytes(_position);
-            if (segment.Count >= 4)
-            {
-                segment.Array[segment.Offset] = (byte)value;
-                segment.Array[segment.Offset + 1] = (byte)(value >> 8);
-                segment.Array[segment.Offset + 2] = (byte)(value >> 16);
-                segment.Array[segment.Offset + 3] = (byte)(value >> 24);
-            }
-            else
-            {
-                _temp[0] = (byte)(value);
-                _temp[1] = (byte)(value >> 8);
-                _temp[2] = (byte)(value >> 16);
-                _temp[3] = (byte)(value >> 24);
-                _buffer.SetBytes(_position, _temp, 0, 4);
-            }
-
-            SetPositionAfterWrite(_position + 4);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteInt64(long value)
-        {
-            ThrowIfDisposed();
-
-            PrepareToWrite(8);
-
-            var bytes = BitConverter.GetBytes(value);
-            _buffer.SetBytes(_position, bytes, 0, 8);
-
-            SetPositionAfterWrite(_position + 8);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteObjectId(ObjectId value)
-        {
-            ThrowIfDisposed();
-
-            PrepareToWrite(12);
-
-            var segment = _buffer.AccessBackingBytes(_position);
-            if (segment.Count >= 12)
-            {
-                value.ToByteArray(segment.Array, segment.Offset);
-            }
-            else
-            {
-                var bytes = value.ToByteArray();
-                _buffer.SetBytes(_position, bytes, 0, 12);
-            }
-
-            SetPositionAfterWrite(_position + 12);
-        }
-
-        /// <inheritdoc/>
-        public override void WriteString(string value, UTF8Encoding encoding)
-        {
-            ThrowIfDisposed();
-
-            var maxLength = encoding.GetMaxByteCount(value.Length) + 5;
-            PrepareToWrite(maxLength);
-
-            int actualLength;
-            var segment = _buffer.AccessBackingBytes(_position);
-            if (segment.Count >= maxLength)
-            {
-                actualLength = encoding.GetBytes(value, 0, value.Length, segment.Array, segment.Offset + 4);
-
-                var lengthPlusOne = actualLength + 1;
-                segment.Array[segment.Offset] = (byte)lengthPlusOne;
-                segment.Array[segment.Offset + 1] = (byte)(lengthPlusOne >> 8);
-                segment.Array[segment.Offset + 2] = (byte)(lengthPlusOne >> 16);
-                segment.Array[segment.Offset + 3] = (byte)(lengthPlusOne >> 24);
-                segment.Array[segment.Offset + 4 + actualLength] = 0;
-            }
-            else
-            {
-                byte[] bytes;
-                if (maxLength <= _tempUtf8.Length)
-                {
-                    bytes = _tempUtf8;
-                    actualLength = encoding.GetBytes(value, 0, value.Length, bytes, 0);
-                }
-                else
-                {
-                    bytes = encoding.GetBytes(value);
-                    actualLength = bytes.Length;
-                }
-
-                var lengthPlusOneBytes = BitConverter.GetBytes(actualLength + 1);
-
-                _buffer.SetBytes(_position, lengthPlusOneBytes, 0, 4);
-                _buffer.SetBytes(_position + 4, bytes, 0, actualLength);
-                _buffer.SetByte(_position + 4 + actualLength, 0);
-            }
-
-            SetPositionAfterWrite(_position + actualLength + 5);
-        }
-    }
-}

+ 0 - 76
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/CStringUtf8Encoding.cs

@@ -1,76 +0,0 @@
-/* Copyright 2016-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-using System.Text;
-
-namespace MongoDB.Bson.IO
-{
-    internal static class CStringUtf8Encoding
-    {
-        public static int GetBytes(string value, byte[] bytes, int byteIndex, UTF8Encoding fallbackEncoding)
-        {
-            var charLength = value.Length;
-            var initialByteIndex = byteIndex;
-
-            for (var charIndex = 0; charIndex < charLength; charIndex++)
-            {
-                var c = (int)value[charIndex];
-                if (c == 0)
-                {
-                    throw new ArgumentException("A CString cannot contain null bytes.", "value");
-                }
-                else if (c <= 0x7f)
-                {
-                    bytes[byteIndex++] = (byte)c;
-                }
-                else if (c <= 0x7ff)
-                {
-                    var byte1 = 0xc0 | (c >> 6);
-                    var byte2 = 0x80 | (c & 0x3f);
-                    bytes[byteIndex++] = (byte)byte1;
-                    bytes[byteIndex++] = (byte)byte2;
-                }
-                else if (c <= 0xd7ff || c >= 0xe000)
-                {
-                    var byte1 = 0xe0 | (c >> 12);
-                    var byte2 = 0x80 | ((c >> 6) & 0x3f);
-                    var byte3 = 0x80 | (c & 0x3f);
-                    bytes[byteIndex++] = (byte)byte1;
-                    bytes[byteIndex++] = (byte)byte2;
-                    bytes[byteIndex++] = (byte)byte3;
-                }
-                else
-                {
-                    // let fallback encoding handle surrogate pairs
-                    var bytesWritten = fallbackEncoding.GetBytes(value, 0, value.Length, bytes, byteIndex);
-                    if (Array.IndexOf<byte>(bytes, 0, initialByteIndex, bytesWritten) != -1)
-                    {
-                        throw new ArgumentException("A CString cannot contain null bytes.", "value");
-                    }
-                    return bytesWritten;
-                }
-            }
-
-            return byteIndex - initialByteIndex;
-        }
-
-        public static int GetMaxByteCount(int charCount)
-        {
-            return charCount * 3;
-        }
-    }
-}

+ 0 - 44
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ContextType.cs

@@ -1,44 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Used by BsonReaders and BsonWriters to represent the current context.
-    /// </summary>
-    public enum ContextType
-    {
-        /// <summary>
-        /// The top level of a BSON document.
-        /// </summary>
-        TopLevel,
-        /// <summary>
-        /// A (possibly embedded) BSON document.
-        /// </summary>
-        Document,
-        /// <summary>
-        /// A BSON array.
-        /// </summary>
-        Array,
-        /// <summary>
-        /// A JavaScriptWithScope BSON value.
-        /// </summary>
-        JavaScriptWithScope,
-        /// <summary>
-        /// The scope document of a JavaScriptWithScope BSON value.
-        /// </summary>
-        ScopeDocument
-    }
-}

+ 0 - 84
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/ElementAppendingBsonWriter.cs

@@ -1,84 +0,0 @@
-/* Copyright 2017-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using MongoDB.Bson.Serialization;
-using MongoDB.Bson.Serialization.Serializers;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// A BsonWriter that appends elements to the end of a document.
-    /// </summary>
-    /// <seealso cref="MongoDB.Bson.IO.IBsonWriter" />
-    internal sealed class ElementAppendingBsonWriter : WrappingBsonWriter
-    {
-        // private fields
-        private int _depth;
-        private readonly List<BsonElement> _elements;
-        private readonly Action<BsonWriterSettings> _settingsConfigurator;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="ElementAppendingBsonWriter" /> class.
-        /// </summary>
-        /// <param name="wrapped">The wrapped writer.</param>
-        /// <param name="elements">The elements to append.</param>
-        /// <param name="settingsConfigurator">The settings configurator.</param>
-        public ElementAppendingBsonWriter(
-            IBsonWriter wrapped,
-            IEnumerable<BsonElement> elements,
-            Action<BsonWriterSettings> settingsConfigurator)
-            : base(wrapped)
-        {
-            if (elements == null) { throw new ArgumentNullException(nameof(elements)); }
-            _elements = elements.ToList();
-            _settingsConfigurator = settingsConfigurator ?? (s => { });
-        }
-
-        // public methods
-        /// <inheritdoc />
-        public override void WriteEndDocument()
-        {
-            if (--_depth == 0)
-            {
-                Wrapped.PushSettings(_settingsConfigurator);
-                try
-                {
-                    var context = BsonSerializationContext.CreateRoot(Wrapped);
-                    foreach (var element in _elements)
-                    {
-                        Wrapped.WriteName(element.Name);
-                        BsonValueSerializer.Instance.Serialize(context, element.Value);
-                    }
-                }
-                finally
-                {
-                    Wrapped.PopSettings();
-                }
-            }
-            base.WriteEndDocument();
-        }
-
-        /// <inheritdoc />
-        public override void WriteStartDocument()
-        {
-            _depth++;
-            base.WriteStartDocument();
-        }
-    }
-}

+ 0 - 39
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IBsonChunk.cs

@@ -1,39 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a chunk of bytes.
-    /// </summary>
-    public interface IBsonChunk : IDisposable
-    {
-        /// <summary>
-        /// Gets the bytes.
-        /// </summary>
-        /// <value>
-        /// The bytes.
-        /// </value>
-        ArraySegment<byte> Bytes { get; }
-
-        /// <summary>
-        /// Returns a new reference to the same chunk that can be independently disposed.
-        /// </summary>
-        /// <returns>A new reference to the same chunk.</returns>
-        IBsonChunk Fork();
-    }
-}

+ 0 - 33
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IBsonChunkSource.cs

@@ -1,33 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a source of chunks.
-    /// </summary>
-    public interface IBsonChunkSource : IDisposable
-    {
-        /// <summary>
-        /// Gets the chunk.
-        /// </summary>
-        /// <remarks>The chunk source is free to return a larger or smaller chunk than requested.</remarks>
-        /// <param name="requestedSize">Size of the requested.</param>
-        /// <returns>A chunk.</returns>
-        IBsonChunk GetChunk(int requestedSize);
-    }
-}

+ 0 - 235
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IBsonReader.cs

@@ -1,235 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a BSON reader.
-    /// </summary>
-    public interface IBsonReader : IDisposable
-    {
-        // properties
-        /// <summary>
-        /// Gets the current BsonType.
-        /// </summary>
-        BsonType CurrentBsonType { get; }
-
-        /// <summary>
-        /// Gets the current state of the reader.
-        /// </summary>
-        BsonReaderState State { get; }
-
-        // methods
-        /// <summary>
-        /// Closes the reader.
-        /// </summary>
-        void Close();
-
-        /// <summary>
-        /// Gets a bookmark to the reader's current position and state.
-        /// </summary>
-        /// <returns>A bookmark.</returns>
-        BsonReaderBookmark GetBookmark();
-
-        /// <summary>
-        /// Gets the current BsonType (calls ReadBsonType if necessary).
-        /// </summary>
-        /// <returns>The current BsonType.</returns>
-        BsonType GetCurrentBsonType();
-
-        /// <summary>
-        /// Determines whether this reader is at end of file.
-        /// </summary>
-        /// <returns>
-        /// Whether this reader is at end of file.
-        /// </returns>
-        bool IsAtEndOfFile();
-
-        /// <summary>
-        /// Reads BSON binary data from the reader.
-        /// </summary>
-        /// <returns>A BsonBinaryData.</returns>
-        BsonBinaryData ReadBinaryData();
-
-        /// <summary>
-        /// Reads a BSON boolean from the reader.
-        /// </summary>
-        /// <returns>A Boolean.</returns>
-        bool ReadBoolean();
-
-        /// <summary>
-        /// Reads a BsonType from the reader.
-        /// </summary>
-        /// <returns>A BsonType.</returns>
-        BsonType ReadBsonType();
-
-        /// <summary>
-        /// Reads BSON binary data from the reader.
-        /// </summary>
-        /// <returns>A byte array.</returns>
-        byte[] ReadBytes();
-
-        /// <summary>
-        /// Reads a BSON DateTime from the reader.
-        /// </summary>
-        /// <returns>The number of milliseconds since the Unix epoch.</returns>
-        long ReadDateTime();
-
-        /// <summary>
-        /// Reads a BSON Decimal128 from the reader.
-        /// </summary>
-        /// <returns>A <see cref="Decimal128" />.</returns>
-        Decimal128 ReadDecimal128();
-
-        /// <summary>
-        /// Reads a BSON Double from the reader.
-        /// </summary>
-        /// <returns>A Double.</returns>
-        double ReadDouble();
-
-        /// <summary>
-        /// Reads the end of a BSON array from the reader.
-        /// </summary>
-        void ReadEndArray();
-
-        /// <summary>
-        /// Reads the end of a BSON document from the reader.
-        /// </summary>
-        void ReadEndDocument();
-
-        /// <summary>
-        /// Reads a BSON Int32 from the reader.
-        /// </summary>
-        /// <returns>An Int32.</returns>
-        int ReadInt32();
-
-        /// <summary>
-        /// Reads a BSON Int64 from the reader.
-        /// </summary>
-        /// <returns>An Int64.</returns>
-        long ReadInt64();
-
-        /// <summary>
-        /// Reads a BSON JavaScript from the reader.
-        /// </summary>
-        /// <returns>A string.</returns>
-        string ReadJavaScript();
-
-        /// <summary>
-        /// Reads a BSON JavaScript with scope from the reader (call ReadStartDocument next to read the scope).
-        /// </summary>
-        /// <returns>A string.</returns>
-        string ReadJavaScriptWithScope();
-
-        /// <summary>
-        /// Reads a BSON MaxKey from the reader.
-        /// </summary>
-        void ReadMaxKey();
-
-        /// <summary>
-        /// Reads a BSON MinKey from the reader.
-        /// </summary>
-        void ReadMinKey();
-
-        /// <summary>
-        /// Reads the name of an element from the reader (using the provided name decoder).
-        /// </summary>
-        /// <param name="nameDecoder">The name decoder.</param>
-        /// <returns>
-        /// The name of the element.
-        /// </returns>
-        string ReadName(INameDecoder nameDecoder);
-
-        /// <summary>
-        /// Reads a BSON null from the reader.
-        /// </summary>
-        void ReadNull();
-
-        /// <summary>
-        /// Reads a BSON ObjectId from the reader.
-        /// </summary>
-        /// <returns>An ObjectId.</returns>
-        ObjectId ReadObjectId();
-
-        /// <summary>
-        /// Reads a raw BSON array.
-        /// </summary>
-        /// <returns>The raw BSON array.</returns>
-        IByteBuffer ReadRawBsonArray();
-
-        /// <summary>
-        /// Reads a raw BSON document.
-        /// </summary>
-        /// <returns>The raw BSON document.</returns>
-        IByteBuffer ReadRawBsonDocument();
-
-        /// <summary>
-        /// Reads a BSON regular expression from the reader.
-        /// </summary>
-        /// <returns>A BsonRegularExpression.</returns>
-        BsonRegularExpression ReadRegularExpression();
-
-        /// <summary>
-        /// Reads the start of a BSON array.
-        /// </summary>
-        void ReadStartArray();
-
-        /// <summary>
-        /// Reads the start of a BSON document.
-        /// </summary>
-        void ReadStartDocument();
-
-        /// <summary>
-        /// Reads a BSON string from the reader.
-        /// </summary>
-        /// <returns>A String.</returns>
-        string ReadString();
-
-        /// <summary>
-        /// Reads a BSON symbol from the reader.
-        /// </summary>
-        /// <returns>A string.</returns>
-        string ReadSymbol();
-
-        /// <summary>
-        /// Reads a BSON timestamp from the reader.
-        /// </summary>
-        /// <returns>The combined timestamp/increment.</returns>
-        long ReadTimestamp();
-
-        /// <summary>
-        /// Reads a BSON undefined from the reader.
-        /// </summary>
-        void ReadUndefined();
-
-        /// <summary>
-        /// Returns the reader to previously bookmarked position and state.
-        /// </summary>
-        /// <param name="bookmark">The bookmark.</param>
-        void ReturnToBookmark(BsonReaderBookmark bookmark);
-
-        /// <summary>
-        /// Skips the name (reader must be positioned on a name).
-        /// </summary>
-        void SkipName();
-
-        /// <summary>
-        /// Skips the value (reader must be positioned on a value).
-        /// </summary>
-        void SkipValue();
-    }
-}

+ 0 - 361
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IBsonReaderExtensions.cs

@@ -1,361 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Contains extensions methods for IBsonReader.
-    /// </summary>
-    public static class IBsonReaderExtensions
-    {
-        /// <summary>
-        /// Positions the reader to an element by name.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>True if the element was found.</returns>
-        public static bool FindElement(this IBsonReader reader, string name)
-        {
-            while (reader.ReadBsonType() != BsonType.EndOfDocument)
-            {
-                var elementName = reader.ReadName();
-                if (elementName == name)
-                {
-                    return true;
-                }
-                reader.SkipValue();
-            }
-
-            return false;
-        }
-
-        /// <summary>
-        /// Positions the reader to a string element by name.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>True if the element was found.</returns>
-        public static string FindStringElement(this IBsonReader reader, string name)
-        {
-            BsonType bsonType;
-            while ((bsonType = reader.ReadBsonType()) != BsonType.EndOfDocument)
-            {
-                if (bsonType == BsonType.String)
-                {
-                    var elementName = reader.ReadName();
-                    if (elementName == name)
-                    {
-                        return reader.ReadString();
-                    }
-                    else
-                    {
-                        reader.SkipValue();
-                    }
-                }
-                else
-                {
-                    reader.SkipName();
-                    reader.SkipValue();
-                }
-            }
-
-            return null;
-        }
-
-        /// <summary>
-        /// Reads a BSON binary data element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>A BsonBinaryData.</returns>
-        public static BsonBinaryData ReadBinaryData(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadBinaryData();
-        }
-
-        /// <summary>
-        /// Reads a BSON boolean element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>A Boolean.</returns>
-        public static bool ReadBoolean(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadBoolean();
-        }
-
-        /// <summary>
-        /// Reads a BSON binary data element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>A byte array.</returns>
-        public static byte[] ReadBytes(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadBytes();
-        }
-
-        /// <summary>
-        /// Reads a BSON DateTime element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>The number of milliseconds since the Unix epoch.</returns>
-        public static long ReadDateTime(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadDateTime();
-        }
-
-        /// <summary>
-        /// Reads a BSON Decimal128 element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>A <see cref="Decimal128"/>.</returns>
-        public static Decimal128 ReadDecimal128(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadDecimal128();
-        }
-
-        /// <summary>
-        /// Reads a BSON Double element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>A Double.</returns>
-        public static double ReadDouble(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadDouble();
-        }
-
-        /// <summary>
-        /// Reads a BSON Int32 element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>An Int32.</returns>
-        public static int ReadInt32(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadInt32();
-        }
-
-        /// <summary>
-        /// Reads a BSON Int64 element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>An Int64.</returns>
-        public static long ReadInt64(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadInt64();
-        }
-
-        /// <summary>
-        /// Reads a BSON JavaScript element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>A string.</returns>
-        public static string ReadJavaScript(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadJavaScript();
-        }
-
-        /// <summary>
-        /// Reads a BSON JavaScript with scope element from the reader (call ReadStartDocument next to read the scope).
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>A string.</returns>
-        public static string ReadJavaScriptWithScope(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadJavaScriptWithScope();
-        }
-
-        /// <summary>
-        /// Reads a BSON MaxKey element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        public static void ReadMaxKey(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            reader.ReadMaxKey();
-        }
-
-        /// <summary>
-        /// Reads a BSON MinKey element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        public static void ReadMinKey(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            reader.ReadMinKey();
-        }
-
-        /// <summary>
-        /// Reads the name of an element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <returns>The name of the element.</returns>
-        public static string ReadName(this IBsonReader reader)
-        {
-            return reader.ReadName(Utf8NameDecoder.Instance);
-        }
-
-        /// <summary>
-        /// Reads the name of an element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        public static void ReadName(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-        }
-
-        /// <summary>
-        /// Reads a BSON null element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        public static void ReadNull(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            reader.ReadNull();
-        }
-
-        /// <summary>
-        /// Reads a BSON ObjectId element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>An ObjectId.</returns>
-        public static ObjectId ReadObjectId(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadObjectId();
-        }
-
-        /// <summary>
-        /// Reads a raw BSON array.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name.</param>
-        /// <returns>
-        /// The raw BSON array.
-        /// </returns>
-        public static IByteBuffer ReadRawBsonArray(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadRawBsonArray();
-        }
-
-        /// <summary>
-        /// Reads a raw BSON document.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name.</param>
-        /// <returns>The raw BSON document.</returns>
-        public static IByteBuffer ReadRawBsonDocument(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadRawBsonDocument();
-        }
-
-        /// <summary>
-        /// Reads a BSON regular expression element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>A BsonRegularExpression.</returns>
-        public static BsonRegularExpression ReadRegularExpression(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadRegularExpression();
-        }
-
-        /// <summary>
-        /// Reads a BSON string element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>A String.</returns>
-        public static string ReadString(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadString();
-        }
-
-        /// <summary>
-        /// Reads a BSON symbol element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>A string.</returns>
-        public static string ReadSymbol(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadSymbol();
-        }
-
-        /// <summary>
-        /// Reads a BSON timestamp element from the reader.
-        /// </summary>
-        /// <returns>The combined timestamp/increment.</returns>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        public static long ReadTimestamp(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            return reader.ReadTimestamp();
-        }
-
-        /// <summary>
-        /// Reads a BSON undefined element from the reader.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        /// <param name="name">The name of the element.</param>
-        public static void ReadUndefined(this IBsonReader reader, string name)
-        {
-            VerifyName(reader, name);
-            reader.ReadUndefined();
-        }
-
-        private static void VerifyName(IBsonReader reader, string expectedName)
-        {
-            var actualName = reader.ReadName();
-            if (actualName != expectedName)
-            {
-                var message = string.Format(
-                    "Expected element name to be '{0}', not '{1}'.",
-                    expectedName, actualName);
-                throw new FormatException(message);
-            }
-        }
-    }
-}

+ 0 - 234
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IBsonWriter.cs

@@ -1,234 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a BSON writer.
-    /// </summary>
-    /// <seealso cref="System.IDisposable" />
-    public interface IBsonWriter : IDisposable
-    {
-        // properties
-        /// <summary>
-        /// Gets the position.
-        /// Not all writers are able to report the position. Those that can't simply return zero.
-        /// </summary>
-        /// <value>
-        /// The position.
-        /// </value>
-        long Position { get; }
-
-        /// <summary>
-        /// Gets the current serialization depth.
-        /// </summary>
-        int SerializationDepth { get; }
-
-        /// <summary>
-        /// Gets the settings of the writer.
-        /// </summary>
-        BsonWriterSettings Settings { get; }
-
-        // methods
-        /// <summary>
-        /// Gets the current state of the writer.
-        /// </summary>
-        BsonWriterState State { get; }
-
-        // methods
-        /// <summary>
-        /// Closes the writer.
-        /// </summary>
-        void Close();
-
-        /// <summary>
-        /// Flushes any pending data to the output destination.
-        /// </summary>
-        void Flush();
-
-        /// <summary>
-        /// Pops the element name validator.
-        /// </summary>
-        /// <returns>The popped element validator.</returns>
-        void PopElementNameValidator();
-
-        /// <summary>
-        /// Pops the settings.
-        /// </summary>
-        void PopSettings();
-
-        /// <summary>
-        /// Pushes the element name validator.
-        /// </summary>
-        /// <param name="validator">The validator.</param>
-        void PushElementNameValidator(IElementNameValidator validator);
-
-        /// <summary>
-        /// Pushes new settings for the writer.
-        /// </summary>
-        /// <param name="configurator">The settings configurator.</param>
-        void PushSettings(Action<BsonWriterSettings> configurator);
-
-        /// <summary>
-        /// Writes BSON binary data to the writer.
-        /// </summary>
-        /// <param name="binaryData">The binary data.</param>
-        void WriteBinaryData(BsonBinaryData binaryData);
-
-        /// <summary>
-        /// Writes a BSON Boolean to the writer.
-        /// </summary>
-        /// <param name="value">The Boolean value.</param>
-        void WriteBoolean(bool value);
-
-        /// <summary>
-        /// Writes BSON binary data to the writer.
-        /// </summary>
-        /// <param name="bytes">The bytes.</param>
-        void WriteBytes(byte[] bytes);
-
-        /// <summary>
-        /// Writes a BSON DateTime to the writer.
-        /// </summary>
-        /// <param name="value">The number of milliseconds since the Unix epoch.</param>
-        void WriteDateTime(long value);
-
-        /// <summary>
-        /// Writes a BSON Decimal128 to the writer.
-        /// </summary>
-        /// <param name="value">The <see cref="Decimal128"/> value.</param>
-        void WriteDecimal128(Decimal128 value);
-
-        /// <summary>
-        /// Writes a BSON Double to the writer.
-        /// </summary>
-        /// <param name="value">The Double value.</param>
-        void WriteDouble(double value);
-
-        /// <summary>
-        /// Writes the end of a BSON array to the writer.
-        /// </summary>
-        void WriteEndArray();
-
-        /// <summary>
-        /// Writes the end of a BSON document to the writer.
-        /// </summary>
-        void WriteEndDocument();
-
-        /// <summary>
-        /// Writes a BSON Int32 to the writer.
-        /// </summary>
-        /// <param name="value">The Int32 value.</param>
-        void WriteInt32(int value);
-
-        /// <summary>
-        /// Writes a BSON Int64 to the writer.
-        /// </summary>
-        /// <param name="value">The Int64 value.</param>
-        void WriteInt64(long value);
-
-        /// <summary>
-        /// Writes a BSON JavaScript to the writer.
-        /// </summary>
-        /// <param name="code">The JavaScript code.</param>
-        void WriteJavaScript(string code);
-
-        /// <summary>
-        /// Writes a BSON JavaScript to the writer (call WriteStartDocument to start writing the scope).
-        /// </summary>
-        /// <param name="code">The JavaScript code.</param>
-        void WriteJavaScriptWithScope(string code);
-
-        /// <summary>
-        /// Writes a BSON MaxKey to the writer.
-        /// </summary>
-        void WriteMaxKey();
-
-        /// <summary>
-        /// Writes a BSON MinKey to the writer.
-        /// </summary>
-        void WriteMinKey();
-
-        /// <summary>
-        /// Writes the name of an element to the writer.
-        /// </summary>
-        /// <param name="name">The name of the element.</param>
-        void WriteName(string name);
-
-        /// <summary>
-        /// Writes a BSON null to the writer.
-        /// </summary>
-        void WriteNull();
-
-        /// <summary>
-        /// Writes a BSON ObjectId to the writer.
-        /// </summary>
-        /// <param name="objectId">The ObjectId.</param>
-        void WriteObjectId(ObjectId objectId);
-
-        /// <summary>
-        /// Writes a raw BSON array.
-        /// </summary>
-        /// <param name="slice">The byte buffer containing the raw BSON array.</param>
-        void WriteRawBsonArray(IByteBuffer slice);
-
-        /// <summary>
-        /// Writes a raw BSON document.
-        /// </summary>
-        /// <param name="slice">The byte buffer containing the raw BSON document.</param>
-        void WriteRawBsonDocument(IByteBuffer slice);
-
-        /// <summary>
-        /// Writes a BSON regular expression to the writer.
-        /// </summary>
-        /// <param name="regex">A BsonRegularExpression.</param>
-        void WriteRegularExpression(BsonRegularExpression regex);
-
-        /// <summary>
-        /// Writes the start of a BSON array to the writer.
-        /// </summary>
-        void WriteStartArray();
-
-        /// <summary>
-        /// Writes the start of a BSON document to the writer.
-        /// </summary>
-        void WriteStartDocument();
-
-        /// <summary>
-        /// Writes a BSON String to the writer.
-        /// </summary>
-        /// <param name="value">The String value.</param>
-        void WriteString(string value);
-
-        /// <summary>
-        /// Writes a BSON Symbol to the writer.
-        /// </summary>
-        /// <param name="value">The symbol.</param>
-        void WriteSymbol(string value);
-
-        /// <summary>
-        /// Writes a BSON timestamp to the writer.
-        /// </summary>
-        /// <param name="value">The combined timestamp/increment value.</param>
-        void WriteTimestamp(long value);
-
-        /// <summary>
-        /// Writes a BSON undefined to the writer.
-        /// </summary>
-        void WriteUndefined();
-    }
-}

+ 0 - 293
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IBsonWriterExtensions.cs

@@ -1,293 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Contains extension methods for IBsonWriter.
-    /// </summary>
-    public static class IBsonWriterExtensions
-    {
-        /// <summary>
-        /// Writes a BSON binary data element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="binaryData">The binary data.</param>
-        public static void WriteBinaryData(this IBsonWriter writer, string name, BsonBinaryData binaryData)
-        {
-            writer.WriteName(name);
-            writer.WriteBinaryData(binaryData);
-        }
-
-        /// <summary>
-        /// Writes a BSON Boolean element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="value">The Boolean value.</param>
-        public static void WriteBoolean(this IBsonWriter writer, string name, bool value)
-        {
-            writer.WriteName(name);
-            writer.WriteBoolean(value);
-        }
-
-        /// <summary>
-        /// Writes a BSON binary data element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="bytes">The bytes.</param>
-        public static void WriteBytes(this IBsonWriter writer, string name, byte[] bytes)
-        {
-            writer.WriteName(name);
-            writer.WriteBytes(bytes);
-        }
-
-        /// <summary>
-        /// Writes a BSON DateTime element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="value">The number of milliseconds since the Unix epoch.</param>
-        public static void WriteDateTime(this IBsonWriter writer, string name, long value)
-        {
-            writer.WriteName(name);
-            writer.WriteDateTime(value);
-        }
-
-        /// <summary>
-        /// Writes a BSON Decimal128 element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="value">The <see cref="Decimal128"/> value.</param>
-        public static void WriteDecimal128(this IBsonWriter writer, string name, Decimal128 value)
-        {
-            writer.WriteName(name);
-            writer.WriteDecimal128(value);
-        }
-
-        /// <summary>
-        /// Writes a BSON Double element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="value">The Double value.</param>
-        public static void WriteDouble(this IBsonWriter writer, string name, double value)
-        {
-            writer.WriteName(name);
-            writer.WriteDouble(value);
-        }
-
-        /// <summary>
-        /// Writes a BSON Int32 element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="value">The Int32 value.</param>
-        public static void WriteInt32(this IBsonWriter writer, string name, int value)
-        {
-            writer.WriteName(name);
-            writer.WriteInt32(value);
-        }
-
-        /// <summary>
-        /// Writes a BSON Int64 element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="value">The Int64 value.</param>
-        public static void WriteInt64(this IBsonWriter writer, string name, long value)
-        {
-            writer.WriteName(name);
-            writer.WriteInt64(value);
-        }
-
-        /// <summary>
-        /// Writes a BSON JavaScript element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="code">The JavaScript code.</param>
-        public static void WriteJavaScript(this IBsonWriter writer, string name, string code)
-        {
-            writer.WriteName(name);
-            writer.WriteJavaScript(code);
-        }
-
-        /// <summary>
-        /// Writes a BSON JavaScript element to the writer (call WriteStartDocument to start writing the scope).
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="code">The JavaScript code.</param>
-        public static void WriteJavaScriptWithScope(this IBsonWriter writer, string name, string code)
-        {
-            writer.WriteName(name);
-            writer.WriteJavaScriptWithScope(code);
-        }
-
-        /// <summary>
-        /// Writes a BSON MaxKey element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        public static void WriteMaxKey(this IBsonWriter writer, string name)
-        {
-            writer.WriteName(name);
-            writer.WriteMaxKey();
-        }
-
-        /// <summary>
-        /// Writes a BSON MinKey element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        public static void WriteMinKey(this IBsonWriter writer, string name)
-        {
-            writer.WriteName(name);
-            writer.WriteMinKey();
-        }
-
-        /// <summary>
-        /// Writes a BSON null element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        public static void WriteNull(this IBsonWriter writer, string name)
-        {
-            writer.WriteName(name);
-            writer.WriteNull();
-        }
-
-        /// <summary>
-        /// Writes a BSON ObjectId element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="objectId">The ObjectId.</param>
-        public static void WriteObjectId(this IBsonWriter writer, string name, ObjectId objectId)
-        {
-            writer.WriteName(name);
-            writer.WriteObjectId(objectId);
-        }
-
-        /// <summary>
-        /// Writes a raw BSON array.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name.</param>
-        /// <param name="slice">The byte buffer containing the raw BSON array.</param>
-        public static void WriteRawBsonArray(this IBsonWriter writer, string name, IByteBuffer slice)
-        {
-            writer.WriteName(name);
-            writer.WriteRawBsonArray(slice);
-        }
-
-        /// <summary>
-        /// Writes a raw BSON document.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name.</param>
-        /// <param name="slice">The byte buffer containing the raw BSON document.</param>
-        public static void WriteRawBsonDocument(this IBsonWriter writer, string name, IByteBuffer slice)
-        {
-            writer.WriteName(name);
-            writer.WriteRawBsonDocument(slice);
-        }
-
-        /// <summary>
-        /// Writes a BSON regular expression element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="regex">A BsonRegularExpression.</param>
-        public static void WriteRegularExpression(this IBsonWriter writer, string name, BsonRegularExpression regex)
-        {
-            writer.WriteName(name);
-            writer.WriteRegularExpression(regex);
-        }
-
-        /// <summary>
-        /// Writes the start of a BSON array element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        public static void WriteStartArray(this IBsonWriter writer, string name)
-        {
-            writer.WriteName(name);
-            writer.WriteStartArray();
-        }
-
-        /// <summary>
-        /// Writes the start of a BSON document element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        public static void WriteStartDocument(this IBsonWriter writer, string name)
-        {
-            writer.WriteName(name);
-            writer.WriteStartDocument();
-        }
-
-        /// <summary>
-        /// Writes a BSON String element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="value">The String value.</param>
-        public static void WriteString(this IBsonWriter writer, string name, string value)
-        {
-            writer.WriteName(name);
-            writer.WriteString(value);
-        }
-
-        /// <summary>
-        /// Writes a BSON Symbol element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="value">The symbol.</param>
-        public static void WriteSymbol(this IBsonWriter writer, string name, string value)
-        {
-            writer.WriteName(name);
-            writer.WriteSymbol(value);
-        }
-
-        /// <summary>
-        /// Writes a BSON timestamp element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="value">The combined timestamp/increment value.</param>
-        public static void WriteTimestamp(this IBsonWriter writer, string name, long value)
-        {
-            writer.WriteName(name);
-            writer.WriteTimestamp(value);
-        }
-
-        /// <summary>
-        /// Writes a BSON undefined element to the writer.
-        /// </summary>
-        /// <param name="writer">The writer.</param>
-        /// <param name="name">The name of the element.</param>
-        public static void WriteUndefined(this IBsonWriter writer, string name)
-        {
-            writer.WriteName(name);
-            writer.WriteUndefined();
-        }
-    }
-}

+ 0 - 122
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IByteBuffer.cs

@@ -1,122 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a byte buffer (backed by various means depending on the implementation).
-    /// </summary>
-    public interface IByteBuffer : IDisposable
-    {
-        // properties
-        /// <summary>
-        /// Gets the capacity.
-        /// </summary>
-        /// <value>
-        /// The capacity.
-        /// </value>
-        int Capacity { get; }
-
-        /// <summary>
-        /// Gets a value indicating whether this instance is read only.
-        /// </summary>
-        /// <value>
-        /// <c>true</c> if this instance is read only; otherwise, <c>false</c>.
-        /// </value>
-        bool IsReadOnly { get; }
-
-        /// <summary>
-        /// Gets or sets the length.
-        /// </summary>
-        /// <value>
-        /// The length.
-        /// </value>
-        int Length { get; set; }
-
-        // methods
-        /// <summary>
-        /// Access the backing bytes directly. The returned ArraySegment will point to the desired position and contain
-        /// as many bytes as possible up to the next chunk boundary (if any). If the returned ArraySegment does not
-        /// contain enough bytes for your needs you will have to call ReadBytes instead.
-        /// </summary>
-        /// <param name="position">The position.</param>
-        /// <returns>
-        /// An ArraySegment pointing directly to the backing bytes for the position.
-        /// </returns>
-        ArraySegment<byte> AccessBackingBytes(int position);
-
-        /// <summary>
-        /// Clears the specified bytes.
-        /// </summary>
-        /// <param name="position">The position.</param>
-        /// <param name="count">The count.</param>
-        void Clear(int position, int count);
-
-        /// <summary>
-        /// Ensure that the buffer has a minimum capacity. Depending on the buffer allocation strategy
-        /// calling this method may result in a higher capacity than the minimum (but never lower).
-        /// </summary>
-        /// <param name="minimumCapacity">The minimum capacity.</param>
-        void EnsureCapacity(int minimumCapacity);
-
-        /// <summary>
-        /// Gets a slice of this buffer.
-        /// </summary>
-        /// <param name="position">The position of the start of the slice.</param>
-        /// <param name="length">The length of the slice.</param>
-        /// <returns>A slice of this buffer.</returns>
-        IByteBuffer GetSlice(int position, int length);
-
-        /// <summary>
-        /// Makes this buffer read only.
-        /// </summary>
-        void MakeReadOnly();
-
-        /// <summary>
-        /// Gets a byte.
-        /// </summary>
-        /// <param name="position">The position.</param>
-        /// <returns>A byte.</returns>
-        byte GetByte(int position);
-
-        /// <summary>
-        /// Gets bytes.
-        /// </summary>
-        /// <param name="position">The position.</param>
-        /// <param name="destination">The destination.</param>
-        /// <param name="offset">The destination offset.</param>
-        /// <param name="count">The count.</param>
-        void GetBytes(int position, byte[] destination, int offset, int count);
-
-        /// <summary>
-        /// Sets a byte.
-        /// </summary>
-        /// <param name="position">The position.</param>
-        /// <param name="value">The value.</param>
-        void SetByte(int position, byte value);
-
-        /// <summary>
-        /// Sets bytes.
-        /// </summary>
-        /// <param name="position">The position.</param>
-        /// <param name="source">The bytes.</param>
-        /// <param name="offset">The offset.</param>
-        /// <param name="count">The count.</param>
-        void SetBytes(int position, byte[] source, int offset, int count);
-    }
-}

+ 0 - 38
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/IElementNameValidator.cs

@@ -1,38 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents an element name validator. Used by BsonWriters when WriteName is called
-    /// to determine if the element name is valid.
-    /// </summary>
-    public interface IElementNameValidator
-    {
-        /// <summary>
-        /// Gets the validator to use for child content (a nested document or array).
-        /// </summary>
-        /// <param name="elementName">The name of the element.</param>
-        /// <returns>The validator to use for child content.</returns>
-        IElementNameValidator GetValidatorForChildContent(string elementName);
-
-        /// <summary>
-        /// Determines whether the element name is valid.
-        /// </summary>
-        /// <param name="elementName">The name of the element.</param>
-        /// <returns>True if the element name is valid.</returns>
-        bool IsValidElementName(string elementName);
-    }
-}

+ 0 - 43
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/INameDecoder.cs

@@ -1,43 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-using System.Text;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a name decoder.
-    /// </summary>
-    public interface INameDecoder
-    {
-        /// <summary>
-        /// Decodes the name.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <param name="encoding">The encoding.</param>
-        /// <returns>
-        /// The name.
-        /// </returns>
-        string Decode(BsonStream stream, UTF8Encoding encoding);
-
-        /// <summary>
-        /// Informs the decoder of an already decoded name (so the decoder can change state if necessary).
-        /// </summary>
-        /// <param name="name">The name.</param>
-        void Inform(string name);
-    }
-}

+ 0 - 174
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/InputBufferChunkSource.cs

@@ -1,174 +0,0 @@
-/* Copyright 2013-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a source of chunks optimized for input buffers.
-    /// </summary>
-    public sealed class InputBufferChunkSource : IBsonChunkSource
-    {
-        // constants
-        const int DefaultMaxChunkSize = 1 * 1024 * 1024;
-        const int DefaultMaxUnpooledChunkSize = 4 * 1024;
-        const int DefaultMinChunkSize = 16 * 1024;
-
-        // fields
-        private readonly IBsonChunkSource _baseSource;
-        private bool _disposed;
-        private readonly int _maxChunkSize;
-        private readonly int _maxUnpooledChunkSize;
-        private readonly int _minChunkSize;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="InputBufferChunkSource"/> class.
-        /// </summary>
-        /// <param name="baseSource">The chunk source.</param>
-        /// <param name="maxUnpooledChunkSize">The maximum size of an unpooled chunk.</param>
-        /// <param name="minChunkSize">The minimum size of a chunk.</param>
-        /// <param name="maxChunkSize">The maximum size of a chunk.</param>
-        public InputBufferChunkSource(
-            IBsonChunkSource baseSource,
-            int maxUnpooledChunkSize = DefaultMaxUnpooledChunkSize,
-            int minChunkSize = DefaultMinChunkSize,
-            int maxChunkSize = DefaultMaxChunkSize)
-        {
-            if (baseSource == null)
-            {
-                throw new ArgumentNullException("baseSource");
-            }
-            if (maxUnpooledChunkSize < 0)
-            {
-                throw new ArgumentOutOfRangeException("maxUnpooledChunkSize");
-            }
-            if (minChunkSize <= 0)
-            {
-                throw new ArgumentOutOfRangeException("minChunkSize");
-            }
-            if (maxChunkSize <= 0)
-            {
-                throw new ArgumentOutOfRangeException("maxChunkSize");
-            }
-            if (!PowerOf2.IsPowerOf2(minChunkSize))
-            {
-                throw new ArgumentException("minChunkSize is not a power of 2.", "minChunkSize");
-            }
-            if (!PowerOf2.IsPowerOf2(maxChunkSize))
-            {
-                throw new ArgumentException("maxChunkSize is not a power of 2.", "maxChunkSize");
-            }
-            if (maxChunkSize < minChunkSize)
-            {
-                throw new ArgumentException("maxChunkSize is less than minChunkSize", "maxChunkSize");
-            }
-
-            _baseSource = baseSource;
-            _maxUnpooledChunkSize = maxUnpooledChunkSize;
-            _minChunkSize = minChunkSize;
-            _maxChunkSize = maxChunkSize;
-        }
-
-        // properties
-        /// <summary>
-        /// Gets the base source.
-        /// </summary>
-        /// <value>
-        /// The base source.
-        /// </value>
-        public IBsonChunkSource BaseSource
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _baseSource;
-            }
-        }
-
-        /// <summary>
-        /// Gets the maximum size of a chunk.
-        /// </summary>
-        /// <value>
-        /// The maximum size of a chunk.
-        /// </value>
-        public int MaxChunkSize
-        {
-            get { return _maxChunkSize; }
-        }
-
-        /// <summary>
-        /// Gets the minimum size of a chunk.
-        /// </summary>
-        /// <value>
-        /// The minimum size of a chunk.
-        /// </value>
-        public int MinChunkSize
-        {
-            get { return _minChunkSize; }
-        }
-
-        /// <summary>
-        /// Gets the maximum size of an unpooled chunk.
-        /// </summary>
-        /// <value>
-        /// The maximum size of an unpooled chunk.
-        /// </value>
-        public int MaxUnpooledChunkSize
-        {
-            get { return _maxUnpooledChunkSize; }
-        }
-
-        // methods        
-        /// <inheritdoc/>
-        public void Dispose()
-        {
-            _disposed = true;
-        }
-
-        /// <inheritdoc/>
-        public IBsonChunk GetChunk(int requestedSize)
-        {
-            if (requestedSize <= 0)
-            {
-                throw new ArgumentOutOfRangeException("requestedSize");
-            }
-            ThrowIfDisposed();
-
-            if (requestedSize <= _maxUnpooledChunkSize)
-            {
-                return new ByteArrayChunk(requestedSize);
-            }
-
-            var powerOf2Size = PowerOf2.RoundUpToPowerOf2(requestedSize);
-            if (powerOf2Size - requestedSize > _minChunkSize)
-            {
-                powerOf2Size = powerOf2Size / 2;
-            }
-            var chunkSize = Math.Max(Math.Min(powerOf2Size, _maxChunkSize), _minChunkSize);
-
-            return _baseSource.GetChunk(chunkSize);
-        }
-
-        private void ThrowIfDisposed()
-        {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException(GetType().Name);
-            }
-        }
-    }
-}

+ 0 - 204
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonBuffer.cs

@@ -1,204 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-using System.Text;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a wrapper around a TextReader to provide some buffering functionality.
-    /// </summary>
-    internal class JsonBuffer
-    {
-        // private fields
-        private readonly StringBuilder _buffer;
-        private int _position;
-        private readonly TextReader _reader;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="JsonBuffer"/> class.
-        /// </summary>
-        /// <param name="json">The json.</param>
-        public JsonBuffer(string json)
-        {
-            if (json == null)
-            {
-                throw new ArgumentNullException("json");
-            }
-            _buffer = new StringBuilder(json);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="JsonBuffer" /> class.
-        /// </summary>
-        /// <param name="reader">The reader.</param>
-        public JsonBuffer(TextReader reader)
-        {
-            if (reader == null)
-            {
-                throw new ArgumentNullException("reader");
-            }
-            _buffer = new StringBuilder(256); // start out with a reasonable initial capacity
-            _reader = reader;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets or sets the current position.
-        /// </summary>
-        public int Position
-        {
-            get { return _position; }
-            set
-            {
-                if (value < 0 || value > _buffer.Length)
-                {
-                    var message = string.Format("Invalid position: {0}.", value);
-                    throw new ArgumentOutOfRangeException("value", message);
-                }
-                _position = value;
-            }
-        }
-
-        // public methods
-        /// <summary>
-        /// Gets a snippet of a maximum length from the buffer (usually to include in an error message).
-        /// </summary>
-        /// <param name="start">The start.</param>
-        /// <param name="maxLength">The maximum length.</param>
-        /// <returns>The snippet.</returns>
-        public string GetSnippet(int start, int maxLength)
-        {
-            if (start < 0)
-            {
-                throw new ArgumentOutOfRangeException("start", "Start cannot be negative.");
-            }
-            if (maxLength < 0)
-            {
-                throw new ArgumentOutOfRangeException("maxLength", "MaxLength cannot be negative.");
-            }
-            if (start > _position)
-            {
-                throw new ArgumentOutOfRangeException("start", "Start is beyond current position.");
-            }
-            var availableCount = _position - start;
-            var count = Math.Min(availableCount, maxLength);
-            return _buffer.ToString(start, count);
-        }
-
-        /// <summary>
-        /// Gets a substring from the buffer.
-        /// </summary>
-        /// <param name="start">The start.</param>
-        /// <param name="count">The count.</param>
-        /// <returns>The substring.</returns>
-        public string GetSubstring(int start, int count)
-        {
-            if (start < 0)
-            {
-                throw new ArgumentOutOfRangeException("start", "Start cannot be negative.");
-            }
-            if (count < 0)
-            {
-                throw new ArgumentOutOfRangeException("count", "Count cannot be negative.");
-            }
-            if (start > _position)
-            {
-                throw new ArgumentOutOfRangeException("start", "Start is beyond current position.");
-            }
-            if (start + count > _position)
-            {
-                throw new ArgumentOutOfRangeException("start", "End of substring is beyond current position.");
-            }
-            return _buffer.ToString(start, count);
-        }
-
-        /// <summary>
-        /// Reads the next character from the text reader and advances the character position by one character.
-        /// </summary>
-        /// <returns>
-        /// The next character from the text reader, or -1 if no more characters are available. The default implementation returns -1.
-        /// </returns>
-        public int Read()
-        {
-            ReadMoreIfAtEndOfBuffer();
-            return _position >= _buffer.Length ? -1 : _buffer[_position++];
-        }
-
-        /// <summary>
-        /// Resets the buffer (clears everything up to the current position).
-        /// </summary>
-        public void ResetBuffer()
-        {
-            // only trim the buffer if enough space will be reclaimed to make it worthwhile
-            var minimumTrimCount = 256; // TODO: make configurable?
-            if (_position >= minimumTrimCount)
-            {
-                _buffer.Remove(0, _position);
-                _position = 0;
-            }
-        }
-
-        /// <summary>
-        /// Unreads one character (moving the current Position back one position).
-        /// </summary>
-        /// <param name="c">The character.</param>
-        public void UnRead(int c)
-        {
-            if (_position == 0)
-            {
-                throw new InvalidOperationException("Unread called when nothing has been read.");
-            }
-
-            if (c == -1)
-            {
-                if (_position != _buffer.Length)
-                {
-                    throw new InvalidOperationException("Unread called with -1 when position is not at the end of the buffer.");
-                }
-            }
-            else
-            {
-                if (_buffer[_position - 1] != c)
-                {
-                    throw new InvalidOperationException("Unread called with a character that does not match what is in the buffer.");
-                }
-                _position -= 1;
-            }
-        }
-
-        // private methods
-        private void ReadMoreIfAtEndOfBuffer()
-        {
-            if (_position >= _buffer.Length)
-            {
-                if (_reader != null)
-                {
-                    var blockSize = 1024; // TODO: make configurable?
-                    var block = new char[blockSize];
-                    var actualCount = _reader.ReadBlock(block, 0, blockSize);
-
-                    if (actualCount > 0)
-                    {
-                        _buffer.Append(block, 0, actualCount);
-                    }
-                }
-            }
-        }
-    }
-}

+ 0 - 299
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonConvert.cs

@@ -1,299 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Globalization;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Encodes and decodes scalar values to JSON compatible strings.
-    /// </summary>
-    public static class JsonConvert
-    {
-        /// <summary>
-        /// Converts a string to a Boolean.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A Boolean.</returns>
-        public static bool ToBoolean(string value)
-        {
-            return bool.Parse(value);
-        }
-
-        /// <summary>
-        /// Converts a string to a DateTime.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A DateTime.</returns>
-        public static DateTime ToDateTime(string value)
-        {
-            var formats = new[]
-            {
-                "yyyy-MM-ddK",
-                "yyyy-MM-ddTHH:mm:ssK",
-                "yyyy-MM-ddTHH:mm:ss.FFFFFFFK"
-            };
-            var style = DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal;
-            return DateTime.ParseExact(value, formats, DateTimeFormatInfo.InvariantInfo, style);
-        }
-
-        /// <summary>
-        /// Converts a string to a DateTimeOffset.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns> A DateTimeOffset.</returns>
-        public static DateTimeOffset ToDateTimeOffset(string value)
-        {
-            return DateTimeOffset.ParseExact(value, "yyyy-MM-ddTHH:mm:ss.FFFFFFFK", DateTimeFormatInfo.InvariantInfo);
-        }
-
-        /// <summary>
-        /// Converts a string to a Decimal.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A Decimal.</returns>
-        public static decimal ToDecimal(string value)
-        {
-            return decimal.Parse(value, NumberFormatInfo.InvariantInfo);
-        }
-
-        /// <summary>
-        /// Converts a string to a <see cref="Decimal128"/>.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A <see cref="Decimal128"/>.</returns>
-        public static Decimal128 ToDecimal128(string value)
-        {
-            return Decimal128.Parse(value);
-        }
-
-        /// <summary>
-        /// Converts a string to a Double.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A Double.</returns>
-        public static double ToDouble(string value)
-        {
-            return double.Parse(value, NumberFormatInfo.InvariantInfo);
-        }
-
-        /// <summary>
-        /// Converts a string to an Int16.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>An Int16.</returns>
-        public static short ToInt16(string value)
-        {
-            return Int16.Parse(value);
-        }
-
-        /// <summary>
-        /// Converts a string to an Int32.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>An Int32.</returns>
-        public static int ToInt32(string value)
-        {
-            return Int32.Parse(value);
-        }
-
-        /// <summary>
-        /// Converts a string to an Int64.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>An Int64.</returns>
-        public static long ToInt64(string value)
-        {
-            return Int64.Parse(value);
-        }
-
-        /// <summary>
-        /// Converts a string to a Single.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A Single.</returns>
-        public static float ToSingle(string value)
-        {
-            return float.Parse(value, NumberFormatInfo.InvariantInfo);
-        }
-
-        /// <summary>
-        /// Converts a Boolean to a string.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A string.</returns>
-        public static string ToString(bool value)
-        {
-            return value ? "true" : "false";
-        }
-
-        /// <summary>
-        /// Converts a DateTime to a string.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A string.</returns>
-        public static string ToString(DateTime value)
-        {
-            return value.ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFFK", DateTimeFormatInfo.InvariantInfo);
-        }
-
-        /// <summary>
-        /// Converts a DateTimeOffset to a string.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A string.</returns>
-        public static string ToString(DateTimeOffset value)
-        {
-            return value.ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFFK", DateTimeFormatInfo.InvariantInfo);
-        }
-
-        /// <summary>
-        /// Converts a Decimal to a string.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A string.</returns>
-        public static string ToString(decimal value)
-        {
-            return value.ToString("G", NumberFormatInfo.InvariantInfo);
-        }
-
-        /// <summary>
-        /// Converts a <see cref="Decimal128"/> to a string.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A string.</returns>
-        public static string ToString(Decimal128 value)
-        {
-            return value.ToString();
-        }
-
-        /// <summary>
-        /// Converts a Double to a string.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A string.</returns>
-        public static string ToString(double value)
-        {
-            return value.ToString("G17", NumberFormatInfo.InvariantInfo);
-        }
-
-        /// <summary>
-        /// Converts a Single to a string.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A string.</returns>
-        public static string ToString(float value)
-        {
-            return value.ToString("R", NumberFormatInfo.InvariantInfo);
-        }
-
-        /// <summary>
-        /// Converts an Int32 to a string.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A string.</returns>
-        public static string ToString(int value)
-        {
-            return value.ToString();
-        }
-
-        /// <summary>
-        /// Converts an Int64 to a string.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A string.</returns>
-        public static string ToString(long value)
-        {
-            return value.ToString();
-        }
-
-        /// <summary>
-        /// Converts an Int16 to a string.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A string.</returns>
-        public static string ToString(short value)
-        {
-            return value.ToString();
-        }
-
-        /// <summary>
-        /// Converts a UInt32 to a string.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A string.</returns>
-        [CLSCompliant(false)]
-        public static string ToString(uint value)
-        {
-            return value.ToString();
-        }
-
-        /// <summary>
-        /// Converts a UInt64 to a string.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A string.</returns>
-        [CLSCompliant(false)]
-        public static string ToString(ulong value)
-        {
-            return value.ToString();
-        }
-
-        /// <summary>
-        /// Converts a UInt16 to a string.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A string.</returns>
-        [CLSCompliant(false)]
-        public static string ToString(ushort value)
-        {
-            return value.ToString();
-        }
-
-        /// <summary>
-        /// Converts a string to a UInt16.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A UInt16.</returns>
-        [CLSCompliant(false)]
-        public static ushort ToUInt16(string value)
-        {
-            return UInt16.Parse(value);
-        }
-
-        /// <summary>
-        /// Converts a string to a UInt32.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A UInt32.</returns>
-        [CLSCompliant(false)]
-        public static uint ToUInt32(string value)
-        {
-            return UInt32.Parse(value);
-        }
-
-        /// <summary>
-        /// Converts a string to a UInt64.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>A UInt64.</returns>
-        [CLSCompliant(false)]
-        public static ulong ToUInt64(string value)
-        {
-            return UInt64.Parse(value);
-        }
-    }
-}

+ 0 - 47
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonOutputMode.cs

@@ -1,47 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents the output mode of a JsonWriter.
-    /// </summary>
-    public enum JsonOutputMode
-    {
-        /// <summary>
-        /// Output strict JSON.
-        /// </summary>
-        Strict,
-
-        /// <summary>
-        /// Use a format that can be pasted in to the MongoDB shell.
-        /// </summary>
-        Shell,
-
-        /// <summary>
-        /// Use JavaScript data types for some values.
-        /// </summary>
-        [Obsolete("Use Shell instead.")]
-        JavaScript = Shell,
-
-        /// <summary>
-        /// Use JavaScript and MongoDB data types for some values.
-        /// </summary>
-        [Obsolete("Use Shell instead.")]
-        TenGen = Shell
-    }
-}

+ 0 - 1926
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonReader.cs

@@ -1,1926 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Text.RegularExpressions;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a BSON reader for a JSON string.
-    /// </summary>
-    public class JsonReader : BsonReader
-    {
-        #region static
-        private static readonly string[] __variableLengthIso8601Formats = new string[]
-        {
-            "yyyy-MM-ddTHH:mm:ss.FFFFFFFK",
-            "yyyy-MM-ddTHH:mm:ss.FFFFFFFzz",
-            "yyyyMMddTHHmmss.FFFFFFFK",
-            "yyyyMMddTHHmmss.FFFFFFFzz"
-        };
-
-        private static readonly string[][] __fixedLengthIso8601Formats = new string[][]
-        {
-            null, // length = 0
-            null, // length = 1
-            null, // length = 2
-            null, // length = 3
-            new [] { "yyyy" }, // length = 4
-            null, // length = 5
-            null, // length = 6
-            new [] { "yyyy-MM" }, // length = 7
-            new [] { "yyyyMMdd" }, // length = 8
-            null, // length = 9
-            new [] { "yyyy-MM-dd" }, // length = 10
-            new [] { "yyyyMMddTHH" }, // length = 11
-            new [] { "yyyyMMddTHHZ" }, // length = 12
-            new [] { "yyyy-MM-ddTHH" , "yyyyMMddTHHmm" }, // length = 13
-            new [] { "yyyy-MM-ddTHHZ", "yyyyMMddTHHmmZ", "yyyyMMddTHHzz" }, // length = 14
-            null, // length = 15
-            new [] { "yyyy-MM-ddTHH:mm", "yyyy-MM-ddTHHzz", "yyyyMMddTHHmmssZ", "yyyyMMddTHHmmzz" }, // length = 16
-            new [] { "yyyy-MM-ddTHH:mmZ", "yyyyMMddTHHzzz" }, // length = 17
-            new [] { "yyyyMMddTHHmmsszz" }, // length = 18
-            new [] { "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-ddTHHzzz", "yyyy-MM-ddTHH:mmzz", "yyyyMMddTHHmmzzz" }, // length = 19
-            null, // length = 20
-            null, // length = 21
-            new [] { "yyyy-MM-ddTHH:mmzzz", "yyyy-MM-ddTHH:mm:sszz" } // length = 22
-        };
-        #endregion
-
-        // private fields
-        private readonly JsonBuffer _buffer;
-        private readonly JsonReaderSettings _jsonReaderSettings; // same value as in base class just declared as derived class
-        private JsonReaderContext _context;
-        private JsonToken _currentToken;
-        private BsonValue _currentValue;
-        private JsonToken _pushedToken;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the JsonReader class.
-        /// </summary>
-        /// <param name="json">The JSON string.</param>
-        public JsonReader(string json)
-            : this(json, JsonReaderSettings.Defaults)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the JsonReader class.
-        /// </summary>
-        /// <param name="json">The JSON string.</param>
-        /// <param name="settings">The reader settings.</param>
-        public JsonReader(string json, JsonReaderSettings settings)
-            : this(new JsonBuffer(json), settings)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the JsonReader class.
-        /// </summary>
-        /// <param name="textReader">The TextReader.</param>
-        public JsonReader(TextReader textReader)
-            : this(textReader, JsonReaderSettings.Defaults)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the JsonReader class.
-        /// </summary>
-        /// <param name="textReader">The TextReader.</param>
-        /// <param name="settings">The reader settings.</param>
-        public JsonReader(TextReader textReader, JsonReaderSettings settings)
-            : this(new JsonBuffer(textReader), settings)
-        {
-        }
-
-        private JsonReader(JsonBuffer buffer, JsonReaderSettings settings)
-            : base(settings)
-        {
-            _buffer = buffer;
-            _jsonReaderSettings = settings; // already frozen by base class
-            _context = new JsonReaderContext(null, ContextType.TopLevel);
-        }
-
-        // public methods
-        /// <summary>
-        /// Closes the reader.
-        /// </summary>
-        public override void Close()
-        {
-            // Close can be called on Disposed objects
-            State = BsonReaderState.Closed;
-        }
-
-        /// <summary>
-        /// Gets a bookmark to the reader's current position and state.
-        /// </summary>
-        /// <returns>A bookmark.</returns>
-        public override BsonReaderBookmark GetBookmark()
-        {
-            return new JsonReaderBookmark(State, CurrentBsonType, CurrentName, _context, _currentToken, _currentValue, _pushedToken, _buffer.Position);
-        }
-
-        /// <summary>
-        /// Determines whether this reader is at end of file.
-        /// </summary>
-        /// <returns>
-        /// Whether this reader is at end of file.
-        /// </returns>
-        public override bool IsAtEndOfFile()
-        {
-            int c;
-            while ((c = _buffer.Read()) != -1)
-            {
-                if (!char.IsWhiteSpace((char)c))
-                {
-                    _buffer.UnRead(c);
-                    return false;
-                }
-            }
-            return true;
-        }
-
-        /// <summary>
-        /// Reads BSON binary data from the reader.
-        /// </summary>
-        /// <returns>A BsonBinaryData.</returns>
-        public override BsonBinaryData ReadBinaryData()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadBinaryData", BsonType.Binary);
-            State = GetNextState();
-            return _currentValue.AsBsonBinaryData;
-        }
-
-        /// <summary>
-        /// Reads a BSON boolean from the reader.
-        /// </summary>
-        /// <returns>A Boolean.</returns>
-        public override bool ReadBoolean()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadBoolean", BsonType.Boolean);
-            State = GetNextState();
-            return _currentValue.AsBoolean;
-        }
-
-        /// <summary>
-        /// Reads a BsonType from the reader.
-        /// </summary>
-        /// <returns>A BsonType.</returns>
-        public override BsonType ReadBsonType()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (State == BsonReaderState.Initial || State == BsonReaderState.ScopeDocument)
-            {
-                if (State == BsonReaderState.Initial)
-                {
-                    _buffer.ResetBuffer();
-                }
-
-                // in JSON the top level value can be of any type so fall through
-                State = BsonReaderState.Type;
-            }
-            if (State != BsonReaderState.Type)
-            {
-                ThrowInvalidState("ReadBsonType", BsonReaderState.Type);
-            }
-
-            if (_context.ContextType == ContextType.Document)
-            {
-                var nameToken = PopToken();
-                switch (nameToken.Type)
-                {
-                    case JsonTokenType.String:
-                    case JsonTokenType.UnquotedString:
-                        CurrentName = nameToken.StringValue;
-                        break;
-                    case JsonTokenType.EndObject:
-                        State = BsonReaderState.EndOfDocument;
-                        return BsonType.EndOfDocument;
-                    default:
-                        var message = string.Format("JSON reader was expecting a name but found '{0}'.", nameToken.Lexeme);
-                        throw new FormatException(message);
-                }
-
-                var colonToken = PopToken();
-                if (colonToken.Type != JsonTokenType.Colon)
-                {
-                    var message = string.Format("JSON reader was expecting ':' but found '{0}'.", colonToken.Lexeme);
-                    throw new FormatException(message);
-                }
-            }
-
-            var valueToken = PopToken();
-            if (_context.ContextType == ContextType.Array && valueToken.Type == JsonTokenType.EndArray)
-            {
-                State = BsonReaderState.EndOfArray;
-                return BsonType.EndOfDocument;
-            }
-
-            var noValueFound = false;
-            switch (valueToken.Type)
-            {
-                case JsonTokenType.BeginArray:
-                    CurrentBsonType = BsonType.Array;
-                    break;
-                case JsonTokenType.BeginObject:
-                    CurrentBsonType = ParseExtendedJson();
-                    break;
-                case JsonTokenType.DateTime:
-                    CurrentBsonType = BsonType.DateTime;
-                    _currentValue = valueToken.DateTimeValue;
-                    break;
-                case JsonTokenType.Double:
-                    CurrentBsonType = BsonType.Double;
-                    _currentValue = valueToken.DoubleValue;
-                    break;
-                case JsonTokenType.EndOfFile:
-                    CurrentBsonType = BsonType.EndOfDocument;
-                    break;
-                case JsonTokenType.Int32:
-                    CurrentBsonType = BsonType.Int32;
-                    _currentValue = valueToken.Int32Value;
-                    break;
-                case JsonTokenType.Int64:
-                    CurrentBsonType = BsonType.Int64;
-                    _currentValue = valueToken.Int64Value;
-                    break;
-                case JsonTokenType.ObjectId:
-                    CurrentBsonType = BsonType.ObjectId;
-                    _currentValue = valueToken.ObjectIdValue;
-                    break;
-                case JsonTokenType.RegularExpression:
-                    CurrentBsonType = BsonType.RegularExpression;
-                    _currentValue = valueToken.RegularExpressionValue;
-                    break;
-                case JsonTokenType.String:
-                    CurrentBsonType = BsonType.String;
-                    _currentValue = valueToken.StringValue;
-                    break;
-                case JsonTokenType.UnquotedString:
-                    switch (valueToken.Lexeme)
-                    {
-                        case "false":
-                        case "true":
-                            CurrentBsonType = BsonType.Boolean;
-                            _currentValue = JsonConvert.ToBoolean(valueToken.Lexeme);
-                            break;
-                        case "Infinity":
-                            CurrentBsonType = BsonType.Double;
-                            _currentValue = double.PositiveInfinity;
-                            break;
-                        case "NaN":
-                            CurrentBsonType = BsonType.Double;
-                            _currentValue = double.NaN;
-                            break;
-                        case "null":
-                            CurrentBsonType = BsonType.Null;
-                            break;
-                        case "undefined":
-                            CurrentBsonType = BsonType.Undefined;
-                            break;
-                        case "BinData":
-                            CurrentBsonType = BsonType.Binary;
-                            _currentValue = ParseBinDataConstructor();
-                            break;
-                        case "Date":
-                            CurrentBsonType = BsonType.String;
-                            _currentValue = ParseDateTimeConstructor(false); // withNew = false
-                            break;
-                        case "HexData":
-                            CurrentBsonType = BsonType.Binary;
-                            _currentValue = ParseHexDataConstructor();
-                            break;
-                        case "ISODate":
-                            CurrentBsonType = BsonType.DateTime;
-                            _currentValue = ParseISODateTimeConstructor();
-                            break;
-                        case "MaxKey":
-                            CurrentBsonType = BsonType.MaxKey;
-                            _currentValue = BsonMaxKey.Value;
-                            break;
-                        case "MinKey":
-                            CurrentBsonType = BsonType.MinKey;
-                            _currentValue = BsonMinKey.Value;
-                            break;
-                        case "NumberDecimal":
-                            CurrentBsonType = BsonType.Decimal128;
-                            _currentValue = ParseNumberDecimalConstructor();
-                            break;
-                        case "Number":
-                        case "NumberInt":
-                            CurrentBsonType = BsonType.Int32;
-                            _currentValue = ParseNumberConstructor();
-                            break;
-                        case "NumberLong":
-                            CurrentBsonType = BsonType.Int64;
-                            _currentValue = ParseNumberLongConstructor();
-                            break;
-                        case "ObjectId":
-                            CurrentBsonType = BsonType.ObjectId;
-                            _currentValue = ParseObjectIdConstructor();
-                            break;
-                        case "RegExp":
-                            CurrentBsonType = BsonType.RegularExpression;
-                            _currentValue = ParseRegularExpressionConstructor();
-                            break;
-                        case "Timestamp":
-                            CurrentBsonType = BsonType.Timestamp;
-                            _currentValue = ParseTimestampConstructor();
-                            break;
-                        case "UUID":
-                        case "GUID":
-                        case "CSUUID":
-                        case "CSGUID":
-                        case "JUUID":
-                        case "JGUID":
-                        case "PYUUID":
-                        case "PYGUID":
-                            CurrentBsonType = BsonType.Binary;
-                            _currentValue = ParseUUIDConstructor(valueToken.Lexeme);
-                            break;
-                        case "new":
-                            CurrentBsonType = ParseNew(out _currentValue);
-                            break;
-                        default:
-                            noValueFound = true;
-                            break;
-                    }
-                    break;
-                default:
-                    noValueFound = true;
-                    break;
-            }
-            if (noValueFound)
-            {
-                var message = string.Format("JSON reader was expecting a value but found '{0}'.", valueToken.Lexeme);
-                throw new FormatException(message);
-            }
-            _currentToken = valueToken;
-
-            if (_context.ContextType == ContextType.Array || _context.ContextType == ContextType.Document)
-            {
-                var commaToken = PopToken();
-                if (commaToken.Type != JsonTokenType.Comma)
-                {
-                    PushToken(commaToken);
-                }
-            }
-
-            switch (_context.ContextType)
-            {
-                case ContextType.Document:
-                case ContextType.ScopeDocument:
-                default:
-                    State = BsonReaderState.Name;
-                    break;
-                case ContextType.Array:
-                case ContextType.JavaScriptWithScope:
-                case ContextType.TopLevel:
-                    State = BsonReaderState.Value;
-                    break;
-            }
-            return CurrentBsonType;
-        }
-
-        /// <summary>
-        /// Reads BSON binary data from the reader.
-        /// </summary>
-        /// <returns>A byte array.</returns>
-        public override byte[] ReadBytes()
-        {
-#pragma warning disable 618
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadBinaryData", BsonType.Binary);
-            State = GetNextState();
-            var binaryData = _currentValue.AsBsonBinaryData;
-
-            var subType = binaryData.SubType;
-            if (subType != BsonBinarySubType.Binary && subType != BsonBinarySubType.OldBinary)
-            {
-                var message = string.Format("ReadBytes requires the binary sub type to be Binary, not {0}.", subType);
-                throw new FormatException(message);
-            }
-
-            return binaryData.Bytes;
-#pragma warning restore
-        }
-
-        /// <summary>
-        /// Reads a BSON DateTime from the reader.
-        /// </summary>
-        /// <returns>The number of milliseconds since the Unix epoch.</returns>
-        public override long ReadDateTime()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadDateTime", BsonType.DateTime);
-            State = GetNextState();
-            return _currentValue.AsBsonDateTime.MillisecondsSinceEpoch;
-        }
-
-        /// <inheritdoc />
-        public override Decimal128 ReadDecimal128()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType(nameof(ReadDecimal128), BsonType.Decimal128);
-            State = GetNextState();
-            return _currentValue.AsDecimal128;
-        }
-
-        /// <summary>
-        /// Reads a BSON Double from the reader.
-        /// </summary>
-        /// <returns>A Double.</returns>
-        public override double ReadDouble()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadDouble", BsonType.Double);
-            State = GetNextState();
-            return _currentValue.AsDouble;
-        }
-
-        /// <summary>
-        /// Reads the end of a BSON array from the reader.
-        /// </summary>
-        public override void ReadEndArray()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (_context.ContextType != ContextType.Array)
-            {
-                ThrowInvalidContextType("ReadEndArray", _context.ContextType, ContextType.Array);
-            }
-            if (State == BsonReaderState.Type)
-            {
-                ReadBsonType(); // will set state to EndOfArray if at end of array
-            }
-            if (State != BsonReaderState.EndOfArray)
-            {
-                ThrowInvalidState("ReadEndArray", BsonReaderState.EndOfArray);
-            }
-
-            _context = _context.PopContext();
-            switch (_context.ContextType)
-            {
-                case ContextType.Array: State = BsonReaderState.Type; break;
-                case ContextType.Document: State = BsonReaderState.Type; break;
-                case ContextType.TopLevel: State = BsonReaderState.Initial; break;
-                default: throw new BsonInternalException("Unexpected ContextType.");
-            }
-
-            if (_context.ContextType == ContextType.Array || _context.ContextType == ContextType.Document)
-            {
-                var commaToken = PopToken();
-                if (commaToken.Type != JsonTokenType.Comma)
-                {
-                    PushToken(commaToken);
-                }
-            }
-        }
-
-        /// <summary>
-        /// Reads the end of a BSON document from the reader.
-        /// </summary>
-        public override void ReadEndDocument()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (_context.ContextType != ContextType.Document && _context.ContextType != ContextType.ScopeDocument)
-            {
-                ThrowInvalidContextType("ReadEndDocument", _context.ContextType, ContextType.Document, ContextType.ScopeDocument);
-            }
-            if (State == BsonReaderState.Type)
-            {
-                ReadBsonType(); // will set state to EndOfDocument if at end of document
-            }
-            if (State != BsonReaderState.EndOfDocument)
-            {
-                ThrowInvalidState("ReadEndDocument", BsonReaderState.EndOfDocument);
-            }
-
-            _context = _context.PopContext();
-            if (_context != null && _context.ContextType == ContextType.JavaScriptWithScope)
-            {
-                _context = _context.PopContext(); // JavaScriptWithScope
-                VerifyToken("}"); // outermost closing bracket for JavaScriptWithScope
-            }
-            switch (_context.ContextType)
-            {
-                case ContextType.Array: State = BsonReaderState.Type; break;
-                case ContextType.Document: State = BsonReaderState.Type; break;
-                case ContextType.TopLevel: State = BsonReaderState.Initial; break;
-                default: throw new BsonInternalException("Unexpected ContextType");
-            }
-
-            if (_context.ContextType == ContextType.Array || _context.ContextType == ContextType.Document)
-            {
-                var commaToken = PopToken();
-                if (commaToken.Type != JsonTokenType.Comma)
-                {
-                    PushToken(commaToken);
-                }
-            }
-        }
-
-        /// <summary>
-        /// Reads a BSON Int32 from the reader.
-        /// </summary>
-        /// <returns>An Int32.</returns>
-        public override int ReadInt32()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadInt32", BsonType.Int32);
-            State = GetNextState();
-            return _currentValue.AsInt32;
-        }
-
-        /// <summary>
-        /// Reads a BSON Int64 from the reader.
-        /// </summary>
-        /// <returns>An Int64.</returns>
-        public override long ReadInt64()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadInt64", BsonType.Int64);
-            State = GetNextState();
-            return _currentValue.AsInt64;
-        }
-
-        /// <summary>
-        /// Reads a BSON JavaScript from the reader.
-        /// </summary>
-        /// <returns>A string.</returns>
-        public override string ReadJavaScript()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadJavaScript", BsonType.JavaScript);
-            State = GetNextState();
-            return _currentValue.AsString;
-        }
-
-        /// <summary>
-        /// Reads a BSON JavaScript with scope from the reader (call ReadStartDocument next to read the scope).
-        /// </summary>
-        /// <returns>A string.</returns>
-        public override string ReadJavaScriptWithScope()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadJavaScriptWithScope", BsonType.JavaScriptWithScope);
-            _context = new JsonReaderContext(_context, ContextType.JavaScriptWithScope);
-            State = BsonReaderState.ScopeDocument;
-            return _currentValue.AsString;
-        }
-
-        /// <summary>
-        /// Reads a BSON MaxKey from the reader.
-        /// </summary>
-        public override void ReadMaxKey()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadMaxKey", BsonType.MaxKey);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Reads a BSON MinKey from the reader.
-        /// </summary>
-        public override void ReadMinKey()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadMinKey", BsonType.MinKey);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Reads the name of an element from the reader.
-        /// </summary>
-        /// <param name="nameDecoder">The name decoder.</param>
-        /// <returns>
-        /// The name of the element.
-        /// </returns>
-        public override string ReadName(INameDecoder nameDecoder)
-        {
-            if (nameDecoder == null)
-            {
-                throw new ArgumentNullException("nameDecoder");
-            }
-
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (State == BsonReaderState.Type)
-            {
-                ReadBsonType();
-            }
-            if (State != BsonReaderState.Name)
-            {
-                ThrowInvalidState("ReadName", BsonReaderState.Name);
-            }
-
-            nameDecoder.Inform(CurrentName);
-            State = BsonReaderState.Value;
-            return CurrentName;
-        }
-
-        /// <summary>
-        /// Reads a BSON null from the reader.
-        /// </summary>
-        public override void ReadNull()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadNull", BsonType.Null);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Reads a BSON ObjectId from the reader.
-        /// </summary>
-        /// <returns>An ObjectId.</returns>
-        public override ObjectId ReadObjectId()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadObjectId", BsonType.ObjectId);
-            State = GetNextState();
-            return _currentValue.AsObjectId;
-        }
-
-        /// <summary>
-        /// Reads a BSON regular expression from the reader.
-        /// </summary>
-        /// <returns>A BsonRegularExpression.</returns>
-        public override BsonRegularExpression ReadRegularExpression()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadRegularExpression", BsonType.RegularExpression);
-            State = GetNextState();
-            return _currentValue.AsBsonRegularExpression;
-        }
-
-        /// <summary>
-        /// Reads the start of a BSON array.
-        /// </summary>
-        public override void ReadStartArray()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadStartArray", BsonType.Array);
-
-            _context = new JsonReaderContext(_context, ContextType.Array);
-            State = BsonReaderState.Type;
-        }
-
-        /// <summary>
-        /// Reads the start of a BSON document.
-        /// </summary>
-        public override void ReadStartDocument()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadStartDocument", BsonType.Document);
-
-            _context = new JsonReaderContext(_context, ContextType.Document);
-            State = BsonReaderState.Type;
-        }
-
-        /// <summary>
-        /// Reads a BSON string from the reader.
-        /// </summary>
-        /// <returns>A String.</returns>
-        public override string ReadString()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadString", BsonType.String);
-            State = GetNextState();
-            return _currentValue.AsString;
-        }
-
-        /// <summary>
-        /// Reads a BSON symbol from the reader.
-        /// </summary>
-        /// <returns>A string.</returns>
-        public override string ReadSymbol()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadSymbol", BsonType.Symbol);
-            State = GetNextState();
-            return _currentValue.AsString;
-        }
-
-        /// <summary>
-        /// Reads a BSON timestamp from the reader.
-        /// </summary>
-        /// <returns>The combined timestamp/increment.</returns>
-        public override long ReadTimestamp()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadTimestamp", BsonType.Timestamp);
-            State = GetNextState();
-            var timestamp = _currentValue.AsBsonTimestamp;
-            return timestamp.Value;
-        }
-
-        /// <summary>
-        /// Reads a BSON undefined from the reader.
-        /// </summary>
-        public override void ReadUndefined()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            VerifyBsonType("ReadUndefined", BsonType.Undefined);
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Returns the reader to previously bookmarked position and state.
-        /// </summary>
-        /// <param name="bookmark">The bookmark.</param>
-        public override void ReturnToBookmark(BsonReaderBookmark bookmark)
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            var jsonReaderBookmark = (JsonReaderBookmark)bookmark;
-            State = jsonReaderBookmark.State;
-            CurrentBsonType = jsonReaderBookmark.CurrentBsonType;
-            CurrentName = jsonReaderBookmark.CurrentName;
-            _context = jsonReaderBookmark.CloneContext();
-            _currentToken = jsonReaderBookmark.CurrentToken;
-            _currentValue = jsonReaderBookmark.CurrentValue;
-            _pushedToken = jsonReaderBookmark.PushedToken;
-            _buffer.Position = jsonReaderBookmark.Position;
-        }
-
-        /// <summary>
-        /// Skips the name (reader must be positioned on a name).
-        /// </summary>
-        public override void SkipName()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (State != BsonReaderState.Name)
-            {
-                ThrowInvalidState("SkipName", BsonReaderState.Name);
-            }
-
-            State = BsonReaderState.Value;
-        }
-
-        /// <summary>
-        /// Skips the value (reader must be positioned on a value).
-        /// </summary>
-        public override void SkipValue()
-        {
-            if (Disposed) { ThrowObjectDisposedException(); }
-            if (State != BsonReaderState.Value)
-            {
-                ThrowInvalidState("SkipValue", BsonReaderState.Value);
-            }
-
-            switch (CurrentBsonType)
-            {
-                case BsonType.Array:
-                    ReadStartArray();
-                    while (ReadBsonType() != BsonType.EndOfDocument)
-                    {
-                        SkipValue();
-                    }
-                    ReadEndArray();
-                    break;
-                case BsonType.Binary:
-                    ReadBinaryData();
-                    break;
-                case BsonType.Boolean:
-                    ReadBoolean();
-                    break;
-                case BsonType.DateTime:
-                    ReadDateTime();
-                    break;
-                case BsonType.Document:
-                    ReadStartDocument();
-                    while (ReadBsonType() != BsonType.EndOfDocument)
-                    {
-                        SkipName();
-                        SkipValue();
-                    }
-                    ReadEndDocument();
-                    break;
-                case BsonType.Double:
-                    ReadDouble();
-                    break;
-                case BsonType.Int32:
-                    ReadInt32();
-                    break;
-                case BsonType.Int64:
-                    ReadInt64();
-                    break;
-                case BsonType.JavaScript:
-                    ReadJavaScript();
-                    break;
-                case BsonType.JavaScriptWithScope:
-                    ReadJavaScriptWithScope();
-                    ReadStartDocument();
-                    while (ReadBsonType() != BsonType.EndOfDocument)
-                    {
-                        SkipName();
-                        SkipValue();
-                    }
-                    ReadEndDocument();
-                    break;
-                case BsonType.MaxKey:
-                    ReadMaxKey();
-                    break;
-                case BsonType.MinKey:
-                    ReadMinKey();
-                    break;
-                case BsonType.Null:
-                    ReadNull();
-                    break;
-                case BsonType.ObjectId:
-                    ReadObjectId();
-                    break;
-                case BsonType.RegularExpression:
-                    ReadRegularExpression();
-                    break;
-                case BsonType.String:
-                    ReadString();
-                    break;
-                case BsonType.Symbol:
-                    ReadSymbol();
-                    break;
-                case BsonType.Timestamp:
-                    ReadTimestamp();
-                    break;
-                case BsonType.Undefined:
-                    ReadUndefined();
-                    break;
-                default:
-                    throw new BsonInternalException("Invalid BsonType.");
-            }
-        }
-
-        // protected methods
-        /// <summary>
-        /// Disposes of any resources used by the reader.
-        /// </summary>
-        /// <param name="disposing">True if called from Dispose.</param>
-        protected override void Dispose(bool disposing)
-        {
-            if (disposing)
-            {
-                try
-                {
-                    Close();
-                }
-                catch { } // ignore exceptions
-            }
-            base.Dispose(disposing);
-        }
-
-        // private methods
-        private string FormatInvalidTokenMessage(JsonToken token)
-        {
-            return string.Format("Invalid JSON token: '{0}'", token.Lexeme);
-        }
-
-        private string FormatJavaScriptDateTimeString(DateTime dateTime)
-        {
-            var utc = BsonUtils.ToUniversalTime(dateTime);
-            var local = BsonUtils.ToLocalTime(utc);
-            var offset = local - utc;
-            var offsetSign = "+";
-            if (offset < TimeSpan.Zero)
-            {
-                offset = -offset;
-                offsetSign = "-";
-            }
-            var timeZone = TimeZoneInfo.Local;
-            var timeZoneName = local.IsDaylightSavingTime() ? timeZone.DaylightName : timeZone.StandardName;
-            var dateTimeString = string.Format(
-                "{0} GMT{1}{2:D2}{3:D2} ({4})",
-                local.ToString("ddd MMM dd yyyy HH:mm:ss"), offsetSign, offset.Hours, offset.Minutes, timeZoneName);
-            return dateTimeString;
-        }
-
-        private BsonReaderState GetNextState()
-        {
-            switch (_context.ContextType)
-            {
-                case ContextType.Array:
-                case ContextType.Document:
-                    return BsonReaderState.Type;
-                case ContextType.TopLevel:
-                    return BsonReaderState.Initial;
-                default:
-                    throw new BsonInternalException("Unexpected ContextType.");
-            }
-        }
-
-        private BsonValue ParseBinDataConstructor()
-        {
-            VerifyToken("(");
-            var subTypeToken = PopToken();
-            if (subTypeToken.Type != JsonTokenType.Int32)
-            {
-                var message = string.Format("JSON reader expected a binary subtype but found '{0}'.", subTypeToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken(",");
-            var bytesToken = PopToken();
-            if (bytesToken.Type != JsonTokenType.String)
-            {
-                var message = string.Format("JSON reader expected a string but found '{0}'.", bytesToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken(")");
-            var bytes = Convert.FromBase64String(bytesToken.StringValue);
-            var subType = (BsonBinarySubType)subTypeToken.Int32Value;
-            GuidRepresentation guidRepresentation;
-            switch (subType)
-            {
-                case BsonBinarySubType.UuidLegacy: guidRepresentation = _jsonReaderSettings.GuidRepresentation; break;
-                case BsonBinarySubType.UuidStandard: guidRepresentation = GuidRepresentation.Standard; break;
-                default: guidRepresentation = GuidRepresentation.Unspecified; break;
-            }
-            return new BsonBinaryData(bytes, subType, guidRepresentation);
-        }
-
-        private BsonValue ParseBinDataExtendedJson()
-        {
-            VerifyToken(":");
-
-            var bytesToken = PopToken();
-            if (bytesToken.Type != JsonTokenType.String)
-            {
-                var message = string.Format("JSON reader expected a string but found '{0}'.", bytesToken.Lexeme);
-                throw new FormatException(message);
-            }
-            var bytes = Convert.FromBase64String(bytesToken.StringValue);
-
-            VerifyToken(",");
-            VerifyString("$type");
-            VerifyToken(":");
-
-            BsonBinarySubType subType;
-            var subTypeToken = PopToken();
-            if (subTypeToken.Type == JsonTokenType.String)
-            {
-                subType = (BsonBinarySubType)Convert.ToInt32(subTypeToken.StringValue, 16);
-            }
-            else if (subTypeToken.Type == JsonTokenType.Int32 || subTypeToken.Type == JsonTokenType.Int64)
-            {
-                subType = (BsonBinarySubType)subTypeToken.Int32Value;
-            }
-            else
-            {
-                var message = string.Format("JSON reader expected a string or integer but found '{0}'.", subTypeToken.Lexeme);
-                throw new FormatException(message);
-            }
-
-            VerifyToken("}");
-
-            GuidRepresentation guidRepresentation;
-            switch (subType)
-            {
-                case BsonBinarySubType.UuidLegacy: guidRepresentation = _jsonReaderSettings.GuidRepresentation; break;
-                case BsonBinarySubType.UuidStandard: guidRepresentation = GuidRepresentation.Standard; break;
-                default: guidRepresentation = GuidRepresentation.Unspecified; break;
-            }
-
-            return new BsonBinaryData(bytes, subType, guidRepresentation);
-        }
-
-        private BsonValue ParseHexDataConstructor()
-        {
-            VerifyToken("(");
-            var subTypeToken = PopToken();
-            if (subTypeToken.Type != JsonTokenType.Int32)
-            {
-                var message = string.Format("JSON reader expected a binary subtype but found '{0}'.", subTypeToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken(",");
-            var bytesToken = PopToken();
-            if (bytesToken.Type != JsonTokenType.String)
-            {
-                var message = string.Format("JSON reader expected a string but found '{0}'.", bytesToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken(")");
-            var bytes = BsonUtils.ParseHexString(bytesToken.StringValue);
-            var subType = (BsonBinarySubType)subTypeToken.Int32Value;
-            GuidRepresentation guidRepresentation;
-            switch (subType)
-            {
-                case BsonBinarySubType.UuidLegacy: guidRepresentation = _jsonReaderSettings.GuidRepresentation; break;
-                case BsonBinarySubType.UuidStandard: guidRepresentation = GuidRepresentation.Standard; break;
-                default: guidRepresentation = GuidRepresentation.Unspecified; break;
-            }
-            return new BsonBinaryData(bytes, subType, guidRepresentation);
-        }
-
-        private BsonType ParseJavaScriptExtendedJson(out BsonValue value)
-        {
-            VerifyToken(":");
-            var codeToken = PopToken();
-            if (codeToken.Type != JsonTokenType.String)
-            {
-                var message = string.Format("JSON reader expected a string but found '{0}'.", codeToken.Lexeme);
-                throw new FormatException(message);
-            }
-            var nextToken = PopToken();
-            switch (nextToken.Type)
-            {
-                case JsonTokenType.Comma:
-                    VerifyString("$scope");
-                    VerifyToken(":");
-                    State = BsonReaderState.Value;
-                    value = codeToken.StringValue;
-                    return BsonType.JavaScriptWithScope;
-                case JsonTokenType.EndObject:
-                    value = codeToken.StringValue;
-                    return BsonType.JavaScript;
-                default:
-                    var message = string.Format("JSON reader expected ',' or '}}' but found '{0}'.", codeToken.Lexeme);
-                    throw new FormatException(message);
-            }
-        }
-
-        private BsonValue ParseISODateTimeConstructor()
-        {
-            VerifyToken("(");
-            var valueToken = PopToken();
-            if (valueToken.Type != JsonTokenType.String)
-            {
-                var message = string.Format("JSON reader expected a string but found '{0}'.", valueToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken(")");
-            var value = valueToken.StringValue;
-            string[] formats = null;
-            if (!value.Contains(".") && value.Length < __fixedLengthIso8601Formats.Length)
-            {
-                formats = __fixedLengthIso8601Formats[value.Length];
-            }
-            if (formats == null)
-            {
-                formats = __variableLengthIso8601Formats;
-            }
-            var utcDateTime = DateTime.ParseExact(value, formats, null, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);
-            return new BsonDateTime(utcDateTime);
-        }
-
-        private BsonValue ParseDateTimeExtendedJson()
-        {
-            VerifyToken(":");
-            var valueToken = PopToken();
-
-            long millisecondsSinceEpoch;
-            if (valueToken.Type == JsonTokenType.Int32 || valueToken.Type == JsonTokenType.Int64)
-            {
-                millisecondsSinceEpoch = valueToken.Int64Value;
-            }
-            else if (valueToken.Type == JsonTokenType.String)
-            {
-                DateTime dateTime;
-                var dateTimeStyles = DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal;
-                if (!DateTime.TryParse(valueToken.StringValue, CultureInfo.InvariantCulture, dateTimeStyles, out dateTime))
-                {
-                    var message = string.Format("Invalid $date string: '{0}'.", valueToken.StringValue);
-                    throw new FormatException(message);
-                }
-                millisecondsSinceEpoch = BsonUtils.ToMillisecondsSinceEpoch(dateTime);
-            }
-            else if (valueToken.Type == JsonTokenType.BeginObject)
-            {
-                VerifyToken("$numberLong");
-                VerifyToken(":");
-                var millisecondsSinceEpochToken = PopToken();
-                if (millisecondsSinceEpochToken.Type == JsonTokenType.String)
-                {
-                    millisecondsSinceEpoch = long.Parse(millisecondsSinceEpochToken.StringValue, CultureInfo.InvariantCulture);
-                }
-                else if (millisecondsSinceEpochToken.Type == JsonTokenType.Int32 || millisecondsSinceEpochToken.Type == JsonTokenType.Int64)
-                {
-                    millisecondsSinceEpoch = millisecondsSinceEpochToken.Int64Value;
-                }
-                else
-                {
-                    var message = string.Format("JSON reader expected an integer or a string for {{ $date : {{ $numberLong : ... }} }} but found a '{0}'.", valueToken.Lexeme);
-                    throw new FormatException(message);
-                }
-                VerifyToken("}");
-            }
-            else
-            {
-                var message = string.Format("JSON reader expected an ISO 8601 string, an integer, or {{ $numberLong : ... }} for $date but found a '{0}'.", valueToken.Lexeme);
-                throw new FormatException(message);
-            }
-
-            VerifyToken("}");
-            return new BsonDateTime(millisecondsSinceEpoch);
-        }
-
-        private BsonValue ParseDateTimeConstructor(bool withNew)
-        {
-            VerifyToken("(");
-
-            // Date when used without "new" behaves differently (JavaScript has some weird parts)
-            if (!withNew)
-            {
-                VerifyToken(")");
-                var dateTimeString = FormatJavaScriptDateTimeString(DateTime.UtcNow);
-                return new BsonString(dateTimeString);
-            }
-
-            var token = PopToken();
-            if (token.Lexeme == ")")
-            {
-                return new BsonDateTime(DateTime.UtcNow);
-            }
-            else if (token.Type == JsonTokenType.String)
-            {
-                VerifyToken(")");
-                var dateTimeString = token.StringValue;
-                var dateTime = ParseJavaScriptDateTimeString(dateTimeString);
-                return new BsonDateTime(dateTime);
-            }
-            else if (token.Type == JsonTokenType.Int32 || token.Type == JsonTokenType.Int64)
-            {
-                var args = new List<long>();
-                while (true)
-                {
-                    args.Add(token.Int64Value);
-                    token = PopToken();
-                    if (token.Lexeme == ")")
-                    {
-                        break;
-                    }
-                    if (token.Lexeme != ",")
-                    {
-                        var message = string.Format("JSON reader expected a ',' or a ')' but found '{0}'.", token.Lexeme);
-                        throw new FormatException(message);
-                    }
-                    token = PopToken();
-                    if (token.Type != JsonTokenType.Int32 && token.Type != JsonTokenType.Int64)
-                    {
-                        var message = string.Format("JSON reader expected an integer but found '{0}'.", token.Lexeme);
-                        throw new FormatException(message);
-                    }
-                }
-                switch (args.Count)
-                {
-                    case 1:
-                        return new BsonDateTime(args[0]);
-                    case 3:
-                    case 4:
-                    case 5:
-                    case 6:
-                    case 7:
-                        var year = (int)args[0];
-                        var month = (int)args[1] + 1; // JavaScript starts at 0 but .NET starts at 1
-                        var day = (int)args[2];
-                        var hours = (args.Count >= 4) ? (int)args[3] : 0;
-                        var minutes = (args.Count >= 5) ? (int)args[4] : 0;
-                        var seconds = (args.Count >= 6) ? (int)args[5] : 0;
-                        var milliseconds = (args.Count == 7) ? (int)args[6] : 0;
-                        var dateTime = new DateTime(year, month, day, hours, minutes, seconds, milliseconds, DateTimeKind.Utc);
-                        return new BsonDateTime(dateTime);
-                    default:
-                        var message = string.Format("JSON reader expected 1 or 3-7 integers but found {0}.", args.Count);
-                        throw new FormatException(message);
-                }
-            }
-            else
-            {
-                var message = string.Format("JSON reader expected an integer or a string but found '{0}'.", token.Lexeme);
-                throw new FormatException(message);
-            }
-        }
-
-        private BsonType ParseExtendedJson()
-        {
-            var nameToken = PopToken();
-            if (nameToken.Type == JsonTokenType.String || nameToken.Type == JsonTokenType.UnquotedString)
-            {
-                switch (nameToken.StringValue)
-                {
-                    case "$binary": _currentValue = ParseBinDataExtendedJson(); return BsonType.Binary;
-                    case "$code": return ParseJavaScriptExtendedJson(out _currentValue);
-                    case "$date": _currentValue = ParseDateTimeExtendedJson(); return BsonType.DateTime;
-                    case "$maxkey": case "$maxKey": _currentValue = ParseMaxKeyExtendedJson(); return BsonType.MaxKey;
-                    case "$minkey": case "$minKey": _currentValue = ParseMinKeyExtendedJson(); return BsonType.MinKey;
-                    case "$numberDecimal": _currentValue = ParseNumberDecimalExtendedJson(); return BsonType.Decimal128;
-                    case "$numberInt": _currentValue = ParseNumberIntExtendedJson(); return BsonType.Int32;
-                    case "$numberLong": _currentValue = ParseNumberLongExtendedJson(); return BsonType.Int64;
-                    case "$oid": _currentValue = ParseObjectIdExtendedJson(); return BsonType.ObjectId;
-                    case "$regex": _currentValue = ParseRegularExpressionExtendedJson(); return BsonType.RegularExpression;
-                    case "$symbol": _currentValue = ParseSymbolExtendedJson(); return BsonType.Symbol;
-                    case "$timestamp": _currentValue = ParseTimestampExtendedJson(); return BsonType.Timestamp;
-                    case "$undefined": _currentValue = ParseUndefinedExtendedJson(); return BsonType.Undefined;
-                }
-            }
-            PushToken(nameToken);
-            return BsonType.Document;
-        }
-
-        private DateTime ParseJavaScriptDateTimeString(string dateTimeString)
-        {
-            // if DateTime.TryParse succeeds we're done, otherwise assume it's an RFC 822 formatted DateTime string
-            DateTime dateTime;
-            if (DateTime.TryParse(dateTimeString, out dateTime))
-            {
-                return dateTime;
-            }
-            else
-            {
-                var rfc822DateTimePattern =
-                    @"^((?<dayOfWeek>(Mon|Tue|Wed|Thu|Fri|Sat|Sun)), )?" +
-                    @"(?<day>\d{1,2}) +" +
-                    @"(?<monthName>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) " +
-                    @"(?<year>\d{2}|\d{4}) " +
-                    @"(?<hour>\d{1,2}):" +
-                    @"(?<minutes>\d{1,2}):" +
-                    @"(?<seconds>\d{1,2}(.\d{1,7})?) " +
-                    @"(?<zone>UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[A-Z]|([+-]\d{4}))$";
-                var match = Regex.Match(dateTimeString, rfc822DateTimePattern);
-                if (match.Success)
-                {
-                    var day = int.Parse(match.Groups["day"].Value);
-
-                    int month;
-                    var monthName = match.Groups["monthName"].Value;
-                    switch (monthName)
-                    {
-                        case "Jan": month = 1; break;
-                        case "Feb": month = 2; break;
-                        case "Mar": month = 3; break;
-                        case "Apr": month = 4; break;
-                        case "May": month = 5; break;
-                        case "Jun": month = 6; break;
-                        case "Jul": month = 7; break;
-                        case "Aug": month = 8; break;
-                        case "Sep": month = 9; break;
-                        case "Oct": month = 10; break;
-                        case "Nov": month = 11; break;
-                        case "Dec": month = 12; break;
-                        default:
-                            var message = string.Format("\"{0}\" is not a valid RFC 822 month name.", monthName);
-                            throw new FormatException(message);
-                    }
-
-                    var yearString = match.Groups["year"].Value;
-                    int year = int.Parse(yearString);
-                    if (yearString.Length == 2)
-                    {
-                        year += 2000;
-                        if (year - DateTime.UtcNow.Year >= 19) { year -= 100; }
-                    }
-
-                    var hour = int.Parse(match.Groups["hour"].Value);
-                    var minutes = int.Parse(match.Groups["minutes"].Value);
-                    var secondsString = match.Groups["seconds"].Value;
-                    int seconds;
-                    double milliseconds;
-                    if (secondsString.IndexOf('.') != -1)
-                    {
-                        var timeSpan = TimeSpan.FromSeconds(double.Parse(secondsString));
-                        seconds = timeSpan.Seconds;
-                        milliseconds = timeSpan.TotalMilliseconds - seconds * 1000;
-                    }
-                    else
-                    {
-                        seconds = int.Parse(secondsString);
-                        milliseconds = 0;
-                    }
-
-                    dateTime = new DateTime(year, month, day, hour, minutes, seconds, DateTimeKind.Utc).AddMilliseconds(milliseconds);
-
-                    // check day of week before converting to UTC
-                    var dayOfWeekString = match.Groups["dayOfWeek"].Value;
-                    if (dayOfWeekString != "")
-                    {
-                        DayOfWeek dayOfWeek;
-                        switch (dayOfWeekString)
-                        {
-                            case "Mon": dayOfWeek = DayOfWeek.Monday; break;
-                            case "Tue": dayOfWeek = DayOfWeek.Tuesday; break;
-                            case "Wed": dayOfWeek = DayOfWeek.Wednesday; break;
-                            case "Thu": dayOfWeek = DayOfWeek.Thursday; break;
-                            case "Fri": dayOfWeek = DayOfWeek.Friday; break;
-                            case "Sat": dayOfWeek = DayOfWeek.Saturday; break;
-                            case "Sun": dayOfWeek = DayOfWeek.Sunday; break;
-                            default:
-                                var message = string.Format("\"{0}\" is not a valid RFC 822 day name.", dayOfWeekString);
-                                throw new FormatException(message);
-                        }
-                        if (dateTime.DayOfWeek != dayOfWeek)
-                        {
-                            var message = string.Format("\"{0}\" is not the right day of the week for {1}.", dayOfWeekString, dateTime.ToString("o"));
-                            throw new FormatException(message);
-                        }
-                    }
-
-                    TimeSpan offset;
-                    var zone = match.Groups["zone"].Value;
-                    switch (zone)
-                    {
-                        case "UT": case "GMT": case "Z": offset = TimeSpan.Zero; break;
-                        case "EST": offset = TimeSpan.FromHours(-5); break;
-                        case "EDT": offset = TimeSpan.FromHours(-4); break;
-                        case "CST": offset = TimeSpan.FromHours(-6); break;
-                        case "CDT": offset = TimeSpan.FromHours(-5); break;
-                        case "MST": offset = TimeSpan.FromHours(-7); break;
-                        case "MDT": offset = TimeSpan.FromHours(-6); break;
-                        case "PST": offset = TimeSpan.FromHours(-8); break;
-                        case "PDT": offset = TimeSpan.FromHours(-7); break;
-                        case "A": offset = TimeSpan.FromHours(-1); break;
-                        case "B": offset = TimeSpan.FromHours(-2); break;
-                        case "C": offset = TimeSpan.FromHours(-3); break;
-                        case "D": offset = TimeSpan.FromHours(-4); break;
-                        case "E": offset = TimeSpan.FromHours(-5); break;
-                        case "F": offset = TimeSpan.FromHours(-6); break;
-                        case "G": offset = TimeSpan.FromHours(-7); break;
-                        case "H": offset = TimeSpan.FromHours(-8); break;
-                        case "I": offset = TimeSpan.FromHours(-9); break;
-                        case "K": offset = TimeSpan.FromHours(-10); break;
-                        case "L": offset = TimeSpan.FromHours(-11); break;
-                        case "M": offset = TimeSpan.FromHours(-12); break;
-                        case "N": offset = TimeSpan.FromHours(1); break;
-                        case "O": offset = TimeSpan.FromHours(2); break;
-                        case "P": offset = TimeSpan.FromHours(3); break;
-                        case "Q": offset = TimeSpan.FromHours(4); break;
-                        case "R": offset = TimeSpan.FromHours(5); break;
-                        case "S": offset = TimeSpan.FromHours(6); break;
-                        case "T": offset = TimeSpan.FromHours(7); break;
-                        case "U": offset = TimeSpan.FromHours(8); break;
-                        case "V": offset = TimeSpan.FromHours(9); break;
-                        case "W": offset = TimeSpan.FromHours(10); break;
-                        case "X": offset = TimeSpan.FromHours(11); break;
-                        case "Y": offset = TimeSpan.FromHours(12); break;
-                        default:
-                            var offsetSign = zone.Substring(0);
-                            var offsetHours = zone.Substring(1, 2);
-                            var offsetMinutes = zone.Substring(3, 2);
-                            offset = TimeSpan.FromHours(int.Parse(offsetHours)) + TimeSpan.FromMinutes(int.Parse(offsetMinutes));
-                            if (offsetSign == "-")
-                            {
-                                offset = -offset;
-                            }
-                            break;
-                    }
-
-                    return dateTime.Add(-offset);
-                }
-                else
-                {
-                    var message = string.Format("The DateTime string \"{0}\" is not a valid DateTime string for either .NET or JavaScript.", dateTimeString);
-                    throw new FormatException(message);
-                }
-            }
-        }
-
-        private BsonValue ParseMaxKeyExtendedJson()
-        {
-            VerifyToken(":");
-            VerifyToken("1");
-            VerifyToken("}");
-            return BsonMaxKey.Value;
-        }
-
-        private BsonValue ParseMinKeyExtendedJson()
-        {
-            VerifyToken(":");
-            VerifyToken("1");
-            VerifyToken("}");
-            return BsonMinKey.Value;
-        }
-
-        private BsonType ParseNew(out BsonValue value)
-        {
-            var typeToken = PopToken();
-            if (typeToken.Type != JsonTokenType.UnquotedString)
-            {
-                var message = string.Format("JSON reader expected a type name but found '{0}'.", typeToken.Lexeme);
-                throw new FormatException(message);
-            }
-            switch (typeToken.Lexeme)
-            {
-                case "BinData":
-                    value = ParseBinDataConstructor();
-                    return BsonType.Binary;
-                case "Date":
-                    value = ParseDateTimeConstructor(true); // withNew = true
-                    return BsonType.DateTime;
-                case "HexData":
-                    value = ParseHexDataConstructor();
-                    return BsonType.Binary;
-                case "ISODate":
-                    value = ParseISODateTimeConstructor();
-                    return BsonType.DateTime;
-                case "NumberDecimal":
-                    value = ParseNumberDecimalConstructor();
-                    return BsonType.Decimal128;
-                case "NumberInt":
-                    value = ParseNumberConstructor();
-                    return BsonType.Int32;
-                case "NumberLong":
-                    value = ParseNumberLongConstructor();
-                    return BsonType.Int64;
-                case "ObjectId":
-                    value = ParseObjectIdConstructor();
-                    return BsonType.ObjectId;
-                case "RegExp":
-                    value = ParseRegularExpressionConstructor();
-                    return BsonType.RegularExpression;
-                case "Timestamp":
-                    value = ParseTimestampConstructor();
-                    return BsonType.Timestamp;
-                case "UUID":
-                case "GUID":
-                case "CSUUID":
-                case "CSGUID":
-                case "JUUID":
-                case "JGUID":
-                case "PYUUID":
-                case "PYGUID":
-                    value = ParseUUIDConstructor(typeToken.Lexeme);
-                    return BsonType.Binary;
-                default:
-                    var message = string.Format("JSON reader expected a type name but found '{0}'.", typeToken.Lexeme);
-                    throw new FormatException(message);
-            }
-        }
-
-        private BsonValue ParseNumberConstructor()
-        {
-            VerifyToken("(");
-            var valueToken = PopToken();
-            int value;
-            if (valueToken.IsNumber)
-            {
-                value = valueToken.Int32Value;
-            }
-            else if (valueToken.Type == JsonTokenType.String)
-            {
-                value = int.Parse(valueToken.StringValue);
-            }
-            else
-            {
-                var message = string.Format("JSON reader expected an integer or a string but found '{0}'.", valueToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken(")");
-            return (BsonInt32)value;
-        }
-
-        private BsonValue ParseNumberDecimalConstructor()
-        {
-            VerifyToken("(");
-            var valueToken = PopToken();
-            Decimal128 value;
-            if (valueToken.Type == JsonTokenType.String)
-            {
-                value = Decimal128.Parse(valueToken.StringValue);
-            }
-            else if (valueToken.Type == JsonTokenType.Int32 || valueToken.Type == JsonTokenType.Int64)
-            {
-                value = new Decimal128(valueToken.Int64Value);
-            }
-            else
-            {
-                var message = string.Format("JSON reader expected an integer or a string but found '{0}'.", valueToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken(")");
-            return (BsonDecimal128)value;
-        }
-
-        private BsonValue ParseNumberLongConstructor()
-        {
-            VerifyToken("(");
-            var valueToken = PopToken();
-            long value;
-            if (valueToken.Type == JsonTokenType.Int32 || valueToken.Type == JsonTokenType.Int64)
-            {
-                value = valueToken.Int64Value;
-            }
-            else if (valueToken.Type == JsonTokenType.String)
-            {
-                value = long.Parse(valueToken.StringValue);
-            }
-            else
-            {
-                var message = string.Format("JSON reader expected an integer or a string but found '{0}'.", valueToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken(")");
-            return (BsonInt64)value;
-        }
-
-        private BsonValue ParseNumberDecimalExtendedJson()
-        {
-            VerifyToken(":");
-
-            Decimal128 value;
-            var valueToken = PopToken();
-            if (valueToken.Type == JsonTokenType.String)
-            {
-                value = Decimal128.Parse(valueToken.StringValue);
-            }
-            else if (valueToken.Type == JsonTokenType.Int32 || valueToken.Type == JsonTokenType.Int64)
-            {
-                value = new Decimal128(valueToken.Int64Value);
-            }
-            else
-            {
-                var message = string.Format("JSON reader expected a string or an integer but found '{0}'.", valueToken.Lexeme);
-                throw new FormatException(message);
-            }
-
-            VerifyToken("}");
-            return (BsonDecimal128)value;
-        }
-
-        private BsonValue ParseNumberIntExtendedJson()
-        {
-            VerifyToken(":");
-
-            int value;
-            var valueToken = PopToken();
-            if (valueToken.Type == JsonTokenType.Int32)
-            {
-                value = valueToken.Int32Value;
-            }
-            else if (valueToken.Type == JsonTokenType.String)
-            {
-                value = JsonConvert.ToInt32(valueToken.StringValue);
-            }
-            else
-            {
-                var message = string.Format("JSON reader expected an integer but found '{0}'.", valueToken.Lexeme);
-                throw new FormatException(message);
-            }
-
-            VerifyToken("}");
-            return (BsonInt32)value;
-        }
-
-        private BsonValue ParseNumberLongExtendedJson()
-        {
-            VerifyToken(":");
-
-            long value;
-            var valueToken = PopToken();
-            if (valueToken.Type == JsonTokenType.String)
-            {
-                value = long.Parse(valueToken.StringValue, CultureInfo.InvariantCulture);
-            }
-            else if (valueToken.Type == JsonTokenType.Int32 || valueToken.Type == JsonTokenType.Int64)
-            {
-                value = valueToken.Int64Value;
-            }
-            else
-            {
-                var message = string.Format("JSON reader expected a string or an integer but found '{0}'.", valueToken.Lexeme);
-                throw new FormatException(message);
-            }
-
-            VerifyToken("}");
-            return (BsonInt64)value;
-        }
-
-        private BsonValue ParseObjectIdConstructor()
-        {
-            VerifyToken("(");
-            var valueToken = PopToken();
-            if (valueToken.Type != JsonTokenType.String)
-            {
-                var message = string.Format("JSON reader expected a string but found '{0}'.", valueToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken(")");
-            return new BsonObjectId(ObjectId.Parse(valueToken.StringValue));
-        }
-
-        private BsonValue ParseObjectIdExtendedJson()
-        {
-            VerifyToken(":");
-            var valueToken = PopToken();
-            if (valueToken.Type != JsonTokenType.String)
-            {
-                var message = string.Format("JSON reader expected a string but found '{0}'.", valueToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken("}");
-            return new BsonObjectId(ObjectId.Parse(valueToken.StringValue));
-        }
-
-        private BsonValue ParseRegularExpressionConstructor()
-        {
-            VerifyToken("(");
-            var patternToken = PopToken();
-            if (patternToken.Type != JsonTokenType.String)
-            {
-                var message = string.Format("JSON reader expected a string but found '{0}'.", patternToken.Lexeme);
-                throw new FormatException(message);
-            }
-            var options = "";
-            var commaToken = PopToken();
-            if (commaToken.Lexeme == ",")
-            {
-                var optionsToken = PopToken();
-                if (optionsToken.Type != JsonTokenType.String)
-                {
-                    var message = string.Format("JSON reader expected a string but found '{0}'.", optionsToken.Lexeme);
-                    throw new FormatException(message);
-                }
-                options = optionsToken.StringValue;
-            }
-            else
-            {
-                PushToken(commaToken);
-            }
-            VerifyToken(")");
-            return new BsonRegularExpression(patternToken.StringValue, options);
-        }
-
-        private BsonValue ParseRegularExpressionExtendedJson()
-        {
-            VerifyToken(":");
-            var patternToken = PopToken();
-            if (patternToken.Type != JsonTokenType.String)
-            {
-                var message = string.Format("JSON reader expected a string but found '{0}'.", patternToken.Lexeme);
-                throw new FormatException(message);
-            }
-            var options = "";
-            var commaToken = PopToken();
-            if (commaToken.Lexeme == ",")
-            {
-                VerifyString("$options");
-                VerifyToken(":");
-                var optionsToken = PopToken();
-                if (optionsToken.Type != JsonTokenType.String)
-                {
-                    var message = string.Format("JSON reader expected a string but found '{0}'.", optionsToken.Lexeme);
-                    throw new FormatException(message);
-                }
-                options = optionsToken.StringValue;
-            }
-            else
-            {
-                PushToken(commaToken);
-            }
-            VerifyToken("}");
-            return new BsonRegularExpression(patternToken.StringValue, options);
-        }
-
-        private BsonValue ParseSymbolExtendedJson()
-        {
-            VerifyToken(":");
-            var nameToken = PopToken();
-            if (nameToken.Type != JsonTokenType.String)
-            {
-                var message = string.Format("JSON reader expected a string but found '{0}'.", nameToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken("}");
-            return (BsonString)nameToken.StringValue; // will be converted to a BsonSymbol at a higher level
-        }
-
-        private BsonValue ParseTimestampConstructor()
-        {
-            VerifyToken("(");
-            int secondsSinceEpoch;
-            var secondsSinceEpochToken = PopToken();
-            if (secondsSinceEpochToken.IsNumber)
-            {
-                secondsSinceEpoch = secondsSinceEpochToken.Int32Value;
-            }
-            else
-            {
-                var message = string.Format("JSON reader expected a number but found '{0}'.", secondsSinceEpochToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken(",");
-            int increment;
-            var incrementToken = PopToken();
-            if (secondsSinceEpochToken.IsNumber)
-            {
-                increment = incrementToken.Int32Value;
-            }
-            else
-            {
-                var message = string.Format("JSON reader expected a number but found '{0}'.", secondsSinceEpochToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken(")");
-            return new BsonTimestamp(secondsSinceEpoch, increment);
-        }
-
-        private BsonValue ParseTimestampExtendedJson()
-        {
-            VerifyToken(":");
-            var nextToken = PopToken();
-            if (nextToken.Type == JsonTokenType.BeginObject)
-            {
-                return ParseTimestampExtendedJsonNewRepresentation();
-            }
-            else
-            {
-                return ParseTimestampExtendedJsonOldRepresentation(nextToken);
-            }
-        }
-
-        private BsonValue ParseTimestampExtendedJsonNewRepresentation()
-        {
-            int? timestamp = null;
-            int? increment = null;
-
-            while (true)
-            {
-                var token = PopToken();
-                if (token.Type != JsonTokenType.String && token.Type != JsonTokenType.UnquotedString)
-                {
-                    throw new FormatException($"JSON reader expected an element name but found '{token.Lexeme}'.");
-                }
-                var name = token.StringValue;
-
-                token = PopToken();
-                if (token.Type != JsonTokenType.Colon)
-                {
-                    throw new FormatException($"JSON reader expected ':' but found '{name}'.");
-                }
-
-                token = PopToken();
-                if (token.Type != JsonTokenType.Int32)
-                {
-                    throw new FormatException($"JSON reader expected an integer but found '{token.Lexeme}'.");
-                }
-                var value = token.Int32Value;
-
-                switch (name)
-                {
-                    case "t":
-                        timestamp = value;
-                        break;
-
-                    case "i":
-                        increment = value;
-                        break;
-
-                    default:
-                        throw new FormatException($"JSON reader expected 't' or 'i' element names but found '{name}'.");
-                }
-
-                token = PopToken();
-                if (token.Type == JsonTokenType.Comma)
-                {
-                    continue;
-                }
-                else if (token.Type == JsonTokenType.EndObject)
-                {
-                    break;
-                }
-                else
-                {
-                    throw new FormatException($"JSON reader expected ',' or '}}'  but found '{token.Lexeme}'.");
-                }
-            }
-            VerifyToken("}");
-
-            if (!timestamp.HasValue)
-            {
-                throw new FormatException("JSON reader did not find the required \"t\" element.");
-            }
-            if (!increment.HasValue)
-            {
-                throw new FormatException("JSON reader did not find the required \"i\" element.");
-            }
-
-            return new BsonTimestamp(timestamp.Value, increment.Value);
-        }
-
-        private BsonValue ParseTimestampExtendedJsonOldRepresentation(JsonToken valueToken)
-        {
-            long value;
-            if (valueToken.Type == JsonTokenType.Int32 || valueToken.Type == JsonTokenType.Int64)
-            {
-                value = valueToken.Int64Value;
-            }
-            else if (valueToken.Type == JsonTokenType.UnquotedString && valueToken.Lexeme == "NumberLong")
-            {
-                value = ParseNumberLongConstructor().AsInt64;
-            }
-            else
-            {
-                var message = string.Format("JSON reader expected an integer but found '{0}'.", valueToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken("}");
-            return new BsonTimestamp(value);
-        }
-
-        private BsonValue ParseUndefinedExtendedJson()
-        {
-            VerifyToken(":");
-            VerifyToken("true");
-            VerifyToken("}");
-            return BsonMaxKey.Value;
-        }
-
-        private BsonValue ParseUUIDConstructor(string uuidConstructorName)
-        {
-            VerifyToken("(");
-            var bytesToken = PopToken();
-            if (bytesToken.Type != JsonTokenType.String)
-            {
-                var message = string.Format("JSON reader expected a string but found '{0}'.", bytesToken.Lexeme);
-                throw new FormatException(message);
-            }
-            VerifyToken(")");
-            var hexString = bytesToken.StringValue.Replace("{", "").Replace("}", "").Replace("-", "");
-            var bytes = BsonUtils.ParseHexString(hexString);
-            var guid = GuidConverter.FromBytes(bytes, GuidRepresentation.Standard);
-            GuidRepresentation guidRepresentation;
-            switch (uuidConstructorName)
-            {
-                case "CSUUID":
-                case "CSGUID":
-                    guidRepresentation = GuidRepresentation.CSharpLegacy;
-                    break;
-                case "JUUID":
-                case "JGUID":
-                    guidRepresentation = GuidRepresentation.JavaLegacy;
-                    break;
-                case "PYUUID":
-                case "PYGUID":
-                    guidRepresentation = GuidRepresentation.PythonLegacy;
-                    break;
-                case "UUID":
-                case "GUID":
-                    guidRepresentation = GuidRepresentation.Standard;
-                    break;
-                default:
-                    throw new BsonInternalException("Unexpected uuidConstructorName");
-            }
-            bytes = GuidConverter.ToBytes(guid, guidRepresentation);
-            var subType = (guidRepresentation == GuidRepresentation.Standard) ? BsonBinarySubType.UuidStandard : BsonBinarySubType.UuidLegacy;
-            return new BsonBinaryData(bytes, subType, guidRepresentation);
-        }
-
-        private JsonToken PopToken()
-        {
-            if (_pushedToken != null)
-            {
-                var token = _pushedToken;
-                _pushedToken = null;
-                return token;
-            }
-            else
-            {
-                return JsonScanner.GetNextToken(_buffer);
-            }
-        }
-
-        private void PushToken(JsonToken token)
-        {
-            if (_pushedToken == null)
-            {
-                _pushedToken = token;
-            }
-            else
-            {
-                throw new BsonInternalException("There is already a pending token.");
-            }
-        }
-
-        private void VerifyString(string expectedString)
-        {
-            var token = PopToken();
-            if ((token.Type != JsonTokenType.String && token.Type != JsonTokenType.UnquotedString) || token.StringValue != expectedString)
-            {
-                var message = string.Format("JSON reader expected '{0}' but found '{1}'.", expectedString, token.StringValue);
-                throw new FormatException(message);
-            }
-        }
-
-        private void VerifyToken(string expectedLexeme)
-        {
-            var token = PopToken();
-            if (token.Lexeme != expectedLexeme)
-            {
-                var message = string.Format("JSON reader expected '{0}' but found '{1}'.", expectedLexeme, token.Lexeme);
-                throw new FormatException(message);
-            }
-        }
-    }
-}

+ 0 - 76
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonReaderBookmark.cs

@@ -1,76 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a bookmark that can be used to return a reader to the current position and state.
-    /// </summary>
-    public class JsonReaderBookmark : BsonReaderBookmark
-    {
-        // private fields
-        private JsonReaderContext _context;
-        private JsonToken _currentToken;
-        private BsonValue _currentValue;
-        private JsonToken _pushedToken;
-        private int _position;
-
-        // constructors
-        internal JsonReaderBookmark(
-            BsonReaderState state,
-            BsonType currentBsonType,
-            string currentName,
-            JsonReaderContext context,
-            JsonToken currentToken,
-            BsonValue currentValue,
-            JsonToken pushedToken,
-            int position)
-            : base(state, currentBsonType, currentName)
-        {
-            _context = context.Clone();
-            _currentToken = currentToken;
-            _currentValue = currentValue;
-            _pushedToken = pushedToken;
-            _position = position;
-        }
-
-        // internal properties
-        internal JsonToken CurrentToken
-        {
-            get { return _currentToken; }
-        }
-
-        internal BsonValue CurrentValue
-        {
-            get { return _currentValue; }
-        }
-
-        internal int Position
-        {
-            get { return _position; }
-        }
-
-        internal JsonToken PushedToken
-        {
-            get { return _pushedToken; }
-        }
-
-        // internal methods
-        internal JsonReaderContext CloneContext()
-        {
-            return _context.Clone();
-        }
-    }
-}

+ 0 - 57
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonReaderContext.cs

@@ -1,57 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace MongoDB.Bson.IO
-{
-    internal class JsonReaderContext
-    {
-        // private fields
-        private JsonReaderContext _parentContext;
-        private ContextType _contextType;
-
-        // constructors
-        // used by Clone
-        private JsonReaderContext()
-        {
-        }
-
-        internal JsonReaderContext(JsonReaderContext parentContext, ContextType contextType)
-        {
-            _parentContext = parentContext;
-            _contextType = contextType;
-        }
-
-        // internal properties
-        internal ContextType ContextType
-        {
-            get { return _contextType; }
-        }
-
-        // public methods
-        /// <summary>
-        /// Creates a clone of the context.
-        /// </summary>
-        /// <returns>A clone of the context.</returns>
-        public JsonReaderContext Clone()
-        {
-            return new JsonReaderContext(_parentContext, _contextType);
-        }
-
-        public JsonReaderContext PopContext()
-        {
-            return _parentContext;
-        }
-    }
-}

+ 0 - 81
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonReaderSettings.cs

@@ -1,81 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents settings for a JsonReader.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class JsonReaderSettings : BsonReaderSettings
-    {
-        // private static fields
-        private static JsonReaderSettings __defaults = null; // delay creation to pick up the latest default values
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the JsonReaderSettings class.
-        /// </summary>
-        public JsonReaderSettings()
-        {
-        }
-
-        // public static properties
-        /// <summary>
-        /// Gets or sets the default settings for a JsonReader.
-        /// </summary>
-        public static JsonReaderSettings Defaults
-        {
-            get
-            {
-                if (__defaults == null)
-                {
-                    __defaults = new JsonReaderSettings();
-                }
-                return __defaults;
-            }
-            set { __defaults = value; }
-        }
-
-        // public properties
-        // public methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        public new JsonReaderSettings Clone()
-        {
-            return (JsonReaderSettings)CloneImplementation();
-        }
-
-        // protected methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        protected override BsonReaderSettings CloneImplementation()
-        {
-            var clone = new JsonReaderSettings
-            {
-                GuidRepresentation = GuidRepresentation
-            };
-            return clone;
-        }
-    }
-}

+ 0 - 523
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonScanner.cs

@@ -1,523 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-using System.Text;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// A static class that represents a JSON scanner.
-    /// </summary>
-    internal static class JsonScanner
-    {
-        // public static methods
-        /// <summary>
-        /// Gets the next JsonToken from a JsonBuffer.
-        /// </summary>
-        /// <param name="buffer">The buffer.</param>
-        /// <returns>The next token.</returns>
-        public static JsonToken GetNextToken(JsonBuffer buffer)
-        {
-            // skip leading whitespace
-            var c = buffer.Read();
-            while (c != -1 && char.IsWhiteSpace((char)c))
-            {
-                c = buffer.Read();
-            }
-            if (c == -1)
-            {
-                return new JsonToken(JsonTokenType.EndOfFile, "<eof>");
-            }
-
-            // leading character determines token type
-            switch (c)
-            {
-                case '{': return new JsonToken(JsonTokenType.BeginObject, "{");
-                case '}': return new JsonToken(JsonTokenType.EndObject, "}");
-                case '[': return new JsonToken(JsonTokenType.BeginArray, "[");
-                case ']': return new JsonToken(JsonTokenType.EndArray, "]");
-                case '(': return new JsonToken(JsonTokenType.LeftParen, "(");
-                case ')': return new JsonToken(JsonTokenType.RightParen, ")");
-                case ':': return new JsonToken(JsonTokenType.Colon, ":");
-                case ',': return new JsonToken(JsonTokenType.Comma, ",");
-                case '\'':
-                case '"':
-                    return GetStringToken(buffer, (char)c);
-                case '/': return GetRegularExpressionToken(buffer);
-                default:
-                    if (c == '-' || char.IsDigit((char)c))
-                    {
-                        return GetNumberToken(buffer, c);
-                    }
-                    else if (c == '$' || c == '_' || char.IsLetter((char)c))
-                    {
-                        return GetUnquotedStringToken(buffer);
-                    }
-                    else
-                    {
-                        buffer.UnRead(c);
-                        throw new FormatException(FormatMessage("Invalid JSON input", buffer, buffer.Position));
-                    }
-            }
-        }
-
-        // private methods
-        private static string FormatMessage(string message, JsonBuffer buffer, int start)
-        {
-            var maxLength = 20;
-            var snippet = buffer.GetSnippet(start, maxLength);
-            return string.Format("{0} '{1}'.", message, snippet);
-        }
-
-        private static JsonToken GetNumberToken(JsonBuffer buffer, int firstChar)
-        {
-            var c = firstChar;
-
-            // leading digit or '-' has already been read
-            var start = buffer.Position - 1;
-            NumberState state;
-            switch (c)
-            {
-                case '-': state = NumberState.SawLeadingMinus; break;
-                case '0': state = NumberState.SawLeadingZero; break;
-                default: state = NumberState.SawIntegerDigits; break;
-            }
-            var type = JsonTokenType.Int64; // assume integer until proved otherwise
-
-            while (true)
-            {
-                c = buffer.Read();
-                switch (state)
-                {
-                    case NumberState.SawLeadingMinus:
-                        switch (c)
-                        {
-                            case '0':
-                                state = NumberState.SawLeadingZero;
-                                break;
-                            case 'I':
-                                state = NumberState.SawMinusI;
-                                break;
-                            default:
-                                if (char.IsDigit((char)c))
-                                {
-                                    state = NumberState.SawIntegerDigits;
-                                }
-                                else
-                                {
-                                    state = NumberState.Invalid;
-                                }
-                                break;
-                        }
-                        break;
-                    case NumberState.SawLeadingZero:
-                        switch (c)
-                        {
-                            case '.':
-                                state = NumberState.SawDecimalPoint;
-                                break;
-                            case 'e':
-                            case 'E':
-                                state = NumberState.SawExponentLetter;
-                                break;
-                            case ',':
-                            case '}':
-                            case ']':
-                            case ')':
-                            case -1:
-                                state = NumberState.Done;
-                                break;
-                            default:
-                                if (char.IsWhiteSpace((char)c))
-                                {
-                                    state = NumberState.Done;
-                                }
-                                else
-                                {
-                                    state = NumberState.Invalid;
-                                }
-                                break;
-                        }
-                        break;
-                    case NumberState.SawIntegerDigits:
-                        switch (c)
-                        {
-                            case '.':
-                                state = NumberState.SawDecimalPoint;
-                                break;
-                            case 'e':
-                            case 'E':
-                                state = NumberState.SawExponentLetter;
-                                break;
-                            case ',':
-                            case '}':
-                            case ']':
-                            case ')':
-                            case -1:
-                                state = NumberState.Done;
-                                break;
-                            default:
-                                if (char.IsDigit((char)c))
-                                {
-                                    state = NumberState.SawIntegerDigits;
-                                }
-                                else if (char.IsWhiteSpace((char)c))
-                                {
-                                    state = NumberState.Done;
-                                }
-                                else
-                                {
-                                    state = NumberState.Invalid;
-                                }
-                                break;
-                        }
-                        break;
-                    case NumberState.SawDecimalPoint:
-                        type = JsonTokenType.Double;
-                        if (char.IsDigit((char)c))
-                        {
-                            state = NumberState.SawFractionDigits;
-                        }
-                        else
-                        {
-                            state = NumberState.Invalid;
-                        }
-                        break;
-                    case NumberState.SawFractionDigits:
-                        switch (c)
-                        {
-                            case 'e':
-                            case 'E':
-                                state = NumberState.SawExponentLetter;
-                                break;
-                            case ',':
-                            case '}':
-                            case ']':
-                            case ')':
-                            case -1:
-                                state = NumberState.Done;
-                                break;
-                            default:
-                                if (char.IsDigit((char)c))
-                                {
-                                    state = NumberState.SawFractionDigits;
-                                }
-                                else if (char.IsWhiteSpace((char)c))
-                                {
-                                    state = NumberState.Done;
-                                }
-                                else
-                                {
-                                    state = NumberState.Invalid;
-                                }
-                                break;
-                        }
-                        break;
-                    case NumberState.SawExponentLetter:
-                        type = JsonTokenType.Double;
-                        switch (c)
-                        {
-                            case '+':
-                            case '-':
-                                state = NumberState.SawExponentSign;
-                                break;
-                            default:
-                                if (char.IsDigit((char)c))
-                                {
-                                    state = NumberState.SawExponentDigits;
-                                }
-                                else
-                                {
-                                    state = NumberState.Invalid;
-                                }
-                                break;
-                        }
-                        break;
-                    case NumberState.SawExponentSign:
-                        if (char.IsDigit((char)c))
-                        {
-                            state = NumberState.SawExponentDigits;
-                        }
-                        else
-                        {
-                            state = NumberState.Invalid;
-                        }
-                        break;
-                    case NumberState.SawExponentDigits:
-                        switch (c)
-                        {
-                            case ',':
-                            case '}':
-                            case ']':
-                            case ')':
-                            case -1:
-                                state = NumberState.Done;
-                                break;
-                            default:
-                                if (char.IsDigit((char)c))
-                                {
-                                    state = NumberState.SawExponentDigits;
-                                }
-                                else if (char.IsWhiteSpace((char)c))
-                                {
-                                    state = NumberState.Done;
-                                }
-                                else
-                                {
-                                    state = NumberState.Invalid;
-                                }
-                                break;
-                        }
-                        break;
-                    case NumberState.SawMinusI:
-                        var sawMinusInfinity = true;
-                        var nfinity = new char[] { 'n', 'f', 'i', 'n', 'i', 't', 'y' };
-                        for (var i = 0; i < nfinity.Length; i++)
-                        {
-                            if (c != nfinity[i])
-                            {
-                                sawMinusInfinity = false;
-                                break;
-                            }
-                            c = buffer.Read();
-                        }
-                        if (sawMinusInfinity)
-                        {
-                            type = JsonTokenType.Double;
-                            switch (c)
-                            {
-                                case ',':
-                                case '}':
-                                case ']':
-                                case ')':
-                                case -1:
-                                    state = NumberState.Done;
-                                    break;
-                                default:
-                                    if (char.IsWhiteSpace((char)c))
-                                    {
-                                        state = NumberState.Done;
-                                    }
-                                    else
-                                    {
-                                        state = NumberState.Invalid;
-                                    }
-                                    break;
-                            }
-                        }
-                        else
-                        {
-                            state = NumberState.Invalid;
-                        }
-                        break;
-                }
-
-                switch (state)
-                {
-                    case NumberState.Done:
-                        buffer.UnRead(c);
-                        var lexeme = buffer.GetSubstring(start, buffer.Position - start);
-                        if (type == JsonTokenType.Double)
-                        {
-                            var value = JsonConvert.ToDouble(lexeme);
-                            return new DoubleJsonToken(lexeme, value);
-                        }
-                        else
-                        {
-                            var value = JsonConvert.ToInt64(lexeme);
-                            if (value < int.MinValue || value > int.MaxValue)
-                            {
-                                return new Int64JsonToken(lexeme, value);
-                            }
-                            else
-                            {
-                                return new Int32JsonToken(lexeme, (int)value);
-                            }
-                        }
-                    case NumberState.Invalid:
-                        throw new FormatException(FormatMessage("Invalid JSON number", buffer, start));
-                }
-            }
-        }
-
-        private static JsonToken GetRegularExpressionToken(JsonBuffer buffer)
-        {
-            // opening slash has already been read
-            var start = buffer.Position - 1;
-            var state = RegularExpressionState.InPattern;
-            while (true)
-            {
-                var c = buffer.Read();
-                switch (state)
-                {
-                    case RegularExpressionState.InPattern:
-                        switch (c)
-                        {
-                            case '/': state = RegularExpressionState.InOptions; break;
-                            case '\\': state = RegularExpressionState.InEscapeSequence; break;
-                            default: state = RegularExpressionState.InPattern; break;
-                        }
-                        break;
-                    case RegularExpressionState.InEscapeSequence:
-                        state = RegularExpressionState.InPattern;
-                        break;
-                    case RegularExpressionState.InOptions:
-                        switch (c)
-                        {
-                            case 'i':
-                            case 'm':
-                            case 'x':
-                            case 's':
-                                state = RegularExpressionState.InOptions;
-                                break;
-                            case ',':
-                            case '}':
-                            case ']':
-                            case ')':
-                            case -1:
-                                state = RegularExpressionState.Done;
-                                break;
-                            default:
-                                if (char.IsWhiteSpace((char)c))
-                                {
-                                    state = RegularExpressionState.Done;
-                                }
-                                else
-                                {
-                                    state = RegularExpressionState.Invalid;
-                                }
-                                break;
-                        }
-                        break;
-                }
-
-                switch (state)
-                {
-                    case RegularExpressionState.Done:
-                        buffer.UnRead(c);
-                        var lexeme = buffer.GetSubstring(start, buffer.Position - start);
-                        var regex = new BsonRegularExpression(lexeme);
-                        return new RegularExpressionJsonToken(lexeme, regex);
-                    case RegularExpressionState.Invalid:
-                        throw new FormatException(FormatMessage("Invalid JSON regular expression", buffer, start));
-                }
-            }
-        }
-
-        private static JsonToken GetStringToken(JsonBuffer buffer, char quoteCharacter)
-        {
-            // opening quote has already been read
-            var start = buffer.Position - 1;
-            var sb = new StringBuilder();
-            while (true)
-            {
-                var c = buffer.Read();
-                switch (c)
-                {
-                    case '\\':
-                        c = buffer.Read();
-                        switch (c)
-                        {
-                            case '\'': sb.Append('\''); break;
-                            case '"': sb.Append('"'); break;
-                            case '\\': sb.Append('\\'); break;
-                            case '/': sb.Append('/'); break;
-                            case 'b': sb.Append('\b'); break;
-                            case 'f': sb.Append('\f'); break;
-                            case 'n': sb.Append('\n'); break;
-                            case 'r': sb.Append('\r'); break;
-                            case 't': sb.Append('\t'); break;
-                            case 'u':
-                                var u1 = buffer.Read();
-                                var u2 = buffer.Read();
-                                var u3 = buffer.Read();
-                                var u4 = buffer.Read();
-                                if (u4 != -1)
-                                {
-                                    var hex = new string(new char[] { (char)u1, (char)u2, (char)u3, (char)u4 });
-                                    var n = Convert.ToInt32(hex, 16);
-                                    sb.Append((char)n);
-                                }
-                                break;
-                            default:
-                                if (c != -1)
-                                {
-                                    var message = string.Format("Invalid escape sequence in JSON string '\\{0}'.", (char)c);
-                                    throw new FormatException(message);
-                                }
-                                break;
-                        }
-                        break;
-                    default:
-                        if (c == quoteCharacter)
-                        {
-                            var lexeme = buffer.GetSubstring(start, buffer.Position - start);
-                            return new StringJsonToken(JsonTokenType.String, lexeme, sb.ToString());
-                        }
-                        if (c != -1)
-                        {
-                            sb.Append((char)c);
-                        }
-                        break;
-                }
-                if (c == -1)
-                {
-                    throw new FormatException(FormatMessage("End of file in JSON string.", buffer, start));
-                }
-            }
-        }
-
-        private static JsonToken GetUnquotedStringToken(JsonBuffer buffer)
-        {
-            // opening letter or $ has already been read
-            var start = buffer.Position - 1;
-            var c = buffer.Read();
-            while (c == '$' || c == '_' || char.IsLetterOrDigit((char)c))
-            {
-                c = buffer.Read();
-            }
-            buffer.UnRead(c);
-            var lexeme = buffer.GetSubstring(start, buffer.Position - start);
-            return new StringJsonToken(JsonTokenType.UnquotedString, lexeme, lexeme);
-        }
-
-        // nested types
-        private enum NumberState
-        {
-            SawLeadingMinus,
-            SawLeadingZero,
-            SawIntegerDigits,
-            SawDecimalPoint,
-            SawFractionDigits,
-            SawExponentLetter,
-            SawExponentSign,
-            SawExponentDigits,
-            SawMinusI,
-            Done,
-            Invalid
-        }
-
-        private enum RegularExpressionState
-        {
-            InPattern,
-            InEscapeSequence,
-            InOptions,
-            Done,
-            Invalid
-        }
-    }
-}

+ 0 - 496
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonToken.cs

@@ -1,496 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a JSON token type.
-    /// </summary>
-    public enum JsonTokenType
-    {
-        /// <summary>
-        /// An invalid token.
-        /// </summary>
-        Invalid,
-        /// <summary>
-        /// A begin array token (a '[').
-        /// </summary>
-        BeginArray,
-        /// <summary>
-        /// A begin object token (a '{').
-        /// </summary>
-        BeginObject,
-        /// <summary>
-        /// An end array token (a ']').
-        /// </summary>
-        EndArray,
-        /// <summary>
-        /// A left parenthesis (a '(').
-        /// </summary>
-        LeftParen,
-        /// <summary>
-        /// A right parenthesis (a ')').
-        /// </summary>
-        RightParen,
-        /// <summary>
-        /// An end object token (a '}').
-        /// </summary>
-        EndObject,
-        /// <summary>
-        /// A colon token (a ':').
-        /// </summary>
-        Colon,
-        /// <summary>
-        /// A comma token (a ',').
-        /// </summary>
-        Comma,
-        /// <summary>
-        /// A DateTime token.
-        /// </summary>
-        DateTime,
-        /// <summary>
-        /// A Double token.
-        /// </summary>
-        Double,
-        /// <summary>
-        /// An Int32 token.
-        /// </summary>
-        Int32,
-        /// <summary>
-        /// And Int64 token.
-        /// </summary>
-        Int64,
-        /// <summary>
-        /// An ObjectId token.
-        /// </summary>
-        ObjectId,
-        /// <summary>
-        /// A regular expression token.
-        /// </summary>
-        RegularExpression,
-        /// <summary>
-        /// A string token.
-        /// </summary>
-        String,
-        /// <summary>
-        /// An unquoted string token.
-        /// </summary>
-        UnquotedString,
-        /// <summary>
-        /// An end of file token.
-        /// </summary>
-        EndOfFile
-    }
-
-    /// <summary>
-    /// Represents a JSON token.
-    /// </summary>
-    public class JsonToken
-    {
-        // private fields
-        private JsonTokenType _type;
-        private string _lexeme;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the JsonToken class.
-        /// </summary>
-        /// <param name="type">The token type.</param>
-        /// <param name="lexeme">The lexeme.</param>
-        public JsonToken(JsonTokenType type, string lexeme)
-        {
-            _type = type;
-            _lexeme = lexeme;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the token type.
-        /// </summary>
-        public JsonTokenType Type
-        {
-            get { return _type; }
-        }
-
-        /// <summary>
-        /// Gets the lexeme.
-        /// </summary>
-        public string Lexeme
-        {
-            get { return _lexeme; }
-        }
-
-        /// <summary>
-        /// Gets the value of a DateTime token.
-        /// </summary>
-        public virtual BsonDateTime DateTimeValue
-        {
-            get { throw new NotSupportedException(); }
-        }
-
-        /// <summary>
-        /// Gets the value of a Double token.
-        /// </summary>
-        public virtual double DoubleValue
-        {
-            get { throw new NotSupportedException(); }
-        }
-
-        /// <summary>
-        /// Gets the value of an Int32 token.
-        /// </summary>
-        public virtual int Int32Value
-        {
-            get { throw new NotSupportedException(); }
-        }
-
-        /// <summary>
-        /// Gets the value of an Int64 token.
-        /// </summary>
-        public virtual long Int64Value
-        {
-            get { throw new NotSupportedException(); }
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether this token is number.
-        /// </summary>
-        /// <value>
-        ///   <c>true</c> if this token is number; otherwise, <c>false</c>.
-        /// </value>
-        public virtual bool IsNumber
-        {
-            get { return false; }
-        }
-
-        /// <summary>
-        /// Gets the value of an ObjectId token.
-        /// </summary>
-        public virtual ObjectId ObjectIdValue
-        {
-            get { throw new NotSupportedException(); }
-        }
-
-        /// <summary>
-        /// Gets the value of a regular expression token.
-        /// </summary>
-        public virtual BsonRegularExpression RegularExpressionValue
-        {
-            get { throw new NotSupportedException(); }
-        }
-
-        /// <summary>
-        /// Gets the value of a string token.
-        /// </summary>
-        public virtual string StringValue
-        {
-            get { throw new NotSupportedException(); }
-        }
-    }
-
-    /// <summary>
-    /// Represents a DateTime JSON token.
-    /// </summary>
-    public class DateTimeJsonToken : JsonToken
-    {
-        // private fields
-        private BsonDateTime _value;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the DateTimeJsonToken class.
-        /// </summary>
-        /// <param name="lexeme">The lexeme.</param>
-        /// <param name="value">The DateTime value.</param>
-        public DateTimeJsonToken(string lexeme, BsonDateTime value)
-            : base(JsonTokenType.DateTime, lexeme)
-        {
-            _value = value;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the value of a DateTime token.
-        /// </summary>
-        public override BsonDateTime DateTimeValue
-        {
-            get { return _value; }
-        }
-    }
-
-    /// <summary>
-    /// Represents a Double JSON token.
-    /// </summary>
-    public class DoubleJsonToken : JsonToken
-    {
-        // private fields
-        private double _value;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the DoubleJsonToken class.
-        /// </summary>
-        /// <param name="lexeme">The lexeme.</param>
-        /// <param name="value">The Double value.</param>
-        public DoubleJsonToken(string lexeme, double value)
-            : base(JsonTokenType.Double, lexeme)
-        {
-            _value = value;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the value of a Double token.
-        /// </summary>
-        public override double DoubleValue
-        {
-            get { return _value; }
-        }
-
-        /// <summary>
-        /// Gets the value of an Int32 token.
-        /// </summary>
-        public override int Int32Value
-        {
-            get { return (int)_value; }
-        }
-
-        /// <summary>
-        /// Gets the value of an Int64 token.
-        /// </summary>
-        public override long Int64Value
-        {
-            get { return (long)_value; }
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether this token is number.
-        /// </summary>
-        /// <value>
-        ///   <c>true</c> if this token is number; otherwise, <c>false</c>.
-        /// </value>
-        public override bool IsNumber
-        {
-            get { return true; }
-        }
-    }
-
-    /// <summary>
-    /// Represents an Int32 JSON token.
-    /// </summary>
-    public class Int32JsonToken : JsonToken
-    {
-        // private fields
-        private int _value;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the Int32JsonToken class.
-        /// </summary>
-        /// <param name="lexeme">The lexeme.</param>
-        /// <param name="value">The Int32 value.</param>
-        public Int32JsonToken(string lexeme, int value)
-            : base(JsonTokenType.Int32, lexeme)
-        {
-            _value = value;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the value of a Double token.
-        /// </summary>
-        public override double DoubleValue
-        {
-            get { return _value; }
-        }
-
-        /// <summary>
-        /// Gets the value of an Int32 token.
-        /// </summary>
-        public override int Int32Value
-        {
-            get { return _value; }
-        }
-
-        /// <summary>
-        /// Gets the value of an Int32 token as an Int64.
-        /// </summary>
-        public override long Int64Value
-        {
-            get { return _value; }
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether this token is number.
-        /// </summary>
-        /// <value>
-        ///   <c>true</c> if this token is number; otherwise, <c>false</c>.
-        /// </value>
-        public override bool IsNumber
-        {
-            get { return true; }
-        }
-    }
-
-    /// <summary>
-    /// Represents an Int64 JSON token.
-    /// </summary>
-    public class Int64JsonToken : JsonToken
-    {
-        // private fields
-        private long _value;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the Int64JsonToken class.
-        /// </summary>
-        /// <param name="lexeme">The lexeme.</param>
-        /// <param name="value">The Int64 value.</param>
-        public Int64JsonToken(string lexeme, long value)
-            : base(JsonTokenType.Int64, lexeme)
-        {
-            _value = value;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the value of a Double token.
-        /// </summary>
-        public override double DoubleValue
-        {
-            get { return _value; }
-        }
-
-        /// <summary>
-        /// Gets the value of an Int32 token.
-        /// </summary>
-        public override int Int32Value
-        {
-            get { return (int)_value; }
-        }
-
-        /// <summary>
-        /// Gets the value of an Int64 token.
-        /// </summary>
-        public override long Int64Value
-        {
-            get { return _value; }
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether this token is number.
-        /// </summary>
-        /// <value>
-        ///   <c>true</c> if this token is number; otherwise, <c>false</c>.
-        /// </value>
-        public override bool IsNumber
-        {
-            get { return true; }
-        }
-    }
-
-    /// <summary>
-    /// Represents an ObjectId JSON token.
-    /// </summary>
-    public class ObjectIdJsonToken : JsonToken
-    {
-        // private fields
-        private ObjectId _value;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the ObjectIdJsonToken class.
-        /// </summary>
-        /// <param name="lexeme">The lexeme.</param>
-        /// <param name="value">The ObjectId value.</param>
-        public ObjectIdJsonToken(string lexeme, ObjectId value)
-            : base(JsonTokenType.ObjectId, lexeme)
-        {
-            _value = value;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the value of an ObjectId token.
-        /// </summary>
-        public override ObjectId ObjectIdValue
-        {
-            get { return _value; }
-        }
-    }
-
-    /// <summary>
-    /// Represents a regular expression JSON token.
-    /// </summary>
-    public class RegularExpressionJsonToken : JsonToken
-    {
-        // private fields
-        private BsonRegularExpression _value;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the RegularExpressionJsonToken class.
-        /// </summary>
-        /// <param name="lexeme">The lexeme.</param>
-        /// <param name="value">The BsonRegularExpression value.</param>
-        public RegularExpressionJsonToken(string lexeme, BsonRegularExpression value)
-            : base(JsonTokenType.RegularExpression, lexeme)
-        {
-            _value = value;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the value of a regular expression token.
-        /// </summary>
-        public override BsonRegularExpression RegularExpressionValue
-        {
-            get { return _value; }
-        }
-    }
-
-    /// <summary>
-    /// Represents a String JSON token.
-    /// </summary>
-    public class StringJsonToken : JsonToken
-    {
-        // private fields
-        private string _value;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the StringJsonToken class.
-        /// </summary>
-        /// <param name="type">The token type.</param>
-        /// <param name="lexeme">The lexeme.</param>
-        /// <param name="value">The String value.</param>
-        public StringJsonToken(JsonTokenType type, string lexeme, string value)
-            : base(type, lexeme)
-        {
-            _value = value;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the value of an String token.
-        /// </summary>
-        public override string StringValue
-        {
-            get { return _value; }
-        }
-    }
-}

+ 0 - 907
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonWriter.cs

@@ -1,907 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Globalization;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Text.RegularExpressions;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a BSON writer to a TextWriter (in JSON format).
-    /// </summary>
-    public class JsonWriter : BsonWriter
-    {
-        // private fields
-        private TextWriter _textWriter;
-        private JsonWriterContext _context;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the JsonWriter class.
-        /// </summary>
-        /// <param name="writer">A TextWriter.</param>
-        public JsonWriter(TextWriter writer)
-            : this(writer, JsonWriterSettings.Defaults)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the JsonWriter class.
-        /// </summary>
-        /// <param name="writer">A TextWriter.</param>
-        /// <param name="settings">Optional JsonWriter settings.</param>
-        public JsonWriter(TextWriter writer, JsonWriterSettings settings)
-            : base(settings)
-        {
-            if (writer == null)
-            {
-                throw new ArgumentNullException("writer");
-            }
-
-            _textWriter = writer;
-            _context = new JsonWriterContext(null, ContextType.TopLevel, "");
-            State = BsonWriterState.Initial;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the base TextWriter.
-        /// </summary>
-        /// <value>
-        /// The base TextWriter.
-        /// </value>
-        public TextWriter BaseTextWriter
-        {
-            get { return _textWriter; }
-        }
-
-        /// <inheritdoc />
-        public override long Position => 0L;
-
-        /// <summary>
-        /// Gets the settings of the writer.
-        /// </summary>
-        public new JsonWriterSettings Settings
-        {
-            get { return (JsonWriterSettings)base.Settings; }
-        }
-
-        // public methods
-        /// <summary>
-        /// Closes the writer.
-        /// </summary>
-        public override void Close()
-        {
-            // Close can be called on Disposed objects
-            if (State != BsonWriterState.Closed)
-            {
-                Flush();
-                _context = null;
-                State = BsonWriterState.Closed;
-            }
-        }
-
-        /// <summary>
-        /// Flushes any pending data to the output destination.
-        /// </summary>
-        public override void Flush()
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            _textWriter.Flush();
-        }
-
-        /// <summary>
-        /// Writes BSON binary data to the writer.
-        /// </summary>
-        /// <param name="binaryData">The binary data.</param>
-        public override void WriteBinaryData(BsonBinaryData binaryData)
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteBinaryData", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            var subType = binaryData.SubType;
-            var bytes = binaryData.Bytes;
-            var guidRepresentation = binaryData.GuidRepresentation;
-
-            WriteNameHelper(Name);
-            switch (Settings.OutputMode)
-            {
-                case JsonOutputMode.Strict:
-                    _textWriter.Write("{{ \"$binary\" : \"{0}\", \"$type\" : \"{1}\" }}", Convert.ToBase64String(bytes), ((int)subType).ToString("x2"));
-                    break;
-
-                case JsonOutputMode.Shell:
-                default:
-                    switch (subType)
-                    {
-                        case BsonBinarySubType.UuidLegacy:
-                        case BsonBinarySubType.UuidStandard:
-                            _textWriter.Write(GuidToString(subType, bytes, guidRepresentation));
-                            break;
-
-                        default:
-                            _textWriter.Write("new BinData({0}, \"{1}\")", (int)subType, Convert.ToBase64String(bytes));
-                            break;
-                    }
-                    break;
-            }
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON Boolean to the writer.
-        /// </summary>
-        /// <param name="value">The Boolean value.</param>
-        public override void WriteBoolean(bool value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteBoolean", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            WriteNameHelper(Name);
-            _textWriter.Write(value ? "true" : "false");
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes BSON binary data to the writer.
-        /// </summary>
-        /// <param name="bytes">The bytes.</param>
-        public override void WriteBytes(byte[] bytes)
-        {
-            WriteBinaryData(new BsonBinaryData(bytes, BsonBinarySubType.Binary));
-        }
-
-        /// <summary>
-        /// Writes a BSON DateTime to the writer.
-        /// </summary>
-        /// <param name="value">The number of milliseconds since the Unix epoch.</param>
-        public override void WriteDateTime(long value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteDateTime", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            WriteNameHelper(Name);
-            switch (Settings.OutputMode)
-            {
-                case JsonOutputMode.Strict:
-                    _textWriter.Write("{{ \"$date\" : {0} }}", value);
-                    break;
-
-                case JsonOutputMode.Shell:
-                default:
-                    // use ISODate for values that fall within .NET's DateTime range, and "new Date" for all others
-                    if (value >= BsonConstants.DateTimeMinValueMillisecondsSinceEpoch &&
-                        value <= BsonConstants.DateTimeMaxValueMillisecondsSinceEpoch)
-                    {
-                        var utcDateTime = BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(value);
-                        _textWriter.Write("ISODate(\"{0}\")", utcDateTime.ToString("yyyy-MM-ddTHH:mm:ss.FFFZ"));
-                    }
-                    else
-                    {
-                        _textWriter.Write("new Date({0})", value);
-                    }
-                    break;
-            }
-
-            State = GetNextState();
-        }
-
-        /// <inheritdoc />
-        public override void WriteDecimal128(Decimal128 value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState(nameof(WriteDecimal128), BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            WriteNameHelper(Name);
-            switch (Settings.OutputMode)
-            {
-                case JsonOutputMode.Shell:
-                    _textWriter.Write("NumberDecimal(\"{0}\")", value.ToString());
-                    break;
-
-                default:
-                    _textWriter.Write("{{ \"$numberDecimal\" : \"{0}\" }}", value.ToString());
-                    break;
-            }
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON Double to the writer.
-        /// </summary>
-        /// <param name="value">The Double value.</param>
-        public override void WriteDouble(double value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteDouble", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            // if string representation looks like an integer add ".0" so that it looks like a double
-            var stringRepresentation = JsonConvert.ToString(value);
-            if (Regex.IsMatch(stringRepresentation, @"^[+-]?\d+$"))
-            {
-                stringRepresentation += ".0";
-            }
-
-            WriteNameHelper(Name);
-            _textWriter.Write(stringRepresentation);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes the end of a BSON array to the writer.
-        /// </summary>
-        public override void WriteEndArray()
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value)
-            {
-                ThrowInvalidState("WriteEndArray", BsonWriterState.Value);
-            }
-
-            base.WriteEndArray();
-            _textWriter.Write("]");
-
-            _context = _context.ParentContext;
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes the end of a BSON document to the writer.
-        /// </summary>
-        public override void WriteEndDocument()
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Name)
-            {
-                ThrowInvalidState("WriteEndDocument", BsonWriterState.Name);
-            }
-
-            base.WriteEndDocument();
-            if (Settings.Indent && _context.HasElements)
-            {
-                _textWriter.Write(Settings.NewLineChars);
-                if (_context.ParentContext != null)
-                {
-                    _textWriter.Write(_context.ParentContext.Indentation);
-                }
-                _textWriter.Write("}");
-            }
-            else
-            {
-                _textWriter.Write(" }");
-            }
-
-            if (_context.ContextType == ContextType.ScopeDocument)
-            {
-                _context = _context.ParentContext;
-                WriteEndDocument();
-            }
-            else
-            {
-                _context = _context.ParentContext;
-            }
-
-            if (_context == null)
-            {
-                State = BsonWriterState.Done;
-            }
-            else
-            {
-                State = GetNextState();
-            }
-        }
-
-        /// <summary>
-        /// Writes a BSON Int32 to the writer.
-        /// </summary>
-        /// <param name="value">The Int32 value.</param>
-        public override void WriteInt32(int value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteInt32", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            WriteNameHelper(Name);
-            _textWriter.Write(value);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON Int64 to the writer.
-        /// </summary>
-        /// <param name="value">The Int64 value.</param>
-        public override void WriteInt64(long value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteInt64", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            WriteNameHelper(Name);
-            switch (Settings.OutputMode)
-            {
-                case JsonOutputMode.Strict:
-                    _textWriter.Write(value);
-                    break;
-
-                case JsonOutputMode.Shell:
-                default:
-                    if (value >= int.MinValue && value <= int.MaxValue)
-                    {
-                        _textWriter.Write("NumberLong({0})", value);
-                    }
-                    else
-                    {
-                        _textWriter.Write("NumberLong(\"{0}\")", value);
-                    }
-                    break;
-            }
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON JavaScript to the writer.
-        /// </summary>
-        /// <param name="code">The JavaScript code.</param>
-        public override void WriteJavaScript(string code)
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteJavaScript", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            WriteNameHelper(Name);
-            _textWriter.Write("{{ \"$code\" : \"{0}\" }}", EscapedString(code));
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON JavaScript to the writer (call WriteStartDocument to start writing the scope).
-        /// </summary>
-        /// <param name="code">The JavaScript code.</param>
-        public override void WriteJavaScriptWithScope(string code)
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteJavaScriptWithScope", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            WriteStartDocument();
-            WriteName("$code");
-            WriteString(code);
-            WriteName("$scope");
-
-            State = BsonWriterState.ScopeDocument;
-        }
-
-        /// <summary>
-        /// Writes a BSON MaxKey to the writer.
-        /// </summary>
-        public override void WriteMaxKey()
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteMaxKey", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            WriteNameHelper(Name);
-            switch (Settings.OutputMode)
-            {
-                case JsonOutputMode.Strict:
-                    _textWriter.Write("{ \"$maxKey\" : 1 }");
-                    break;
-
-                case JsonOutputMode.Shell:
-                default:
-                    _textWriter.Write("MaxKey");
-                    break;
-            }
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON MinKey to the writer.
-        /// </summary>
-        public override void WriteMinKey()
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteMinKey", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            WriteNameHelper(Name);
-            switch (Settings.OutputMode)
-            {
-                case JsonOutputMode.Strict:
-                    _textWriter.Write("{ \"$minKey\" : 1 }");
-                    break;
-
-                case JsonOutputMode.Shell:
-                default:
-                    _textWriter.Write("MinKey");
-                    break;
-            }
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON null to the writer.
-        /// </summary>
-        public override void WriteNull()
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteNull", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            WriteNameHelper(Name);
-            _textWriter.Write("null");
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON ObjectId to the writer.
-        /// </summary>
-        /// <param name="objectId">The ObjectId.</param>
-        public override void WriteObjectId(ObjectId objectId)
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteObjectId", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            WriteNameHelper(Name);
-            switch (Settings.OutputMode)
-            {
-                case JsonOutputMode.Strict:
-                    _textWriter.Write("{{ \"$oid\" : \"{0}\" }}", objectId.ToString());
-                    break;
-
-                case JsonOutputMode.Shell:
-                default:
-                    _textWriter.Write("ObjectId(\"{0}\")", objectId.ToString());
-                    break;
-            }
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON regular expression to the writer.
-        /// </summary>
-        /// <param name="regex">A BsonRegularExpression.</param>
-        public override void WriteRegularExpression(BsonRegularExpression regex)
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteRegularExpression", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            var pattern = regex.Pattern;
-            var options = regex.Options;
-
-            WriteNameHelper(Name);
-            switch (Settings.OutputMode)
-            {
-                case JsonOutputMode.Strict:
-                    _textWriter.Write("{{ \"$regex\" : \"{0}\", \"$options\" : \"{1}\" }}", EscapedString(pattern), EscapedString(options));
-                    break;
-
-                case JsonOutputMode.Shell:
-                default:
-                    var escapedPattern = (pattern == "") ? "(?:)" : pattern.Replace("/", @"\/");
-                    _textWriter.Write("/{0}/{1}", escapedPattern, options);
-                    break;
-            }
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes the start of a BSON array to the writer.
-        /// </summary>
-        public override void WriteStartArray()
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteStartArray", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            base.WriteStartArray();
-            WriteNameHelper(Name);
-            _textWriter.Write("[");
-
-            _context = new JsonWriterContext(_context, ContextType.Array, Settings.IndentChars);
-            State = BsonWriterState.Value;
-        }
-
-        /// <summary>
-        /// Writes the start of a BSON document to the writer.
-        /// </summary>
-        public override void WriteStartDocument()
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial && State != BsonWriterState.ScopeDocument)
-            {
-                ThrowInvalidState("WriteStartDocument", BsonWriterState.Value, BsonWriterState.Initial, BsonWriterState.ScopeDocument);
-            }
-
-            base.WriteStartDocument();
-            if (State == BsonWriterState.Value || State == BsonWriterState.ScopeDocument)
-            {
-                WriteNameHelper(Name);
-            }
-            _textWriter.Write("{");
-
-            var contextType = (State == BsonWriterState.ScopeDocument) ? ContextType.ScopeDocument : ContextType.Document;
-            _context = new JsonWriterContext(_context, contextType, Settings.IndentChars);
-            State = BsonWriterState.Name;
-        }
-
-        /// <summary>
-        /// Writes a BSON String to the writer.
-        /// </summary>
-        /// <param name="value">The String value.</param>
-        public override void WriteString(string value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteString", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            WriteNameHelper(Name);
-            WriteQuotedString(value);
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON Symbol to the writer.
-        /// </summary>
-        /// <param name="value">The symbol.</param>
-        public override void WriteSymbol(string value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteSymbol", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            WriteNameHelper(Name);
-            _textWriter.Write("{{ \"$symbol\" : \"{0}\" }}", EscapedString(value));
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON timestamp to the writer.
-        /// </summary>
-        /// <param name="value">The combined timestamp/increment value.</param>
-        public override void WriteTimestamp(long value)
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteTimestamp", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            var secondsSinceEpoch = (int)((value >> 32) & 0xffffffff);
-            var increment = (int)(value & 0xffffffff);
-
-            WriteNameHelper(Name);
-            switch (Settings.OutputMode)
-            {
-                case JsonOutputMode.Strict:
-                    _textWriter.Write("{{ \"$timestamp\" : {{ \"t\" : {0}, \"i\" : {1} }} }}", secondsSinceEpoch, increment);
-                    break;
-
-                case JsonOutputMode.Shell:
-                default:
-                    _textWriter.Write("Timestamp({0}, {1})", secondsSinceEpoch, increment);
-                    break;
-            }
-
-            State = GetNextState();
-        }
-
-        /// <summary>
-        /// Writes a BSON undefined to the writer.
-        /// </summary>
-        public override void WriteUndefined()
-        {
-            if (Disposed) { throw new ObjectDisposedException("JsonWriter"); }
-            if (State != BsonWriterState.Value && State != BsonWriterState.Initial)
-            {
-                ThrowInvalidState("WriteUndefined", BsonWriterState.Value, BsonWriterState.Initial);
-            }
-
-            WriteNameHelper(Name);
-            switch (Settings.OutputMode)
-            {
-                case JsonOutputMode.Strict:
-                    _textWriter.Write("{ \"$undefined\" : true }");
-                    break;
-
-                case JsonOutputMode.Shell:
-                default:
-                    _textWriter.Write("undefined");
-                    break;
-            }
-
-            State = GetNextState();
-        }
-
-        // protected methods
-        /// <summary>
-        /// Disposes of any resources used by the writer.
-        /// </summary>
-        /// <param name="disposing">True if called from Dispose.</param>
-        protected override void Dispose(bool disposing)
-        {
-            if (disposing)
-            {
-                try
-                {
-                    Close();
-                }
-                catch { } // ignore exceptions
-            }
-            base.Dispose(disposing);
-        }
-
-        // private methods
-        private string EscapedString(string value)
-        {
-            if (value.All(c => !NeedsEscaping(c)))
-            {
-                return value;
-            }
-
-            var sb = new StringBuilder(value.Length);
-
-            foreach (char c in value)
-            {
-                switch (c)
-                {
-                    case '"': sb.Append("\\\""); break;
-                    case '\\': sb.Append("\\\\"); break;
-                    case '\b': sb.Append("\\b"); break;
-                    case '\f': sb.Append("\\f"); break;
-                    case '\n': sb.Append("\\n"); break;
-                    case '\r': sb.Append("\\r"); break;
-                    case '\t': sb.Append("\\t"); break;
-                    default:
-                        switch (CharUnicodeInfo.GetUnicodeCategory(c))
-                        {
-                            case UnicodeCategory.UppercaseLetter:
-                            case UnicodeCategory.LowercaseLetter:
-                            case UnicodeCategory.TitlecaseLetter:
-                            case UnicodeCategory.OtherLetter:
-                            case UnicodeCategory.DecimalDigitNumber:
-                            case UnicodeCategory.LetterNumber:
-                            case UnicodeCategory.OtherNumber:
-                            case UnicodeCategory.SpaceSeparator:
-                            case UnicodeCategory.ConnectorPunctuation:
-                            case UnicodeCategory.DashPunctuation:
-                            case UnicodeCategory.OpenPunctuation:
-                            case UnicodeCategory.ClosePunctuation:
-                            case UnicodeCategory.InitialQuotePunctuation:
-                            case UnicodeCategory.FinalQuotePunctuation:
-                            case UnicodeCategory.OtherPunctuation:
-                            case UnicodeCategory.MathSymbol:
-                            case UnicodeCategory.CurrencySymbol:
-                            case UnicodeCategory.ModifierSymbol:
-                            case UnicodeCategory.OtherSymbol:
-                                sb.Append(c);
-                                break;
-                            default:
-                                sb.AppendFormat("\\u{0:x4}", (int)c);
-                                break;
-                        }
-                        break;
-                }
-            }
-
-            return sb.ToString();
-        }
-
-        private BsonWriterState GetNextState()
-        {
-            if (_context.ContextType == ContextType.Array || _context.ContextType == ContextType.TopLevel)
-            {
-                return BsonWriterState.Value;
-            }
-            else
-            {
-                return BsonWriterState.Name;
-            }
-        }
-
-        private string GuidToString(BsonBinarySubType subType, byte[] bytes, GuidRepresentation guidRepresentation)
-        {
-            if (bytes.Length != 16)
-            {
-                var message = string.Format("Length of binary subtype {0} must be 16, not {1}.", subType, bytes.Length);
-                throw new ArgumentException(message);
-            }
-            if (subType == BsonBinarySubType.UuidLegacy && guidRepresentation == GuidRepresentation.Standard)
-            {
-                throw new ArgumentException("GuidRepresentation for binary subtype UuidLegacy must not be Standard.");
-            }
-            if (subType == BsonBinarySubType.UuidStandard && guidRepresentation != GuidRepresentation.Standard)
-            {
-                var message = string.Format("GuidRepresentation for binary subtype UuidStandard must be Standard, not {0}.", guidRepresentation);
-                throw new ArgumentException(message);
-            }
-
-            if (guidRepresentation == GuidRepresentation.Unspecified)
-            {
-                var s = BsonUtils.ToHexString(bytes);
-                var parts = new string[]
-                {
-                    s.Substring(0, 8),
-                    s.Substring(8, 4),
-                    s.Substring(12, 4),
-                    s.Substring(16, 4),
-                    s.Substring(20, 12)
-                };
-                return string.Format("HexData({0}, \"{1}\")", (int)subType, string.Join("-", parts));
-            }
-            else
-            {
-                string uuidConstructorName;
-                switch (guidRepresentation)
-                {
-                    case GuidRepresentation.CSharpLegacy: uuidConstructorName = "CSUUID"; break;
-                    case GuidRepresentation.JavaLegacy: uuidConstructorName = "JUUID"; break;
-                    case GuidRepresentation.PythonLegacy: uuidConstructorName = "PYUUID"; break;
-                    case GuidRepresentation.Standard: uuidConstructorName = "UUID"; break;
-                    default: throw new BsonInternalException("Unexpected GuidRepresentation");
-                }
-                var guid = GuidConverter.FromBytes(bytes, guidRepresentation);
-                return string.Format("{0}(\"{1}\")", uuidConstructorName, guid.ToString());
-            }
-        }
-
-        private bool NeedsEscaping(char c)
-        {
-            switch (c)
-            {
-                case '"':
-                case '\\':
-                case '\b':
-                case '\f':
-                case '\n':
-                case '\r':
-                case '\t':
-                    return true;
-
-                default:
-                    switch (CharUnicodeInfo.GetUnicodeCategory(c))
-                    {
-                        case UnicodeCategory.UppercaseLetter:
-                        case UnicodeCategory.LowercaseLetter:
-                        case UnicodeCategory.TitlecaseLetter:
-                        case UnicodeCategory.OtherLetter:
-                        case UnicodeCategory.DecimalDigitNumber:
-                        case UnicodeCategory.LetterNumber:
-                        case UnicodeCategory.OtherNumber:
-                        case UnicodeCategory.SpaceSeparator:
-                        case UnicodeCategory.ConnectorPunctuation:
-                        case UnicodeCategory.DashPunctuation:
-                        case UnicodeCategory.OpenPunctuation:
-                        case UnicodeCategory.ClosePunctuation:
-                        case UnicodeCategory.InitialQuotePunctuation:
-                        case UnicodeCategory.FinalQuotePunctuation:
-                        case UnicodeCategory.OtherPunctuation:
-                        case UnicodeCategory.MathSymbol:
-                        case UnicodeCategory.CurrencySymbol:
-                        case UnicodeCategory.ModifierSymbol:
-                        case UnicodeCategory.OtherSymbol:
-                            return false;
-
-                        default:
-                            return true;
-                    }
-            }
-        }
-
-        private void WriteNameHelper(string name)
-        {
-            switch (_context.ContextType)
-            {
-                case ContextType.Array:
-                    // don't write Array element names in Json
-                    if (_context.HasElements)
-                    {
-                        _textWriter.Write(", ");
-                    }
-                    break;
-                case ContextType.Document:
-                case ContextType.ScopeDocument:
-                    if (_context.HasElements)
-                    {
-                        _textWriter.Write(",");
-                    }
-                    if (Settings.Indent)
-                    {
-                        _textWriter.Write(Settings.NewLineChars);
-                        _textWriter.Write(_context.Indentation);
-                    }
-                    else
-                    {
-                        _textWriter.Write(" ");
-                    }
-                    WriteQuotedString(name);
-                    _textWriter.Write(" : ");
-                    break;
-                case ContextType.TopLevel:
-                    break;
-                default:
-                    throw new BsonInternalException("Invalid ContextType.");
-            }
-
-            _context.HasElements = true;
-        }
-
-        private void WriteQuotedString(string value)
-        {
-            _textWriter.Write("\"");
-            _textWriter.Write(EscapedString(value));
-            _textWriter.Write("\"");
-        }
-    }
-}

+ 0 - 56
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonWriterContext.cs

@@ -1,56 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-namespace MongoDB.Bson.IO
-{
-    internal class JsonWriterContext
-    {
-        // private fields
-        private JsonWriterContext _parentContext;
-        private ContextType _contextType;
-        private string _indentation;
-        private bool _hasElements = false;
-
-        // constructors
-        internal JsonWriterContext(JsonWriterContext parentContext, ContextType contextType, string indentChars)
-        {
-            _parentContext = parentContext;
-            _contextType = contextType;
-            _indentation = (parentContext == null) ? indentChars : parentContext.Indentation + indentChars;
-        }
-
-        // internal properties
-        internal JsonWriterContext ParentContext
-        {
-            get { return _parentContext; }
-        }
-
-        internal ContextType ContextType
-        {
-            get { return _contextType; }
-        }
-
-        internal string Indentation
-        {
-            get { return _indentation; }
-        }
-
-        internal bool HasElements
-        {
-            get { return _hasElements; }
-            set { _hasElements = value; }
-        }
-    }
-}

+ 0 - 178
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/JsonWriterSettings.cs

@@ -1,178 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Text;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents settings for a JsonWriter.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class JsonWriterSettings : BsonWriterSettings
-    {
-        // private static fields
-        private static JsonWriterSettings __defaults = null; // delay creation to pick up the latest default values
-
-        // private fields
-        private Encoding _encoding = Encoding.UTF8;
-        private bool _indent = false;
-        private string _indentChars = "  ";
-        private string _newLineChars = "\r\n";
-        private JsonOutputMode _outputMode = JsonOutputMode.Shell;
-        private Version _shellVersion;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the JsonWriterSettings class.
-        /// </summary>
-        public JsonWriterSettings()
-        {
-        }
-
-        // public static properties
-        /// <summary>
-        /// Gets or sets the default JsonWriterSettings.
-        /// </summary>
-        public static JsonWriterSettings Defaults
-        {
-            get
-            {
-                if (__defaults == null)
-                {
-                    __defaults = new JsonWriterSettings();
-                }
-                return __defaults;
-            }
-            set { __defaults = value; }
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets or sets the output Encoding.
-        /// </summary>
-        [Obsolete("Set the Encoding when you create a StreamWriter instead (this property is ignored).")]
-        public Encoding Encoding
-        {
-            get { return _encoding; }
-            set
-            {
-                if (IsFrozen) { throw new InvalidOperationException("JsonWriterSettings is frozen."); }
-                _encoding = value;
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets whether to indent the output.
-        /// </summary>
-        public bool Indent
-        {
-            get { return _indent; }
-            set
-            {
-                if (IsFrozen) { throw new InvalidOperationException("JsonWriterSettings is frozen."); }
-                _indent = value;
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets the indent characters.
-        /// </summary>
-        public string IndentChars
-        {
-            get { return _indentChars; }
-            set
-            {
-                if (IsFrozen) { throw new InvalidOperationException("JsonWriterSettings is frozen."); }
-                _indentChars = value;
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets the new line characters.
-        /// </summary>
-        public string NewLineChars
-        {
-            get { return _newLineChars; }
-            set
-            {
-                if (IsFrozen) { throw new InvalidOperationException("JsonWriterSettings is frozen."); }
-                _newLineChars = value;
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets the output mode.
-        /// </summary>
-        public JsonOutputMode OutputMode
-        {
-            get { return _outputMode; }
-            set
-            {
-                if (IsFrozen) { throw new InvalidOperationException("JsonWriterSettings is frozen."); }
-                _outputMode = value;
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets the shell version (used with OutputMode Shell).
-        /// </summary>
-        public Version ShellVersion
-        {
-            get { return _shellVersion; }
-            set
-            {
-                if (IsFrozen) { throw new InvalidOperationException("JsonWriterSettings is frozen."); }
-                _shellVersion = value;
-            }
-        }
-
-        // public methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        public new JsonWriterSettings Clone()
-        {
-            return (JsonWriterSettings)CloneImplementation();
-        }
-
-        // protected methods
-        /// <summary>
-        /// Creates a clone of the settings.
-        /// </summary>
-        /// <returns>A clone of the settings.</returns>
-        protected override BsonWriterSettings CloneImplementation()
-        {
-            var clone = new JsonWriterSettings
-            {
-#pragma warning disable 618
-                Encoding = _encoding,
-#pragma warning restore
-                GuidRepresentation = GuidRepresentation,
-                Indent = _indent,
-                IndentChars = _indentChars,
-                MaxSerializationDepth = MaxSerializationDepth,
-                NewLineChars = _newLineChars,
-                OutputMode = _outputMode,
-                ShellVersion = _shellVersion
-            };
-            return clone;
-        }
-    }
-}

+ 0 - 452
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/MultiChunkBuffer.cs

@@ -1,452 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// An IByteBuffer that is backed by multiple chunks.
-    /// </summary>
-    public sealed class MultiChunkBuffer : IByteBuffer
-    {
-        // private fields
-        private int _capacity;
-        private int _chunkIndex;
-        private List<IBsonChunk> _chunks;
-        private readonly IBsonChunkSource _chunkSource;
-        private bool _disposed;
-        private bool _isReadOnly;
-        private int _length;
-        private List<int> _positions;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="MultiChunkBuffer"/> class.
-        /// </summary>
-        /// <param name="chunkSource">The chunk pool.</param>
-        /// <exception cref="System.ArgumentNullException">chunkPool</exception>
-        public MultiChunkBuffer(IBsonChunkSource chunkSource)
-        {
-            if (chunkSource == null)
-            {
-                throw new ArgumentNullException("chunkSource");
-            }
-
-            _chunks = new List<IBsonChunk>();
-            _chunkSource = chunkSource;
-            _length = 0;
-            _positions = new List<int> { 0 };
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="MultiChunkBuffer"/> class.
-        /// </summary>
-        /// <param name="chunks">The chunks.</param>
-        /// <param name="length">The length.</param>
-        /// <param name="isReadOnly">Whether the buffer is read only.</param>
-        /// <exception cref="System.ArgumentNullException">chunks</exception>
-        public MultiChunkBuffer(IEnumerable<IBsonChunk> chunks, int? length = null, bool isReadOnly = false)
-        {
-            if (chunks == null)
-            {
-                throw new ArgumentNullException("chunks");
-            }
-            var materializedList = new List<IBsonChunk>(chunks);
-
-            var capacity = 0;
-            var positions = new List<int> { 0 };
-            foreach (var chunk in materializedList)
-            {
-                capacity += chunk.Bytes.Count;
-                positions.Add(capacity);
-            }
-
-            if (length.HasValue && (length.Value < 0 || length.Value > capacity))
-            {
-                throw new ArgumentOutOfRangeException("length");
-            }
-
-            _capacity = capacity;
-            _chunks = materializedList;
-            _isReadOnly = isReadOnly;
-            _length = length ?? capacity;
-            _positions = positions;
-        }
-
-        // public properties
-        /// <inheritdoc/>
-        public int Capacity
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _isReadOnly ? _length : _capacity;
-            }
-        }
-
-        /// <summary>
-        /// Gets the chunk source.
-        /// </summary>
-        /// <value>
-        /// The chunk source.
-        /// </value>
-        public IBsonChunkSource ChunkSource
-        {
-            get { return _chunkSource; }
-        }
-
-        /// <inheritdoc/>
-        public bool IsReadOnly
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _isReadOnly;
-            }
-        }
-
-        /// <inheritdoc/>
-        public int Length
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _length;
-            }
-            set
-            {
-                ThrowIfDisposed();
-                if (value < 0 || value > _capacity)
-                {
-                    throw new ArgumentOutOfRangeException("value");
-                }
-                EnsureIsWritable();
-
-                _length = value;
-            }
-        }
-
-        // public methods
-        /// <inheritdoc/>
-        public ArraySegment<byte> AccessBackingBytes(int position)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-
-            var chunkIndex = GetChunkIndex(position);
-            if (chunkIndex < _chunks.Count)
-            {
-                var segment = _chunks[chunkIndex].Bytes;
-                var chunkOffset = position - _positions[chunkIndex];
-                var chunkRemaining = segment.Count - chunkOffset;
-                return new ArraySegment<byte>(segment.Array, segment.Offset + chunkOffset, chunkRemaining);
-            }
-            else
-            {
-                if (_chunks.Count > 0)
-                {
-                    var segment = _chunks[chunkIndex - 1].Bytes;
-                    return new ArraySegment<byte>(segment.Array, segment.Offset + segment.Count, 0);
-                }
-                else
-                {
-                    return new ArraySegment<byte>(new byte[0], 0, 0);
-                }
-            }
-        }
-
-        /// <inheritdoc/>
-        public void Clear(int position, int count)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            if (count < 0 || position + count > _length)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-            EnsureIsWritable();
-
-            var chunkIndex = GetChunkIndex(position);
-            var chunkOffset = position - _positions[chunkIndex];
-            while (count > 0)
-            {
-                var segment = _chunks[chunkIndex].Bytes;
-                var chunkRemaining = segment.Count - chunkOffset;
-                var partialCount = Math.Min(count, chunkRemaining);
-                Array.Clear(segment.Array, segment.Offset + chunkOffset, partialCount);
-                chunkIndex += 1;
-                chunkOffset = 0;
-                count -= partialCount;
-            }
-        }
-
-        /// <inheritdoc/>
-        public void Dispose()
-        {
-            if (!_disposed)
-            {
-                _disposed = true;
-                foreach (var chunk in _chunks)
-                {
-                    chunk.Dispose();
-                }
-                _chunks = null;
-                _positions = null;
-            }
-        }
-
-        /// <inheritdoc/>
-        public void EnsureCapacity(int minimumCapacity)
-        {
-            if (minimumCapacity < 0)
-            {
-                throw new ArgumentOutOfRangeException("minimumCapacity");
-            }
-            ThrowIfDisposed();
-            EnsureIsWritable();
-
-            if (_capacity < minimumCapacity)
-            {
-                ExpandCapacity(minimumCapacity);
-            }
-        }
-
-        /// <inheritdoc/>
-        public byte GetByte(int position)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position >= _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-
-            var chunkIndex = GetChunkIndex(position);
-            var chunkOffset = position - _positions[chunkIndex];
-            var segment = _chunks[chunkIndex].Bytes;
-            return segment.Array[segment.Offset + chunkOffset];
-        }
-
-        /// <inheritdoc/>
-        public void GetBytes(int position, byte[] destination, int offset, int count)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            if (destination == null)
-            {
-                throw new ArgumentNullException("destination");
-            }
-            if (offset < 0 || offset > destination.Length)
-            {
-                throw new ArgumentOutOfRangeException("offset");
-            }
-            if (count < 0 || position + count > _length || offset + count > destination.Length)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-
-            var chunkIndex = GetChunkIndex(position);
-            var chunkOffset = position - _positions[chunkIndex];
-            while (count > 0)
-            {
-                var segment = _chunks[chunkIndex].Bytes;
-                var chunkRemaining = segment.Count - chunkOffset;
-                var partialCount = Math.Min(count, chunkRemaining);
-                Buffer.BlockCopy(segment.Array, segment.Offset + chunkOffset, destination, offset, partialCount);
-                chunkIndex += 1;
-                chunkOffset = 0;
-                count -= partialCount;
-                offset += partialCount;
-            }
-        }
-
-        /// <inheritdoc/>
-        public IByteBuffer GetSlice(int position, int length)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            if (length < 0 || position + length > _length)
-            {
-                throw new ArgumentOutOfRangeException("length");
-            }
-            EnsureIsReadOnly();
-
-            if (length == 0)
-            {
-                return new ByteArrayBuffer(new byte[0]);
-            }
-
-            var firstChunkIndex = GetChunkIndex(position);
-            var lastChunkIndex = GetChunkIndex(position + length - 1);
-
-            IByteBuffer forkedBuffer;
-            if (firstChunkIndex == lastChunkIndex)
-            {
-                var forkedChunk = _chunks[firstChunkIndex].Fork();
-                forkedBuffer = new SingleChunkBuffer(forkedChunk, forkedChunk.Bytes.Count, isReadOnly: true);
-            }
-            else
-            {
-                var forkedChunks = _chunks.Skip(firstChunkIndex).Take(lastChunkIndex - firstChunkIndex + 1).Select(c => c.Fork());
-                var forkedBufferLength = _positions[lastChunkIndex + 1] - _positions[firstChunkIndex];
-                forkedBuffer = new MultiChunkBuffer(forkedChunks, forkedBufferLength, isReadOnly: true);
-            }
-
-            var offset = position - _positions[firstChunkIndex];
-            return new ByteBufferSlice(forkedBuffer, offset, length);
-        }
-
-        /// <inheritdoc/>
-        public void MakeReadOnly()
-        {
-            ThrowIfDisposed();
-            _isReadOnly = true;
-        }
-
-        /// <inheritdoc/>
-        public void SetByte(int position, byte value)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position >= _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            EnsureIsWritable();
-
-            var chunkIndex = GetChunkIndex(position);
-            var chunkOffset = position - _positions[chunkIndex];
-            var segment = _chunks[chunkIndex].Bytes;
-            segment.Array[segment.Offset + chunkOffset] = value;
-        }
-
-        /// <inheritdoc/>
-        public void SetBytes(int position, byte[] source, int offset, int count)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            if (source == null)
-            {
-                throw new ArgumentNullException("source");
-            }
-            if (offset < 0 || offset > source.Length)
-            {
-                throw new ArgumentOutOfRangeException("offset");
-            }
-            if (count < 0 || position + count > _length || offset + count > source.Length)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-            EnsureIsWritable();
-
-            var chunkIndex = GetChunkIndex(position);
-            var chunkOffset = position - _positions[chunkIndex];
-            while (count > 0)
-            {
-                var segment = _chunks[chunkIndex].Bytes;
-                var chunkRemaining = segment.Count - chunkOffset;
-                var partialCount = Math.Min(count, chunkRemaining);
-                Buffer.BlockCopy(source, offset, segment.Array, segment.Offset + chunkOffset, partialCount);
-                chunkIndex += 1;
-                chunkOffset = 0;
-                offset += partialCount;
-                count -= partialCount;
-            }
-        }
-
-        // private methods
-        private void EnsureIsReadOnly()
-        {
-            if (!_isReadOnly)
-            {
-                throw new InvalidOperationException("MultiChunkBuffer is not read only.");
-            }
-        }
-
-        private void EnsureIsWritable()
-        {
-            if (_isReadOnly)
-            {
-                throw new InvalidOperationException("MultiChunkBuffer is not writable.");
-            }
-        }
-
-        private void ExpandCapacity(int minimumCapacity)
-        {
-            if (_chunkSource == null)
-            {
-                throw new InvalidOperationException("Capacity cannot be expanded because this buffer was created without specifying a chunk source.");
-            }
-
-            while (_capacity < minimumCapacity)
-            {
-                var chunk = _chunkSource.GetChunk(minimumCapacity);
-                _chunks.Add(chunk);
-                var newCapacity = (long)_capacity + (long)chunk.Bytes.Count;
-                if (newCapacity > int.MaxValue)
-                {
-                    throw new InvalidOperationException("Capacity is limited to 2GB.");
-                }
-                _capacity = (int)newCapacity;
-                _positions.Add(_capacity);
-            }
-        }
-
-        private int GetChunkIndex(int position)
-        {
-            // locality of reference means this loop will only execute once most of the time
-            while (true)
-            {
-                if (_chunkIndex + 1 < _positions.Count && position >= _positions[_chunkIndex + 1])
-                {
-                    _chunkIndex++;
-                }
-                else if (position < _positions[_chunkIndex])
-                {
-                    _chunkIndex--;
-                }
-                else
-                {
-                    return _chunkIndex;
-                }
-            }
-        }
-
-        private void ThrowIfDisposed()
-        {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException(GetType().Name);
-            }
-        }
-    }
-}

+ 0 - 60
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/NoOpElementNameValidator.cs

@@ -1,60 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents an element name validator that does no validation.
-    /// </summary>
-    public class NoOpElementNameValidator : IElementNameValidator
-    {
-        // private static fields
-        private static readonly NoOpElementNameValidator __instance = new NoOpElementNameValidator();
-
-        // public static properties
-        /// <summary>
-        /// Gets the instance.
-        /// </summary>
-        /// <value>
-        /// The instance.
-        /// </value>
-        public static NoOpElementNameValidator Instance
-        {
-            get { return __instance; }
-        }
-
-        // public methods
-        /// <summary>
-        /// Gets the validator to use for child content (a nested document or array).
-        /// </summary>
-        /// <param name="elementName">The name of the element.</param>
-        /// <returns>The validator to use for child content.</returns>
-        public IElementNameValidator GetValidatorForChildContent(string elementName)
-        {
-            return this;
-        }
-
-        /// <summary>
-        /// Determines whether the element name is valid.
-        /// </summary>
-        /// <param name="elementName">The name of the element.</param>
-        /// <returns>True if the element name is valid.</returns>
-        public bool IsValidElementName(string elementName)
-        {
-            return true;
-        }
-    }
-}

+ 0 - 176
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/OutputBufferChunkSource.cs

@@ -1,176 +0,0 @@
-/* Copyright 2013-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a source of chunks optimized for output buffers.
-    /// </summary>
-    public sealed class OutputBufferChunkSource : IBsonChunkSource
-    {
-        // constants
-        const int DefaultInitialUnpooledChunkSize = 1024;
-        const int DefaultMaxChunkSize = 1 * 1024 * 1024;
-        const int DefaultMinChunkSize = 16 * 1024;
-
-        // fields
-        private readonly IBsonChunkSource _baseSource;
-        private bool _disposed;
-        private int _initialUnpooledChunkSize;
-        private readonly int _maxChunkSize;
-        private readonly int _minChunkSize;
-        private int _previousChunkSize;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="OutputBufferChunkSource"/> class.
-        /// </summary>
-        /// <param name="baseSource">The chunk source.</param>
-        /// <param name="initialUnpooledChunkSize">The size of the initial unpooled chunk.</param>
-        /// <param name="minChunkSize">The minimum size of a chunk.</param>
-        /// <param name="maxChunkSize">The maximum size of a chunk.</param>
-        public OutputBufferChunkSource(
-            IBsonChunkSource baseSource,
-            int initialUnpooledChunkSize = DefaultInitialUnpooledChunkSize,
-            int minChunkSize = DefaultMinChunkSize,
-            int maxChunkSize = DefaultMaxChunkSize)
-        {
-            if (baseSource == null)
-            {
-                throw new ArgumentNullException("baseSource");
-            }
-            if (initialUnpooledChunkSize < 0)
-            {
-                throw new ArgumentOutOfRangeException("initialUnpooledChunkSize");
-            }
-            if (minChunkSize <= 0)
-            {
-                throw new ArgumentOutOfRangeException("minChunkSize");
-            }
-            if (maxChunkSize <= 0)
-            {
-                throw new ArgumentOutOfRangeException("maxChunkSize");
-            }
-            if (!PowerOf2.IsPowerOf2(minChunkSize))
-            {
-                throw new ArgumentException("minChunkSize is not a power of 2.", "minChunkSize");
-            }
-            if (!PowerOf2.IsPowerOf2(maxChunkSize))
-            {
-                throw new ArgumentException("maxChunkSize is not a power of 2.", "maxChunkSize");
-            }
-            if (maxChunkSize < minChunkSize)
-            {
-                throw new ArgumentException("maxChunkSize is less than minChunkSize", "maxChunkSize");
-            }
-
-            _baseSource = baseSource;
-            _initialUnpooledChunkSize = initialUnpooledChunkSize;
-            _minChunkSize = minChunkSize;
-            _maxChunkSize = maxChunkSize;
-        }
-
-        // properties
-        /// <summary>
-        /// Gets the base source.
-        /// </summary>
-        /// <value>
-        /// The base source.
-        /// </value>
-        public IBsonChunkSource BaseSource
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _baseSource;
-            }
-        }
-
-        /// <summary>
-        /// Gets the initial unpooled chunk size.
-        /// </summary>
-        /// <value>
-        /// The initial unpooled chunk size.
-        /// </value>
-        public int InitialUnpooledChunkSize
-        {
-            get { return _initialUnpooledChunkSize; }
-        }
-
-        /// <summary>
-        /// Gets the maximum size of a chunk.
-        /// </summary>
-        /// <value>
-        /// The maximum size of a chunk.
-        /// </value>
-        public int MaxChunkSize
-        {
-            get { return _maxChunkSize; }
-        }
-
-        /// <summary>
-        /// Gets the minimum size of a chunk.
-        /// </summary>
-        /// <value>
-        /// The minimum size of a chunk.
-        /// </value>
-        public int MinChunkSize
-        {
-            get { return _minChunkSize; }
-        }
-
-        // methods
-        /// <inheritdoc/>
-        public void Dispose()
-        {
-            _disposed = true;
-        }
-
-        /// <inheritdoc/>
-        public IBsonChunk GetChunk(int requestedSize)
-        {
-            if (requestedSize <= 0)
-            {
-                throw new ArgumentOutOfRangeException("requestedSize");
-            }
-            ThrowIfDisposed();
-
-            IBsonChunk chunk;
-            if (_previousChunkSize == 0 && _initialUnpooledChunkSize != 0)
-            {
-                chunk = new ByteArrayChunk(_initialUnpooledChunkSize);
-            }
-            else
-            {
-                var powerOf2Size = PowerOf2.RoundUpToPowerOf2(_previousChunkSize + 1);
-                var chunkSize = Math.Max(Math.Min(powerOf2Size, _maxChunkSize), _minChunkSize);
-                chunk = _baseSource.GetChunk(chunkSize);
-            }
-
-            _previousChunkSize = chunk.Bytes.Count;
-            return chunk;
-        }
-
-        private void ThrowIfDisposed()
-        {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException(GetType().Name);
-            }
-        }
-    }
-}

+ 0 - 283
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/SingleChunkBuffer.cs

@@ -1,283 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// An IByteBuffer that is backed by a single chunk.
-    /// </summary>
-    public sealed class SingleChunkBuffer : IByteBuffer
-    {
-        // private fields
-        private IBsonChunk _chunk;
-        private bool _disposed;
-        private bool _isReadOnly;
-        private int _length;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="SingleChunkBuffer"/> class.
-        /// </summary>
-        /// <param name="chunk">The chuns.</param>
-        /// <param name="length">The length.</param>
-        /// <param name="isReadOnly">Whether the buffer is read only.</param>
-        public SingleChunkBuffer(IBsonChunk chunk, int length, bool isReadOnly = false)
-        {
-            if (chunk == null)
-            {
-                throw new ArgumentNullException("chunk");
-            }
-            if (length < 0 || length > chunk.Bytes.Count)
-            {
-                throw new ArgumentOutOfRangeException("length");
-            }
-
-            _chunk = chunk;
-            _length = length;
-            _isReadOnly = isReadOnly;
-        }
-
-        // public properties
-        /// <inheritdoc/>
-        public int Capacity
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _isReadOnly ? _length : _chunk.Bytes.Count;
-            }
-        }
-
-        /// <inheritdoc/>
-        public bool IsReadOnly
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _isReadOnly;
-            }
-        }
-
-        /// <inheritdoc/>
-        public int Length
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _length;
-            }
-            set
-            {
-                ThrowIfDisposed();
-                if (value < 0 || value > _chunk.Bytes.Count)
-                {
-                    throw new ArgumentOutOfRangeException("value");
-                }
-                EnsureIsWritable();
-
-                _length = value;
-            }
-        }
-
-        // public methods
-        /// <inheritdoc/>
-        public ArraySegment<byte> AccessBackingBytes(int position)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-
-            var segment = _chunk.Bytes;
-            return new ArraySegment<byte>(segment.Array, segment.Offset + position, _length - position);
-        }
-
-        /// <inheritdoc/>
-        public void Clear(int position, int count)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            if (count < 0 || position + count > _length)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-            EnsureIsWritable();
-
-            var segment = _chunk.Bytes;
-            Array.Clear(segment.Array, segment.Offset + position, count);
-        }
-
-        /// <inheritdoc/>
-        public void Dispose()
-        {
-            if (!_disposed)
-            {
-                _disposed = true;
-                _chunk.Dispose();
-                _chunk = null;
-            }
-        }
-
-        /// <inheritdoc/>
-        public void EnsureCapacity(int minimumCapacity)
-        {
-            if (minimumCapacity < 0)
-            {
-                throw new ArgumentOutOfRangeException("minimumCapacity");
-            }
-            ThrowIfDisposed();
-            EnsureIsWritable();
-
-            if (_chunk.Bytes.Count < minimumCapacity)
-            {
-                throw new NotSupportedException("Capacity cannot be expanded for a SingleChunkBuffer.");
-            }
-        }
-
-        /// <inheritdoc/>
-        public byte GetByte(int position)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-
-            var segment = _chunk.Bytes;
-            return segment.Array[segment.Offset + position];
-        }
-
-        /// <inheritdoc/>
-        public void GetBytes(int position, byte[] destination, int offset, int count)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            if (destination == null)
-            {
-                throw new ArgumentNullException("destination");
-            }
-            if (offset < 0 || offset > destination.Length)
-            {
-                throw new ArgumentOutOfRangeException("offset");
-            }
-            if (count < 0 || position + count > _length || offset + count > destination.Length)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-
-            var segment = _chunk.Bytes;
-            Buffer.BlockCopy(segment.Array, segment.Offset + position, destination, offset, count);
-        }
-
-        /// <inheritdoc/>
-        public IByteBuffer GetSlice(int position, int length)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            if (length < 0 || position + length > _length)
-            {
-                throw new ArgumentOutOfRangeException("length");
-            }
-            EnsureIsReadOnly();
-
-            var forkedBuffer = new SingleChunkBuffer(_chunk.Fork(), _length, isReadOnly: true);
-            return new ByteBufferSlice(forkedBuffer, position, length);
-        }
-
-        /// <inheritdoc/>
-        public void MakeReadOnly()
-        {
-            ThrowIfDisposed();
-            _isReadOnly = true;
-        }
-
-        /// <inheritdoc/>
-        public void SetByte(int position, byte value)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            EnsureIsWritable();
-
-            var segment = _chunk.Bytes;
-            segment.Array[segment.Offset + position] = value;
-        }
-
-        /// <inheritdoc/>
-        public void SetBytes(int position, byte[] source, int offset, int count)
-        {
-            ThrowIfDisposed();
-            if (position < 0 || position > _length)
-            {
-                throw new ArgumentOutOfRangeException("position");
-            }
-            if (source == null)
-            {
-                throw new ArgumentNullException("source");
-            }
-            if (offset < 0 || offset > source.Length)
-            {
-                throw new ArgumentOutOfRangeException("offset");
-            }
-            if (count < 0 || position + count > _length || offset + count > source.Length)
-            {
-                throw new ArgumentOutOfRangeException("count");
-            }
-            EnsureIsWritable();
-
-            var segment = _chunk.Bytes;
-            Buffer.BlockCopy(source, offset, segment.Array, segment.Offset + position, count);
-        }
-
-        // private methods
-        private void EnsureIsReadOnly()
-        {
-            if (!_isReadOnly)
-            {
-                throw new InvalidOperationException("MultiChunkBuffer is not read only.");
-            }
-        }
-
-        private void EnsureIsWritable()
-        {
-            if (_isReadOnly)
-            {
-                throw new InvalidOperationException("MultiChunkBuffer is not writable.");
-            }
-        }
-
-        private void ThrowIfDisposed()
-        {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException(GetType().Name);
-            }
-        }
-    }
-}

+ 0 - 105
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/TrieNameDecoder.cs

@@ -1,105 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a Trie-based name decoder that also provides a value.
-    /// </summary>
-    /// <typeparam name="TValue">The type of the value.</typeparam>
-    public class TrieNameDecoder<TValue> : INameDecoder
-    {
-        // private fields
-        private bool _found;
-        private readonly BsonTrie<TValue> _trie;
-        private TValue _value;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="TrieNameDecoder{TValue}"/> class.
-        /// </summary>
-        /// <param name="trie">The trie.</param>
-        public TrieNameDecoder(BsonTrie<TValue> trie)
-        {
-            _trie = trie;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets a value indicating whether this <see cref="TrieNameDecoder{TValue}"/> is found.
-        /// </summary>
-        /// <value>
-        ///   <c>true</c> if found; otherwise, <c>false</c>.
-        /// </value>
-        public bool Found
-        {
-            get { return _found; }
-        }
-
-        /// <summary>
-        /// Gets the value.
-        /// </summary>
-        /// <value>
-        /// The value.
-        /// </value>
-        public TValue Value
-        {
-            get { return _value; }
-        }
-
-        // public methods
-        /// <summary>
-        /// Reads the name.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <param name="encoding">The encoding.</param>
-        /// <returns>
-        /// The name.
-        /// </returns>
-        public string Decode(BsonStream stream, UTF8Encoding encoding)
-        {
-            BsonTrieNode<TValue> node;
-            var oldPosition = stream.Position;
-            if (_trie.TryGetNode(stream, out node))
-            {
-                if (node.HasValue)
-                {
-                    _found = true;
-                    _value = node.Value;
-                    return node.ElementName;
-                }
-
-                stream.Position = oldPosition;
-            }
-
-            return stream.ReadCString(encoding);
-        }
-
-        /// <summary>
-        /// Informs the decoder of an already decoded name (so the decoder can change state if necessary).
-        /// </summary>
-        /// <param name="name">The name.</param>
-        public void Inform(string name)
-        {
-            _found = _trie.TryGetValue(name, out _value);
-        }
-    }
-}

+ 0 - 46
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/Utf8Encodings.cs

@@ -1,46 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System.Text;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a singleton instance of a strict UTF8Encoding.
-    /// </summary>
-    public static class Utf8Encodings
-    {
-        // private static fields
-        private static readonly UTF8Encoding __lenient = new UTF8Encoding(false, false);
-        private static readonly UTF8Encoding __strict = new UTF8Encoding(false, true);
-
-        // public static properties
-        /// <summary>
-        /// Gets the lenient instance.
-        /// </summary>
-        public static UTF8Encoding Lenient
-        {
-            get { return __lenient; }
-        }
-
-        /// <summary>
-        /// Gets the strict instance.
-        /// </summary>
-        public static UTF8Encoding Strict
-        {
-            get { return __strict; }
-        }
-    }
-}

+ 0 - 67
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/Utf8Helper.cs

@@ -1,67 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System.Text;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a class that has some helper methods for decoding UTF8 strings.
-    /// </summary>
-    public static class Utf8Helper
-    {
-        // private static fields
-        private static readonly string[] __asciiStringTable = new string[128];
-
-        // static constructor
-        static Utf8Helper()
-        {
-            for (int i = 0; i < __asciiStringTable.Length; ++i)
-            {
-                __asciiStringTable[i] = new string((char)i, 1);
-            }
-        }
-
-        // public static methods
-        /// <summary>
-        /// Decodes a UTF8 string.
-        /// </summary>
-        /// <param name="bytes">The bytes.</param>
-        /// <param name="index">The index.</param>
-        /// <param name="count">The count.</param>
-        /// <param name="encoding">The encoding.</param>
-        /// <returns>The decoded string.</returns>
-        public static string DecodeUtf8String(byte[] bytes, int index, int count, UTF8Encoding encoding)
-        {
-            switch (count)
-            {
-                // special case empty strings
-                case 0:
-                    return "";
-
-                // special case single character strings
-                case 1:
-                    var byte1 = (int)bytes[index];
-                    if (byte1 < __asciiStringTable.Length)
-                    {
-                        return __asciiStringTable[byte1];
-                    }
-                    break;
-            }
-
-            return encoding.GetString(bytes, index, count);
-        }
-    }
-}

+ 0 - 64
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/Utf8NameDecoder.cs

@@ -1,64 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-using System.Text;
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// Represents a UTF8 name decoder.
-    /// </summary>
-    public class Utf8NameDecoder : INameDecoder
-    {
-        // private static fields
-        private static readonly Utf8NameDecoder __instance = new Utf8NameDecoder();
-
-        // public static properties
-        /// <summary>
-        /// Gets the instance.
-        /// </summary>
-        /// <value>
-        /// The instance.
-        /// </value>
-        public static Utf8NameDecoder Instance
-        {
-            get { return __instance; }
-        }
-
-        // public methods
-        /// <summary>
-        /// Decodes the name.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <param name="encoding">The encoding.</param>
-        /// <returns>
-        /// The name.
-        /// </returns>
-        public string Decode(BsonStream stream, UTF8Encoding encoding)
-        {
-            var utf8 = stream.ReadCStringBytes();
-            return Utf8Helper.DecodeUtf8String(utf8.Array, utf8.Offset, utf8.Count, encoding);
-        }
-
-        /// <summary>
-        /// Informs the decoder of an already decoded name (so the decoder can change state if necessary).
-        /// </summary>
-        /// <param name="name">The name.</param>
-        public void Inform(string name)
-        {
-        }
-    }
-}

+ 0 - 361
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/IO/WrappingBsonWriter.cs

@@ -1,361 +0,0 @@
-/* Copyright 2017-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson.IO
-{
-    /// <summary>
-    /// An abstract base class for an IBsonWriter that wraps another IBsonWriter.
-    /// </summary>
-    /// <seealso cref="MongoDB.Bson.IO.IBsonWriter" />
-    public abstract class WrappingBsonWriter : IBsonWriter
-    {
-        // private fields
-        private bool _disposed;
-        private readonly IBsonWriter _wrapped;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="WrappingBsonWriter"/> class.
-        /// </summary>
-        /// <param name="wrapped">The wrapped writer.</param>
-        public WrappingBsonWriter(IBsonWriter wrapped)
-        {
-            if (wrapped == null)
-            {
-                throw new ArgumentNullException(nameof(wrapped));
-            }
-            _wrapped = wrapped;
-        }
-
-        // public properties
-        /// <inheritdoc />
-        public virtual long Position
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _wrapped.Position;
-            }
-        }
-
-        /// <inheritdoc />
-        public virtual int SerializationDepth
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _wrapped.SerializationDepth;
-            }
-        }
-
-        /// <inheritdoc />
-        public virtual BsonWriterSettings Settings
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _wrapped.Settings;
-            }
-        }
-
-        /// <inheritdoc />
-        public virtual BsonWriterState State
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _wrapped.State;
-            }
-        }
-
-        /// <summary>
-        /// Gets the wrapped writer.
-        /// </summary>
-        /// <value>
-        /// The wrapped writer.
-        /// </value>
-        public IBsonWriter Wrapped
-        {
-            get
-            {
-                ThrowIfDisposed();
-                return _wrapped;
-            }
-        }
-
-        // public methods
-        /// <inheritdoc />
-        public virtual void Close()
-        {
-            // let subclass decide whether to throw or not if Dispose has been called
-            _wrapped.Close();
-        }
-
-        /// <inheritdoc />
-        public void Dispose()
-        {
-            Dispose(true);
-            GC.SuppressFinalize(this);
-        }
-
-        /// <inheritdoc />
-        public virtual void Flush()
-        {
-            ThrowIfDisposed();
-            _wrapped.Flush();
-        }
-
-        /// <inheritdoc />
-        public virtual void PopElementNameValidator()
-        {
-            ThrowIfDisposed();
-            _wrapped.PopElementNameValidator();
-        }
-
-        /// <inheritdoc />
-        public virtual void PopSettings()
-        {
-            ThrowIfDisposed();
-            _wrapped.PopSettings();
-        }
-
-        /// <inheritdoc />
-        public virtual void PushElementNameValidator(IElementNameValidator validator)
-        {
-            ThrowIfDisposed();
-            _wrapped.PushElementNameValidator(validator);
-        }
-
-        /// <inheritdoc />
-        public virtual void PushSettings(Action<BsonWriterSettings> configurator)
-        {
-            ThrowIfDisposed();
-            _wrapped.PushSettings(configurator);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteBinaryData(BsonBinaryData binaryData)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteBinaryData(binaryData);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteBoolean(bool value)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteBoolean(value);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteBytes(byte[] bytes)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteBytes(bytes);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteDateTime(long value)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteDateTime(value);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteDecimal128(Decimal128 value)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteDecimal128(value);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteDouble(double value)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteDouble(value);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteEndArray()
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteEndArray();
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteEndDocument()
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteEndDocument();
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteInt32(int value)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteInt32(value);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteInt64(long value)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteInt64(value);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteJavaScript(string code)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteJavaScript(code);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteJavaScriptWithScope(string code)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteJavaScriptWithScope(code);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteMaxKey()
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteMaxKey();
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteMinKey()
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteMinKey();
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteName(string name)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteName(name);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteNull()
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteNull();
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteObjectId(ObjectId objectId)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteObjectId(objectId);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteRawBsonArray(IByteBuffer slice)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteRawBsonArray(slice);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteRawBsonDocument(IByteBuffer slice)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteRawBsonDocument(slice);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteRegularExpression(BsonRegularExpression regex)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteRegularExpression(regex);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteStartArray()
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteStartArray();
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteStartDocument()
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteStartDocument();
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteString(string value)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteString(value);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteSymbol(string value)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteSymbol(value);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteTimestamp(long value)
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteTimestamp(value);
-        }
-
-        /// <inheritdoc />
-        public virtual void WriteUndefined()
-        {
-            ThrowIfDisposed();
-            _wrapped.WriteUndefined();
-        }
-
-        // protected methods
-        /// <summary>
-        /// Releases unmanaged and - optionally - managed resources.
-        /// </summary>
-        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
-        protected virtual void Dispose(bool disposing)
-        {
-            if (!_disposed)
-            {
-                if (disposing)
-                {
-                    _wrapped.Dispose();
-                }
-                _disposed = true;
-            }
-        }
-
-        /// <summary>
-        /// Throws if disposed.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException"></exception>
-        protected void ThrowIfDisposed()
-        {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException(GetType().FullName);
-            }
-        }
-    }
-}

+ 0 - 755
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonArray.cs

@@ -1,755 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using MongoDB.Shared;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents a BSON array.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonArray : BsonValue, IComparable<BsonArray>, IEquatable<BsonArray>, IList<BsonValue>
-    {
-        // private fields
-        private readonly List<BsonValue> _values;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonArray class.
-        /// </summary>
-        public BsonArray()
-            : this(0)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonArray class.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonArray(IEnumerable<bool> values)
-
-            : this(0)
-        {
-            AddRange(values);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonArray class.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonArray(IEnumerable<BsonValue> values)
-            : this(0)
-        {
-            AddRange(values);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonArray class.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonArray(IEnumerable<DateTime> values)
-            : this(0)
-        {
-            AddRange(values);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonArray class.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonArray(IEnumerable<double> values)
-            : this(0)
-        {
-            AddRange(values);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonArray class.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonArray(IEnumerable<int> values)
-            : this(0)
-        {
-            AddRange(values);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonArray class.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonArray(IEnumerable<long> values)
-            : this(0)
-        {
-            AddRange(values);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonArray class.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonArray(IEnumerable<ObjectId> values)
-            : this(0)
-        {
-            AddRange(values);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonArray class.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonArray(IEnumerable<string> values)
-            : this(0)
-        {
-            AddRange(values);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonArray class.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonArray(IEnumerable values)
-            : this(0)
-        {
-            AddRange(values);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonArray class.
-        /// </summary>
-        /// <param name="capacity">The initial capacity of the array.</param>
-        public BsonArray(int capacity)
-        {
-            _values = new List<BsonValue>(capacity);
-        }
-
-        // public operators
-        /// <summary>
-        /// Compares two BsonArray values.
-        /// </summary>
-        /// <param name="lhs">The first BsonArray.</param>
-        /// <param name="rhs">The other BsonArray.</param>
-        /// <returns>True if the two BsonArray values are not equal according to ==.</returns>
-        public static bool operator !=(BsonArray lhs, BsonArray rhs)
-        {
-            return !(lhs == rhs);
-        }
-
-        /// <summary>
-        /// Compares two BsonArray values.
-        /// </summary>
-        /// <param name="lhs">The first BsonArray.</param>
-        /// <param name="rhs">The other BsonArray.</param>
-        /// <returns>True if the two BsonArray values are equal according to ==.</returns>
-        public static bool operator ==(BsonArray lhs, BsonArray rhs)
-        {
-            return object.Equals(lhs, rhs); // handles lhs == null correctly
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the BsonType of this BsonValue.
-        /// </summary>
-        public override BsonType BsonType
-        {
-            get { return BsonType.Array; }
-        }
-
-        /// <summary>
-        /// Gets or sets the total number of elements the internal data structure can hold without resizing.
-        /// </summary>
-        public virtual int Capacity
-        {
-            get { return _values.Capacity; }
-            set { _values.Capacity = value; }
-        }
-
-        /// <summary>
-        /// Gets the count of array elements.
-        /// </summary>
-        public virtual int Count
-        {
-            get { return _values.Count; }
-        }
-
-        /// <summary>
-        /// Gets whether the array is read-only.
-        /// </summary>
-        public virtual bool IsReadOnly
-        {
-            get { return false; }
-        }
-
-        /// <summary>
-        /// Gets the array elements as raw values (see BsonValue.RawValue).
-        /// </summary>
-        [Obsolete("Use ToArray to ToList instead.")]
-        public virtual IEnumerable<object> RawValues
-        {
-            get { return _values.Select(v => v.RawValue); }
-        }
-
-        /// <summary>
-        /// Gets the array elements.
-        /// </summary>
-        public virtual IEnumerable<BsonValue> Values
-        {
-            get { return _values; }
-        }
-
-        // public indexers
-        /// <summary>
-        /// Gets or sets a value by position.
-        /// </summary>
-        /// <param name="index">The position.</param>
-        /// <returns>The value.</returns>
-        public override BsonValue this[int index]
-        {
-            get { return _values[index]; }
-            set
-            {
-                if (value == null)
-                {
-                    throw new ArgumentNullException("value");
-                }
-                _values[index] = value;
-            }
-        }
-
-        // public static methods
-        /// <summary>
-        /// Creates a new BsonArray.
-        /// </summary>
-        /// <param name="value">A value to be mapped to a BsonArray.</param>
-        /// <returns>A BsonArray or null.</returns>
-        public new static BsonArray Create(object value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-
-            return (BsonArray)BsonTypeMapper.MapToBsonValue(value, BsonType.Array);
-        }
-
-        // public methods
-        /// <summary>
-        /// Adds an element to the array.
-        /// </summary>
-        /// <param name="value">The value to add to the array.</param>
-        /// <returns>The array (so method calls can be chained).</returns>
-        public virtual BsonArray Add(BsonValue value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-
-            _values.Add(value);
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds multiple elements to the array.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        /// <returns>The array (so method calls can be chained).</returns>
-        public virtual BsonArray AddRange(IEnumerable<bool> values)
-        {
-            if (values == null)
-            {
-                throw new ArgumentNullException("values");
-            }
-
-            foreach (var value in values)
-            {
-                Add((BsonBoolean)value);
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds multiple elements to the array.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        /// <returns>The array (so method calls can be chained).</returns>
-        public virtual BsonArray AddRange(IEnumerable<BsonValue> values)
-        {
-            if (values == null)
-            {
-                throw new ArgumentNullException("values");
-            }
-
-            foreach (var value in values)
-            {
-                Add(value);
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds multiple elements to the array.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        /// <returns>The array (so method calls can be chained).</returns>
-        public virtual BsonArray AddRange(IEnumerable<DateTime> values)
-        {
-            if (values == null)
-            {
-                throw new ArgumentNullException("values");
-            }
-
-            foreach (var value in values)
-            {
-                Add(new BsonDateTime(value));
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds multiple elements to the array.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        /// <returns>The array (so method calls can be chained).</returns>
-        public virtual BsonArray AddRange(IEnumerable<double> values)
-        {
-            if (values == null)
-            {
-                throw new ArgumentNullException("values");
-            }
-
-            foreach (var value in values)
-            {
-                Add((BsonDouble)value);
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds multiple elements to the array.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        /// <returns>The array (so method calls can be chained).</returns>
-        public virtual BsonArray AddRange(IEnumerable<int> values)
-        {
-            if (values == null)
-            {
-                throw new ArgumentNullException("values");
-            }
-
-            foreach (var value in values)
-            {
-                Add((BsonInt32)value);
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds multiple elements to the array.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        /// <returns>The array (so method calls can be chained).</returns>
-        public virtual BsonArray AddRange(IEnumerable<long> values)
-        {
-            if (values == null)
-            {
-                throw new ArgumentNullException("values");
-            }
-
-            foreach (var value in values)
-            {
-                Add((BsonInt64)value);
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds multiple elements to the array.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        /// <returns>The array (so method calls can be chained).</returns>
-        public virtual BsonArray AddRange(IEnumerable<ObjectId> values)
-        {
-            if (values == null)
-            {
-                throw new ArgumentNullException("values");
-            }
-
-            foreach (var value in values)
-            {
-                Add(new BsonObjectId(value));
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds multiple elements to the array.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        /// <returns>The array (so method calls can be chained).</returns>
-        public virtual BsonArray AddRange(IEnumerable<string> values)
-        {
-            if (values == null)
-            {
-                throw new ArgumentNullException("values");
-            }
-
-            foreach (var value in values)
-            {
-                _values.Add((value == null) ? (BsonValue)BsonNull.Value : (BsonString)value);
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds multiple elements to the array.
-        /// </summary>
-        /// <param name="values">A list of values to add to the array.</param>
-        /// <returns>The array (so method calls can be chained).</returns>
-        public virtual BsonArray AddRange(IEnumerable values)
-        {
-            if (values == null)
-            {
-                throw new ArgumentNullException("values");
-            }
-
-            foreach (var value in values)
-            {
-                Add(BsonTypeMapper.MapToBsonValue(value));
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Creates a shallow clone of the array (see also DeepClone).
-        /// </summary>
-        /// <returns>A shallow clone of the array.</returns>
-        public override BsonValue Clone()
-        {
-            var clone = new BsonArray(_values.Capacity);
-            foreach (var value in _values)
-            {
-                clone.Add(value);
-            }
-            return clone;
-        }
-
-        /// <summary>
-        /// Clears the array.
-        /// </summary>
-        public virtual void Clear()
-        {
-            _values.Clear();
-        }
-
-        /// <summary>
-        /// Compares the array to another array.
-        /// </summary>
-        /// <param name="rhs">The other array.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this array is less than, equal to, or greather than the other.</returns>
-        public virtual int CompareTo(BsonArray rhs)
-        {
-            if (rhs == null) { return 1; }
-
-            // lhs and rhs might be subclasses of BsonArray
-            using (var lhsEnumerator = GetEnumerator())
-            using (var rhsEnumerator = rhs.GetEnumerator())
-            {
-                while (true)
-                {
-                    var lhsHasNext = lhsEnumerator.MoveNext();
-                    var rhsHasNext = rhsEnumerator.MoveNext();
-                    if (!lhsHasNext && !rhsHasNext) { return 0; }
-                    if (!lhsHasNext) { return -1; }
-                    if (!rhsHasNext) { return 1; }
-
-                    var lhsValue = lhsEnumerator.Current;
-                    var rhsValue = rhsEnumerator.Current;
-                    var result = lhsValue.CompareTo(rhsValue);
-                    if (result != 0) { return result; }
-                }
-            }
-        }
-
-        /// <summary>
-        /// Compares the array to another BsonValue.
-        /// </summary>
-        /// <param name="other">The other BsonValue.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this array is less than, equal to, or greather than the other BsonValue.</returns>
-        public override int CompareTo(BsonValue other)
-        {
-            if (other == null) { return 1; }
-            var otherArray = other as BsonArray;
-            if (otherArray != null)
-            {
-                return CompareTo(otherArray);
-            }
-            return CompareTypeTo(other);
-        }
-
-        /// <summary>
-        /// Tests whether the array contains a value.
-        /// </summary>
-        /// <param name="value">The value to test for.</param>
-        /// <returns>True if the array contains the value.</returns>
-        public virtual bool Contains(BsonValue value)
-        {
-            // don't throw ArgumentNullException if value is null
-            // just let _values.Contains return false
-            return _values.Contains(value);
-        }
-
-        /// <summary>
-        /// Copies elements from this array to another array.
-        /// </summary>
-        /// <param name="array">The other array.</param>
-        /// <param name="arrayIndex">The zero based index of the other array at which to start copying.</param>
-        public virtual void CopyTo(BsonValue[] array, int arrayIndex)
-        {
-            for (int i = 0, j = arrayIndex; i < _values.Count; i++, j++)
-            {
-                array[j] = _values[i];
-            }
-        }
-
-        /// <summary>
-        /// Copies elements from this array to another array as raw values (see BsonValue.RawValue).
-        /// </summary>
-        /// <param name="array">The other array.</param>
-        /// <param name="arrayIndex">The zero based index of the other array at which to start copying.</param>
-        [Obsolete("Use ToArray or ToList instead.")]
-        public virtual void CopyTo(object[] array, int arrayIndex)
-        {
-            for (int i = 0, j = arrayIndex; i < _values.Count; i++, j++)
-            {
-                array[j] = _values[i].RawValue;
-            }
-        }
-
-        /// <summary>
-        /// Creates a deep clone of the array (see also Clone).
-        /// </summary>
-        /// <returns>A deep clone of the array.</returns>
-        public override BsonValue DeepClone()
-        {
-            var clone = new BsonArray(_values.Capacity);
-            foreach (var value in _values)
-            {
-                clone.Add(value.DeepClone());
-            }
-            return clone;
-        }
-
-        /// <summary>
-        /// Compares this array to another array.
-        /// </summary>
-        /// <param name="obj">The other array.</param>
-        /// <returns>True if the two arrays are equal.</returns>
-        public bool Equals(BsonArray obj)
-        {
-            return Equals((object)obj); // handles obj == null correctly
-        }
-
-        /// <summary>
-        /// Compares this BsonArray to another object.
-        /// </summary>
-        /// <param name="obj">The other object.</param>
-        /// <returns>True if the other object is a BsonArray and equal to this one.</returns>
-        public override bool Equals(object obj)
-        {
-            if (object.ReferenceEquals(obj, null) || !(obj is BsonArray)) { return false; }
-
-            // lhs and rhs might be subclasses of BsonArray
-            var rhs = (BsonArray)obj;
-            return Values.SequenceEqual(rhs.Values);
-        }
-
-        /// <summary>
-        /// Gets an enumerator that can enumerate the elements of the array.
-        /// </summary>
-        /// <returns>An enumerator.</returns>
-        public virtual IEnumerator<BsonValue> GetEnumerator()
-        {
-            return _values.GetEnumerator();
-        }
-
-        /// <summary>
-        /// Gets the hash code.
-        /// </summary>
-        /// <returns>The hash code.</returns>
-        public override int GetHashCode()
-        {
-            return new Hasher()
-                .Hash(BsonType)
-                .HashElements(Values)
-                .GetHashCode();
-        }
-
-        /// <summary>
-        /// Gets the index of a value in the array.
-        /// </summary>
-        /// <param name="value">The value to search for.</param>
-        /// <returns>The zero based index of the value (or -1 if not found).</returns>
-        public virtual int IndexOf(BsonValue value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-            return _values.IndexOf(value);
-        }
-
-        /// <summary>
-        /// Gets the index of a value in the array.
-        /// </summary>
-        /// <param name="value">The value to search for.</param>
-        /// <param name="index">The zero based index at which to start the search.</param>
-        /// <returns>The zero based index of the value (or -1 if not found).</returns>
-        public virtual int IndexOf(BsonValue value, int index)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-            return _values.IndexOf(value, index);
-        }
-
-        /// <summary>
-        /// Gets the index of a value in the array.
-        /// </summary>
-        /// <param name="value">The value to search for.</param>
-        /// <param name="index">The zero based index at which to start the search.</param>
-        /// <param name="count">The number of elements to search.</param>
-        /// <returns>The zero based index of the value (or -1 if not found).</returns>
-        public virtual int IndexOf(BsonValue value, int index, int count)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-            return _values.IndexOf(value, index, count);
-        }
-
-        /// <summary>
-        /// Inserts a new value into the array.
-        /// </summary>
-        /// <param name="index">The zero based index at which to insert the new value.</param>
-        /// <param name="value">The new value.</param>
-        public virtual void Insert(int index, BsonValue value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-            _values.Insert(index, value);
-        }
-
-        /// <summary>
-        /// Removes the first occurrence of a value from the array.
-        /// </summary>
-        /// <param name="value">The value to remove.</param>
-        /// <returns>True if the value was removed.</returns>
-        public virtual bool Remove(BsonValue value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-            return _values.Remove(value);
-        }
-
-        /// <summary>
-        /// Removes an element from the array.
-        /// </summary>
-        /// <param name="index">The zero based index of the element to remove.</param>
-        public virtual void RemoveAt(int index)
-        {
-            _values.RemoveAt(index);
-        }
-
-        /// <summary>
-        /// Converts the BsonArray to an array of BsonValues.
-        /// </summary>
-        /// <returns>An array of BsonValues.</returns>
-        public virtual BsonValue[] ToArray()
-        {
-            return _values.ToArray();
-        }
-
-        /// <summary>
-        /// Converts the BsonArray to a list of BsonValues.
-        /// </summary>
-        /// <returns>A list of BsonValues.</returns>
-        public virtual List<BsonValue> ToList()
-        {
-            return _values.ToList();
-        }
-
-        /// <summary>
-        /// Returns a string representation of the array.
-        /// </summary>
-        /// <returns>A string representation of the array.</returns>
-        public override string ToString()
-        {
-            var sb = new StringBuilder();
-            sb.Append("[");
-            for (int i = 0; i < _values.Count; i++)
-            {
-                if (i > 0) { sb.Append(", "); }
-                sb.Append(_values[i].ToString());
-            }
-            sb.Append("]");
-            return sb.ToString();
-        }
-
-        // explicit interface implementations
-        // our version of Add returns BsonArray
-        void ICollection<BsonValue>.Add(BsonValue value)
-        {
-            Add(value);
-        }
-
-        IEnumerator IEnumerable.GetEnumerator()
-        {
-            return GetEnumerator();
-        }
-    }
-}

+ 0 - 362
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonBinaryData.cs

@@ -1,362 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Linq;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents BSON binary data.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonBinaryData : BsonValue, IComparable<BsonBinaryData>, IEquatable<BsonBinaryData>
-    {
-        // private fields
-        private readonly byte[] _bytes;
-        private readonly BsonBinarySubType _subType;
-        private readonly GuidRepresentation _guidRepresentation; // only relevant if subType is UuidStandard or UuidLegacy
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonBinaryData class.
-        /// </summary>
-        /// <param name="bytes">The binary data.</param>
-        public BsonBinaryData(byte[] bytes)
-            : this(bytes, BsonBinarySubType.Binary)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonBinaryData class.
-        /// </summary>
-        /// <param name="bytes">The binary data.</param>
-        /// <param name="subType">The binary data subtype.</param>
-        public BsonBinaryData(byte[] bytes, BsonBinarySubType subType)
-            : this(bytes, subType, subType == BsonBinarySubType.UuidStandard ? GuidRepresentation.Standard : GuidRepresentation.Unspecified)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonBinaryData class.
-        /// </summary>
-        /// <param name="bytes">The binary data.</param>
-        /// <param name="subType">The binary data subtype.</param>
-        /// <param name="guidRepresentation">The representation for Guids.</param>
-        public BsonBinaryData(byte[] bytes, BsonBinarySubType subType, GuidRepresentation guidRepresentation)
-        {
-            if (bytes == null)
-            {
-                throw new ArgumentNullException(nameof(bytes));
-            }
-            if (subType == BsonBinarySubType.UuidStandard || subType == BsonBinarySubType.UuidLegacy)
-            {
-                if (bytes.Length != 16)
-                {
-                    var message = string.Format(
-                        "Length must be 16, not {0}, when subType is {1}.",
-                        bytes.Length, subType);
-                    throw new ArgumentException(message, nameof(bytes));
-                }
-                BsonBinarySubType expectedSubType;
-                switch (guidRepresentation)
-                {
-                    case GuidRepresentation.CSharpLegacy:
-                    case GuidRepresentation.JavaLegacy:
-                    case GuidRepresentation.PythonLegacy:
-                    case GuidRepresentation.Unspecified:
-                        expectedSubType = BsonBinarySubType.UuidLegacy;
-                        break;
-
-                    case GuidRepresentation.Standard:
-                        expectedSubType = BsonBinarySubType.UuidStandard;
-                        break;
-
-                    default:
-                        throw new ArgumentException($"Invalid guidRepresentation: {guidRepresentation}.", nameof(guidRepresentation));
-                }
-
-                if (subType != expectedSubType)
-                {
-                    throw new ArgumentException($"GuidRepresentation {guidRepresentation} is only valid with subType {expectedSubType}, not with subType {subType}.", nameof(guidRepresentation));
-                }
-            }
-            else
-            {
-                if (guidRepresentation != GuidRepresentation.Unspecified)
-                {
-                    var message = string.Format(
-                        "GuidRepresentation must be Unspecified, not {0}, when subType is not UuidStandard or UuidLegacy.",
-                        guidRepresentation);
-                    throw new ArgumentException(message, nameof(guidRepresentation));
-                }
-            }
-            _bytes = bytes;
-            _subType = subType;
-            _guidRepresentation = guidRepresentation;
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonBinaryData class.
-        /// </summary>
-        /// <param name="guid">A Guid.</param>
-        public BsonBinaryData(Guid guid)
-            : this(guid, BsonDefaults.GuidRepresentation)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonBinaryData class.
-        /// </summary>
-        /// <param name="guid">A Guid.</param>
-        /// <param name="guidRepresentation">The representation for Guids.</param>
-        public BsonBinaryData(Guid guid, GuidRepresentation guidRepresentation)
-            : this(GuidConverter.ToBytes(guid, guidRepresentation), (guidRepresentation == GuidRepresentation.Standard) ? BsonBinarySubType.UuidStandard : BsonBinarySubType.UuidLegacy, guidRepresentation)
-        {
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the BsonType of this BsonValue.
-        /// </summary>
-        public override BsonType BsonType
-        {
-            get { return BsonType.Binary; }
-        }
-
-        /// <summary>
-        /// Gets the binary data.
-        /// </summary>
-        public byte[] Bytes
-        {
-            get { return _bytes; }
-        }
-
-        /// <summary>
-        /// Gets the representation to use when representing the Guid as BSON binary data.
-        /// </summary>
-        public GuidRepresentation GuidRepresentation
-        {
-            get { return _guidRepresentation; }
-        }
-
-        /// <summary>
-        /// Gets the BsonBinaryData as a Guid if the subtype is UuidStandard or UuidLegacy, otherwise null.
-        /// </summary>
-#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
-        [Obsolete("Use Value instead.")]
-        public override object RawValue
-        {
-            get
-            {
-                if (_subType == BsonBinarySubType.Binary || _subType == BsonBinarySubType.OldBinary)
-                {
-                    return _bytes;
-                }
-                else if (_subType == BsonBinarySubType.UuidStandard || _subType == BsonBinarySubType.UuidLegacy)
-                {
-                    return ToGuid();
-                }
-                else
-                {
-                    return null;
-                }
-            }
-        }
-#pragma warning restore 618
-
-        /// <summary>
-        /// Gets the binary data subtype.
-        /// </summary>
-        public BsonBinarySubType SubType
-        {
-            get { return _subType; }
-        }
-
-        // public operators
-        /// <summary>
-        /// Converts a byte array to a BsonBinaryData.
-        /// </summary>
-        /// <param name="bytes">A byte array.</param>
-        /// <returns>A BsonBinaryData.</returns>
-        public static implicit operator BsonBinaryData(byte[] bytes)
-        {
-            return new BsonBinaryData(bytes);
-        }
-
-        /// <summary>
-        /// Converts a Guid to a BsonBinaryData.
-        /// </summary>
-        /// <param name="value">A Guid.</param>
-        /// <returns>A BsonBinaryData.</returns>
-        public static implicit operator BsonBinaryData(Guid value)
-        {
-            return new BsonBinaryData(value);
-        }
-
-        /// <summary>
-        /// Compares two BsonBinaryData values.
-        /// </summary>
-        /// <param name="lhs">The first BsonBinaryData.</param>
-        /// <param name="rhs">The other BsonBinaryData.</param>
-        /// <returns>True if the two BsonBinaryData values are not equal according to ==.</returns>
-        public static bool operator !=(BsonBinaryData lhs, BsonBinaryData rhs)
-        {
-            return !(lhs == rhs);
-        }
-
-        /// <summary>
-        /// Compares two BsonBinaryData values.
-        /// </summary>
-        /// <param name="lhs">The first BsonBinaryData.</param>
-        /// <param name="rhs">The other BsonBinaryData.</param>
-        /// <returns>True if the two BsonBinaryData values are equal according to ==.</returns>
-        public static bool operator ==(BsonBinaryData lhs, BsonBinaryData rhs)
-        {
-            if (object.ReferenceEquals(lhs, null)) { return object.ReferenceEquals(rhs, null); }
-            return lhs.Equals(rhs);
-        }
-
-        // public static methods
-        /// <summary>
-        /// Creates a new BsonBinaryData.
-        /// </summary>
-        /// <param name="value">An object to be mapped to a BsonBinaryData.</param>
-        /// <returns>A BsonBinaryData or null.</returns>
-        public new static BsonBinaryData Create(object value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-
-            return (BsonBinaryData)BsonTypeMapper.MapToBsonValue(value, BsonType.Binary);
-        }
-
-        // public methods
-        /// <summary>
-        /// Compares this BsonBinaryData to another BsonBinaryData.
-        /// </summary>
-        /// <param name="other">The other BsonBinaryData.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonBinaryData is less than, equal to, or greather than the other.</returns>
-        public int CompareTo(BsonBinaryData other)
-        {
-            if (other == null) { return 1; }
-            int r = _subType.CompareTo(other._subType);
-            if (r != 0) { return r; }
-            for (int i = 0; i < _bytes.Length && i < other._bytes.Length; i++)
-            {
-                r = _bytes[i].CompareTo(other._bytes[i]);
-                if (r != 0) { return r; }
-            }
-            return _bytes.Length.CompareTo(other._bytes.Length);
-        }
-
-        /// <summary>
-        /// Compares the BsonBinaryData to another BsonValue.
-        /// </summary>
-        /// <param name="other">The other BsonValue.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonBinaryData is less than, equal to, or greather than the other BsonValue.</returns>
-        public override int CompareTo(BsonValue other)
-        {
-            if (other == null) { return 1; }
-            var otherBinaryData = other as BsonBinaryData;
-            if (otherBinaryData != null)
-            {
-                return CompareTo(otherBinaryData);
-            }
-            return CompareTypeTo(other);
-        }
-
-        /// <summary>
-        /// Compares this BsonBinaryData to another BsonBinaryData.
-        /// </summary>
-        /// <param name="rhs">The other BsonBinaryData.</param>
-        /// <returns>True if the two BsonBinaryData values are equal.</returns>
-        public bool Equals(BsonBinaryData rhs)
-        {
-            if (object.ReferenceEquals(rhs, null) || GetType() != rhs.GetType()) { return false; }
-            // note: guidRepresentation is not considered when testing for Equality
-            return object.ReferenceEquals(this, rhs) || _subType == rhs._subType && _bytes.SequenceEqual(rhs._bytes);
-        }
-
-        /// <summary>
-        /// Compares this BsonBinaryData to another object.
-        /// </summary>
-        /// <param name="obj">The other object.</param>
-        /// <returns>True if the other object is a BsonBinaryData and equal to this one.</returns>
-        public override bool Equals(object obj)
-        {
-            return Equals(obj as BsonBinaryData); // works even if obj is null or of a different type
-        }
-
-        /// <summary>
-        /// Gets the hash code.
-        /// </summary>
-        /// <returns>The hash code.</returns>
-        public override int GetHashCode()
-        {
-            // see Effective Java by Joshua Bloch
-            // note: guidRepresentation is not considered when computing the hash code
-            int hash = 17;
-            hash = 37 * hash + BsonType.GetHashCode();
-            foreach (byte b in _bytes)
-            {
-                hash = 37 * hash + b;
-            }
-            hash = 37 * hash + _subType.GetHashCode();
-            return hash;
-        }
-
-        /// <summary>
-        /// Converts this BsonBinaryData to a Guid.
-        /// </summary>
-        /// <returns>A Guid.</returns>
-        public Guid ToGuid()
-        {
-            return ToGuid(_guidRepresentation);
-        }
-
-        /// <summary>
-        /// Converts this BsonBinaryData to a Guid.
-        /// </summary>
-        /// <param name="guidRepresentation">The representation for Guids.</param>
-        /// <returns>A Guid.</returns>
-        public Guid ToGuid(GuidRepresentation guidRepresentation)
-        {
-            if (_subType != BsonBinarySubType.UuidStandard && _subType != BsonBinarySubType.UuidLegacy)
-            {
-                var message = string.Format("SubType must be UuidStandard or UuidLegacy, not {0}.", _subType);
-                throw new InvalidOperationException(message);
-            }
-            if (guidRepresentation == GuidRepresentation.Unspecified)
-            {
-                throw new ArgumentException("GuidRepresentation cannot be Unspecified.");
-            }
-            return GuidConverter.FromBytes(_bytes, guidRepresentation);
-        }
-
-        /// <summary>
-        /// Returns a string representation of the binary data.
-        /// </summary>
-        /// <returns>A string representation of the binary data.</returns>
-        public override string ToString()
-        {
-            return string.Format("{0}:0x{1}", _subType, BsonUtils.ToHexString(_bytes));
-        }
-    }
-}

+ 0 - 58
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonBinarySubType.cs

@@ -1,58 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents the binary data subtype of a BsonBinaryData.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public enum BsonBinarySubType
-    {
-        /// <summary>
-        /// Binary data.
-        /// </summary>
-        Binary = 0x00,
-        /// <summary>
-        /// A function.
-        /// </summary>
-        Function = 0x01,
-        /// <summary>
-        /// Obsolete binary data subtype (use Binary instead).
-        /// </summary>
-        [Obsolete("Use Binary instead")]
-        OldBinary = 0x02,
-        /// <summary>
-        /// A UUID in a driver dependent legacy byte order.
-        /// </summary>
-        UuidLegacy = 0x03,
-        /// <summary>
-        /// A UUID in standard network byte order.
-        /// </summary>
-        UuidStandard = 0x04,
-        /// <summary>
-        /// An MD5 hash.
-        /// </summary>
-        MD5 = 0x05,
-        /// <summary>
-        /// User defined binary data.
-        /// </summary>
-        UserDefined = 0x80
-    }
-}

+ 0 - 312
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonBoolean.cs

@@ -1,312 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using MongoDB.Bson.IO;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents a BSON boolean value.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonBoolean : BsonValue, IComparable<BsonBoolean>, IEquatable<BsonBoolean>
-    {
-        // private static fields
-        private static BsonBoolean __falseInstance = new BsonBoolean(false);
-        private static BsonBoolean __trueInstance = new BsonBoolean(true);
-
-        // private fields
-        private readonly bool _value;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonBoolean class.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        public BsonBoolean(bool value)
-        {
-            _value = value;
-        }
-
-        // public static properties
-        /// <summary>
-        /// Gets the instance of BsonBoolean that represents false.
-        /// </summary>
-        public static BsonBoolean False
-        {
-            get { return __falseInstance; }
-        }
-
-        /// <summary>
-        /// Gets the instance of BsonBoolean that represents true.
-        /// </summary>
-        public static BsonBoolean True
-        {
-            get { return __trueInstance; }
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the BsonType of this BsonValue.
-        /// </summary>
-        public override BsonType BsonType
-        {
-            get { return BsonType.Boolean; }
-        }
-
-        /// <summary>
-        /// Gets the BsonBoolean as a bool.
-        /// </summary>
-        [Obsolete("Use Value instead.")]
-        public override object RawValue
-        {
-            get { return _value; }
-        }
-
-        /// <summary>
-        /// Gets the value of this BsonBoolean.
-        /// </summary>
-        public bool Value
-        {
-            get { return _value; }
-        }
-
-        // public operators
-        /// <summary>
-        /// Converts a bool to a BsonBoolean.
-        /// </summary>
-        /// <param name="value">A bool.</param>
-        /// <returns>A BsonBoolean.</returns>
-        public static implicit operator BsonBoolean(bool value)
-        {
-            return value ? __trueInstance : __falseInstance;
-        }
-
-        /// <summary>
-        /// Compares two BsonBoolean values.
-        /// </summary>
-        /// <param name="lhs">The first BsonBoolean.</param>
-        /// <param name="rhs">The other BsonBoolean.</param>
-        /// <returns>True if the two BsonBoolean values are not equal according to ==.</returns>
-        public static bool operator !=(BsonBoolean lhs, BsonBoolean rhs)
-        {
-            return !(lhs == rhs);
-        }
-
-        /// <summary>
-        /// Compares two BsonBoolean values.
-        /// </summary>
-        /// <param name="lhs">The first BsonBoolean.</param>
-        /// <param name="rhs">The other BsonBoolean.</param>
-        /// <returns>True if the two BsonBoolean values are equal according to ==.</returns>
-        public static bool operator ==(BsonBoolean lhs, BsonBoolean rhs)
-        {
-            if (object.ReferenceEquals(lhs, null)) { return object.ReferenceEquals(rhs, null); }
-            return lhs.Equals(rhs);
-        }
-
-        // public static methods
-        /// <summary>
-        /// Returns one of the two possible BsonBoolean values.
-        /// </summary>
-        /// <param name="value">An object to be mapped to a BsonBoolean.</param>
-        /// <returns>A BsonBoolean or null.</returns>
-        public new static BsonBoolean Create(object value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-
-            return (BsonBoolean)BsonTypeMapper.MapToBsonValue(value, BsonType.Boolean);
-        }
-
-        // public methods
-        /// <summary>
-        /// Compares this BsonBoolean to another BsonBoolean.
-        /// </summary>
-        /// <param name="other">The other BsonBoolean.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonBoolean is less than, equal to, or greather than the other.</returns>
-        public int CompareTo(BsonBoolean other)
-        {
-            if (other == null) { return 1; }
-            return (_value ? 1 : 0).CompareTo(other._value ? 1 : 0);
-        }
-
-        /// <summary>
-        /// Compares the BsonBoolean to another BsonValue.
-        /// </summary>
-        /// <param name="other">The other BsonValue.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonBoolean is less than, equal to, or greather than the other BsonValue.</returns>
-        public override int CompareTo(BsonValue other)
-        {
-            if (other == null) { return 1; }
-            var otherBoolean = other as BsonBoolean;
-            if (otherBoolean != null)
-            {
-                return (_value ? 1 : 0).CompareTo(otherBoolean._value ? 1 : 0);
-            }
-            return CompareTypeTo(other);
-        }
-
-        /// <summary>
-        /// Compares this BsonBoolean to another BsonBoolean.
-        /// </summary>
-        /// <param name="rhs">The other BsonBoolean.</param>
-        /// <returns>True if the two BsonBoolean values are equal.</returns>
-        public bool Equals(BsonBoolean rhs)
-        {
-            if (object.ReferenceEquals(rhs, null) || GetType() != rhs.GetType()) { return false; }
-            return _value == rhs._value;
-        }
-
-        /// <summary>
-        /// Compares this BsonBoolean to another object.
-        /// </summary>
-        /// <param name="obj">The other object.</param>
-        /// <returns>True if the other object is a BsonBoolean and equal to this one.</returns>
-        public override bool Equals(object obj)
-        {
-            return Equals(obj as BsonBoolean); // works even if obj is null or of a different type
-        }
-
-        /// <summary>
-        /// Gets the hash code.
-        /// </summary>
-        /// <returns>The hash code.</returns>
-        public override int GetHashCode()
-        {
-            // see Effective Java by Joshua Bloch
-            int hash = 17;
-            hash = 37 * hash + BsonType.GetHashCode();
-            hash = 37 * hash + _value.GetHashCode();
-            return hash;
-        }
-
-        /// <summary>
-        /// Converts this BsonValue to a Boolean (using the JavaScript definition of truthiness).
-        /// </summary>
-        /// <returns>A Boolean.</returns>
-        public override bool ToBoolean()
-        {
-            return _value;
-        }
-
-        /// <summary>
-        /// Returns a string representation of the value.
-        /// </summary>
-        /// <returns>A string representation of the value.</returns>
-        public override string ToString()
-        {
-            return JsonConvert.ToString(_value);
-        }
-
-        // protected methods
-        /// <inheritdoc/>
-        protected override TypeCode IConvertibleGetTypeCodeImplementation()
-        {
-            return TypeCode.Boolean;
-        }
-
-        /// <inheritdoc/>
-        protected override bool IConvertibleToBooleanImplementation(IFormatProvider provider)
-        {
-            return _value;
-        }
-
-        /// <inheritdoc/>
-        protected override byte IConvertibleToByteImplementation(IFormatProvider provider)
-        {
-            return Convert.ToByte(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override decimal IConvertibleToDecimalImplementation(IFormatProvider provider)
-        {
-            return Convert.ToDecimal(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override double IConvertibleToDoubleImplementation(IFormatProvider provider)
-        {
-            return Convert.ToDouble(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override short IConvertibleToInt16Implementation(IFormatProvider provider)
-        {
-            return Convert.ToInt16(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override int IConvertibleToInt32Implementation(IFormatProvider provider)
-        {
-            return Convert.ToInt32(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override long IConvertibleToInt64Implementation(IFormatProvider provider)
-        {
-            return Convert.ToInt64(_value, provider);
-        }
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override sbyte IConvertibleToSByteImplementation(IFormatProvider provider)
-        {
-            return Convert.ToSByte(_value, provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-        protected override float IConvertibleToSingleImplementation(IFormatProvider provider)
-        {
-            return Convert.ToSingle(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override string IConvertibleToStringImplementation(IFormatProvider provider)
-        {
-            return Convert.ToString(_value, provider);
-        }
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override ushort IConvertibleToUInt16Implementation(IFormatProvider provider)
-        {
-            return Convert.ToUInt16(_value, provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override uint IConvertibleToUInt32Implementation(IFormatProvider provider)
-        {
-            return Convert.ToUInt32(_value, provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override ulong IConvertibleToUInt64Implementation(IFormatProvider provider)
-        {
-            return Convert.ToUInt64(_value, provider);
-        }
-#pragma warning restore
-    }
-}

+ 0 - 284
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonDateTime.cs

@@ -1,284 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using MongoDB.Bson.IO;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents a BSON DateTime value.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonDateTime : BsonValue, IComparable<BsonDateTime>, IEquatable<BsonDateTime>
-    {
-        // private fields
-        private readonly long _millisecondsSinceEpoch;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonDateTime class.
-        /// </summary>
-        /// <param name="value">A DateTime.</param>
-        public BsonDateTime(DateTime value)
-        {
-            _millisecondsSinceEpoch = BsonUtils.ToMillisecondsSinceEpoch(value);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDateTime class.
-        /// </summary>
-        /// <param name="millisecondsSinceEpoch">Milliseconds since Unix Epoch.</param>
-        public BsonDateTime(long millisecondsSinceEpoch)
-        {
-            _millisecondsSinceEpoch = millisecondsSinceEpoch;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the BsonType of this BsonValue.
-        /// </summary>
-        public override BsonType BsonType
-        {
-            get { return BsonType.DateTime; }
-        }
-
-        /// <summary>
-        /// Gets whether this BsonDateTime is a valid .NET DateTime.
-        /// </summary>
-        public override bool IsValidDateTime
-        {
-            get
-            {
-                return
-                    _millisecondsSinceEpoch >= BsonConstants.DateTimeMinValueMillisecondsSinceEpoch &&
-                    _millisecondsSinceEpoch <= BsonConstants.DateTimeMaxValueMillisecondsSinceEpoch;
-            }
-        }
-
-        /// <summary>
-        /// Gets the number of milliseconds since the Unix Epoch.
-        /// </summary>
-        public long MillisecondsSinceEpoch
-        {
-            get { return _millisecondsSinceEpoch; }
-        }
-
-        /// <summary>
-        /// Gets the number of milliseconds since the Unix Epoch.
-        /// </summary>
-        [Obsolete("Use MillisecondsSinceEpoch instead.")]
-        public override object RawValue
-        {
-            get { return _millisecondsSinceEpoch; }
-        }
-
-        /// <summary>
-        /// Gets the DateTime value.
-        /// </summary>
-        [Obsolete("Use ToUniversalTime instead.")]
-        public DateTime Value
-        {
-            get
-            {
-                return BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(_millisecondsSinceEpoch);
-            }
-        }
-
-        // public operators
-        /// <summary>
-        /// Converts a DateTime to a BsonDateTime.
-        /// </summary>
-        /// <param name="value">A DateTime.</param>
-        /// <returns>A BsonDateTime.</returns>
-        public static implicit operator BsonDateTime(DateTime value)
-        {
-            return new BsonDateTime(value);
-        }
-
-        /// <summary>
-        /// Compares two BsonDateTime values.
-        /// </summary>
-        /// <param name="lhs">The first BsonDateTime.</param>
-        /// <param name="rhs">The other BsonDateTime.</param>
-        /// <returns>True if the two BsonDateTime values are not equal according to ==.</returns>
-        public static bool operator !=(BsonDateTime lhs, BsonDateTime rhs)
-        {
-            return !(lhs == rhs);
-        }
-
-        /// <summary>
-        /// Compares two BsonDateTime values.
-        /// </summary>
-        /// <param name="lhs">The first BsonDateTime.</param>
-        /// <param name="rhs">The other BsonDateTime.</param>
-        /// <returns>True if the two BsonDateTime values are equal according to ==.</returns>
-        public static bool operator ==(BsonDateTime lhs, BsonDateTime rhs)
-        {
-            if (object.ReferenceEquals(lhs, null)) { return object.ReferenceEquals(rhs, null); }
-            return lhs.Equals(rhs);
-        }
-
-        // public static methods
-        /// <summary>
-        /// Creates a new BsonDateTime.
-        /// </summary>
-        /// <param name="value">An object to be mapped to a BsonDateTime.</param>
-        /// <returns>A BsonDateTime or null.</returns>
-        public new static BsonDateTime Create(object value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-
-            return (BsonDateTime)BsonTypeMapper.MapToBsonValue(value, BsonType.DateTime);
-        }
-
-        // public methods
-        /// <summary>
-        /// Compares this BsonDateTime to another BsonDateTime.
-        /// </summary>
-        /// <param name="other">The other BsonDateTime.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonDateTime is less than, equal to, or greather than the other.</returns>
-        public int CompareTo(BsonDateTime other)
-        {
-            if (other == null) { return 1; }
-            return _millisecondsSinceEpoch.CompareTo(other._millisecondsSinceEpoch);
-        }
-
-        /// <summary>
-        /// Compares the BsonDateTime to another BsonValue.
-        /// </summary>
-        /// <param name="other">The other BsonValue.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonDateTime is less than, equal to, or greather than the other BsonValue.</returns>
-        public override int CompareTo(BsonValue other)
-        {
-            if (other == null) { return 1; }
-            var otherDateTime = other as BsonDateTime;
-            if (otherDateTime != null)
-            {
-                return _millisecondsSinceEpoch.CompareTo(otherDateTime._millisecondsSinceEpoch);
-            }
-            var otherTimestamp = other as BsonTimestamp;
-            if (otherTimestamp != null)
-            {
-                return _millisecondsSinceEpoch.CompareTo(otherTimestamp.Timestamp * 1000L); // timestamp is in seconds
-            }
-            return CompareTypeTo(other);
-        }
-
-        /// <summary>
-        /// Compares this BsonDateTime to another BsonDateTime.
-        /// </summary>
-        /// <param name="rhs">The other BsonDateTime.</param>
-        /// <returns>True if the two BsonDateTime values are equal.</returns>
-        public bool Equals(BsonDateTime rhs)
-        {
-            if (object.ReferenceEquals(rhs, null) || GetType() != rhs.GetType()) { return false; }
-            return _millisecondsSinceEpoch == rhs._millisecondsSinceEpoch;
-        }
-
-        /// <summary>
-        /// Compares this BsonDateTime to another object.
-        /// </summary>
-        /// <param name="obj">The other object.</param>
-        /// <returns>True if the other object is a BsonDateTime and equal to this one.</returns>
-        public override bool Equals(object obj)
-        {
-            return Equals(obj as BsonDateTime); // works even if obj is null or of a different type
-        }
-
-        /// <summary>
-        /// Gets the hash code.
-        /// </summary>
-        /// <returns>The hash code.</returns>
-        public override int GetHashCode()
-        {
-            // see Effective Java by Joshua Bloch
-            int hash = 17;
-            hash = 37 * hash + BsonType.GetHashCode();
-            hash = 37 * hash + _millisecondsSinceEpoch.GetHashCode();
-            return hash;
-        }
-
-        /// <summary>
-        /// Converts this BsonValue to a DateTime in local time.
-        /// </summary>
-        /// <returns>A DateTime.</returns>
-        public override DateTime ToLocalTime()
-        {
-            return BsonUtils.ToLocalTime(ToUniversalTime());
-        }
-
-        /// <summary>
-        /// Converts this BsonValue to a DateTime? in local time.
-        /// </summary>
-        /// <returns>A DateTime?.</returns>
-        public override DateTime? ToNullableLocalTime()
-        {
-            return ToLocalTime();
-        }
-
-        /// <summary>
-        /// Converts this BsonValue to a DateTime? in UTC.
-        /// </summary>
-        /// <returns>A DateTime?.</returns>
-        public override DateTime? ToNullableUniversalTime()
-        {
-            return ToUniversalTime();
-        }
-
-        /// <summary>
-        /// Converts this BsonValue to a DateTime in UTC.
-        /// </summary>
-        /// <returns>A DateTime.</returns>
-        public override DateTime ToUniversalTime()
-        {
-            return BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(_millisecondsSinceEpoch);
-        }
-
-        /// <summary>
-        /// Returns a string representation of the value.
-        /// </summary>
-        /// <returns>A string representation of the value.</returns>
-        public override string ToString()
-        {
-            if (IsValidDateTime)
-            {
-                return BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(_millisecondsSinceEpoch).ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFFK");
-            }
-            else
-            {
-                return JsonConvert.ToString(_millisecondsSinceEpoch);
-            }
-        }
-
-        // protected methods
-        /// <inheritdoc/>
-        protected override TypeCode IConvertibleGetTypeCodeImplementation()
-        {
-            return TypeCode.DateTime;
-        }
-
-        /// <inheritdoc/>
-        protected override DateTime IConvertibleToDateTimeImplementation(IFormatProvider provider)
-        {
-            return ToUniversalTime();
-        }
-    }
-}

+ 0 - 350
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonDecimal128.cs

@@ -1,350 +0,0 @@
-/* Copyright 2016-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using MongoDB.Bson.IO;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents a BSON Decimal128 value.
-    /// </summary>
-    /// <seealso cref="MongoDB.Bson.BsonValue" />
-#if NET452
-    [Serializable]
-#endif
-    public class BsonDecimal128 : BsonValue, IComparable<BsonDecimal128>, IEquatable<BsonDecimal128>
-    {
-        // private fields
-        private readonly Decimal128 _value;
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BsonDecimal128" /> class.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        public BsonDecimal128(Decimal128 value)
-        {
-            _value = value;
-        }
-
-        // public properties
-        /// <inheritdoc />
-        public override BsonType BsonType
-        {
-            get { return BsonType.Decimal128; }
-        }
-
-        /// <inheritdoc />
-        [Obsolete("Use Value instead.")]
-        public override object RawValue
-        {
-            get { return _value; }
-        }
-
-        /// <summary>
-        /// Gets the value.
-        /// </summary>
-        public Decimal128 Value
-        {
-            get { return _value; }
-        }
-
-        // public operators
-        /// <summary>
-        /// Converts a Decimal128 to a BsonDecimal128.
-        /// </summary>
-        /// <param name="value">A Decimal128.</param>
-        /// <returns>A BsonDecimal128.</returns>
-        public static implicit operator BsonDecimal128(Decimal128 value)
-        {
-            return new BsonDecimal128(value);
-        }
-
-        /// <summary>
-        /// Compares two BsonDecimal128 values.
-        /// </summary>
-        /// <param name="lhs">The first BsonDecimal128.</param>
-        /// <param name="rhs">The other BsonDecimal128.</param>
-        /// <returns>True if the two BsonDecimal128 values are not equal according to ==.</returns>
-        public static bool operator !=(BsonDecimal128 lhs, BsonDecimal128 rhs)
-        {
-            return !(lhs == rhs);
-        }
-
-        /// <summary>
-        /// Compares two BsonDecimal128 values.
-        /// </summary>
-        /// <param name="lhs">The first BsonDecimal128.</param>
-        /// <param name="rhs">The other BsonDecimal128.</param>
-        /// <returns>True if the two BsonDecimal128 values are equal according to ==.</returns>
-        public static bool operator ==(BsonDecimal128 lhs, BsonDecimal128 rhs)
-        {
-            if (object.ReferenceEquals(lhs, null)) { return object.ReferenceEquals(rhs, null); }
-            return lhs.OperatorEqualsImplementation(rhs);
-        }
-
-        // public static methods
-        /// <summary>
-        /// Creates a new instance of the BsonDecimal128 class.
-        /// </summary>
-        /// <param name="value">An object to be mapped to a BsonDecimal128.</param>
-        /// <returns>A BsonDecimal128.</returns>
-        public new static BsonDecimal128 Create(object value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-
-            return (BsonDecimal128)BsonTypeMapper.MapToBsonValue(value, BsonType.Decimal128);
-        }
-
-        // public methods
-        /// <summary>
-        /// Compares this BsonDecimal128 to another BsonDecimal128.
-        /// </summary>
-        /// <param name="other">The other BsonDecimal128.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonDecimal128 is less than, equal to, or greather than the other.</returns>
-        public int CompareTo(BsonDecimal128 other)
-        {
-            if (other == null) { return 1; }
-            return _value.CompareTo(other._value);
-        }
-
-        /// <inheritdoc />
-        public override int CompareTo(BsonValue other)
-        {
-            if (other == null) { return 1; }
-
-            var otherDecimal128 = other as BsonDecimal128;
-            if (otherDecimal128 != null)
-            {
-                return _value.CompareTo(otherDecimal128.Value);
-            }
-
-            var otherInt32 = other as BsonInt32;
-            if (otherInt32 != null)
-            {
-                return _value.CompareTo((Decimal128)otherInt32.Value);
-            }
-
-            var otherInt64 = other as BsonInt64;
-            if (otherInt64 != null)
-            {
-                return _value.CompareTo((Decimal128)otherInt64.Value);
-            }
-
-            var otherDouble = other as BsonDouble;
-            if (otherDouble != null)
-            {
-                return _value.CompareTo((Decimal128)otherDouble.Value);
-            }
-
-            return CompareTypeTo(other);
-        }
-
-        /// <summary>
-        /// Compares this BsonDecimal128 to another BsonDecimal128.
-        /// </summary>
-        /// <param name="rhs">The other BsonDecimal128.</param>
-        /// <returns>True if the two BsonDecimal128 values are equal.</returns>
-        public bool Equals(BsonDecimal128 rhs)
-        {
-            if (object.ReferenceEquals(rhs, null) || GetType() != rhs.GetType()) { return false; }
-            return _value.Equals(rhs._value); // use Equals instead of == so NaN is handled correctly
-        }
-
-        /// <inheritdoc />
-        public override bool Equals(object obj)
-        {
-            return Equals(obj as BsonDecimal128); // works even if obj is null or of a different type
-        }
-
-        /// <inheritdoc />
-        public override int GetHashCode()
-        {
-            // see Effective Java by Joshua Bloch
-            int hash = 17;
-            hash = 37 * hash + BsonType.GetHashCode();
-            hash = 37 * hash + _value.GetHashCode();
-            return hash;
-        }
-
-        /// <inheritdoc />
-        public override bool ToBoolean()
-        {
-            return !(Decimal128.IsNaN(_value) || _value.Equals(Decimal128.Zero));
-        }
-
-        /// <inheritdoc />
-        public override decimal ToDecimal()
-        {
-            return Decimal128.ToDecimal(_value);
-        }
-
-        /// <inheritdoc />
-        public override Decimal128 ToDecimal128()
-        {
-            return _value;
-        }
-
-        /// <inheritdoc />
-        public override double ToDouble()
-        {
-            return Decimal128.ToDouble(_value);
-        }
-
-        /// <inheritdoc />
-        public override int ToInt32()
-        {
-            return Decimal128.ToInt32(_value);
-        }
-
-        /// <inheritdoc />
-        public override long ToInt64()
-        {
-            return Decimal128.ToInt64(_value);
-        }
-
-        /// <inheritdoc />
-        public override string ToString()
-        {
-            return JsonConvert.ToString(_value);
-        }
-
-        // protected methods
-        /// <inheritdoc/>
-        protected override TypeCode IConvertibleGetTypeCodeImplementation()
-        {
-            return TypeCode.Object;
-        }
-
-        /// <inheritdoc/>
-        protected override bool IConvertibleToBooleanImplementation(IFormatProvider provider)
-        {
-            return ((IConvertible)_value).ToBoolean(provider);
-        }
-
-        /// <inheritdoc/>
-        protected override byte IConvertibleToByteImplementation(IFormatProvider provider)
-        {
-            return ((IConvertible)_value).ToByte(provider);
-        }
-
-        /// <inheritdoc/>
-        protected override decimal IConvertibleToDecimalImplementation(IFormatProvider provider)
-        {
-            return ((IConvertible)_value).ToDecimal(provider);
-        }
-
-        /// <inheritdoc/>
-        protected override double IConvertibleToDoubleImplementation(IFormatProvider provider)
-        {
-            return ((IConvertible)_value).ToDouble(provider);
-        }
-
-        /// <inheritdoc/>
-        protected override short IConvertibleToInt16Implementation(IFormatProvider provider)
-        {
-            return ((IConvertible)_value).ToInt16(provider);
-        }
-
-        /// <inheritdoc/>
-        protected override int IConvertibleToInt32Implementation(IFormatProvider provider)
-        {
-            return ((IConvertible)_value).ToInt32(provider);
-        }
-
-        /// <inheritdoc/>
-        protected override long IConvertibleToInt64Implementation(IFormatProvider provider)
-        {
-            return ((IConvertible)_value).ToInt64(provider);
-        }
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override sbyte IConvertibleToSByteImplementation(IFormatProvider provider)
-        {
-            return ((IConvertible)_value).ToSByte(provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-        protected override float IConvertibleToSingleImplementation(IFormatProvider provider)
-        {
-            return ((IConvertible)_value).ToSingle(provider);
-        }
-
-        /// <inheritdoc/>
-        protected override string IConvertibleToStringImplementation(IFormatProvider provider)
-        {
-            return ((IConvertible)_value).ToString(provider);
-        }
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override ushort IConvertibleToUInt16Implementation(IFormatProvider provider)
-        {
-            return ((IConvertible)_value).ToUInt16(provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override uint IConvertibleToUInt32Implementation(IFormatProvider provider)
-        {
-            return ((IConvertible)_value).ToUInt32(provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override ulong IConvertibleToUInt64Implementation(IFormatProvider provider)
-        {
-            return ((IConvertible)_value).ToUInt64(provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-        protected override bool OperatorEqualsImplementation(BsonValue rhs)
-        {
-            var rhsDecimal128 = rhs as BsonDecimal128;
-            if (rhsDecimal128 != null)
-            {
-                return _value == rhsDecimal128._value; // use == instead of Equals so NaN is handled correctly
-            }
-
-            var rhsInt32 = rhs as BsonInt32;
-            if (rhsInt32 != null)
-            {
-                return _value == (Decimal128)rhsInt32.Value;
-            }
-
-            var rhsInt64 = rhs as BsonInt64;
-            if (rhsInt64 != null)
-            {
-                return _value == (Decimal128)rhsInt64.Value;
-            }
-
-            var rhsDouble = rhs as BsonDouble;
-            if (rhsDouble != null)
-            {
-                return _value == (Decimal128)rhsDouble.Value; // use == instead of Equals so NaN is handled correctly
-            }
-
-            return this.Equals(rhs);
-        }
-    }
-}

+ 0 - 1313
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonDocument.cs

@@ -1,1313 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using MongoDB.Bson.IO;
-using MongoDB.Bson.Serialization;
-using MongoDB.Bson.Serialization.Serializers;
-using MongoDB.Shared;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents a BSON document.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonDocument : BsonValue, IComparable<BsonDocument>, IConvertibleToBsonDocument, IEnumerable<BsonElement>, IEquatable<BsonDocument>
-    {
-        // constants
-        private const int __indexesThreshold = 8; // the _indexes dictionary will not be created until the document grows to contain 8 elements
-
-        // private fields
-        // use a list and a dictionary because we want to preserve the order in which the elements were added
-        // if duplicate names are present only the first one will be in the dictionary (the others can only be accessed by index)
-        private readonly List<BsonElement> _elements = new List<BsonElement>();
-        private Dictionary<string, int> _indexes = null; // maps names to indexes into elements list (not created until there are enough elements to justify it)
-        private bool _allowDuplicateNames;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonDocument class.
-        /// </summary>
-        public BsonDocument()
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocument class specifying whether duplicate element names are allowed
-        /// (allowing duplicate element names is not recommended).
-        /// </summary>
-        /// <param name="allowDuplicateNames">Whether duplicate element names are allowed.</param>
-        public BsonDocument(bool allowDuplicateNames)
-        {
-            _allowDuplicateNames = allowDuplicateNames;
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocument class and adds one element.
-        /// </summary>
-        /// <param name="element">An element to add to the document.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonDocument(BsonElement element)
-        {
-            Add(element);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocument class and adds new elements from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">A dictionary to initialize the document from.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonDocument(Dictionary<string, object> dictionary)
-        {
-            AddRange(dictionary);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocument class and adds new elements from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">A dictionary to initialize the document from.</param>
-        /// <param name="keys">A list of keys to select values from the dictionary.</param>
-        [Obsolete("Use BsonDocument(IEnumerable<BsonElement> elements) instead.")]
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonDocument(Dictionary<string, object> dictionary, IEnumerable<string> keys)
-        {
-            Add(dictionary, keys);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocument class and adds new elements from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">A dictionary to initialize the document from.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonDocument(IEnumerable<KeyValuePair<string, object>> dictionary)
-        {
-            AddRange(dictionary);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocument class and adds new elements from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">A dictionary to initialize the document from.</param>
-        /// <param name="keys">A list of keys to select values from the dictionary.</param>
-        [Obsolete("Use BsonDocument(IEnumerable<BsonElement> elements) instead.")]
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonDocument(IDictionary<string, object> dictionary, IEnumerable<string> keys)
-        {
-            Add(dictionary, keys);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocument class and adds new elements from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">A dictionary to initialize the document from.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonDocument(IDictionary dictionary)
-        {
-            AddRange(dictionary);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocument class and adds new elements from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">A dictionary to initialize the document from.</param>
-        /// <param name="keys">A list of keys to select values from the dictionary.</param>
-        [Obsolete("Use BsonDocument(IEnumerable<BsonElement> elements) instead.")]
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonDocument(IDictionary dictionary, IEnumerable keys)
-        {
-            Add(dictionary, keys);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocument class and adds new elements from a list of elements.
-        /// </summary>
-        /// <param name="elements">A list of elements to add to the document.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonDocument(IEnumerable<BsonElement> elements)
-        {
-            AddRange(elements);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocument class and adds one or more elements.
-        /// </summary>
-        /// <param name="elements">One or more elements to add to the document.</param>
-        [Obsolete("Use BsonDocument(IEnumerable<BsonElement> elements) instead.")]
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonDocument(params BsonElement[] elements)
-        {
-            Add(elements);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the BsonDocument class and creates and adds a new element.
-        /// </summary>
-        /// <param name="name">The name of the element to add to the document.</param>
-        /// <param name="value">The value of the element to add to the document.</param>
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public BsonDocument(string name, BsonValue value)
-        {
-            Add(name, value);
-        }
-
-        // public operators
-        /// <summary>
-        /// Compares two BsonDocument values.
-        /// </summary>
-        /// <param name="lhs">The first BsonDocument.</param>
-        /// <param name="rhs">The other BsonDocument.</param>
-        /// <returns>True if the two BsonDocument values are not equal according to ==.</returns>
-        public static bool operator !=(BsonDocument lhs, BsonDocument rhs)
-        {
-            return !(lhs == rhs);
-        }
-
-        /// <summary>
-        /// Compares two BsonDocument values.
-        /// </summary>
-        /// <param name="lhs">The first BsonDocument.</param>
-        /// <param name="rhs">The other BsonDocument.</param>
-        /// <returns>True if the two BsonDocument values are equal according to ==.</returns>
-        public static bool operator ==(BsonDocument lhs, BsonDocument rhs)
-        {
-            return object.Equals(lhs, rhs); // handles lhs == null correctly
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets or sets whether to allow duplicate names (allowing duplicate names is not recommended).
-        /// </summary>
-        public bool AllowDuplicateNames
-        {
-            get { return _allowDuplicateNames; }
-            set { _allowDuplicateNames = value; }
-        }
-
-        /// <summary>
-        /// Gets the BsonType of this BsonValue.
-        /// </summary>
-        public override BsonType BsonType
-        {
-            get { return BsonType.Document; }
-        }
-
-        // ElementCount could be greater than the number of Names if allowDuplicateNames is true
-        /// <summary>
-        /// Gets the number of elements.
-        /// </summary>
-        public virtual int ElementCount
-        {
-            get { return _elements.Count; }
-        }
-
-        /// <summary>
-        /// Gets the elements.
-        /// </summary>
-        public virtual IEnumerable<BsonElement> Elements
-        {
-            get { return _elements; }
-        }
-
-        /// <summary>
-        /// Gets the element names.
-        /// </summary>
-        public virtual IEnumerable<string> Names
-        {
-            get { return _elements.Select(e => e.Name); }
-        }
-
-        /// <summary>
-        /// Gets the raw values (see BsonValue.RawValue).
-        /// </summary>
-        [Obsolete("Use Values instead.")]
-        public virtual IEnumerable<object> RawValues
-        {
-            get { return _elements.Select(e => e.Value.RawValue); }
-        }
-
-        /// <summary>
-        /// Gets the values.
-        /// </summary>
-        public virtual IEnumerable<BsonValue> Values
-        {
-            get { return _elements.Select(e => e.Value); }
-        }
-
-        // public indexers
-        // note: the return type of the indexers is BsonValue and NOT BsonElement so that we can write code like:
-        //     BsonDocument car;
-        //     car["color"] = "red"; // changes value of existing element or adds new element
-        //         note: we are using implicit conversion from string to BsonValue
-        // to convert the returned BsonValue to a .NET type you have two approaches (explicit cast or As method):
-        //     string color = (string) car["color"]; // throws exception if value is not a string (returns null if not found)
-        //     string color = car["color"].AsString; // throws exception if value is not a string (results in a NullReferenceException if not found)
-        //     string color = car["color", "none"].AsString; // throws exception if value is not a string (default to "none" if not found)
-        // the second approach offers a more fluent interface (with fewer parenthesis!)
-        //     string name = car["brand"].AsBsonSymbol.Name;
-        //     string name = ((BsonSymbol) car["brand"]).Name; // the extra parenthesis are required and harder to read
-        // there are also some conversion methods (and note that ToBoolean uses the JavaScript definition of truthiness)
-        //     bool ok = result["ok"].ToBoolean(); // works whether ok is false, true, 0, 0.0, 1, 1.0, "", "xyz", BsonNull.Value, etc...
-        //     bool ok = result["ok", false].ToBoolean(); // defaults to false if ok element is not found
-        //     int n = result["n"].ToInt32(); // works whether n is Int32, Int64, Double or String (if it can be parsed)
-        //     long n = result["n"].ToInt64(); // works whether n is Int32, Int64, Double or String (if it can be parsed)
-        //     double d = result["n"].ToDouble(); // works whether d is Int32, Int64, Double or String (if it can be parsed)
-        // to work in terms of BsonElements use Add, GetElement and SetElement
-        //     car.Add(new BsonElement("color", "red")); // might throw exception if allowDuplicateNames is false
-        //     car.SetElement(new BsonElement("color", "red")); // replaces existing element or adds new element
-        //     BsonElement colorElement = car.GetElement("color"); // returns null if element "color" is not found
-
-        /// <summary>
-        /// Gets or sets a value by position.
-        /// </summary>
-        /// <param name="index">The position.</param>
-        /// <returns>The value.</returns>
-        public override BsonValue this[int index]
-        {
-            get { return _elements[index].Value; }
-            set
-            {
-                if (value == null)
-                {
-                    throw new ArgumentNullException("value");
-                }
-                _elements[index] = new BsonElement(_elements[index].Name, value);
-            }
-        }
-
-        /// <summary>
-        /// Gets the value of an element or a default value if the element is not found.
-        /// </summary>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="defaultValue">The default value to return if the element is not found.</param>
-        /// <returns>Teh value of the element or a default value if the element is not found.</returns>
-        [Obsolete("Use GetValue(string name, BsonValue defaultValue) instead.")]
-        public virtual BsonValue this[string name, BsonValue defaultValue]
-        {
-            get { return GetValue(name, defaultValue); }
-        }
-
-        /// <summary>
-        /// Gets or sets a value by name.
-        /// </summary>
-        /// <param name="name">The name.</param>
-        /// <returns>The value.</returns>
-        public override BsonValue this[string name]
-        {
-            get
-            {
-                if (name == null)
-                {
-                    throw new ArgumentNullException("name");
-                }
-                var index = IndexOfName(name);
-                if (index != -1)
-                {
-                    return _elements[index].Value;
-                }
-                else
-                {
-                    string message = string.Format("Element '{0}' not found.", name);
-                    throw new KeyNotFoundException(message);
-                }
-            }
-            set
-            {
-                if (name == null)
-                {
-                    throw new ArgumentNullException("name");
-                }
-                if (value == null)
-                {
-                    throw new ArgumentNullException("value");
-                }
-                var index = IndexOfName(name);
-                if (index != -1)
-                {
-                    _elements[index] = new BsonElement(name, value);
-                }
-                else
-                {
-                    Add(new BsonElement(name, value));
-                }
-            }
-        }
-
-        // public static methods
-        /// <summary>
-        /// Creates a new BsonDocument by mapping an object to a BsonDocument.
-        /// </summary>
-        /// <param name="value">The object to be mapped to a BsonDocument.</param>
-        /// <returns>A BsonDocument.</returns>
-        public new static BsonDocument Create(object value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-
-            return (BsonDocument)BsonTypeMapper.MapToBsonValue(value, BsonType.Document);
-        }
-
-        /// <summary>
-        /// Parses a JSON string and returns a BsonDocument.
-        /// </summary>
-        /// <param name="json">The JSON string.</param>
-        /// <returns>A BsonDocument.</returns>
-        public static BsonDocument Parse(string json)
-        {
-            using (var jsonReader = new JsonReader(json))
-            {
-                var context = BsonDeserializationContext.CreateRoot(jsonReader);
-                var document = BsonDocumentSerializer.Instance.Deserialize(context);
-                if (!jsonReader.IsAtEndOfFile())
-                {
-                    throw new FormatException("String contains extra non-whitespace characters beyond the end of the document.");
-                }
-                return document;
-            }
-        }
-
-        /// <summary>
-        /// Tries to parse a JSON string and returns a value indicating whether it succeeded or failed.
-        /// </summary>
-        /// <param name="s">The JSON string.</param>
-        /// <param name="result">The result.</param>
-        /// <returns>Whether it succeeded or failed.</returns>
-        public static bool TryParse(string s, out BsonDocument result)
-        {
-            try
-            {
-                result = Parse(s);
-                return true;
-            }
-            catch
-            {
-                result = null;
-                return false;
-            }
-        }
-
-        // public methods
-        /// <summary>
-        /// Adds an element to the document.
-        /// </summary>
-        /// <param name="element">The element to add.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        public virtual BsonDocument Add(BsonElement element)
-        {
-            var isDuplicate = IndexOfName(element.Name) != -1;
-            if (isDuplicate && !_allowDuplicateNames)
-            {
-                var message = string.Format("Duplicate element name '{0}'.", element.Name);
-                throw new InvalidOperationException(message);
-            }
-            else
-            {
-                _elements.Add(element);
-                if (!isDuplicate)
-                {
-                    if (_indexes == null)
-                    {
-                        RebuildIndexes();
-                    }
-                    else
-                    {
-                        _indexes.Add(element.Name, _elements.Count - 1); // index of the newly added element
-                    }
-                }
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds elements to the document from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">The dictionary.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        [Obsolete("Use AddRange instead.")]
-        public virtual BsonDocument Add(Dictionary<string, object> dictionary)
-        {
-            return AddRange(dictionary);
-        }
-
-        /// <summary>
-        /// Adds elements to the document from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">The dictionary.</param>
-        /// <param name="keys">Which keys of the hash table to add.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        [Obsolete("Use AddRange(IEnumerable<BsonElement> elements) instead.")]
-        public virtual BsonDocument Add(Dictionary<string, object> dictionary, IEnumerable<string> keys)
-        {
-            return Add((IDictionary<string, object>)dictionary, keys);
-        }
-
-        /// <summary>
-        /// Adds elements to the document from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">The dictionary.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        [Obsolete("Use AddRange instead.")]
-        public virtual BsonDocument Add(IDictionary<string, object> dictionary)
-        {
-            return AddRange(dictionary);
-        }
-
-        /// <summary>
-        /// Adds elements to the document from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">The dictionary.</param>
-        /// <param name="keys">Which keys of the hash table to add.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        [Obsolete("Use AddRange(IEnumerable<BsonElement> elements) instead.")]
-        public virtual BsonDocument Add(IDictionary<string, object> dictionary, IEnumerable<string> keys)
-        {
-            if (dictionary == null)
-            {
-                throw new ArgumentNullException("dictionary");
-            }
-            if (keys == null)
-            {
-                throw new ArgumentNullException("keys");
-            }
-
-            foreach (var key in keys)
-            {
-                Add(key, BsonTypeMapper.MapToBsonValue(dictionary[key]));
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds elements to the document from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">The dictionary.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        [Obsolete("Use AddRange instead.")]
-        public virtual BsonDocument Add(IDictionary dictionary)
-        {
-            return AddRange(dictionary);
-        }
-
-        /// <summary>
-        /// Adds elements to the document from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">The dictionary.</param>
-        /// <param name="keys">Which keys of the hash table to add.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        [Obsolete("Use AddRange(IEnumerable<BsonElement> elements) instead.")]
-        public virtual BsonDocument Add(IDictionary dictionary, IEnumerable keys)
-        {
-            if (dictionary == null)
-            {
-                throw new ArgumentNullException("dictionary");
-            }
-            if (keys == null)
-            {
-                throw new ArgumentNullException("keys");
-            }
-
-            foreach (var key in keys)
-            {
-                if (key == null)
-                {
-                    throw new ArgumentException("keys", "A key passed to BsonDocument.Add is null.");
-                }
-                if (key.GetType() != typeof(string))
-                {
-                    throw new ArgumentOutOfRangeException("keys", "A key passed to BsonDocument.Add is not a string.");
-                }
-                Add((string)key, BsonTypeMapper.MapToBsonValue(dictionary[key]));
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds a list of elements to the document.
-        /// </summary>
-        /// <param name="elements">The list of elements.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        [Obsolete("Use AddRange instead.")]
-        public virtual BsonDocument Add(IEnumerable<BsonElement> elements)
-        {
-            return AddRange(elements);
-        }
-
-        /// <summary>
-        /// Adds a list of elements to the document.
-        /// </summary>
-        /// <param name="elements">The list of elements.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        [Obsolete("Use AddRange(IEnumerable<BsonElement> elements) instead.")]
-        public virtual BsonDocument Add(params BsonElement[] elements)
-        {
-            return AddRange((IEnumerable<BsonElement>)elements);
-        }
-
-        /// <summary>
-        /// Creates and adds an element to the document.
-        /// </summary>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="value">The value of the element.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        public virtual BsonDocument Add(string name, BsonValue value)
-        {
-            if (name == null)
-            {
-                throw new ArgumentNullException("name");
-            }
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-
-            Add(new BsonElement(name, value));
-
-            return this;
-        }
-
-        /// <summary>
-        /// Creates and adds an element to the document, but only if the condition is true.
-        /// </summary>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="value">The value of the element.</param>
-        /// <param name="condition">Whether to add the element to the document.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        public virtual BsonDocument Add(string name, BsonValue value, bool condition)
-        {
-            if (name == null)
-            {
-                throw new ArgumentNullException("name");
-            }
-
-            if (condition)
-            {
-                // don't check for null value unless condition is true
-                if (value == null)
-                {
-                    throw new ArgumentNullException("value");
-                }
-
-                Add(new BsonElement(name, value));
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Creates and adds an element to the document, but only if the condition is true.
-        /// If the condition is false the value factory is not called at all.
-        /// </summary>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="valueFactory">A delegate called to compute the value of the element if condition is true.</param>
-        /// <param name="condition">Whether to add the element to the document.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        public virtual BsonDocument Add(string name, Func<BsonValue> valueFactory, bool condition)
-        {
-            if (name == null)
-            {
-                throw new ArgumentNullException("name");
-            }
-            if (valueFactory == null)
-            {
-                throw new ArgumentNullException("valueFactory");
-            }
-
-            if (condition)
-            {
-                Add(new BsonElement(name, valueFactory()));
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds elements to the document from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">The dictionary.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        public virtual BsonDocument AddRange(Dictionary<string, object> dictionary)
-        {
-            return AddRange((IEnumerable<KeyValuePair<string, object>>)dictionary);
-        }
-
-        /// <summary>
-        /// Adds elements to the document from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">The dictionary.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        public virtual BsonDocument AddRange(IDictionary dictionary)
-        {
-            if (dictionary == null)
-            {
-                throw new ArgumentNullException("dictionary");
-            }
-
-            foreach (DictionaryEntry entry in dictionary)
-            {
-                if (entry.Key == null)
-                {
-                    throw new ArgumentException("A key passed to BsonDocument.AddRange is null.", "keys");
-                }
-                if (entry.Key.GetType() != typeof(string))
-                {
-                    throw new ArgumentOutOfRangeException("dictionary", "One or more keys in the dictionary passed to BsonDocument.AddRange is not a string.");
-                }
-                Add((string)entry.Key, BsonTypeMapper.MapToBsonValue(entry.Value));
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds a list of elements to the document.
-        /// </summary>
-        /// <param name="elements">The list of elements.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        public virtual BsonDocument AddRange(IEnumerable<BsonElement> elements)
-        {
-            if (elements == null)
-            {
-                throw new ArgumentNullException("elements");
-            }
-
-            foreach (var element in elements)
-            {
-                Add(element);
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Adds elements to the document from a dictionary of key/value pairs.
-        /// </summary>
-        /// <param name="dictionary">The dictionary.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        public virtual BsonDocument AddRange(IEnumerable<KeyValuePair<string, object>> dictionary)
-        {
-            if (dictionary == null)
-            {
-                throw new ArgumentNullException("dictionary");
-            }
-
-            foreach (var entry in dictionary)
-            {
-                Add(entry.Key, BsonTypeMapper.MapToBsonValue(entry.Value));
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Clears the document (removes all elements).
-        /// </summary>
-        public virtual void Clear()
-        {
-            _elements.Clear();
-            _indexes = null;
-        }
-
-        /// <summary>
-        /// Creates a shallow clone of the document (see also DeepClone).
-        /// </summary>
-        /// <returns>A shallow clone of the document.</returns>
-        public override BsonValue Clone()
-        {
-            BsonDocument clone = new BsonDocument();
-            foreach (BsonElement element in _elements)
-            {
-                clone.Add(element.Clone());
-            }
-            return clone;
-        }
-
-        /// <summary>
-        /// Compares this document to another document.
-        /// </summary>
-        /// <param name="rhs">The other document.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this document is less than, equal to, or greather than the other.</returns>
-        public virtual int CompareTo(BsonDocument rhs)
-        {
-            if (rhs == null) { return 1; }
-
-            // lhs and rhs might be subclasses of BsonDocument
-            using (var lhsEnumerator = Elements.GetEnumerator())
-            using (var rhsEnumerator = rhs.Elements.GetEnumerator())
-            {
-                while (true)
-                {
-                    var lhsHasNext = lhsEnumerator.MoveNext();
-                    var rhsHasNext = rhsEnumerator.MoveNext();
-                    if (!lhsHasNext && !rhsHasNext) { return 0; }
-                    if (!lhsHasNext) { return -1; }
-                    if (!rhsHasNext) { return 1; }
-
-                    var lhsElement = lhsEnumerator.Current;
-                    var rhsElement = rhsEnumerator.Current;
-                    var result = lhsElement.Name.CompareTo(rhsElement.Name);
-                    if (result != 0) { return result; }
-                    result = lhsElement.Value.CompareTo(rhsElement.Value);
-                    if (result != 0) { return result; }
-                }
-            }
-        }
-
-        /// <summary>
-        /// Compares the BsonDocument to another BsonValue.
-        /// </summary>
-        /// <param name="other">The other BsonValue.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonDocument is less than, equal to, or greather than the other BsonValue.</returns>
-        public override int CompareTo(BsonValue other)
-        {
-            if (other == null) { return 1; }
-            var otherDocument = other as BsonDocument;
-            if (otherDocument != null)
-            {
-                return CompareTo(otherDocument);
-            }
-            return CompareTypeTo(other);
-        }
-
-        /// <summary>
-        /// Tests whether the document contains an element with the specified name.
-        /// </summary>
-        /// <param name="name">The name of the element to look for.</param>
-        /// <returns>True if the document contains an element with the specified name.</returns>
-        public virtual bool Contains(string name)
-        {
-            return IndexOfName(name) != -1;
-        }
-
-        /// <summary>
-        /// Tests whether the document contains an element with the specified value.
-        /// </summary>
-        /// <param name="value">The value of the element to look for.</param>
-        /// <returns>True if the document contains an element with the specified value.</returns>
-        public virtual bool ContainsValue(BsonValue value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-            return _elements.Any(e => e.Value == value);
-        }
-
-        /// <summary>
-        /// Creates a deep clone of the document (see also Clone).
-        /// </summary>
-        /// <returns>A deep clone of the document.</returns>
-        public override BsonValue DeepClone()
-        {
-            BsonDocument clone = new BsonDocument();
-            foreach (BsonElement element in _elements)
-            {
-                clone.Add(element.DeepClone());
-            }
-            return clone;
-        }
-
-        /// <summary>
-        /// Compares this document to another document.
-        /// </summary>
-        /// <param name="obj">The other document.</param>
-        /// <returns>True if the two documents are equal.</returns>
-        public bool Equals(BsonDocument obj)
-        {
-            return Equals((object)obj); // handles obj == null correctly
-        }
-
-        /// <summary>
-        /// Compares this BsonDocument to another object.
-        /// </summary>
-        /// <param name="obj">The other object.</param>
-        /// <returns>True if the other object is a BsonDocument and equal to this one.</returns>
-        public override bool Equals(object obj)
-        {
-            if (object.ReferenceEquals(obj, null) || !(obj is BsonDocument)) { return false; }
-
-            // lhs and rhs might be subclasses of BsonDocument
-            var rhs = (BsonDocument)obj;
-            return Elements.SequenceEqual(rhs.Elements);
-        }
-
-        /// <summary>
-        /// Gets an element of this document.
-        /// </summary>
-        /// <param name="index">The zero based index of the element.</param>
-        /// <returns>The element.</returns>
-        public virtual BsonElement GetElement(int index)
-        {
-            return _elements[index];
-        }
-
-        /// <summary>
-        /// Gets an element of this document.
-        /// </summary>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>A BsonElement.</returns>
-        public virtual BsonElement GetElement(string name)
-        {
-            if (name == null)
-            {
-                throw new ArgumentNullException("name");
-            }
-            var index = IndexOfName(name);
-            if (index != -1)
-            {
-                return _elements[index];
-            }
-            else
-            {
-                string message = string.Format("Element '{0}' not found.", name);
-                throw new KeyNotFoundException(message);
-            }
-        }
-
-        /// <summary>
-        /// Gets an enumerator that can be used to enumerate the elements of this document.
-        /// </summary>
-        /// <returns>An enumerator.</returns>
-        public virtual IEnumerator<BsonElement> GetEnumerator()
-        {
-            return _elements.GetEnumerator();
-        }
-
-        /// <summary>
-        /// Gets the hash code.
-        /// </summary>
-        /// <returns>The hash code.</returns>
-        public override int GetHashCode()
-        {
-            return new Hasher()
-                .Hash(BsonType)
-                .HashElements(Elements)
-                .GetHashCode();
-        }
-
-        /// <summary>
-        /// Gets the value of an element.
-        /// </summary>
-        /// <param name="index">The zero based index of the element.</param>
-        /// <returns>The value of the element.</returns>
-        public virtual BsonValue GetValue(int index)
-        {
-            return this[index];
-        }
-
-        /// <summary>
-        /// Gets the value of an element.
-        /// </summary>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>The value of the element.</returns>
-        public virtual BsonValue GetValue(string name)
-        {
-            if (name == null)
-            {
-                throw new ArgumentNullException("name");
-            }
-            return this[name];
-        }
-
-        /// <summary>
-        /// Gets the value of an element or a default value if the element is not found.
-        /// </summary>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="defaultValue">The default value returned if the element is not found.</param>
-        /// <returns>The value of the element or the default value if the element is not found.</returns>
-        public virtual BsonValue GetValue(string name, BsonValue defaultValue)
-        {
-            if (name == null)
-            {
-                throw new ArgumentNullException("name");
-            }
-
-            var index = IndexOfName(name);
-            if (index != -1)
-            {
-                return _elements[index].Value;
-            }
-            else
-            {
-                return defaultValue;
-            }
-        }
-
-        /// <summary>
-        /// Gets the index of an element.
-        /// </summary>
-        /// <param name="name">The name of the element.</param>
-        /// <returns>The index of the element, or -1 if the element is not found.</returns>
-        public virtual int IndexOfName(string name)
-        {
-            if (_indexes == null)
-            {
-                var count = _elements.Count;
-                for (var index = 0; index < count; index++)
-                {
-                    if (_elements[index].Name == name)
-                    {
-                        return index;
-                    }
-                }
-
-                return -1;
-            }
-            else
-            {
-                int index;
-                if (_indexes.TryGetValue(name, out index))
-                {
-                    return index;
-                }
-                else
-                {
-                    return -1;
-                }
-            }
-        }
-
-        /// <summary>
-        /// Inserts a new element at a specified position.
-        /// </summary>
-        /// <param name="index">The position of the new element.</param>
-        /// <param name="element">The element.</param>
-        public virtual void InsertAt(int index, BsonElement element)
-        {
-            var isDuplicate = IndexOfName(element.Name) != -1;
-            if (isDuplicate && !_allowDuplicateNames)
-            {
-                var message = string.Format("Duplicate element name '{0}' not allowed.", element.Name);
-                throw new InvalidOperationException(message);
-            }
-            else
-            {
-                _elements.Insert(index, element);
-                RebuildIndexes();
-            }
-        }
-
-        /// <summary>
-        /// Merges another document into this one. Existing elements are not overwritten.
-        /// </summary>
-        /// <param name="document">The other document.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        public virtual BsonDocument Merge(BsonDocument document)
-        {
-            Merge(document, false); // don't overwriteExistingElements
-            return this;
-        }
-
-        /// <summary>
-        /// Merges another document into this one, specifying whether existing elements are overwritten.
-        /// </summary>
-        /// <param name="document">The other document.</param>
-        /// <param name="overwriteExistingElements">Whether to overwrite existing elements.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        public virtual BsonDocument Merge(BsonDocument document, bool overwriteExistingElements)
-        {
-            if (document == null)
-            {
-                throw new ArgumentNullException("document");
-            }
-
-            foreach (BsonElement element in document)
-            {
-                if (overwriteExistingElements || !Contains(element.Name))
-                {
-                    this[element.Name] = element.Value;
-                }
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Removes an element from this document (if duplicate element names are allowed
-        /// then all elements with this name will be removed).
-        /// </summary>
-        /// <param name="name">The name of the element to remove.</param>
-        public virtual void Remove(string name)
-        {
-            if (name == null)
-            {
-                throw new ArgumentNullException("name");
-            }
-
-            if (_allowDuplicateNames)
-            {
-                var count = _elements.Count;
-                var removedAny = false;
-                for (var i = count - 1; i >= 0; i--)
-                {
-                    if (_elements[i].Name == name)
-                    {
-                        _elements.RemoveAt(i);
-                        removedAny = true;
-                    }
-                }
-
-                if (removedAny)
-                {
-                    RebuildIndexes();
-                }
-            }
-            else
-            {
-                var index = IndexOfName(name);
-                if (index != -1)
-                {
-                    _elements.RemoveAt(index);
-                    RebuildIndexes();
-                }
-            }
-        }
-
-        /// <summary>
-        /// Removes an element from this document.
-        /// </summary>
-        /// <param name="index">The zero based index of the element to remove.</param>
-        public virtual void RemoveAt(int index)
-        {
-            _elements.RemoveAt(index);
-            RebuildIndexes();
-        }
-
-        /// <summary>
-        /// Removes an element from this document.
-        /// </summary>
-        /// <param name="element">The element to remove.</param>
-        public virtual void RemoveElement(BsonElement element)
-        {
-            if (_elements.Remove(element))
-            {
-                RebuildIndexes();
-            }
-        }
-
-        /// <summary>
-        /// Sets the value of an element.
-        /// </summary>
-        /// <param name="index">The zero based index of the element whose value is to be set.</param>
-        /// <param name="value">The new value.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        public virtual BsonDocument Set(int index, BsonValue value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-            this[index] = value;
-            return this;
-        }
-
-        /// <summary>
-        /// Sets the value of an element (an element will be added if no element with this name is found).
-        /// </summary>
-        /// <param name="name">The name of the element whose value is to be set.</param>
-        /// <param name="value">The new value.</param>
-        /// <returns>The document (so method calls can be chained).</returns>
-        public virtual BsonDocument Set(string name, BsonValue value)
-        {
-            if (name == null)
-            {
-                throw new ArgumentNullException("name");
-            }
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-            this[name] = value;
-            return this;
-        }
-
-        /// <summary>
-        /// Sets an element of the document (replacing the existing element at that position).
-        /// </summary>
-        /// <param name="index">The zero based index of the element to replace.</param>
-        /// <param name="element">The new element.</param>
-        /// <returns>The document.</returns>
-        public virtual BsonDocument SetElement(int index, BsonElement element)
-        {
-            var oldName = _elements[index].Name;
-            _elements[index] = element;
-
-            if (element.Name != oldName)
-            {
-                RebuildIndexes();
-            }
-
-            return this;
-        }
-
-        /// <summary>
-        /// Sets an element of the document (replaces any existing element with the same name or adds a new element if an element with the same name is not found).
-        /// </summary>
-        /// <param name="element">The new element.</param>
-        /// <returns>The document.</returns>
-        public virtual BsonDocument SetElement(BsonElement element)
-        {
-            var index = IndexOfName(element.Name);
-            if (index != -1)
-            {
-                _elements[index] = element;
-            }
-            else
-            {
-                Add(element);
-            }
-            return this;
-        }
-
-        /// <summary>
-        /// Converts the BsonDocument to a Dictionary&lt;string, object&gt;.
-        /// </summary>
-        /// <returns>A dictionary.</returns>
-        public Dictionary<string, object> ToDictionary()
-        {
-            var options = new BsonTypeMapperOptions
-            {
-                DuplicateNameHandling = DuplicateNameHandling.ThrowException,
-                MapBsonArrayTo = typeof(object[]), // TODO: should this be List<object>?
-                MapBsonDocumentTo = typeof(Dictionary<string, object>),
-                MapOldBinaryToByteArray = false
-            };
-            return (Dictionary<string, object>)BsonTypeMapper.MapToDotNetValue(this, options);
-        }
-
-        /// <summary>
-        /// Converts the BsonDocument to a Hashtable.
-        /// </summary>
-        /// <returns>A hashtable.</returns>
-        public Hashtable ToHashtable()
-        {
-            var options = new BsonTypeMapperOptions
-            {
-                DuplicateNameHandling = DuplicateNameHandling.ThrowException,
-                MapBsonArrayTo = typeof(object[]), // TODO: should this be ArrayList?
-                MapBsonDocumentTo = typeof(Hashtable),
-                MapOldBinaryToByteArray = false
-            };
-            return (Hashtable)BsonTypeMapper.MapToDotNetValue(this, options);
-        }
-
-        /// <summary>
-        /// Returns a string representation of the document.
-        /// </summary>
-        /// <returns>A string representation of the document.</returns>
-        public override string ToString()
-        {
-            return this.ToJson();
-        }
-
-        /// <summary>
-        /// Tries to get an element of this document.
-        /// </summary>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="value">The element.</param>
-        /// <returns>True if an element with that name was found.</returns>
-        public virtual bool TryGetElement(string name, out BsonElement value)
-        {
-            if (name == null)
-            {
-                throw new ArgumentNullException("name");
-            }
-            var index = IndexOfName(name);
-            if (index != -1)
-            {
-                value = _elements[index];
-                return true;
-            }
-            else
-            {
-                value = default(BsonElement);
-                return false;
-            }
-        }
-
-        /// <summary>
-        /// Tries to get the value of an element of this document.
-        /// </summary>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="value">The value of the element.</param>
-        /// <returns>True if an element with that name was found.</returns>
-        public virtual bool TryGetValue(string name, out BsonValue value)
-        {
-            if (name == null)
-            {
-                throw new ArgumentNullException("name");
-            }
-            var index = IndexOfName(name);
-            if (index != -1)
-            {
-                value = _elements[index].Value;
-                return true;
-            }
-            else
-            {
-                value = null;
-                return false;
-            }
-        }
-
-        // private methods
-        private void RebuildIndexes()
-        {
-            if (_elements.Count < __indexesThreshold)
-            {
-                _indexes = null;
-                return;
-            }
-
-            if (_indexes == null)
-            {
-                _indexes = new Dictionary<string, int>();
-            }
-            else
-            {
-                _indexes.Clear();
-            }
-
-            // process the elements in reverse order so that in case of duplicates the dictionary ends up pointing at the first one
-            var count = _elements.Count;
-            for (int index = count - 1; index >= 0; index--)
-            {
-                BsonElement element = _elements[index];
-                _indexes[element.Name] = index;
-            }
-        }
-
-        // explicit interface implementations
-        BsonDocument IConvertibleToBsonDocument.ToBsonDocument()
-        {
-            return this;
-        }
-
-        IEnumerator IEnumerable.GetEnumerator()
-        {
-            return GetEnumerator();
-        }
-    }
-}

+ 0 - 195
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonDocumentWrapper.cs

@@ -1,195 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using MongoDB.Bson.IO;
-using MongoDB.Bson.Serialization;
-using MongoDB.Bson.Serialization.Serializers;
-
-namespace MongoDB.Bson
-{
-    // this class is a wrapper for an object that we intend to serialize as a BsonDocument
-    // it is a subclass of BsonDocument so that it may be used where a BsonDocument is expected
-    // this class is mostly used by MongoCollection and MongoCursor when supporting generic query objects
-
-    // if all that ever happens with this wrapped object is that it gets serialized then the BsonDocument is never materialized
-
-    /// <summary>
-    /// Represents a BsonDocument wrapper.
-    /// </summary>
-    public class BsonDocumentWrapper : MaterializedOnDemandBsonDocument
-    {
-        // private fields
-        private readonly object _wrapped;
-        private readonly IBsonSerializer _serializer;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BsonDocumentWrapper"/> class.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        public BsonDocumentWrapper(object value)
-            : this(value, UndiscriminatedActualTypeSerializer<object>.Instance)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BsonDocumentWrapper"/> class.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <param name="serializer">The serializer.</param>
-        public BsonDocumentWrapper(object value, IBsonSerializer serializer)
-        {
-            if (serializer == null)
-            {
-                throw new ArgumentNullException("serializer");
-            }
-
-            _wrapped = value;
-            _serializer = serializer;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the serializer.
-        /// </summary>
-        /// <value>
-        /// The serializer.
-        /// </value>
-        public IBsonSerializer Serializer
-        {
-            get { return _serializer; }
-        }
-
-        /// <summary>
-        /// Gets the wrapped value.
-        /// </summary>
-        public object Wrapped
-        {
-            get { return _wrapped; }
-        }
-
-        // public static methods
-        /// <summary>
-        /// Creates a new instance of the BsonDocumentWrapper class.
-        /// </summary>
-        /// <typeparam name="TNominalType">The nominal type of the wrapped object.</typeparam>
-        /// <param name="value">The wrapped object.</param>
-        /// <returns>A BsonDocumentWrapper.</returns>
-        public static BsonDocumentWrapper Create<TNominalType>(TNominalType value)
-        {
-            return Create(typeof(TNominalType), value);
-        }
-
-        /// <summary>
-        /// Creates a new instance of the BsonDocumentWrapper class.
-        /// </summary>
-        /// <param name="nominalType">The nominal type of the wrapped object.</param>
-        /// <param name="value">The wrapped object.</param>
-        /// <returns>A BsonDocumentWrapper.</returns>
-        public static BsonDocumentWrapper Create(Type nominalType, object value)
-        {
-            var serializer = BsonSerializer.LookupSerializer(nominalType);
-            return new BsonDocumentWrapper(value, serializer);
-        }
-
-        /// <summary>
-        /// Creates a list of new instances of the BsonDocumentWrapper class.
-        /// </summary>
-        /// <typeparam name="TNominalType">The nominal type of the wrapped objects.</typeparam>
-        /// <param name="values">A list of wrapped objects.</param>
-        /// <returns>A list of BsonDocumentWrappers.</returns>
-        public static IEnumerable<BsonDocumentWrapper> CreateMultiple<TNominalType>(IEnumerable<TNominalType> values)
-        {
-            if (values == null)
-            {
-                throw new ArgumentNullException("values");
-            }
-
-            var serializer = BsonSerializer.LookupSerializer(typeof(TNominalType));
-            return values.Select(v => new BsonDocumentWrapper(v, serializer));
-        }
-
-        /// <summary>
-        /// Creates a list of new instances of the BsonDocumentWrapper class.
-        /// </summary>
-        /// <param name="nominalType">The nominal type of the wrapped object.</param>
-        /// <param name="values">A list of wrapped objects.</param>
-        /// <returns>A list of BsonDocumentWrappers.</returns>
-        public static IEnumerable<BsonDocumentWrapper> CreateMultiple(Type nominalType, IEnumerable values)
-        {
-            if (nominalType == null)
-            {
-                throw new ArgumentNullException("nominalType");
-            }
-            if (values == null)
-            {
-                throw new ArgumentNullException("values");
-            }
-
-            var serializer = BsonSerializer.LookupSerializer(nominalType);
-            return values.Cast<object>().Select(v => new BsonDocumentWrapper(v, serializer));
-        }
-
-        // public methods
-        /// <summary>
-        /// Creates a shallow clone of the document (see also DeepClone).
-        /// </summary>
-        /// <returns>
-        /// A shallow clone of the document.
-        /// </returns>
-        public override BsonValue Clone()
-        {
-            if (IsMaterialized)
-            {
-                return base.Clone();
-            }
-            else
-            {
-                return new BsonDocumentWrapper(
-                    _wrapped,
-                    _serializer);
-            }
-        }
-
-        // protected methods
-        /// <summary>
-        /// Materializes the BsonDocument.
-        /// </summary>
-        /// <returns>The materialized elements.</returns>
-        protected override IEnumerable<BsonElement> Materialize()
-        {
-            var bsonDocument = new BsonDocument();
-            var writerSettings = BsonDocumentWriterSettings.Defaults;
-            using (var bsonWriter = new BsonDocumentWriter(bsonDocument, writerSettings))
-            {
-                var context = BsonSerializationContext.CreateRoot(bsonWriter);
-                _serializer.Serialize(context, _wrapped);
-            }
-
-            return bsonDocument.Elements;
-        }
-
-        /// <summary>
-        /// Informs subclasses that the Materialize process completed so they can free any resources related to the unmaterialized state.
-        /// </summary>
-        protected override void MaterializeCompleted()
-        {
-        }
-    }
-}

+ 0 - 374
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonDouble.cs

@@ -1,374 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Globalization;
-using MongoDB.Bson.IO;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents a BSON double value.
-    /// </summary>
-    /// <seealso cref="MongoDB.Bson.BsonValue" />
-#if NET452
-    [Serializable]
-#endif
-    public class BsonDouble : BsonValue, IComparable<BsonDouble>, IEquatable<BsonDouble>
-    {
-         #region static
-        const int __minPrecreatedValue = -100;
-        const int __maxPrecreatedValue = 100;
-        private static readonly BsonDouble[] __precreatedInstances = new BsonDouble[__maxPrecreatedValue - __minPrecreatedValue + 1];
-
-        static BsonDouble()
-        {
-            for (var i = __minPrecreatedValue; i <= __maxPrecreatedValue; i++)
-            {
-                var precreatedInstance = new BsonDouble(i);
-                var index = i - __minPrecreatedValue;
-                __precreatedInstances[index] = precreatedInstance;
-            }
-        }
-        #endregion
-
-        // private fields
-        private readonly double _value;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonDouble class.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        public BsonDouble(double value)
-        {
-            _value = value;
-        }
-
-        // public properties
-        /// <inheritdoc />
-        public override BsonType BsonType
-        {
-            get { return BsonType.Double; }
-        }
-
-        /// <inheritdoc />
-        [Obsolete("Use Value instead.")]
-        public override object RawValue
-        {
-            get { return _value; }
-        }
-
-        /// <summary>
-        /// Gets the value of this BsonDouble.
-        /// </summary>
-        public double Value
-        {
-            get { return _value; }
-        }
-
-        // public operators
-        /// <summary>
-        /// Converts a double to a BsonDouble.
-        /// </summary>
-        /// <param name="value">A double.</param>
-        /// <returns>A BsonDouble.</returns>
-        public static implicit operator BsonDouble(double value)
-        {
-            var intValue = (int)value;
-            if (intValue == value && intValue >= __minPrecreatedValue && intValue <= __maxPrecreatedValue)
-            {
-                var index = intValue - __minPrecreatedValue;
-                return __precreatedInstances[index];
-            }
-            return new BsonDouble(value);
-        }
-
-        /// <summary>
-        /// Compares two BsonDouble values.
-        /// </summary>
-        /// <param name="lhs">The first BsonDouble.</param>
-        /// <param name="rhs">The other BsonDouble.</param>
-        /// <returns>True if the two BsonDouble values are not equal according to ==.</returns>
-        public static bool operator !=(BsonDouble lhs, BsonDouble rhs)
-        {
-            return !(lhs == rhs);
-        }
-
-        /// <summary>
-        /// Compares two BsonDouble values.
-        /// </summary>
-        /// <param name="lhs">The first BsonDouble.</param>
-        /// <param name="rhs">The other BsonDouble.</param>
-        /// <returns>True if the two BsonDouble values are equal according to ==.</returns>
-        public static bool operator ==(BsonDouble lhs, BsonDouble rhs)
-        {
-            if (object.ReferenceEquals(lhs, null)) { return object.ReferenceEquals(rhs, null); }
-            return lhs.OperatorEqualsImplementation(rhs);
-        }
-
-        // public static methods
-        /// <summary>
-        /// Creates a new instance of the BsonDouble class.
-        /// </summary>
-        /// <param name="value">An object to be mapped to a BsonDouble.</param>
-        /// <returns>A BsonDouble.</returns>
-        public new static BsonDouble Create(object value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-
-            return (BsonDouble)BsonTypeMapper.MapToBsonValue(value, BsonType.Double);
-        }
-
-        // public methods
-        /// <summary>
-        /// Compares this BsonDouble to another BsonDouble.
-        /// </summary>
-        /// <param name="other">The other BsonDouble.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonDouble is less than, equal to, or greather than the other.</returns>
-        public int CompareTo(BsonDouble other)
-        {
-            if (other == null) { return 1; }
-            return _value.CompareTo(other._value);
-        }
-
-        /// <inheritdoc />
-        public override int CompareTo(BsonValue other)
-        {
-            if (other == null) { return 1; }
-
-            var otherDouble = other as BsonDouble;
-            if (otherDouble != null)
-            {
-                return _value.CompareTo(otherDouble._value);
-            }
-
-            var otherInt32 = other as BsonInt32;
-            if (otherInt32 != null)
-            {
-                return _value.CompareTo((double)otherInt32.Value);
-            }
-
-            var otherInt64 = other as BsonInt64;
-            if (otherInt64 != null)
-            {
-                return _value.CompareTo((double)otherInt64.Value);
-            }
-
-            var otherDecimal128 = other as BsonDecimal128;
-            if (otherDecimal128 != null)
-            {
-                return ((Decimal128)_value).CompareTo(otherDecimal128.Value);
-            }
-
-            return CompareTypeTo(other);
-        }
-
-        /// <summary>
-        /// Compares this BsonDouble to another BsonDouble.
-        /// </summary>
-        /// <param name="rhs">The other BsonDouble.</param>
-        /// <returns>True if the two BsonDouble values are equal.</returns>
-        public bool Equals(BsonDouble rhs)
-        {
-            if (object.ReferenceEquals(rhs, null) || GetType() != rhs.GetType()) { return false; }
-            return _value.Equals(rhs._value); // use Equals instead of == so NaN is handled correctly
-        }
-
-        /// <inheritdoc />
-        public override bool Equals(object obj)
-        {
-            return Equals(obj as BsonDouble); // works even if obj is null or of a different type
-        }
-
-        /// <inheritdoc />
-        public override int GetHashCode()
-        {
-            // see Effective Java by Joshua Bloch
-            int hash = 17;
-            hash = 37 * hash + BsonType.GetHashCode();
-            hash = 37 * hash + _value.GetHashCode();
-            return hash;
-        }
-
-        /// <inheritdoc />
-        public override bool ToBoolean()
-        {
-            return !(double.IsNaN(_value) || _value == 0.0);
-        }
-
-        /// <inheritdoc />
-        public override decimal ToDecimal()
-        {
-            return (decimal)_value;
-        }
-
-        /// <inheritdoc />
-        public override Decimal128 ToDecimal128()
-        {
-            return (Decimal128)_value;
-        }
-
-        /// <inheritdoc />
-        public override double ToDouble()
-        {
-            return _value;
-        }
-
-        /// <inheritdoc />
-        public override int ToInt32()
-        {
-            return (int)_value;
-        }
-
-        /// <inheritdoc />
-        public override long ToInt64()
-        {
-            return (long)_value;
-        }
-
-        /// <inheritdoc />
-        public override string ToString()
-        {
-            return JsonConvert.ToString(_value);
-        }
-
-        // protected methods
-        /// <inheritdoc/>
-        protected override TypeCode IConvertibleGetTypeCodeImplementation()
-        {
-            return TypeCode.Double;
-        }
-
-        /// <inheritdoc/>
-        protected override bool IConvertibleToBooleanImplementation(IFormatProvider provider)
-        {
-            return Convert.ToBoolean(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override byte IConvertibleToByteImplementation(IFormatProvider provider)
-        {
-            return Convert.ToByte(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override decimal IConvertibleToDecimalImplementation(IFormatProvider provider)
-        {
-            return Convert.ToDecimal(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override double IConvertibleToDoubleImplementation(IFormatProvider provider)
-        {
-            return _value;
-        }
-
-        /// <inheritdoc/>
-        protected override short IConvertibleToInt16Implementation(IFormatProvider provider)
-        {
-            return Convert.ToInt16(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override int IConvertibleToInt32Implementation(IFormatProvider provider)
-        {
-            return Convert.ToInt32(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override long IConvertibleToInt64Implementation(IFormatProvider provider)
-        {
-            return Convert.ToInt64(_value, provider);
-        }
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override sbyte IConvertibleToSByteImplementation(IFormatProvider provider)
-        {
-            return Convert.ToSByte(_value, provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-        protected override float IConvertibleToSingleImplementation(IFormatProvider provider)
-        {
-            return Convert.ToSingle(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override string IConvertibleToStringImplementation(IFormatProvider provider)
-        {
-            return Convert.ToString(_value, provider);
-        }
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override ushort IConvertibleToUInt16Implementation(IFormatProvider provider)
-        {
-            return Convert.ToUInt16(_value, provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override uint IConvertibleToUInt32Implementation(IFormatProvider provider)
-        {
-            return Convert.ToUInt32(_value, provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override ulong IConvertibleToUInt64Implementation(IFormatProvider provider)
-        {
-            return Convert.ToUInt64(_value, provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-        protected override bool OperatorEqualsImplementation(BsonValue rhs)
-        {
-            var rhsDouble = rhs as BsonDouble;
-            if (rhsDouble != null)
-            {
-                return _value == rhsDouble._value; // use == instead of Equals so NaN is handled correctly
-            }
-
-            var rhsInt32 = rhs as BsonInt32;
-            if (rhsInt32 != null)
-            {
-                return _value == (double)rhsInt32.Value;
-            }
-
-            var rhsInt64 = rhs as BsonInt64;
-            if (rhsInt64 != null)
-            {
-                return _value == (double)rhsInt64.Value;
-            }
-
-            var rhsDecimal128 = rhs as BsonDecimal128;
-            if (rhsDecimal128 != null)
-            {
-                return _value == (double)rhsDecimal128.Value; // use == instead of Equals so NaN is handled correctly
-            }
-
-            return this.Equals(rhs);
-        }
-    }
-}

+ 0 - 178
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonElement.cs

@@ -1,178 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents a BSON element.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public struct BsonElement : IComparable<BsonElement>, IEquatable<BsonElement>
-    {
-        // private fields
-        private readonly string _name;
-        private readonly BsonValue _value;
-
-        // constructors
-        // NOTE: for every public BsonElement constructor there is a matching constructor, Add and Set method in BsonDocument
-
-        /// <summary>
-        /// Initializes a new instance of the BsonElement class.
-        /// </summary>
-        /// <param name="name">The name of the element.</param>
-        /// <param name="value">The value of the element.</param>
-        public BsonElement(string name, BsonValue value)
-        {
-            if (name == null)
-            {
-                throw new ArgumentNullException("name");
-            }
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-            ValidateElementName(name);
-            _name = name;
-            _value = value;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the name of the element.
-        /// </summary>
-        public string Name
-        {
-            get { return _name; }
-        }
-
-        /// <summary>
-        /// Gets or sets the value of the element.
-        /// </summary>
-        public BsonValue Value
-        {
-            get { return _value; }
-        }
-
-        // public operators
-        /// <summary>
-        /// Compares two BsonElements.
-        /// </summary>
-        /// <param name="lhs">The first BsonElement.</param>
-        /// <param name="rhs">The other BsonElement.</param>
-        /// <returns>True if the two BsonElements are equal (or both null).</returns>
-        public static bool operator ==(BsonElement lhs, BsonElement rhs)
-        {
-            return Equals(lhs, rhs);
-        }
-
-        /// <summary>
-        /// Compares two BsonElements.
-        /// </summary>
-        /// <param name="lhs">The first BsonElement.</param>
-        /// <param name="rhs">The other BsonElement.</param>
-        /// <returns>True if the two BsonElements are not equal (or one is null and the other is not).</returns>
-        public static bool operator !=(BsonElement lhs, BsonElement rhs)
-        {
-            return !(lhs == rhs);
-        }
-
-        // private static methods
-        private static void ValidateElementName(string name)
-        {
-            if (name.IndexOf('\0') >= 0)
-            {
-                throw new ArgumentException("Element name cannot contain null (0x00) characters");
-            }
-        }
-
-        // public methods
-        /// <summary>
-        /// Creates a shallow clone of the element (see also DeepClone).
-        /// </summary>
-        /// <returns>A shallow clone of the element.</returns>
-        public BsonElement Clone()
-        {
-            return new BsonElement(_name, _value);
-        }
-
-        /// <summary>
-        /// Creates a deep clone of the element (see also Clone).
-        /// </summary>
-        /// <returns>A deep clone of the element.</returns>
-        public BsonElement DeepClone()
-        {
-            return new BsonElement(_name, _value.DeepClone());
-        }
-
-        /// <summary>
-        /// Compares this BsonElement to another BsonElement.
-        /// </summary>
-        /// <param name="other">The other BsonElement.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonElement is less than, equal to, or greather than the other.</returns>
-        public int CompareTo(BsonElement other)
-        {
-            int r = _name.CompareTo(other._name);
-            if (r != 0) { return r; }
-            return _value.CompareTo(other._value);
-        }
-
-        /// <summary>
-        /// Compares this BsonElement to another BsonElement.
-        /// </summary>
-        /// <param name="rhs">The other BsonElement.</param>
-        /// <returns>True if the two BsonElement values are equal.</returns>
-        public bool Equals(BsonElement rhs)
-        {
-            return _name == rhs._name && _value == rhs._value;
-        }
-
-        /// <summary>
-        /// Compares this BsonElement to another object.
-        /// </summary>
-        /// <param name="obj">The other object.</param>
-        /// <returns>True if the other object is a BsonElement and equal to this one.</returns>
-        public override bool Equals(object obj)
-        {
-            if (obj == null || obj.GetType() != typeof(BsonElement)) { return false; }
-            return Equals((BsonElement)obj);
-        }
-
-        /// <summary>
-        /// Gets the hash code.
-        /// </summary>
-        /// <returns>The hash code.</returns>
-        public override int GetHashCode()
-        {
-            // see Effective Java by Joshua Bloch
-            int hash = 17;
-            hash = 37 * hash + _name.GetHashCode();
-            hash = 37 * hash + _value.GetHashCode();
-            return hash;
-        }
-
-        /// <summary>
-        /// Returns a string representation of the value.
-        /// </summary>
-        /// <returns>A string representation of the value.</returns>
-        public override string ToString()
-        {
-            return string.Format("{0}={1}", _name, _value);
-        }
-    }
-}

+ 0 - 457
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonInt32.cs

@@ -1,457 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using MongoDB.Bson.IO;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents a BSON int value.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonInt32 : BsonValue, IComparable<BsonInt32>, IEquatable<BsonInt32>
-    {
-        #region static
-        const int __minPrecreatedValue = -100;
-        const int __maxPrecreatedValue = 100;
-        private static readonly BsonInt32[] __precreatedInstances = new BsonInt32[__maxPrecreatedValue - __minPrecreatedValue + 1];
-
-        static BsonInt32()
-        {
-            for (var i = __minPrecreatedValue; i <= __maxPrecreatedValue; i++)
-            {
-                var precreatedInstance = new BsonInt32(i);
-                var index = i - __minPrecreatedValue;
-                __precreatedInstances[index] = precreatedInstance;
-            }
-        }
-        #endregion
-
-        // private fields
-        private readonly int _value;
-
-        // constructors
-        /// <summary>
-        /// Creates a new instance of the BsonInt32 class.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        public BsonInt32(int value)
-        {
-            _value = value;
-        }
-
-        // public static properties
-        /// <summary>
-        /// Gets an instance of BsonInt32 that represents -1.
-        /// </summary>
-        [Obsolete("Use (BsonInt32)(-1) instead.")]
-        public static BsonInt32 MinusOne
-        {
-            get { return (BsonInt32)(-1); }
-        }
-
-        /// <summary>
-        /// Gets an instance of BsonInt32 that represents -0.
-        /// </summary>
-        [Obsolete("Use (BsonInt32)0 instead.")]
-        public static BsonInt32 Zero
-        {
-            get { return (BsonInt32)0; }
-        }
-
-        /// <summary>
-        /// Gets an instance of BsonInt32 that represents 1.
-        /// </summary>
-        [Obsolete("Use (BsonInt32)1 instead.")]
-        public static BsonInt32 One
-        {
-            get { return (BsonInt32)1; }
-        }
-
-        /// <summary>
-        /// Gets an instance of BsonInt32 that represents 2.
-        /// </summary>
-        [Obsolete("Use (BsonInt32)2 instead.")]
-        public static BsonInt32 Two
-        {
-            get { return (BsonInt32)2; }
-        }
-
-        /// <summary>
-        /// Gets an instance of BsonInt32 that represents 3.
-        /// </summary>
-        [Obsolete("Use (BsonInt32)3 instead.")]
-        public static BsonInt32 Three
-        {
-            get { return (BsonInt32)3; }
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the BsonType of this BsonValue.
-        /// </summary>
-        public override BsonType BsonType
-        {
-            get { return BsonType.Int32; }
-        }
-
-        /// <summary>
-        /// Gets the BsonInt32 as an int.
-        /// </summary>
-        [Obsolete("Use Value instead.")]
-        public override object RawValue
-        {
-            get { return _value; }
-        }
-
-        /// <summary>
-        /// Gets the value of this BsonInt32.
-        /// </summary>
-        public int Value
-        {
-            get { return _value; }
-        }
-
-        // public operators
-        /// <summary>
-        /// Converts an int to a BsonInt32.
-        /// </summary>
-        /// <param name="value">An int.</param>
-        /// <returns>A BsonInt32.</returns>
-        public static implicit operator BsonInt32(int value)
-        {
-            if (value >= __minPrecreatedValue && value <= __maxPrecreatedValue)
-            {
-                var index = value - __minPrecreatedValue;
-                return __precreatedInstances[index];
-            }
-            return new BsonInt32(value);
-        }
-
-        /// <summary>
-        /// Compares two BsonInt32 values.
-        /// </summary>
-        /// <param name="lhs">The first BsonInt32.</param>
-        /// <param name="rhs">The other BsonInt32.</param>
-        /// <returns>True if the two BsonInt32 values are not equal according to ==.</returns>
-        public static bool operator !=(BsonInt32 lhs, BsonInt32 rhs)
-        {
-            return !(lhs == rhs);
-        }
-
-        /// <summary>
-        /// Compares two BsonInt32 values.
-        /// </summary>
-        /// <param name="lhs">The first BsonInt32.</param>
-        /// <param name="rhs">The other BsonInt32.</param>
-        /// <returns>True if the two BsonInt32 values are equal according to ==.</returns>
-        public static bool operator ==(BsonInt32 lhs, BsonInt32 rhs)
-        {
-            if (object.ReferenceEquals(lhs, null)) { return object.ReferenceEquals(rhs, null); }
-            return lhs.OperatorEqualsImplementation(rhs);
-        }
-
-        // public static methods
-        /// <summary>
-        /// Creates a new BsonInt32.
-        /// </summary>
-        /// <param name="value">An object to be mapped to a BsonInt32.</param>
-        /// <returns>A BsonInt32 or null.</returns>
-        public new static BsonInt32 Create(object value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-
-            return (BsonInt32)BsonTypeMapper.MapToBsonValue(value, BsonType.Int32);
-        }
-
-        // public methods
-        /// <summary>
-        /// Compares this BsonInt32 to another BsonInt32.
-        /// </summary>
-        /// <param name="other">The other BsonInt32.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonInt32 is less than, equal to, or greather than the other.</returns>
-        public int CompareTo(BsonInt32 other)
-        {
-            if (other == null) { return 1; }
-            return _value.CompareTo(other._value);
-        }
-
-        /// <summary>
-        /// Compares the BsonInt32 to another BsonValue.
-        /// </summary>
-        /// <param name="other">The other BsonValue.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonInt32 is less than, equal to, or greather than the other BsonValue.</returns>
-        public override int CompareTo(BsonValue other)
-        {
-            if (other == null) { return 1; }
-
-            var otherInt32 = other as BsonInt32;
-            if (otherInt32 != null)
-            {
-                return _value.CompareTo(otherInt32._value);
-            }
-
-            var otherInt64 = other as BsonInt64;
-            if (otherInt64 != null)
-            {
-                return ((long)_value).CompareTo(otherInt64.Value);
-            }
-
-            var otherDouble = other as BsonDouble;
-            if (otherDouble != null)
-            {
-                return ((double)_value).CompareTo(otherDouble.Value);
-            }
-
-            var otherDecimal128 = other as BsonDecimal128;
-            if (otherDecimal128 != null)
-            {
-                return ((Decimal128)_value).CompareTo(otherDecimal128.Value);
-            }
-
-            return CompareTypeTo(other);
-        }
-
-        /// <summary>
-        /// Compares this BsonInt32 to another BsonInt32.
-        /// </summary>
-        /// <param name="rhs">The other BsonInt32.</param>
-        /// <returns>True if the two BsonInt32 values are equal.</returns>
-        public bool Equals(BsonInt32 rhs)
-        {
-            if (object.ReferenceEquals(rhs, null) || GetType() != rhs.GetType()) { return false; }
-            return _value == rhs._value;
-        }
-
-        /// <summary>
-        /// Compares this BsonInt32 to another object.
-        /// </summary>
-        /// <param name="obj">The other object.</param>
-        /// <returns>True if the other object is a BsonInt32 and equal to this one.</returns>
-        public override bool Equals(object obj)
-        {
-            return Equals(obj as BsonInt32); // works even if obj is null or of a different type
-        }
-
-        /// <summary>
-        /// Gets the hash code.
-        /// </summary>
-        /// <returns>The hash code.</returns>
-        public override int GetHashCode()
-        {
-            // see Effective Java by Joshua Bloch
-            int hash = 17;
-            hash = 37 * hash + BsonType.GetHashCode();
-            hash = 37 * hash + _value.GetHashCode();
-            return hash;
-        }
-
-        /// <summary>
-        /// Converts this BsonValue to a Boolean (using the JavaScript definition of truthiness).
-        /// </summary>
-        /// <returns>A Boolean.</returns>
-        public override bool ToBoolean()
-        {
-            return _value != 0;
-        }
-
-        /// <inheritdoc/>
-        public override decimal ToDecimal()
-        {
-            return (decimal)_value;
-        }
-
-        /// <inheritdoc/>
-        public override Decimal128 ToDecimal128()
-        {
-            return (Decimal128)_value;
-        }
-
-        /// <summary>
-        /// Converts this BsonValue to a Double.
-        /// </summary>
-        /// <returns>A Double.</returns>
-        public override double ToDouble()
-        {
-            return (double)_value;
-        }
-
-        /// <summary>
-        /// Converts this BsonValue to an Int32.
-        /// </summary>
-        /// <returns>An Int32.</returns>
-        public override int ToInt32()
-        {
-            return _value;
-        }
-
-        /// <summary>
-        /// Converts this BsonValue to an Int64.
-        /// </summary>
-        /// <returns>An Int32.</returns>
-        public override long ToInt64()
-        {
-            return (long)_value;
-        }
-
-        /// <summary>
-        /// Returns a string representation of the value.
-        /// </summary>
-        /// <returns>A string representation of the value.</returns>
-        public override string ToString()
-        {
-            return JsonConvert.ToString(_value);
-        }
-
-        // protected methods
-        /// <inheritdoc/>
-        protected override TypeCode IConvertibleGetTypeCodeImplementation()
-        {
-            return TypeCode.Int32;
-        }
-
-        /// <inheritdoc/>
-        protected override bool IConvertibleToBooleanImplementation(IFormatProvider provider)
-        {
-            return Convert.ToBoolean(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override byte IConvertibleToByteImplementation(IFormatProvider provider)
-        {
-            return Convert.ToByte(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override char IConvertibleToCharImplementation(IFormatProvider provider)
-        {
-            return Convert.ToChar(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override decimal IConvertibleToDecimalImplementation(IFormatProvider provider)
-        {
-            return Convert.ToDecimal(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override double IConvertibleToDoubleImplementation(IFormatProvider provider)
-        {
-            return Convert.ToDouble(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override short IConvertibleToInt16Implementation(IFormatProvider provider)
-        {
-            return Convert.ToInt16(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override int IConvertibleToInt32Implementation(IFormatProvider provider)
-        {
-            return _value;
-        }
-
-        /// <inheritdoc/>
-        protected override long IConvertibleToInt64Implementation(IFormatProvider provider)
-        {
-            return Convert.ToInt64(_value, provider);
-        }
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override sbyte IConvertibleToSByteImplementation(IFormatProvider provider)
-        {
-            return Convert.ToSByte(_value, provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-        protected override float IConvertibleToSingleImplementation(IFormatProvider provider)
-        {
-            return Convert.ToSingle(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override string IConvertibleToStringImplementation(IFormatProvider provider)
-        {
-            return Convert.ToString(_value, provider);
-        }
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override ushort IConvertibleToUInt16Implementation(IFormatProvider provider)
-        {
-            return Convert.ToUInt16(_value, provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override uint IConvertibleToUInt32Implementation(IFormatProvider provider)
-        {
-            return Convert.ToUInt32(_value, provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override ulong IConvertibleToUInt64Implementation(IFormatProvider provider)
-        {
-            return Convert.ToUInt64(_value, provider);
-        }
-#pragma warning restore
-
-        /// <summary>
-        /// Compares this BsonInt32 against another BsonValue.
-        /// </summary>
-        /// <param name="rhs">The other BsonValue.</param>
-        /// <returns>True if this BsonInt32 and the other BsonValue are equal according to ==.</returns>
-        protected override bool OperatorEqualsImplementation(BsonValue rhs)
-        {
-            var rhsInt32 = rhs as BsonInt32;
-            if (rhsInt32 != null)
-            {
-                return _value == rhsInt32._value;
-            }
-
-            var rhsInt64 = rhs as BsonInt64;
-            if (rhsInt64 != null)
-            {
-                return (long)_value == rhsInt64.Value;
-            }
-
-            var rhsDouble = rhs as BsonDouble;
-            if (rhsDouble != null)
-            {
-                return (double)_value == rhsDouble.Value; // use == instead of Equals so NaN is handled correctly
-            }
-
-            var rhsDecimal128 = rhs as BsonDecimal128;
-            if (rhsDecimal128 != null)
-            {
-                return _value == (int)rhsDecimal128.Value; // use == instead of Equals so NaN is handled correctly
-            }
-
-            return this.Equals(rhs);
-        }
-    }
-}

+ 0 - 411
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonInt64.cs

@@ -1,411 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using MongoDB.Bson.IO;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents a BSON long value.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonInt64 : BsonValue, IComparable<BsonInt64>, IEquatable<BsonInt64>
-    {
-         #region static
-        const long __minPrecreatedValue = -100L;
-        const long __maxPrecreatedValue = 100L;
-        private static readonly BsonInt64[] __precreatedInstances = new BsonInt64[__maxPrecreatedValue - __minPrecreatedValue + 1];
-
-        static BsonInt64()
-        {
-            for (var i = __minPrecreatedValue; i <= __maxPrecreatedValue; i++)
-            {
-                var precreatedInstance = new BsonInt64(i);
-                var index = i - __minPrecreatedValue;
-                __precreatedInstances[index] = precreatedInstance;
-            }
-        }
-        #endregion
-
-       // private fields
-        private readonly long _value;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonInt64 class.
-        /// </summary>
-        /// <param name="value">The value.</param>
-        public BsonInt64(long value)
-        {
-            _value = value;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the BsonType of this BsonValue.
-        /// </summary>
-        public override BsonType BsonType
-        {
-            get { return BsonType.Int64; }
-        }
-
-        /// <summary>
-        /// Gets the BsonInt64 as a long.
-        /// </summary>
-        [Obsolete("Use Value instead.")]
-        public override object RawValue
-        {
-            get { return _value; }
-        }
-
-        /// <summary>
-        /// Gets the value of this BsonInt64.
-        /// </summary>
-        public long Value
-        {
-            get { return _value; }
-        }
-
-        // public operators
-        /// <summary>
-        /// Converts a long to a BsonInt64.
-        /// </summary>
-        /// <param name="value">A long.</param>
-        /// <returns>A BsonInt64.</returns>
-        public static implicit operator BsonInt64(long value)
-        {
-            if (value >= __minPrecreatedValue && value <= __maxPrecreatedValue)
-            {
-                var index = value - __minPrecreatedValue;
-                return __precreatedInstances[index];
-            }
-            return new BsonInt64(value);
-        }
-
-        /// <summary>
-        /// Compares two BsonInt64 values.
-        /// </summary>
-        /// <param name="lhs">The first BsonInt64.</param>
-        /// <param name="rhs">The other BsonInt64.</param>
-        /// <returns>True if the two BsonInt64 values are not equal according to ==.</returns>
-        public static bool operator !=(BsonInt64 lhs, BsonInt64 rhs)
-        {
-            return !(lhs == rhs);
-        }
-
-        /// <summary>
-        /// Compares two BsonInt64 values.
-        /// </summary>
-        /// <param name="lhs">The first BsonInt64.</param>
-        /// <param name="rhs">The other BsonInt64.</param>
-        /// <returns>True if the two BsonInt64 values are equal according to ==.</returns>
-        public static bool operator ==(BsonInt64 lhs, BsonInt64 rhs)
-        {
-            if (object.ReferenceEquals(lhs, null)) { return object.ReferenceEquals(rhs, null); }
-            return lhs.OperatorEqualsImplementation(rhs);
-        }
-
-        // public static methods
-        /// <summary>
-        /// Creates a new BsonInt64.
-        /// </summary>
-        /// <param name="value">An object to be mapped to a BsonInt64.</param>
-        /// <returns>A BsonInt64 or null.</returns>
-        public new static BsonInt64 Create(object value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-
-            return (BsonInt64)BsonTypeMapper.MapToBsonValue(value, BsonType.Int64);
-        }
-
-        // public methods
-        /// <summary>
-        /// Compares this BsonInt64 to another BsonInt64.
-        /// </summary>
-        /// <param name="other">The other BsonInt64.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonInt64 is less than, equal to, or greather than the other.</returns>
-        public int CompareTo(BsonInt64 other)
-        {
-            if (other == null) { return 1; }
-            return _value.CompareTo(other._value);
-        }
-
-        /// <summary>
-        /// Compares the BsonInt64 to another BsonValue.
-        /// </summary>
-        /// <param name="other">The other BsonValue.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonInt64 is less than, equal to, or greather than the other BsonValue.</returns>
-        public override int CompareTo(BsonValue other)
-        {
-            if (other == null) { return 1; }
-
-            var otherInt64 = other as BsonInt64;
-            if (otherInt64 != null)
-            {
-                return _value.CompareTo(otherInt64._value);
-            }
-
-            var otherInt32 = other as BsonInt32;
-            if (otherInt32 != null)
-            {
-                return _value.CompareTo((long)otherInt32.Value);
-            }
-
-            var otherDouble = other as BsonDouble;
-            if (otherDouble != null)
-            {
-                return ((double)_value).CompareTo(otherDouble.Value);
-            }
-
-            var otherDecimal128 = other as BsonDecimal128;
-            if (otherDecimal128 != null)
-            {
-                return new Decimal128(_value).CompareTo(otherDecimal128.Value);
-            }
-
-            return CompareTypeTo(other);
-        }
-
-        /// <summary>
-        /// Compares this BsonInt64 to another BsonInt64.
-        /// </summary>
-        /// <param name="rhs">The other BsonInt64.</param>
-        /// <returns>True if the two BsonInt64 values are equal.</returns>
-        public bool Equals(BsonInt64 rhs)
-        {
-            if (object.ReferenceEquals(rhs, null) || GetType() != rhs.GetType()) { return false; }
-            return _value == rhs._value;
-        }
-
-        /// <summary>
-        /// Compares this BsonInt64 to another object.
-        /// </summary>
-        /// <param name="obj">The other object.</param>
-        /// <returns>True if the other object is a BsonInt64 and equal to this one.</returns>
-        public override bool Equals(object obj)
-        {
-            return Equals(obj as BsonInt64); // works even if obj is null or of a different type
-        }
-
-        /// <summary>
-        /// Gets the hash code.
-        /// </summary>
-        /// <returns>The hash code.</returns>
-        public override int GetHashCode()
-        {
-            // see Effective Java by Joshua Bloch
-            int hash = 17;
-            hash = 37 * hash + BsonType.GetHashCode();
-            hash = 37 * hash + _value.GetHashCode();
-            return hash;
-        }
-
-        /// <summary>
-        /// Converts this BsonValue to a Boolean (using the JavaScript definition of truthiness).
-        /// </summary>
-        /// <returns>A Boolean.</returns>
-        public override bool ToBoolean()
-        {
-            return _value != 0;
-        }
-
-        /// <inheritdoc/>
-        public override decimal ToDecimal()
-        {
-            return (decimal)_value;
-        }
-
-        /// <inheritdoc/>
-        public override Decimal128 ToDecimal128()
-        {
-            return (Decimal128)_value;
-        }
-
-        /// <summary>
-        /// Converts this BsonValue to a Double.
-        /// </summary>
-        /// <returns>A Double.</returns>
-        public override double ToDouble()
-        {
-            return (double)_value;
-        }
-
-        /// <summary>
-        /// Converts this BsonValue to an Int32.
-        /// </summary>
-        /// <returns>An Int32.</returns>
-        public override int ToInt32()
-        {
-            return (int)_value;
-        }
-
-        /// <summary>
-        /// Converts this BsonValue to an Int64.
-        /// </summary>
-        /// <returns>An Int32.</returns>
-        public override long ToInt64()
-        {
-            return _value;
-        }
-
-        /// <summary>
-        /// Returns a string representation of the value.
-        /// </summary>
-        /// <returns>A string representation of the value.</returns>
-        public override string ToString()
-        {
-            return JsonConvert.ToString(_value);
-        }
-
-        // protected methods
-        /// <inheritdoc/>
-        protected override TypeCode IConvertibleGetTypeCodeImplementation()
-        {
-            return TypeCode.Int64;
-        }
-
-        /// <inheritdoc/>
-        protected override bool IConvertibleToBooleanImplementation(IFormatProvider provider)
-        {
-            return Convert.ToBoolean(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override byte IConvertibleToByteImplementation(IFormatProvider provider)
-        {
-            return Convert.ToByte(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override char IConvertibleToCharImplementation(IFormatProvider provider)
-        {
-            return Convert.ToChar(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override decimal IConvertibleToDecimalImplementation(IFormatProvider provider)
-        {
-            return Convert.ToDecimal(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override double IConvertibleToDoubleImplementation(IFormatProvider provider)
-        {
-            return Convert.ToDouble(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override short IConvertibleToInt16Implementation(IFormatProvider provider)
-        {
-            return Convert.ToInt16(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override int IConvertibleToInt32Implementation(IFormatProvider provider)
-        {
-            return Convert.ToInt32(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override long IConvertibleToInt64Implementation(IFormatProvider provider)
-        {
-            return _value;
-        }
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override sbyte IConvertibleToSByteImplementation(IFormatProvider provider)
-        {
-            return Convert.ToSByte(_value, provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-        protected override float IConvertibleToSingleImplementation(IFormatProvider provider)
-        {
-            return Convert.ToSingle(_value, provider);
-        }
-
-        /// <inheritdoc/>
-        protected override string IConvertibleToStringImplementation(IFormatProvider provider)
-        {
-            return Convert.ToString(_value, provider);
-        }
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override ushort IConvertibleToUInt16Implementation(IFormatProvider provider)
-        {
-            return Convert.ToUInt16(_value, provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override uint IConvertibleToUInt32Implementation(IFormatProvider provider)
-        {
-            return Convert.ToUInt32(_value, provider);
-        }
-#pragma warning restore
-
-        /// <inheritdoc/>
-#pragma warning disable 3002
-        protected override ulong IConvertibleToUInt64Implementation(IFormatProvider provider)
-        {
-            return Convert.ToUInt64(_value, provider);
-        }
-#pragma warning restore
-       
-        /// <summary>
-        /// Compares this BsonInt32 against another BsonValue.
-        /// </summary>
-        /// <param name="rhs">The other BsonValue.</param>
-        /// <returns>True if this BsonInt64 and the other BsonValue are equal according to ==.</returns>
-        protected override bool OperatorEqualsImplementation(BsonValue rhs)
-        {
-            var rhsInt64 = rhs as BsonInt64;
-            if (rhsInt64 != null)
-            {
-                return _value == rhsInt64._value;
-            }
-
-            var rhsInt32 = rhs as BsonInt32;
-            if (rhsInt32 != null)
-            {
-                return _value == (long)rhsInt32.Value;
-            }
-
-            var rhsDouble = rhs as BsonDouble;
-            if (rhsDouble != null)
-            {
-                return (double)_value == rhsDouble.Value; // use == instead of Equals so NaN is handled correctly
-            }
-
-            var rhsDecimal128 = rhs as BsonDecimal128;
-            if (rhsDecimal128 != null)
-            {
-                return _value == (long)rhsDecimal128.Value;
-            }
-
-            return this.Equals(rhs);
-        }
-    }
-}

+ 0 - 182
Server/ThirdParty/MongoDBDriver/MongoDB.Bson/ObjectModel/BsonJavaScript.cs

@@ -1,182 +0,0 @@
-/* Copyright 2010-present MongoDB Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-
-namespace MongoDB.Bson
-{
-    /// <summary>
-    /// Represents a BSON JavaScript value.
-    /// </summary>
-#if NET452
-    [Serializable]
-#endif
-    public class BsonJavaScript : BsonValue, IComparable<BsonJavaScript>, IEquatable<BsonJavaScript>
-    {
-        // private fields
-        private readonly string _code;
-
-        // constructors
-        /// <summary>
-        /// Initializes a new instance of the BsonJavaScript class.
-        /// </summary>
-        /// <param name="code">The JavaScript code.</param>
-        public BsonJavaScript(string code)
-        {
-            if (code == null)
-            {
-                throw new ArgumentNullException("code");
-            }
-            _code = code;
-        }
-
-        // public properties
-        /// <summary>
-        /// Gets the BsonType of this BsonValue.
-        /// </summary>
-        public override BsonType BsonType
-        {
-            get { return BsonType.JavaScript; }
-        }
-
-        /// <summary>
-        /// Gets the JavaScript code.
-        /// </summary>
-        public string Code
-        {
-            get { return _code; }
-        }
-
-        /// <summary>
-        /// Compares two BsonJavaScript values.
-        /// </summary>
-        /// <param name="lhs">The first BsonJavaScript.</param>
-        /// <param name="rhs">The other BsonJavaScript.</param>
-        /// <returns>True if the two BsonJavaScript values are not equal according to ==.</returns>
-        public static bool operator !=(BsonJavaScript lhs, BsonJavaScript rhs)
-        {
-            return !(lhs == rhs);
-        }
-
-        /// <summary>
-        /// Compares two BsonJavaScript values.
-        /// </summary>
-        /// <param name="lhs">The first BsonJavaScript.</param>
-        /// <param name="rhs">The other BsonJavaScript.</param>
-        /// <returns>True if the two BsonJavaScript values are equal according to ==.</returns>
-        public static bool operator ==(BsonJavaScript lhs, BsonJavaScript rhs)
-        {
-            if (object.ReferenceEquals(lhs, null)) { return object.ReferenceEquals(rhs, null); }
-            return lhs.Equals(rhs);
-        }
-
-        // public operators
-        /// <summary>
-        /// Converts a string to a BsonJavaScript.
-        /// </summary>
-        /// <param name="code">A string.</param>
-        /// <returns>A BsonJavaScript.</returns>
-        public static implicit operator BsonJavaScript(string code)
-        {
-            return new BsonJavaScript(code);
-        }
-
-        /// <summary>
-        /// Creates a new BsonJavaScript.
-        /// </summary>
-        /// <param name="value">An object to be mapped to a BsonJavaScript.</param>
-        /// <returns>A BsonJavaScript or null.</returns>
-        public new static BsonJavaScript Create(object value)
-        {
-            if (value == null)
-            {
-                throw new ArgumentNullException("value");
-            }
-
-            return (BsonJavaScript)BsonTypeMapper.MapToBsonValue(value, BsonType.JavaScript);
-        }
-
-        // public methods
-        /// <summary>
-        /// Compares this BsonJavaScript to another BsonJavaScript.
-        /// </summary>
-        /// <param name="other">The other BsonJavaScript.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonJavaScript is less than, equal to, or greather than the other.</returns>
-        public int CompareTo(BsonJavaScript other)
-        {
-            if (other == null) { return 1; }
-            return _code.CompareTo(other._code);
-        }
-
-        /// <summary>
-        /// Compares the BsonJavaScript to another BsonValue.
-        /// </summary>
-        /// <param name="other">The other BsonValue.</param>
-        /// <returns>A 32-bit signed integer that indicates whether this BsonJavaScript is less than, equal to, or greather than the other BsonValue.</returns>
-        public override int CompareTo(BsonValue other)
-        {
-            if (other == null) { return 1; }
-            var otherJavaScript = other as BsonJavaScript;
-            if (otherJavaScript != null)
-            {
-                return CompareTo(otherJavaScript);
-            }
-            return CompareTypeTo(other);
-        }
-
-        /// <summary>
-        /// Compares this BsonJavaScript to another BsonJavaScript.
-        /// </summary>
-        /// <param name="rhs">The other BsonJavaScript.</param>
-        /// <returns>True if the two BsonJavaScript values are equal.</returns>
-        public bool Equals(BsonJavaScript rhs)
-        {
-            if (object.ReferenceEquals(rhs, null) || GetType() != rhs.GetType()) { return false; }
-            return _code == rhs._code;
-        }
-
-        /// <summary>
-        /// Compares this BsonJavaScript to another object.
-        /// </summary>
-        /// <param name="obj">The other object.</param>
-        /// <returns>True if the other object is a BsonJavaScript and equal to this one.</returns>
-        public override bool Equals(object obj)
-        {
-            return Equals(obj as BsonJavaScript); // works even if obj is null or of a different type
-        }
-
-        /// <summary>
-        /// Gets the hash code.
-        /// </summary>
-        /// <returns>The hash code.</returns>
-        public override int GetHashCode()
-        {
-            // see Effective Java by Joshua Bloch
-            int hash = 17;
-            hash = 37 * hash + BsonType.GetHashCode();
-            hash = 37 * hash + _code.GetHashCode();
-            return hash;
-        }
-
-        /// <summary>
-        /// Returns a string representation of the value.
-        /// </summary>
-        /// <returns>A string representation of the value.</returns>
-        public override string ToString()
-        {
-            return string.Format("new BsonJavaScript(\"{0}\")", _code);
-        }
-    }
-}

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません