public TResult Invoke <TResult>(AspectActivatorContext activatorContext)
        {
            var context = _aspectContextFactory.CreateContext(activatorContext);

            try
            {
                var aspectBuilder = _aspectBuilderFactory.Create(context);
                var task          = aspectBuilder.Build()(context);
                if (task.IsFaulted)
                {
                    throw _aspectExceptionWrapper.Wrap(context, task.Exception.InnerException);
                }
                if (!task.IsCompleted)
                {
                    // try to avoid potential deadlocks.
                    NoSyncContextScope.Run(task);
                    // task.GetAwaiter().GetResult();
                }

                return((TResult)context.ReturnValue);
            }
            catch (Exception ex)
            {
                throw _aspectExceptionWrapper.Wrap(context, ex);
            }
            finally
            {
                _aspectContextFactory.ReleaseContext(context);
            }
        }
        public TResult Invoke <TResult>(AspectActivatorContext activatorContext)
        {
            var context = _aspectContextFactory.CreateContext(activatorContext);

            try
            {
                var aspectBuilder = _aspectBuilderFactory.Create(context);
                var task          = aspectBuilder.Build()(context);
                if (task.IsFaulted)
                {
                    throw context.InvocationException(task.Exception);
                }
                else if (!task.IsCompleted)
                {
                    task.GetAwaiter().GetResult();
                }
                return((TResult)context.ReturnValue);
            }
            catch (Exception ex)
            {
                throw context.InvocationException(ex);
            }
            finally
            {
                _aspectContextFactory.ReleaseContext(context);
            }
        }
Ejemplo n.º 3
0
        public TResult Invoke <TResult>(AspectActivatorContext activatorContext)
        {
            var context = aspectContextFactory.CreateContext(activatorContext);

            try
            {
                var aspectBuilder = aspectBuilderFactory.Create(context);
                var task          = aspectBuilder.Build()(context);
                if (task.IsFaulted)
                {
                    throw task.Exception.InnerException;
                }

                if (!task.IsCompleted)
                {
                    // try to avoid potential deadlocks.
                    NoSyncContextScope.Run(task);
                }
                return((TResult)context.ReturnValue);
            }
            finally
            {
                aspectContextFactory.ReleaseContext(context);
            }
        }
Ejemplo n.º 4
0
        public TResult Invoke <TResult>(AspectActivatorContext activatorContext)
        {
            var context = _aspectContextFactory.CreateContext(activatorContext);

            try
            {
                var aspectBuilder = _aspectBuilderFactory.Create(context);
                var invoke        = aspectBuilder.Build()(context);
                if (invoke.IsFaulted)
                {
                    var innerException = invoke.Exception?.InnerException;
                    throw context.InvocationException(innerException);
                }

                return((TResult)context.ReturnValue);
            }
            finally
            {
                _aspectContextFactory.ReleaseContext(context);
            }
        }