| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using CefSharp;
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace UAS_Web.tool
- {
- class MessageFilter : IResponseFilter
- {
- public event Action<byte[]> NotifyData;
- private int contentLength = 0;
- public List<byte> dataAll = new List<byte>();
- public void SetContentLength(int contentLength)
- {
- this.contentLength = contentLength;
- }
- public void Dispose()
- {
-
- }
- public FilterStatus Filter(Stream dataIn, out long dataInRead, Stream dataOut, out long dataOutWritten)
- {
- try
- {
- if (dataIn == null)
- {
- dataInRead = 0;
- dataOutWritten = 0;
- return FilterStatus.Done;
- }
- dataInRead = dataIn.Length;
- dataOutWritten = Math.Min(dataInRead, dataOut.Length);
- dataIn.CopyTo(dataOut);
- dataIn.Seek(0, SeekOrigin.Begin);
- byte[] bs = new byte[dataIn.Length];
- dataIn.Read(bs, 0, bs.Length);
- dataAll.AddRange(bs);
- if (dataAll.Count == this.contentLength)
- {
- // 通过这里进行通知
- NotifyData(dataAll.ToArray());
- return FilterStatus.Done;
- }
- else if (dataAll.Count < this.contentLength)
- {
- dataInRead = dataIn.Length;
- dataOutWritten = dataIn.Length;
- return FilterStatus.NeedMoreData;
- }
- else
- {
- return FilterStatus.Error;
- }
- }
- catch (Exception)
- {
- dataInRead = dataIn.Length;
- dataOutWritten = dataIn.Length;
- return FilterStatus.Done;
- }
- }
- public bool InitFilter()
- {
- return true;
- }
- }
- }
|