Skip to content

Commit adb9524

Browse files
committed
MongoDB.Driver.GridFS compiled with .NET Core
1 parent ceb6a6f commit adb9524

File tree

11 files changed

+6362
-33
lines changed

11 files changed

+6362
-33
lines changed

mongo-csharp-driver.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{EF7A
2020
EndProject
2121
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MongoDB.Tests.ConsoleApp", "samples\MongoDB.Tests.ConsoleApp\MongoDB.Tests.ConsoleApp.xproj", "{CCD9B0EE-086A-46F4-8307-9E46E50C57C2}"
2222
EndProject
23+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MongoDB.Driver.GridFS", "src\MongoDB.Driver.GridFS\MongoDB.Driver.GridFS.xproj", "{9976071B-899E-4687-B0E7-B45AE6AFF6C8}"
24+
EndProject
2325
Global
2426
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2527
Debug|Any CPU = Debug|Any CPU
@@ -42,6 +44,10 @@ Global
4244
{CCD9B0EE-086A-46F4-8307-9E46E50C57C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
4345
{CCD9B0EE-086A-46F4-8307-9E46E50C57C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
4446
{CCD9B0EE-086A-46F4-8307-9E46E50C57C2}.Release|Any CPU.Build.0 = Release|Any CPU
47+
{9976071B-899E-4687-B0E7-B45AE6AFF6C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
48+
{9976071B-899E-4687-B0E7-B45AE6AFF6C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
49+
{9976071B-899E-4687-B0E7-B45AE6AFF6C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
50+
{9976071B-899E-4687-B0E7-B45AE6AFF6C8}.Release|Any CPU.Build.0 = Release|Any CPU
4551
EndGlobalSection
4652
GlobalSection(SolutionProperties) = preSolution
4753
HideSolutionNode = FALSE
@@ -51,5 +57,6 @@ Global
5157
{B86DE81A-6CAB-458D-852C-358114C146DB} = {B4E459B4-5B8C-4933-BECC-AEB36CEC84F6}
5258
{22C3CF35-4EEE-40DE-A313-33E2CFAC1F08} = {B4E459B4-5B8C-4933-BECC-AEB36CEC84F6}
5359
{CCD9B0EE-086A-46F4-8307-9E46E50C57C2} = {EF7A690C-F868-4E61-8ED7-3D05AC39D209}
60+
{9976071B-899E-4687-B0E7-B45AE6AFF6C8} = {B4E459B4-5B8C-4933-BECC-AEB36CEC84F6}
5461
EndGlobalSection
5562
EndGlobal

samples/MongoDB.Tests.ConsoleApp/project.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"type": "platform",
1111
"version": "1.0.0-rc2-3002702"
1212
},
13-
"RaisingStudio.MongoDB.Bson": "2.2.4-*",
14-
"RaisingStudio.MongoDB.Driver": "2.2.4-*"
13+
"MongoDB.Bson": "2.2.4-*",
14+
"MongoDB.Driver": "2.2.4-*"
1515
},
1616

1717
"frameworks": {

src/MongoDB.Driver.Core/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"authors": [ "[email protected]" ],
44
"description": "MongoDB supported Driver Core library. See http://www.mongodb.org/display/DOCS/CSharp+Language+Center for more details.",
55
"dependencies": {
6-
"RaisingStudio.MongoDB.Bson": "2.2.4-*",
6+
"MongoDB.Bson": "2.2.4-*",
77
"NETStandard.Library": "1.5.0-rc2-24027",
88
"System.Collections.Specialized": "4.0.1-rc2-24027",
99
"System.Diagnostics.TraceSource": "4.0.0-rc2-24027",

src/MongoDB.Driver.GridFS/DelegatingStream.cs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515

1616
using System;
1717
using System.IO;
18+
#if NETCORE50 || NETSTANDARD1_5
19+
#else
1820
using System.Runtime.Remoting;
21+
#endif
1922
using System.Threading;
2023
using System.Threading.Tasks;
2124

@@ -93,6 +96,8 @@ public override int WriteTimeout
9396
}
9497

9598
// methods
99+
#if NETCORE50 || NETSTANDARD1_5
100+
#else
96101
/// <inheritdoc/>
97102
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
98103
{
@@ -111,12 +116,6 @@ public override void Close()
111116
_wrappedStream.Close();
112117
}
113118

114-
/// <inheritdoc/>
115-
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
116-
{
117-
return _wrappedStream.CopyToAsync(destination, bufferSize, cancellationToken);
118-
}
119-
120119
/// <inheritdoc/>
121120
public override ObjRef CreateObjRef(Type requestedType)
122121
{
@@ -130,15 +129,6 @@ protected override WaitHandle CreateWaitHandle()
130129
throw new NotSupportedException();
131130
}
132131

133-
/// <inheritdoc/>
134-
protected override void Dispose(bool disposing)
135-
{
136-
if (disposing)
137-
{
138-
_wrappedStream.Dispose();
139-
}
140-
}
141-
142132
/// <inheritdoc/>
143133
public override int EndRead(IAsyncResult asyncResult)
144134
{
@@ -152,40 +142,56 @@ public override void EndWrite(IAsyncResult asyncResult)
152142
}
153143

154144
/// <inheritdoc/>
155-
public override bool Equals(object obj)
145+
public override object InitializeLifetimeService()
156146
{
157-
return _wrappedStream.Equals(obj);
147+
return _wrappedStream.InitializeLifetimeService();
158148
}
159149

160150
/// <inheritdoc/>
161-
public override void Flush()
151+
[Obsolete()]
152+
protected override void ObjectInvariant()
162153
{
163-
_wrappedStream.Flush();
154+
throw new NotSupportedException();
164155
}
156+
#endif
165157

166158
/// <inheritdoc/>
167-
public override Task FlushAsync(CancellationToken cancellationToken)
159+
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
168160
{
169-
return _wrappedStream.FlushAsync(cancellationToken);
161+
return _wrappedStream.CopyToAsync(destination, bufferSize, cancellationToken);
170162
}
171163

172164
/// <inheritdoc/>
173-
public override int GetHashCode()
165+
protected override void Dispose(bool disposing)
174166
{
175-
return _wrappedStream.GetHashCode();
167+
if (disposing)
168+
{
169+
_wrappedStream.Dispose();
170+
}
176171
}
177172

178173
/// <inheritdoc/>
179-
public override object InitializeLifetimeService()
174+
public override bool Equals(object obj)
180175
{
181-
return _wrappedStream.InitializeLifetimeService();
176+
return _wrappedStream.Equals(obj);
182177
}
183178

184179
/// <inheritdoc/>
185-
[Obsolete()]
186-
protected override void ObjectInvariant()
180+
public override void Flush()
187181
{
188-
throw new NotSupportedException();
182+
_wrappedStream.Flush();
183+
}
184+
185+
/// <inheritdoc/>
186+
public override Task FlushAsync(CancellationToken cancellationToken)
187+
{
188+
return _wrappedStream.FlushAsync(cancellationToken);
189+
}
190+
191+
/// <inheritdoc/>
192+
public override int GetHashCode()
193+
{
194+
return _wrappedStream.GetHashCode();
189195
}
190196

191197
/// <inheritdoc/>

src/MongoDB.Driver.GridFS/GridFSDownloadStreamBase.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ protected IGridFSBucket<TFileId> Bucket
7272
get { return _bucket; }
7373
}
7474

75+
#if NETCORE50 || NETSTANDARD1_5
76+
public override void Close(CancellationToken cancellationToken)
77+
{
78+
}
79+
80+
public override Task CloseAsync(CancellationToken cancellationToken = default(CancellationToken))
81+
{
82+
return Task.FromResult(true);
83+
}
84+
#else
7585
// public methods
7686
public override void Close()
7787
{
@@ -88,6 +98,7 @@ public override void Close(CancellationToken cancellationToken)
8898
base.Close();
8999
return Task.FromResult(true);
90100
}
101+
#endif
91102

92103
public override void Flush()
93104
{

src/MongoDB.Driver.GridFS/GridFSForwardOnlyDownloadStream.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ internal class GridFSForwardOnlyDownloadStream<TFileId> : GridFSDownloadStreamBa
4242
private readonly int _lastChunkNumber;
4343
private readonly int _lastChunkSize;
4444
private readonly MD5 _md5;
45+
#if NETCORE50 || NETSTANDARD1_5
46+
private byte[] _md5Buffer;
47+
#else
48+
#endif
4549
private int _nextChunkNumber;
4650
private long _position;
4751

@@ -57,6 +61,10 @@ public GridFSForwardOnlyDownloadStream(
5761
if (_checkMD5)
5862
{
5963
_md5 = MD5.Create();
64+
#if NETCORE50 || NETSTANDARD1_5
65+
_md5Buffer = new byte[0];
66+
#else
67+
#endif
6068
}
6169

6270
_lastChunkNumber = (int)((fileInfo.Length - 1) / fileInfo.ChunkSizeBytes);
@@ -170,6 +178,10 @@ protected override void Dispose(bool disposing)
170178
if (_md5 != null)
171179
{
172180
_md5.Dispose();
181+
#if NETCORE50 || NETSTANDARD1_5
182+
_md5Buffer = null;
183+
#else
184+
#endif
173185
}
174186
}
175187

@@ -197,8 +209,12 @@ private void CloseHelper()
197209

198210
if (_checkMD5 && _position == FileInfo.Length)
199211
{
212+
#if NETCORE50 || NETSTANDARD1_5
213+
var md5 = BsonUtils.ToHexString(_md5.ComputeHash(_md5Buffer));
214+
#else
200215
_md5.TransformFinalBlock(new byte[0], 0, 0);
201216
var md5 = BsonUtils.ToHexString(_md5.Hash);
217+
#endif
202218
if (!md5.Equals(FileInfo.MD5, StringComparison.OrdinalIgnoreCase))
203219
{
204220
#pragma warning disable 618
@@ -300,7 +316,14 @@ private void GetNextBatchFromCursor(bool hasMore)
300316

301317
if (_checkMD5)
302318
{
319+
#if NETCORE50 || NETSTANDARD1_5
320+
var buffer = new byte[_md5Buffer.Length + bytes.Length];
321+
Buffer.BlockCopy(_md5Buffer, 0, buffer, 0, _md5Buffer.Length);
322+
Buffer.BlockCopy(bytes, 0, buffer, _md5Buffer.Length, bytes.Length);
323+
_md5Buffer = buffer;
324+
#else
303325
_md5.TransformBlock(bytes, 0, bytes.Length, null, 0);
326+
#endif
304327
}
305328
}
306329
}

src/MongoDB.Driver.GridFS/GridFSForwardOnlyUploadStream.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ internal class GridFSForwardOnlyUploadStream<TFileId> : GridFSUploadStream<TFile
5050
private readonly BsonValue _idAsBsonValue;
5151
private long _length;
5252
private readonly MD5 _md5;
53+
#if NETCORE50 || NETSTANDARD1_5
54+
private byte[] _md5Buffer;
55+
#else
56+
#endif
5357
private readonly BsonDocument _metadata;
5458

5559
// constructors
@@ -147,10 +151,13 @@ public override long Position
147151
await operation.ExecuteAsync(_binding, cancellationToken).ConfigureAwait(false);
148152
}
149153

154+
#if NETCORE50 || NETSTANDARD1_5
155+
#else
150156
public override void Close()
151157
{
152158
Close(CancellationToken.None);
153159
}
160+
#endif
154161

155162
public override void Close(CancellationToken cancellationToken)
156163
{
@@ -167,7 +174,10 @@ public override void Close(CancellationToken cancellationToken)
167174
WriteFilesCollectionDocument(cancellationToken);
168175
}
169176

177+
#if NETCORE50 || NETSTANDARD1_5
178+
#else
170179
base.Close();
180+
#endif
171181
}
172182

173183
public override async Task CloseAsync(CancellationToken cancellationToken = default(CancellationToken))
@@ -185,7 +195,10 @@ public override void Close(CancellationToken cancellationToken)
185195
await WriteFilesCollectionDocumentAsync(cancellationToken).ConfigureAwait(false);
186196
}
187197

198+
#if NETCORE50 || NETSTANDARD1_5
199+
#else
188200
base.Close();
201+
#endif
189202
}
190203

191204
public override void Flush()
@@ -271,7 +284,11 @@ private BsonDocument CreateFilesCollectionDocument()
271284
{ "length", _length },
272285
{ "chunkSize", _chunkSizeBytes },
273286
{ "uploadDate", uploadDateTime },
287+
#if NETCORE50 || NETSTANDARD1_5
288+
{ "md5", BsonUtils.ToHexString(_md5.ComputeHash(_md5Buffer)) },
289+
#else
274290
{ "md5", BsonUtils.ToHexString(_md5.Hash) },
291+
#endif
275292
{ "filename", _filename },
276293
{ "contentType", _contentType, _contentType != null },
277294
{ "aliases", () => new BsonArray(_aliases.Select(a => new BsonString(a))), _aliases != null },
@@ -296,7 +313,14 @@ private IEnumerable<BsonDocument> CreateWriteBatchChunkDocuments()
296313
chunkDocuments.Add(chunkDocument);
297314

298315
_batchPosition += chunk.Length;
316+
#if NETCORE50 || NETSTANDARD1_5
317+
var buffer = new byte[_md5Buffer.Length + chunk.Length];
318+
Buffer.BlockCopy(_md5Buffer, 0, buffer, 0, _md5Buffer.Length);
319+
Buffer.BlockCopy(chunk, 0, buffer, _md5Buffer.Length, chunk.Length);
320+
_md5Buffer = buffer;
321+
#else
299322
_md5.TransformBlock(chunk, 0, chunk.Length, null, 0);
323+
#endif
300324
}
301325

