///<summary>
        /// Uses the action pipeline to invoke the method.
        ///</summary>
        ///<param name="target">The object instance to invoke the method on.</param>
        ///<param name="methodName">The name of the method to invoke.</param>
        ///<param name="view">The view.</param>
        ///<param name="source">The source of the invocation.</param>
        ///<param name="eventArgs">The event args.</param>
        ///<param name="parameters">The method parameters.</param>
        public static void Invoke(object target, string methodName, DependencyObject view = null, FrameworkElement source = null, object eventArgs = null, object[] parameters = null)
        {
            var context = new ActionExecutionContext {
                Target  = target,
                Method  = target.GetType().GetMethod(methodName),
                Message = new ActionMessage {
                    MethodName = methodName
                },
                View      = view,
                Source    = source,
                EventArgs = eventArgs
            };

            if (parameters != null)
            {
                parameters.Apply(x => context.Message.Parameters.Add(x as Parameter ?? new Parameter {
                    Value = x
                }));
            }

            ActionMessage.InvokeAction(context);
        }
        static ActionMessage CreateMessage(DependencyObject target, string messageText)
        {
            var message = new ActionMessage();

            messageText = messageText.Replace("Action", string.Empty);

            var openingParenthesisIndex = messageText.IndexOf('(');

            if (openingParenthesisIndex < 0)
            {
                openingParenthesisIndex = messageText.Length;
            }
            var closingParenthesisIndex = messageText.LastIndexOf(')');

            if (closingParenthesisIndex < 0)
            {
                closingParenthesisIndex = messageText.Length;
            }

            var core = messageText.Substring(0, openingParenthesisIndex).Trim();

            message.MethodName = core;

            if (closingParenthesisIndex - openingParenthesisIndex > 1)
            {
                var paramString = messageText.Substring(openingParenthesisIndex + 1,
                                                        closingParenthesisIndex - openingParenthesisIndex - 1);

                var parameters = Regex.Split(paramString);

                foreach (var parameter in parameters)
                {
                    message.Parameters.Add(CreateParameter(target, parameter.Trim()));
                }
            }

            return(message);
        }
Beispiel #3
0
 /// <summary>
 /// Makes the parameter aware of the <see cref="ActionMessage"/> that it's attached to.
 /// </summary>
 /// <param name="owner">The action message.</param>
 internal void MakeAwareOf(ActionMessage owner)
 {
     Owner = owner;
 }