本文整理汇总了C#中MongoDB.Driver.MongoUrlBuilder类的典型用法代码示例。如果您正苦于以下问题:C# MongoUrlBuilder类的具体用法?C# MongoUrlBuilder怎么用?C# MongoUrlBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoUrlBuilder类属于MongoDB.Driver命名空间,在下文中一共展示了MongoUrlBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetServerLog
//=========================================================================
//
// AJAX ACTIONS
//
//=========================================================================
/// <summary>
/// Fetches the instance log by connecting to its mongod server.
/// This is fast and cheap, but won't work if the instance is down.
/// </summary>
public JsonResult GetServerLog(int id)
{
var server = ServerStatus.Get(id);
var urlBuilder = new MongoUrlBuilder();
urlBuilder.ConnectTimeout = new TimeSpan(0, 0, 3);
urlBuilder.Server = MongoServerAddress.Parse(server.Name);
urlBuilder.ReadPreference = ReadPreference.SecondaryPreferred;
var client = new MongoClient(urlBuilder.ToMongoUrl());
var conn = client.GetServer();
try
{
var command = new CommandDocument
{
{ "getLog", "global" }
};
var result = conn.GetDatabase("admin").RunCommand(command);
return Json(new { log = HtmlizeFromLogArray(result.
Response["log"].AsBsonArray) },
JsonRequestBehavior.AllowGet);
}
catch (MongoException e)
{
return Json(new { error = e.Message },
JsonRequestBehavior.AllowGet);
}
}
示例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: Build
public virtual IPersistStreams Build()
{
var connectionString = this.TransformConnectionString(this.GetConnectionString());
var builder = new MongoUrlBuilder(connectionString);
var database = (new MongoClient(connectionString)).GetServer().GetDatabase(builder.DatabaseName);
return new MongoPersistenceEngine(database, this.serializer);
}
示例4: Initalize
public static void Initalize(TestContext testContext)
{
XmlConfigurator.Configure();
// we have to start mongo DB
DirectoryInfo mongoDbDir = GetMongoDbDir(testContext);
var mongodbexe = mongoDbDir.GetFiles("mongod.exe").Single();
DirectoryInfo testCtxDirectory = new DirectoryInfo(testContext.TestDir);
DirectoryInfo dataDbDir = testCtxDirectory.CreateSubdirectory(new Config().GetAppSetting<string>(CommonTestStrings.MongodbDir));
string connectionString = new Config().GetConnectionString(CommonStrings.Database.ConnectionStringName).ConnectionString;
MongoUrlBuilder mub = new MongoUrlBuilder(connectionString);
string args = string.Format(@"--dbpath ""{0}"" --port {1}", dataDbDir.FullName, mub.Server.Port);
var psi = new ProcessStartInfo {
FileName = mongodbexe.FullName,
WorkingDirectory = testCtxDirectory.FullName,
Arguments = args,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
mongoDbProcess = Process.Start(psi);
}
示例5: 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());
}
示例6: 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;
}
示例7: 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());
}
示例8: 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;
}
示例9: InitiateDatabase
private void InitiateDatabase()
{
var connectionString = ConfigurationManager.ConnectionStrings["Mongo.ConnectionString"].ConnectionString;
var mongoUrlBuilder = new MongoUrlBuilder(connectionString);
mongoClient = new MongoClient(mongoUrlBuilder.ToMongoUrl());
Database = mongoClient.GetDatabase(mongoUrlBuilder.DatabaseName);
}
示例10: CreatDataBase
static MongoDatabase CreatDataBase(string bdName, string userName, string userPw)
{
var mongoUrlBuilder = new MongoUrlBuilder("mongodb://localhost");
MongoServer server = MongoServer.Create(mongoUrlBuilder.ToMongoUrl());
MongoCredentials credentials = new MongoCredentials(userName, userPw);
MongoDatabase database = server.GetDatabase(bdName, credentials);
return database;
}
示例11: MongoUriConstructor
public void MongoUriConstructor()
{
var uriBuilder = new MongoUrlBuilder("mongodb://myUsername:[email protected]/myDatabase");
IMongoDatabaseFactory mongoDbFactory = new SimpleMongoDatabaseFactory(uriBuilder.ToMongoUrl());
Assert.That(ReflectionUtils.GetInstanceFieldValue(mongoDbFactory, "_credentials"), Is.EqualTo(new MongoCredentials("myUsername", "myPassword")));
Assert.That(ReflectionUtils.GetInstanceFieldValue(mongoDbFactory, "_databaseName").ToString(), Is.EqualTo("myDatabase"));
}
示例12: MangoDBSetDatabaseNameRandom
private static string MangoDBSetDatabaseNameRandom(string connectionString)
{
var urlBuilder = new MongoUrlBuilder(connectionString)
{
DatabaseName = "brCounterTest_" + Guid.NewGuid().ToString("N")
};
return urlBuilder.ToString();
}
示例13: 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();
}
示例14: MongoContentTypeRegistry
public MongoContentTypeRegistry(string connectionString, string collectionName)
{
var builder = new MongoUrlBuilder(connectionString);
this.collectionName = collectionName;
databaseName = builder.DatabaseName;
mongoServer = MongoServer.Create(connectionString);
DropContentTypesCollection();
}
示例15: MongoEventStore
public MongoEventStore(string connectionString, ITypeCatalog typeCatalog)
{
_eventHashRef = new Dictionary<string, string>();
typeCatalog.GetDerivedTypes(typeof(DomainEvent)).ToList().
ForEach(x => BsonClassMap.RegisterClassMap(new DomainEventMapper(x, _eventHashRef)));
var connection = new MongoUrlBuilder(connectionString);
_collection = MongoServer.Create(connection.ToMongoUrl()).GetDatabase(connection.DatabaseName).GetCollection<DomainEvent>("events");
}