本文整理汇总了C#中MongoDB.Bson.IO.BsonDocumentWriter.WriteName方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocumentWriter.WriteName方法的具体用法?C# BsonDocumentWriter.WriteName怎么用?C# BsonDocumentWriter.WriteName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.BsonDocumentWriter
的用法示例。
在下文中一共展示了BsonDocumentWriter.WriteName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeValue
public static BsonValue SerializeValue(this ISerializationExpression field, object value)
{
Ensure.IsNotNull(field, nameof(field));
var tempDocument = new BsonDocument();
using (var bsonWriter = new BsonDocumentWriter(tempDocument))
{
var context = BsonSerializationContext.CreateRoot(bsonWriter);
bsonWriter.WriteStartDocument();
bsonWriter.WriteName("value");
field.Serializer.Serialize(context, value);
bsonWriter.WriteEndDocument();
return tempDocument[0];
}
}
示例2: SerializeValues
public static BsonArray SerializeValues(this ISerializationExpression field, IEnumerable values)
{
var tempDocument = new BsonDocument();
using (var bsonWriter = new BsonDocumentWriter(tempDocument))
{
var context = BsonSerializationContext.CreateRoot(bsonWriter);
bsonWriter.WriteStartDocument();
bsonWriter.WriteName("values");
bsonWriter.WriteStartArray();
foreach (var value in values)
{
field.Serializer.Serialize(context, value);
}
bsonWriter.WriteEndArray();
bsonWriter.WriteEndDocument();
return (BsonArray)tempDocument[0];
}
}
示例3: ConvertStoreDataToBsonDocument
/// <summary>
///
/// </summary>
/// <param name="storeData"></param>
/// <returns></returns>
private static BsonDocument ConvertStoreDataToBsonDocument(SessionStateStoreData storeData)
{
var items = storeData.Items;
var document = new BsonDocument();
var documentWriterSettings = new BsonDocumentWriterSettings();
var documentWriter = new BsonDocumentWriter(document, documentWriterSettings);
documentWriter.WriteStartDocument();
foreach (string key in items.Keys) {
var value = items[key];
documentWriter.WriteName(key);
BsonSerializer.Serialize(documentWriter, value.GetType(), value);
}
documentWriter.WriteEndDocument();
return document;
}
示例4: SetPropertyValues
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection values)
{
if (context == null) {
throw TraceException("SetPropertyValues", new ArgumentNullException("context"));
}
if (values == null) {
throw TraceException("SetPropertyValues", new ArgumentNullException("values"));
}
var userName = (string) context["UserName"];
var isAuthenticated = (bool) context["IsAuthenticated"];
if (string.IsNullOrWhiteSpace(userName) || values.Count == 0) {
return;
}
var updateValues = (from SettingsPropertyValue value in values
let allowAnonymous = value.Property.Attributes["AllowAnonymous"].Equals(true)
where (value.IsDirty || !value.UsingDefaultValue) && (isAuthenticated || allowAnonymous)
select value).ToList();
// If there are no values to update, then we're done here.
if (updateValues.Count == 0) {
return;
}
// If the user doesn't exist, and it's anonymous, create it.
var user = GetMongoUser(userName);
if (user == null) {
if (!isAuthenticated) {
user = new MongoMembershipUser {
UserName = userName,
IsAnonymous = true,
CreationDate = DateTime.Now,
};
try {
var users = GetUserCollection();
users.Insert(user);
}
catch (MongoSafeModeException e) {
var message = ProviderResources.CouldNotCreateUser;
throw TraceException("SetPropertyValues", new ProviderException(message, e));
}
} else {
var message = ProviderResources.CouldNotFindUser;
throw TraceException("SetPropertyValues", new ProviderException(message));
}
}
// Create the properties BSON document.
var properties = new BsonDocument();
var propertiesWriterSettings = new BsonDocumentWriterSettings();
var propertiesWriter = new BsonDocumentWriter(properties, propertiesWriterSettings);
propertiesWriter.WriteStartDocument();
foreach (var value in updateValues) {
propertiesWriter.WriteName(value.Name);
switch (value.Property.SerializeAs) {
case SettingsSerializeAs.String:
case SettingsSerializeAs.Xml:
BsonSerializer.Serialize(propertiesWriter, typeof (string), value.SerializedValue);
break;
case SettingsSerializeAs.Binary:
BsonSerializer.Serialize(propertiesWriter, typeof (byte[]), value.SerializedValue);
break;
case SettingsSerializeAs.ProviderSpecific:
BsonSerializer.Serialize(propertiesWriter, value.Property.PropertyType, value.PropertyValue);
break;
default:
throw TraceException("SetPropertyValues", new ArgumentOutOfRangeException());
}
}
propertiesWriter.WriteEndDocument();
// Create the profile BSON document.
var profile = SerializationHelper.Serialize(typeof (MongoProfile), new MongoProfile {
Properties = properties,
LastActivityDate = DateTime.Now,
LastUpdateDate = DateTime.Now
});
try {
var query = Query.EQ("UserName", userName);
var update = Update.Set("Profile", profile);
var users = GetUserCollection();
users.Update(query, update);
} catch (MongoSafeModeException e) {
var message = ProviderResources.CouldNotUpdateProfile;
throw TraceException("SetPropertyValues", new ProviderException(message, e));
}
}
示例5: SerializeValue
/// <summary>
/// Serializes the value.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The serialized value.</returns>
public BsonValue SerializeValue(object value)
{
var tempDocument = new BsonDocument();
using (var bsonWriter = new BsonDocumentWriter(tempDocument))
{
var context = BsonSerializationContext.CreateRoot<BsonDocument>(bsonWriter);
bsonWriter.WriteStartDocument();
bsonWriter.WriteName("value");
context.SerializeWithChildContext(_serializer, value);
bsonWriter.WriteEndDocument();
return tempDocument[0];
}
}
示例6: SerializeValues
/// <summary>
/// Serializes the values.
/// </summary>
/// <param name="values">The values.</param>
/// <returns>The serialized values.</returns>
public BsonArray SerializeValues(IEnumerable values)
{
var tempDocument = new BsonDocument();
using (var bsonWriter = new BsonDocumentWriter(tempDocument))
{
var context = BsonSerializationContext.CreateRoot<BsonDocument>(bsonWriter);
bsonWriter.WriteStartDocument();
bsonWriter.WriteName("values");
bsonWriter.WriteStartArray();
foreach (var value in values)
{
context.SerializeWithChildContext(_serializer, value);
}
bsonWriter.WriteEndArray();
bsonWriter.WriteEndDocument();
return tempDocument[0].AsBsonArray;
}
}