302326
return chunkDocuments;
@@ -313,6 +337,10 @@ protected override void Dispose(bool disposing)
313337
if (_md5 != null)
314338
{
315339
_md5.Dispose();
340+
#if NETCORE50 || NETSTANDARD1_5
341+
_md5Buffer = null;
342+
#else
343+
#endif
316344
}
317345

318346
_binding.Dispose();
@@ -460,7 +488,10 @@ private void WriteFinalBatch(CancellationToken cancellationToken)
460488
TruncateFinalChunk();
461489
WriteBatch(cancellationToken);
462490
}
491+
#if NETCORE50 || NETSTANDARD1_5
492+
#else
463493
_md5.TransformFinalBlock(new byte[0], 0, 0);
494+
#endif
464495
}
465496

466497
private async Task WriteFinalBatchAsync(CancellationToken cancellationToken)
@@ -470,7 +501,10 @@ private async Task WriteFinalBatchAsync(CancellationToken cancellationToken)
470501
TruncateFinalChunk();
471502
await WriteBatchAsync(cancellationToken).ConfigureAwait(false);
472503
}
504+
#if NETCORE50 || NETSTANDARD1_5
505+
#else
473506
_md5.TransformFinalBlock(new byte[0], 0, 0);
507+
#endif
474508
}
475509
}
476510
}
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>9976071b-899e-4687-b0e7-b45ae6aff6c8</ProjectGuid>
11+
<RootNamespace>MongoDB.Driver.GridFS</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>

0 commit comments

Comments
 (0)