HttpHandler.queries.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using BeetleX;
  2. using BeetleX.Buffers;
  3. using SpanJson;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace PlatformBenchmarks
  9. {
  10. public partial class HttpHandler
  11. {
  12. public async ValueTask queries(string queryString, PipeStream stream, HttpToken token, ISession session)
  13. {
  14. int count = 1;
  15. if(!string.IsNullOrEmpty(queryString))
  16. {
  17. var values = queryString.Split('=');
  18. if(values.Length>1)
  19. {
  20. if(int.TryParse(values[1],out int size))
  21. {
  22. count = size;
  23. }
  24. }
  25. }
  26. if (count > 500)
  27. count = 500;
  28. if (count < 1)
  29. count = 1;
  30. try
  31. {
  32. var data = await token.Db.LoadMultipleQueriesRows(count);
  33. stream.Write(_jsonResultPreamble.Data, 0, _jsonResultPreamble.Length);
  34. token.ContentLength = stream.Allocate(HttpHandler._LengthSize);
  35. GMTDate.Default.Write(stream);
  36. token.ContentPostion = stream.CacheLength;
  37. System.Text.Json.JsonSerializer.Serialize(GetUtf8JsonWriter(stream, token), data, SerializerOptions);
  38. }
  39. catch (Exception e_)
  40. {
  41. stream.Write(e_.Message);
  42. }
  43. OnCompleted(stream, session, token);
  44. }
  45. }
  46. }