예제 #1
0
        private void DefaultWriteLog(MethodInvokation call, object result, ILog log, Log4NetAttribute attr)
        {
            StringBuilder buf = new StringBuilder();

            buf.Append(call.Method.Name + "(");

            bool fFirstParam = true;

            foreach (InterceptedParameter param in call.Parameters)
            {
                if (fFirstParam)
                {
                    fFirstParam = false;
                }
                else
                {
                    buf.Append(", ");
                }

                buf.Append(param.Name + ":" + param.Value);
            }
            buf.Append(")");

            Log(log, attr.Level, buf.ToString());
        }
예제 #2
0
        public object HandleCall(MethodInvokation call)
        {
            call_it++;

            // Call intercepted function
            object result = call.Proceed();

            try
            {
                MethodInfo mInfo = call.Method as MethodInfo;
                foreach (Attribute attr in Attribute.GetCustomAttributes(mInfo))
                {
                    if (attr.GetType() == typeof(Log4NetAttribute))
                    {
                        WriteLog(call, result, attr as Log4NetAttribute);
                    }
                }
            }
            catch (Exception ex)
            {
                defaultLog.Error("Failure in Log4NetInterceptor", ex);
            }

            return(result);
        }
예제 #3
0
        private void WriteLog(MethodInvokation call, object result, Log4NetAttribute attr)
        {
            // Select logger
            ILog log = null;

            if (attr.LogPath != null)
            {
                log = LogManager.GetLogger(attr.LogPath, typeof(Log4NetInterceptor));
            }
            else
            {
                log = defaultLog;
            }

            // Write
            if (attr == null || attr.Format == null)
            {
                DefaultWriteLog(call, result, log, attr);
            }
            else
            {
                object[] arg = new object[call.Parameters.Count + 1];
                int      it;
                for (it = 0; it < call.Parameters.Count; it++)
                {
                    InterceptedParameter param = call.Parameters[it] as InterceptedParameter;
                    arg[it] = param.Value;
                }

                arg[it] = result;

                Log(log, attr.Level, String.Format(attr.Format, arg));
            }
        }
        public object HandleCall(MethodInvokation call)
        {
            call_it ++;

            // Call intercepted function
            object result = call.Proceed();

            try
            {
                MethodInfo mInfo = call.Method as MethodInfo;
                foreach (Attribute attr in Attribute.GetCustomAttributes(mInfo))
                {
                    if (attr.GetType() == typeof(Log4NetAttribute))
                    {
                        WriteLog(call, result, attr as Log4NetAttribute);
                    }
                }
            }
            catch(Exception ex)
            {
                defaultLog.Error("Failure in Log4NetInterceptor", ex);
            }

            return result;
        }
 /*
  get
     {
         System.String value = m_Name;
         object refValue = (object) value;
         bool cancel = false;
         MatsSoft.NPersist.Framework.IInterceptor interceptor = ((MatsSoft.NPersist.Framework.IInterceptable) this).GetInterceptor();
         if (interceptor != null) { interceptor.NotifyPropertyGet(this, "Name", ref refValue, ref cancel); }
         if (cancel) { return null; }
         value = (System.String) refValue;
         return value;
     }
 */
 private object HandleGetProperty(MethodInvokation call)
 {
     string propertyName = call.Method.Name.Substring(4);
     object value = call.Proceed();
     bool cancel = false;
     Puzzle.NPersist.Framework.Interfaces.IInterceptor interceptor = context.Interceptor;
     if (interceptor != null) {interceptor.NotifyPropertyGet(call.Target,propertyName,ref value,ref cancel) ;}
     if (cancel) {return GetDefaultValue(call.ReturnType);}
     return value;
 }
        public object HandleCall(MethodInvokation call)
        {
            if (call.Method.Name.StartsWith("get_") )
                return HandleGetProperty(call);

            if (call.Method.Name.StartsWith("set_") )
                return HandleSetProperty(call);

            throw new Exception ("Blame Roger for this bug!");
        }
 /*
     set
     {
         object refValue = (object) value;
         bool cancel = false;
         MatsSoft.NPersist.Framework.IInterceptor interceptor = ((MatsSoft.NPersist.Framework.IInterceptable) this).GetInterceptor();
         if (interceptor != null) { interceptor.NotifyPropertySet(this, "Name", ref refValue, ref cancel); }
         if (cancel) { return; }
         m_Name = (System.String) refValue;
     }
 */
 private object HandleSetProperty(MethodInvokation call)
 {
     bool cancel = false;
     object value = ((InterceptedParameter)call.Parameters[0]).Value;
     string propertyName = call.Method.Name.Substring(4);
     object refValue = value;
     Puzzle.NPersist.Framework.Interfaces.IInterceptor interceptor = context.Interceptor;
     if (interceptor != null) { interceptor.NotifyPropertySet(call.Target, propertyName, ref refValue, ref cancel); }
     if (cancel) { return null; }
     ((InterceptedParameter)call.Parameters[0]).Value = refValue;
     call.Proceed();
     return null;
 }
        public object HandleCall(MethodInvokation call)
        {
            if (call.Method.Name.StartsWith("get_"))
            {
                return(HandleGetProperty(call));
            }

            if (call.Method.Name.StartsWith("set_"))
            {
                return(HandleSetProperty(call));
            }

            throw new Exception("Blame Roger for this bug!");
        }
        /*
         * get
         * {
         * System.String value = m_Name;
         * object refValue = (object) value;
         * bool cancel = false;
         * MatsSoft.NPersist.Framework.IInterceptor interceptor = ((MatsSoft.NPersist.Framework.IInterceptable) this).GetInterceptor();
         * if (interceptor != null) { interceptor.NotifyPropertyGet(this, "Name", ref refValue, ref cancel); }
         * if (cancel) { return null; }
         * value = (System.String) refValue;
         * return value;
         * }
         */
        private object HandleGetProperty(MethodInvokation call)
        {
            string propertyName = call.Method.Name.Substring(4);
            object value        = call.Proceed();
            bool   cancel       = false;

            Puzzle.NPersist.Framework.Interfaces.IInterceptor interceptor = context.Interceptor;
            if (interceptor != null)
            {
                interceptor.NotifyPropertyGet(call.Target, propertyName, ref value, ref cancel);
            }
            if (cancel)
            {
                return(GetDefaultValue(call.ReturnType));
            }
            return(value);
        }
        private void DefaultWriteLog(MethodInvokation call, object result, ILog log, Log4NetAttribute attr)
        {
            StringBuilder buf = new StringBuilder();
            buf.Append(call.Method.Name + "(");

            bool fFirstParam = true;
            foreach (InterceptedParameter param in call.Parameters)
            {
                if(fFirstParam)
                    fFirstParam = false;
                else
                    buf.Append(", ");

                buf.Append(param.Name + ":" + param.Value);
            }
            buf.Append(")");

            Log(log, attr.Level, buf.ToString());
        }
        /*
         *      set
         *      {
         *              object refValue = (object) value;
         *              bool cancel = false;
         *              MatsSoft.NPersist.Framework.IInterceptor interceptor = ((MatsSoft.NPersist.Framework.IInterceptable) this).GetInterceptor();
         *              if (interceptor != null) { interceptor.NotifyPropertySet(this, "Name", ref refValue, ref cancel); }
         *              if (cancel) { return; }
         *              m_Name = (System.String) refValue;
         *      }
         */
        private object HandleSetProperty(MethodInvokation call)
        {
            bool   cancel       = false;
            object value        = ((InterceptedParameter)call.Parameters[0]).Value;
            string propertyName = call.Method.Name.Substring(4);
            object refValue     = value;

            Puzzle.NPersist.Framework.Interfaces.IInterceptor interceptor = context.Interceptor;
            if (interceptor != null)
            {
                interceptor.NotifyPropertySet(call.Target, propertyName, ref refValue, ref cancel);
            }
            if (cancel)
            {
                return(null);
            }
            ((InterceptedParameter)call.Parameters[0]).Value = refValue;
            call.Proceed();
            return(null);
        }
        public object HandleCall(MethodInvokation call)
        {
            if (context.Interceptor == null)
            {
                call.Proceed();
                return null;
            }
            else
            {
                bool cancel = false;
                context.Interceptor.NotifyInstantiatingObject(call.Target,ref cancel) ;

                if (!cancel)
                    call.Proceed() ;

                context.Interceptor.NotifyInstantiatedObject(call.Target) ;

                return null;
            }
        }
