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)
        {
            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 (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();
            }
        }
        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 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 });
                    }
                }
            }
        }
Esempio n. 13
0
 public void Invoke(InterceptionArgs arg)
 {
     System.Diagnostics.Trace.WriteLine("Before call");
     arg.Proceed();
     System.Diagnostics.Trace.WriteLine("After call");
 }