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


C# MongoServer.Disconnect方法代码示例

本文整理汇总了C#中MongoServer.Disconnect方法的典型用法代码示例。如果您正苦于以下问题:C# MongoServer.Disconnect方法的具体用法?C# MongoServer.Disconnect怎么用?C# MongoServer.Disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoServer的用法示例。


在下文中一共展示了MongoServer.Disconnect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnImport_Click

 /// <summary>
 /// 导入按钮事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnImport_Click(object sender, EventArgs e)
 {
     innerServer = MongoServer.Create(@"mongodb://localhost:28030");
     innerServer.Connect();
     innerDatabase = innerServer.GetDatabase("HearthStone");
     innerCollection = innerDatabase.GetCollection("Card");
     if (String.IsNullOrEmpty(ExcelPicker.SelectedPathOrFileName)) return;
     Import();
     GC.Collect();
     innerServer.Disconnect();
 }
开发者ID:jonesgithub,项目名称:MagicMongoDBTool,代码行数:16,代码来源:frmImport.cs

示例2: Run

        public void Run()
        {
            try
            {
                MongoDbServer = MongoServer.Create(MongoDbLocation);
                MongoDb = MongoDbServer.GetDatabase(MongoDbName);

                MongoCollection docs = MongoDb.GetCollection("docs");
                docs.Save(new { Id = Guid.NewGuid(), Name = "John"});

            }
            finally
            {
                Console.WriteLine("Finished");
                MongoDbServer.Disconnect();
            }
        }
开发者ID:jnyryan,项目名称:MongoDb-Console-App,代码行数:17,代码来源:CreateSecureDatabase.cs

示例3: Main

 static void Main(string[] args)
 {
     var mongoServerAddress = new MongoServerAddress("127.0.0.1", 27017);
     var mongoServerSettings = new MongoServerSettings();
     mongoServerSettings.Server = mongoServerAddress;
     var mongoServer = new MongoServer(mongoServerSettings);
     mongoServer.Connect();
     IEnumerable<string> databases = mongoServer.GetDatabaseNames();
     var mongoDatabase = mongoServer.GetDatabase("classfrogdb");
     var classCollection = mongoDatabase.GetCollection("classes");
     classCollection.RemoveAll();
     var documents = classCollection.FindAll();
     ClassInstance instance = new ClassInstance();
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     mongoServer.Disconnect();
 }
开发者ID:nirmalclassfrog,项目名称:classfrog,代码行数:24,代码来源:Program.cs

示例4: TestConnection

 private static bool TestConnection(MongoServer server)
 {
     bool result = false;
     try
     {
         server.Connect();
         if (server.State == MongoServerState.Connected || server.State == MongoServerState.ConnectedToSubset)
         {
             result = true;
         }
     }
     finally
     {
         server.Disconnect();
     }
     return result;
 }
开发者ID:S-origin,项目名称:Tam.Framework,代码行数:17,代码来源:MongoHelper.cs

示例5: TestMongoConnection

        private void TestMongoConnection(
            MongoServer server, 
            string database,
            string loggerName)
        {
            var db = server.GetDatabase(database);
            var collection = db.GetCollection(loggerName);

            // Clear out test collection
            collection.RemoveAll();

            var logger = LogManager.GetLogger(loggerName);

            logger.LogException(
                LogLevel.Error,
                "Test Log Message",
                new Exception("Test Exception", new Exception("Inner Exception")));

            Thread.Sleep(2000);

            collection.FindAll().Count()
                .Should().Be(1);

            var logEntry = collection.FindAll().First();

            logEntry["level"]
                .Should().Be(LogLevel.Error.ToString());
            logEntry["message"]
                .Should().Be("Test Log Message");
            
			var exception = logEntry["exception"].AsBsonDocument;
			
			exception["message"]
                .Should().Be("Test Exception");
            
			var innerException = exception["innerException"].AsBsonDocument;
			
			innerException["message"]
                .Should().Be("Inner Exception");

            // Clean-up
            db.DropCollection(loggerName);
            server.Disconnect();
        }
开发者ID:kayone,项目名称:NLog.MongoDB,代码行数:44,代码来源:IntegrationTests.cs

示例6: SetupStore

        private void SetupStore(MongoServer mongoServer, string databaseName, string collectionName)
        {
            Contract.Requires<ArgumentNullException>(mongoServer != null);
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(databaseName));
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(collectionName));

            mongoServer.Connect();

            var db = _mongoServer.GetDatabase(databaseName);
            var coll = db.GetCollection(collectionName);
            coll.EnsureIndex("Events.EventSourceId", "Events.EventSequence");

            mongoServer.Disconnect();
        }
开发者ID:stevebeauge,项目名称:ncqrs-MongoDbEventStore,代码行数:14,代码来源:MongoDBEventStore.cs


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