本文整理汇总了C#中MongoDB.Driver.MongoUrlBuilder.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# MongoUrlBuilder.ToString方法的具体用法?C# MongoUrlBuilder.ToString怎么用?C# MongoUrlBuilder.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.MongoUrlBuilder
的用法示例。
在下文中一共展示了MongoUrlBuilder.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MongoDBDatabase
public MongoDBDatabase()
{
Name = "MongoDB";
CollectionName = "collection";
Category = "NoSQL\\Document Store";
Description = "MongoDB C# Driver 2.0.0beta";
Website = "http://www.mongodb.org/";
Color = Color.FromArgb(235, 215, 151);
Requirements = new string[]
{
"MongoDB.Bson.dll",
"MongoDB.Driver.dll",
"MongoDB.Driver.Core.dll",
"MongoDB.Driver.Legacy.dll"
};
MongoUrlBuilder builder = new MongoUrlBuilder();
builder.MaxConnectionIdleTime = TimeSpan.FromHours(1);
builder.MaxConnectionLifeTime = TimeSpan.FromHours(1);
builder.Server = new MongoServerAddress("localhost");
builder.W = 1;
ConnectionString = builder.ToString();
InsertsPerQuery = 5000;
}
示例2: TestDefaults
public void TestDefaults()
{
var builder = new MongoUrlBuilder();
Assert.AreEqual(null, builder.DefaultCredentials);
Assert.AreEqual(null, builder.Server);
Assert.AreEqual(null, builder.Servers);
Assert.AreEqual(null, builder.DatabaseName);
Assert.AreEqual(ConnectionMode.Automatic, builder.ConnectionMode);
Assert.AreEqual(MongoDefaults.ConnectTimeout, builder.ConnectTimeout);
Assert.AreEqual(MongoDefaults.GuidRepresentation, builder.GuidRepresentation);
Assert.AreEqual(false, builder.IPv6);
Assert.AreEqual(MongoDefaults.MaxConnectionIdleTime, builder.MaxConnectionIdleTime);
Assert.AreEqual(MongoDefaults.MaxConnectionLifeTime, builder.MaxConnectionLifeTime);
Assert.AreEqual(MongoDefaults.MaxConnectionPoolSize, builder.MaxConnectionPoolSize);
Assert.AreEqual(MongoDefaults.MinConnectionPoolSize, builder.MinConnectionPoolSize);
Assert.AreEqual(null, builder.ReadPreference);
Assert.AreEqual(null, builder.ReplicaSetName);
Assert.AreEqual(null, builder.SafeMode);
#pragma warning disable 618
Assert.AreEqual(false, builder.SlaveOk);
#pragma warning restore
Assert.AreEqual(MongoDefaults.SocketTimeout, builder.SocketTimeout);
Assert.AreEqual(MongoDefaults.WaitQueueMultiple, builder.WaitQueueMultiple);
Assert.AreEqual(MongoDefaults.WaitQueueSize, builder.WaitQueueSize);
Assert.AreEqual(MongoDefaults.WaitQueueTimeout, builder.WaitQueueTimeout);
Assert.AreEqual(MongoDefaults.ComputedWaitQueueSize, builder.ComputedWaitQueueSize);
var connectionString = "mongodb://"; // not actually a valid connection string because it's missing the host
Assert.AreEqual(connectionString, builder.ToString());
}
示例3: TestConnectTimeout
public void TestConnectTimeout()
{
var connectionString = "mongodb://localhost/?connectTimeout=123ms";
var builder = new MongoUrlBuilder("mongodb://localhost") { ConnectTimeout = TimeSpan.FromMilliseconds(123) };
Assert.AreEqual(TimeSpan.FromMilliseconds(123), builder.ConnectTimeout);
Assert.AreEqual(connectionString, builder.ToString());
Assert.AreEqual(connectionString, new MongoUrlBuilder(connectionString).ToString());
connectionString = "mongodb://localhost/?connectTimeout=123s";
builder = new MongoUrlBuilder("mongodb://localhost") { ConnectTimeout = TimeSpan.FromSeconds(123) };
Assert.AreEqual(TimeSpan.FromSeconds(123), builder.ConnectTimeout);
Assert.AreEqual(connectionString, builder.ToString());
Assert.AreEqual(connectionString, new MongoUrlBuilder(connectionString).ToString());
connectionString = "mongodb://localhost/?connectTimeout=123m";
builder = new MongoUrlBuilder("mongodb://localhost") { ConnectTimeout = TimeSpan.FromMinutes(123) };
Assert.AreEqual(TimeSpan.FromMinutes(123), builder.ConnectTimeout);
Assert.AreEqual(connectionString, builder.ToString());
Assert.AreEqual(connectionString, new MongoUrlBuilder(connectionString).ToString());
connectionString = "mongodb://localhost/?connectTimeout=123h";
builder = new MongoUrlBuilder("mongodb://localhost") { ConnectTimeout = TimeSpan.FromHours(123) };
Assert.AreEqual(TimeSpan.FromHours(123), builder.ConnectTimeout);
Assert.AreEqual(connectionString, builder.ToString());
Assert.AreEqual(connectionString, new MongoUrlBuilder(connectionString).ToString());
}
示例4: TestDefaults
public void TestDefaults() {
var builder = new MongoUrlBuilder();
Assert.AreEqual(MongoDefaults.ComputedWaitQueueSize, builder.ComputedWaitQueueSize);
Assert.AreEqual(ConnectionMode.Direct, builder.ConnectionMode);
Assert.AreEqual(MongoDefaults.ConnectTimeout, builder.ConnectTimeout);
Assert.AreEqual(null, builder.DatabaseName);
Assert.AreEqual(null, builder.DefaultCredentials);
Assert.AreEqual(false, builder.IPv6);
Assert.AreEqual(MongoDefaults.MaxConnectionIdleTime, builder.MaxConnectionIdleTime);
Assert.AreEqual(MongoDefaults.MaxConnectionLifeTime, builder.MaxConnectionLifeTime);
Assert.AreEqual(MongoDefaults.MaxConnectionPoolSize, builder.MaxConnectionPoolSize);
Assert.AreEqual(MongoDefaults.MinConnectionPoolSize, builder.MinConnectionPoolSize);
Assert.AreEqual(null, builder.ReplicaSetName);
Assert.AreEqual(null, builder.SafeMode);
Assert.AreEqual(null, builder.Server);
Assert.AreEqual(null, builder.Servers);
Assert.AreEqual(false, builder.SlaveOk);
Assert.AreEqual(MongoDefaults.SocketTimeout, builder.SocketTimeout);
Assert.AreEqual(MongoDefaults.WaitQueueMultiple, builder.WaitQueueMultiple);
Assert.AreEqual(MongoDefaults.WaitQueueSize, builder.WaitQueueSize);
Assert.AreEqual(MongoDefaults.WaitQueueTimeout, builder.WaitQueueTimeout);
var connectionString = "mongodb://";
Assert.AreEqual(connectionString, builder.ToString());
}
示例5: TokuMXDatabase
public TokuMXDatabase()
{
Name = "TokuMX";
CollectionName = "collection";
Category = "NoSQL\\Document Store";
Description = "TokuMX v2.0";
Website = "http://www.tokutek.com/tokumx-for-mongodb/";
Color = Color.Chartreuse;
Requirements = new string[]
{
"MongoDB.Bson.dll",
"MongoDB.Driver.dll",
"MongoDB.Driver.Core.dll",
"MongoDB.Driver.Legacy.dll"
};
MongoUrlBuilder builder = new MongoUrlBuilder();
builder.MaxConnectionIdleTime = TimeSpan.FromHours(1);
builder.MaxConnectionLifeTime = TimeSpan.FromHours(1);
builder.Server = new MongoServerAddress("localhost");
builder.W = 1;
ConnectionString = builder.ToString();
InsertsPerQuery = 5000;
}
示例6: GetDatabaseConnectionString
/// <summary>
/// Gets the database connection string.
/// </summary>
/// <param name="config">The config.</param>
/// <returns></returns>
internal static string GetDatabaseConnectionString(NameValueCollection config)
{
string connectionString = GetConnectionString(config);
var builder = new MongoUrlBuilder(connectionString);
builder.DatabaseName = GetDatabaseName(connectionString, config);
return builder.ToString();
}
示例7: MangoDBSetDatabaseNameRandom
private static string MangoDBSetDatabaseNameRandom(string connectionString)
{
var urlBuilder = new MongoUrlBuilder(connectionString)
{
DatabaseName = "brCounterTest_" + Guid.NewGuid().ToString("N")
};
return urlBuilder.ToString();
}
示例8: MongoUrl
/// <summary>
/// Creates a new instance of MongoUrl.
/// </summary>
/// <param name="url">The URL containing the settings.</param>
public MongoUrl(
string url
) {
var builder = new MongoUrlBuilder(url); // parses url
serverSettings = builder.ToServerSettings().FrozenCopy();
this.waitQueueMultiple = builder.WaitQueueMultiple;
this.waitQueueSize = builder.WaitQueueSize;
this.databaseName = builder.DatabaseName;
this.url = builder.ToString(); // keep canonical form
}
示例9: TestHostWithPort
public void TestHostWithPort() {
var builder = new MongoUrlBuilder() { Server = new MongoServerAddress("mongo.xyz.com", 12345) };
Assert.AreEqual(1, builder.Servers.Count());
Assert.AreEqual("mongo.xyz.com", builder.Server.Host);
Assert.AreEqual(12345, builder.Server.Port);
Assert.AreEqual(ConnectionMode.Direct, builder.ConnectionMode);
Assert.AreEqual(null, builder.ReplicaSetName);
var connectionString = "mongodb://mongo.xyz.com:12345";
Assert.AreEqual(connectionString, builder.ToString());
Assert.AreEqual(connectionString, new MongoUrlBuilder(connectionString).ToString());
}
示例10: TestHost
public void TestHost()
{
var builder = new MongoUrlBuilder() { Server = new MongoServerAddress("mongo.xyz.com") };
Assert.AreEqual(null, builder.DefaultCredentials);
Assert.AreEqual(1, builder.Servers.Count());
Assert.AreEqual("mongo.xyz.com", builder.Server.Host);
Assert.AreEqual(27017, builder.Server.Port);
Assert.AreEqual(null, builder.DatabaseName);
Assert.AreEqual(ConnectionMode.Automatic, builder.ConnectionMode);
var connectionString = "mongodb://mongo.xyz.com";
Assert.AreEqual(connectionString, builder.ToString());
Assert.AreEqual(connectionString, new MongoUrlBuilder(connectionString).ToString());
}
示例11: MongoUrl
public MongoUrl(
string url
)
{
var builder = new MongoUrlBuilder(url);
this.url = builder.ToString(); // keep canonical form
this.credentials = builder.Credentials;
this.servers = builder.Servers;
this.databaseName = builder.DatabaseName;
this.connectionMode = builder.ConnectionMode;
this.replicaSetName = builder.ReplicaSetName;
this.safeMode = builder.SafeMode ?? SafeMode.False; // never null
this.slaveOk = builder.SlaveOk;
}
示例12: TestConnectionMode
public void TestConnectionMode()
{
var connectionString = "mongodb://localhost";
var builder = new MongoUrlBuilder("mongodb://localhost") { ConnectionMode = ConnectionMode.Direct };
Assert.AreEqual(ConnectionMode.Direct, builder.ConnectionMode);
Assert.AreEqual(connectionString, builder.ToString());
Assert.AreEqual(connectionString, new MongoUrlBuilder(connectionString).ToString());
connectionString = "mongodb://localhost/?connect=replicaSet";
builder = new MongoUrlBuilder("mongodb://localhost") { ConnectionMode = ConnectionMode.ReplicaSet };
Assert.AreEqual(ConnectionMode.ReplicaSet, builder.ConnectionMode);
Assert.AreEqual(connectionString, builder.ToString());
Assert.AreEqual(connectionString, new MongoUrlBuilder(connectionString).ToString());
}
示例13: BootstrapContainer
private IContainer BootstrapContainer()
{
var container = new Container();
container.Configure(cfg =>
{
cfg.Scan(scanner =>
{
scanner.WithDefaultConventions();
scanner.AssemblyContainingType<IScript>();
});
var mongoUrlBuilder = new MongoUrlBuilder(Properties.Settings.Default.TestDatabaseConnectionString);
cfg.For<MongoUrlBuilder>()
.Singleton()
.Use(new MongoUrlBuilder(Properties.Settings.Default.TestDatabaseConnectionString));
cfg.For<MongoDatabase>()
.Transient()
.Use(ctx =>
{
var client = new MongoClient(mongoUrlBuilder.ToString());
client.GetServer().Connect();
return client.GetServer().GetDatabase(mongoUrlBuilder.DatabaseName);
});
cfg.For<MongoDbScriptEnumerator>()
.Transient()
.Use<MongoDbScriptEnumerator>()
.Ctor<string>().Is(Properties.Settings.Default.LogCollectionName);
cfg.For<MongoScriptRunner>()
.Transient()
.Use(() => new MongoScriptRunner(Properties.Settings.Default.MongoClientPath, mongoUrlBuilder.ToMongoUrl()));
});
return container;
}
示例14: TestTwoHosts
public void TestTwoHosts()
{
var builder = new MongoUrlBuilder()
{
Servers = new MongoServerAddress[]
{
new MongoServerAddress("mongo1.xyz.com"),
new MongoServerAddress("mongo2.xyz.com")
}
};
var servers = builder.Servers.ToArray();
Assert.AreEqual(null, builder.DefaultCredentials);
Assert.AreEqual(2, servers.Length);
Assert.AreEqual("mongo1.xyz.com", servers[0].Host);
Assert.AreEqual(27017, servers[0].Port);
Assert.AreEqual("mongo2.xyz.com", servers[1].Host);
Assert.AreEqual(27017, servers[1].Port);
Assert.AreEqual(null, builder.DatabaseName);
Assert.AreEqual(ConnectionMode.Automatic, builder.ConnectionMode);
Assert.AreEqual(null, builder.ReplicaSetName);
var connectionString = "mongodb://mongo1.xyz.com,mongo2.xyz.com";
Assert.AreEqual(connectionString, builder.ToString());
Assert.AreEqual(connectionString, new MongoUrlBuilder(connectionString).ToString());
}
示例15: TestSlaveOkTrue
public void TestSlaveOkTrue()
{
#pragma warning disable 618
var builder = new MongoUrlBuilder("mongodb://localhost") { SlaveOk = true };
Assert.AreEqual(true, builder.SlaveOk);
#pragma warning restore
var connectionString = "mongodb://localhost/?slaveOk=true";
Assert.AreEqual(connectionString, builder.ToString());
Assert.AreEqual(connectionString, new MongoUrlBuilder(connectionString).ToString());
}