Skip to content

Commit 6323f0b

Browse files
committed
CSHARP-1565: Build and test MongoDB.Driver.GridFS against .NET Core
1 parent 188e2c8 commit 6323f0b

28 files changed

+2162
-27
lines changed

CSharpDriver.Dotnet.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MongoDB.Driver.Legacy.TestH
3636
EndProject
3737
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MongoDB.Driver.Legacy.Tests.Dotnet", "tests\MongoDB.Driver.Legacy.Tests.Dotnet\MongoDB.Driver.Legacy.Tests.Dotnet.xproj", "{7586E8E3-687B-4064-B862-DCD307267B65}"
3838
EndProject
39+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MongoDB.Driver.GridFS.Dotnet", "src\MongoDB.Driver.GridFS.Dotnet\MongoDB.Driver.GridFS.Dotnet.xproj", "{0A36CE36-4E10-4CD7-924F-86EE07962AA0}"
40+
EndProject
41+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MongoDB.Driver.GridFS.Tests.Dotnet", "tests\MongoDB.Driver.GridFS.Tests.Dotnet\MongoDB.Driver.GridFS.Tests.Dotnet.xproj", "{7E266FA4-DD26-4462-A4A6-FD50BA4CCF4C}"
42+
EndProject
3943
Global
4044
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4145
Debug|Any CPU = Debug|Any CPU
@@ -90,6 +94,14 @@ Global
9094
{7586E8E3-687B-4064-B862-DCD307267B65}.Debug|Any CPU.Build.0 = Debug|Any CPU
9195
{7586E8E3-687B-4064-B862-DCD307267B65}.Release|Any CPU.ActiveCfg = Release|Any CPU
9296
{7586E8E3-687B-4064-B862-DCD307267B65}.Release|Any CPU.Build.0 = Release|Any CPU
97+
{0A36CE36-4E10-4CD7-924F-86EE07962AA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
98+
{0A36CE36-4E10-4CD7-924F-86EE07962AA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
99+
{0A36CE36-4E10-4CD7-924F-86EE07962AA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
100+
{0A36CE36-4E10-4CD7-924F-86EE07962AA0}.Release|Any CPU.Build.0 = Release|Any CPU
101+
{7E266FA4-DD26-4462-A4A6-FD50BA4CCF4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
102+
{7E266FA4-DD26-4462-A4A6-FD50BA4CCF4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
103+
{7E266FA4-DD26-4462-A4A6-FD50BA4CCF4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
104+
{7E266FA4-DD26-4462-A4A6-FD50BA4CCF4C}.Release|Any CPU.Build.0 = Release|Any CPU
93105
EndGlobalSection
94106
GlobalSection(SolutionProperties) = preSolution
95107
HideSolutionNode = FALSE
@@ -107,5 +119,7 @@ Global
107119
{0A996882-082C-449A-8530-6E6D4CD52BAA} = {CB619CDE-385F-4D7D-8601-A6482943975C}
108120
{7D946D76-6645-4F67-BCAB-198F78FC8B24} = {6D163A80-981C-491A-B519-465342D76568}
109121
{7586E8E3-687B-4064-B862-DCD307267B65} = {6D163A80-981C-491A-B519-465342D76568}
122+
{0A36CE36-4E10-4CD7-924F-86EE07962AA0} = {CB619CDE-385F-4D7D-8601-A6482943975C}
123+
{7E266FA4-DD26-4462-A4A6-FD50BA4CCF4C} = {6D163A80-981C-491A-B519-465342D76568}
110124
EndGlobalSection
111125
EndGlobal
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
8+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
9+
<PropertyGroup Label="Globals">
10+
<ProjectGuid>0a36ce36-4e10-4cd7-924f-86ee07962aa0</ProjectGuid>
11+
<RootNamespace>MongoDB.Driver.GridFS.Dotnet</RootNamespace>
12+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
13+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
14+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
15+
</PropertyGroup>
16+
17+
<PropertyGroup>
18+
<SchemaVersion>2.0</SchemaVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
21+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"version": "1.0.0-*",
3+
4+
"dependencies": {
5+
"MongoDB.Bson.Dotnet": "1.0.0-*",
6+
"MongoDB.Driver.Core.Dotnet": "1.0.0-*",
7+
"MongoDB.Driver.Dotnet": "1.0.0-*",
8+
"NETStandard.Library": "1.6.0"
9+
},
10+
11+
"frameworks": {
12+
"netstandard1.6": {
13+
"imports": "dnxcore50",
14+
"buildOptions": {
15+
"compile": {
16+
"include": [ "../MongoDB.Driver.GridFS/**/*.cs", "../MongoDB.Shared/IncrementalMD5.cs" ]
17+
},
18+
"define": [ "DEBUG", "TRACE", "NETSTANDARD16" ]
19+
}
20+
}
21+
}
22+
}

src/MongoDB.Driver.GridFS/DelegatingStream.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
using System;
1717
using System.IO;
18+
#if NET45
1819
using System.Runtime.Remoting;
20+
#endif
1921
using System.Threading;
2022
using System.Threading.Tasks;
2123

@@ -93,42 +95,52 @@ public override int WriteTimeout
9395
}
9496

9597
// methods
98+
#if NET45
9699
/// <inheritdoc/>
97100
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
98101
{
99102
return _wrappedStream.BeginRead(buffer, offset, count, callback, state);
100103
}
104+
#endif
101105

106+
#if NET45
102107
/// <inheritdoc/>
103108
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
104109
{
105110
return _wrappedStream.BeginWrite(buffer, offset, count, callback, state);
106111
}
112+
#endif
107113

114+
#if NET45
108115
/// <inheritdoc/>
109116
public override void Close()
110117
{
111118
_wrappedStream.Close();
112119
}
120+
#endif
113121

114122
/// <inheritdoc/>
115123
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
116124
{
117125
return _wrappedStream.CopyToAsync(destination, bufferSize, cancellationToken);
118126
}
119127

120-
/// <inheritdoc/>
128+
#if NET45
129+
/// <inheritdoc/>
121130
public override ObjRef CreateObjRef(Type requestedType)
122131
{
123132
return _wrappedStream.CreateObjRef(requestedType);
124133
}
134+
#endif
125135

136+
#if NET45
126137
/// <inheritdoc/>
127138
[Obsolete()]
128139
protected override WaitHandle CreateWaitHandle()
129140
{
130141
throw new NotSupportedException();
131142
}
143+
#endif
132144

133145
/// <inheritdoc/>
134146
protected override void Dispose(bool disposing)
@@ -139,17 +151,21 @@ protected override void Dispose(bool disposing)
139151
}
140152
}
141153

154+
#if NET45
142155
/// <inheritdoc/>
143156
public override int EndRead(IAsyncResult asyncResult)
144157
{
145158
return _wrappedStream.EndRead(asyncResult);
146159
}
160+
#endif
147161

162+
#if NET45
148163
/// <inheritdoc/>
149164
public override void EndWrite(IAsyncResult asyncResult)
150165
{
151166
_wrappedStream.EndWrite(asyncResult);
152167
}
168+
#endif
153169

154170
/// <inheritdoc/>
155171
public override bool Equals(object obj)
@@ -175,18 +191,22 @@ public override int GetHashCode()
175191
return _wrappedStream.GetHashCode();
176192
}
177193

178-
/// <inheritdoc/>
194+
#if NET45
195+
/// <inheritdoc/>
179196
public override object InitializeLifetimeService()
180197
{
181198
return _wrappedStream.InitializeLifetimeService();
182199
}
200+
#endif
183201

202+
#if NET45
184203
/// <inheritdoc/>
185204
[Obsolete()]
186205
protected override void ObjectInvariant()
187206
{
188207
throw new NotSupportedException();
189208
}
209+
#endif
190210

191211
/// <inheritdoc/>
192212
public override int Read(byte[] buffer, int offset, int count)

src/MongoDB.Driver.GridFS/GridFSChunkException.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
*/
1515

1616
using System;
17+
#if NET45
1718
using System.Runtime.Serialization;
19+
#endif
1820
using MongoDB.Bson;
1921
using MongoDB.Driver.Core.Misc;
2022

@@ -28,15 +30,15 @@ namespace MongoDB.Driver.GridFS
2830
#endif
2931
public class GridFSChunkException : GridFSException
3032
{
31-
#region static
33+
#region static
3234
private static string FormatMessage(BsonValue id, long n, string reason)
3335
{
3436
Ensure.IsNotNull(id, nameof(id));
3537
Ensure.IsGreaterThanOrEqualToZero(n, nameof(n));
3638
Ensure.IsNotNull(reason, nameof(reason));
3739
return string.Format("GridFS chunk {0} of file id {1} is {2}.", n, id, reason);
3840
}
39-
#endregion
41+
#endregion
4042

4143
// constructors
4244
/// <summary>

src/MongoDB.Driver.GridFS/GridFSDownloadStream.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16+
using System;
1617
using System.IO;
1718
using System.Threading;
1819
using System.Threading.Tasks;

src/MongoDB.Driver.GridFS/GridFSException.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
*/
1515

1616
using System;
17+
#if NET45
1718
using System.Runtime.Serialization;
19+
#endif
1820

1921
namespace MongoDB.Driver.GridFS
2022
{

src/MongoDB.Driver.GridFS/GridFSFileNotFoundException.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
*/
1515

1616
using System;
17+
#if NET45
1718
using System.Runtime.Serialization;
19+
#endif
1820
using MongoDB.Bson;
1921
using MongoDB.Driver.Core.Misc;
2022

@@ -28,7 +30,7 @@ namespace MongoDB.Driver.GridFS
2830
#endif
2931
public class GridFSFileNotFoundException : GridFSException
3032
{
31-
#region static
33+
#region static
3234
private static string FormatMessage(BsonValue id)
3335
{
3436
Ensure.IsNotNull(id, nameof(id));
@@ -40,7 +42,7 @@ private static string FormatMessage(string filename, int revision)
4042
Ensure.IsNotNull(filename, nameof(filename));
4143
return string.Format("GridFS file not found: revision {0} of filename \"{1}\".", revision, filename);
4244
}
43-
#endregion
45+
#endregion
4446

4547
// constructors
4648
/// <summary>

src/MongoDB.Driver.GridFS/GridFSForwardOnlyDownloadStream.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using MongoDB.Driver.Core.Bindings;
2727
using MongoDB.Driver.Core.Misc;
2828
using MongoDB.Driver.Core.Operations;
29+
using MongoDB.Shared;
2930

3031
namespace MongoDB.Driver.GridFS
3132
{
@@ -41,7 +42,7 @@ internal class GridFSForwardOnlyDownloadStream<TFileId> : GridFSDownloadStreamBa
4142
private readonly BsonValue _idAsBsonValue;
4243
private readonly int _lastChunkNumber;
4344
private readonly int _lastChunkSize;
44-
private readonly MD5 _md5;
45+
private readonly IncrementalMD5 _md5;
4546
private int _nextChunkNumber;
4647
private long _position;
4748

@@ -56,7 +57,7 @@ public GridFSForwardOnlyDownloadStream(
5657
_checkMD5 = checkMD5;
5758
if (_checkMD5)
5859
{
59-
_md5 = MD5.Create();
60+
_md5 = IncrementalMD5.Create();
6061
}
6162

6263
_lastChunkNumber = (int)((fileInfo.Length - 1) / fileInfo.ChunkSizeBytes);
@@ -197,8 +198,7 @@ private void CloseHelper()
197198

198199
if (_checkMD5 && _position == FileInfo.Length)
199200
{
200-
_md5.TransformFinalBlock(new byte[0], 0, 0);
201-
var md5 = BsonUtils.ToHexString(_md5.Hash);
201+
var md5 = BsonUtils.ToHexString(_md5.GetHashAndReset());
202202
if (!md5.Equals(FileInfo.MD5, StringComparison.OrdinalIgnoreCase))
203203
{
204204
#pragma warning disable 618
@@ -300,7 +300,7 @@ private void GetNextBatchFromCursor(bool hasMore)
300300

301301
if (_checkMD5)
302302
{
303-
_md5.TransformBlock(bytes, 0, bytes.Length, null, 0);
303+
_md5.AppendData(bytes, 0, bytes.Length);
304304
}
305305
}
306306
}

src/MongoDB.Driver.GridFS/GridFSForwardOnlyUploadStream.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using MongoDB.Bson.Serialization;
2424
using MongoDB.Driver.Core.Bindings;
2525
using MongoDB.Driver.Core.Operations;
26+
using MongoDB.Shared;
2627

2728
namespace MongoDB.Driver.GridFS
2829
{
@@ -49,7 +50,7 @@ internal class GridFSForwardOnlyUploadStream<TFileId> : GridFSUploadStream<TFile
4950
private readonly TFileId _id;
5051
private readonly BsonValue _idAsBsonValue;
5152
private long _length;
52-
private readonly MD5 _md5;
53+
private readonly IncrementalMD5 _md5;
5354
private readonly BsonDocument _metadata;
5455

5556
// constructors
@@ -75,7 +76,7 @@ public GridFSForwardOnlyUploadStream(
7576
_batchSize = batchSize;
7677

7778
_batch = new List<byte[]>();
78-
_md5 = MD5.Create();
79+
_md5 = IncrementalMD5.Create();
7980

8081
var idSerializer = bucket.Options.SerializerRegistry.GetSerializer<TFileId>();
8182
var idSerializationInfo = new BsonSerializationInfo("_id", idSerializer, typeof(TFileId));
@@ -271,7 +272,7 @@ private BsonDocument CreateFilesCollectionDocument()
271272
{ "length", _length },
272273
{ "chunkSize", _chunkSizeBytes },
273274
{ "uploadDate", uploadDateTime },
274-
{ "md5", BsonUtils.ToHexString(_md5.Hash) },
275+
{ "md5", BsonUtils.ToHexString(_md5.GetHashAndReset()) },
275276
{ "filename", _filename },
276277
{ "contentType", _contentType, _contentType != null },
277278
{ "aliases", () => new BsonArray(_aliases.Select(a => new BsonString(a))), _aliases != null },
@@ -296,7 +297,7 @@ private IEnumerable<BsonDocument> CreateWriteBatchChunkDocuments()
296297
chunkDocuments.Add(chunkDocument);
297298

298299
_batchPosition += chunk.Length;
299-
_md5.TransformBlock(chunk, 0, chunk.Length, null, 0);
300+
_md5.AppendData(chunk, 0, chunk.Length);
300301
}
301302

302303
return chunkDocuments;
@@ -460,7 +461,6 @@ private void WriteFinalBatch(CancellationToken cancellationToken)
460461
TruncateFinalChunk();
461462
WriteBatch(cancellationToken);
462463
}
463-
_md5.TransformFinalBlock(new byte[0], 0, 0);
464464
}
465465

466466
private async Task WriteFinalBatchAsync(CancellationToken cancellationToken)
@@ -470,7 +470,6 @@ private async Task WriteFinalBatchAsync(CancellationToken cancellationToken)
470470
TruncateFinalChunk();
471471
await WriteBatchAsync(cancellationToken).ConfigureAwait(false);
472472
}
473-
_md5.TransformFinalBlock(new byte[0], 0, 0);
474473
}
475474
}
476475
}

src/MongoDB.Driver.GridFS/GridFSMD5Exception.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
*/
1515

1616
using System;
17+
#if NET45
1718
using System.Runtime.Serialization;
19+
#endif
1820
using MongoDB.Bson;
1921
using MongoDB.Driver.Core.Misc;
2022

@@ -28,13 +30,13 @@ namespace MongoDB.Driver.GridFS
2830
#endif
2931
public class GridFSMD5Exception : GridFSException
3032
{
31-
#region static
33+
#region static
3234
private static string FormatMessage(BsonValue id)
3335
{
3436
Ensure.IsNotNull(id, nameof(id));
3537
return string.Format("GridFS MD5 check failed: file id {0}.", id);
3638
}
37-
#endregion
39+
#endregion
3840

3941
// constructors
4042
/// <summary>

0 commit comments

Comments
 (0)