• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Driver.MongoUrlBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MongoDB.Driver.MongoUrlBuilder的典型用法代码示例。如果您正苦于以下问题:C# MongoUrlBuilder类的具体用法?C# MongoUrlBuilder怎么用?C# MongoUrlBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MongoUrlBuilder类属于MongoDB.Driver命名空间,在下文中一共展示了MongoUrlBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Connect

 public static CountersDatabase Connect(string mongoUrl)
 {
     MongoUrlBuilder builder = new MongoUrlBuilder(mongoUrl);
     builder.SocketTimeout = new TimeSpan(0, 30, 0);
     //builder.Server = port.HasValue ? new MongoServerAddress(host, port.Value) : new MongoServerAddress(host);
     MongoServer server = MongoServer.Create(builder.ToServerSettings());
     server.Connect();
     MongoDatabase db = server.GetDatabase(builder.DatabaseName);
     return new CountersDatabase(server, db);
 }
开发者ID:demonix,项目名称:iPoint.ServiceStatistics,代码行数:10,代码来源:CountersDatabase.cs


示例17: GetDatabase

        private static MongoDatabase GetDatabase()
        {
            var testDbConnStrBuilder = new MongoUrlBuilder("mongodb://localhost/Guid-vs-ObjectId?safe=true");
            var connectionString = testDbConnStrBuilder.ToMongoUrl();
            var client = new MongoClient(connectionString);
            var mongoDatabase = client.GetServer().GetDatabase(connectionString.DatabaseName);

            mongoDatabase.SetProfilingLevel(ProfilingLevel.All);
            return mongoDatabase;
        }
开发者ID:Restuta,项目名称:mongo.Guid-vs-ObjectId-performance,代码行数:10,代码来源:Program.cs


示例18: BookContext

        public BookContext()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString;
            var con = new MongoUrlBuilder(connectionString);

            client = new MongoClient(connectionString);
            database = client.GetDatabase(con.DatabaseName);

            gridFS = new MongoGridFS(new MongoServer(new MongoServerSettings { Server = con.Server }),con.DatabaseName, new MongoGridFSSettings());
        }
开发者ID:Ubuntus,项目名称:TestWithMongoDB,代码行数:10,代码来源:BookContext.cs


示例19: 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
 }
开发者ID:zxy050,项目名称:mongo-csharp-driver,代码行数:14,代码来源:MongoUrl.cs


示例20: MongoContentTreeProvider

 public MongoContentTreeProvider(string connectionString, string collectionName, Uri invalidateCacheUri)
 {
     ContentChanged += (sender, e) => { };
     var builder = new MongoUrlBuilder(connectionString);
     this.collectionName = collectionName;
     databaseName = builder.DatabaseName;
     mongoServer = MongoServer.Create(connectionString);
     cacheEndpoint = new InvalidateCacheEndpoint(invalidateCacheUri);
     cacheEndpoint.CacheInvalidated += InvalidateCache;
     cacheEndpoint.Open();
 }
开发者ID:burkhartt,项目名称:Bennington,代码行数:11,代码来源:MongoContentTreeProvider.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Driver.QueryDocument类代码示例发布时间:2022-05-26
下一篇:
C# Driver.MongoUrl类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap