升级到最新版本后,过滤器无法按预期工作

时间:2018-09-20 13:48:04

标签: c# cefsharp

我正在通过以下方式捕获v-bind: placeholder

JSON

要使用捕获过滤器,我要做的事情:

    public IResponseFilter GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response)
    {
        if (request.Url.ToLower().Contains("myurl") )
        {
            return Filters.CreateFilter(request.Identifier.ToString());
        }

        return null;
    }

我的 public void OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength) { if (request.Url.ToLower().Contains("myurl")) { if (Filters.GetFilter(request.Identifier.ToString()) is JsonFilter filter) { //Do something and remove filter... Filters.DeleteFilter(request.Identifier.ToString()); } } } 实现是:

IResponseFilter

以上内容适用于class Filters { private static ConcurrentDictionary<string, IResponseFilter> dataList = new ConcurrentDictionary<string, IResponseFilter>(); public static IResponseFilter CreateFilter(string guid) { var filter = new JsonFilter(); dataList.TryAdd(guid, filter); return filter; } public static IResponseFilter GetFilter(string guid) { return dataList[guid]; } public static void DeleteFilter(string guid) { dataList.TryRemove(guid, out IResponseFilter filter); } } internal class JsonFilter : IResponseFilter { public List<byte> DataAll = new List<byte>(); public FilterStatus Filter(Stream dataIn, out long dataInRead, Stream dataOut, out long dataOutWritten) { try { if (dataIn == null || dataIn.Length == 0) { 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); dataInRead = dataIn.Length; dataOutWritten = dataIn.Length; return FilterStatus.NeedMoreData; } catch { dataInRead = dataIn.Length; dataOutWritten = dataIn.Length; return FilterStatus.Done; } } public bool InitFilter() { return true; } public void Dispose() { } } 的旧版本。但是,现在我在cefSharp上遇到了异常,因为在字典中找不到过滤器。

在较新的版本中发生了更改,还是我的实现不够可靠?

0 个答案:

没有答案