MessageFilter.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using CefSharp;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. namespace UAS_Web.tool
  6. {
  7. class MessageFilter : IResponseFilter
  8. {
  9. public event Action<byte[]> NotifyData;
  10. private int contentLength = 0;
  11. public List<byte> dataAll = new List<byte>();
  12. public void SetContentLength(int contentLength)
  13. {
  14. this.contentLength = contentLength;
  15. }
  16. public void Dispose()
  17. {
  18. }
  19. public FilterStatus Filter(Stream dataIn, out long dataInRead, Stream dataOut, out long dataOutWritten)
  20. {
  21. try
  22. {
  23. if (dataIn == null || dataIn.Length == 0)
  24. {
  25. dataInRead = 0;
  26. dataOutWritten = 0;
  27. return FilterStatus.Done;
  28. }
  29. dataInRead = dataIn.Length;
  30. dataOutWritten = Math.Min(dataInRead, dataOut.Length);
  31. dataIn.CopyTo(dataOut);
  32. dataIn.Seek(0, SeekOrigin.Begin);
  33. byte[] bs = new byte[dataIn.Length];
  34. dataIn.Read(bs, 0, bs.Length);
  35. dataAll.AddRange(bs);
  36. dataInRead = dataIn.Length;
  37. dataOutWritten = dataIn.Length;
  38. return FilterStatus.NeedMoreData;
  39. }
  40. catch (Exception )
  41. {
  42. dataInRead = dataIn.Length;
  43. dataOutWritten = dataIn.Length;
  44. return FilterStatus.Done;
  45. }
  46. }
  47. public bool InitFilter()
  48. {
  49. return true;
  50. }
  51. }
  52. }