Represents command execution result
Inheritance: System.EventArgs
Example #1
0
        /// <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("OnCommandResult missing result argument");
                return;
            }

            if (String.IsNullOrEmpty(callbackId))
            {
                Debug.WriteLine("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("PhoneGapCommandResult", new string[] { status, callbackId, jsonResult });
            }
            else
            {
                scriptCallback = new ScriptCallback("PhoneGapCommandResult", new string[] { status, callbackId, jsonResult, result.Cast });
            }

            this.InvokeScriptCallback(scriptCallback);
        }
Example #2
0
        private void OnCommandResult(object sender, PluginResult result, string callbackId)
        {
            BaseCommand command = sender as BaseCommand;

            if (command == null)
            {
                Debug.WriteLine("OnCommandResult missing argument");
            }
            else if (result == null)
            {
                Debug.WriteLine("OnCommandResult missing argument");
            }
            else if (!String.IsNullOrEmpty(callbackId))
            {
               this.InvokeJSSCallback(callbackId, result);
               }

            // else // no callback required

            // remove listener
            command.OnCommandResult -= delegate(object o, PluginResult res) {
                OnCommandResult(sender, result, callbackId);
            };
        }
Example #3
0
        private void OnCommandResult(object sender, PluginResult result)
        {
            BaseCommand command  = sender as BaseCommand;

            if (command == null)
            {
                Debug.WriteLine("OnCommandResult missing argument");
                return;
            }

            if (result == null)
            {
                Debug.WriteLine("OnCommandResult missing argument");
                return;
            }

            // no callback requied
            if (!command.IsJSCallbackAttached) return;

            this.InvokeJSSCallback(command.JSCallackId, result);
        }
Example #4
0
        private void InvokeJSSCallback(String callbackId, PluginResult result)
        {
            this.Dispatcher.BeginInvoke((ThreadStart)delegate()
            {

                if (String.IsNullOrEmpty(callbackId))
                {
                    throw new ArgumentNullException("callbackId");
                }

                if (result == null)
                {
                    throw new ArgumentNullException("result");
                }

                //string callBackScript = result.ToCallbackString(callbackId, "commandResult", "commandError");

                // TODO: this is correct invokation method
                //this.GapBrowser.InvokeScript("eval", new string[] {callBackScript });

                /// But we temporary use this version because C#<->JS bridge is on fully ready
                ///
                try
                {
                    string status = ((int)result.Result).ToString();
                    string jsonResult = result.ToJSONString();
                    if (String.IsNullOrEmpty(result.Cast))
                    {
                        this.GapBrowser.InvokeScript("PhoneGapCommandResult", new string[] { status, callbackId, jsonResult });
                    }
                    else
                    {
                        this.GapBrowser.InvokeScript("PhoneGapCommandResult", new string[] { status, callbackId, jsonResult, result.Cast });
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Exception in InvokeJSSCallback :: " + ex.Message);
                }
            });
        }
Example #5
0
        private void InvokeJSSCallback(String callbackId, PluginResult result)
        {
            if (String.IsNullOrEmpty(callbackId))
            {
                throw new ArgumentNullException("callbackId");
            }

            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            string callBackScript = result.ToCallbackString(callbackId, "commandResult", "commandError");

            // TODO: this is correct invokation method
            //this.GapBrowser.InvokeScript("eval", new string[] {callBackScript });

            /// But we temporary use this version because C#<->JS bridge is not fully ready
            if (result.IsSuccess)
            {
                this.GapBrowser.InvokeScript("commandResult", new string[] { callbackId, result.ToJSONString() });
            }
            else
            {
                this.GapBrowser.InvokeScript("commandError", new string[] { callbackId, result.ToJSONString() });
            }
        }