コード例 #1
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 _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);
            }
        }
コード例 #2
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 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);
            }
        }
コード例 #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);
            }
        }
コード例 #4
0
 public TResult Invoke <TResult>(AspectActivatorContext activatorContext)
 {
     using (var context = _aspectContextFactory.CreateContext(activatorContext))
     {
         var aspectBuilder = _aspectBuilderFactory.Create(context);
         var invoke        = aspectBuilder.Build()(context);
         if (invoke.IsFaulted)
         {
             var innerException = invoke.Exception?.InnerException;
             throw context.InvocationException(innerException);
         }
         if (!invoke.IsCompleted)
         {
             invoke.GetAwaiter().GetResult();
         }
         return((TResult)context.ReturnValue);
     }
 }
コード例 #5
0
        public async Task <TReturn> InvokeAsync <TReturn>(AspectActivatorContext activatorContext)
        {
            using (var context = _aspectContextFactory.CreateContext <TReturn>(activatorContext))
            {
                var aspectBuilder = _aspectBuilderFactory.Create(context);
                await aspectBuilder.Build()(() => context.Target.Invoke(context.Parameters))(context);

                return(await Unwrap <TReturn>(context.ReturnParameter.Value));
            }
        }
コード例 #6
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);
            }
        }