예제 #1
0
 /// <summary>
 /// Sets a function for a <see cref="IScriptExecutor" /> as a wrapped <see cref="ScriptExecutorBase.SimplePredicate" />
 /// version of a <see cref="ScriptExecutorBase.SimpleAction" />.
 /// The <see cref="ScriptExecutorBase.SimpleAction" /> is wrapped in a try-catch-blocks and
 /// the wrapper returns <see langword="true" /> on succeed or <see langword="false" /> if execution fails.
 /// </summary>
 /// <param name="executor">The script executor.</param>
 /// <param name="actionName">The name of the action in the script.</param>
 /// <param name="action">The action to invoke.</param>
 /// <param name="beforeInvoke">The optional action to invoke BEFORE try-catch-block is executed.</param>
 /// <returns>The object in <paramref name="executor" />.</returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="executor" />, <paramref name="action" /> and/or <paramref name="beforeInvoke" /> are <see langword="null" />.
 /// </exception>
 /// <remarks>
 /// An exception of <paramref name="beforeInvoke" /> invokation is rethrown.
 /// </remarks>
 public static void SetSimplePredicateWrapper(IScriptExecutor executor,
                                              IEnumerable <char> actionName,
                                              ScriptExecutorBase.SimpleAction action,
                                              ScriptExecutorBase.SimpleAction beforeInvoke)
 {
     SetSimplePredicateWrapper(executor,
                               actionName,
                               action,
                               beforeInvoke,
                               true);
 }
        // Public Methods (3) 

        /// <summary>
        /// Sets a function for a <see cref="IScriptExecutor" /> as a wrapped <see cref="ScriptExecutorBase.SimplePredicate" />
        /// version of a <see cref="ScriptExecutorBase.SimpleAction" />.
        /// The <see cref="ScriptExecutorBase.SimpleAction" /> is wrapped in a try-catch-blocks and
        /// the wrapper returns <see langword="true" /> on succeed or <see langword="false" /> if execution fails.
        /// </summary>
        /// <typeparam name="TExecutor">Type of the script executor.</typeparam>
        /// <param name="executor">The script executor.</param>
        /// <param name="actionName">The name of the action in the script.</param>
        /// <param name="action">The action to invoke.</param>
        /// <returns>The object in <paramref name="executor" />.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="executor" /> and/or <paramref name="action" /> are <see langword="null" />.
        /// </exception>
        public static TExecutor SetSimplePredicateWrapper <TExecutor>(this TExecutor executor,
                                                                      IEnumerable <char> actionName,
                                                                      ScriptExecutorBase.SimpleAction action)
            where TExecutor : IScriptExecutor
        {
            ScriptHelper.SetSimplePredicateWrapper(executor,
                                                   actionName,
                                                   action);

            return(executor);
        }
예제 #3
0
        // Public Methods (3) 

        /// <summary>
        /// Sets a function for a <see cref="IScriptExecutor" /> as a wrapped <see cref="ScriptExecutorBase.SimplePredicate" />
        /// version of a <see cref="ScriptExecutorBase.SimpleAction" />.
        /// The <see cref="ScriptExecutorBase.SimpleAction" /> is wrapped in a try-catch-blocks and
        /// the wrapper returns <see langword="true" /> on succeed or <see langword="false" /> if execution fails.
        /// </summary>
        /// <param name="executor">The script executor.</param>
        /// <param name="actionName">The name of the action in the script.</param>
        /// <param name="action">The action to invoke.</param>
        /// <returns>The object in <paramref name="executor" />.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="executor" /> and/or <paramref name="action" /> are <see langword="null" />.
        /// </exception>
        public static void SetSimplePredicateWrapper(IScriptExecutor executor,
                                                     IEnumerable <char> actionName,
                                                     ScriptExecutorBase.SimpleAction action)
        {
            SetSimplePredicateWrapper(executor,
                                      actionName,
                                      action,
                                      delegate(object[] args)
            {
                // dummy
            });
        }
