Exemplo n.º 1
0
 public string Eval(ScopedCode code, params string[] args)
 {
     var cmd = new Command("$eval", code) { { "args", args } };
       return ExecuteCommand(cmd)["retval"] as string;
 }
Exemplo n.º 2
0
 public Doc ReadDoc()
 {
     var doc = new Doc();
       ReadInt32(); //size (ignored)
       while(true)
       {
     var type = (BsonType)ReadByte();
     if (type == BsonType.EOO)
     {
       return doc;
     }
     var name = ReadShortString();
     object o = null;
     switch (type)
     {
       case BsonType.NUMBER:
     o = ReadDouble();
     break;
       case BsonType.STRING:
     o = ReadString(ReadInt32());
     break;
       case BsonType.OBJECT:
     o = ReadDoc();
     break;
       case BsonType.ARRAY:
     o = ReadDoc().ToList();
     break;
       case BsonType.BINARY:
     var count = ReadInt32();
     ReadByte(); //TODO: handle 'subtype'
     o = ReadBytes(count);
     break;
       case BsonType.UNDEFINED:
     break;
       case BsonType.OID:
     o = ReadObjectId();
     break;
       case BsonType.BOOLEAN:
     o = ReadBoolean();
     break;
       case BsonType.DATE:
     o = ReadDate();
     break;
       case BsonType.NULL:
     break;
       case BsonType.REGEX:
     o = new Regex(ReadShortString());
     ReadShortString(); //TODO: options
     break;
       case BsonType.REF:
     o = ReadDBRef();
     break;
       case BsonType.CODE:
     o = new Code(ReadString(ReadInt32()));
     break;
       case BsonType.SYMBOL:
     o = new Symbol(ReadString(ReadInt32()));
     break;
       case BsonType.CODE_W_SCOPE:
     ReadInt32();
     o = new ScopedCode(ReadString(ReadInt32()), ReadDoc());
     break;
       case BsonType.NUMBER_INT:
     o = ReadInt32();
     break;
       case BsonType.TIMESTAMP:
     o = new TimeStamp(ReadInt64());
     break;
       case BsonType.NUMBER_LONG:
     o = ReadInt64();
     break;
       case BsonType.MINKEY:
     break;
       case BsonType.MAXKEY:
     break;
       default:
     break;
     }
     doc.Add(name, o);
       }
 }