示例#1
0
文件: Interpret.cs 项目: angellcq/src
        /// <summary>
        /// Executes the action for the specificed action verb. It
        /// contains one function with arguments
        /// </summary>
        /// <param name="actionVerb">action to perform</param>
        /// <returns>true on success</returns>
        public bool Execute(ActionVerb actionVerb)
        {
            bool retVal = true;

            try
            {
                // use reflection to get the method to execute
                MethodInfo mi = GetType().GetMethod(actionVerb.Action, BindingFlags.NonPublic | BindingFlags.Instance);
                if (mi != null)
                {
                    mi.Invoke(this, new object[] { actionVerb.ArgList });
                }
                else
                {
                    Log.Debug("Error executing verb " + actionVerb.Action + ". Mi is null");
                }
            }
            catch (Exception e)
            {
                Log.Debug("Error executing verb " + actionVerb.Action + ". Exception: " + e.ToString());
                retVal = false;
            }

            return(retVal);
        }
示例#2
0
文件: Parser.cs 项目: angellcq/src
        /// <summary>
        /// Parses an input script into intermediate code (PCode)
        /// The script is essentially a semi-colon delimited set of
        /// functions with arguments.
        ///
        /// Each function can have 0 or more arguments, each argument
        /// should be delimited by a comma.  There are no argument
        /// types.  All arguments are treated as strings.
        ///
        /// An example of a script is:
        ///   "highlightSelected(@SelectedWidget, false); select(@SelectedBox); transition(RowRotation)"
        /// This script has three function calls:
        ///     "highlightSelected" with arguments "@SelectedWidget" and "false"
        ///     "select" with argument "@SelectedBox"
        ///     "transition" with argument "RowRotation"
        /// </summary>
        /// <param name="inputString">Input script</param>
        /// <param name="pCode">Returns interpreted form</param>
        /// <returns>true if parsed successfully, false otherwise</returns>
        public bool Parse(String inputString, ref PCode pCode)
        {
            bool retVal = true;

            if (String.IsNullOrEmpty(inputString))
            {
                return(retVal);
            }

            pCode.Script = inputString.Trim();
            if (String.IsNullOrEmpty(pCode.Script))
            {
                return(retVal);
            }

            // semi-colon is the function separator
            var tokens = pCode.Script.Split(';');

            // now parse each function
            foreach (var token in tokens)
            {
                var trimmedToken = token.Trim();
                if (trimmedToken.Length > 0)
                {
                    var actionVerb = new ActionVerb();

                    // function may have comma delimited arguments.
                    // extract them
                    bool ret = parseActionVerb(trimmedToken, ref actionVerb);
                    if (ret)
                    {
                        pCode.ActionVerbList.Add(actionVerb);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (!retVal)
            {
                pCode.ActionVerbList.Clear();
            }

            return(retVal);
        }
示例#3
0
文件: Parser.cs 项目: angellcq/src
        /// <summary>
        /// Takes a single function as a script, extracts the function name and the
        /// list of arguments and returns an actionVerb object the encapsulates
        /// the function name and the args
        ///
        ///  For eg, if the input script for the function is:
        ///    "highlightSelected(@SelectedWidget, false)
        /// This will result in an ActionVerb with the Name set to "highlightSelected"
        /// with argument list "@SelectedWidget" and "false"
        /// </summary>
        /// <param name="inputString">Input script</param>
        /// <param name="actionVerb">Output func name and args</param>
        /// <returns>true on success, false if there was an error</returns>
        private bool parseActionVerb(String inputString, ref ActionVerb actionVerb)
        {
            var action    = String.Empty;
            var arguments = String.Empty;

            // extract the func name and the arguments
            bool retVal = getActionAndArguments(inputString, ref action, ref arguments);

            if (retVal)
            {
                // now, split the args and get a list
                var argList = new List <string>();
                retVal = splitArguments(arguments, ref argList);

                if (retVal)
                {
                    actionVerb.Action  = action;
                    actionVerb.ArgList = argList;
                }
            }

            return(retVal);
        }
示例#4
0
文件: Parser.cs 项目: glwu/acat
        /// <summary>
        /// Takes a single function as a script, extracts the function name and the
        /// list of arguments and returns an actionVerb object the encapsulates
        /// the function name and the args
        ///
        ///  For eg, if the input script for the function is:
        ///    "highlightSelected(@SelectedWidget, false)
        /// This will result in an ActionVerb with the Name set to "highlightSelected"
        /// with argument list "@SelectedWidget" and "false"
        /// </summary>
        /// <param name="inputString">Input script</param>
        /// <param name="actionVerb">Output func name and args</param>
        /// <returns>true on success, false if there was an error</returns>
        private bool parseActionVerb(String inputString, ref ActionVerb actionVerb)
        {
            var action = String.Empty;
            var arguments = String.Empty;

            // extract the func name and the arguments
            bool retVal = getActionAndArguments(inputString, ref action, ref arguments);
            if (retVal)
            {
                // now, split the args and get a list
                var argList = new List<string>();
                retVal = splitArguments(arguments, ref argList);

                if (retVal)
                {
                    actionVerb.Action = action;
                    actionVerb.ArgList = argList;
                }
            }

            return retVal;
        }
示例#5
0
文件: Parser.cs 项目: glwu/acat
        /// <summary>
        /// Parses an input script into intermediate code (PCode)
        /// The script is essentially a semi-colon delimited set of
        /// functions with arguments.
        ///
        /// Each function can have 0 or more arguments, each argument
        /// should be delimited by a comma.  There are no argument
        /// types.  All arguments are treated as strings.
        ///
        /// An example of a script is:
        ///   "highlightSelected(@SelectedWidget, false); select(@SelectedBox); transition(RowRotation)"
        /// This script has three function calls:
        ///     "highlightSelected" with arguments "@SelectedWidget" and "false"
        ///     "select" with argument "@SelectedBox"
        ///     "transition" with argument "RowRotation"
        /// </summary>
        /// <param name="inputString">Input script</param>
        /// <param name="pCode">Returns interpreted form</param>
        /// <returns>true if parsed successfully, false otherwise</returns>
        public bool Parse(String inputString, ref PCode pCode)
        {
            bool retVal = true;

            if (String.IsNullOrEmpty(inputString))
            {
                return retVal;
            }

            pCode.Script = inputString.Trim();
            if (String.IsNullOrEmpty(pCode.Script))
            {
                return retVal;
            }

            // semi-colon is the function separator
            var tokens = pCode.Script.Split(';');

            // now parse each function
            foreach (var token in tokens)
            {
                var trimmedToken = token.Trim();
                if (trimmedToken.Length > 0)
                {
                    var actionVerb = new ActionVerb();

                    // function may have comma delimited arguments.
                    // extract them
                    retVal = parseActionVerb(trimmedToken, ref actionVerb);
                    if (retVal)
                    {
                        pCode.ActionVerbList.Add(actionVerb);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (!retVal)
            {
                pCode.ActionVerbList.Clear();
            }

            return retVal;
        }
示例#6
0
文件: Interpret.cs 项目: glwu/acat
        /// <summary>
        /// Executes the action for the specified action verb. It
        /// contains one function with arguments
        /// </summary>
        /// <param name="actionVerb">action to perform</param>
        /// <returns>true on success</returns>
        public bool Execute(ActionVerb actionVerb)
        {
            bool retVal = true;
            try
            {
                // use reflection to get the method to execute
                MethodInfo mi = GetType().GetMethod(actionVerb.Action, BindingFlags.NonPublic | BindingFlags.Instance);
                if (mi != null)
                {
                    mi.Invoke(this, new object[] { actionVerb.ArgList });
                }
                else
                {
                    Log.Debug("Error executing verb " + actionVerb.Action + ". Mi is null");
                }
            }
            catch (Exception e)
            {
                Log.Debug("Error executing verb " + actionVerb.Action + ". Exception: " + e.ToString());
                retVal = false;
            }

            return retVal;
        }