Skip to content

Commit

Permalink
Added back lost changes for ConfigurationSection. Once connection poo…
Browse files Browse the repository at this point in the history
…ling is merged this will change again
  • Loading branch information
Sedward committed Mar 10, 2010
1 parent 8f2276d commit f3c2eac
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
6 changes: 4 additions & 2 deletions MongoDB.Net-Tests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<configSections>
<section name="MongoDB" type="MongoDB.Driver.Configuration.MongoDBConfiguration, MongoDB.Driver" />
</configSections>
<MongoDB host="servername" port="27017" database="test" use_authentication="true" username="user" password="password" />

<MongoDB>
<connection host="servername" port="27017" database="test" use_authentication="false" username="user" password="password"/>
<gridFS collection="testFS" chunkSize="512000" />
</MongoDB>
</configuration>
8 changes: 5 additions & 3 deletions MongoDB.Net-Tests/TestConfigurationSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public class TestConfigurationSection
public void TestReadConfig(){

MongoDBConfiguration config = (MongoDBConfiguration)System.Configuration.ConfigurationManager.GetSection("MongoDB");
Assert.AreEqual("servername", config.Host);
Assert.AreEqual(27017, config.Port);
Assert.AreEqual("test", config.Database);
Assert.AreEqual("servername", config.Connection.Host);
Assert.AreEqual(27017, config.Connection.Port);
Assert.AreEqual("test", config.Connection.Database);
Assert.AreEqual("testFS", config.GridFS.Collection);
Assert.AreEqual(512000, config.GridFS.ChunkSize);
}

}
Expand Down
46 changes: 36 additions & 10 deletions MongoDBDriver/MongoDBConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,36 @@ public class MongoDBConfiguration : ConfigurationSection

public MongoDBConfiguration() { }

[ConfigurationProperty("connection")]
public ConnectionElement Connection{
get{return (ConnectionElement)this["connection"];}
set{ this["connection"] = value; }
}

[ConfigurationProperty("gridFS")]
public GridFSElement GridFS
{
get { return (GridFSElement)this["gridFS"]; }
set { this["gridFS"] = value; }
}

}


public class ConnectionElement : ConfigurationElement
{

[ConfigurationProperty("port", DefaultValue = "27017", IsRequired = true)]
[IntegerValidator(MinValue = 1, MaxValue = 65535, ExcludeRange = false)]
public int Port
{
public int Port{
get { return (Int32)this["port"]; }
set { this["port"] = value; }
}

[ConfigurationProperty("host", DefaultValue = "localhost", IsRequired = true)]
public string Host {
public string Host{
get { return (String)this["host"]; }
set { this["host"] = value; }

}

[ConfigurationProperty("database", IsRequired = true)]
Expand All @@ -47,15 +64,24 @@ public string Password{
get { return (String)this["password"]; }
set { this["password"] = value; }
}

}

/// <summary>
/// Not used at the moment but could be used later
/// </summary>
public class ChildConfigElement : ConfigurationElement
public class GridFSElement : ConfigurationElement
{
public ChildConfigElement() { }
[ConfigurationProperty("collection", IsRequired = false, DefaultValue="fs")]
public string Collection
{
get { return (String)this["collection"]; }
set { this["collection"] = value; }
}

[ConfigurationProperty("chunkSize", IsRequired = false, DefaultValue="256000")]
public Int32 ChunkSize
{
get { return (Int32)this["chunkSize"]; }
set { this["chunkSize"] = value; }
}

}

}

0 comments on commit f3c2eac

Please sign in to comment.