Explorar o código

server端迁移到netcore,运行成功

tanghai %!s(int64=8) %!d(string=hai) anos
pai
achega
ff64aa7e01
Modificáronse 100 ficheiros con 13760 adicións e 2517 borrados
  1. 1 0
      .gitignore
  2. 109 61
      Client-Server.sln
  3. 1 0
      Client-Server.sln.DotSettings.user
  4. 2 2
      Config/StartConfig/Benchmark.txt
  5. 1 0
      Config/StartConfig/LocalAllServer.txt
  6. 2 2
      Run.sh
  7. 0 35
      Server/App/Properties/AssemblyInfo.cs
  8. 8 0
      Server/App/Properties/launchSettings.json
  9. 20 66
      Server/App/Server.App.csproj
  10. 0 10
      Server/App/Server.App.csproj.user
  11. 0 33
      Server/Base/Logger/Log4NetAdapter.cs
  12. 0 35
      Server/Base/Properties/AssemblyInfo.cs
  13. 59 163
      Server/Base/Server.Base.csproj
  14. 0 6
      Server/Base/Server.Base.csproj.user
  15. 0 35
      Server/Hotfix/Properties/AssemblyInfo.cs
  16. 17 85
      Server/Hotfix/Server.Hotfix.csproj
  17. BIN=BIN
      Server/Lib/CommandLine.dll
  18. BIN=BIN
      Server/Lib/ICSharpCode.SharpZipLib.dll
  19. BIN=BIN
      Server/Lib/MongoDB.Bson.dll
  20. BIN=BIN
      Server/Lib/MongoDB.Driver.Core.dll
  21. BIN=BIN
      Server/Lib/MongoDB.Driver.dll
  22. BIN=BIN
      Server/Lib/NLog.dll
  23. BIN=BIN
      Server/Lib/Newtonsoft.Json.dll
  24. BIN=BIN
      Server/Lib/log4net.dll
  25. BIN=BIN
      Server/Lib/protobuf-net.dll
  26. 4 4
      Server/Model/Component/AppManagerComponent.cs
  27. 1 1
      Server/Model/Component/BenchmarkComponent.cs
  28. 4 5
      Server/Model/Component/OptionComponent.cs
  29. 3 11
      Server/Model/Other/Options.cs
  30. 0 35
      Server/Model/Properties/AssemblyInfo.cs
  31. 56 228
      Server/Model/Server.Model.csproj
  32. 0 6
      Server/Model/Server.Model.csproj.user
  33. 0 97
      Server/Server.sln
  34. 0 1585
      Server/Server.sln.DotSettings
  35. 0 3
      Server/Server.sln.DotSettings.user
  36. 11 9
      Server/ThirdParty/ENet/ENet.vcxproj
  37. BIN=BIN
      Server/ThirdParty/MongodbDriver/DotNetCoreDriver/.vs/DotNetCoreDriver/v15/sqlite3/storage.ide
  38. BIN=BIN
      Server/ThirdParty/MongodbDriver/DotNetCoreDriver/.vs/DotNetCoreDriver/v15/sqlite3/storage.ide-journal
  39. 37 0
      Server/ThirdParty/MongodbDriver/DotNetCoreDriver/DotNetCoreDriver.sln
  40. 23 0
      Server/ThirdParty/MongodbDriver/DotNetCoreDriver/MongoDB.Bson/MongoDB.Bson.csproj
  41. 22 0
      Server/ThirdParty/MongodbDriver/DotNetCoreDriver/MongoDB.Driver.Core/MongoDB.Driver.Core.csproj
  42. 23 0
      Server/ThirdParty/MongodbDriver/DotNetCoreDriver/MongoDB.Driver/MongoDB.Driver.csproj
  43. 61 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/BsonConstants.cs
  44. 105 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/BsonDefaults.cs
  45. 246 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/BsonExtensionMethods.cs
  46. 265 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/BsonUtils.cs
  47. 81 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/Exceptions/BsonException.cs
  48. 71 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/Exceptions/BsonInternalException.cs
  49. 71 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/Exceptions/BsonSerializationException.cs
  50. 62 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/Exceptions/DuplicateBsonMemberMapAttributeException.cs
  51. 71 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/Exceptions/TruncationException.cs
  52. 125 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/ArrayElementNameAccelerator.cs
  53. 825 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonBinaryReader.cs
  54. 52 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonBinaryReaderBookmark.cs
  55. 87 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonBinaryReaderContext.cs
  56. 148 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonBinaryReaderSettings.cs
  57. 763 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonBinaryWriter.cs
  58. 59 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonBinaryWriterContext.cs
  59. 134 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonBinaryWriterSettings.cs
  60. 259 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonChunkPool.cs
  61. 562 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonDocumentReader.cs
  62. 52 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonDocumentReaderBookmark.cs
  63. 128 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonDocumentReaderContext.cs
  64. 90 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonDocumentReaderSettings.cs
  65. 548 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonDocumentWriter.cs
  66. 91 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonDocumentWriterContext.cs
  67. 91 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonDocumentWriterSettings.cs
  68. 440 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonReader.cs
  69. 67 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonReaderBookmark.cs
  70. 123 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonReaderSettings.cs
  71. 60 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonReaderState.cs
  72. 140 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonStream.cs
  73. 567 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonStreamAdapter.cs
  74. 315 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonStreamExtensions.cs
  75. 354 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonTrie.cs
  76. 453 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonWriter.cs
  77. 137 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonWriterSettings.cs
  78. 48 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonWriterState.cs
  79. 294 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/ByteArrayBuffer.cs
  80. 111 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/ByteArrayChunk.cs
  81. 75 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/ByteBufferFactory.cs
  82. 235 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/ByteBufferSlice.cs
  83. 727 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/ByteBufferStream.cs
  84. 76 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/CStringUtf8Encoding.cs
  85. 44 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/ContextType.cs
  86. 39 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/IBsonChunk.cs
  87. 33 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/IBsonChunkSource.cs
  88. 235 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/IBsonReader.cs
  89. 361 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/IBsonReaderExtensions.cs
  90. 213 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/IBsonWriter.cs
  91. 293 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/IBsonWriterExtensions.cs
  92. 122 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/IByteBuffer.cs
  93. 38 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/IElementNameValidator.cs
  94. 43 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/INameDecoder.cs
  95. 174 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/InputBufferChunkSource.cs
  96. 204 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/JsonBuffer.cs
  97. 299 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/JsonConvert.cs
  98. 47 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/JsonOutputMode.cs
  99. 1866 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/JsonReader.cs
  100. 76 0
      Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/JsonReaderBookmark.cs

+ 1 - 0
.gitignore

@@ -41,3 +41,4 @@ _ReSharper.CSharp/
 /Release
 .idea/
 /Unity/Logs
+/netcoreapp2.0

+ 109 - 61
Client-Server.sln

