示例#1
0
        /// <summary>
        ///    Method invoked when (instead of) a new handler is added to the target event.
        /// </summary>
        /// <param name="args">Context information.</param>
        public override void OnAddHandler(EventInterceptionArgs args)
        {
            var  weakEventClient       = args.Handler.Target as IWeakEventClient;
            bool supportsWeakReference = weakEventClient != null;

            // Throw an exception if the client does not support weak events and we are not allowed to hold strong references.
            if (!supportsWeakReference && args.Handler.Target != null && !AllowStrongReferences)
            {
                throw new InvalidOperationException(
                          $"Attempt to add a reference to the weak event {args.Event} from type {args.Handler.Target.GetType()}, which does not implement the IWeakEventClient interface.");
            }

            // Add the handler to our own list.
            if (_weakEventHandler.AddHandler(args.Handler, supportsWeakReference))
            {
                // If it is the first handler we are adding, add a fake handler to ourselves to the target event.
                // Whichever handler will add here will be passed to OnInvokeHandler, so it is safe and convenient to pass null.
                args.AddHandler(null);
            }

            // Register the handler to the client to prevent garbage collection of the handler.
            if (supportsWeakReference)
            {
                weakEventClient.RegisterEventHandler(args.Handler);
            }
        }
        /// <summary>
        /// Method invoked <i>instead</i> of the <c>Remove</c> semantic of the event to which the current aspect is applied,
        /// i.e. when a delegate is removed from this event.
        /// </summary>
        /// <param name="args">Handler arguments.</param>
        public override void OnRemoveHandler(EventInterceptionArgs args)
        {
            Console.WriteLine(string.Format("Event {0} removed.", args.Event.Name));

            //If ProceedRemoveHandler is not called the handler that
            //was supposed to be removed will never get removed.
            args.ProceedRemoveHandler();
        }
 public override void OnRemoveHandler(EventInterceptionArgs args)
 {
     StringBuilder sb = new StringBuilder();
     sb.AppendFormat("Event {0} was removed from\n", args.Event.Name);
     sb.AppendFormat("\tclass: {0} \n", args.Handler.Target.GetType().FullName);
     sb.AppendFormat("\tassembly: {0}", args.Handler.Target.GetType().Module);
     Console.WriteLine(sb);
     base.OnRemoveHandler(args);
 }
    public override void OnInvokeHandler(EventInterceptionArgs args)
    {
        int x = 0;

        if (x > 0)         //Do you logic here
        {
            args.ProceedInvokeHandler();
        }
    }
 public override void OnAddHandler(EventInterceptionArgs args)
 {
     lock (_lockObject)
     {
         if (!_delegates.Contains(args.Handler))
         {
             _delegates.Add(args.Handler);
             args.ProceedAddHandler();
         }
     }
 }
 public override void OnRemoveHandler(EventInterceptionArgs args)
 {
     lock (_lockObject)
     {
         if (_delegates.Contains(args.Handler))
         {
             _delegates.Remove(args.Handler);
             args.ProceedRemoveHandler();
         }
     }
 }
        /// <summary>
        ///   Method invoked when (instead of) a new handler is removed from the target event.
        /// </summary>
        /// <param name="args">Context information.</param>
        public override void OnRemoveHandler(EventInterceptionArgs args)
        {
            // Remove the handler from our own list.
            if (RemoveHandler(args.Handler))
            {
                args.RemoveHandler(null);
            }

            // Remove the handler from the client.
            DelegateReferenceKeeper.RemoveReference(args.Handler);
        }
        /// <summary>
        ///     Method invoked when (instead of) a new handler is removed from the target event.
        /// </summary>
        /// <param name="args">Context information.</param>
        public override void OnRemoveHandler(EventInterceptionArgs args)
        {
            // Remove the handler from our own list.
            if (RemoveHandler(args.Handler))
            {
                // If this is the last handler, remove the fake handler to ourselves from the target event.
                args.RemoveHandler(null);
            }

            // Remove the handler from the client.
            DelegateReferenceKeeper.RemoveReference(args.Handler);
        }
