Ejemplo n.º 1
0
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            if (RunMethodPre)
            {
                args.Proceed();
            }

            if (DefaultProvider != null && !_defaultProviderSet)
            {
                _defaultProvider    = (TypedValueProvider)Activator.CreateInstance(DefaultProvider);
                _defaultProviderSet = true;
            }

            if (GameFunction)
            {
                try
                {
                    args.ReturnValue = JsonConvert.DeserializeObject(ScriptInterface.Instance.CallGameFunction(Name, args.Arguments.ToArray()), (args.Method as MethodInfo).ReturnType);
                }
                catch
                {
                    args.ReturnValue = DefaultValue ?? _defaultProvider.Provide((args.Method as MethodInfo).ReturnType);
                }
            }
            else
            {
                args.ReturnValue = FlashUtil.Call(Name, (args.Method as MethodInfo).ReturnType, args.Arguments.ToArray());
            }
            if (RunMethodPost && !RunMethodPre)
            {
                args.Proceed();
            }
        }
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            if (args.Instance is ICacheAware cacheAware && !cacheAware.CacheEnabled)
            {
                args.Proceed();
                return;
            }

            var key = GetKey(args.Method as MethodInfo, args.Arguments);

            using (var connection = ConnectionMultiplexer.Connect(redisServer.Value))
            {
                var db         = connection.GetDatabase();
                var redisValue = db.StringGet(key);

                if (redisValue.IsNullOrEmpty)
                {
                    args.Proceed();
                    db.StringSet(key, JsonConvert.SerializeObject(args.ReturnValue), Expiry);
                }
                else
                {
                    args.ReturnValue = JsonConvert.DeserializeObject(redisValue.ToString(), (args.Method as MethodInfo).ReturnType);
                }
            }
        }
Ejemplo n.º 3
0
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            //var form =(Form) args.Instance;
            //if (form.InvokeRequired)
            //{
            //    form.Invoke(new Action(args.Proceed));
            //}
            //else
            //{
            //    args.Proceed();
            //}

            var form = args.Instance as Form;

            if (form == null)
            {
                args.Proceed();
            }
            if (form.InvokeRequired)
            {
                form.Invoke(new Action(args.Proceed));
            }
            else
            {
                args.Proceed();
            }
        }
Ejemplo n.º 4
0
    public override void OnInvoke(MethodInterceptionArgs args)
    {
        Control c = (Control)args.Instance;

        if (!c.InvokeRequired)
        {
            args.Proceed();
        }
        else
        {
            c.Invoke((Action)(() => args.Proceed()));
        }
    }
Ejemplo n.º 5
0
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            if( args.Method.IsConstructor || args.Method.Name == "NewSession")
            {
                args.Proceed();
            }

            var c = args.Instance as IProvideNewSession;

            using( c.NewSession() )
            {
                args.Proceed();
            }
        }
Ejemplo n.º 6
0
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            if (args.Method.IsConstructor || args.Method.Name == "NewSession")
            {
                args.Proceed();
            }

            var c = args.Instance as IProvideNewSession;

            using (c.NewSession())
            {
                args.Proceed();
            }
        }
Ejemplo n.º 7
0
 public sealed override void OnInvoke(MethodInterceptionArgs args)
 {
     if (null != args.Instance)
     {
         lock (args.Instance)
         {
             args.Proceed();
         }
     }
     else
     {
         args.Proceed();
     }
 }
Ejemplo n.º 8
0
 public override void OnInvoke(MethodInterceptionArgs args)
 {
     for (var left = _times; left > 0; left--)
     {
         try
         {
             args.Proceed();
             break;
         }
         catch (Exception)
         {
         }
     }
     args.Proceed();     // optional
 }
