Example #1
0
        /// <summary>
        /// Wrapper method used to instrument System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction().
        /// </summary>
        /// <param name="asyncControllerActionInvoker">The AsyncControllerActionInvoker instance.</param>
        /// <param name="asyncResult">The <see cref="IAsyncResult"/> returned by <see cref="BeginInvokeAction"/>.</param>
        /// <returns>Returns the <see cref="bool"/> returned by the original EndInvokeAction().</returns>
        public static bool EndInvokeAction(dynamic asyncControllerActionInvoker, dynamic asyncResult)
        {
            AspNetMvc5Integration integration = null;

            try
            {
                if (HttpContext.Current != null)
                {
                    integration = HttpContext.Current?.Items[HttpContextKey] as AspNetMvc5Integration;
                }
            }
            catch
            {
                // TODO: log this as an instrumentation error, but continue calling instrumented method
            }

            try
            {
                // call the original method, catching and rethrowing any unhandled exceptions
                return(asyncControllerActionInvoker.EndInvokeAction(asyncResult));
            }
            catch (Exception ex)
            {
                integration?.SetException(ex);
                throw;
            }
            finally
            {
                integration?.Dispose();
            }
        }
Example #2
0
        /// <summary>
        /// Wrapper method used to instrument System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction().
        /// </summary>
        /// <param name="asyncControllerActionInvoker">The AsyncControllerActionInvoker instance.</param>
        /// <param name="controllerContext">The ControllerContext for the current request.</param>
        /// <param name="actionName">The name of the controller action.</param>
        /// <param name="callback">An <see cref="AsyncCallback"/> delegate.</param>
        /// <param name="state">An object that holds the state of the async operation.</param>
        /// <returns>Returns the <see cref="IAsyncResult "/> returned by the original BeginInvokeAction() that is later passed to <see cref="EndInvokeAction"/>.</returns>
        public static object BeginInvokeAction(
            dynamic asyncControllerActionInvoker,
            dynamic controllerContext,
            dynamic actionName,
            dynamic callback,
            dynamic state)
        {
            AspNetMvc5Integration integration = null;

            try
            {
                if (HttpContext.Current != null)
                {
                    integration = new AspNetMvc5Integration((object)controllerContext);
                    HttpContext.Current.Items[HttpContextKey] = integration;
                }
            }
            catch
            {
                // TODO: log this as an instrumentation error, but continue calling instrumented method
            }

            try
            {
                // call the original method, catching and rethrowing any unhandled exceptions
                return(asyncControllerActionInvoker.BeginInvokeAction(controllerContext, actionName, callback, state));
            }
            catch (Exception ex)
            {
                integration?.SetException(ex);
                throw;
            }
        }