public void Invoke(InterceptionArgs arg)
        {
            arg.Proceed();

            if (this._action == null)
            {
                var      method     = this._type.GetMethod(this._methodName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static);
                object[] parameters = (method.GetParameters().Length == 0) ? null : new[] { this._key };
                var      instance   = this._instance;

                if (instance == null)
                {
                    if (method.IsStatic == false)
                    {
                        instance = (this._serviceProvider == null) ? Activator.CreateInstance(this._type) : ActivatorUtilities.CreateInstance(this._serviceProvider, this._type);
                    }
                }

                method.Invoke(instance, parameters);
            }
            else
            {
                this._action();
            }
        }
 public void Invoke(InterceptionArgs arg)
 {
     if (this.handlers.TryGetValue(arg.Method, out var handler) == true)
     {
         handler.Invoke(arg);
     }
 }
 public void Invoke(InterceptionArgs arg)
 {
     if (this.condition(arg) == true)
     {
         this.handler.Invoke(arg);
     }
 }
		public void Invoke(InterceptionArgs arg)
		{
			//call base implementation
			arg.Proceed();
			//then change the result
			arg.Result = 20;
		}
 public void Invoke(InterceptionArgs arg)
 {
     //call base implementation
     arg.Proceed();
     //then change the result
     arg.Result = 20;
 }
 public void Invoke(InterceptionArgs arg)
 {
     if (arg.Target is IInterceptionHandler)
     {
         (arg.Target as IInterceptionHandler).Invoke(arg);
     }
 }
Пример #7
0
        private InterceptionArgs CreateAspectArgs(MethodInfo methodInfo, object[] args)
        {
            var              realType         = _service.GetType();
            MethodInfo       mInfo            = realType.GetMethod(methodInfo.Name);
            InterceptionArgs interceptionArgs = new InterceptionArgs(mInfo, args);

            return(interceptionArgs);
        }
        public void Invoke(InterceptionArgs arg)
        {
            var handler = this.Interception;

            if (handler != null)
            {
                handler(this, arg);
            }
        }
        public void Invoke(InterceptionArgs arg)
        {
            var options = new TransactionOptions()
            {
                IsolationLevel = this.isolationLevel, Timeout = this.timeout
            };

            new TransactionScope(this.scopeOption, options, this.asyncFlowOption);
        }
 public void Invoke(InterceptionArgs arg)
 {
     if (arg.Method.ReturnType == typeof(void))
     {
         new Thread(() =>
         {
             arg.Proceed();
         }).Start();
     }
 }
        public void Invoke(InterceptionArgs arg)
        {
            var principal = ClaimsPrincipal.Current;

            if ((principal == null) || (!this.roles.Any(role => principal.IsInRole(role))))
            {
                throw new InvalidOperationException("Attepted to access protected method without needed security.");
            }

            arg.Proceed();
        }
        public void Invoke(InterceptionArgs arg)
        {
            var task = Task.Run(() =>
            {
                arg.Proceed();
            });

            if (task.Wait(TimeSpan.FromSeconds(this.TimeoutSeconds)) == false)
            {
                throw new TimeoutException();
            }
        }
