protected InvokeResult InvokeListenerMethodOnListenerObject(object requestObject)
    {
        InvokeResult returnValue = new InvokeResult();

        try
        {
            var safeMethod       = new Spring.Reflection.Dynamic.SafeMethod(this._listenerMethod);
            var invocationResult = safeMethod.Invoke(this._listenerObject, requestObject);
            if (this._listenerMethod.ReturnType.IsAssignableFrom(typeof(Task)))
            {
                ((Task)invocationResult).GetAwaiter().GetResult();

                if (this._listenerMethod.ReturnType.IsGenericType)
                {
                    returnValue.ReturnedValue = ((Task <dynamic>)invocationResult).Result;
                }
                else
                {
                    returnValue.ReturnedValue = null;
                }
            }
            else
            {
                returnValue.ReturnedValue = invocationResult;
            }
        }
        catch (System.Exception ex)
        {
            returnValue.Exception = ex;
        }
        return(returnValue);
    }
Example #2
0
        /// <summary>
        /// Creates dynamic method instance for the specified <see cref="MethodInfo"/>.
        /// </summary>
        /// <param name="method">Method info to create dynamic method for.</param>
        /// <returns>Dynamic method for the specified <see cref="MethodInfo"/>.</returns>
        public static IDynamicMethod Create(MethodInfo method)
        {
            AssertUtils.ArgumentNotNull(method, "You cannot create a dynamic method for a null value.");

            IDynamicMethod dynamicMethod = new SafeMethod(method);

            return(dynamicMethod);
        }
        /// <summary>
        /// Avoid beforeFieldInit
        /// </summary>
        static LocalResourceManager()
        {
            LocalResXResourceProviderFactoryType = typeof(IResourceProvider).Assembly.GetType("System.Web.Compilation.ResXResourceProviderFactory", true);
            LocalResXResourceProviderType = typeof(IResourceProvider).Assembly.GetType("System.Web.Compilation.LocalResXResourceProvider", true);

            GetResourceProviderDelegate fnGetResourceProvider = null;
            ResourceProviderFactory rpf = null;
            SafeMethod glra = null;
            SecurityCritical.ExecutePrivileged(new PermissionSet(PermissionState.Unrestricted), delegate
            {
                fnGetResourceProvider = (GetResourceProviderDelegate)Delegate.CreateDelegate(typeof(GetResourceProviderDelegate), typeof(ResourceExpressionBuilder).GetMethod("GetLocalResourceProvider", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[] { typeof(TemplateControl) }, null));
                rpf = (ResourceProviderFactory)Activator.CreateInstance( LocalResXResourceProviderFactoryType, true );
                glra = new SafeMethod(LocalResXResourceProviderType.GetMethod("GetLocalResourceAssembly", BindingFlags.Instance | BindingFlags.NonPublic));
            });
            getLocalResourceProvider = fnGetResourceProvider;
            LocalResXResourceProviderFactory = rpf;
            fnGetLocalResourceAssembly = glra;
        }
Example #4
0
		public object Invoke(IMethodInvocation info)
		{
			try
			{
				MethodInfo methodInfo = info.Method;
				object returnValue = base.Invoke(methodInfo, info.Arguments, info.Proxy);

				if (returnValue != InvokeImplementation)
				{
					return returnValue;
				}

				var method = new SafeMethod(methodInfo);
				return method.Invoke(GetImplementation(), info.Arguments);
			}
			catch (TargetInvocationException ex)
			{
				exceptionInternalPreserveStackTrace.Invoke(ex.InnerException, new Object[] {});
				throw ex.InnerException;
			}
		}
        /// <summary>
        /// Invokes the joinpoint using dynamic reflection.
        /// </summary>
        /// <remarks>
        /// <p>
        /// Subclasses can override this to use custom invocation.
        /// </p>
        /// </remarks>
        /// <returns>
        /// The return value of the invocation of the joinpoint.
        /// </returns>
        /// <exception cref="System.Exception">
        /// If invoking the joinpoint resulted in an exception.
        /// </exception>
        /// <see cref="Spring.Aop.Framework.AbstractMethodInvocation.InvokeJoinpoint"/>
        protected override object InvokeJoinpoint()
        {
            MethodInfo targetMethodInfo = ((this.proxyMethod == null)) ? method : this.proxyMethod;

            IDynamicMethod targetMethod = new SafeMethod(targetMethodInfo);

            try
            {
                AssertUtils.Understands(target, "target", targetMethodInfo);
                return targetMethod.Invoke(target, arguments);
            }
            // Only happens if fallback to standard reflection.
            catch (TargetInvocationException ex)
            {
                throw ReflectionUtils.UnwrapTargetInvocationException(ex);
            }
        }
