本文整理汇总了C#中MongoDB.Bson.BsonDocumentWrapper类的典型用法代码示例。如果您正苦于以下问题:C# BsonDocumentWrapper类的具体用法?C# BsonDocumentWrapper怎么用?C# BsonDocumentWrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonDocumentWrapper类属于MongoDB.Bson命名空间,在下文中一共展示了BsonDocumentWrapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveRequestData
public static void SaveRequestData(HttpContextBase context)
{
var url = context.Request.Url.ToString();
var data = new BsonDocumentWrapper(new
{
//_id = ObjectId.GenerateNewId(),
at = DateTime.UtcNow,
url,
method = context.Request.HttpMethod,
headers = From(context.Request.Headers),
clientIp = context.Request.UserHostAddress
}).ToBsonDocument();
if (context.Request.Form.Count > 0)
{
data.Add("form", From(context.Request.Form));
}
var cookies = From(context.Response.Cookies);
if (cookies.Length > 0)
data.Add("cookies", BsonArray.Create((IEnumerable)cookies));
var referrer = context.Request.UrlReferrer;
if (referrer != null)
data.Add("referrer", referrer.ToString());
try
{
DB.Database.GetCollection("requestsLog").Insert(data);
}
catch
{
}
}
示例2: TestAddNameValue
public void TestAddNameValue()
{
var wrapper = new BsonDocumentWrapper(new BsonDocument());
Assert.AreEqual(false, wrapper.IsMaterialized);
wrapper.Add("x", 1);
Assert.AreEqual(true, wrapper.IsMaterialized);
Assert.AreEqual(1, wrapper.ElementCount);
Assert.AreEqual("x", wrapper.GetElement(0).Name);
Assert.AreEqual(new BsonInt32(1), wrapper[0]);
}
示例3: MongoQueryMessage
internal MongoQueryMessage(
string collectionFullName,
QueryFlags flags,
int numberToSkip,
int numberToReturn,
object query,
BsonDocumentWrapper fields
)
: this(collectionFullName, flags, numberToSkip, numberToReturn, query, fields, null)
{
}
示例4: CreateProtocol
// methods
protected override IWireProtocol<BsonDocument> CreateProtocol(IConnectionHandle connection, WriteRequest request)
{
var insertRequest = (InsertRequest)request;
var wrapper = new BsonDocumentWrapper(insertRequest.Document, insertRequest.Serializer);
var documentSource = new BatchableSource<BsonDocument>(new[] { wrapper });
return new InsertWireProtocol<BsonDocument>(
DatabaseName,
CollectionName,
WriteConcern,
BsonDocumentSerializer.Instance,
documentSource,
connection.Description.MaxBatchCount,
connection.Description.MaxMessageSize,
continueOnError: false);
}
示例5: TestTryGetValue
public void TestTryGetValue()
{
var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
Assert.AreEqual(false, wrapper.IsMaterialized);
BsonValue value;
var result = wrapper.TryGetValue("x", out value);
Assert.AreEqual(true, wrapper.IsMaterialized);
Assert.AreEqual(true, result);
Assert.AreEqual(new BsonInt32(1), value);
}
示例6: TestTryGetElement
public void TestTryGetElement()
{
var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
Assert.AreEqual(false, wrapper.IsMaterialized);
BsonElement element;
var result = wrapper.TryGetElement("x", out element);
Assert.AreEqual(true, wrapper.IsMaterialized);
Assert.AreEqual(true, result);
Assert.AreEqual("x", element.Name);
Assert.AreEqual(new BsonInt32(1), element.Value);
}
示例7: TestToString
public void TestToString()
{
var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
Assert.AreEqual(false, wrapper.IsMaterialized);
var expected = "{ 'x' : 1 }".Replace("'", "\"");
var s = wrapper.ToString();
Assert.AreEqual(false, wrapper.IsMaterialized); // ToString just serializes, doesn't materialize
Assert.AreEqual(expected, s);
}
示例8: TestGetValueByName
public void TestGetValueByName()
{
var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
Assert.AreEqual(false, wrapper.IsMaterialized);
var value = wrapper.GetValue("x");
Assert.AreEqual(true, wrapper.IsMaterialized);
Assert.AreEqual(new BsonInt32(1), value);
}
示例9: TestConstructorWithNullNominalTypeAndObjectAndIsUpdateDocument
public void TestConstructorWithNullNominalTypeAndObjectAndIsUpdateDocument()
{
Assert.Throws<ArgumentNullException>(() => { var wrapper = new BsonDocumentWrapper(null, _c, false); });
}
示例10: TestConstructorWithNominalTypeAndObject
public void TestConstructorWithNominalTypeAndObject()
{
var wrapper = new BsonDocumentWrapper(typeof(C), _c);
var expected = "{ \"X\" : 1 }";
Assert.AreEqual(expected, wrapper.ToJson());
}
示例11: TestConstructorWithObject
public void TestConstructorWithObject()
{
var wrapper = new BsonDocumentWrapper(_c);
var expected = "{ \"X\" : 1 }";
Assert.AreEqual(expected, wrapper.ToJson());
}
示例12: TestRawValues
public void TestRawValues()
{
#pragma warning disable 618
var wrapper = new BsonDocumentWrapper(new BsonDocument());
Assert.AreEqual(false, wrapper.IsMaterialized);
var values = wrapper.RawValues.ToArray();
Assert.AreEqual(true, wrapper.IsMaterialized);
Assert.AreEqual(0, values.Length);
wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
Assert.AreEqual(false, wrapper.IsMaterialized);
values = wrapper.RawValues.ToArray();
Assert.AreEqual(true, wrapper.IsMaterialized);
Assert.AreEqual(1, values.Length);
Assert.AreEqual(1, values[0]);
#pragma warning restore
}
示例13: TestNames
public void TestNames()
{
var wrapper = new BsonDocumentWrapper(new BsonDocument());
Assert.AreEqual(false, wrapper.IsMaterialized);
var names = wrapper.Names.ToArray();
Assert.AreEqual(true, wrapper.IsMaterialized);
Assert.AreEqual(0, names.Length);
wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
Assert.AreEqual(false, wrapper.IsMaterialized);
names = wrapper.Names.ToArray();
Assert.AreEqual(true, wrapper.IsMaterialized);
Assert.AreEqual(1, names.Length);
Assert.AreEqual("x", names[0]);
}
示例14: TestMergeOverwrite
public void TestMergeOverwrite()
{
var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
Assert.AreEqual(false, wrapper.IsMaterialized);
var result = wrapper.Merge(new BsonDocument("x", 2), true);
Assert.AreEqual(true, wrapper.IsMaterialized);
Assert.AreSame(wrapper, result);
Assert.AreEqual(1, wrapper.ElementCount);
Assert.AreEqual("x", wrapper.GetElement(0).Name);
Assert.AreEqual(new BsonInt32(2), wrapper[0]);
}
示例15: TestIndexerByName
public void TestIndexerByName()
{
var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
Assert.AreEqual(false, wrapper.IsMaterialized);
var value = wrapper["x"];
Assert.AreEqual(true, wrapper.IsMaterialized);
Assert.AreEqual(new BsonInt32(1), value);
wrapper = new BsonDocumentWrapper(new BsonDocument());
Assert.AreEqual(false, wrapper.IsMaterialized);
wrapper["x"] = 1;
Assert.AreEqual(true, wrapper.IsMaterialized);
Assert.AreEqual(1, wrapper.ElementCount);
Assert.AreEqual("x", wrapper.GetElement(0).Name);
Assert.AreEqual(new BsonInt32(1), wrapper[0]);
}