예제 #4
0
        /// <summary>
        /// Sets a function for a <see cref="IScriptExecutor" /> as a wrapped <see cref="ScriptExecutorBase.SimplePredicate" />
        /// version of a <see cref="ScriptExecutorBase.SimpleAction" />.
        /// The <see cref="ScriptExecutorBase.SimpleAction" /> is wrapped in a try-catch-blocks and
        /// the wrapper returns <see langword="true" /> on succeed or <see langword="false" /> if execution fails.
        /// </summary>
        /// <param name="executor">The script executor.</param>
        /// <param name="actionName">The name of the action in the script.</param>
        /// <param name="action">The action to invoke.</param>
        /// <param name="beforeInvoke">The optional action to invoke BEFORE try-catch-block is executed.</param>
        /// <param name="rethrowBeforeInvokeException">
        /// Rethrow an exception of <paramref name="beforeInvoke" /> invokation or not.
        /// If <see langword="false" /> the wrapper will return <see langword="null" /> instead of a boolean value.
        /// </param>
        /// <returns>The object in <paramref name="executor" />.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="executor" />, <paramref name="action" /> and/or <paramref name="beforeInvoke" /> are <see langword="null" />.
        /// </exception>
        public static void SetSimplePredicateWrapper(IScriptExecutor executor,
                                                     IEnumerable <char> actionName,
                                                     ScriptExecutorBase.SimpleAction action,
                                                     ScriptExecutorBase.SimpleAction beforeInvoke,
                                                     bool rethrowBeforeInvokeException)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

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

            SetScriptDelegate(executor,
                              actionName,
                              new ScriptExecutorBase.SimplePredicate(delegate(object[] args)
            {
                try
                {
                    if (beforeInvoke != null)
                    {
                        beforeInvoke(args);
                    }
                }
                catch
                {
                    if (rethrowBeforeInvokeException)
                    {
                        throw;
                    }

                    // tell script that 'beforeInvoke' has been failed
                    return(null);
                }

                try
                {
                    action(args);
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }));
        }
        /// <summary>
        /// Sets a function for a <see cref="IScriptExecutor" /> as a wrapped <see cref="ScriptExecutorBase.SimplePredicate" />
        /// version of a <see cref="ScriptExecutorBase.SimpleAction" />.
        /// The <see cref="ScriptExecutorBase.SimpleAction" /> is wrapped in a try-catch-blocks and
        /// the wrapper returns <see langword="true" /> on succeed or <see langword="false" /> if execution fails.
        /// </summary>
        /// <typeparam name="TExecutor">Type of the script executor.</typeparam>
        /// <param name="executor">The script executor.</param>
        /// <param name="actionName">The name of the action in the script.</param>
        /// <param name="action">The action to invoke.</param>
        /// <param name="beforeInvoke">The optional action to invoke BEFORE try-catch-block is executed.</param>
        /// <param name="rethrowBeforeInvokeException">
        /// Rethrow an exception of <paramref name="beforeInvoke" /> invokation or not.
        /// If <see langword="false" /> the wrapper will return <see langword="null" /> instead of a boolean value.
        /// </param>
        /// <returns>The object in <paramref name="executor" />.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="executor" />, <paramref name="action" /> and/or <paramref name="beforeInvoke" /> are <see langword="null" />.
        /// </exception>
        public static TExecutor SetSimplePredicateWrapper <TExecutor>(this TExecutor executor,
                                                                      IEnumerable <char> actionName,
                                                                      ScriptExecutorBase.SimpleAction action,
                                                                      ScriptExecutorBase.SimpleAction beforeInvoke,
                                                                      bool rethrowBeforeInvokeException)
            where TExecutor : IScriptExecutor
        {
            ScriptHelper.SetSimplePredicateWrapper(executor,
                                                   actionName,
                                                   action,
                                                   beforeInvoke,
                                                   rethrowBeforeInvokeException);

            return(executor);
        }
        // Public Methods (1) 

        /// <summary>
        /// Sets a simple action with a variable number of parameters.
        /// </summary>
        /// <param name="executor">The script executor.</param>
        /// <param name="actionName">The name of the function in the script.</param>
        /// <param name="action">The action delegate to set.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="executor" /> is <see langword="null" />.
        /// </exception>
        public static void SetSimpleAction(IScriptExecutor executor, IEnumerable <char> actionName, ScriptExecutorBase.SimpleAction action)
        {
            SetScriptDelegate(executor, actionName, action);
        }