예제 #13
0
        public object HandleCall(MethodInvokation call)
        {
            if (context.Interceptor == null)
            {
                call.Proceed();
                return(null);
            }
            else
            {
                bool cancel = false;
                context.Interceptor.NotifyInstantiatingObject(call.Target, ref cancel);

                if (!cancel)
                {
                    call.Proceed();
                }

                context.Interceptor.NotifyInstantiatedObject(call.Target);

                return(null);
            }
        }
        private void WriteLog(MethodInvokation call, object result, Log4NetAttribute attr)
        {
            // Select logger
            ILog log = null;
            if(attr.LogPath != null)
            {
                log = LogManager.GetLogger(attr.LogPath, typeof(Log4NetInterceptor));
            }
            else
            {
                log = defaultLog;
            }

            // Write
            if(attr == null || attr.Format == null)
            {
                DefaultWriteLog(call, result, log, attr);
            }
            else
            {
                object[] arg = new object[call.Parameters.Count + 1];
                int it;
                for(it = 0; it < call.Parameters.Count; it ++)
                {
                    InterceptedParameter param = call.Parameters[it] as InterceptedParameter;
                    arg[it] = param.Value;
                }

                arg[it] = result;

                Log(log, attr.Level, String.Format(attr.Format, arg));
            }
        }