public void WriteResult(IBsonDataReader result, Env env) { var index = 0; var writer = new JsonWriter(Console.Out) { Pretty = this.Pretty, Indent = 2 }; foreach (var item in result.ToEnumerable()) { if (env.Running == false) { return; } this.Write(ConsoleColor.Cyan, string.Format("[{0}]: ", ++index)); if (this.Pretty) { Console.WriteLine(); } Console.ForegroundColor = ConsoleColor.DarkCyan; writer.Serialize(item); Console.WriteLine(); } }
public static IEnumerable <BsonValue> ToEnumerable(this IBsonDataReader reader) { while (reader.Read()) { yield return(reader.Current); } }
public DataTable Convert(IBsonDataReader reader) { DataRow dataRow = null; bool isArrayField = false; _dataTable = new DataTable(); // Populate datatable while (reader.Read()) { if (_dataTable.Columns.Count == 0) { // Add columns to table foreach (var keyValuePair in (BsonDocument)reader.Current) { if (keyValuePair.Value.Type == BsonType.Array) { _dataTable.Columns.Add(new DataColumn(keyValuePair.Key, typeof(String))); } else { _dataTable.Columns.Add(new DataColumn(keyValuePair.Key, keyValuePair.Value.Type.ToSystemType())); } } } dataRow = _dataTable.NewRow(); // Populate new row with data foreach (var keyValuePair in (BsonDocument)reader.Current) { if (keyValuePair.Value.Type == BsonType.Array) { ProcessArrayField(keyValuePair.Key, keyValuePair.Value); isArrayField = true; } else { dataRow[keyValuePair.Key] = keyValuePair.Value.RawValue; } } // Add row to table if (isArrayField == false) { _dataTable.Rows.Add(dataRow); _dataTable.AcceptChanges(); } } return(_dataTable); }
public static IEnumerable <BsonValue> ToEnumerable(this IBsonDataReader reader) { try { while (reader.Read()) { yield return(reader.Current); } } finally { reader.Dispose(); } }
public static async IAsyncEnumerable <BsonValue> ToAsyncEnumerable(this IBsonDataReader reader) { try { while (await reader.ReadAsync()) { yield return(reader.Current); } } finally { await reader.DisposeAsync(); } }
public void ReadResult(IBsonDataReader reader) { this.Result = new List <BsonValue>(); this.LimitExceeded = false; this.Collection = reader.Collection; var index = 0; while (reader.Read()) { if (index++ >= ResultLimit && ResultLimit > 0) { this.LimitExceeded = true; break; } this.Result.Add(reader.Current); } }
public void ReadResult(IBsonDataReader reader) { Result = new List <BsonValue>(); LimitExceeded = false; Collection = reader.Collection; var index = 0; while (reader.Read()) { if (index++ >= RESULT_LIMIT) { LimitExceeded = true; break; } Result.Add(reader.Current); } }
public static IEnumerable <BsonValue> ToEnumerable(this IBsonDataReader reader) { IEnumerable <BsonValue> _() { while (reader.Read()) { yield return(reader.Current); } reader.Dispose(); }; try { return(_()); } catch { reader.Dispose(); throw; } }
public static BsonValue SingleOrDefault(this IBsonDataReader reader) => ToEnumerable(reader).SingleOrDefault();
public static BsonValue FirstOrDefault(this IBsonDataReader reader) => ToEnumerable(reader).FirstOrDefault();
public static IList <BsonValue> ToList(this IBsonDataReader reader) => ToEnumerable(reader).ToList();
public static BsonValue[] ToArray(this IBsonDataReader reader) => ToEnumerable(reader).ToArray();
public SharedDataReader(IBsonDataReader reader, Action dispose) { _reader = reader; _dispose = dispose; }