当前位置: 首页>>代码示例>>C#>>正文


C# Driver.MongoUrlBuilder类代码示例

本文整理汇总了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);
     }
 }
开发者ID:pkdevbox,项目名称:mongo-azure,代码行数:35,代码来源:ServerController.cs

示例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());
        }
开发者ID:yfann,项目名称:mongo-csharp-driver,代码行数:30,代码来源:MongoUrlBuilderTests.cs

示例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);
		}
开发者ID:valeriob,项目名称:EventStore,代码行数:7,代码来源:MongoPersistenceFactory.cs

示例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);
        }
开发者ID:sayedihashimi,项目名称:khyber-pass,代码行数:25,代码来源:MongoUnitTestBase.cs

示例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());
        }
开发者ID:vshlos,项目名称:mongo-csharp-driver,代码行数:26,代码来源:MongoUrlBuilderTests.cs

示例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;
        }
开发者ID:pavel-gridnev,项目名称:DatabaseBenchmark,代码行数:26,代码来源:MongoDBDatabase.cs

示例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());
        }
开发者ID:ebix,项目名称:mongo-csharp-driver,代码行数:25,代码来源:MongoUrlBuilderTests.cs

示例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;
        }
开发者ID:pavel-gridnev,项目名称:DatabaseBenchmark,代码行数:26,代码来源:TokuMXDatabase.cs

示例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);
 }
开发者ID:tareq89,项目名称:TaskCat,代码行数:7,代码来源:DbContext.cs

示例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;
 }
开发者ID:ilnur-slv,项目名称:-mvc3-_FanFictionDB,代码行数:8,代码来源:BookRepository.cs

示例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"));
        }
开发者ID:thomast74,项目名称:spring-net-data-mongodb,代码行数:8,代码来源:SimpleMongoDbFactoryTests.cs

示例12: MangoDBSetDatabaseNameRandom

 private static string MangoDBSetDatabaseNameRandom(string connectionString)
 {
     var urlBuilder = new MongoUrlBuilder(connectionString)
                          {
                              DatabaseName = "brCounterTest_" + Guid.NewGuid().ToString("N")
                          };
     return urlBuilder.ToString();
 }
开发者ID:sFedyashov,项目名称:BuildRevisionCounter,代码行数:8,代码来源:DBUtil.cs

示例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();
        }
开发者ID:saykorz,项目名称:LunarBase,代码行数:13,代码来源:ConnectionHelper.cs

示例14: MongoContentTypeRegistry

        public MongoContentTypeRegistry(string connectionString, string collectionName)
        {
            var builder = new MongoUrlBuilder(connectionString);
            this.collectionName = collectionName;
            databaseName = builder.DatabaseName;
            mongoServer = MongoServer.Create(connectionString);

            DropContentTypesCollection();
        }
开发者ID:burkhartt,项目名称:Bennington,代码行数:9,代码来源:MongoContentTypeRegistry.cs

示例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");
        }
开发者ID:brianwigfield,项目名称:SimpleCQRS,代码行数:9,代码来源:MongoEventStore.cs


注:本文中的MongoDB.Driver.MongoUrlBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。