Example #1
0
        public async Task <List <Fortune> > LoadFortunesRows()
        {
            var result = new List <Fortune>();

            using (var db = await DBConnectionGroupPool.Pop())
            {
                FortuneCommand.Connection = db.Connection;
                using (var rdr = await FortuneCommand.ExecuteReaderAsync(CommandBehavior.Default))
                {
                    while (await rdr.ReadAsync())
                    {
                        result.Add(new Fortune
                        {
                            Id      = rdr.GetInt32(0),
                            Message = rdr.GetString(1)
                        });
                    }
                }
            }
            result.Add(new Fortune {
                Message = "Additional fortune added at request time."
            });
            result.Sort();
            return(result);
        }
Example #2
0
 public async Task <World[]> LoadMultipleQueriesRows(int count)
 {
     using (var db = await DBConnectionGroupPool.Pop())
     {
         return(await LoadMultipleRows(count, db.Connection));
     }
 }
Example #3
0
            static async Task <World[]> LoadUncachedQueries(int id, int i, int count, RawDb rawdb, World[] result)
            {
                using (var db = await DBConnectionGroupPool.Pop())
                {
                    Func <ICacheEntry, Task <CachedWorld> > create = async(entry) =>
                    {
                        return(await rawdb.ReadSingleRow(db.Connection, rawdb.SingleCommand));
                    };

                    var cacheKeys = _cacheKeys;
                    var key       = cacheKeys[id];

                    rawdb.SingleCommand.Connection          = db.Connection;
                    rawdb.SingleCommand.Parameters[0].Value = id;

                    for (; i < result.Length; i++)
                    {
                        var data = await _cache.GetOrCreateAsync <CachedWorld>(key, create);

                        result[i] = data;
                        id        = rawdb._random.Next(1, 10001);
                        rawdb.SingleCommand.Connection          = db.Connection;
                        rawdb.SingleCommand.Parameters[0].Value = id;
                        key = cacheKeys[id];
                    }
                }
                return(result);
            }
Example #4
0
 public async Task <World> LoadSingleQueryRow()
 {
     using (var db = await DBConnectionGroupPool.Pop())
     {
         SingleCommand.Connection          = db.Connection;
         SingleCommand.Parameters[0].Value = _random.Next(1, 10001);
         return(await ReadSingleRow(db.Connection, SingleCommand));
     }
 }
Example #5
0
        public async Task <World[]> LoadMultipleUpdatesRows(int count)
        {
            using (var db = await DBConnectionGroupPool.Pop())
            {
                var updateCmd = UpdateCommandsCached.PopCommand(count);
                try
                {
                    updateCmd.Connection              = db.Connection;
                    SingleCommand.Connection          = db.Connection;
                    SingleCommand.Parameters[0].Value = _random.Next(1, int.MaxValue) % 10000 + 1;
                    var results = new World[count];
                    for (int i = 0; i < count; i++)
                    {
                        results[i] = await ReadSingleRow(db.Connection, SingleCommand);

                        SingleCommand.Parameters[0].Value = _random.Next(1, int.MaxValue) % 10000 + 1;
                    }

                    for (int i = 0; i < count; i++)
                    {
                        var randomNumber = _random.Next(1, int.MaxValue) % 10000 + 1;
                        updateCmd.Parameters[i * 2].Value     = results[i].Id;
                        updateCmd.Parameters[i * 2 + 1].Value = randomNumber;
                        results[i].RandomNumber = randomNumber;
                    }

                    await updateCmd.ExecuteNonQueryAsync();

                    return(results);
                }
                catch (Exception e_)
                {
                    throw e_;
                }
                finally
                {
                    UpdateCommandsCached.PushCommand(count, updateCmd);
                }
            }
        }