Esempio n. 1
0
        public static JObject ToJson(this BsonDocument bsonDocument)
        {
            var json = new JObject();

            foreach (var(key, value) in bsonDocument.GetElements())
            {
                switch (value.Type)
                {
                case BsonType.String:
                    json[key] = value.AsString;
                    break;

                case BsonType.Boolean:
                    json[key] = value.AsBoolean;
                    break;

                case BsonType.Int64:
                    json[key] = value.AsInt64;
                    break;

                case BsonType.Double:
                    json[key] = value.AsDouble;
                    break;

                case BsonType.ObjectId:
                    json[key] = value.AsObjectId.ToString();
                    break;
                }
            }

            return(json);
        }
Esempio n. 2
0
 /// <summary>
 /// Get all collections with pageID
 /// </summary>
 public IEnumerable <KeyValuePair <string, uint> > GetCollections()
 {
     foreach (var el in _collections.GetElements())
     {
         yield return(new KeyValuePair <string, uint>(el.Key, (uint)el.Value.AsInt32));
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Write BsonDocument as BSON specs. Returns document bytes count
        /// </summary>
        public int WriteDocument(BsonDocument value, bool recalc)
        {
            var bytesCount = value.GetBytesCount(recalc);

            this.Write(bytesCount);

            foreach (var el in value.GetElements())
            {
                this.WriteElement(el.Key, el.Value);
            }

            this.Write((byte)0x00);

            return(bytesCount);
        }
Esempio n. 4
0
        /// <summary>
        /// Write BsonDocument as BSON specs. Returns document bytes count
        /// </summary>
        public async Task <int> WriteDocument(BsonDocument value, bool recalc)
        {
            var bytesCount = value.GetBytesCount(recalc);

            await this.Write(bytesCount);

            foreach (var el in value.GetElements())
            {
                await this.WriteElement(el.Key, el.Value);
            }

            await this.Write((byte)0x00);

            return(bytesCount);
        }