Пример #13
0
        protected override object Invoke(MethodInfo targetMethod, object[] args)
        {
            InterceptionArgs arg = null;

            arg = new InterceptionArgs(this.target, targetMethod, () =>
            {
                arg.Result = targetMethod.Invoke(this.target, args);
                return(arg.Result);
            }, args);
            this.handler.Invoke(arg);
            return(arg.Result);
        }
        public void Invoke(InterceptionArgs arg)
        {
            for (var i = 0; i < this.Handlers.Count; ++i)
            {
                this.Handlers[i].Invoke(arg);

                if (arg.Handled == true)
                {
                    break;
                }
            }
        }
        public void Invoke(InterceptionArgs arg)
        {
            var timer = Stopwatch.StartNew();

            this.logger.Log(this.logLevel, new EventId(), $"About to invoke {arg.Method} of type {arg.Method.DeclaringType}", null, (state, ex) => state.ToString());
            try
            {
                arg.Proceed();
                this.logger.Log(this.logLevel, new EventId(), $"Invokation of {arg.Method} of type {arg.Method.DeclaringType} took {timer.Elapsed}", null, (state, ex) => state.ToString());
            }
            catch (Exception ex)
            {
                this.logger.Log(this.logLevel, new EventId(), $"Invokation of {arg.Method} took {timer.Elapsed} and resulted in exception {ex}", ex, (state, _) => state.ToString());
            }
        }
        public void Invoke(InterceptionArgs arg)
        {
            var key = this.CreateCacheKey(arg.Method, arg.Arguments);

            if (this.GetCachedResult(key, out var result) == false)
            {
                arg.Proceed();
                result = arg.Result;
                this.SetCacheResult(key, result);
            }
            else
            {
                arg.Result = result;
            }
        }
        public void Invoke(InterceptionArgs arg)
        {
            var methodAttrs = arg
                              .Method
                              .GetCustomAttributes <InterceptionAttribute>(true)
                              .OrderByDescending(x => x.Order);

            var typeAttrs = this.GetInterceptionAttributes(arg.Target.GetType())
                            .OrderByDescending(x => x.Order);

            var interfaceAttrs = arg
                                 .Target
                                 .GetType()
                                 .GetInterfaces()
                                 .SelectMany(x => this.GetInterceptionAttributes(x))
                                 .OrderByDescending(x => x.Order);

            var attrs = methodAttrs
                        .Concat(typeAttrs)
                        .Concat(interfaceAttrs);

            foreach (var attr in attrs)
            {
                IInterceptionHandler handler = null;

                if (attr is IHandlerFactory)
                {
                    handler = (attr as IHandlerFactory).Instantiate(this.serviceProvider);
                }
                else
                {
                    var handlerType = attr.InterceptionHandlerType;

                    if (handlerType != null)
                    {
                        handler = this.Instantiate(handlerType);
                    }
                }

                if (handler != null)
                {
                    handler.Invoke(arg);
                }
            }
        }
Пример #18
0
        protected override object Invoke(MethodInfo targetMethod, object[] args)
        {
            object[]         interceptions    = null;
            InterceptionArgs interceptionArgs = null;

            try
            {
                interceptionArgs = CreateAspectArgs(targetMethod, args);
                interceptions    = GetInterceptions(targetMethod);

                // BeforeMethodArgs çalıştırılır. Cache vb. gelen datalar result değişkenine aktarılır
                BeforeMethodArgs beforeMethodArgs = new BeforeMethodArgs(interceptionArgs);
                object           result           = RunOnBeforeInterception(interceptions, beforeMethodArgs);
                //result dolu ise ilgili methodun çalışmasına gerek yoktur

                if (result == null)
                {
                    //result null ise ilgili method çalıştırılır.
                    result = targetMethod.Invoke(_service, args);
                }

                //After İnterceptionlar çalıştırılır
                AfterMethodArgs afterMethodArgs = new AfterMethodArgs(interceptionArgs);
                RunOnAfterInterception(interceptions, new AfterMethodArgs(afterMethodArgs, result));
                //RunOnAfterInterception(interceptions, new AfterMethodArgs(interceptionArgs, result));

                return(result);
            }
            catch (Exception ex)
            {
                var exArg = new ExceptionMethodArgs(interceptionArgs, ex);
                RunOnExceptionInterception(interceptions, exArg);
                throw ex.InnerException ?? ex;
                //return null;
            }
            //catch (Exception ex) when (ex is TargetInvocationException)
            //{

            //    var exArg = new ExceptionMethodArgs(e,ex);
            //    RunOnExceptionInterception(interceptions, exArg);
            //    //throw ex.InnerException ?? ex;
            //    return null;
            //}
        }
Пример #19
0
        public void Invoke(InterceptionArgs arg)
        {
            var attrs = arg.Target.GetType().GetCustomAttributes(true).OfType <InterceptionAttribute>().OrderBy(x => x.Order);

            foreach (var attr in attrs)
            {
                var handlerType = attr.InterceptionHandlerType;

                if (handlerType != null)
                {
                    var handler = Activator.CreateInstance(handlerType) as IInterceptionHandler;

                    if (handler != null)
                    {
                        handler.Invoke(arg);
                    }
                }
            }
        }
