internal DjondbCursor(Command cmd, string cursorId, BSONArrayObj arr) { // TODO: Complete member initialization this._command = cmd; this._cursorId = cursorId; this._rows = arr; if (_rows == null) { _rows = new BSONArrayObj(); } this._pos = 0; this._current = null; if (this._rows == null) { this._count = 0; } else { this._count = this._rows.Count; } if (cursorId != null) { this._status = CursorStatus.CS_LOADING; } else { this._status = CursorStatus.CS_RECORDS_LOADED; } }
private void WriteBSONArray(BSONArrayObj ar) { long elements = ar.Count; WriteLong(elements); foreach (BSONObj o in ar) { WriteBSON(o); } }
private BSONArrayObj ReadResultFetchRecords() { int flag = this._network.ReadInt32(); BSONArrayObj result = null; if (flag == 1) { result = this._network.ReadBSONArray(); } readErrorInformation(); return(result); }
public BSONArrayObj ReadBSONArray() { long elements = ReadLong(); BSONArrayObj res = new BSONArrayObj(); for (long x = 0; x < elements; x++) { BSONObj o = ReadBSON(); res.Add(o); } return(res); }
private DjondbCursor ReadResultFind() { string cursorId = this._network.ReadString(); int flag = this._network.ReadInt32(); DjondbCursor cursor = null; BSONArrayObj arr = null; if (flag == 1) { arr = _network.ReadBSONArray(); } cursor = new DjondbCursor(this, cursorId, arr); readErrorInformation(); return(cursor); }
private bool InternalNext() { if (_status == CursorStatus.CS_CLOSED) { throw new ApplicationException("Cursor is Closed"); } bool result = true; if (_count > _pos) { _current = _rows[_pos]; _pos++; } else { if (_status == CursorStatus.CS_LOADING) { BSONArrayObj page = _command.FetchRecords(_cursorId); if (page == null) { _status = CursorStatus.CS_RECORDS_LOADED; result = false; } else { _rows.Add(page); _count += page.Count; result = InternalNext(); } } else { result = false; } } return(result); }
public void Add(BSONArrayObj arr) { _array.AddRange(arr); }
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); }
internal void WriteBSON(BSONObj bSONObj) { WriteLong(bSONObj.Count); foreach (KeyValuePair <string, object> kv in bSONObj) { WriteString(kv.Key); object val = kv.Value; Int32? i = val as Int32?; if (i != null) { WriteLong(0); WriteInt32((int)i); } else { long?l = val as long?; if (l != null) { WriteLong(2); WriteLong((long)l); } else { float?f = val as float?; if (f != null) { WriteLong(1); WriteDouble(Convert.ToDouble(f)); } else { string s = val as string; if (s != null) { WriteLong(4); WriteString(s); } else { BSONObj bObj = val as BSONObj; if (bObj != null) { WriteLong(5); WriteBSON(bObj); } else { bool?b = val as bool?; if (b != null) { WriteLong(10); WriteBoolean((bool)b); } else { BSONArrayObj ar = val as BSONArrayObj; if (ar != null) { WriteLong(6); WriteBSONArray(ar); } else { double?d = val as double?; if (d != null) { WriteLong(1); WriteDouble((double)d); } else { throw new ApplicationException("Unknown data type"); } } } } } } } } } }