@@ -13,14 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Client", "Client", "{914C77
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Server", "Server", "{46008B91-6EC0-448B-8D1A-D8C6D2EEBEF4}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.App", "Server\App\Server.App.csproj", "{3F8DC04C-9E05-403F-B6A5-36293EB99937}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Base", "Server\Base\Server.Base.csproj", "{E5078EC6-2B0E-4711-BE8B-D99F69638316}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Hotfix", "Server\Hotfix\Server.Hotfix.csproj", "{3878BD71-2F75-4EDF-882F-BC708154B1B0}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Model", "Server\Model\Server.Model.csproj", "{820D3488-76B9-4EE8-872A-BE06C2350B20}"
-EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ThirdParty", "ThirdParty", "{78640FA0-9F11-412D-A639-61F03D02407A}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ENet", "Server\ThirdParty\ENet\ENet.vcxproj", "{C9992B7C-313E-4C9F-A954-640D01EDFB58}"
@@ -29,6 +21,22 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Editor", "Unity\Unity
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Editor.Plugins", "Unity\Unity.Editor.Plugins.csproj", "{81A6E58E-BFF2-F1C8-1C4E-6316985F642C}"
 EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server.App", "Server\App\Server.App.csproj", "{69F1AA11-D05A-4843-B0DD-56B5E2E212A8}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server.Base", "Server\Base\Server.Base.csproj", "{909B117C-7709-4F48-A142-40CE26FF99C9}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server.Model", "Server\Model\Server.Model.csproj", "{EE38E3D2-3D2A-4061-BD50-AE8568126C7D}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server.Hotfix", "Server\Hotfix\Server.Hotfix.csproj", "{C305ED5B-8425-47A1-BEE1-85830CADC27A}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MongodbDriver", "MongodbDriver", "{4940CE10-6652-4AC6-9D30-CF200A217643}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoDB.Bson", "Server\ThirdParty\MongodbDriver\DotNetCoreDriver\MongoDB.Bson\MongoDB.Bson.csproj", "{BC611535-3BDA-45C5-8765-9E242E312B8F}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoDB.Driver", "Server\ThirdParty\MongodbDriver\DotNetCoreDriver\MongoDB.Driver\MongoDB.Driver.csproj", "{6D19C1F8-085C-422E-8DAF-2E49024DB08C}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoDB.Driver.Core", "Server\ThirdParty\MongodbDriver\DotNetCoreDriver\MongoDB.Driver.Core\MongoDB.Driver.Core.csproj", "{831276B2-B7EB-4FD0-93E5-4D2109C78950}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -75,60 +83,12 @@ Global
 		{40533600-4E69-4F7D-A924-E1A3B4127255}.Release|x64.Build.0 = Release|Any CPU
 		{40533600-4E69-4F7D-A924-E1A3B4127255}.Release|x86.ActiveCfg = Release|Any CPU
 		{40533600-4E69-4F7D-A924-E1A3B4127255}.Release|x86.Build.0 = Release|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|x64.Build.0 = Debug|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|x86.Build.0 = Debug|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|Any CPU.Build.0 = Release|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x64.ActiveCfg = Release|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x64.Build.0 = Release|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x86.ActiveCfg = Release|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x86.Build.0 = Release|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|x64.Build.0 = Debug|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|x86.Build.0 = Debug|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|Any CPU.Build.0 = Release|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|x64.ActiveCfg = Release|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|x64.Build.0 = Release|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|x86.ActiveCfg = Release|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|x86.Build.0 = Release|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|x64.Build.0 = Debug|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|x86.Build.0 = Debug|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|Any CPU.Build.0 = Release|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|x64.ActiveCfg = Release|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|x64.Build.0 = Release|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|x86.ActiveCfg = Release|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|x86.Build.0 = Release|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|x64.Build.0 = Debug|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|x86.Build.0 = Debug|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|Any CPU.Build.0 = Release|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|x64.ActiveCfg = Release|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|x64.Build.0 = Release|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|x86.ActiveCfg = Release|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|x86.Build.0 = Release|Any CPU
 		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|Any CPU.ActiveCfg = Debug|Win32
 		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x64.ActiveCfg = Debug|x64
 		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x64.Build.0 = Debug|x64
 		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x86.ActiveCfg = Debug|Win32
 		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x86.Build.0 = Debug|Win32
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|Any CPU.ActiveCfg = Release|Win32
+		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|Any CPU.ActiveCfg = Release|x64
 		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x64.ActiveCfg = Release|x64
 		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x64.Build.0 = Release|x64
 		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x86.ActiveCfg = Release|Win32
@@ -157,6 +117,90 @@ Global
 		{81A6E58E-BFF2-F1C8-1C4E-6316985F642C}.Release|x64.Build.0 = Release|Any CPU
 		{81A6E58E-BFF2-F1C8-1C4E-6316985F642C}.Release|x86.ActiveCfg = Release|Any CPU
 		{81A6E58E-BFF2-F1C8-1C4E-6316985F642C}.Release|x86.Build.0 = Release|Any CPU
+		{69F1AA11-D05A-4843-B0DD-56B5E2E212A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{69F1AA11-D05A-4843-B0DD-56B5E2E212A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{69F1AA11-D05A-4843-B0DD-56B5E2E212A8}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{69F1AA11-D05A-4843-B0DD-56B5E2E212A8}.Debug|x64.Build.0 = Debug|Any CPU
+		{69F1AA11-D05A-4843-B0DD-56B5E2E212A8}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{69F1AA11-D05A-4843-B0DD-56B5E2E212A8}.Debug|x86.Build.0 = Debug|Any CPU
+		{69F1AA11-D05A-4843-B0DD-56B5E2E212A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{69F1AA11-D05A-4843-B0DD-56B5E2E212A8}.Release|Any CPU.Build.0 = Release|Any CPU
+		{69F1AA11-D05A-4843-B0DD-56B5E2E212A8}.Release|x64.ActiveCfg = Release|Any CPU
+		{69F1AA11-D05A-4843-B0DD-56B5E2E212A8}.Release|x64.Build.0 = Release|Any CPU
+		{69F1AA11-D05A-4843-B0DD-56B5E2E212A8}.Release|x86.ActiveCfg = Release|Any CPU
+		{69F1AA11-D05A-4843-B0DD-56B5E2E212A8}.Release|x86.Build.0 = Release|Any CPU
+		{909B117C-7709-4F48-A142-40CE26FF99C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{909B117C-7709-4F48-A142-40CE26FF99C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{909B117C-7709-4F48-A142-40CE26FF99C9}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{909B117C-7709-4F48-A142-40CE26FF99C9}.Debug|x64.Build.0 = Debug|Any CPU
+		{909B117C-7709-4F48-A142-40CE26FF99C9}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{909B117C-7709-4F48-A142-40CE26FF99C9}.Debug|x86.Build.0 = Debug|Any CPU
+		{909B117C-7709-4F48-A142-40CE26FF99C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{909B117C-7709-4F48-A142-40CE26FF99C9}.Release|Any CPU.Build.0 = Release|Any CPU
+		{909B117C-7709-4F48-A142-40CE26FF99C9}.Release|x64.ActiveCfg = Release|Any CPU
+		{909B117C-7709-4F48-A142-40CE26FF99C9}.Release|x64.Build.0 = Release|Any CPU
+		{909B117C-7709-4F48-A142-40CE26FF99C9}.Release|x86.ActiveCfg = Release|Any CPU
+		{909B117C-7709-4F48-A142-40CE26FF99C9}.Release|x86.Build.0 = Release|Any CPU
+		{EE38E3D2-3D2A-4061-BD50-AE8568126C7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{EE38E3D2-3D2A-4061-BD50-AE8568126C7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{EE38E3D2-3D2A-4061-BD50-AE8568126C7D}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{EE38E3D2-3D2A-4061-BD50-AE8568126C7D}.Debug|x64.Build.0 = Debug|Any CPU
+		{EE38E3D2-3D2A-4061-BD50-AE8568126C7D}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{EE38E3D2-3D2A-4061-BD50-AE8568126C7D}.Debug|x86.Build.0 = Debug|Any CPU
+		{EE38E3D2-3D2A-4061-BD50-AE8568126C7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{EE38E3D2-3D2A-4061-BD50-AE8568126C7D}.Release|Any CPU.Build.0 = Release|Any CPU
+		{EE38E3D2-3D2A-4061-BD50-AE8568126C7D}.Release|x64.ActiveCfg = Release|Any CPU
+		{EE38E3D2-3D2A-4061-BD50-AE8568126C7D}.Release|x64.Build.0 = Release|Any CPU
+		{EE38E3D2-3D2A-4061-BD50-AE8568126C7D}.Release|x86.ActiveCfg = Release|Any CPU
+		{EE38E3D2-3D2A-4061-BD50-AE8568126C7D}.Release|x86.Build.0 = Release|Any CPU
+		{C305ED5B-8425-47A1-BEE1-85830CADC27A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{C305ED5B-8425-47A1-BEE1-85830CADC27A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{C305ED5B-8425-47A1-BEE1-85830CADC27A}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{C305ED5B-8425-47A1-BEE1-85830CADC27A}.Debug|x64.Build.0 = Debug|Any CPU
+		{C305ED5B-8425-47A1-BEE1-85830CADC27A}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{C305ED5B-8425-47A1-BEE1-85830CADC27A}.Debug|x86.Build.0 = Debug|Any CPU
+		{C305ED5B-8425-47A1-BEE1-85830CADC27A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{C305ED5B-8425-47A1-BEE1-85830CADC27A}.Release|Any CPU.Build.0 = Release|Any CPU
+		{C305ED5B-8425-47A1-BEE1-85830CADC27A}.Release|x64.ActiveCfg = Release|Any CPU
+		{C305ED5B-8425-47A1-BEE1-85830CADC27A}.Release|x64.Build.0 = Release|Any CPU
+		{C305ED5B-8425-47A1-BEE1-85830CADC27A}.Release|x86.ActiveCfg = Release|Any CPU
+		{C305ED5B-8425-47A1-BEE1-85830CADC27A}.Release|x86.Build.0 = Release|Any CPU
+		{BC611535-3BDA-45C5-8765-9E242E312B8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{BC611535-3BDA-45C5-8765-9E242E312B8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{BC611535-3BDA-45C5-8765-9E242E312B8F}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{BC611535-3BDA-45C5-8765-9E242E312B8F}.Debug|x64.Build.0 = Debug|Any CPU
+		{BC611535-3BDA-45C5-8765-9E242E312B8F}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{BC611535-3BDA-45C5-8765-9E242E312B8F}.Debug|x86.Build.0 = Debug|Any CPU
+		{BC611535-3BDA-45C5-8765-9E242E312B8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{BC611535-3BDA-45C5-8765-9E242E312B8F}.Release|Any CPU.Build.0 = Release|Any CPU
+		{BC611535-3BDA-45C5-8765-9E242E312B8F}.Release|x64.ActiveCfg = Release|Any CPU
+		{BC611535-3BDA-45C5-8765-9E242E312B8F}.Release|x64.Build.0 = Release|Any CPU
+		{BC611535-3BDA-45C5-8765-9E242E312B8F}.Release|x86.ActiveCfg = Release|Any CPU
+		{BC611535-3BDA-45C5-8765-9E242E312B8F}.Release|x86.Build.0 = Release|Any CPU
+		{6D19C1F8-085C-422E-8DAF-2E49024DB08C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{6D19C1F8-085C-422E-8DAF-2E49024DB08C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{6D19C1F8-085C-422E-8DAF-2E49024DB08C}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{6D19C1F8-085C-422E-8DAF-2E49024DB08C}.Debug|x64.Build.0 = Debug|Any CPU
+		{6D19C1F8-085C-422E-8DAF-2E49024DB08C}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{6D19C1F8-085C-422E-8DAF-2E49024DB08C}.Debug|x86.Build.0 = Debug|Any CPU
+		{6D19C1F8-085C-422E-8DAF-2E49024DB08C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{6D19C1F8-085C-422E-8DAF-2E49024DB08C}.Release|Any CPU.Build.0 = Release|Any CPU
+		{6D19C1F8-085C-422E-8DAF-2E49024DB08C}.Release|x64.ActiveCfg = Release|Any CPU
+		{6D19C1F8-085C-422E-8DAF-2E49024DB08C}.Release|x64.Build.0 = Release|Any CPU
+		{6D19C1F8-085C-422E-8DAF-2E49024DB08C}.Release|x86.ActiveCfg = Release|Any CPU
+		{6D19C1F8-085C-422E-8DAF-2E49024DB08C}.Release|x86.Build.0 = Release|Any CPU
+		{831276B2-B7EB-4FD0-93E5-4D2109C78950}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{831276B2-B7EB-4FD0-93E5-4D2109C78950}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{831276B2-B7EB-4FD0-93E5-4D2109C78950}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{831276B2-B7EB-4FD0-93E5-4D2109C78950}.Debug|x64.Build.0 = Debug|Any CPU
+		{831276B2-B7EB-4FD0-93E5-4D2109C78950}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{831276B2-B7EB-4FD0-93E5-4D2109C78950}.Debug|x86.Build.0 = Debug|Any CPU
+		{831276B2-B7EB-4FD0-93E5-4D2109C78950}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{831276B2-B7EB-4FD0-93E5-4D2109C78950}.Release|Any CPU.Build.0 = Release|Any CPU
+		{831276B2-B7EB-4FD0-93E5-4D2109C78950}.Release|x64.ActiveCfg = Release|Any CPU
+		{831276B2-B7EB-4FD0-93E5-4D2109C78950}.Release|x64.Build.0 = Release|Any CPU
+		{831276B2-B7EB-4FD0-93E5-4D2109C78950}.Release|x86.ActiveCfg = Release|Any CPU
+		{831276B2-B7EB-4FD0-93E5-4D2109C78950}.Release|x86.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -165,14 +209,18 @@ Global
 		{D1FDB199-0FB7-099D-3771-C6A942E4E326} = {914C77C9-212A-4DD0-8D9A-074620E77FAA}
 		{CF118143-7E37-744F-BE45-3F55345FEC40} = {914C77C9-212A-4DD0-8D9A-074620E77FAA}
 		{40533600-4E69-4F7D-A924-E1A3B4127255} = {914C77C9-212A-4DD0-8D9A-074620E77FAA}
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937} = {46008B91-6EC0-448B-8D1A-D8C6D2EEBEF4}
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316} = {46008B91-6EC0-448B-8D1A-D8C6D2EEBEF4}
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0} = {46008B91-6EC0-448B-8D1A-D8C6D2EEBEF4}
-		{820D3488-76B9-4EE8-872A-BE06C2350B20} = {46008B91-6EC0-448B-8D1A-D8C6D2EEBEF4}
 		{78640FA0-9F11-412D-A639-61F03D02407A} = {46008B91-6EC0-448B-8D1A-D8C6D2EEBEF4}
 		{C9992B7C-313E-4C9F-A954-640D01EDFB58} = {78640FA0-9F11-412D-A639-61F03D02407A}
 		{C17F48D3-964E-E97C-3D2E-966F7A6C6D93} = {914C77C9-212A-4DD0-8D9A-074620E77FAA}
 		{81A6E58E-BFF2-F1C8-1C4E-6316985F642C} = {914C77C9-212A-4DD0-8D9A-074620E77FAA}
+		{69F1AA11-D05A-4843-B0DD-56B5E2E212A8} = {46008B91-6EC0-448B-8D1A-D8C6D2EEBEF4}
+		{909B117C-7709-4F48-A142-40CE26FF99C9} = {46008B91-6EC0-448B-8D1A-D8C6D2EEBEF4}
+		{EE38E3D2-3D2A-4061-BD50-AE8568126C7D} = {46008B91-6EC0-448B-8D1A-D8C6D2EEBEF4}
+		{C305ED5B-8425-47A1-BEE1-85830CADC27A} = {46008B91-6EC0-448B-8D1A-D8C6D2EEBEF4}
+		{4940CE10-6652-4AC6-9D30-CF200A217643} = {78640FA0-9F11-412D-A639-61F03D02407A}
+		{BC611535-3BDA-45C5-8765-9E242E312B8F} = {4940CE10-6652-4AC6-9D30-CF200A217643}
+		{6D19C1F8-085C-422E-8DAF-2E49024DB08C} = {4940CE10-6652-4AC6-9D30-CF200A217643}
+		{831276B2-B7EB-4FD0-93E5-4D2109C78950} = {4940CE10-6652-4AC6-9D30-CF200A217643}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {EABC01E3-3EB5-47EF-B46E-AAD8BB3585F1}

+ 1 - 0
Client-Server.sln.DotSettings.user

@@ -1,6 +1,7 @@
 <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
 	<s:String x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/IntelliSenseCompletingCharacters/CSharpCompletingCharacters/NonCompletingCharacters/@EntryValue"></s:String>
 	<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AC2G_005FEnterMapHandler_002Ecs_002Fl_003AServer_003FHotfix_003FHandler_003FC2G_005FEnterMapHandler_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
+	<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AInnerOpcode_002Ecs_002Fl_003AServer_003FModel_003FEntity_003FMessage_003FInnerOpcode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
 	<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlayer_002Ecs_002Fl_003AUnity_003FAssets_003FScripts_003FEntity_003FPlayer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
 	<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlayerComponent_002Ecs_002Fl_003AUnity_003FAssets_003FScripts_003FComponent_003FPlayerComponent_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
 	<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlayerFactory_002Ecs_002Fl_003AUnity_003FAssets_003FScripts_003FFactory_003FPlayerFactory_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>

+ 2 - 2
Config/StartConfig/Benchmark.txt

@@ -1,2 +1,2 @@
-{ "_t" : "StartConfig", "_id" : NumberLong("96832337674244"), "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("96832337674245"), "Host" : "127.0.0.1", "Port" : 20000 }, { "_t" : "OuterConfig", "_id" : NumberLong("96832337674246"), "Host" : "127.0.0.1", "Port" : 10000 }], "AppId" : 1, "AppType" : "AllServer", "ServerIP" : "*" }
-{ "_t" : "StartConfig", "_id" : NumberLong("96866810789911"), "components" : [{ "_t" : "ClientConfig", "_id" : NumberLong("96866810789912"), "Host" : "127.0.0.1", "Port" : 10000 }], "AppId" : 2, "AppType" : "Benchmark", "ServerIP" : "*" }
+{ "_t" : "StartConfig", "_id" : NumberLong("98808811814943"), "components" : [{ "_t" : "OuterConfig", "Host" : "127.0.0.1", "Port" : 10000, "Host2" : null }, { "_t" : "InnerConfig", "Host" : "127.0.0.1", "Port" : 20000 }], "AppId" : 1, "AppType" : "Manager", "ServerIP" : "*" }
+{ "_t" : "StartConfig", "_id" : NumberLong("98808818892845"), "components" : [{ "_t" : "ClientConfig", "Host" : "127.0.0.1", "Port" : 10000 }], "AppId" : 2, "AppType" : "Benchmark", "ServerIP" : "*" }

+ 1 - 0
Config/StartConfig/LocalAllServer.txt

@@ -1 +1,2 @@
 { "_t" : "StartConfig", "_id" : NumberLong("98547768819754"), "components" : [{ "_t" : "OuterConfig", "Host" : "127.0.0.1", "Port" : 10002, "Host2" : null }, { "_t" : "InnerConfig", "Host" : "127.0.0.1", "Port" : 20000 }, { "_t" : "HttpConfig", "Url" : "", "AppId" : 0, "AppKey" : "", "ManagerSystemUrl" : "" }, { "_t" : "DBConfig", "ConnectionString" : null, "DBName" : null }], "AppId" : 1, "AppType" : "AllServer", "ServerIP" : "*" }
+{ "_t" : "StartConfig", "_id" : NumberLong("98809428705310"), "components" : [{ "_t" : "ClientConfig", "Host" : "127.0.0.1", "Port" : 10002 }], "AppId" : 2, "AppType" : "Benchmark", "ServerIP" : "*" }

+ 2 - 2
Run.sh

@@ -8,9 +8,9 @@ then
 fi
 
 xbuild ./Server/Server.sln
-cd Bin
+cd netcoreapp2.0
 cmake ..
 make
 
 ps -ef | grep App.exe | awk '{print $2}' | xargs kill -9
-mono --debug App.exe --appId=1 --appType=Manager --config=../$1
+dotnet App.dll --appId=1 --appType=Manager --config=../$1

+ 0 - 35
Server/App/Properties/AssemblyInfo.cs

@@ -1,35 +0,0 @@
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-// 有关程序集的一般信息由以下
-// 控制。更改这些特性值可修改
-// 与程序集关联的信息。
-[assembly: AssemblyTitle("Server.App")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("Server.App")]
-[assembly: AssemblyCopyright("Copyright ©  2016")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-//将 ComVisible 设置为 false 将使此程序集中的类型
-//对 COM 组件不可见。  如果需要从 COM 访问此程序集中的类型,
-//请将此类型的 ComVisible 特性设置为 true。
-[assembly: ComVisible(false)]
-
-// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
-[assembly: Guid("3f8dc04c-9e05-403f-b6a5-36293eb99937")]
-
-// 程序集的版本信息由下列四个值组成: 
-//
-//      主版本
-//      次版本
-//      生成号
-//      修订号
-//
-//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
-// 方法是按如下所示使用“*”: :
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]

+ 8 - 0
Server/App/Properties/launchSettings.json

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "Server.App": {
+      "commandName": "Project",
+      "commandLineArgs": "--appId=1 --appType=AllServer --config=../Config/StartConfig/LocalAllServer.txt"
+    }
+  }
+}

+ 20 - 66
Server/App/Server.App.csproj

@@ -1,80 +1,34 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+<Project Sdk="Microsoft.NET.Sdk">
+
   <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProjectGuid>{3F8DC04C-9E05-403F-B6A5-36293EB99937}</ProjectGuid>
     <OutputType>Exe</OutputType>
-    <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>App</RootNamespace>
+    <TargetFramework>netcoreapp2.0</TargetFramework>
     <AssemblyName>App</AssemblyName>
-    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
-    <FileAlignment>512</FileAlignment>
-    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+    <RootNamespace>App</RootNamespace>
   </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <PlatformTarget>AnyCPU</PlatformTarget>
-    <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
-    <OutputPath>..\..\Bin\</OutputPath>
-    <DefineConstants>TRACE;DEBUG;SERVER</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+    <DefineConstants>TRACE;DEBUG;NETCOREAPP2_0;SERVER</DefineConstants>
+    <OutputPath>..\..\</OutputPath>
   </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-    <PlatformTarget>AnyCPU</PlatformTarget>
-    <DebugType>pdbonly</DebugType>
-    <Optimize>true</Optimize>
-    <OutputPath>..\..\Bin\</OutputPath>
-    <DefineConstants>TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
+    <DefineConstants>TRACE;RELEASE;NETCOREAPP2_0;SERVER</DefineConstants>
+    <OutputPath>..\..\</OutputPath>
   </PropertyGroup>
+
   <ItemGroup>
-    <Reference Include="MongoDB.Bson, Version=2.3.0.157, Culture=neutral, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\Lib\MongoDB.Bson.dll</HintPath>
-    </Reference>
-    <Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\Lib\NLog.dll</HintPath>
-    </Reference>
-    <Reference Include="System" />
-    <Reference Include="System.Core" />
+    <PackageReference Include="NLog" Version="5.0.0-beta11" />
   </ItemGroup>
+
   <ItemGroup>
-    <Compile Include="Program.cs" />
-    <Compile Include="Properties\AssemblyInfo.cs" />
+    <ProjectReference Include="..\Model\Server.Model.csproj" />
   </ItemGroup>
+
   <ItemGroup>
-    <None Include="App.config" />
-    <None Include="NLog.xsd">
-      <SubType>Designer</SubType>
-    </None>
-  </ItemGroup>
-  <ItemGroup>
-    <None Include="NLog.config">
+    <None Update="NLog.config">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
   </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\Base\Server.Base.csproj">
-      <Project>{e5078ec6-2b0e-4711-be8b-d99f69638316}</Project>
-      <Name>Server.Base</Name>
-    </ProjectReference>
-    <ProjectReference Include="..\Model\Server.Model.csproj">
-      <Project>{820d3488-76b9-4ee8-872a-be06c2350b20}</Project>
-      <Name>Server.Model</Name>
-    </ProjectReference>
-  </ItemGroup>
-  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
-       Other similar extension points exist, see Microsoft.Common.targets.
-  <Target Name="BeforeBuild">
-  </Target>
-  <Target Name="AfterBuild">
-  </Target>
-  -->
-</Project>
+
+</Project>

+ 0 - 10
Server/App/Server.App.csproj.user

@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
-    <StartArguments>--appId=1 --appType=AllServer --config=../Config/StartConfig/LocalAllServer.txt</StartArguments>
-    <StartAction>Project</StartAction>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
-    <StartArguments>--appId=1 --appType=AllServer --config=../Config/StartConfig/LocalAllServer.txt</StartArguments>
-  </PropertyGroup>
-</Project>

+ 0 - 33
Server/Base/Logger/Log4NetAdapter.cs

@@ -1,33 +0,0 @@
-using log4net;
-
-namespace Model
-{
-	public class Log4NetAdapter : ALogDecorater, ILog
-	{
-		private readonly log4net.ILog logger = LogManager.GetLogger("Logger");
-
-		public Log4NetAdapter(ALogDecorater decorater = null): base(decorater)
-		{
-		}
-
-		public void Warning(string message)
-		{
-			this.logger.Warn(this.Decorate(message));
-		}
-
-		public void Info(string message)
-		{
-			this.logger.Info(this.Decorate(message));
-		}
-
-		public void Debug(string message)
-		{
-			this.logger.Debug(this.Decorate(message));
-		}
-
-		public void Error(string message)
-		{
-			this.logger.Error(this.Decorate(message));
-		}
-	}
-}

+ 0 - 35
Server/Base/Properties/AssemblyInfo.cs

@@ -1,35 +0,0 @@
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-// 有关程序集的一般信息由以下
-// 控制。更改这些特性值可修改
-// 与程序集关联的信息。
-[assembly: AssemblyTitle("Base")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("Base")]
-[assembly: AssemblyCopyright("Copyright ©  2016")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-//将 ComVisible 设置为 false 将使此程序集中的类型
-//对 COM 组件不可见。  如果需要从 COM 访问此程序集中的类型,
-//请将此类型的 ComVisible 特性设置为 true。
-[assembly: ComVisible(false)]
-
-// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
-[assembly: Guid("e5078ec6-2b0e-4711-be8b-d99f69638316")]
-
-// 程序集的版本信息由下列四个值组成: 
-//
-//      主版本
-//      次版本
-//      生成号
-//      修订号
-//
-//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
-// 方法是按如下所示使用“*”: :
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]

+ 59 - 163
Server/Base/Server.Base.csproj

@@ -1,172 +1,68 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+<Project Sdk="Microsoft.NET.Sdk">
+
   <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProjectGuid>{E5078EC6-2B0E-4711-BE8B-D99F69638316}</ProjectGuid>
-    <OutputType>Library</OutputType>
-    <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>Base</RootNamespace>
+    <TargetFramework>netcoreapp2.0</TargetFramework>
     <AssemblyName>Base</AssemblyName>
-    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
-    <FileAlignment>512</FileAlignment>
+    <RootNamespace>Model</RootNamespace>
   </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
-    <OutputPath>..\..\Bin\</OutputPath>
-    <DefineConstants>TRACE;DEBUG;SERVER</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+    <DefineConstants>TRACE;DEBUG;NETCOREAPP2_0;SERVER</DefineConstants>
+    <OutputPath>..\..\</OutputPath>
   </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-    <DebugType>pdbonly</DebugType>
-    <Optimize>true</Optimize>
-    <OutputPath>..\..\Bin\</OutputPath>
-    <DefineConstants>TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
+    <DefineConstants>TRACE;RELEASE;NETCOREAPP2_0;SERVER</DefineConstants>
+    <OutputPath>..\..\</OutputPath>
   </PropertyGroup>
+
   <ItemGroup>
-    <Reference Include="ICSharpCode.SharpZipLib">
-      <HintPath>..\Lib\ICSharpCode.SharpZipLib.dll</HintPath>
-    </Reference>
-    <Reference Include="log4net">
-      <HintPath>..\Lib\log4net.dll</HintPath>
-    </Reference>
-    <Reference Include="MongoDB.Bson">
-      <HintPath>..\Lib\MongoDB.Bson.dll</HintPath>
-    </Reference>
-    <Reference Include="NLog">
-      <HintPath>..\Lib\NLog.dll</HintPath>
-    </Reference>
-    <Reference Include="protobuf-net">
-      <HintPath>..\Lib\protobuf-net.dll</HintPath>
-    </Reference>
-    <Reference Include="System" />
-    <Reference Include="System.Core" />
-    <Reference Include="System.Xml" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\DoubleMap.cs" Link="DoubleMap.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\EQueue.cs" Link="EQueue.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\ArrayHelper.cs" Link="Helper\ArrayHelper.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\ByteHelper.cs" Link="Helper\ByteHelper.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\EnumHelper.cs" Link="Helper\EnumHelper.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\FileHelper.cs" Link="Helper\FileHelper.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\IdGenerater.cs" Link="Helper\IdGenerater.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\MD5Helper.cs" Link="Helper\MD5Helper.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\MethodInfoHelper.cs" Link="Helper\MethodInfoHelper.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\NetHelper.cs" Link="Helper\NetHelper.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\ProtobufHelper.cs" Link="Helper\ProtobufHelper.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\RandomHelper.cs" Link="Helper\RandomHelper.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\StringHelper.cs" Link="Helper\StringHelper.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\TimeHelper.cs" Link="Helper\TimeHelper.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\ZipHelper.cs" Link="Helper\ZipHelper.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\MultiMap.cs" Link="MultiMap.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\AChannel.cs" Link="Network\AChannel.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\AService.cs" Link="Network\AService.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\TNet\PacketParser.cs" Link="Network\TNet\PacketParser.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\TNet\TBuffer.cs" Link="Network\TNet\TBuffer.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\TNet\TChannel.cs" Link="Network\TNet\TChannel.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\TNet\TService.cs" Link="Network\TNet\TService.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\Library.cs" Link="Network\UNet\Library.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\NativeMethods.cs" Link="Network\UNet\NativeMethods.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\NativeStructs.cs" Link="Network\UNet\NativeStructs.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UAddress.cs" Link="Network\UNet\UAddress.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UChannel.cs" Link="Network\UNet\UChannel.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UPacket.cs" Link="Network\UNet\UPacket.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UPoller.cs" Link="Network\UNet\UPoller.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UService.cs" Link="Network\UNet\UService.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\USocket.cs" Link="Network\UNet\USocket.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\USocketManager.cs" Link="Network\UNet\USocketManager.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\QueueDictionary.cs" Link="QueueDictionary.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\TryLocker.cs" Link="TryLocker.cs" />
   </ItemGroup>
+
   <ItemGroup>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\DoubleMap.cs">
-      <Link>DoubleMap.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\EQueue.cs">
-      <Link>EQueue.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\ArrayHelper.cs">
-      <Link>Helper\ArrayHelper.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\ByteHelper.cs">
-      <Link>Helper\ByteHelper.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\EnumHelper.cs">
-      <Link>Helper\EnumHelper.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\FileHelper.cs">
-      <Link>Helper\FileHelper.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\IdGenerater.cs">
-      <Link>Helper\IdGenerater.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\MD5Helper.cs">
-      <Link>Helper\MD5Helper.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\MethodInfoHelper.cs">
-      <Link>Helper\MethodInfoHelper.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\NetHelper.cs">
-      <Link>Helper\NetHelper.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\ProtobufHelper.cs">
-      <Link>Helper\ProtobufHelper.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\RandomHelper.cs">
-      <Link>Helper\RandomHelper.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\StringHelper.cs">
-      <Link>Helper\StringHelper.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\TimeHelper.cs">
-      <Link>Helper\TimeHelper.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\ZipHelper.cs">
-      <Link>Helper\ZipHelper.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\MultiMap.cs">
-      <Link>MultiMap.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\AChannel.cs">
-      <Link>Network\AChannel.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\AService.cs">
-      <Link>Network\AService.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\TNet\PacketParser.cs">
-      <Link>Network\TNet\PacketParser.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\TNet\TBuffer.cs">
-      <Link>Network\TNet\TBuffer.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\TNet\TChannel.cs">
-      <Link>Network\TNet\TChannel.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\TNet\TService.cs">
-      <Link>Network\TNet\TService.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\Library.cs">
-      <Link>Network\UNet\Library.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\NativeMethods.cs">
-      <Link>Network\UNet\NativeMethods.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\NativeStructs.cs">
-      <Link>Network\UNet\NativeStructs.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UAddress.cs">
-      <Link>Network\UNet\UAddress.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UChannel.cs">
-      <Link>Network\UNet\UChannel.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UPacket.cs">
-      <Link>Network\UNet\UPacket.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UPoller.cs">
-      <Link>Network\UNet\UPoller.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UService.cs">
-      <Link>Network\UNet\UService.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\USocket.cs">
-      <Link>Network\UNet\USocket.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\USocketManager.cs">
-      <Link>Network\UNet\USocketManager.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\QueueDictionary.cs">
-      <Link>QueueDictionary.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\TryLocker.cs">
-      <Link>TryLocker.cs</Link>
-    </Compile>
-    <Compile Include="Log.cs" />
-    <Compile Include="Logger\ALogDecorater.cs" />
-    <Compile Include="Logger\ILog.cs" />
-    <Compile Include="Logger\Log4NetAdapter.cs" />
-    <Compile Include="Logger\NLogAdapter.cs" />
-    <Compile Include="Logger\StackInfoDecorater.cs" />
-    <Compile Include="LogType.cs" />
-    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Folder Include="Helper\" />
+    <Folder Include="Network\TNet\" />
+    <Folder Include="Network\UNet\" />
   </ItemGroup>
-  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
-       Other similar extension points exist, see Microsoft.Common.targets.
-  <Target Name="BeforeBuild">
-  </Target>
-  <Target Name="AfterBuild">
-  </Target>
-  -->
-</Project>
+
+  <ItemGroup>
+    <PackageReference Include="NLog" Version="5.0.0-beta11" />
+    <PackageReference Include="protobuf-net" Version="2.3.2" />
+    <PackageReference Include="SharpZipLib" Version="1.0.0-alpha2" />
+  </ItemGroup>
+
+</Project>

+ 0 - 6
Server/Base/Server.Base.csproj.user

@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <ProjectView>ProjectFiles</ProjectView>
-  </PropertyGroup>
-</Project>

+ 0 - 35
Server/Hotfix/Properties/AssemblyInfo.cs

@@ -1,35 +0,0 @@
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-// 有关程序集的一般信息由以下
-// 控制。更改这些特性值可修改
-// 与程序集关联的信息。
-[assembly: AssemblyTitle("Controller")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("Controller")]
-[assembly: AssemblyCopyright("Copyright ©  2016")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-//将 ComVisible 设置为 false 将使此程序集中的类型
-//对 COM 组件不可见。  如果需要从 COM 访问此程序集中的类型,
-//请将此类型的 ComVisible 特性设置为 true。
-[assembly: ComVisible(false)]
-
-// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
-[assembly: Guid("3878bd71-2f75-4edf-882f-bc708154b1b0")]
-
-// 程序集的版本信息由下列四个值组成: 
-//
-//      主版本
-//      次版本
-//      生成号
-//      修订号
-//
-//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
-// 方法是按如下所示使用“*”: :
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.*")]
-[assembly: AssemblyFileVersion("1.0.0.0")]

+ 17 - 85
Server/Hotfix/Server.Hotfix.csproj

@@ -1,92 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+<Project Sdk="Microsoft.NET.Sdk">
+
   <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProjectGuid>{3878BD71-2F75-4EDF-882F-BC708154B1B0}</ProjectGuid>
-    <OutputType>Library</OutputType>
-    <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>Hotfix</RootNamespace>
+    <TargetFramework>netcoreapp2.0</TargetFramework>
     <AssemblyName>Hotfix</AssemblyName>
-    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
-    <FileAlignment>512</FileAlignment>
+    <RootNamespace>Hotfix</RootNamespace>
   </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
-    <OutputPath>..\..\Bin\</OutputPath>
-    <DefineConstants>TRACE;DEBUG;SERVER</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+    <DefineConstants>TRACE;DEBUG;NETCOREAPP2_0;SERVER</DefineConstants>
+    <OutputPath>..\..\</OutputPath>
   </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-    <DebugType>pdbonly</DebugType>
-    <Optimize>true</Optimize>
-    <OutputPath>..\..\Bin\</OutputPath>
-    <DefineConstants>TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
+    <DefineConstants>TRACE;RELEASE;NETCOREAPP2_0;SERVER</DefineConstants>
+    <OutputPath>..\..\</OutputPath>
   </PropertyGroup>
+
   <ItemGroup>
-    <Reference Include="System" />
-    <Reference Include="System.Core" />
-    <Reference Include="System.Numerics" />
-  </ItemGroup>
-  <ItemGroup>
-    <Compile Include="Handler\C2G_EnterMapHandler.cs" />
-    <Compile Include="Handler\M2M_TrasferUnitRequest.cs" />
-    <Compile Include="Handler\Actor_TransferHandler.cs" />
-    <Compile Include="Handler\Actor_TestRequestHandler.cs" />
-    <Compile Include="Handler\Actor_TestHandler.cs" />
-    <Compile Include="Handler\DBQueryBatchRequestHandler.cs" />
-    <Compile Include="Handler\DBQueryJsonRequestHandler.cs" />
-    <Compile Include="Handler\DBQueryRequestHandler.cs" />
-    <Compile Include="Handler\DBSaveBatchRequestHandler.cs" />
-    <Compile Include="Handler\DBSaveRequestHandler.cs" />
-    <Compile Include="Handler\G2M_CreateUnitHandler.cs" />
-    <Compile Include="Helper\HotfixHelper.cs" />
-    <Compile Include="Helper\MessageHelper.cs" />
-    <Compile Include="Handler\C2G_LoginGateHandler.cs" />
-    <Compile Include="Handler\C2R_PingHandler.cs" />
-    <Compile Include="Handler\G2G_LockReleaseRequestHandler.cs" />
-    <Compile Include="Handler\ObjectGetRequestHandler.cs" />
-    <Compile Include="Handler\ObjectUnLockRequestHandler.cs" />
-    <Compile Include="Handler\ObjectLockRequestHandler.cs" />
-    <Compile Include="Handler\ObjectRemoveRequestHandler.cs" />
-    <Compile Include="Handler\ObjectAddRequestHandler.cs" />
-    <Compile Include="Handler\M2A_ReloadHandler.cs" />
-    <Compile Include="Handler\C2M_ReloadHandler.cs" />
-    <Compile Include="Handler\G2G_LockRequestHandler.cs" />
-    <Compile Include="Handler\R2G_GetLoginKeyHandler.cs" />
-    <Compile Include="Other\EntityActorHandler.cs" />
-    <Compile Include="Other\InnerMessageDispatcher.cs" />
-    <Compile Include="Other\OuterMessageDispatcher.cs" />
-    <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="Handler\C2R_LoginHandler.cs" />
-    <Compile Include="System\ActorComponentSystem.cs" />
-    <Compile Include="System\NetInnerComponentSystem.cs" />
-    <Compile Include="System\NetOuterComponentSystem.cs" />
-    <Compile Include="System\RealmGateAddressComponentSystem.cs" />
-    <Compile Include="System\ServerFrameComponentSystem.cs" />
-  </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\Base\Server.Base.csproj">
-      <Project>{e5078ec6-2b0e-4711-be8b-d99f69638316}</Project>
-      <Name>Server.Base</Name>
-    </ProjectReference>
-    <ProjectReference Include="..\Model\Server.Model.csproj">
-      <Project>{820d3488-76b9-4ee8-872a-be06c2350b20}</Project>
-      <Name>Server.Model</Name>
-    </ProjectReference>
+    <ProjectReference Include="..\Base\Server.Base.csproj" />
+    <ProjectReference Include="..\Model\Server.Model.csproj" />
   </ItemGroup>
-  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
-       Other similar extension points exist, see Microsoft.Common.targets.
-  <Target Name="BeforeBuild">
-  </Target>
-  <Target Name="AfterBuild">
-  </Target>
-  -->
-</Project>
+
+</Project>

BIN=BIN
Server/Lib/CommandLine.dll


BIN=BIN
Server/Lib/ICSharpCode.SharpZipLib.dll


BIN=BIN
Server/Lib/MongoDB.Bson.dll


BIN=BIN
Server/Lib/MongoDB.Driver.Core.dll


BIN=BIN
Server/Lib/MongoDB.Driver.dll


BIN=BIN
Server/Lib/NLog.dll


BIN=BIN
Server/Lib/Newtonsoft.Json.dll


BIN=BIN
Server/Lib/log4net.dll


BIN=BIN
Server/Lib/protobuf-net.dll


+ 4 - 4
Server/Model/Component/AppManagerComponent.cs

@@ -48,11 +48,11 @@ namespace Model
 			string configFile = optionComponent.Options.Config;
 			StartConfig startConfig = startConfigComponent.Get(appId);
 #if __MonoCS__
-			const string exe = @"mono";
-			string arguments = $"--debug App.exe --appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}";
+			const string exe = @"dotnet";
+			string arguments = $"App.dll --appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}";
 #else
-			const string exe = @"App.exe";
-			string arguments = $"--appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}";
+			const string exe = @"dotnet";
+			string arguments = $"App.dll --appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}";
 #endif
 
 			Log.Info($"{exe} {arguments}");

+ 1 - 1
Server/Model/Component/BenchmarkComponent.cs

@@ -23,7 +23,7 @@ namespace Model
 			{
 				NetOuterComponent networkComponent = Game.Scene.GetComponent<NetOuterComponent>();
 
-				for (int i = 0; i < 100; i++)
+				for (int i = 0; i < 200; i++)
 				{
 					await Game.Scene.GetComponent<TimerComponent>().WaitAsync(10);
 					this.TestAsync(networkComponent, address, i);

+ 4 - 5
Server/Model/Component/OptionComponent.cs

@@ -14,14 +14,13 @@ namespace Model
 	
 	public class OptionComponent : Component
 	{
-		public Options Options { get; } = new Options();
+		public Options Options { get; set; }
 
 		public void Awake(string[] args)
 		{
-			if (!Parser.Default.ParseArguments(args, this.Options))
-			{
-				throw new Exception($"命令行格式错误!");
-			}
+			Parser.Default.ParseArguments<Options>(args)
+				.WithNotParsed(error => throw new Exception($"命令行格式错误!"))
+				.WithParsed(options => { Options = options; });
 		}
 	}
 }

+ 3 - 11
Server/Model/Other/Options.cs

@@ -1,13 +1,10 @@
-using System;
-using MongoDB.Bson;
-
-#if SERVER
+#if SERVER
 using CommandLine;
 #endif
 
 namespace Model
 {
-	public class Options: ICloneable
+	public class Options
 	{
 		[Option("appId", Required = true)]
 		public int AppId { get; set; }
@@ -16,12 +13,7 @@ namespace Model
 		[Option("appType", Required = true)]
 		public AppType AppType { get; set; }
 
-		[Option("config", Required = false, DefaultValue = "Start.txt")]
+		[Option("config", Required = false)]
 		public string Config { get; set; }
-
-		public object Clone()
-		{
-			return MongoHelper.FromBson<Options>(this.ToBson());
-		}
 	}
 }

+ 0 - 35
Server/Model/Properties/AssemblyInfo.cs

@@ -1,35 +0,0 @@
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-// 有关程序集的一般信息由以下
-// 控制。更改这些特性值可修改
-// 与程序集关联的信息。
-[assembly: AssemblyTitle("Model")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("Model")]
-[assembly: AssemblyCopyright("Copyright ©  2016")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-//将 ComVisible 设置为 false 将使此程序集中的类型
-//对 COM 组件不可见。  如果需要从 COM 访问此程序集中的类型,
-//请将此类型的 ComVisible 特性设置为 true。
-[assembly: ComVisible(false)]
-
-// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
-[assembly: Guid("820d3488-76b9-4ee8-872a-be06c2350b20")]
-
-// 程序集的版本信息由下列四个值组成: 
-//
-//      主版本
-//      次版本
-//      生成号
-//      修订号
-//
-//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
-// 方法是按如下所示使用“*”: :
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]

+ 56 - 228
Server/Model/Server.Model.csproj

@@ -1,239 +1,67 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+<Project Sdk="Microsoft.NET.Sdk">
+
   <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProjectGuid>{820D3488-76B9-4EE8-872A-BE06C2350B20}</ProjectGuid>
-    <OutputType>Library</OutputType>
-    <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>Model</RootNamespace>
+    <TargetFramework>netcoreapp2.0</TargetFramework>
     <AssemblyName>Model</AssemblyName>
-    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
-    <FileAlignment>512</FileAlignment>
+    <RootNamespace>Model</RootNamespace>
   </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
-    <OutputPath>..\..\Bin\</OutputPath>
-    <DefineConstants>TRACE;DEBUG;SERVER</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+    <DefineConstants>TRACE;DEBUG;NETCOREAPP2_0;SERVER</DefineConstants>
+    <OutputPath>..\..\</OutputPath>
   </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-    <DebugType>pdbonly</DebugType>
-    <Optimize>true</Optimize>
-    <OutputPath>..\..\Bin\</OutputPath>
-    <DefineConstants>TRACE;SERVER</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
+    <DefineConstants>TRACE;RELEASE;NETCOREAPP2_0;SERVER</DefineConstants>
+    <OutputPath>..\..\</OutputPath>
   </PropertyGroup>
+
+  <ItemGroup>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\AppType.cs" Link="Message\AppType.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\IMessageDispatcher.cs" Link="Message\IMessageDispatcher.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\IMessagePacker.cs" Link="Message\IMessagePacker.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\MessageInfo.cs" Link="Base\Message\MessageInfo.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\MongoPacker.cs" Link="Message\MongoPacker.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\ProtobufPacker.cs" Link="Message\ProtobufPacker.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\RpcException.cs" Link="Message\RpcException.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\Component.cs" Link="Base\Object\Component.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ComponentFactory.cs" Link="Base\Object\ComponentFactory.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\Disposer.cs" Link="Base\Object\Disposer.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\Entity.cs" Link="Base\Object\Entity.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\EntityFactory.cs" Link="Base\Object\EntityFactory.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\IAwake.cs" Link="Base\Object\IAwake.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ILateUpdate.cs" Link="Base\Object\ILateUpdate.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ILoad.cs" Link="Base\Object\ILoad.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\IStart.cs" Link="Base\Object\IStart.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\IUpdate.cs" Link="Base\Object\IUpdate.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\Object.cs" Link="Base\Object\Object.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ObjectEventAttribute.cs" Link="Base\Object\ObjectEventAttribute.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ObjectPool.cs" Link="Base\Object\ObjectPool.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Component\ConfigComponent.cs" Link="Component\ConfigComponent.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Component\EventComponent.cs" Link="Component\EventComponent.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Component\NetworkComponent.cs" Link="Component\NetworkComponent.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Component\TimerComponent.cs" Link="Component\TimerComponent.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Entity\Message\Opcode.cs" Link="Entity\Message\Opcode.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Entity\Message\OuterMessage.cs" Link="Entity\Message\OuterMessage.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Entity\Session.cs" Link="Entity\Session.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Helper\MongoHelper.cs" Link="Helper\MongoHelper.cs" />
+  </ItemGroup>
+
   <ItemGroup>
-    <Reference Include="CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\Lib\CommandLine.dll</HintPath>
-    </Reference>
-    <Reference Include="MongoDB.Bson, Version=2.3.0.157, Culture=neutral, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\Lib\MongoDB.Bson.dll</HintPath>
-    </Reference>
-    <Reference Include="MongoDB.Driver">
-      <HintPath>..\Lib\MongoDB.Driver.dll</HintPath>
-    </Reference>
-    <Reference Include="MongoDB.Driver.Core">
-      <HintPath>..\Lib\MongoDB.Driver.Core.dll</HintPath>
-    </Reference>
-    <Reference Include="Newtonsoft.Json">
-      <HintPath>..\Lib\Newtonsoft.Json.dll</HintPath>
-    </Reference>
-    <Reference Include="System" />
-    <Reference Include="System.Core" />
-    <Reference Include="System.Numerics" />
+    <Folder Include="Helper\" />
   </ItemGroup>
+
   <ItemGroup>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\DoubleMap.cs">
-      <Link>Entity\DoubleMap.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\AppType.cs">
-      <Link>Message\AppType.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\IMessageDispatcher.cs">
-      <Link>Message\IMessageDispatcher.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\IMessagePacker.cs">
-      <Link>Message\IMessagePacker.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\MessageInfo.cs">
-      <Link>Base\Message\MessageInfo.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\MongoPacker.cs">
-      <Link>Message\MongoPacker.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\ProtobufPacker.cs">
-      <Link>Message\ProtobufPacker.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\RpcException.cs">
-      <Link>Message\RpcException.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\Component.cs">
-      <Link>Base\Object\Component.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ComponentFactory.cs">
-      <Link>Base\Object\ComponentFactory.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\Disposer.cs">
-      <Link>Base\Object\Disposer.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\Entity.cs">
-      <Link>Base\Object\Entity.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\EntityFactory.cs">
-      <Link>Base\Object\EntityFactory.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\IAwake.cs">
-      <Link>Base\Object\IAwake.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ILoad.cs">
-      <Link>Base\Object\ILoad.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\IStart.cs">
-      <Link>Base\Object\IStart.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\IUpdate.cs">
-      <Link>Base\Object\IUpdate.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\Object.cs">
-      <Link>Base\Object\Object.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ObjectEventAttribute.cs">
-      <Link>Base\Object\ObjectEventAttribute.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ObjectPool.cs">
-      <Link>Base\Object\ObjectPool.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Component\ConfigComponent.cs">
-      <Link>Component\ConfigComponent.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Component\EventComponent.cs">
-      <Link>Component\EventComponent.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Component\NetworkComponent.cs">
-      <Link>Component\NetworkComponent.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Component\TimerComponent.cs">
-      <Link>Component\TimerComponent.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Entity\Message\Opcode.cs">
-      <Link>Entity\Message\Opcode.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Entity\Message\OuterMessage.cs">
-      <Link>Entity\Message\OuterMessage.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Entity\Session.cs">
-      <Link>Entity\Session.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Helper\MongoHelper.cs">
-      <Link>Helper\MongoHelper.cs</Link>
-    </Compile>
-    <Compile Include="Base\Other\HttpHandlerAttribute.cs" />
-    <Compile Include="Base\Other\IHttpHandler.cs" />
-    <Compile Include="Component\ActorProxyComponent.cs" />
-    <Compile Include="Component\HttpComponent.cs" />
-    <Compile Include="Component\ServerFrameComponent.cs" />
-    <Compile Include="Component\PlayerComponent.cs" />
-    <Compile Include="Component\Unit\UnitGateComponent.cs" />
-    <Compile Include="Entity\Player.cs" />
-    <Compile Include="Entity\Location.cs" />
-    <Compile Include="Base\Message\AMRpcHandler.cs" />
-    <Compile Include="Base\Message\IEntityActorHandler.cs" />
-    <Compile Include="Component\OpcodeTypeComponent.cs" />
-    <Compile Include="Component\ActorManagerComponent.cs" />
-    <Compile Include="Component\BenchmarkComponent.cs" />
-    <Compile Include="Component\Config\ClientConfig.cs" />
-    <Compile Include="Component\Config\DBConfig.cs" />
-    <Compile Include="Component\Config\HttpConfig.cs" />
-    <Compile Include="Component\Config\InnerConfig.cs" />
-    <Compile Include="Component\Config\OuterConfig.cs" />
-    <Compile Include="Component\DBCacheComponent.cs" />
-    <Compile Include="Component\DBComponent.cs" />
-    <Compile Include="Component\DBProxyComponent.cs" />
-    <Compile Include="Component\KVComponent.cs" />
-    <Compile Include="Component\LocationProxyComponent.cs" />
-    <Compile Include="Component\ActorMessageDispatherComponent.cs" />
-    <Compile Include="Component\MessageDispatherComponent.cs" />
-    <Compile Include="Component\NetInnerComponent.cs" />
-    <Compile Include="Component\NetOuterComponent.cs" />
-    <Compile Include="Component\RobotComponent.cs" />
-    <Compile Include="Component\Session\SessionPlayerComponent.cs" />
-    <Compile Include="Component\LocationComponent.cs" />
-    <Compile Include="Component\ActorComponent.cs" />
-    <Compile Include="Component\UnitComponent.cs" />
-    <Compile Include="Component\Player\SessionInfoComponent.cs" />
-    <Compile Include="Component\Unit\MasterComponent.cs" />
-    <Compile Include="Component\Unit\LockComponent.cs" />
-    <Compile Include="Component\AppManagerComponent.cs" />
-    <Compile Include="Component\GateSessionKeyComponent.cs" />
-    <Compile Include="Component\RealmGateAddressComponent.cs" />
-    <Compile Include="Component\OptionComponent.cs" />
-    <Compile Include="Component\StartConfigComponent.cs" />
-    <Compile Include="Base\Config\ACategory.cs" />
-    <Compile Include="Base\Config\AConfig.cs" />
-    <Compile Include="Base\Config\AConfigComponent.cs" />
-    <Compile Include="Base\Config\ConfigAttribute.cs" />
-    <Compile Include="Base\Config\ConfigHelper.cs" />
-    <Compile Include="Base\Config\ICategory.cs" />
-    <Compile Include="Entity\Config\BuffConfig.cs" />
-    <Compile Include="Entity\Config\StartConfig.cs" />
-    <Compile Include="Entity\ActorProxy.cs" />
-    <Compile Include="Entity\SceneEntity.cs" />
-    <Compile Include="Entity\EntityDB.cs" />
-    <Compile Include="Entity\DBTask.cs" />
-    <Compile Include="Entity\DBTaskQueue.cs" />
-    <Compile Include="Entity\Game.cs" />
-    <Compile Include="Entity\Http.cs" />
-    <Compile Include="Entity\Message\InnerMessage.cs" />
-    <Compile Include="Entity\Message\InnerOpcode.cs" />
-    <Compile Include="Entity\Scene.cs" />
-    <Compile Include="Entity\Unit.cs" />
-    <Compile Include="Base\Event\AEventAttribute.cs" />
-    <Compile Include="Base\Event\Env.cs" />
-    <Compile Include="Base\Event\EnvKey.cs" />
-    <Compile Include="Base\Event\EventAttribute.cs" />
-    <Compile Include="Base\Event\EventIdType.cs" />
-    <Compile Include="Base\Event\IEvent.cs" />
-    <Compile Include="Base\Helper\DllHelper.cs" />
-    <Compile Include="Base\Message\AActorMessage.cs" />
-    <Compile Include="Base\Message\AMessage.cs" />
-    <Compile Include="Base\Message\AMActorHandler.cs" />
-    <Compile Include="Base\Message\ErrorCode.cs" />
-    <Compile Include="Base\Message\IMActorHandler.cs" />
-    <Compile Include="Base\Message\IMHandler.cs" />
-    <Compile Include="Base\Message\ActorMessageAttribute.cs" />
-    <Compile Include="Base\Message\MessageAttribute.cs" />
-    <Compile Include="Base\Message\ActorMessageHandlerAttribute.cs" />
-    <Compile Include="Base\Message\MessageHandlerAttribute.cs" />
-    <Compile Include="Base\Message\OpcodeHelper.cs" />
-    <Compile Include="Base\Object\ComponentDB.cs" />
-    <Compile Include="Base\Object\EntityType.cs" />
-    <Compile Include="Base\Object\ObjectEvents.cs" />
-    <Compile Include="Message\AMHandler.cs" />
-    <Compile Include="Other\OneThreadSynchronizationContext.cs" />
-    <Compile Include="Other\Options.cs" />
-    <Compile Include="Properties\AssemblyInfo.cs" />
+    <PackageReference Include="CommandLineParser" Version="2.1.1-beta" />
+    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
+    <PackageReference Include="SharpZipLib" Version="1.0.0-alpha2" />
   </ItemGroup>
+
   <ItemGroup>
-    <ProjectReference Include="..\Base\Server.Base.csproj">
-      <Project>{e5078ec6-2b0e-4711-be8b-d99f69638316}</Project>
-      <Name>Server.Base</Name>
-    </ProjectReference>
+    <ProjectReference Include="..\Base\Server.Base.csproj" />
+    <ProjectReference Include="..\ThirdParty\MongodbDriver\DotNetCoreDriver\MongoDB.Bson\MongoDB.Bson.csproj" />
+    <ProjectReference Include="..\ThirdParty\MongodbDriver\DotNetCoreDriver\MongoDB.Driver.Core\MongoDB.Driver.Core.csproj" />
+    <ProjectReference Include="..\ThirdParty\MongodbDriver\DotNetCoreDriver\MongoDB.Driver\MongoDB.Driver.csproj" />
   </ItemGroup>
-  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
-       Other similar extension points exist, see Microsoft.Common.targets.
-  <Target Name="BeforeBuild">
-  </Target>
-  <Target Name="AfterBuild">
-  </Target>
-  -->
-</Project>
+
+</Project>

+ 0 - 6
Server/Model/Server.Model.csproj.user

@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <ProjectView>ProjectFiles</ProjectView>
-  </PropertyGroup>
-</Project>

+ 0 - 97
Server/Server.sln

@@ -1,97 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.26730.15
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Base", "Base\Server.Base.csproj", "{E5078EC6-2B0E-4711-BE8B-D99F69638316}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Model", "Model\Server.Model.csproj", "{820D3488-76B9-4EE8-872A-BE06C2350B20}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ThirdParty", "ThirdParty", "{01CCAD69-09B1-42F9-8A39-489268BEE18D}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.App", "App\Server.App.csproj", "{3F8DC04C-9E05-403F-B6A5-36293EB99937}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ENet", "ThirdParty\ENet\ENet.vcxproj", "{C9992B7C-313E-4C9F-A954-640D01EDFB58}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Hotfix", "Hotfix\Server.Hotfix.csproj", "{3878BD71-2F75-4EDF-882F-BC708154B1B0}"
-EndProject
-Global
-	GlobalSection(SolutionConfigurationPlatforms) = preSolution
-		Debug|Any CPU = Debug|Any CPU
-		Debug|x64 = Debug|x64
-		Debug|x86 = Debug|x86
-		Release|Any CPU = Release|Any CPU
-		Release|x64 = Release|x64
-		Release|x86 = Release|x86
-	EndGlobalSection
-	GlobalSection(ProjectConfigurationPlatforms) = postSolution
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|x64.Build.0 = Debug|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|x86.Build.0 = Debug|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|Any CPU.Build.0 = Release|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|x64.ActiveCfg = Release|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|x64.Build.0 = Release|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|x86.ActiveCfg = Release|Any CPU
-		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|x86.Build.0 = Release|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|x64.Build.0 = Debug|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|x86.Build.0 = Debug|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|Any CPU.Build.0 = Release|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|x64.ActiveCfg = Release|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|x64.Build.0 = Release|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|x86.ActiveCfg = Release|Any CPU
-		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|x86.Build.0 = Release|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|x64.Build.0 = Debug|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|x86.Build.0 = Debug|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|Any CPU.Build.0 = Release|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x64.ActiveCfg = Release|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x64.Build.0 = Release|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x86.ActiveCfg = Release|Any CPU
-		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x86.Build.0 = Release|Any CPU
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|Any CPU.ActiveCfg = Debug|Win32
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|Any CPU.Build.0 = Debug|Win32
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x64.ActiveCfg = Debug|x64
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x64.Build.0 = Debug|x64
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x86.ActiveCfg = Debug|Win32
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x86.Build.0 = Debug|Win32
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|Any CPU.ActiveCfg = Release|Win32
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x64.ActiveCfg = Release|x64
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x64.Build.0 = Release|x64
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x86.ActiveCfg = Release|Win32
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x86.Build.0 = Release|Win32
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|x64.Build.0 = Debug|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|x86.Build.0 = Debug|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|Any CPU.Build.0 = Release|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|x64.ActiveCfg = Release|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|x64.Build.0 = Release|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|x86.ActiveCfg = Release|Any CPU
-		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|x86.Build.0 = Release|Any CPU
-	EndGlobalSection
-	GlobalSection(SolutionProperties) = preSolution
-		HideSolutionNode = FALSE
-	EndGlobalSection
-	GlobalSection(NestedProjects) = preSolution
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58} = {01CCAD69-09B1-42F9-8A39-489268BEE18D}
-	EndGlobalSection
-	GlobalSection(ExtensibilityGlobals) = postSolution
-		SolutionGuid = {0B3370FF-162C-439D-9E8D-7DDFF59AD82B}
-	EndGlobalSection
-EndGlobal

+ 0 - 1585
Server/Server.sln.DotSettings

@@ -1,1585 +0,0 @@
-<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
-	<s:String x:Key="/Default/CodeEditing/Intellisense/ClrSymbolsFilterFactory/StoredFilters/@EntryValue">&lt;root&gt;&lt;filter&gt;&lt;namespace_mask&gt;Boo&lt;/namespace_mask&gt;&lt;has_type_parameters&gt;Any&lt;/has_type_parameters&gt;&lt;element_kind&gt;Any&lt;/element_kind&gt;&lt;/filter&gt;&lt;/root&gt;</s:String>
-	<s:Boolean x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/AutoCompleteBasicCompletion/@EntryValue">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/CompletionFilters/PersistFilterState/@EntryValue">True</s:Boolean>
-	
-	<s:String x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/IntelliSenseCompletingCharacters/CSharpCompletingCharacters/NonCompletingCharacters/@EntryValue">&lt;&gt;</s:String>
-	
-	
-	<s:Boolean x:Key="/Default/CodeEditing/Localization/CSharpLocalizationOptions/DontAnalyseVerbatimStrings/@EntryValue">False</s:Boolean>
-	<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/FileMasksToSkip/=_002A_002Emin_002Ejs/@EntryIndexedValue">True</s:Boolean>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeThisQualifier/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertIfStatementToReturnStatement/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertPropertyToExpressionBody/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToAutoProperty/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToAutoPropertyWithPrivateSetter/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=DelegateSubtraction/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=FieldCanBeMadeReadOnly_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ForCanBeConvertedToForeach/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ImplicitlyCapturedClosure/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InconsistentNaming/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LoopCanBeConvertedToQuery/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LoopCanBePartlyConvertedToQuery/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleNullReferenceException/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantAssignment/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SpecifyACultureInStringConversionExplicitly/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestUseVarKeywordEverywhere/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestUseVarKeywordEvident/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestVarOrType_005FElsewhere/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedAutoPropertyAccessor_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedAutoPropertyAccessor_002ELocal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedMember_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseNullPropagation/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseObjectOrCollectionInitializer/@EntryIndexedValue">DO_NOT_SHOW</s:String>
-	
-	<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Unity/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Unity"&gt;&lt;CSArrangeThisQualifier&gt;True&lt;/CSArrangeThisQualifier&gt;&lt;CSRemoveCodeRedundancies&gt;True&lt;/CSRemoveCodeRedundancies&gt;&lt;CSMakeFieldReadonly&gt;True&lt;/CSMakeFieldReadonly&gt;&lt;CSUseVar&gt;&lt;BehavourStyle&gt;DISABLED&lt;/BehavourStyle&gt;&lt;LocalVariableStyle&gt;IMPLICIT_WHEN_INITIALIZER_HAS_TYPE&lt;/LocalVariableStyle&gt;&lt;ForeachVariableStyle&gt;IMPLICIT_EXCEPT_SIMPLE_TYPES&lt;/ForeachVariableStyle&gt;&lt;/CSUseVar&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;False&lt;/EmbraceInRegion&gt;&lt;RegionName&gt;&lt;/RegionName&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;CSMakeAutoPropertyGetOnly&gt;True&lt;/CSMakeAutoPropertyGetOnly&gt;&lt;CSUseAutoProperty&gt;True&lt;/CSUseAutoProperty&gt;&lt;RemoveCodeRedundancies&gt;True&lt;/RemoveCodeRedundancies&gt;&lt;/Profile&gt;</s:String>
-	<s:String x:Key="/Default/CodeStyle/CodeCleanup/RecentlyUsedProfile/@EntryValue">tanghai</s:String>
-	
-	
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ThisQualifier/INSTANCE_MEMBERS_QUALIFY_MEMBERS/@EntryValue">All</s:String>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_FIRST_ARG_BY_PAREN/@EntryValue">True</s:Boolean>
-	
-	
-	
-	
-	
-	<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/CONTINUOUS_INDENT_MULTIPLIER/@EntryValue">2</s:Int64>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_ATTRIBUTE_STYLE/@EntryValue">JOIN</s:String>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_FIXED_BRACES_STYLE/@EntryValue">ALWAYS_ADD</s:String>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_FOR_BRACES_STYLE/@EntryValue">ALWAYS_ADD</s:String>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_FOREACH_BRACES_STYLE/@EntryValue">ALWAYS_ADD</s:String>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_IFELSE_BRACES_STYLE/@EntryValue">ALWAYS_ADD</s:String>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_USING_BRACES_STYLE/@EntryValue">ALWAYS_ADD</s:String>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_WHILE_BRACES_STYLE/@EntryValue">ALWAYS_ADD</s:String>
-	
-	
-	
-	<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_CODE/@EntryValue">1</s:Int64>
-	<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue">1</s:Int64>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_USER_LINEBREAKS/@EntryValue">False</s:Boolean>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/MODIFIERS_ORDER/@EntryValue">private public protected internal new abstract virtual override sealed static readonly extern unsafe volatile async</s:String>
-	
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE/@EntryValue">False</s:Boolean>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ACCESSOR_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_WHILE_ON_NEW_LINE/@EntryValue">True</s:Boolean>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/REDUNDANT_THIS_QUALIFIER_STYLE/@EntryValue">ALWAYS_USE</s:String>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SIMPLE_EMBEDDED_STATEMENT_STYLE/@EntryValue">LINE_BREAK</s:String>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AROUND_MULTIPLICATIVE_OP/@EntryValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_EXTENDS_COLON/@EntryValue">False</s:Boolean>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_TERNARY_QUEST/@EntryValue">False</s:Boolean>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/STICK_COMMENT/@EntryValue">False</s:Boolean>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_AFTER_DECLARATION_LPAR/@EntryValue">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_FIRST_TYPE_PARAMETER_CONSTRAINT/@EntryValue">True</s:Boolean>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_FOR_STMT_HEADER_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
-	<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">150</s:Int64>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_MULTIPLE_DECLARATION_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_TERNARY_EXPR_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/JavaScriptCodeFormatting/ALIGN_MULTIPLE_DECLARATION/@EntryValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/JavaScriptCodeFormatting/JavaScriptFormatOther/ALIGN_MULTIPLE_DECLARATION/@EntryValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/XmlFormatter/BlankLineAfterProcessingInstructions/@EntryValue">False</s:Boolean>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/XmlFormatter/ProcessingInstructionAttributeIndenting/@EntryValue">TwoSteps</s:String>
-	<s:String x:Key="/Default/CodeStyle/CodeFormatting/XmlFormatter/TagAttributeIndenting/@EntryValue">TwoSteps</s:String>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/XmlFormatter/TagSpaceBeforeHeaderEnd1/@EntryValue">False</s:Boolean>
-	<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/XmlFormatter/WrapBeforeAttr/@EntryValue">False</s:Boolean>
-	
-	<s:String x:Key="/Default/CodeStyle/CSharpMemberOrderPattern/CustomPattern/@EntryValue">&lt;?xml version="1.0" encoding="utf-8" ?&gt;&#xD;
-&#xD;
-&lt;!--&#xD;
-I. Overall&#xD;
-&#xD;
-I.1 Each pattern can have &lt;Match&gt;....&lt;/Match&gt; element. For the given type declaration, the pattern with the match, evaluated to 'true' with the largest weight, will be used &#xD;
-I.2 Each pattern consists of the sequence of &lt;Entry&gt;...&lt;/Entry&gt; elements. Type member declarations are distributed between entries&#xD;
-I.3 If pattern has RemoveAllRegions="true" attribute, then all regions will be cleared prior to reordering. Otherwise, only auto-generated regions will be cleared&#xD;
-I.4 The contents of each entry is sorted by given keys (First key is primary,  next key is secondary, etc). Then the declarations are grouped and en-regioned by given property&#xD;
-&#xD;
-II. Available match operands&#xD;
-&#xD;
-Each operand may have Weight="..." attribute. This weight will be added to the match weight if the operand is evaluated to 'true'.&#xD;
-The default weight is 1&#xD;
-&#xD;
-II.1 Boolean functions:&#xD;
-II.1.1 &lt;And&gt;....&lt;/And&gt;&#xD;
-II.1.2 &lt;Or&gt;....&lt;/Or&gt;&#xD;
-II.1.3 &lt;Not&gt;....&lt;/Not&gt;&#xD;
-&#xD;
-II.2 Operands&#xD;
-II.2.1 &lt;Kind Is="..."/&gt;. Kinds are: class, struct, interface, enum, delegate, type, constructor, destructor, property, indexer, method, operator, field, constant, event, member&#xD;
-II.2.2 &lt;Name Is="..." [IgnoreCase="true/false"] /&gt;. The 'Is' attribute contains regular expression&#xD;
-II.2.3 &lt;HasAttribute CLRName="..." [Inherit="true/false"] /&gt;. The 'CLRName' attribute contains regular expression&#xD;
-II.2.4 &lt;Access Is="..."/&gt;. The 'Is' values are: public, protected, internal, protected internal, private&#xD;
-II.2.5 &lt;Static/&gt;&#xD;
-II.2.6 &lt;Abstract/&gt;&#xD;
-II.2.7 &lt;Virtual/&gt;&#xD;
-II.2.8 &lt;Override/&gt;&#xD;
-II.2.9 &lt;Sealed/&gt;&#xD;
-II.2.10 &lt;Readonly/&gt;&#xD;
-II.2.11 &lt;ImplementsInterface CLRName="..."/&gt;. The 'CLRName' attribute contains regular expression&#xD;
-II.2.12 &lt;HandlesEvent /&gt;&#xD;
---&gt;&#xD;
-&#xD;
-&lt;Patterns xmlns="urn:shemas-jetbrains-com:member-reordering-patterns"&gt;&#xD;
-&#xD;
-  &lt;!--Do not reorder COM interfaces and structs marked by StructLayout attribute--&gt;&#xD;
-  &lt;Pattern&gt;&#xD;
-    &lt;Match&gt;&#xD;
-      &lt;Or Weight="100"&gt;&#xD;
-        &lt;And&gt;&#xD;
-          &lt;Kind Is="interface"/&gt;&#xD;
-          &lt;Or&gt;&#xD;
-            &lt;HasAttribute CLRName="System.Runtime.InteropServices.InterfaceTypeAttribute"/&gt;&#xD;
-            &lt;HasAttribute CLRName="System.Runtime.InteropServices.ComImport"/&gt;&#xD;
-          &lt;/Or&gt;&#xD;
-        &lt;/And&gt;&#xD;
-        &lt;HasAttribute CLRName="System.Runtime.InteropServices.StructLayoutAttribute"/&gt;&#xD;
-      &lt;/Or&gt;&#xD;
-    &lt;/Match&gt;&#xD;
-  &lt;/Pattern&gt;&#xD;
-&#xD;
-  &lt;!--Special formatting of NUnit test fixture--&gt;&#xD;
-  &lt;Pattern RemoveAllRegions="true"&gt;&#xD;
-    &lt;Match&gt;&#xD;
-      &lt;And Weight="100"&gt;&#xD;
-        &lt;Kind Is="class"/&gt;&#xD;
-        &lt;HasAttribute CLRName="NUnit.Framework.TestFixtureAttribute" Inherit="true"/&gt;&#xD;
-      &lt;/And&gt;&#xD;
-    &lt;/Match&gt;&#xD;
-&#xD;
-    &lt;!--Setup/Teardow--&gt;&#xD;
-    &lt;Entry&gt;&#xD;
-      &lt;Match&gt;&#xD;
-        &lt;And&gt;&#xD;
-          &lt;Kind Is="method"/&gt;&#xD;
-          &lt;Or&gt;&#xD;
-            &lt;HasAttribute CLRName="NUnit.Framework.SetUpAttribute" Inherit="true"/&gt;&#xD;
-            &lt;HasAttribute CLRName="NUnit.Framework.TearDownAttribute" Inherit="true"/&gt;&#xD;
-            &lt;HasAttribute CLRName="NUnit.Framework.FixtureSetUpAttribute" Inherit="true"/&gt;&#xD;
-            &lt;HasAttribute CLRName="NUnit.Framework.FixtureTearDownAttribute" Inherit="true"/&gt;&#xD;
-          &lt;/Or&gt;&#xD;
-        &lt;/And&gt;&#xD;
-      &lt;/Match&gt;&#xD;
-      &lt;Group Region="Setup/Teardown"/&gt;&#xD;
-    &lt;/Entry&gt;&#xD;
-    &#xD;
-    &lt;!--All other members--&gt;&#xD;
-    &lt;Entry/&gt;&#xD;
-    &#xD;
-    &lt;!--Test methods--&gt;&#xD;
-    &lt;Entry&gt;&#xD;
-      &lt;Match&gt;&#xD;
-        &lt;And Weight="100"&gt;&#xD;
-          &lt;Kind Is="method"/&gt;&#xD;
-          &lt;HasAttribute CLRName="NUnit.Framework.TestAttribute" Inherit="false"/&gt;&#xD;
-        &lt;/And&gt;&#xD;
-      &lt;/Match&gt;&#xD;
-      &lt;Sort&gt;&#xD;
-        &lt;Name/&gt;&#xD;
-      &lt;/Sort&gt;&#xD;
-    &lt;/Entry&gt;&#xD;
-  &lt;/Pattern&gt;&#xD;
-&#xD;
-  &lt;!--Default pattern--&gt;&#xD;
-  &lt;Pattern&gt;&#xD;
-&#xD;
-    &lt;!--public delegate--&gt;&#xD;
-    &lt;Entry&gt;&#xD;
-      &lt;Match&gt;&#xD;
-        &lt;And Weight="100"&gt;&#xD;
-          &lt;Access Is="public"/&gt;&#xD;
-          &lt;Kind Is="delegate"/&gt;&#xD;
-        &lt;/And&gt;&#xD;
-      &lt;/Match&gt;&#xD;
-      &lt;Sort&gt;&#xD;
-        &lt;Name/&gt;&#xD;
-      &lt;/Sort&gt;&#xD;
-      &lt;Group Region="Delegates"/&gt;&#xD;
-    &lt;/Entry&gt;&#xD;
-    &#xD;
-    &lt;!--public enum--&gt;&#xD;
-    &lt;Entry&gt;&#xD;
-      &lt;Match&gt;&#xD;
-        &lt;And Weight="100"&gt;&#xD;
-          &lt;Access Is="public"/&gt;&#xD;
-          &lt;Kind Is="enum"/&gt;&#xD;
-        &lt;/And&gt;&#xD;
-      &lt;/Match&gt;&#xD;
-      &lt;Sort&gt;&#xD;
-        &lt;Name/&gt;&#xD;
-      &lt;/Sort&gt;&#xD;
-      &lt;Group&gt;&#xD;
-        &lt;Name Region="${Name} enum"/&gt;&#xD;
-      &lt;/Group&gt;&#xD;
-    &lt;/Entry&gt;&#xD;
-&#xD;
-    &lt;!--static fields and constants--&gt;&#xD;
-    &lt;Entry&gt;&#xD;
-      &lt;Match&gt;&#xD;
-        &lt;Or&gt;&#xD;
-          &lt;Kind Is="constant"/&gt;&#xD;
-          &lt;And&gt;&#xD;
-            &lt;Kind Is="field"/&gt;&#xD;
-            &lt;Static/&gt;&#xD;
-          &lt;/And&gt;&#xD;
-        &lt;/Or&gt;&#xD;
-      &lt;/Match&gt;&#xD;
-      &lt;Sort&gt;&#xD;
-        &lt;Kind Order="constant field"/&gt;&#xD;
-      &lt;/Sort&gt;&#xD;
-    &lt;/Entry&gt;&#xD;
-    &#xD;
-    &lt;!--instance fields--&gt;&#xD;
-    &lt;Entry&gt;&#xD;
-      &lt;Match&gt;&#xD;
-        &lt;And&gt;&#xD;
-          &lt;Kind Is="field"/&gt;&#xD;
-          &lt;Not&gt;&#xD;
-            &lt;Static/&gt;&#xD;
-          &lt;/Not&gt;&#xD;
-        &lt;/And&gt;&#xD;
-      &lt;/Match&gt;&#xD;
-      &lt;Sort&gt;&#xD;
-        &lt;Readonly/&gt;&#xD;
-        &lt;Name/&gt;&#xD;
-      &lt;/Sort&gt;&#xD;
-    &lt;/Entry&gt;&#xD;
-&#xD;
-    &lt;!--Constructors. Place static one first--&gt;&#xD;
-    &lt;Entry&gt;&#xD;
-      &lt;Match&gt;&#xD;
-        &lt;Kind Is="constructor"/&gt;&#xD;
-      &lt;/Match&gt;&#xD;
-      &lt;Sort&gt;&#xD;
-        &lt;Static/&gt;&#xD;
-      &lt;/Sort&gt;&#xD;
-    &lt;/Entry&gt;&#xD;
-    &#xD;
-    &lt;!--properties, indexers--&gt;&#xD;
-    &lt;Entry&gt;&#xD;
-      &lt;Match&gt;&#xD;
-        &lt;Or&gt;&#xD;
-          &lt;Kind Is="property"/&gt;&#xD;
-          &lt;Kind Is="indexer"/&gt;&#xD;
-        &lt;/Or&gt;&#xD;
-      &lt;/Match&gt;&#xD;
-    &lt;/Entry&gt;&#xD;
-    &#xD;
-    &lt;!--interface implementations--&gt;&#xD;
-    &lt;Entry&gt;&#xD;
-      &lt;Match&gt;&#xD;
-        &lt;And Weight="100"&gt;&#xD;
-          &lt;Kind Is="member"/&gt;&#xD;
-          &lt;ImplementsInterface/&gt;&#xD;
-        &lt;/And&gt;&#xD;
-      &lt;/Match&gt;&#xD;
-      &lt;Sort&gt;&#xD;
-        &lt;ImplementsInterface Immediate="true"/&gt;&#xD;
-      &lt;/Sort&gt;&#xD;
-      &lt;Group&gt;&#xD;
-        &lt;ImplementsInterface Immediate="true" Region="${ImplementsInterface} Members"/&gt;&#xD;
-      &lt;/Group&gt;&#xD;
-    &lt;/Entry&gt;&#xD;
-    &#xD;
-    &lt;!--all other members--&gt;&#xD;
-    &lt;Entry/&gt;&#xD;
-    &#xD;
-    &lt;!--nested types--&gt;&#xD;
-    &lt;Entry&gt;&#xD;
-      &lt;Match&gt;&#xD;
-        &lt;Kind Is="type"/&gt;&#xD;
-      &lt;/Match&gt;&#xD;
-      &lt;Sort&gt;&#xD;
-        &lt;Name/&gt;&#xD;
-      &lt;/Sort&gt;&#xD;
-      &lt;Group&gt;&#xD;
-        &lt;Name Region="Nested type: ${Name}"/&gt;&#xD;
-      &lt;/Group&gt;&#xD;
-    &lt;/Entry&gt;&#xD;
-  &lt;/Pattern&gt;&#xD;
-  &#xD;
-&lt;/Patterns&gt;&#xD;
-</s:String>
-	<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseExplicitType</s:String>
-	<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseExplicitType</s:String>
-	<s:Boolean x:Key="/Default/CodeStyle/Generate/=Properties/@KeyIndexDefined">True</s:Boolean>
-	<s:String x:Key="/Default/CodeStyle/Generate/=Properties/Options/=DebuggerStepsThrough/@EntryIndexedValue">False</s:String>
-	<s:String x:Key="/Default/CodeStyle/Generate/=Properties/Options/=XmlDocumentation/@EntryIndexedValue">False</s:String>
-	<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/EventHandlerPatternLong/@EntryValue">$object$_On$event$</s:String>
-	<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
-	<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
-	<s:String x:Key="/Default/CodeStyle/Naming/VBNaming/EventHandlerPatternLong/@EntryValue">$object$_On$event$</s:String>
-	<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
-	
-	<s:String x:Key="/Default/Environment/Editor/MatchingBraceHighlighting/Position/@EntryValue">BOTH_SIDES</s:String>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Environment/OpenDocument/OpenDocumentAfterModification/@EntryValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Environment/SearchAndNavigation/AutoExpandResults/@EntryValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Environment/SearchAndNavigation/MergeOccurences/@EntryValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Environment/SearchAndNavigation/OpenPreviewTabForSelectedItemInFindResults/@EntryValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpFileLayoutPatternsUpgrade/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsCodeFormatterSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsParsFormattingSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsWrapperSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EXml_002ECodeStyle_002EFormatSettingsUpgrade_002EXmlMoveToCommonFormatterSettingsUpgrade/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Environment/TextControl/HighlightCurrentLine/@EntryValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Environment/UnitTesting/MsTestProvider/UseTestRunConfigFromMetadataFile/@EntryValue">False</s:Boolean>
-	<s:Boolean x:Key="/Default/Environment/UpdatesManger/IsDownloadUpdateDataAllowed/@EntryValue">False</s:Boolean>
-	<s:String x:Key="/Default/Environment/UserInterface/ShortcutSchemeName/@EntryValue">VS</s:String>
-	<s:Boolean x:Key="/Default/Housekeeping/GlobalSettingsUpgraded/IsUpgraded/@EntryValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/IntellisenseHousekeeping/HintUsed/@EntryValue">True</s:Boolean>
-	<s:String x:Key="/Default/Housekeeping/Layout/DialogWindows/OptionsDialog/SelectedPageId/@EntryValue">CSharpBracesLayoutPage</s:String>
-	<s:String x:Key="/Default/Housekeeping/Layout/DialogWindows/RefactoringWizardWindow/Location/@EntryValue">247,0</s:String>
-	<s:Boolean x:Key="/Default/Housekeeping/LiveTemplatesHousekeeping/HotspotSessionHintIsShown/@EntryValue">True</s:Boolean>
-	<s:Int64 x:Key="/Default/Housekeeping/TreeModelBrowserPanelPersistance/PreviewSplitterHorizontalPosition/=SearchUsagesDescriptor/@EntryIndexedValue">269</s:Int64>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=AnalyzeReferences/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=BlockComment/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EBookmarksMenu/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EGoToBookmark0/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EGoToBookmark1/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EGoToBookmark2/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EGoToBookmark3/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EGoToBookmark4/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EGoToBookmark5/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EGoToBookmark6/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EGoToBookmark7/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EGoToBookmark8/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EGoToBookmark9/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EToggleBookmark0/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EToggleBookmark1/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EToggleBookmark2/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EToggleBookmark3/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EToggleBookmark4/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EToggleBookmark5/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EToggleBookmark6/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EToggleBookmark7/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EToggleBookmark8/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Bookmarks_002EToggleBookmark9/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ChangeSignature/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=CleanupCode/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=CompleteCodeSmart/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=CompleteCodeTypeName/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=DuplicateText/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=EnableDaemon/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=EncapsulateField/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ExploreStackTrace/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ExtendSelection/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ExtractMethod/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=FindUsagesAdvanced/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ForceCompleteItem/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Generate/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GenerateFileBesides/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoBase/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoContainingDeclaration/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoFile/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoFileMember/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoInheritors/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoLastEditLocation/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoNextErrorInSolution/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoNextHighlight/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoNextMethod/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoNextOccurence/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoPrevErrorInSolution/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoPrevHighlight/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoPreviousOccurence/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoPrevMethod/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoRecentEdits/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoRecentFiles/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoRelatedFiles/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoSymbol/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoType/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoTypeDeclaration/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=GotoUsage/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=HighlightUsages/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=InlineVariable/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=InspectThis/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=IntroduceField/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=IntroduceVariable/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=IntroParameter/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=LineComment/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=LiveTemplates_002EInsert/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=LocateInSolutionExplorerAction/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Move/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=MoveDown/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=MoveLeft/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=MoveRight/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=MoveUp/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=NavigateTo/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ParameterInfo_002EGoToPreviousSignature/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=QuickDoc/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=QuickFix/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=RefactorThis/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=Rename/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ReSharper_005FUnitTest_005FDebugContext/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ReSharper_005FUnitTest_005FRunContext/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=SafeDelete/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=SelectContainingDeclaration/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ShowAnalyzeReferences/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ShowCodeStructure/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ShowFindResults/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ShowHierarchyWindow/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ShowInspectionWindow/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ShowTodoExplorer/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ShowUnitTestExplorer/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ShowUnitTestSessions/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=ShrinkSelection/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=SilentCleanupCode/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=SurroundWith/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=TypeHierarchy_002EBrowse/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=UnitTest_002ERunCurrentSession/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=UnitTest_002ERunSolution/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=UnitTestSession_002ERepeatPreviousRun/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=WindowManager_002EActivateRecentTool/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ActionsWithShortcuts/=WindowManager_002ECloseRecentTool/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=AnalyzeReferences/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=AnalyzeReferences/Shortcuts/=Control_002BAlt_002BY/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark1/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark1/Shortcuts/=Control_002BD1/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark2/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark2/Shortcuts/=Control_002BD2/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark3/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark3/Shortcuts/=Control_002BD3/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark4/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark4/Shortcuts/=Control_002BD4/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark5/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark5/Shortcuts/=Control_002BD5/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark6/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark6/Shortcuts/=Control_002BD6/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark7/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark7/Shortcuts/=Control_002BD7/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark8/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark8/Shortcuts/=Control_002BD8/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark9/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EGoToBookmark9/Shortcuts/=Control_002BD9/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EToggleBookmark1/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EToggleBookmark1/Shortcuts/=Shift_002BControl_002BD1/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EToggleBookmark2/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EToggleBookmark2/Shortcuts/=Shift_002BControl_002BD2/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EToggleBookmark3/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EToggleBookmark3/Shortcuts/=Shift_002BControl_002BD3/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EToggleBookmark7/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EToggleBookmark7/Shortcuts/=Shift_002BControl_002BD7/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EToggleBookmark8/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Bookmarks_002EToggleBookmark8/Shortcuts/=Shift_002BControl_002BD8/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ChangeSignature/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ChangeSignature/Shortcuts/=Control_002BR_0020Control_002BS/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ChangeSignature/Shortcuts/=Control_002BR_0020S/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=CleanupCode/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=CleanupCode/Shortcuts/=Control_002BE_0020C/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=CleanupCode/Shortcuts/=Control_002BE_0020Control_002BC/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=CompleteCodeSmart/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=CompleteCodeSmart/Shortcuts/=Control_002BAlt_002BSpace/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=DuplicateText/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=DuplicateText/Shortcuts/=Control_002BD/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=EncapsulateField/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=EncapsulateField/Shortcuts/=Control_002BR_0020Control_002BE/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=EncapsulateField/Shortcuts/=Control_002BR_0020E/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ExploreStackTrace/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ExploreStackTrace/Shortcuts/=Control_002BE_0020Control_002BT/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ExploreStackTrace/Shortcuts/=Control_002BE_0020T/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ExtendSelection/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ExtendSelection/Shortcuts/=Control_002BAlt_002BRight/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ExtractMethod/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ExtractMethod/Shortcuts/=Control_002BR_0020Control_002BM/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ExtractMethod/Shortcuts/=Control_002BR_0020M/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=FindUsagesAdvanced/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=FindUsagesAdvanced/Shortcuts/=Shift_002BControl_002BAlt_002BF12/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GenerateFileBesides/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GenerateFileBesides/Shortcuts/=Control_002BAlt_002BInsert/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoContainingDeclaration/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoContainingDeclaration/Shortcuts/=Control_002BOemOpenBrackets/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoFile/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoFile/Shortcuts/=Shift_002BControl_002BT/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoNextHighlight/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoNextHighlight/Shortcuts/=Alt_002BNext/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoNextMethod/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoNextMethod/Shortcuts/=Alt_002BDown/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoNextOccurence/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoNextOccurence/Shortcuts/=Control_002BAlt_002BNext/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoPrevHighlight/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoPrevHighlight/Shortcuts/=Alt_002BPageUp/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoPreviousOccurence/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoPreviousOccurence/Shortcuts/=Control_002BAlt_002BPageUp/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoPrevMethod/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoPrevMethod/Shortcuts/=Alt_002BUp/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoRecentEdits/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoRecentEdits/Shortcuts/=Shift_002BControl_002BOemcomma/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoRecentFiles/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoRecentFiles/Shortcuts/=Control_002BOemcomma/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoSymbol/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoSymbol/Shortcuts/=Shift_002BAlt_002BT/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoType/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoType/Shortcuts/=Control_002BT/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoTypeDeclaration/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoTypeDeclaration/Shortcuts/=Shift_002BControl_002BF11/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoUsage/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=GotoUsage/Shortcuts/=Shift_002BAlt_002BF12/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=HighlightUsages/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=HighlightUsages/Shortcuts/=Shift_002BAlt_002BF11/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=InlineVariable/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=InlineVariable/Shortcuts/=Control_002BR_0020Control_002BI/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=InlineVariable/Shortcuts/=Control_002BR_0020I/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=IntroduceField/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=IntroduceField/Shortcuts/=Control_002BR_0020Control_002BF/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=IntroduceField/Shortcuts/=Control_002BR_0020F/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=IntroduceVariable/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=IntroduceVariable/Shortcuts/=Control_002BR_0020Control_002BV/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=IntroduceVariable/Shortcuts/=Control_002BR_0020V/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=IntroParameter/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=IntroParameter/Shortcuts/=Control_002BR_0020Control_002BP/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=IntroParameter/Shortcuts/=Control_002BR_0020P/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=LocateInSolutionExplorerAction/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=LocateInSolutionExplorerAction/Shortcuts/=Shift_002BAlt_002BL/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Move/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Move/Shortcuts/=Control_002BR_0020Control_002BO/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Move/Shortcuts/=Control_002BR_0020O/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=MoveDown/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=MoveDown/Shortcuts/=Shift_002BControl_002BAlt_002BDown/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=MoveLeft/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=MoveLeft/Shortcuts/=Shift_002BControl_002BAlt_002BLeft/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=MoveRight/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=MoveRight/Shortcuts/=Shift_002BControl_002BAlt_002BRight/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=MoveUp/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=MoveUp/Shortcuts/=Shift_002BControl_002BAlt_002BUp/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=QuickFix/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=QuickFix/Shortcuts/=Alt_002BReturn/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=RefactorThis/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=RefactorThis/Shortcuts/=Shift_002BControl_002BR/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Rename/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Rename/Shortcuts/=Control_002BR_0020Control_002BR/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=Rename/Shortcuts/=Control_002BR_0020R/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ReSharper_005FUnitTest_005FDebugContext/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ReSharper_005FUnitTest_005FDebugContext/Shortcuts/=Control_002BU_0020Control_002BD/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ReSharper_005FUnitTest_005FDebugContext/Shortcuts/=Control_002BU_0020D/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ReSharper_005FUnitTest_005FRunContext/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ReSharper_005FUnitTest_005FRunContext/Shortcuts/=Control_002BU_0020Control_002BR/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ReSharper_005FUnitTest_005FRunContext/Shortcuts/=Control_002BU_0020R/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=SafeDelete/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=SafeDelete/Shortcuts/=Control_002BR_0020Control_002BD/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=SafeDelete/Shortcuts/=Control_002BR_0020D/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=SelectContainingDeclaration/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=SelectContainingDeclaration/Shortcuts/=Shift_002BControl_002BOemOpenBrackets/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowAnalyzeReferences/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowAnalyzeReferences/Shortcuts/=Control_002BAlt_002BY/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowCodeStructure/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowCodeStructure/Shortcuts/=Control_002BAlt_002BF/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowFindResults/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowFindResults/Shortcuts/=Control_002BAlt_002BF12/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowHierarchyWindow/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowHierarchyWindow/Shortcuts/=Control_002BAlt_002BH/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowInspectionWindow/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowInspectionWindow/Shortcuts/=Control_002BAlt_002BV/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowTodoExplorer/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowTodoExplorer/Shortcuts/=Control_002BAlt_002BD/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowUnitTestExplorer/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowUnitTestExplorer/Shortcuts/=Control_002BAlt_002BU/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowUnitTestSessions/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShowUnitTestSessions/Shortcuts/=Control_002BAlt_002BT/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShrinkSelection/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=ShrinkSelection/Shortcuts/=Control_002BAlt_002BLeft/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=SilentCleanupCode/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=SilentCleanupCode/Shortcuts/=Control_002BE_0020Control_002BF/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=SilentCleanupCode/Shortcuts/=Control_002BE_0020F/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=SurroundWith/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=SurroundWith/Shortcuts/=Control_002BE_0020Control_002BU/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=SurroundWith/Shortcuts/=Control_002BE_0020U/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=UnitTest_002ERunCurrentSession/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=UnitTest_002ERunCurrentSession/Shortcuts/=Control_002BU_0020Control_002BY/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=UnitTest_002ERunCurrentSession/Shortcuts/=Control_002BU_0020Y/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=UnitTest_002ERunSolution/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=UnitTest_002ERunSolution/Shortcuts/=Control_002BU_0020Control_002BL/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=UnitTest_002ERunSolution/Shortcuts/=Control_002BU_0020L/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=UnitTestSession_002ERepeatPreviousRun/@KeyIndexDefined">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=UnitTestSession_002ERepeatPreviousRun/Shortcuts/=Control_002BU_0020Control_002BU/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/ConflictingActions/=UnitTestSession_002ERepeatPreviousRun/Shortcuts/=Control_002BU_0020U/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Add/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BBack/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BDown/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BF/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BF10/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BF11/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BF12/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BF2/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BF3/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BF4/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BF5/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BF6/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BF7/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BF8/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BF9/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BG/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BLeft/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BM/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BMultiply/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BNext/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BO/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BOem7/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BOemcomma/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BOemPeriod/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BP/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BPageUp/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BPause/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BR/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BReturn/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BRight/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BS/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BSubtract/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BUp/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Alt_002BW/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=B/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Back/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BA/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAdd/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BA/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BB/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BC/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BD/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BDown/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BE/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BF/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BF1/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BF10/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BF11/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BF12/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BF5/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BF6/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BG/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BH/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BI/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BInsert/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BJ/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BL/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BLeft/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BM/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BNext/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BO/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BOem6/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BOemPeriod/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BP/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BPageUp/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BPause/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BQ/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BR/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BRight/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BS/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BSpace/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BT/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BU/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BUp/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BV/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BW/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BX/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BY/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BAlt_002BZ/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BB/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BBack/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BC/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BD/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BD1/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BD2/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BD3/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BD4/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BD5/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BD6/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BD7/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BD8/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BD9/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BDelete/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BDivide/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BDown/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BE/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BEnd/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BF/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BF1/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BF10/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BF11/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BF12/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BF2/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BF4/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BF5/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BF6/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BF7/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BF9/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BG/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BH/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BHome/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BI/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BInsert/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BJ/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BK/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BL/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BLeft/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BM/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BN/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BNext/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BO/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BOem1/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BOem6/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BOem7/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BOemBackslash/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BOemcomma/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BOemOpenBrackets/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BOemPeriod/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BOemplus/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BP/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BPageUp/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BPause/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BQ/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BR/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BReturn/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BRight/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BS/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BSpace/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BSubtract/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BT/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BTab/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BU/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BUp/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BV/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BW/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BX/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BY/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Control_002BZ/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Delete/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Down/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=End/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Escape/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=F1/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=F10/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=F11/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=F12/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=F2/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=F4/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=F5/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=F6/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=F7/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=F8/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=F9/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Home/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=I/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Insert/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Left/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Next/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=O/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=PageUp/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Return/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Right/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BA/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BB/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BBack/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BC/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BD/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BD3/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BD4/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BDown/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BEnd/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BF/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BF10/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BF11/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BF12/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BF6/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BF7/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BH/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BHome/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BL/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BLeft/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BN/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BOemcomma/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BOemPeriod/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BP/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BQ/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BR/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BReturn/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BRight/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BS/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BT/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BUp/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BV/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BAlt_002BW/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BBack/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BA/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BAlt_002BC/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BAlt_002BDown/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BAlt_002BF11/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BAlt_002BF12/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BAlt_002BLeft/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BAlt_002BP/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BAlt_002BR/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BAlt_002BRight/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BAlt_002BS/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BAlt_002BUp/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BAlt_002BW/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BB/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BC/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BD/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BD1/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BD2/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BD3/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BD7/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BD8/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BDown/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BE/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BEnd/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BF10/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BF11/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BF12/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BF5/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BF6/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BF9/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BG/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BH/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BHome/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BI/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BInsert/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BJ/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BL/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BLeft/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BM/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BN/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BNext/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BO/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BOem6/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BOemcomma/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BOemOpenBrackets/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BOemPeriod/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BP/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BPageUp/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BR/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BReturn/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BRight/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BS/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BSpace/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BSubtract/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BT/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BTab/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BU/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BUp/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BV/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BW/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BX/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BY/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BControl_002BZ/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BDelete/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BDown/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BEnd/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BEscape/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BF1/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BF11/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BF12/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BF4/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BF5/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BF6/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BF7/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BF8/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BF9/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BHome/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BInsert/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BLeft/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BNext/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BPageUp/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BReturn/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BRight/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BSpace/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BTab/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Shift_002BUp/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Subtract/@KeyIndexDefined">True</s:Boolean>
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Tab/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Up/@KeyIndexDefined">True</s:Boolean>
-	
-	
-	</wpf:ResourceDictionary>

+ 0 - 3
Server/Server.sln.DotSettings.user

@@ -1,3 +0,0 @@
-<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
-	<s:Int64 x:Key="/Default/Environment/SearchAndNavigation/DefaultOccurrencesGroupingIndex/@EntryValue">0</s:Int64>
-	<s:String x:Key="/Default/Housekeeping/Layout/DialogWindows/OptionsDialog/SelectedPageId/@EntryValue">EnhancedTooltip.OptionsPage</s:String></wpf:ResourceDictionary>

+ 11 - 9
Server/ThirdParty/ENet/ENet.vcxproj

@@ -24,7 +24,7 @@
     <Keyword>ManagedCProj</Keyword>
     <RootNamespace>ENet</RootNamespace>
     <ProjectName>ENet</ProjectName>
-    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion>7.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -44,14 +44,14 @@
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v141_xp</PlatformToolset>
     <CLRSupport>false</CLRSupport>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
-    <PlatformToolset>v141</PlatformToolset>
+    <PlatformToolset>v141_xp</PlatformToolset>
     <CLRSupport>false</CLRSupport>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
@@ -74,8 +74,8 @@
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <LinkIncremental>true</LinkIncremental>
     <IncludePath>$(SolutionDir)\Platform\;$(IncludePath)</IncludePath>
-    <OutDir>$(SolutionDir)..\Bin\</OutDir>
-    <IntDir>$(SolutionDir)..\Temp\</IntDir>
+    <OutDir>$(ProjectDir)..\..\..\netcoreapp2.0</OutDir>
+    <IntDir>$(ProjectDir)..\..\..\Temp</IntDir>
     <TargetExt>.dll</TargetExt>
     <TargetName>$(ProjectName)</TargetName>
   </PropertyGroup>
@@ -84,16 +84,18 @@
     <TargetName>$(ProjectName)</TargetName>
     <LinkIncremental>true</LinkIncremental>
     <IncludePath>$(SolutionDir)\Platform\;$(IncludePath)</IncludePath>
-    <OutDir>$(SolutionDir)..\Bin\</OutDir>
-    <IntDir>$(SolutionDir)..\Temp\</IntDir>
+    <OutDir>$(ProjectDir)..\..\..\netcoreapp2.0</OutDir>
+    <IntDir>$(ProjectDir)..\..\..\Temp\</IntDir>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <LinkIncremental>false</LinkIncremental>
-    <OutDir>$(SolutionDir)\Bin\Release\</OutDir>
-    <IntDir>$(SolutionDir)\Temp\Release\</IntDir>
+    <OutDir>$(ProjectDir)..\..\..\netcoreapp2.0</OutDir>
+    <IntDir>$(ProjectDir)..\..\..\Temp</IntDir>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
     <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(ProjectDir)..\..\..\netcoreapp2.0</OutDir>
+    <IntDir>$(ProjectDir)..\..\..\Temp</IntDir>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>

BIN=BIN
Server/ThirdParty/MongodbDriver/DotNetCoreDriver/.vs/DotNetCoreDriver/v15/sqlite3/storage.ide


BIN=BIN
Server/ThirdParty/MongodbDriver/DotNetCoreDriver/.vs/DotNetCoreDriver/v15/sqlite3/storage.ide-journal


+ 37 - 0
Server/ThirdParty/MongodbDriver/DotNetCoreDriver/DotNetCoreDriver.sln

@@ -0,0 +1,37 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.26730.12
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoDB.Bson", "MongoDB.Bson\MongoDB.Bson.csproj", "{4F9A224A-2032-46AD-8B72-A206D5241DAA}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Driver.Core", "MongoDB.Driver.Core\MongoDB.Driver.Core.csproj", "{B9B4FF03-4B5D-45EF-89D4-A492FC552908}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Driver", "MongoDB.Driver\MongoDB.Driver.csproj", "{0CD3811C-FD10-42BE-9285-F01393029272}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{4F9A224A-2032-46AD-8B72-A206D5241DAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{4F9A224A-2032-46AD-8B72-A206D5241DAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{4F9A224A-2032-46AD-8B72-A206D5241DAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{4F9A224A-2032-46AD-8B72-A206D5241DAA}.Release|Any CPU.Build.0 = Release|Any CPU
+		{B9B4FF03-4B5D-45EF-89D4-A492FC552908}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{B9B4FF03-4B5D-45EF-89D4-A492FC552908}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{B9B4FF03-4B5D-45EF-89D4-A492FC552908}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{B9B4FF03-4B5D-45EF-89D4-A492FC552908}.Release|Any CPU.Build.0 = Release|Any CPU
+		{0CD3811C-FD10-42BE-9285-F01393029272}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{0CD3811C-FD10-42BE-9285-F01393029272}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{0CD3811C-FD10-42BE-9285-F01393029272}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{0CD3811C-FD10-42BE-9285-F01393029272}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {F94F8D2C-01B3-46C5-B881-BA78F1395239}
+	EndGlobalSection
+EndGlobal

+ 23 - 0
Server/ThirdParty/MongodbDriver/DotNetCoreDriver/MongoDB.Bson/MongoDB.Bson.csproj

@@ -0,0 +1,23 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>netstandard2.0</TargetFramework>
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
+    <OutputPath>..\..\..\..\..\netcoreapp2.0\</OutputPath>
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+    <OutputPath>..\..\..\..\..\netcoreapp2.0\</OutputPath>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <Compile Include="..\..\MongoDB.Bson\**\*.cs;..\..\MongoDB.Shared\Hasher.cs" Exclude="..\..\MongoDB.Bson\Properties\**;..\..\MongoDB.Bson\obj\**;bin\**;obj\**;**\*.xproj;packages\**" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
+  </ItemGroup>
+
+</Project>

+ 22 - 0
Server/ThirdParty/MongodbDriver/DotNetCoreDriver/MongoDB.Driver.Core/MongoDB.Driver.Core.csproj

@@ -0,0 +1,22 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>netstandard2.0</TargetFramework>
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
+    <OutputPath>..\..\..\..\..\netcoreapp2.0\</OutputPath>
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+    <OutputPath>..\..\..\..\..\netcoreapp2.0\</OutputPath>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <Compile Include="..\..\MongoDB.Driver.Core\**\*.cs;..\..\MongoDB.Shared\ApplicationNameHelper.cs;..\..\MongoDB.Shared\Hasher.cs" Exclude="..\..\MongoDB.Driver.Core\Properties\**;..\..\MongoDB.Driver.Core\obj\**;bin\**;obj\**;**\*.xproj;packages\**" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\MongoDB.Bson\MongoDB.Bson.csproj" />
+  </ItemGroup>
+</Project>

+ 23 - 0
Server/ThirdParty/MongodbDriver/DotNetCoreDriver/MongoDB.Driver/MongoDB.Driver.csproj

@@ -0,0 +1,23 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>netstandard2.0</TargetFramework>
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
+    <OutputPath>..\..\..\..\..\netcoreapp2.0\</OutputPath>
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+    <OutputPath>..\..\..\..\..\netcoreapp2.0\</OutputPath>
+  </PropertyGroup>
+  
+  <ItemGroup>
+    <Compile Include="..\..\MongoDB.Driver\**\*.cs;..\..\MongoDB.Shared\ApplicationNameHelper.cs;..\..\MongoDB.Shared\Hasher.cs" Exclude="..\..\MongoDB.Driver\Properties\**;..\..\MongoDB.Driver\obj\**;bin\**;obj\**;**\*.xproj;packages\**" />
+  </ItemGroup>
+  
+  <ItemGroup>
+    <ProjectReference Include="..\MongoDB.Bson\MongoDB.Bson.csproj" />
+    <ProjectReference Include="..\MongoDB.Driver.Core\MongoDB.Driver.Core.csproj" />
+  </ItemGroup>
+</Project>

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

@@ -0,0 +1,61 @@
+/* Copyright 2010-2014 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; } }
+    }
+}

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

@@ -0,0 +1,105 @@
+/* Copyright 2010-2014 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; }
+        }
+    }
+}

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

@@ -0,0 +1,246 @@
+/* Copyright 2010-2014 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();
+            }
+        }
+    }
+}

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

@@ -0,0 +1,265 @@
+/* Copyright 2010-2017 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;
+        }
+    }
+}

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

@@ -0,0 +1,81 @@
+/* Copyright 2010-2016 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 NET45
+using System.Runtime.Serialization;
+#endif
+
+namespace MongoDB.Bson
+{
+    /// <summary>
+    /// Represents a BSON exception.
+    /// </summary>
+#if NET45
+    [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 NET45
+        /// <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
+    }
+}

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

@@ -0,0 +1,71 @@
+/* Copyright 2010-2016 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 NET45
+using System.Runtime.Serialization;
+#endif
+
+namespace MongoDB.Bson
+{
+    /// <summary>
+    /// Represents a BSON internal exception (almost surely the result of a bug).
+    /// </summary>
+#if NET45
+    [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 NET45
+        /// <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
+    }
+}

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

@@ -0,0 +1,71 @@
+/* Copyright 2010-2016 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 NET45
+using System.Runtime.Serialization;
+#endif
+
+namespace MongoDB.Bson
+{
+    /// <summary>
+    /// Represents a BSON serialization exception.
+    /// </summary>
+#if NET45
+    [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 NET45
+        /// <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
+    }
+}

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

@@ -0,0 +1,62 @@
+/* Copyright 2010-2016 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 NET45
+    [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 NET45
+        /// <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
+    }
+}

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

@@ -0,0 +1,71 @@
+/* Copyright 2010-2016 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 NET45
+using System.Runtime.Serialization;
+#endif
+
+namespace MongoDB.Bson
+{
+    /// <summary>
+    /// Represents a truncation exception.
+    /// </summary>
+#if NET45
+    [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 NET45
+        /// <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
+    }
+}

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

@@ -0,0 +1,125 @@
+/* Copyright 2010-2016 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);
+        }
+    }
+}

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

@@ -0,0 +1,825 @@
+/* Copyright 2010-2017 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;
+        }
+    }
+}

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

@@ -0,0 +1,52 @@
+/* Copyright 2010-2014 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();
+        }
+    }
+}

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

@@ -0,0 +1,87 @@
+/* Copyright 2010-2016 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;
+        }
+    }
+}

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

@@ -0,0 +1,148 @@
+/* Copyright 2010-2016 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 NET45
+    [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;
+        }
+    }
+}

+ 763 - 0
Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonBinaryWriter.cs

@@ -0,0 +1,763 @@
+/* Copyright 2010-2016 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 readonly BsonBinaryWriterSettings _settings; // same value as in base class just declared as derived class
+        private readonly Stack<int> _maxDocumentSizeStack = new Stack<int>();
+        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);
+            _settings = settings; // already frozen by base class
+            _maxDocumentSizeStack.Push(_settings.MaxDocumentSize);
+
+            _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; }
+        }
+
+        // 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>
+        public void PopMaxDocumentSize()
+        {
+            _maxDocumentSizeStack.Pop();
+        }
+
+        /// <summary>
+        /// Pushes a new max document size onto the max document size stack.
+        /// </summary>
+        /// <param name="maxDocumentSize">The maximum size of the document.</param>
+        public void PushMaxDocumentSize(int maxDocumentSize)
+        {
+            _maxDocumentSizeStack.Push(Math.Min(maxDocumentSize, _maxDocumentSizeStack.Peek()));
+        }
+
+#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 > _maxDocumentSizeStack.Peek())
+            {
+                var message = string.Format("Size {0} is larger than MaxDocumentSize {1}.", size, _maxDocumentSizeStack.Peek());
+                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);
+            }
+        }
+    }
+}

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

@@ -0,0 +1,59 @@
+/* Copyright 2010-2014 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; }
+        }
+    }
+}

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

@@ -0,0 +1,134 @@
+/* Copyright 2010-2016 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 NET45
+    [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;
+        }
+    }
+}

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

@@ -0,0 +1,259 @@
+/* Copyright 2010-2015 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);
+            }
+        }
+    }
+}

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

@@ -0,0 +1,562 @@
+/* Copyright 2010-2016 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.");
+            }
+        }
+    }
+}

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

@@ -0,0 +1,52 @@
+/* Copyright 2010-2014 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();
+        }
+    }
+}

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

@@ -0,0 +1,128 @@
+/* Copyright 2010-2014 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;
+        }
+    }
+}

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

@@ -0,0 +1,90 @@
+/* Copyright 2010-2016 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 NET45
+    [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;
+        }
+    }
+}

+ 548 - 0
Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonDocumentWriter.cs

@@ -0,0 +1,548 @@
+/* Copyright 2010-2016 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; }
+        }
+
+        // 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);
+            }
+        }
+    }
+}

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

@@ -0,0 +1,91 @@
+/* Copyright 2010-2014 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; }
+        }
+    }
+}

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

@@ -0,0 +1,91 @@
+/* Copyright 2010-2016 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 NET45
+    [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;
+        }
+    }
+}

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

@@ -0,0 +1,440 @@
+/* Copyright 2010-2016 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
+                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);
+            }
+        }
+    }
+}

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

@@ -0,0 +1,67 @@
+/* Copyright 2010-2014 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; }
+        }
+    }
+}

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

@@ -0,0 +1,123 @@
+/* Copyright 2010-2016 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 NET45
+    [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);
+        }
+    }
+}

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

@@ -0,0 +1,60 @@
+/* Copyright 2010-2014 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
+    }
+}

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

@@ -0,0 +1,140 @@
+/* Copyright 2010-2016 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);
+    }
+}

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

@@ -0,0 +1,567 @@
+/* Copyright 2010-2016 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 NET45
+        /// <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 NET45
+        /// <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 NET45
+        /// <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 NET45
+        /// <inheritdoc/>
+        public override int EndRead(IAsyncResult asyncResult)
+        {
+            ThrowIfDisposed();
+            return _stream.EndRead(asyncResult);
+        }
+#endif
+
+#if NET45
+        /// <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
+                    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);
+        }
+    }
+}

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

@@ -0,0 +1,315 @@
+/* Copyright 2010-2016 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;
+            }
+        }
+    }
+}

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

@@ -0,0 +1,354 @@
+/* Copyright 2010-2015 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;
+        }
+    }
+}

+ 453 - 0
Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/BsonWriter.cs

@@ -0,0 +1,453 @@
+/* Copyright 2010-2016 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 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
+        /// <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;
+        }
+
+        /// <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;
+        }
+
+        /// <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);
+        }
+    }
+}

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

@@ -0,0 +1,137 @@
+/* Copyright 2010-2016 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 NET45
+    [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);
+        }
+    }
+}

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

@@ -0,0 +1,48 @@
+/* Copyright 2010-2014 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
+    }
+}

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

@@ -0,0 +1,294 @@
+/* Copyright 2010-2015 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);
+            }
+        }
+    }
+}

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

@@ -0,0 +1,111 @@
+/* Copyright 2013-2015 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);
+            }
+        }
+    }
+}

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

@@ -0,0 +1,75 @@
+/* Copyright 2010-2015 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);
+            }
+        }
+    }
+}

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

@@ -0,0 +1,235 @@
+/* Copyright 2010-2015 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);
+            }
+        }
+    }
+}

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

@@ -0,0 +1,727 @@
+/* Copyright 2010-2016 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);
+        }
+    }
+}

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

@@ -0,0 +1,76 @@
+/* Copyright 2016 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;
+        }
+    }
+}

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

@@ -0,0 +1,44 @@
+/* Copyright 2010-2014 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
+    }
+}

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

@@ -0,0 +1,39 @@
+/* Copyright 2010-2015 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();
+    }
+}

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

@@ -0,0 +1,33 @@
+/* Copyright 2010-2015 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);
+    }
+}

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

@@ -0,0 +1,235 @@
+/* Copyright 2010-2016 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();
+    }
+}

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

@@ -0,0 +1,361 @@
+/* Copyright 2010-2016 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);
+            }
+        }
+    }
+}

+ 213 - 0
Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/IBsonWriter.cs

@@ -0,0 +1,213 @@
+/* Copyright 2010-2016 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>
+    public interface IBsonWriter : IDisposable
+    {
+        // properties
+        /// <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>
+        /// Pushes the element name validator.
+        /// </summary>
+        /// <param name="validator">The validator.</param>
+        void PushElementNameValidator(IElementNameValidator validator);
+
+        /// <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();
+    }
+}

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

@@ -0,0 +1,293 @@
+/* Copyright 2010-2016 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();
+        }
+    }
+}

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

@@ -0,0 +1,122 @@
+/* Copyright 2010-2015 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);
+    }
+}

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

@@ -0,0 +1,38 @@
+/* Copyright 2010-2014 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);
+    }
+}

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

@@ -0,0 +1,43 @@
+/* Copyright 2010-2015 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);
+    }
+}

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

@@ -0,0 +1,174 @@
+/* Copyright 2013-2015 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);
+            }
+        }
+    }
+}

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

@@ -0,0 +1,204 @@
+/* Copyright 2010-2014 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);
+                    }
+                }
+            }
+        }
+    }
+}

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

@@ -0,0 +1,299 @@
+/* Copyright 2010-2016 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);
+        }
+    }
+}

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

@@ -0,0 +1,47 @@
+/* Copyright 2010-2014 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
+    }
+}

+ 1866 - 0
Server/ThirdParty/MongodbDriver/MongoDB.Bson/IO/JsonReader.cs

@@ -0,0 +1,1866 @@
+/* Copyright 2010-2016 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 "$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 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()
+        {
+            VerifyString("t");
+            VerifyToken(":");
+            var secondsSinceEpochToken = PopToken();
+            int secondsSinceEpoch;
+            if (secondsSinceEpochToken.IsNumber)
+            {
+                secondsSinceEpoch = secondsSinceEpochToken.Int32Value;
+            }
+            else
+            {
+                var message = string.Format("JSON reader expected an integer but found '{0}'.", secondsSinceEpochToken.Lexeme);
+                throw new FormatException(message);
+            }
+            VerifyToken(",");
+            VerifyString("i");
+            VerifyToken(":");
+            var incrementToken = PopToken();
+            int increment;
+            if (incrementToken.IsNumber)
+            {
+                increment = incrementToken.Int32Value;
+            }
+            else
+            {
+                var message = string.Format("JSON reader expected an integer but found '{0}'.", incrementToken.Lexeme);
+                throw new FormatException(message);
+            }
+            VerifyToken("}");
+            VerifyToken("}");
+            return new BsonTimestamp(secondsSinceEpoch, increment);
+        }
+
+        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);
+            }
+        }
+    }
+}

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

@@ -0,0 +1,76 @@
+/* Copyright 2010-2014 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();
+        }
+    }
+}

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio