示例#1
0
        private void WriteOptions()
        {
            BSONObj o = new BSONObj();

            if (_activeTransaction != null)
            {
                o.add("_transactionId", _activeTransaction);
            }
            this._network.WriteBSON(o);
        }
示例#2
0
        public BSONObj ReadBSON()
        {
            BSONObj o        = new BSONObj();
            long    elements = ReadLong();

            for (long x = 0; x < elements; x++)
            {
                string key  = ReadString();
                long   type = ReadLong();
                switch (type)
                {
                case 0:
                    o.add(key, ReadInt32());
                    break;

                case 1:
                    o.add(key, ReadDouble());
                    break;

                case 2:
                    o.add(key, ReadLong());
                    break;

                case 4:
                    o.add(key, ReadString());
                    break;

                case 5:
                    o.add(key, ReadBSON());
                    break;

                case 6:
                    o.add(key, ReadBSONArray());
                    break;

                case 10:
                    o.add(key, ReadBoolean());
                    break;

                default:
                    throw new ApplicationException("Type not supported");
                }
            }
            return(o);
        }
示例#3
0
        public DjondbCursor ExecuteQuery(string query)
        {
            this._network.Reset();
            this._network.WriteHeader();
            this._network.WriteInt32((int)CommandType.EXECUTEQUERY);
            WriteOptions();
            this._network.WriteString(query);
            this._network.Flush();

            int          flag   = this._network.ReadInt32();
            DjondbCursor cursor = null;

            if (flag == 1)
            {
                CommandType commandType = (CommandType)this._network.ReadInt32();
                switch (commandType)
                {
                case CommandType.INSERT:
                    ReadResultInsert();
                    break;

                case CommandType.BACKUP:
                    ReadResultBackup();
                    break;

                case CommandType.COMMIT:
                    ReadResultCommit();
                    break;

                case CommandType.CREATEINDEX:
                    ReadResultCreateIndex();
                    break;

                case CommandType.DROPNAMESPACE:
                    ReadResultDropNamespace();
                    break;

                case CommandType.FIND:
                    cursor = ReadResultFind();
                    break;

                case CommandType.REMOVE:
                    ReadResultRemove();
                    break;

                case CommandType.ROLLBACK:
                    ReadResultRollbackTransaction();
                    break;

                case CommandType.SHOWDBS:
                    string[]     dbs    = ReadResultShowDbs();
                    BSONArrayObj arrDbs = new BSONArrayObj();
                    foreach (string db in dbs)
                    {
                        BSONObj o = new BSONObj();
                        o.add("db", db);
                        arrDbs.Add(o);
                    }
                    cursor = new DjondbCursor(this, null, arrDbs);
                    break;

                case CommandType.SHOWNAMESPACES:
                    string[]     nss   = ReadResultShowNameSpaces();
                    BSONArrayObj arrNs = new BSONArrayObj();
                    foreach (string ns in nss)
                    {
                        BSONObj o = new BSONObj();
                        o.add("ns", ns);
                        arrNs.Add(o);
                    }
                    cursor = new DjondbCursor(this, null, arrNs);
                    break;

                case CommandType.UPDATE:
                    ReadResultUpdate();
                    break;
                }
            }
            if (cursor == null)
            {
                BSONArrayObj arr    = new BSONArrayObj();
                BSONObj      result = new BSONObj();
                result.add("date", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss:nn"));
                result.add("success", true);
                arr.Add(result);
                cursor = new DjondbCursor(this, null, arr);
            }
            readErrorInformation();
            return(cursor);
        }