Skip to content

Commit

Permalink
Remove ConnectionState in favor of an IsConnected property since the …
Browse files Browse the repository at this point in the history
…ConnectionState is already only true or false.
  • Loading branch information
lanwin committed May 18, 2010
1 parent 3bab1ac commit 3d62bb8
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void TestReconnectOnce()
catch(IOException)
{
//Should be able to resend.
Assert.IsTrue(conn.State == ConnectionState.Opened);
Assert.IsTrue(conn.IsConnected);
var qmsg = GenerateQueryMessage();
var rmsg = conn.SendTwoWayMessage(qmsg);
Assert.IsNotNull(rmsg);
Expand Down
23 changes: 13 additions & 10 deletions source/MongoDB/Connections/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public ReplyMessage<Document> SendTwoWayMessage(IRequestMessage message){
/// <returns></returns>
/// <exception cref="IOException">A reconnect will be issued but it is up to the caller to handle the error.</exception>
public ReplyMessage<T> SendTwoWayMessage<T>(IRequestMessage message, BsonReaderSettings readerSettings) where T:class {
if (State != ConnectionState.Opened) {
if(!IsConnected)
throw new MongoConnectionException ("Operation cannot be performed on a closed connection.", this);
}

try {
var reply = new ReplyMessage<T>(readerSettings);
lock (_connection) {
Expand All @@ -102,9 +102,9 @@ public ReplyMessage<T> SendTwoWayMessage<T>(IRequestMessage message, BsonReaderS
/// <param name="message">The message.</param>
/// <exception cref="IOException">A reconnect will be issued but it is up to the caller to handle the error.</exception>
public void SendMessage (IRequestMessage message){
if (State != ConnectionState.Opened) {
throw new MongoConnectionException ("Operation cannot be performed on a closed connection.", this);
}
if(!IsConnected)
throw new MongoConnectionException("Operation cannot be performed on a closed connection.", this);

try {
lock (_connection) {
message.Write (_connection.GetStream ());
Expand All @@ -117,11 +117,14 @@ public void SendMessage (IRequestMessage message){
}

/// <summary>
/// Gets the state.
/// Gets a value indicating whether this instance is connected.
/// </summary>
/// <value>The state.</value>
public ConnectionState State {
get { return _connection != null ? ConnectionState.Opened : ConnectionState.Closed; }
/// <value>
/// <c>true</c> if this instance is connected; otherwise, <c>false</c>.
/// </value>
public bool IsConnected
{
get { return _connection != null && _connection.IsConnected; }
}

/// <summary>
Expand Down Expand Up @@ -168,7 +171,7 @@ private void ReplaceInvalidConnection (){
/// Gets the stream.
/// </summary>
/// <returns></returns>
public Stream GetStream (){
internal Stream GetStream (){
return _connection.GetStream ();
}

Expand Down
16 changes: 0 additions & 16 deletions source/MongoDB/Connections/ConnectionState.cs

This file was deleted.

2 changes: 1 addition & 1 deletion source/MongoDB/Cursor_1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void Dispose()
/// <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(Id == 0 || _connection.State != ConnectionState.Opened) //All server side resources disposed of.
if(Id == 0 || !_connection.IsConnected) //All server side resources disposed of.
return;

KillCursor(Id);
Expand Down
9 changes: 3 additions & 6 deletions source/MongoDB/Mongo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public bool TryConnect()
try
{
_connection.Open();
return _connection.State == ConnectionState.Opened;
return _connection.IsConnected;
}
catch(MongoException)
{
return _connection.State == ConnectionState.Opened;
return _connection.IsConnected;
}
}

Expand All @@ -115,7 +115,7 @@ public bool TryConnect()
public bool Disconnect()
{
_connection.Close();
return _connection.State == ConnectionState.Closed;
return _connection.IsConnected;
}

/// <summary>
Expand All @@ -124,9 +124,6 @@ public bool Disconnect()
/// <returns></returns>
public IEnumerable<IMongoDatabase> GetDatabases()
{
if(_connection == null || _connection.State != ConnectionState.Opened)
throw new MongoException("Open connection required");

var result = _connection.SendCommand(_configuration.SerializationFactory, "admin", typeof(Document), new Document("listDatabases", 1));

return ((IEnumerable<Document>)result["databases"])
Expand Down
1 change: 0 additions & 1 deletion source/MongoDB/MongoDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@
<Compile Include="Connections\Connection.cs" />
<Compile Include="Connections\ConnectionFactory.cs" />
<Compile Include="Connections\ConnectionFactoryBase.cs" />
<Compile Include="Connections\ConnectionState.cs" />
<Compile Include="Connections\IConnectionFactory.cs" />
<Compile Include="Connections\PooledConnectionFactory.cs" />
<Compile Include="Connections\SimpleConnectionFactory.cs" />
Expand Down
3 changes: 3 additions & 0 deletions source/MongoDB/Oid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class Oid : IEquatable<Oid>, IComparable<Oid>, IFormattable
/// <summary>
/// Initializes a new instance of the <see cref="Oid"/> class.
/// </summary>
/// <remarks>
/// Needed for some serializers.
/// </remarks>
protected Oid()
{
}
Expand Down

0 comments on commit 3d62bb8

Please sign in to comment.