Пример #20
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            var           method  = this.Target.GetType().GetMethod(binder.Name);
            Func <object> handler = () => { return(method.Invoke(this.Target, args)); };
            var           arg     = new InterceptionArgs(this.Target, method, handler, args);

            this.handler.Invoke(arg);

            if (arg.Handled == true)
            {
                result = arg.Result;
            }
            else
            {
                result = method.Invoke(this.Target, args);
            }

            return(true);
        }
        public void Invoke(InterceptionArgs arg)
        {
            var retries = 0;

            while (retries < this.numRetries)
            {
                try
                {
                    arg.Proceed();
                    break;
                }
                catch
                {
                    retries++;
                    if (retries == this.numRetries)
                    {
                        throw;
                    }
                    Thread.Sleep(this.delay);
                }
            }
        }
 public void Invoke(InterceptionArgs arg)
 {
     for (var i = 0; i < this.Retries; i++)
     {
         try
         {
             arg.Proceed();
             break;
         }
         catch
         {
             if (i != this.Retries - 1)
             {
                 Thread.Sleep(this.Delay);
             }
             else
             {
                 throw;
             }
         }
     }
 }
		public void Invoke(InterceptionArgs arg)
		{
			for (var i = 0; i < this.Retries; i++)
			{
				try
				{
					arg.Proceed();
					break;
				}
				catch
				{
					if (i != this.Retries - 1)
					{
						Thread.Sleep(this.Delay);
					}
					else
					{
						throw;
					}
				}
			}
		}
        public void Invoke(InterceptionArgs arg)
        {
            var isSetter                 = arg.Method.Name.StartsWith("set_");
            var propertyName             = isSetter ? arg.Method.Name.Substring(4) : string.Empty;
            var isNotifyPropertyChanging = isSetter && arg.Target is INotifyPropertyChanging;
            var isNotifyPropertyChanged  = isSetter && arg.Target is INotifyPropertyChanged;

            if (isNotifyPropertyChanging)
            {
                var eventDelegate = (MulticastDelegate)arg.Target.GetType().GetField(nameof(INotifyPropertyChanging.PropertyChanging), BindingFlags.Instance | BindingFlags.NonPublic).GetValue(arg.Target);
                var args          = new PropertyChangingEventArgs(propertyName);

                if (eventDelegate != null)
                {
                    foreach (var handler in eventDelegate.GetInvocationList())
                    {
                        handler.Method.Invoke(handler.Target, new object[] { arg.Target, args });
                    }
                }
            }

            arg.Proceed();

            if (isNotifyPropertyChanged)
            {
                var eventDelegate = (MulticastDelegate)arg.Target.GetType().GetField(nameof(INotifyPropertyChanged.PropertyChanged), BindingFlags.Instance | BindingFlags.NonPublic).GetValue(arg.Target);
                var args          = new PropertyChangedEventArgs(propertyName);

                if (eventDelegate != null)
                {
                    foreach (var handler in eventDelegate.GetInvocationList())
                    {
                        handler.Method.Invoke(handler.Target, new object[] { arg.Target, args });
                    }
                }
            }
        }
 public override void Invoke(InterceptionArgs arg)
 {
     Console.Out.WriteLine("Calling " + arg.Method);
 }
        public void Invoke(InterceptionArgs arg)
        {
            Array.ForEach(arg.Arguments, x => Validator.ValidateObject(x, new ValidationContext(x, this.serviceProvider, new Dictionary <object, object>())));

            Validator.ValidateObject(arg.Target, new ValidationContext(arg.Target, this.serviceProvider, new Dictionary <object, object>()));
        }
		public override void Invoke(InterceptionArgs arg)
		{
			Console.Out.WriteLine("Calling " + arg.Method);
		}
Пример #28
0
 public void Invoke(InterceptionArgs arg)
 {
     System.Diagnostics.Trace.WriteLine("Before call");
     arg.Proceed();
     System.Diagnostics.Trace.WriteLine("After call");
 }
Пример #29
0
 public void Invoke(InterceptionArgs arg)
 {
     this.action(arg);
 }
Пример #30
0
 public void Invoke(InterceptionArgs arg)
 {
     Console.Out.WriteLine($"Calling {arg.Method}");
 }