/// <summary>
        /// Executes a callback function
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="keepCallback"></param>
        private void ExecuteCallback(Callback callback, bool keepCallback = false)
        {
            var status = callback.Success
                ? PluginResult.Status.OK
                : PluginResult.Status.ERROR;

            var result = new PluginResult(status, callback.ReturnValue) { KeepCallback = keepCallback };
            base.DispatchCommandResult(result);
        }
        public void DispatchCommandResult(PluginResult result)
        {
            if (OnCommandResult != null)
            {
                OnCommandResult(this, result);

                if (!result.KeepCallback)
                {
                    Dispose();
                }
            }
        }
        /// <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

            var callbackIdToRemove = callbackId;

            int ignore;
            if(!Int32.TryParse(callbackId, out ignore) && !(callbackId.StartsWith("'") || callbackId.StartsWith("\"")))
            {
                callbackId = "'" + callbackId + "'";
            }

            string status = ((int) result.Result).ToString();
            string jsonResult = result.ToJSONString();

            ScriptCallback scriptCallback = String.IsNullOrEmpty(result.Cast)
                ? new ScriptCallback("CordovaCommandResult", new[] { status, callbackId, jsonResult})
                : new ScriptCallback("CordovaCommandResult", new[] { status, callbackId, jsonResult, result.Cast});

            InvokeScriptCallback(scriptCallback);

            webBrowser.RemoveCommandId(callbackIdToRemove);
        }