예제 #1
0
        static void OnJavaScriptNativeMap(IWebBrowser browser, JsQueryEventArgs args)
        {
            MapResult result = null;
            var       info   = This.GetBrowserInfo(browser);

            try
            {
                var json    = args.Request;
                var mapInfo = JsonConvert.DeserializeObject <MapActionInfo>(json);
                var context = new JsNativeInvokeContext(info, mapInfo, (typeName) => NativeTypeDic.ContainsKey(typeName) ? NativeTypeDic[typeName] : null);
                result = JsNativeInvokeHandleFactory.This.CreateHandle(context).Handle();
                if (result == null)
                {
                    browser.ResponseJsQuery(args.WebView, args.QueryId, args.CustomMsg, "OK");
                    return;
                }
                var resultJson = JsonConvert.SerializeObject(result);
                browser.ResponseJsQuery(args.WebView, args.QueryId, args.CustomMsg, resultJson);
            }
            catch (Exception ex)
            {
                if (result != null && result.Data.DataType == MapDataType.NativeObjectId)
                {
                    info.DestroyNativeObject(((NativeObjectInfo)result.Data.Value).Id, false);
                }
                result = new MapResult {
                    Status = false, Data = new MapDataInfo {
                        DataType = MapDataType.Value, Value = ex.Message
                    }
                };
                var resultJson = JsonConvert.SerializeObject(result).Replace("\\r", "").Replace("\\n", "");
                browser.ResponseJsQuery(args.WebView, args.QueryId, args.CustomMsg, resultJson);
            }
        }
 public IJsNavateInvokeHandle CreateHandle(JsNativeInvokeContext context)
 {
     if (HandleCreaterMap.ContainsKey(context.MapInfo.Action))
     {
         return(HandleCreaterMap[context.MapInfo.Action](context));
     }
     throw new InvalidOperationException($"处理器{context.MapInfo.Action}无法创建,该处理器构建器未在工厂注册");
 }
 internal TneEventRemoveListenerHandle(JsNativeInvokeContext context) : base(context)
 {
 }
 internal GetAccessHandle(JsNativeInvokeContext context) : base(context)
 {
 }
 public StaticInvokeHandle(JsNativeInvokeContext context) : base(context)
 {
 }
 protected ObjectInvokeHandle(JsNativeInvokeContext context)
 {
     this.Context = context;
 }
 public CreateInvokeHandle(JsNativeInvokeContext context)
 {
     this._context = context;
 }