Example #1
0
        ///
        /// This is executed when a function is specified in any ez-scripting that isn't a native function.
        /// You can check to see if the function that was called is your function.
        /// If it is, do something and return something.
        /// If you don't return something, a default value of TRUE is returned.
        /// If you throw an exception, the ez-script control will receive the exception and present the error to the user.
        ///
        private void FunctionEval_AdditionalFunctionEvent(object sender, ExpressionEvaluation.AdditionalFunctionEventArgs e)
        {
            foreach (var customFunction in this.functions)
            {
                if (!e.Name.Equals(customFunction.Name, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                var numberOfArguments = e.Parameters != null ? e.Parameters.Length : 0;

                if (numberOfArguments < customFunction.ParametersNames.Length)
                {
                    var msg = new StringBuilder();
                    msg.AppendFormat(
                        "Expects {0} parameter(s). Usage: {1}({2})",
                        customFunction.ParametersNames.Length,
                        customFunction.Name,
                        string.Join(", ", customFunction.ParametersNames.Select(x => "<" + x + ">")));

                    throw new Exception(msg.ToString());
                }

                e.ReturnValue = customFunction.Function(customFunction.Name, e.Parameters);
                return;
            }
        }
Example #2
0
 /// <summary>
 /// This is executed when a function is specified in any ez-scripting that isn't a native function.
 /// You can check to see if the function that was called is your function.
 /// If it is, do something and return something.
 /// If you don't return something, a default value of TRUE is returned.
 /// If you throw an exception, the ez-script control will receive the exception and present the error to the user.
 /// </summary>
 private void FunctionEval_AdditionalFunctionEvent(object sender, ExpressionEvaluation.AdditionalFunctionEventArgs e)
 {
     try
     {
         string[] arr  = ToStringArray(e.Parameters);
         string   name = e.Name;
         bool     flagOK;
         // Check if the function is one of our function
         string result = CheckProcessfunctions(name, arr, out flagOK);
         if (result == false.ToString())
         {
             throw new Exception("Bot is not running command cancelled");
         }
         e.ReturnValue = result;
     }
     catch (Exception ex)
     {
         EZ_Builder.EZBManager.Log("Error in control '{0}'. Message: {1}", this.Text, ex.Message);
     }
 }