private void ExecuteError(int errcode, string errmessage) { try { System.Diagnostics.Debug.WriteLine("GeoLocation.ExecuteError"); System.Func <Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue> _func = _funcError as System.Func <Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue>; Jint.Native.Function.ScriptFunctionInstance JintScript = _func.Target as Jint.Native.Function.ScriptFunctionInstance; Jint.Engine _JintEngine = JintScript.Engine; JsValue A = new JsValue(1); JsValue[] B = new Jint.Native.JsValue[1]; Jint.Native.Json.JsonParser _jsp = new Jint.Native.Json.JsonParser(_JintEngine); String FormatString = "{{\"code\":{0}, \"message\":\"{1}\"}}"; String Error = String.Format(FormatString, errcode, errmessage); B[0] = _jsp.Parse(Error); _func.Invoke(A, B); } catch (Exception exp) { System.Diagnostics.Debug.WriteLine("Exception" + exp.Message); } }
private void ExecuteSuccess(Geoposition _pos) { try { System.Diagnostics.Debug.WriteLine("GeoLocation.ExecuteSuccess"); System.Func <Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue> _func = _funcSuccess as System.Func <Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue>; Jint.Native.Function.ScriptFunctionInstance JintScript = _func.Target as Jint.Native.Function.ScriptFunctionInstance; Jint.Engine _JintEngine = JintScript.Engine; JsValue A = new JsValue(1); JsValue[] B = new JsValue[1]; Jint.Native.Json.JsonParser _jsp = new Jint.Native.Json.JsonParser(_JintEngine); String FormatString = "{{\"coords\":{{\"latitude\":{0}, \"longitude\":{1}}}}}"; String Coordinates = String.Format(FormatString, _pos.Coordinate.Latitude, _pos.Coordinate.Longitude); B[0] = _jsp.Parse(Coordinates); _func.Invoke(A, B); } catch (Jint.Runtime.JavaScriptException exc) { System.Diagnostics.Debug.WriteLine("JavaScriptException" + exc.Message + " " + exc.LineNumber); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception" + e.Message); ExecuteError(e.HResult, e.Message); } }