Represents Cordova native command call: action callback, etc
Esempio n. 1
0
        /// <summary>
        /// Retrieves command call parameters and creates wrapper for them
        /// </summary>
        /// <param name="commandStr">Command string in the form 'service/action/callback/args'</param>
        /// <returns>New class instance or null of string does not represent Cordova command</returns>
        public static CordovaCommandCall Parse(string commandStr)
        {
            if (string.IsNullOrEmpty(commandStr))
            {
                return null;
                //throw new ArgumentNullException("commandStr");
            }

            string[] split = commandStr.Split('/');
            if (split.Length < 3)
            {
                return null;
            }

            CordovaCommandCall commandCallParameters = new CordovaCommandCall();

            commandCallParameters.Service = split[0];
            commandCallParameters.Action = split[1];
            commandCallParameters.CallbackId = split[2];
            commandCallParameters.Args = split.Length <= 3 ? String.Empty : String.Join("/", split.Skip(3));

            // sanity check for illegal names
            // was failing with ::
            // CordovaCommandResult :: 1, Device1, {"status":1,"message":"{\"name\":\"XD.....
            if (commandCallParameters.Service.IndexOfAny(new char[] { '@', ':', ',', '!', ' ' }) > -1)
            {
                return null;
            }

            return commandCallParameters;
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieves command call parameters and creates wrapper for them
        /// </summary>
        /// <param name="commandStr">Command string in the form 'service/action/callback/args'</param>
        /// <returns>New class instance or null of string does not represent Cordova command</returns>
        public static CordovaCommandCall Parse(string commandStr)
        {
            if (string.IsNullOrEmpty(commandStr))
            {
                return(null);
                //throw new ArgumentNullException("commandStr");
            }

            string[] split = commandStr.Split('/');
            if (split.Length < 3)
            {
                return(null);
            }

            CordovaCommandCall commandCallParameters = new CordovaCommandCall();

            commandCallParameters.Service    = split[0];
            commandCallParameters.Action     = split[1];
            commandCallParameters.CallbackId = split[2];
            commandCallParameters.Args       = split.Length <= 3 ? String.Empty : String.Join("/", split.Skip(3));

            // sanity check for illegal names
            // was failing with ::
            // CordovaCommandResult :: 1, Device1, {"status":1,"message":"{\"name\":\"XD.....
            if (commandCallParameters.Service.IndexOfAny(new char[] { '@', ':', ',', '!', ' ' }) > -1)
            {
                return(null);
            }


            return(commandCallParameters);
        }
Esempio n. 3
0
 public override void ProcessCommand(CordovaCommandCall commandCallParams)
 {
     BaseCommand bc = CommandFactory.CreateByServiceName(commandCallParams.Service);
     if (bc != null)
     {
         try
         {
             ((XBaseCommand)bc).app = this.app;
         }
         catch (InvalidCastException)
         {
         }
     }
     base.ProcessCommand(commandCallParams);
 }
Esempio n. 4
0
        /// <summary>
        /// Retrieves command call parameters and creates wrapper for them
        /// </summary>
        /// <param name="commandStr">Command string in the form 'service/action/callback/args'</param>
        /// <returns>New class instance or null of string does not represent Cordova command</returns>
        public static CordovaCommandCall Parse(string commandStr)
        {
            //System.Diagnostics.Debug.WriteLine("CommandString : " + commandStr);
            if (string.IsNullOrEmpty(commandStr))
            {
                return(null);
            }

            string[] split = commandStr.Split('/');
            if (split.Length < 3)
            {
                return(null);
            }

            CordovaCommandCall commandCallParameters = new CordovaCommandCall();

            commandCallParameters.Service    = split[0];
            commandCallParameters.Action     = split[1];
            commandCallParameters.CallbackId = split[2];

            try
            {
                string arg = split.Length <= 3 ? "[]" : String.Join("/", split.Skip(3));
                // save the exception
                if (!arg.StartsWith("["))
                {
                    arg = string.Format("[{0}]", arg);
                }
                List <string> args = JSON.JsonHelper.Deserialize <List <string> >(arg);
                args.Add(commandCallParameters.CallbackId);
                commandCallParameters.Args = JSON.JsonHelper.Serialize(args.ToArray());
            }
            catch (Exception)
            {
                return(null);
            }
            // sanity check for illegal names
            // was failing with ::
            // CordovaCommandResult :: 1, Device1, {"status":1,"message":"{\"name\":\"XD.....
            if (commandCallParameters.Service.IndexOfAny(new char[] { '@', ':', ',', '!', ' ' }) > -1)
            {
                return(null);
            }

            return(commandCallParameters);
        }
Esempio n. 5
0
        /// <summary>
        /// Retrieves command call parameters and creates wrapper for them
        /// </summary>
        /// <param name="commandStr">Command string in the form 'service/action/callback/args'</param>
        /// <returns>New class instance or null of string does not represent Cordova command</returns>
        public static CordovaCommandCall Parse(string commandStr)
        {
            //System.Diagnostics.Debug.WriteLine("CommandString : " + commandStr);
            if (string.IsNullOrEmpty(commandStr))
            {
                return null;
            }

            string[] split = commandStr.Split('/');
            if (split.Length < 3)
            {
                return null;
            }

            CordovaCommandCall commandCallParameters = new CordovaCommandCall();
            commandCallParameters.Service = split[0];
            commandCallParameters.Action = split[1];
            commandCallParameters.CallbackId = split[2];
            commandCallParameters.Namespace = String.Empty;

            try
            {
                string arg = split.Length <= 3 ? "[]" : String.Join("/", split.Skip(3));
                // save the exception
                if (!arg.StartsWith("["))
                {
                    arg = string.Format("[{0}]", arg);
                }
                List<string> args = JSON.JsonHelper.Deserialize<List<string>>(arg);
                args.Add(commandCallParameters.CallbackId);
                commandCallParameters.Args = JSON.JsonHelper.Serialize(args.ToArray());
            }
            catch (Exception)
            {
                return null;
            }
            // sanity check for illegal names
            // was failing with ::
            // CordovaCommandResult :: 1, Device1, {"status":1,"message":"{\"name\":\"XD.....
            if (commandCallParameters.Service.IndexOfAny(new char[] { '@', ':', ',', '!', ' ' }) > -1)
            {
                return null;
            }

            return commandCallParameters;
        }
Esempio n. 6
0
        /// <summary>
        /// Executes command and returns result back.
        /// </summary>
        /// <param name="commandCallParams">Command to execute</param>
        public void ProcessCommand(CordovaCommandCall commandCallParams)
        {
            if (commandCallParams == null)
            {
                throw new ArgumentNullException("commandCallParams");
            }

            try
            {
                BaseCommand bc = CommandFactory.CreateByServiceName(commandCallParams.Service);

                if (bc == null)
                {
                    this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION));
                    return;
                }

                EventHandler<PluginResult> OnCommandResultHandler = delegate(object o, PluginResult res)
                {
                    this.OnCommandResult(commandCallParams.CallbackId, res);
                };

                bc.OnCommandResult -= OnCommandResultHandler;
                bc.OnCommandResult += OnCommandResultHandler;

                EventHandler<ScriptCallback> OnCustomScriptHandler = delegate(object o, ScriptCallback script)
                {
                    this.InvokeScriptCallback(script);
                };

                bc.OnCustomScript -= OnCustomScriptHandler;
                bc.OnCustomScript += OnCustomScriptHandler;

                // TODO: alternative way is using thread pool (ThreadPool.QueueUserWorkItem) instead of
                // new thread for every command call; but num threads are not sufficient - 2 threads per CPU core

                Thread thread = new Thread(func =>
                {
                    try
                    {
                        bc.InvokeMethodNamed(commandCallParams.Action, commandCallParams.Args);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("ERROR: Exception in ProcessCommand :: " + ex.Message);
                        bc.OnCommandResult -= OnCommandResultHandler;
                        bc.OnCustomScript -= OnCustomScriptHandler;

                        Debug.WriteLine("ERROR: failed to InvokeMethodNamed :: " + commandCallParams.Action + " on Object :: " + commandCallParams.Service);

                        this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.INVALID_ACTION));

                        return;
                    }
                });

                thread.Start();
            }
            catch (Exception ex)
            {
                // ERROR
                Debug.WriteLine(String.Format("ERROR: Unable to execute command :: {0}:{1}:{3} ",
                    commandCallParams.Service, commandCallParams.Action, ex.Message));

                this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.ERROR));
                return;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Executes command and returns result back.
        /// </summary>
        /// <param name="commandCallParams">Command to execute</param>
        public void ProcessCommand(CordovaCommandCall commandCallParams)
        {
            if (commandCallParams == null)
            {
                throw new ArgumentNullException("commandCallParams");
            }

            try
            {
                BaseCommand bc = CommandFactory.CreateByServiceName(commandCallParams.Service, commandCallParams.Namespace);

                if (bc == null)
                {
                    this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION));
                    return;
                }

                // TODO: consider removing custom script functionality at all since we already marked it as absolute (see BaseCommand)
                EventHandler <ScriptCallback> OnCustomScriptHandler = delegate(object o, ScriptCallback script)
                {
                    this.InvokeScriptCallback(script);
                };

                EventHandler <PluginResult> OnCommandResultHandler = delegate(object o, PluginResult res)
                {
                    if (res.CallbackId == null || res.CallbackId == commandCallParams.CallbackId)
                    {
                        this.OnCommandResult(commandCallParams.CallbackId, res);
                        if (!res.KeepCallback)
                        {
                            bc.RemoveResultHandler(commandCallParams.CallbackId);
                            bc.OnCustomScript -= OnCustomScriptHandler;
                        }
                    }
                };

                //bc.OnCommandResult += OnCommandResultHandler;
                bc.AddResultHandler(commandCallParams.CallbackId, OnCommandResultHandler);

                bc.OnCustomScript += OnCustomScriptHandler;

                Windows.System.Threading.ThreadPool.RunAsync((workItem) =>
                {
                    try
                    {
                        bc.InvokeMethodNamed(commandCallParams.CallbackId, commandCallParams.Action, commandCallParams.Args);
                        commands.Add(bc);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("ERROR: Exception in ProcessCommand :: " + ex.Message);
                        bc.RemoveResultHandler(commandCallParams.CallbackId);
                        bc.OnCustomScript -= OnCustomScriptHandler;

                        Debug.WriteLine("ERROR: failed to InvokeMethodNamed :: " + commandCallParams.Action + " on Object :: " + commandCallParams.Service);
                        this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.INVALID_ACTION));
                        return;
                    }
                });
            }
            catch (Exception ex)
            {
                // ERROR
                Debug.WriteLine(String.Format("ERROR: Unable to execute command :: {0}:{1}:{2} ",
                                              commandCallParams.Service, commandCallParams.Action, ex.Message));

                this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.ERROR));
                return;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Executes command and returns result back.
        /// </summary>
        /// <param name="commandCallParams">Command to execute</param>
        public void ProcessCommand(CordovaCommandCall commandCallParams)
        {
            if (commandCallParams == null)
            {
                throw new ArgumentNullException("commandCallParams");
            }

            try
            {
                BaseCommand bc = CommandFactory.CreateByServiceName(commandCallParams.Service);

                if (bc == null)
                {
                    this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION));
                    return;
                }

                EventHandler <PluginResult> OnCommandResultHandler = delegate(object o, PluginResult res)
                {
                    this.OnCommandResult(commandCallParams.CallbackId, res);
                };

                bc.OnCommandResult += OnCommandResultHandler;

                EventHandler <ScriptCallback> OnCustomScriptHandler = delegate(object o, ScriptCallback script)
                {
                    this.InvokeScriptCallback(script);
                };


                bc.OnCustomScript += OnCustomScriptHandler;

                ThreadStart methodInvokation = () =>
                {
                    try
                    {
                        bc.InvokeMethodNamed(commandCallParams.Action, commandCallParams.Args);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("ERROR: Exception in ProcessCommand :: " + ex.Message);
                        bc.OnCommandResult -= OnCommandResultHandler;
                        bc.OnCustomScript  -= OnCustomScriptHandler;

                        Debug.WriteLine("ERROR: failed to InvokeMethodNamed :: " + commandCallParams.Action + " on Object :: " + commandCallParams.Service);

                        this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.INVALID_ACTION));

                        return;
                    }
                };

                if ((bc is File) || (bc is Accelerometer))
                {
                    // Due to some issues with the IsolatedStorage in current version of WP8 SDK we have to run all File Api commands synchronously.
                    // TODO: test this in WP8 RTM
                    methodInvokation.Invoke();
                }
                else
                {
                    new Thread(methodInvokation).Start();
                }
            }
            catch (Exception ex)
            {
                // ERROR
                Debug.WriteLine(String.Format("ERROR: Unable to execute command :: {0}:{1}:{3} ",
                                              commandCallParams.Service, commandCallParams.Action, ex.Message));

                this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.ERROR));
                return;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Executes command and returns result back.
        /// </summary>
        /// <param name="commandCallParams">Command to execute</param>
        public void ProcessCommand(CordovaCommandCall commandCallParams)
        {

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

            try
            {
                BaseCommand bc = CommandFactory.CreateByServiceName(commandCallParams.Service, commandCallParams.Namespace);

                if (bc == null)
                {
                    this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION));
                    return;
                }

                // TODO: consider removing custom script functionality at all since we already marked it as absolute (see BaseCommand)
                EventHandler<ScriptCallback> OnCustomScriptHandler = delegate(object o, ScriptCallback script)
                {
                    this.InvokeScriptCallback(script);
                };

                EventHandler<PluginResult> OnCommandResultHandler = delegate(object o, PluginResult res)
                {
                    if (res.CallbackId == null || res.CallbackId == commandCallParams.CallbackId)
                    {
                        this.OnCommandResult(commandCallParams.CallbackId, res);
                        if (!res.KeepCallback)
                        {
                            bc.RemoveResultHandler(commandCallParams.CallbackId);
                            bc.OnCustomScript -= OnCustomScriptHandler;
                        }
                    }
                };

                //bc.OnCommandResult += OnCommandResultHandler;
                bc.AddResultHandler(commandCallParams.CallbackId, OnCommandResultHandler);

                bc.OnCustomScript += OnCustomScriptHandler;

                Windows.System.Threading.ThreadPool.RunAsync((workItem) =>
                {
                    try
                    {
                        bc.InvokeMethodNamed(commandCallParams.CallbackId, commandCallParams.Action, commandCallParams.Args);
                        commands.Add(bc);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("ERROR: Exception in ProcessCommand :: " + ex.Message);
                        bc.RemoveResultHandler(commandCallParams.CallbackId);
                        bc.OnCustomScript -= OnCustomScriptHandler;

                        Debug.WriteLine("ERROR: failed to InvokeMethodNamed :: " + commandCallParams.Action + " on Object :: " + commandCallParams.Service);
                        this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.INVALID_ACTION));
                        return;
                    }
                });

            }
            catch (Exception ex)
            {
                // ERROR
                Debug.WriteLine(String.Format("ERROR: Unable to execute command :: {0}:{1}:{2} ",
                    commandCallParams.Service, commandCallParams.Action, ex.Message));

                this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.ERROR));
                return;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Executes command and returns result back.
        /// </summary>
        /// <param name="commandCallParams">Command to execute</param>
        public void ProcessCommand(CordovaCommandCall commandCallParams)
        {

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

            try
            {
                BaseCommand bc = CommandFactory.CreateByServiceName(commandCallParams.Service, commandCallParams.Namespace);

                if (bc == null)
                {
                    this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION));
                    return;
                }

                EventHandler<PluginResult> OnCommandResultHandler = delegate(object o, PluginResult res)
                {
                    if (res.CallbackId == null || res.CallbackId == commandCallParams.CallbackId)
                    {
                        this.OnCommandResult(commandCallParams.CallbackId, res);
                        if (!res.KeepCallback)
                        {
                            bc.RemoveResultHandler(commandCallParams.CallbackId);
                        }
                    }
                };

                //bc.OnCommandResult += OnCommandResultHandler;
                bc.AddResultHandler(commandCallParams.CallbackId, OnCommandResultHandler);

                EventHandler<ScriptCallback> OnCustomScriptHandler = delegate(object o, ScriptCallback script)
                {
                    this.InvokeScriptCallback(script);
                };

                bc.OnCustomScript += OnCustomScriptHandler;

                ThreadStart methodInvokation = () =>
                {
                    try
                    {
                        bc.InvokeMethodNamed(commandCallParams.CallbackId, commandCallParams.Action, commandCallParams.Args);
                        commands.Add(bc);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("ERROR: Exception in ProcessCommand :: " + ex.Message);
                        bc.RemoveResultHandler(commandCallParams.CallbackId);
                        bc.OnCustomScript -= OnCustomScriptHandler;

                        Debug.WriteLine("ERROR: failed to InvokeMethodNamed :: " + commandCallParams.Action + " on Object :: " + commandCallParams.Service);
                        this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.INVALID_ACTION));
                        return;
                    }
                };

                new Thread(methodInvokation).Start();

            }
            catch (Exception ex)
            {
                // ERROR
                Debug.WriteLine(String.Format("ERROR: Unable to execute command :: {0}:{1}:{2} ",
                    commandCallParams.Service, commandCallParams.Action, ex.Message));

                this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.ERROR));
                return;
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Executes command and returns result back.
        /// </summary>
        /// <param name="commandCallParams">Command to execute</param>
        public void ProcessCommand(CordovaCommandCall commandCallParams)
        {
            if (commandCallParams == null)
            {
                throw new ArgumentNullException("commandCallParams");
            }

            try
            {
                BaseCommand bc = CommandFactory.CreateByServiceName(commandCallParams.Service, commandCallParams.Namespace);

                if (bc == null)
                {
                    this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION));
                    return;
                }

                EventHandler <PluginResult> OnCommandResultHandler = delegate(object o, PluginResult res)
                {
                    if (res.CallbackId == null || res.CallbackId == commandCallParams.CallbackId)
                    {
                        this.OnCommandResult(commandCallParams.CallbackId, res);
                        if (!res.KeepCallback)
                        {
                            bc.RemoveResultHandler(commandCallParams.CallbackId);
                        }
                    }
                };

                //bc.OnCommandResult += OnCommandResultHandler;
                bc.AddResultHandler(commandCallParams.CallbackId, OnCommandResultHandler);

                EventHandler <ScriptCallback> OnCustomScriptHandler = delegate(object o, ScriptCallback script)
                {
                    this.InvokeScriptCallback(script);
                };

                bc.OnCustomScript += OnCustomScriptHandler;

                ThreadStart methodInvokation = () =>
                {
                    try
                    {
                        bc.InvokeMethodNamed(commandCallParams.CallbackId, commandCallParams.Action, commandCallParams.Args);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("ERROR: Exception in ProcessCommand :: " + ex.Message);
                        bc.RemoveResultHandler(commandCallParams.CallbackId);
                        bc.OnCustomScript -= OnCustomScriptHandler;

                        Debug.WriteLine("ERROR: failed to InvokeMethodNamed :: " + commandCallParams.Action + " on Object :: " + commandCallParams.Service);
                        this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.INVALID_ACTION));
                        return;
                    }
                };

                new Thread(methodInvokation).Start();
            }
            catch (Exception ex)
            {
                // ERROR
                Debug.WriteLine(String.Format("ERROR: Unable to execute command :: {0}:{1}:{2} ",
                                              commandCallParams.Service, commandCallParams.Action, ex.Message));

                this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.ERROR));
                return;
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Executes command and returns result back.
        /// </summary>
        /// <param name="commandCallParams">Command to execute</param>
        public void ProcessCommand(CordovaCommandCall commandCallParams)
        {
            if (commandCallParams == null)
            {
                throw new ArgumentNullException("commandCallParams");
            }

            try
            {
                BaseCommand bc = CommandFactory.CreateByServiceName(commandCallParams.Service);

                if (bc == null)
                {
                    this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION));
                    return;
                }

                EventHandler<PluginResult> OnCommandResultHandler = delegate(object o, PluginResult res)
                {
                    this.OnCommandResult(commandCallParams.CallbackId, res);
                };

                bc.OnCommandResult += OnCommandResultHandler;

                EventHandler<ScriptCallback> OnCustomScriptHandler = delegate(object o, ScriptCallback script)
                {
                    this.InvokeScriptCallback(script);
                };

                bc.OnCustomScript += OnCustomScriptHandler;

                ThreadStart methodInvokation = () =>
                {

                    try
                    {
                        bc.InvokeMethodNamed(commandCallParams.Action, commandCallParams.Args);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("ERROR: Exception in ProcessCommand :: " + ex.Message);
                        bc.OnCommandResult -= OnCommandResultHandler;
                        bc.OnCustomScript -= OnCustomScriptHandler;

                        Debug.WriteLine("ERROR: failed to InvokeMethodNamed :: " + commandCallParams.Action + " on Object :: " + commandCallParams.Service);

                        this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.INVALID_ACTION));

                        return;
                    }
                };

                if ((bc is File) || (bc is Accelerometer))
                {
                    // Due to some issues with the IsolatedStorage in current version of WP8 SDK we have to run all File Api commands synchronously.
                    // TODO: test this in WP8 RTM
                    methodInvokation.Invoke();
                }
                else
                {
                    new Thread(methodInvokation).Start();
                }

            }
            catch (Exception ex)
            {
                // ERROR
                Debug.WriteLine(String.Format("ERROR: Unable to execute command :: {0}:{1}:{3} ",
                    commandCallParams.Service, commandCallParams.Action, ex.Message));

                this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.ERROR));
                return;
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Executes command and returns result back.
        /// </summary>
        /// <param name="commandCallParams">Command to execute</param>
        public void ProcessCommand(CordovaCommandCall commandCallParams)
        {
            if (commandCallParams == null)
            {
                throw new ArgumentNullException("commandCallParams");
            }

            try
            {
                BaseCommand bc = CommandFactory.CreateByServiceName(commandCallParams.Service);

                if (bc == null)
                {
                    this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION));
                    return;
                }

                EventHandler <PluginResult> OnCommandResultHandler = delegate(object o, PluginResult res)
                {
                    this.OnCommandResult(commandCallParams.CallbackId, res);
                };

                bc.OnCommandResult += OnCommandResultHandler;

                EventHandler <ScriptCallback> OnCustomScriptHandler = delegate(object o, ScriptCallback script)
                {
                    this.InvokeScriptCallback(script);
                };


                bc.OnCustomScript += OnCustomScriptHandler;

                // TODO: alternative way is using thread pool (ThreadPool.QueueUserWorkItem) instead of
                // new thread for every command call; but num threads are not sufficient - 2 threads per CPU core

                Thread thread = new Thread(func =>
                {
                    try
                    {
                        bc.InvokeMethodNamed(commandCallParams.Action, commandCallParams.Args);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("ERROR: Exception in ProcessCommand :: " + ex.Message);
                        bc.OnCommandResult -= OnCommandResultHandler;
                        bc.OnCustomScript  -= OnCustomScriptHandler;

                        Debug.WriteLine("ERROR: failed to InvokeMethodNamed :: " + commandCallParams.Action + " on Object :: " + commandCallParams.Service);

                        this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.INVALID_ACTION));

                        return;
                    }
                });

                thread.Start();
            }
            catch (Exception ex)
            {
                // ERROR
                Debug.WriteLine(String.Format("ERROR: Unable to execute command :: {0}:{1}:{3} ",
                                              commandCallParams.Service, commandCallParams.Action, ex.Message));

                this.OnCommandResult(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.ERROR));
                return;
            }
        }