コード例 #1
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);
                }
            }
        }
コード例 #2
0
        public virtual void OnStartLine(ReadOnlySpan <byte> http, ReadOnlySpan <byte> method, ReadOnlySpan <byte> url, ISession session, HttpToken token, PipeStream stream)
        {
            if (!Program.Debug)
            {
                UpdateCommandsCached.Init();
                if (Program.UpDB)
                {
                    DBConnectionGroupPool.Init(64, RawDb._connectionString);
                }
                else
                {
                    DBConnectionGroupPool.Init(256, RawDb._connectionString);
                }
            }
            int queryIndex = AnalysisUrl(url);
            ReadOnlySpan <byte> baseUrl     = default;
            ReadOnlySpan <byte> queryString = default;

            if (queryIndex > 0)
            {
                baseUrl     = url.Slice(0, queryIndex);
                queryString = url.Slice(queryIndex + 1, url.Length - queryIndex - 1);
            }
            else
            {
                baseUrl = url;
            }
            OnWriteHeader(stream, token);
            if (baseUrl.Length == _path_Plaintext.Length && baseUrl.StartsWith(_path_Plaintext))
            {
                stream.Write(_headerContentTypeText.Data, 0, _headerContentTypeText.Length);
                OnWriteContentLength(stream, token);
                Plaintext(url, stream, token, session);
            }
            else if (baseUrl.Length == _path_Json.Length && baseUrl.StartsWith(_path_Json))
            {
                stream.Write(_headerContentTypeJson.Data, 0, _headerContentTypeJson.Length);
                OnWriteContentLength(stream, token);
                Json(url, stream, token, session);
            }
            else if (baseUrl.Length == _path_Db.Length && baseUrl.StartsWith(_path_Db))
            {
                stream.Write(_headerContentTypeJson.Data, 0, _headerContentTypeJson.Length);
                OnWriteContentLength(stream, token);
                db(stream, token, session);
            }
            else if (baseUrl.Length == _path_Queries.Length && baseUrl.StartsWith(_path_Queries))
            {
                stream.Write(_headerContentTypeJson.Data, 0, _headerContentTypeJson.Length);
                OnWriteContentLength(stream, token);
                queries(Encoding.ASCII.GetString(queryString), stream, token, session);
            }

            else if (baseUrl.Length == _cached_worlds.Length && baseUrl.StartsWith(_cached_worlds))
            {
                stream.Write(_headerContentTypeJson.Data, 0, _headerContentTypeJson.Length);
                OnWriteContentLength(stream, token);
                caching(Encoding.ASCII.GetString(queryString), stream, token, session);
            }

            else if (baseUrl.Length == _path_Updates.Length && baseUrl.StartsWith(_path_Updates))
            {
                stream.Write(_headerContentTypeJson.Data, 0, _headerContentTypeJson.Length);
                OnWriteContentLength(stream, token);
                updates(Encoding.ASCII.GetString(queryString), stream, token, session);
            }
            else if (baseUrl.Length == _path_Fortunes.Length && baseUrl.StartsWith(_path_Fortunes))
            {
                stream.Write(_headerContentTypeHtml.Data, 0, _headerContentTypeHtml.Length);
                OnWriteContentLength(stream, token);
                fortunes(stream, token, session);
            }
            else
            {
                stream.Write(_headerContentTypeHtml.Data, 0, _headerContentTypeHtml.Length);
                OnWriteContentLength(stream, token);
                Default(url, stream, token, session);
            }
        }