Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="caller">The object on which to perform the method. Null if the method is static.</param>
        /// <param name="method">The method to perform on the caller, or statically.</param>
        /// <param name="target">The target DataItem that will contain the result. It is populated after</param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public ProxyRequestAction AddAction(object caller, MethodBase method, IDataBoundObject target, object[] parameters)
        {
            ProxyRequestAction action = new ProxyRequestAction(caller, target, method.DeclaringType.AssemblyQualifiedName, method.Name, parameters);

            _actions.Add(action);

            //if (target != null)
            //	target.ActionIndex = _actions.IndexOf(action);

            action.ActionIndex = _actions.IndexOf(action);
            return(action);
        }
Ejemplo n.º 2
0
        public ProxyResult ProcessRequest(ProxyRequest request)
        {
            _instances.Add(OperationContext.Current, this);

            // Proxy result used to store the results of the actions
            ProxyResult result = new ProxyResult(request);

            _result = result;

            // Action loop
            for (int currentIndex = 0; currentIndex < request.Actions.Count; currentIndex++)
            {
                ProxyRequestAction action = request.Actions[currentIndex];
                CurrentAction = action;

                try
                {
                    // Replace proxy object parameters with actual values (from previous actions)
                    for (int p = 0; p < action.Parameters.Length; p++)
                    {
                        if (action.Parameters[p] is IDataBoundObject)
                        {
                            IDataBoundObject o = (IDataBoundObject)action.Parameters[p];
                            if (o.ProxyActionIndex < currentIndex)
                            {
                                // Parameter is a proxy object referencing a previous step, so replace with that step's result
                                action.Parameters[p] = result[o.ProxyActionIndex].ReturnValue;
                            }
                            else
                            {
                                throw new InvalidOperationException(String.Format("Cannot execute action #{0} because it requires the result of action #{1}", currentIndex, o.ProxyActionIndex));
                            }
                        }
                    }

                    // Get the method to invoke
                    Type targetType = action.Caller != null?action.Caller.GetType() : Type.GetType(action.MethodType);

                    MethodInfo method = targetType.GetMethod(action.MethodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

                    // Perform the action and store the result
                    object val = method.Invoke(action.Caller, action.Parameters);
                    result[currentIndex].ReturnValue = val;
                }
                catch (Exception ex)
                {
                    result[currentIndex].ReturnValue = ex is TargetInvocationException ?
                                                       ((TargetInvocationException)ex).InnerException :
                                                       ex;

                    // If request is specified as a transaction, break execution
                    if (request.StopOnError)
                    {
                        break;
                    }
                }
            }

            // Done, remove from static results and return
            _result            = null;
            this.CurrentAction = null;
            _instances.Remove(OperationContext.Current);

            return(result);
        }
Ejemplo n.º 3
0
 public ProxyResultActionData this[ProxyRequestAction action]
 {
     get { return(this[action.ActionIndex]); }
 }