public void Execute(object parameter)
        {
            var command = TargetInstance.GetType().GetProperty("Instance").GetValue(TargetInstance) as ICommand;
            var result  = _commandCoordinator.Handle(command);
            var process = Proxy as ICanProcessCommandProcess;

            process.Process(command, result);
        }
Example #2
0
        private object InvokeMethod(MethodBase method, Type[] parameterTypes, object[] parameters)
        {
            if (TargetInstance != null)
            {
                if (TargetType == null)
                {
                    TargetType = TargetInstance.GetType();
                }

                MethodBase underlyingMethod = TargetType.GetMethod(method.Name, parameterTypes);
                if (method == null)
                {
                    // Look for method definition in ancestor interfaces
                    foreach (Type interfaceType in TargetType.GetInterfaces())
                    {
                        underlyingMethod = interfaceType.GetMethod(method.Name, parameterTypes);
                        if (underlyingMethod != null)
                        {
                            break;
                        }
                    }
                }

                //MethodInfo underlyingMethod = underlyingType.GetMethod(method.Name);

                if (underlyingMethod == null)
                {
                    Debug.WriteLine("No underlying method found for " + method.Name);
                    throw new NotImplementedException(String.Format("Method {0} not found in underlying object", method.Name));
                }
                else
                {
                    return(underlyingMethod.Invoke(TargetInstance, parameters));
                }
            }

            return(null);
        }
        /// <summary>
        /// Creates the JavaScript client side object that matches the
        /// server side method signature. The JScript function maps
        /// to a CallMethod() call on the client.
        /// </summary>
        private void GenerateClassWrapperForCallbackMethods()
        {
            if (ServiceType != AjaxMethodCallbackServiceTypes.AjaxMethodCallback)
            {
                GenerateClassWrapperForWcfAndAsmx();
                return;
            }

            StringBuilder sb = new StringBuilder();

            if (GenerateClientProxyClass == ProxyClassGenerationModes.jsdebug)
            {
                ClientScriptProxy.Current.RegisterClientScriptInclude(this, typeof(ControlResources), ServerUrl.ToLower() + "/jsdebug", ScriptRenderModes.Script);
                return;
            }
            if (GenerateClientProxyClass == ProxyClassGenerationModes.Inline)
            {
                Type objectType = null;

                if (ClientProxyTargetType != null)
                {
                    objectType = ClientProxyTargetType;
                }
                else if (TargetInstance != null)
                {
                    objectType = TargetInstance.GetType();
                }
                // assume Page as default
                else
                {
                    objectType = Page.GetType();
                }

                sb.Append("var " + ID + " = { ");

                MethodInfo[] Methods = objectType.GetMethods(BindingFlags.Instance | BindingFlags.Public);
                foreach (MethodInfo Method in Methods)
                {
                    if (Method.GetCustomAttributes(typeof(CallbackMethodAttribute), false).Length > 0)
                    {
                        sb.Append("\r\n    " + Method.Name + ": function " + "(");

                        string ParameterList = "";
                        foreach (ParameterInfo Parm in Method.GetParameters())
                        {
                            ParameterList += Parm.Name + ",";
                        }
                        sb.Append(ParameterList + "completed,errorHandler)");

                        sb.AppendFormat(
                            @"
    {{
        var _cb = {0}_GetProxy();
        _cb.callMethod(""{1}"",[{2}],completed,errorHandler);
        return _cb;           
    }},", ID, Method.Name, ParameterList.TrimEnd(','));
                    }
                }

                if (sb.Length > 0)
                {
                    sb.Length--; // strip trailing ,
                }
                // End of class
                sb.Append("\r\n}\r\n");
            }
            string Url = null;

            if (string.IsNullOrEmpty(ServerUrl))
            {
                Url = Context.Request.Path;
            }
            else
            {
                Url = ResolveUrl(ServerUrl);
            }

            sb.Append(
                "function " + ID + @"_GetProxy() {
    var _cb = new AjaxMethodCallback('" + ID + "','" + Url + @"',
                                    { timeout: " + Timeout.ToString() + @",
                                      postbackMode: '" + PostBackMode.ToString() + @"',
                                      formName: '" + PostBackFormName + @"' 
                                    });
    return _cb;
}
");
            ClientScriptProxy.RegisterStartupScript(this, GetType(), ID + "_ClientProxy", sb.ToString(), true);
        }