private void RetrieveData() { QueryMessage query = new QueryMessage(); query.FullCollectionName = this.FullCollectionName; query.Query = BuildSpec(); query.NumberToReturn = this.limit; query.NumberToSkip = this.skip; query.Options = options; if(this.fields != null){ query.ReturnFieldSelector = this.fields; } try{ this.reply = connection.SendTwoWayMessage(query); this.id = this.reply.CursorID; if(this.limit < 0)this.limit = this.limit * -1; }catch(IOException ioe){ throw new MongoCommException("Could not read data, communication failure", this.connection,ioe); } }
private void RetrieveMoreData() { GetMoreMessage gmm = new GetMoreMessage(this.fullCollectionName, this.Id, this.limit); try{ this.reply = connection.SendTwoWayMessage(gmm); this.id = this.reply.CursorID; }catch(IOException ioe){ this.id = 0; throw new MongoCommException("Could not read data, communication failure", this.connection,ioe); } }
/// <summary> /// Used for sending a message that gets a reply such as a query. /// </summary> /// <param name="msg"></param> /// <returns></returns> /// <exception cref="IOException">A reconnect will be issued but it is up to the caller to handle the error.</exception> public ReplyMessage SendTwoWayMessage(IRequestMessage msg) { if (this.State != ConnectionState.Opened) { throw new MongoCommException ("Operation cannot be performed on a closed connection.", this); } try { ReplyMessage reply = new ReplyMessage (); lock (_connection) { msg.Write (_connection.GetStream ()); reply.Read (_connection.GetStream ()); } return reply; } catch (IOException) { ReplaceInvalidConnection (); throw; } }