本文整理汇总了C#中MongoConnection.SendMessage方法的典型用法代码示例。如果您正苦于以下问题:C# MongoConnection.SendMessage方法的具体用法?C# MongoConnection.SendMessage怎么用?C# MongoConnection.SendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoConnection
的用法示例。
在下文中一共展示了MongoConnection.SendMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendMessageWithWriteConcern
protected WriteConcernResult SendMessageWithWriteConcern(
MongoConnection connection,
BsonBuffer buffer,
int requestId,
BsonBinaryReaderSettings readerSettings,
BsonBinaryWriterSettings writerSettings,
WriteConcern writeConcern)
{
CommandDocument getLastErrorCommand = null;
if (writeConcern.Enabled)
{
var fsync = (writeConcern.FSync == null) ? null : (BsonValue)writeConcern.FSync;
var journal = (writeConcern.Journal == null) ? null : (BsonValue)writeConcern.Journal;
var w = (writeConcern.W == null) ? null : writeConcern.W.ToGetLastErrorWValue();
var wTimeout = (writeConcern.WTimeout == null) ? null : (BsonValue)(int)writeConcern.WTimeout.Value.TotalMilliseconds;
getLastErrorCommand = new CommandDocument
{
{ "getlasterror", 1 }, // use all lowercase for backward compatibility
{ "fsync", fsync, fsync != null },
{ "j", journal, journal != null },
{ "w", w, w != null },
{ "wtimeout", wTimeout, wTimeout != null }
};
// piggy back on network transmission for message
var getLastErrorMessage = new MongoQueryMessage(writerSettings, DatabaseName + ".$cmd", QueryFlags.None, 0, 1, getLastErrorCommand, null);
getLastErrorMessage.WriteToBuffer(buffer);
}
connection.SendMessage(buffer, requestId);
WriteConcernResult writeConcernResult = null;
if (writeConcern.Enabled)
{
var writeConcernResultSerializer = BsonSerializer.LookupSerializer(typeof(WriteConcernResult));
var replyMessage = connection.ReceiveMessage<WriteConcernResult>(readerSettings, writeConcernResultSerializer, null);
if (replyMessage.NumberReturned == 0)
{
throw new MongoCommandException("Command 'getLastError' failed. No response returned");
}
writeConcernResult = replyMessage.Documents[0];
writeConcernResult.Command = getLastErrorCommand;
var mappedException = ExceptionMapper.Map(writeConcernResult);
if (mappedException != null)
{
throw mappedException;
}
}
return writeConcernResult;
}
示例2: SendMessageWithWriteConcern
protected SendMessageWithWriteConcernResult SendMessageWithWriteConcern(
MongoConnection connection,
Stream stream,
int requestId,
BsonBinaryReaderSettings readerSettings,
BsonBinaryWriterSettings writerSettings,
WriteConcern writeConcern)
{
var result = new SendMessageWithWriteConcernResult();
if (writeConcern.Enabled)
{
var maxDocumentSize = connection.ServerInstance.MaxDocumentSize;
var fsync = (writeConcern.FSync == null) ? null : (BsonValue)writeConcern.FSync;
var journal = (writeConcern.Journal == null) ? null : (BsonValue)writeConcern.Journal;
var w = (writeConcern.W == null) ? null : writeConcern.W.ToGetLastErrorWValue();
var wTimeout = (writeConcern.WTimeout == null) ? null : (BsonValue)(int)writeConcern.WTimeout.Value.TotalMilliseconds;
var getLastErrorCommand = new CommandDocument
{
{ "getlasterror", 1 }, // use all lowercase for backward compatibility
{ "fsync", fsync, fsync != null },
{ "j", journal, journal != null },
{ "w", w, w != null },
{ "wtimeout", wTimeout, wTimeout != null }
};
// piggy back on network transmission for message
var getLastErrorMessage = new MongoQueryMessage(writerSettings, DatabaseName + ".$cmd", QueryFlags.None, maxDocumentSize, 0, 1, getLastErrorCommand, null);
getLastErrorMessage.WriteTo(stream);
result.GetLastErrorCommand = getLastErrorCommand;
result.GetLastErrorRequestId = getLastErrorMessage.RequestId;
}
connection.SendMessage(stream, requestId);
return result;
}