updates.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using BeetleX;
  2. using BeetleX.Buffers;
  3. using SpanJson;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. namespace PlatformBenchmarks
  8. {
  9. public partial class HttpHandler
  10. {
  11. public async void updates(string queryString, PipeStream stream, HttpToken token, ISession session)
  12. {
  13. int count = 1;
  14. if (!string.IsNullOrEmpty(queryString))
  15. {
  16. var values = queryString.Split('=');
  17. if (values.Length > 1)
  18. {
  19. if (int.TryParse(values[1], out int size))
  20. {
  21. count = size;
  22. }
  23. }
  24. }
  25. if (count > 500)
  26. count = 500;
  27. if (count < 1)
  28. count = 1;
  29. try
  30. {
  31. var data = await token.Db.LoadMultipleUpdatesRows(count);
  32. await JsonSerializer.NonGeneric.Utf8.SerializeAsync(data, stream);
  33. }
  34. catch (Exception e_)
  35. {
  36. HttpServer.ApiServer.Log(BeetleX.EventArgs.LogType.Error, null, $"updates error {e_.Message}@{e_.StackTrace}");
  37. stream.Write(e_.Message);
  38. }
  39. OnCompleted(stream, session, token);
  40. }
  41. }
  42. }