Example #6
0
        /// <summary>
        /// Creates dynamic method instance for the specified <see cref="MethodInfo"/>.
        /// </summary>
        /// <param name="method">Method info to create dynamic method for.</param>
        /// <returns>Dynamic method for the specified <see cref="MethodInfo"/>.</returns>
        public static IDynamicMethod Create(MethodInfo method)
        {
            AssertUtils.ArgumentNotNull(method, "You cannot create a dynamic method for a null value.");

            IDynamicMethod dynamicMethod = new SafeMethod(method);
            return dynamicMethod;
        }
        static WebApplicationContext()
        {
            ILog s_weblog = LogManager.GetLogger(typeof(WebApplicationContext));

            // register for ContextRegistry.Cleared event - we need to discard our cache in this case
            ContextRegistry.Cleared += new EventHandler(OnContextRegistryCleared);

#if !MONO_2_0
            if (HttpRuntime.AppDomainAppVirtualPath != null) // check if we're within an ASP.NET AppDomain!
            {
                // ensure HttpRuntime has been fully initialized!
                // this is a problem,.if ASP.NET Web Administration Application is used. This app does not fully set up the AppDomain...
                HttpRuntime runtime =
                    (HttpRuntime)
                    typeof(HttpRuntime).GetField("_theRuntime", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

                bool beforeFirstRequest = false;
                lock (runtime)
                {
                    beforeFirstRequest =
                        (bool)
                        typeof(HttpRuntime).GetField("_beforeFirstRequest", BindingFlags.Instance | BindingFlags.NonPublic).
                            GetValue(runtime);
                }
                s_weblog.Debug("BeforeFirstRequest:" + beforeFirstRequest);
                if (beforeFirstRequest)
                {
                    try
                    {
                        string firstRequestPath = HttpRuntime.AppDomainAppVirtualPath.TrimEnd('/') + "/dummy.context";
                        s_weblog.Info("Forcing first request " + firstRequestPath);
                        SafeMethod fnProcessRequestNow = new SafeMethod(typeof(HttpRuntime).GetMethod("ProcessRequestNow", BindingFlags.Static | BindingFlags.NonPublic));
                        SimpleWorkerRequest wr = new SimpleWorkerRequest(firstRequestPath, string.Empty, new StringWriter());
                        fnProcessRequestNow.Invoke(null, new object[] { wr });
                        //                        HttpRuntime.ProcessRequest(
                        //                            wr);
                        s_weblog.Info("Successfully processed first request!");
                    }
                    catch (Exception ex)
                    {
                        s_weblog.Error("Failed processing first request", ex);
                        throw;
                    }
                }
            }
#endif
        }
Example #8
0
        private void Initialize(string methodName, object[] argValues, object context)
        {
            Type contextType = (context is Type ? context as Type : context.GetType());

            // check the context type first
            MethodInfo mi = GetBestMethod(contextType, methodName, BINDING_FLAGS, argValues);

            // if not found, probe the Type's type          
            if (mi == null)
            {
                mi = GetBestMethod(typeof(Type), methodName, BINDING_FLAGS, argValues);
            }

            if (mi == null)
            {
                return;
            }
            else
            {
                ParameterInfo[] parameters = mi.GetParameters();
                if (parameters.Length > 0)
                {
                    ParameterInfo lastParameter = parameters[parameters.Length - 1];
                    cachedIsParamArray = lastParameter.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0;
                    if (cachedIsParamArray)
                    {
                        paramArrayType = lastParameter.ParameterType.GetElementType();
                        argumentCount = parameters.Length;
                    }
                }

                cachedInstanceMethod = new SafeMethod(mi);
                cachedInstanceMethodHash = CalculateMethodHash(contextType, argValues);
            }
        }