示例#9
0
 private static void Invoke(EventInterceptionArgs args)
 {
     try
     {
         args.ProceedInvokeHandler();
     }
     catch (Exception e)
     {
         Trace.TraceError(e.ToString());
         args.ProceedRemoveHandler();
     }
 }
        /// <summary>
        ///   Method invoked when (instead of) a new handler is added to the target event.
        /// </summary>
        /// <param name="args">Context information.</param>
        public override void OnAddHandler(EventInterceptionArgs args)
        {
            // Add the handler to our own list.
            if (AddHandler(args.Handler))
            {
                args.AddHandler(null);
            }


            // Register the handler to the client to prevent garbage collection of the handler.
            DelegateReferenceKeeper.AddReference(args.Handler);
        }
示例#11
0
 public override void OnInvokeHandler(EventInterceptionArgs args)
 {
     ThreadPool.QueueUserWorkItem(state =>
     {
         try
         {
             args.ProceedInvokeHandler();
         }
         catch
         {
             args.ProceedRemoveHandler();
         }
     });
 }
        /// <summary>
        ///     Method invoked when (instead of) a new handler is added to the target event.
        /// </summary>
        /// <param name="args">Context information.</param>
        public override void OnAddHandler(EventInterceptionArgs args)
        {
            // Add the handler to our own list.
            if (AddHandler(args.Handler))
            {
                // If it is the first handler we are adding, add a fake handler to ourselves to the target event.
                // Whichever handler will add here will be passed to OnInvokeHandler, so it is safe and convenient to pass null.
                args.AddHandler(null);
            }


            // Register the handler to the client to prevent garbage collection of the handler.
            DelegateReferenceKeeper.AddReference(args.Handler);
        }
 public override void OnInvokeHandler( EventInterceptionArgs args )
 {
     ThreadPool.QueueUserWorkItem( state =>
                                       {
                                           try
                                           {
                                               args.ProceedInvokeHandler();
                                           }
                                           catch
                                           {
                                               args.ProceedRemoveHandler();
                                           }
                                       } );
 }
示例#14
0
        public override void OnInvokeHandler(EventInterceptionArgs args)
        {
            DispatcherObject dispatcherObject = args.Handler.Target as DispatcherObject;

            if (dispatcherObject == null || dispatcherObject.CheckAccess())
            {
                args.ProceedInvokeHandler();
            }
            else
            {
                // We have to dispatch synchronously to avoid the object to be changed
                // before the time the event is raised and the time it is processed.
                dispatcherObject.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(args.ProceedInvokeHandler));
            }
        }
        public override void OnInvokeHandler( EventInterceptionArgs args )
        {
            DispatcherObject dispatcherObject = args.Handler.Target as DispatcherObject;

            if ( dispatcherObject == null || dispatcherObject.CheckAccess() )
            {
                args.ProceedInvokeHandler();
            }
            else
            {
                // We have to dispatch synchronously to avoid the object to be changed
                // before the time the event is raised and the time it is processed.
                dispatcherObject.Dispatcher.Invoke( DispatcherPriority.Normal, new Action( args.ProceedInvokeHandler ) );
            }
        }
        public void OnInvoke(EventInterceptionArgs args)
        {
            ReaderWriterLockSlim @lock = ((IReaderWriterSynchronized)args.Instance).Lock;

            bool reEnterWriteLock = @lock.IsWriteLockHeld;

            this.Enter(@lock);

            try
            {
                args.ProceedInvokeHandler();
            }
            finally
            {
                this.Exit(reEnterWriteLock, @lock);
            }
        }
示例#17
0
        /// <summary>
        ///    Method invoked when (instead of) a new handler is removed from the target event.
        /// </summary>
        /// <param name="args">Context information.</param>
        public override void OnRemoveHandler(EventInterceptionArgs args)
        {
            var weakEventClient = args.Handler.Target as IWeakEventClient;

            bool supportsWeakReference = weakEventClient != null;

            // Remove the handler from our own list.
            if (_weakEventHandler.RemoveHandler(args.Handler))
            {
                // If this is the last handler, remove the fake handler to ourselves from the target event.
                args.RemoveHandler(null);
            }

            // Remove the handler from the client.
            if (supportsWeakReference)
            {
                weakEventClient.UnregisterEventHandler(args.Handler);
            }
        }