Ejemplo n.º 9
0
 public override void OnInvoke(MethodInterceptionArgs eventArgs)
 {
     if (ConfigurationManager.AppSettings["disable_Async"] != null)
     {
         eventArgs.Proceed();
     }
     else
     {
         new Thread(() =>
         {
             eventArgs.Proceed();
             ConnectionManager.CloseConnection();
         }).Start();
     }
 }
            public override void OnInvoke(MethodInterceptionArgs args)
            {
                IDispatcherObject threadAffined = args.Instance as IDispatcherObject;
                IDispatcher       dispatcher    = threadAffined.Dispatcher;

                if (dispatcher == null)
                {
                    throw new InvalidOperationException("Cannot dispatch method: synchronization context is null");
                }


                if (this.isAsync)
                {
                    dispatcher.BeginInvoke(new WorkItem(args, true));
                }
                else if (dispatcher.CheckAccess())
                {
                    args.Proceed();
                }
                else
                {
                    WorkItemWithExceptionInterceptor workItem = new WorkItemWithExceptionInterceptor(args);
                    dispatcher.Invoke(workItem);

                    if (workItem.HasError)
                    {
                        throw new AggregateException("Exception has been thrown by the target of an invocation", workItem.Exception);
                    }
                }
            }
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            var aggregateExceptions = new List <Exception>();
            var retries             = 0;

            while (retries++ < this._maxRetries)
            {
                try
                {
                    Console.WriteLine();
                    Console.WriteLine("starting transaction...");
                    using (var scope = new TransactionScope())
                    {
                        Console.WriteLine("transaction started...");
                        Console.WriteLine("start invoking method from aspect...");
                        args.Proceed();
                        Console.WriteLine("method invokation done...");
                        scope.Complete();
                        Console.WriteLine("scope completed...");
                    }

                    break;
                }
                catch (Exception ex)
                {
                    aggregateExceptions.Add(ex);
                    if (retries >= this._maxRetries)
                    {
                        throw new AggregateException($"Trasaction failed after {this._maxRetries} attempts", aggregateExceptions);
                    }

                    Thread.Sleep(TimeSpan.FromSeconds(this._retryDelay));
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        ///    Method invoked <i>instead</i> of the original method.
        /// </summary>
        /// <param name="args">Method invocation context.</param>
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            for (var retryIndex = 0;; retryIndex++)
            {
                try
                {
                    // Invoke the intercepted method
                    args.Proceed();

                    // If we get here, it means the execution was successful.
                    return;
                }
                catch (Exception e) when(ExceptionTypeFilter(e))
                {
                    // The intercepted method threw an exception. Figure out if we can retry the method.
                    if (retryIndex < MaxRetries)
                    {
                        // Yes, we can retry. Write some message and wait a bit.

                        Console.WriteLine(
                            "Method failed with exception {0}. Sleeping {1} s and retrying. This was our {2}th attempt.",
                            e.GetType().Namespace, Delay, retryIndex + 1);

                        Thread.Sleep(TimeSpan.FromSeconds(Delay));

                        // Continue to the next iteration.
                    }
                    else
                    {
                        // No, we cannot retry. Retry the exception.
                        throw;
                    }
                }
            }
        }
        private static readonly ManualResetEvent ZeroPendingInvokes = new ManualResetEvent(true); //true/signalled if there are no invokes pending

        public override sealed void OnInvoke(MethodInterceptionArgs args)
        {
            var synchronizeObject = InvokeRequiredInfo.SynchronizeObject ?? args.Instance as ISynchronizeInvoke;

            if (synchronizeObject == null || !synchronizeObject.InvokeRequired)
            {
                args.Proceed();
            }
            else
            {
                lock (InvokeLock)
                {
                    try
                    {
                        if (Interlocked.Increment(ref pendingInvokes) > 0)
                        {
                            ZeroPendingInvokes.Reset();
                        }
                        synchronizeObject.Invoke(new Action(args.Proceed), new object[0]);
                    }
                    catch (ObjectDisposedException e)
                    {
                        LogInvokeError(args.Method.Name, e, false);
                    }
                    finally
                    {
                        if (Interlocked.Decrement(ref pendingInvokes) == 0)
                        {
                            ZeroPendingInvokes.Set();
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
        private static readonly ManualResetEvent ZeroPendingInvokes = new ManualResetEvent(true); //true/signalled if there are no invokes pending
        
        public override sealed void OnInvoke(MethodInterceptionArgs args)
        {
            var synchronizeObject = InvokeRequiredInfo.SynchronizeObject ?? args.Instance as ISynchronizeInvoke;

            if (synchronizeObject == null || !synchronizeObject.InvokeRequired)
            {
                args.Proceed();
            }
            else
            {
                lock (InvokeLock)
                {
                    try
                    {
                        if (Interlocked.Increment(ref pendingInvokes) > 0)
                        {
                            ZeroPendingInvokes.Reset();
                        }
                        synchronizeObject.Invoke(new Action(args.Proceed), new object[0]);
                    }
                    catch (ObjectDisposedException e)
                    {
                        LogInvokeError(args.Method.Name, e, false);
                    }
                    finally
                    {
                        if (Interlocked.Decrement(ref pendingInvokes) == 0)
                        {
                            ZeroPendingInvokes.Set();
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
0
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            Console.WriteLine("{0}方法开始:{1}", args.Method.Name, DateTime.Now);
            using (var ts = new TransactionScope())
            {
                var retries   = 3;//重试3次
                var succeeded = false;
                while (!succeeded)
                {
                    try
                    {
                        args.Proceed(); //继续执行拦截的方法
                        ts.Complete();  //事务完成
                        succeeded = true;
                    }

                    catch (Exception ex)
                    {
                        if (retries >= 0)
                        {
                            retries--;
                        }
                        else
                        {
                            throw ex;
                        }
                    }
                }
            }
            Console.WriteLine("{0}方法结束:{1}", args.Method.Name, DateTime.Now);
        }
Ejemplo n.º 16
0
        public override void OnInvoke(MethodInterceptionArgs eventArgs)
        {
            DispatcherObject dispatcherObject = (DispatcherObject)(eventArgs.Instance ?? eventArgs.Arguments.GetArgument(0));


            if (dispatcherObject == null || dispatcherObject.CheckAccess())
            {
                // We are already in the GUI thread. Proceed.
                eventArgs.Proceed();
            }
            else
            {
                if (this.Async)
                {
                    // Invoke the target method asynchronously (don't wait).
                    dispatcherObject.Dispatcher.BeginInvoke(this.Priority,
                                                            new Action(eventArgs.Proceed));
                }
                else
                {
                    // Invoke the target method synchronously.
                    dispatcherObject.Dispatcher.Invoke(
                        this.Priority,
                        new Action(eventArgs.Proceed));
                }
            }
        }
Ejemplo n.º 17
0
        public void Process(MethodInterceptionArgs args, ILogger log)
        {
            try
            {
                args.Proceed();
            }
            catch (DefaultException ex)
            {
                log.Error(string.Format("Mensaje: {0} Trace: {1}", ex.Message, ex.StackTrace));

                var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
                var url = urlHelper.Action("OperationError", "Error", new { area = "" });
                url += "/" + ex.Message;
                var result = new RedirectResult(url);

                args.ReturnValue = result;
            }
            catch (Exception ex)
            {
                log.Error(string.Format("Mensaje: {0} Trace: {1}", ex.Message, ex.StackTrace));

                var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
                var url = urlHelper.Action("Index", "Error", new { area = "" });

                var result = new RedirectResult(url);

                args.ReturnValue = result;
            }
        }
Ejemplo n.º 18
0
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            var i = GetArgumentIndex(args);

            if (!i.HasValue)
            {
                args.Proceed();
                return;
            }

            using (IDbConnection db = new MySqlConnection(ConnectionString))
            {
                args.Arguments.SetArgument(i.Value, db);
                args.Proceed();
            }
        }
Ejemplo n.º 19
0
        public override void OnInvoke( MethodInterceptionArgs eventArgs )
        {
            // Compute the cache key.
            string key = this.formatStrings.Format( eventArgs.Instance,
                         eventArgs.Method,
                         eventArgs.Arguments.ToArray() );

            object value;

            if ( !cache.TryGetValue( key, out value ) )
            {
                lock ( this )
                {
                    if ( !cache.TryGetValue( key, out value ) )
                    {
                        eventArgs.Proceed();
                        value = eventArgs.ReturnValue;
                        cache.Add( key, value );
                        return;
                    }
                }
            }

            eventArgs.ReturnValue = value;
        }
Ejemplo n.º 20
0
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            Console.WriteLine("Starting transaction");
            // start new transaction
            using (var scope = new TransactionScope())
            {
                // retry up to three times
                var retries = 3;
                var succeeded = false;
                while (!succeeded)
                {
                    try
                    {
                        args.Proceed();

                        // complete transaction
                        scope.Complete();
                        succeeded = true;
                    }
                    catch
                    {
                        // don't re-throw until the
                        // retry limit is reached
                        if (retries >= 0)
                            retries--;
                        else
                            throw;
                    }
                }
            }
            Console.WriteLine("Transaction complete");
        }
Ejemplo n.º 21
0
        public override void OnInvoke(MethodInterceptionArgs eventArgs)
        {
            // Compute the cache key.
            string key = this.formatStrings.Format(eventArgs.Instance,
                                                   eventArgs.Method,
                                                   eventArgs.Arguments.ToArray());

            object value;

            if (!cache.TryGetValue(key, out value))
            {
                lock (this)
                {
                    if (!cache.TryGetValue(key, out value))
                    {
                        eventArgs.Proceed();
                        value = eventArgs.ReturnValue;
                        cache.Add(key, value);
                        return;
                    }
                }
            }

            eventArgs.ReturnValue = value;
        }
Ejemplo n.º 22
0
        /// <summary>
        ///   Method invoked <i>instead</i> of the method to which the aspect has been applied.
        /// </summary>
        /// <param name="args">Advice arguments.</param>
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            //AmbientDataContextAmbientScopeProvider.Begin()
            //Auditing
            //Save
            //Disposing

            var auditingManager = CreateAuditingManager();

            using (var scope = auditingManager.BeginScope())
            {
                try
                {
                    args.Proceed();
                    var exs = auditingManager.Current !.Log.Exceptions;
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    scope.SaveAsync();
                }
            }
        }
            public void OnWaitOne(MethodInterceptionArgs args)
            {
                DeadlockMonitor.ExecuteAction(
                    () =>
                {
                    if (!(args.Instance is Mutex))
                    {
                        return;
                    }

                    if (args.Arguments.Count == 0 || args.Arguments[0] is bool ||
                        (args.Arguments[0] is int && (int)args.Arguments[0] == Timeout.Infinite))
                    {
                        Mutex mutex      = args.Instance as Mutex;
                        bool?exitContext = args.Arguments.Count > 0 ? (bool?)args.Arguments[0] : null;
                        LockAspectHelper.NoTimeoutAcquire(
                            () => DeadlockMonitor.EnterWaiting(mutex, ResourceType.Lock),
                            timeout =>
                            exitContext.HasValue
                                        ? mutex.WaitOne(timeout, exitContext.Value)
                                        : mutex.WaitOne(timeout),
                            () => DeadlockMonitor.ConvertWaitingToAcquired(mutex, ResourceType.Lock),
                            () => DeadlockMonitor.ExitWaiting(mutex, ResourceType.Lock));
                    }
                    else
                    {
                        args.Proceed();

                        if ((bool)args.ReturnValue)
                        {
                            DeadlockMonitor.EnterAcquired(args.Instance, ResourceType.Lock);
                        }
                    }
                });
            }
Ejemplo n.º 24
0
 public override void OnInvoke(MethodInterceptionArgs args)
 {
     try
     {
         if (_commandContract.PreCondition())
         {
             _commandContract.PreConditionAsync().ContinueWith(task =>
             {
                 if (task.Result)
                 {
                     args.Proceed();
                 }
                 else
                 {
                     args.ReturnValue = false;
                 }
             });
         }
         else
         {
             args.ReturnValue = false;
         }
     }
     catch (Exception e)
     {
         args.ReturnValue = false;
     }
 }
Ejemplo n.º 25
0
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            Control c = null;

            if (args.Instance is Control)
            {
                c = (Control)args.Instance;
            }
            else if (args.Instance is ListViewItem)
            {
                c = ((ListViewItem)args.Instance).ListView;
            }
            else if (args.Instance is DataGridViewRow)
            {
                c = ((DataGridViewRow)args.Instance).DataGridView;
            }
            if (c.InvokeRequired)
            {
                c.BeginInvoke(new Action(args.Proceed));
            }
            else
            {
                args.Proceed();
            }
        }
Ejemplo n.º 26
0
 public override void OnInvoke(MethodInterceptionArgs args)
 {
     LoggingHelper.Writelog("Starting transaction");
     using (var scope = new TransactionScope())
     {
         var retries   = 3;
         var succeeded = false;
         while (!succeeded)
         {
             try
             {
                 args.Proceed();//包含了被调用方法传递过来的参数了
                 scope.Complete();
                 succeeded = true;
             }
             catch
             {
                 if (retries >= 0)
                 {
                     retries--;
                 }
                 else
                 {
                     throw;
                 }
             }
         }
     }
     LoggingHelper.Writelog("Transaction complete");
 }
Ejemplo n.º 27
0
        public void OnMethodInvokeBase(MethodInterceptionArgs args)
        {
            var            methodStrategy    = this.MethodAttributes[args.Method.Name];
            IDisposable    implicitOpertaion = null;
            ITrackedObject stackPeek         = StackTrace.StackPeek() as ITrackedObject;

            if (methodStrategy == MethodSnapshotStrategy.Always ||
                (methodStrategy == MethodSnapshotStrategy.Auto && (stackPeek == null || !ReferenceEquals(stackPeek.Tracker, this.ThisTracker))))

            {
                implicitOpertaion = this.ThisTracker.StartImplicitOperation();
            }
            try
            {
                StackTrace.PushOnStack(args.Instance);
                args.Proceed();
            }
            finally
            {
                StackTrace.PopFromStack();
                if (implicitOpertaion != null)
                {
                    implicitOpertaion.Dispose();
                }
            }
        }
        public void OnMethodInvokeBase(MethodInterceptionArgs args)
        {
            MethodInfo methodInfo = (MethodInfo)args.Method;

            if (methodInfo.IsGenericMethod)
            {
                methodInfo = methodInfo.GetGenericMethodDefinition();
            }

            var            methodDescriptor = this.MethodAttributes[new MemberInfoIdentity(methodInfo)];
            IDisposable    operationScope   = null;
            ITrackedObject stackPeek        = StackTrace.StackPeek() as ITrackedObject;


            if (methodDescriptor.MethodOperationStrategy == MethodOperationStrategy.Always ||
                (methodDescriptor.MethodOperationStrategy == MethodOperationStrategy.Auto &&
                 (stackPeek == null || !ReferenceEquals(stackPeek.Tracker, this.ThisTracker))))
            {
                operationScope = this.ThisTracker.StartImplicitOperationScope(string.Format(this.MethodOperationStringFormat, methodDescriptor.OperationName ?? args.Method.Name));
            }
            try
            {
                StackTrace.PushOnStack(args.Instance);
                args.Proceed();
            }
            finally
            {
                StackTrace.PopFromStack();
                if (operationScope != null)
                {
                    operationScope.Dispose();
                }
            }
        }
 public override void OnInvoke(MethodInterceptionArgs args)
 {
     LoggingHelper.Writelog("Starting transaction");
     using (var scope = new TransactionScope())
     {
         var retries = 3;
         var succeeded = false;
         while (!succeeded)
         {
             try
             {
                 args.Proceed();//包含了被调用方法传递过来的参数了
                 scope.Complete();
                 succeeded = true;
             }
             catch
             {
                 if (retries >= 0)
                     retries--;
                 else
                     throw;
             }
         }
     }
     LoggingHelper.Writelog("Transaction complete");
 }
 public override void OnInvoke(MethodInterceptionArgs args)
 {
     try
     {
         args.Proceed();
     }
     catch (Exception) { }
 }
 public override void OnInvoke(MethodInterceptionArgs args)
 {
     try
     {
         args.Proceed();
     }
     catch (Exception) { }
 }
Ejemplo n.º 32
0
            public override void OnInvoke(MethodInterceptionArgs args)
            {
                var target = (SomeClass)args.Instance;

                target.SomeFunction();

                args.Proceed();     // performs the method it applied to
            }
Ejemplo n.º 33
0
 public override void OnInvoke(MethodInterceptionArgs args)
 {
     var form = (Form) args.Instance;
     if (form.InvokeRequired)
         form.Invoke(new Action(args.Proceed));
     else
         args.Proceed();
 }
Ejemplo n.º 34
0
 public override void OnInvoke(MethodInterceptionArgs args)
 {
     foreach (int p in this.encodedParams)
     {
         args.Arguments.SetArgument(p, "encoded value");
     }
     args.Proceed();
 }
        public void OnEditableObjectImplementationInvoke(MethodInterceptionArgs args)
        {
            if (!this.interfaceImplementationMap.ContainsKey(args.Method))
            {
                args.Proceed();
            }

            args.ReturnValue = this.interfaceImplementationMap[args.Method].Invoke(this, new object[0]);
        }
Ejemplo n.º 36
0
 public override void OnInvoke(MethodInterceptionArgs args)
 {
     DateTime startTime = DateTime.Now;
     args.Proceed();
     long duration = (DateTime.Now.Ticks - startTime.Ticks) / 10000;
     // give info only the process that takes more than 200 msec 
     if (duration > 200)
         mLogger.Info("{0}->{1} proceeded in {2} msec.", args.Instance, args.Method, duration);
 }
Ejemplo n.º 37
0
        /// <summary>
        /// Method invoked <i>instead</i> of the method to which the aspect has been applied.
        /// </summary>
        /// <param name="args">Advice arguments.</param>
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            args.Proceed();

            if (args.Instance is IService)
            {
                (args.Instance as IService).Transaction.Commit();
            }
        }
            internal static void OnEnter(MethodInterceptionArgs args, ResourceType type, bool addAcquierdEdge = true)
            {
                Func <int, bool> acquireLock;

                if (args.Arguments.Count == 0)   // when arguments count == 0 it must be ReaderWriterLockSlim
                {
                    acquireLock = timeout =>
                    {
                        bool lockTaken;
                        ReaderWriterLockSlim rwl = (ReaderWriterLockSlim)args.Instance;
                        switch (type)
                        {
                        case ResourceType.Read:
                            lockTaken = rwl.TryEnterReadLock(timeout);
                            break;

                        case ResourceType.Write:
                            lockTaken = rwl.TryEnterWriteLock(timeout);
                            break;

                        case ResourceType.UpgradeableRead:
                            lockTaken = rwl.TryEnterUpgradeableReadLock(timeout);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                        return(lockTaken);
                    };
                }
                else
                {
                    acquireLock = timeout =>
                    {
                        bool lockTaken;
                        args.Arguments.SetArgument(0, timeout);

                        try
                        {
                            args.Proceed();
                            lockTaken = true;
                        }
                        catch (ApplicationException)
                        {
                            lockTaken = false;
                        }
                        return(lockTaken);
                    };
                }

                LockAspectHelper.NoTimeoutAcquire(
                    () => DeadlockMonitor.EnterWaiting(args.Instance, ResourceType.Read),
                    acquireLock,
                    addAcquierdEdge ? () => DeadlockMonitor.ConvertWaitingToAcquired(args.Instance, ResourceType.Read) : (Action)(() => { }),
                    () => DeadlockMonitor.ExitWaiting(args.Instance, ResourceType.Read));
            }
Ejemplo n.º 39
0
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            for (int i = 0; i < args.Arguments.Count; i++)
            {
                FixString(args, i);
                FixStringsInObjects(args.Arguments[i]);
            }

            args.Proceed();
        }
Ejemplo n.º 40
0
		public override void OnInvoke( MethodInterceptionArgs args )
		{
			var coercer = args.Instance as ICoercer;
			if ( coercer != null )
			{
				var arguments = args.Arguments;
				arguments.SetArgument( 0, coercer.Coerce( arguments.GetArgument( 0 ) ) );
			}
			args.Proceed();
		}
Ejemplo n.º 41
0
 public override void OnInvoke(MethodInterceptionArgs eventArgs)
 {
     if (MainControl.InvokeRequired)
     {
         MainControl.BeginInvoke(eventArgs.Proceed);
     }
     else
     {
         eventArgs.Proceed();
     }
 }
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            var instanciaAppService = args.Instance as AppService;

            if (instanciaAppService == null)
                throw new Exception("Se agregó el atributo commits sobre una clase que no hereda de AppService");

            instanciaAppService.BeginTransaction();
            args.Proceed();
            instanciaAppService.Commit();
        }
Ejemplo n.º 43
0
		public override void OnInvoke( MethodInterceptionArgs args )
		{
			var specification = args.Instance as ISpecification;
			if ( specification != null )
			{
				args.ReturnValue = specification.IsSatisfiedBy( args.Arguments[0] );
			}
			else
			{
				args.Proceed();
			}
		}
		public override void OnInvoke( MethodInterceptionArgs args )
		{
			var invocation = args.Instance as IParameterizedSourceRelay;
			if ( invocation != null )
			{
				args.ReturnValue = invocation.Get( args.Arguments[0] );
			}
			else
			{
				args.Proceed();
			}
		}
		public override void OnInvoke( MethodInterceptionArgs args )
		{
			var controller = args.Instance as IAutoValidationController;
			if ( controller != null && !controller.IsActive )
			{
				args.ReturnValue = controller.Execute( args.Arguments[0], new Invocation( args.GetReturnValue ) ) ?? args.ReturnValue;
			}
			else
			{
				args.Proceed();
			}
		}
		public override void OnInvoke( MethodInterceptionArgs args )
		{
			var invocation = args.Instance as ICommandRelay;
			if ( invocation != null )
			{
				invocation.Execute( args.Arguments[0] );
			}
			else
			{
				args.Proceed();
			}
		}
Ejemplo n.º 47
0
		public override void OnInvoke( MethodInterceptionArgs args )
		{
			var source = args.Instance as IPolicySource;
			if ( source != null )
			{
				source.Get().Execute( args.Proceed );
			}
			else
			{
				args.Proceed();
			}
		}
Ejemplo n.º 48
0
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            if ( args.Method.IsConstructor )
            {
                args.Proceed();
            }

            var c = args.Instance as CmdletProvider;

            if (c.TransactionAvailable())
            {
                using (c.CurrentPSTransaction)
                {
                    args.Proceed();
                }
            }
            else
            {
                args.Proceed();
            }
        }
Ejemplo n.º 49
0
 public override void OnInvoke(MethodInterceptionArgs args)
 {
     var dispatcher = (Form) args.Instance;
     if (!dispatcher.InvokeRequired)
     {
         args.Proceed();
     }
     else
     {
         dispatcher.Invoke(new Action(args.Proceed));
     }
 }
 public override void OnInvoke(MethodInterceptionArgs args)
 {
     var activity = args.Instance as Activity;
     if (activity == null)
     {
         Log.Error("OnGuiThreadAttribute", "OnGuiThreadAttribute can only be used on methods within an Activity");
         args.Proceed();
     }
     else
     {
         activity.RunOnUiThread(args.Proceed);
     }
 }
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            for (int i = 0; i < this.filters.Length; i++)
            {
                FilterAttribute filter = this.filters[i];
                if (filter != null)
                {
                    args.Arguments[i] = filter.ApplyFilter(args.Arguments[i]);
                }
            }

            args.Proceed();
        }
Ejemplo n.º 52
0
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            base.OnInvoke(args);

            if (args.Arguments.Count > 0)
            {
                if (args.Arguments[0] is string)
                {
                    args.Arguments[0] = (args.Arguments[0] as string).ToLower();
                }
            }
            args.Proceed();
        }
		public override void OnInvoke( MethodInterceptionArgs args )
		{
			var controller = args.Instance as IAutoValidationController;
			if ( controller != null && !controller.IsActive )
			{
				var parameter = args.Arguments[0];
				args.ReturnValue = controller.Handles( parameter ) || controller.Marked( parameter, args.GetReturnValue<bool>() );
			}
			else
			{
				args.Proceed();
			}
		}
 public override void OnInvoke(MethodInterceptionArgs eventArgs)
 {
     if (Configuration.IsRecording())
     {
         eventArgs.Proceed();
         if (RecordingStack.Count > 0)
         {
             Guid callGuid = RecordingStack.Peek();
             RecordingServices.Recorder.RecordDependency(callGuid, eventArgs.Instance, (MethodInfo)eventArgs.Method, eventArgs.ReturnValue);
         }
     }
     else
     {
         if (RecordingServices.DependencyPlayback.HasReturnValue((MethodInfo)eventArgs.Method))
         {
             eventArgs.ReturnValue = RecordingServices.DependencyPlayback.GetReturnValue((MethodInfo)eventArgs.Method);
         }
         else
         {
             eventArgs.Proceed();
         }
     }
 }
Ejemplo n.º 55
0
 public override void OnInvoke(MethodInterceptionArgs args)
 {
   Control c = null;
   if (args.Instance is Control)
     c = (Control) args.Instance;
   else if (args.Instance is ListViewItem)
     c = ((ListViewItem) args.Instance).ListView;
   else if (args.Instance is DataGridViewRow)
     c = ((DataGridViewRow)args.Instance).DataGridView;
   if (c.InvokeRequired)
     c.BeginInvoke(new Action(args.Proceed));
   else
     args.Proceed();
 }
 public override void OnInvoke(MethodInterceptionArgs eventArgs)
 {
     var targetControl = eventArgs.Instance as Control;
     if (targetControl == null)
     {
         return;
     }
     if (targetControl.InvokeRequired)
     {
         targetControl.Invoke(new Action(eventArgs.Proceed));
     }
     else
     {
         eventArgs.Proceed();
     }
 }
Ejemplo n.º 57
0
        public void Process(MethodInterceptionArgs args, ILogger log)
        {
            var controller = (Controller)args.Instance;

            if (controller.ModelState.IsValid)
            {
                try
                {
                    args.Proceed();
                }
                catch (DefaultException ex)
                {
                    log.Error(string.Format("Mensaje: {0} Trace: {1}", ex.Message, ex.StackTrace));

                    var jsonResponse = new JsonResponse { Message = ex.Message };

                    args.ReturnValue = new JsonResult { Data = jsonResponse, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
                }
                catch (Exception ex)
                {
                    string mensajeError = PresentationResources.DatosIncorrectos;

                    log.Error(string.Format("Mensaje: {0} Trace: {1}", ex.Message, ex.StackTrace));

                    switch (ex.HResult)
                    {
                        case Constantes.Error2146233087:
                            mensajeError = PresentationResources.NoSePuedeProcesar;
                            break;
                    }

                    var jsonResponse = new JsonResponse { Message = mensajeError };
                    args.ReturnValue = new JsonResult { Data = jsonResponse, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
                }
            }
            else
            {
                string message = string.Join("<br />", controller.ModelState.Values.SelectMany(p => p.Errors).Select(p => p.ErrorMessage));

                var jsonResponse = new JsonResponse { Message = message };

                args.ReturnValue = new JsonResult { Data = jsonResponse, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
            }
        }
Ejemplo n.º 58
0
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            var cacheKey = BuildCacheKey(args);

            if (HttpContext.Current.Cache[cacheKey] != null)
            {
                args.ReturnValue = HttpContext.Current.Cache[cacheKey];
                return;
            }

            args.Proceed();

            HttpContext.Current.Cache.Add(cacheKey, args.ReturnValue,
               null,
               DateTime.Now.AddSeconds(30),
               Cache.NoSlidingExpiration,
               CacheItemPriority.Normal,
               null);
        }
        public override void OnInvoke( MethodInterceptionArgs args )
        {
            DispatcherObject dispatcherObject = (DispatcherObject) args.Instance;

            if ( this.Async )
            {
                // Invoke the method asynchronously on the GUI thread.
                dispatcherObject.Dispatcher.BeginInvoke( this.priority, new Action( args.Proceed ) );
            }
            else if ( dispatcherObject.CheckAccess() )
            {
                // We have access to the GUI object. Invoke the method synchronously.
                args.Proceed();
            }
            else
            {
                // We don't have access to the GUI thread. Invoke the method synchronously on that thread.
                dispatcherObject.Dispatcher.Invoke( DispatcherPriority.Normal, new Action( args.Proceed ) );
            }
        }
        // Record time spent executing the method
        public override void OnInvoke(MethodInterceptionArgs eventArgs)
        {
            string metricName = GetMetricName(
                            eventArgs.Method.DeclaringType,
                            eventArgs.Method.Name,
                            eventArgs.Method.IsGenericMethod,
                            eventArgs.Method.GetGenericArguments());

            var sensor = new TimingSensor(metricName) { FeatureName = _featureName, FeatureGroup = _featureGroup };
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            // continue with method invocation
            eventArgs.Proceed();

            stopwatch.Stop();

            sensor.Add(stopwatch.ElapsedMilliseconds);
        }