/// <summary> /// Handles command execution result. /// </summary> /// <param name="callbackId">Command callback identifier on client side</param> /// <param name="result">Execution result</param> private void OnCommandResult(string callbackId, PluginResult result) { #region args checking if (result == null) { Debug.WriteLine("ERROR: OnCommandResult missing result argument"); return; } if (String.IsNullOrEmpty(callbackId)) { Debug.WriteLine("ERROR: OnCommandResult missing callbackId argument"); return; } #endregion string status = ((int)result.Result).ToString(); string jsonResult = result.ToJSONString(); ScriptCallback scriptCallback = null; if (String.IsNullOrEmpty(result.Cast)) { scriptCallback = new ScriptCallback("CordovaCommandResult", new string[] { status, callbackId, jsonResult }); } else { scriptCallback = new ScriptCallback("CordovaCommandResult", new string[] { status, callbackId, jsonResult, result.Cast }); } this.InvokeScriptCallback(scriptCallback); }
/// <summary> /// Executes client java script /// </summary> /// <param name="script">Script to execute on client side</param> private void InvokeScriptCallback(ScriptCallback script) { if (script == null) { throw new ArgumentNullException("script"); } if (String.IsNullOrEmpty(script.ScriptName)) { throw new ArgumentNullException("ScriptName"); } //Debug.WriteLine("INFO:: About to invoke ::" + script.ScriptName + " with args ::" + script.Args[0]); this.webBrowser.Dispatcher.BeginInvoke((ThreadStart) delegate() { try { //Debug.WriteLine("INFO:: InvokingScript::" + script.ScriptName + " with args ::" + script.Args[0]); this.webBrowser.InvokeScript(script.ScriptName, script.Args); } catch (Exception ex) { Debug.WriteLine("ERROR: Exception in InvokeScriptCallback :: " + ex.Message); } }); }
/// <summary> /// Executes client java script /// </summary> /// <param name="script">Script to execute on client side</param> private void InvokeScriptCallback(ScriptCallback script) { if (script == null) { throw new ArgumentNullException("script"); } if (String.IsNullOrEmpty(script.ScriptName)) { throw new ArgumentNullException("ScriptName"); } //Debug.WriteLine("INFO:: About to invoke ::" + script.ScriptName + " with args ::" + script.Args[0]); this.webBrowser.Dispatcher.BeginInvoke((ThreadStart)delegate() { try { //Debug.WriteLine("INFO:: InvokingScript::" + script.ScriptName + " with args ::" + script.Args[0]); this.webBrowser.InvokeScript(script.ScriptName, script.Args); } catch (Exception ex) { Debug.WriteLine("ERROR: Exception in InvokeScriptCallback :: " + ex.Message); } }); }
private void MessageReceivedHandler(ProximityDevice sender, ProximityMessage message) { var bytes = message.Data.ToArray(); List<NdefRecord> records = Ndef.parse(bytes); NfcTag tag = new NfcTag(records); // calling a global js method to fire an nfc event ScriptCallback script = new ScriptCallback("fireNfcTagEvent", new string[] { "ndef", JsonHelper.Serialize(tag) }); this.InvokeCustomScript(script, false); }