updates.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 Task updates(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.LoadMultipleUpdatesRows(count);
  33. await JsonSerializer.NonGeneric.Utf8.SerializeAsync(data, stream);
  34. }
  35. catch (Exception e_)
  36. {
  37. HttpServer.ApiServer.Log(BeetleX.EventArgs.LogType.Error, null, $"updates error {e_.Message}@{e_.StackTrace}");
  38. stream.Write(e_.Message);
  39. }
  40. OnCompleted(stream, session, token);
  41. }
  42. }
  43. }