示例#18
0
        /// <summary>
        /// Method invoked when the event to which the current aspect is applied is fired, <i>for each</i> delegate
        /// of this event, and <i>instead of</i> invoking this delegate.
        /// </summary>
        /// <param name="args">Handler arguments.</param>
        /// <exception cref="System.ArgumentException">
        /// 必须为IdentityObject或其子类
        /// or
        /// EventName事件上找不到EventDescriptionAttribute
        /// </exception>
        public override void OnInvokeHandler(EventInterceptionArgs args)
        {
            base.OnInvokeHandler(args);

            var i = args.Instance as IdentityObject;

            if (i == null)
            {
                throw new ArgumentException("必须为IdentityObject或其子类");
            }

            var d = args.Event.GetCustomAttribute(typeof(DescriptionAttribute), true) as DescriptionAttribute;

            if (d == null)
            {
                throw new ArgumentException("EventName事件上找不到DescriptionAttribute");
            }

            i.Info("引发" + d.Description);
        }
示例#19
0
        internal static void SaveEventInfo(EventInterceptionArgs args, LoggingType loggingType)
        {
            try
            {
                LogItem item = LogSessionManager.Instance.CurrentSession.GetNewLogItem();
                item.HashCode = -1;


                if (args.Instance != null)
                {
                    bool firstTime;
                    item.ObjectId = ObjIDGenerator.Instance.GetId(args.Instance, out firstTime);
                }
                item.ThreadId  = System.Threading.Thread.CurrentThread.ManagedThreadId;
                item.ProcessId = System.Diagnostics.Process.GetCurrentProcess().Id;
                item.Name      = args.Event.Name;
                Debug.Assert(args.Event.DeclaringType != null, "args.Event.DeclaringType != null");
                item.ClassName   = args.Event.DeclaringType.Name;
                item.Namespace   = args.Event.DeclaringType.Namespace;
                item.LoggingType = loggingType;

                try
                {
                    var stackFrame = new StackFrame(3);
                    item.ParentMethod    = stackFrame.GetMethod().Name;
                    item.ParentClass     = stackFrame.GetMethod().DeclaringType.Name;
                    item.ParentNamespace = stackFrame.GetMethod().DeclaringType.Namespace;
                }
                catch
                {
                }

                Database.Instance.Add(item);
            }
            catch (Exception ex)
            {
                SimpleLogger.Logger.Log("SaveCallInfo", ex);
                throw;
            }
        }
示例#20
0
 public override void OnInvokeHandler(EventInterceptionArgs args)
 {
     Console.WriteLine("Event {0} invoked", args.Event.Name);
     args.ProceedInvokeHandler();
 }
        /// <summary>
        ///   Method invoked when (instead of) a the target event is raised.
        /// </summary>
        /// <param name="args">Context information.</param>
        public override void OnInvokeHandler(EventInterceptionArgs args)
        {
            // Note that args.Handler == null because it's the value we added in OnAddHandler, but it really does not matter.

            InvokeHandler(args.Arguments.ToArray());
        }
示例#22
0
 public override void OnAddHandler(EventInterceptionArgs args)
 {
     Console.WriteLine("Event eklendi");
     args.ProceedAddHandler();
 }
示例#23
0
 public override void OnRemoveHandler(EventInterceptionArgs args)
 {
     Console.WriteLine("Event kaldırıldı");
     args.ProceedRemoveHandler();
 }
示例#24
0
 public override void OnInvokeHandler(EventInterceptionArgs args) // Вызываем событие асинхронно
 {
     Task.Factory.StartNew(() => Invoke(args)).Start();
 }
示例#25
0
 public override void OnInvokeHandler(EventInterceptionArgs args)
 {
     Console.WriteLine("Event Invoke Edildi");
     args.ProceedInvokeHandler();
 }
示例#26
0
 public override void OnInvokeHandler(EventInterceptionArgs args)
 {
     LogHelper.SaveEventInfo(args, LogHelper.LoggingType.EventRaised);
     base.OnInvokeHandler(args);
 }
        public void OnInvoke( EventInterceptionArgs args )
        {
            ReaderWriterLockSlim @lock = ((IReaderWriterSynchronized)args.Instance).Lock;

            bool reEnterWriteLock = @lock.IsWriteLockHeld;

            this.Enter( @lock );

            try
            {
                args.ProceedInvokeHandler();
            }
            finally
            {
                this.Exit( reEnterWriteLock, @lock );
            }
        }
示例#28
0
 public override void OnAddHandler(EventInterceptionArgs args)
 {
     Console.WriteLine("Event {0} added", args.Event.Name);
     args.ProceedAddHandler();
 }