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
		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);
            }
        }
        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
        }