Пример #1
0
        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();
            }
        }
Пример #2
0
 public static IEnumerable <BsonValue> ToEnumerable(this IBsonDataReader reader)
 {
     while (reader.Read())
     {
         yield return(reader.Current);
     }
 }
Пример #3
0
        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();
     }
 }
Пример #5
0
 public static async IAsyncEnumerable <BsonValue> ToAsyncEnumerable(this IBsonDataReader reader)
 {
     try
     {
         while (await reader.ReadAsync())
         {
             yield return(reader.Current);
         }
     }
     finally
     {
         await reader.DisposeAsync();
     }
 }
Пример #6
0
        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);
            }
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
        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();
Пример #13
0
 public SharedDataReader(IBsonDataReader reader, Action dispose)
 {
     _reader  = reader;
     _dispose = dispose;
 }