public BucketKeysEnumerator(string dbName, string colName, string queryString, NodeContext context) { _dbName = dbName; _colName = colName; if (context != null) { _databasesManager = context.DatabasesManager; } Alachisoft.NosDB.Common.Server.Engine.Impl.Query query = new Alachisoft.NosDB.Common.Server.Engine.Impl.Query(); query.QueryText = queryString; Alachisoft.NosDB.Common.Server.Engine.Impl.ReadQueryOperation readQueryOperation = new Alachisoft.NosDB.Common.Server.Engine.Impl.ReadQueryOperation(); readQueryOperation.Database = dbName; readQueryOperation.Collection = colName; readQueryOperation.Query = query; if (_databasesManager != null) { response = _databasesManager.ExecuteReader(readQueryOperation); } if (response == null || !response.IsSuccessfull) { throw new Exception(Common.ErrorHandling.ErrorMessages.GetErrorMessage(response.ErrorCode) + ":Query failed on collection" + colName); } if (response != null && response.DataChunk != null && response.DataChunk.Documents != null && response.DataChunk.Documents.Count > 0) { lastDataChunk = response.DataChunk; isLastChunk = response.DataChunk.IsLastChunk; this.dataChunkEnumerator = response.DataChunk.Documents.GetEnumerator(); } }
public bool MoveNext() { if (dataChunkEnumerator == null) { return(false); } if (dataChunkEnumerator.MoveNext()) { try { Alachisoft.NosDB.Common.JSONDocument document = dataChunkEnumerator.Current as Alachisoft.NosDB.Common.JSONDocument; StateTransferKey stateTxferKey = document.Parse <StateTransferKey>(); currentKey = stateTxferKey != null ? stateTxferKey.DocKey : null; return(true); } catch (Exception ex) { return(false); } } else { if (this.isLastChunk) { return(false); } else { Alachisoft.NosDB.Common.Server.Engine.Impl.GetChunkOperation getChunkOperation = new Alachisoft.NosDB.Common.Server.Engine.Impl.GetChunkOperation(); getChunkOperation.Database = this._dbName; getChunkOperation.Collection = this._colName; getChunkOperation.ReaderUID = lastDataChunk.ReaderUID; getChunkOperation.LastChunkId = lastDataChunk.ChunkId; Alachisoft.NosDB.Common.Server.Engine.Impl.GetChunkResponse getChunkResponse = null; try { if (_databasesManager != null) { getChunkResponse = (Alachisoft.NosDB.Common.Server.Engine.Impl.GetChunkResponse)_databasesManager.GetDataChunk(getChunkOperation); } } catch (Exception) { return(false); } if (getChunkResponse != null && getChunkResponse.IsSuccessfull) { this.lastDataChunk = getChunkResponse.DataChunk; this.isLastChunk = lastDataChunk.IsLastChunk; this.dataChunkEnumerator = lastDataChunk.Documents.GetEnumerator(); if (dataChunkEnumerator.MoveNext()) { try { Alachisoft.NosDB.Common.JSONDocument document = dataChunkEnumerator.Current as Alachisoft.NosDB.Common.JSONDocument; StateTransferKey stateTxferKey = document.Parse <StateTransferKey>(); currentKey = stateTxferKey != null ? stateTxferKey.DocKey : null; return(true); } catch (Exception ex) { return(false); } } } else { return(false); } } } return(false); }