本文整理汇总了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();
}
示例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();
}
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}