Skip to content

Commit 740c248

Browse files
author
rstam
committed
CSHARP-614, CSHARP-615: Added MongoClient and replaced SafeMode with WriteConcern and related changes.
1 parent a0bb011 commit 740c248

34 files changed

+3198
-769
lines changed

Driver/Core/CommandResults/SafeModeResult.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,15 @@
1717
using System.Collections.Generic;
1818
using System.Linq;
1919
using System.Text;
20-
using System.Text.RegularExpressions;
21-
22-
using MongoDB.Bson;
2320

2421
namespace MongoDB.Driver
2522
{
2623
/// <summary>
27-
/// Represents the results of an operation performed with a safe mode.
24+
/// Represents the results of an operation performed with a WriteConcern other than FireAndForget.
2825
/// </summary>
2926
[Serializable]
27+
[Obsolete("Use WriteConcernResult instead.")]
3028
public class SafeModeResult : GetLastErrorResult
3129
{
32-
// constructors
33-
/// <summary>
34-
/// Initializes a new instance of the SafeModeResult class.
35-
/// </summary>
36-
public SafeModeResult()
37-
{
38-
}
3930
}
4031
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* Copyright 2010-2012 10gen Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Text;
20+
21+
namespace MongoDB.Driver
22+
{
23+
/// <summary>
24+
/// Represents the results of an operation performed with a WriteConcern other than FireAndForget.
25+
/// </summary>
26+
[Serializable]
27+
#pragma warning disable 618
28+
public class WriteConcernResult : SafeModeResult
29+
#pragma warning restore
30+
{
31+
}
32+
}

Driver/Core/MongoClient.cs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* Copyright 2010-2012 10gen Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Text;
20+
21+
namespace MongoDB.Driver
22+
{
23+
/// <summary>
24+
/// Represents a client to MongoDB.
25+
/// </summary>
26+
public class MongoClient
27+
{
28+
// private fields
29+
private readonly MongoClientSettings _settings;
30+
31+
// constructors
32+
/// <summary>
33+
/// Initializes a new instance of the MongoClient class.
34+
/// </summary>
35+
public MongoClient()
36+
: this(new MongoClientSettings())
37+
{
38+
}
39+
40+
/// <summary>
41+
/// Initializes a new instance of the MongoClient class.
42+
/// </summary>
43+
/// <param name="settings">The settings.</param>
44+
public MongoClient(MongoClientSettings settings)
45+
{
46+
_settings = settings.FrozenCopy();
47+
}
48+
49+
/// <summary>
50+
/// Initializes a new instance of the MongoClient class.
51+
/// </summary>
52+
/// <param name="url">The URL.</param>
53+
public MongoClient(MongoUrl url)
54+
: this(MongoClientSettings.FromUrl(url))
55+
{
56+
}
57+
58+
/// <summary>
59+
/// Initializes a new instance of the MongoClient class.
60+
/// </summary>
61+
/// <param name="connectionString">The connection string.</param>
62+
public MongoClient(string connectionString)
63+
: this(ParseConnectionString(connectionString))
64+
{
65+
}
66+
67+
// public properties
68+
/// <summary>
69+
/// Gets the client settings.
70+
/// </summary>
71+
public MongoClientSettings Settings
72+
{
73+
get { return _settings; }
74+
}
75+
76+
// private static methods
77+
private static MongoClientSettings ParseConnectionString(string connectionString)
78+
{
79+
if (connectionString.StartsWith("mongodb://"))
80+
{
81+
var url = new MongoUrl(connectionString);
82+
return MongoClientSettings.FromUrl(url);
83+
}
84+
else
85+
{
86+
var builder = new MongoConnectionStringBuilder(connectionString);
87+
return MongoClientSettings.FromConnectionStringBuilder(builder);
88+
}
89+
}
90+
91+
// public methods
92+
/// <summary>
93+
/// Gets a MongoServer object using this client's settings.
94+
/// </summary>
95+
/// <returns>A MongoServer.</returns>
96+
public MongoServer GetServer()
97+
{
98+
var serverSettings = MongoServerSettings.FromClientSettings(_settings);
99+
#pragma warning disable 618
100+
return MongoServer.Create(serverSettings);
101+
#pragma warning restore
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)