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


C# BsonDocumentWriter.WriteName方法代码示例

本文整理汇总了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];
            }
        }
开发者ID:robblovell,项目名称:mongo-csharp-driver,代码行数:15,代码来源:ISerializationExpression.cs

示例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];
            }
        }
开发者ID:robblovell,项目名称:mongo-csharp-driver,代码行数:19,代码来源:ISerializationExpression.cs

示例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;
 }
开发者ID:cdmckay,项目名称:mongodb-aspnet-providers,代码行数:20,代码来源:MongoSessionStateStore.cs

示例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));
            }
        }
开发者ID:cdmckay,项目名称:mongodb-aspnet-providers,代码行数:91,代码来源:MongoProfileProvider.cs

示例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];
     }
 }
开发者ID:Bogdan0x400,项目名称:mongo-csharp-driver,代码行数:18,代码来源:BsonSerializationInfo.cs

示例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;
            }
        }
开发者ID:Bogdan0x400,项目名称:mongo-csharp-driver,代码行数:24,代码来源:BsonSerializationInfo.cs


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