Exemplo n.º 1
0
        public object Invoke(IMethodInvocation invocation)
        {
            RecordAuditorClassAttribute auditorClassAttribute = GetRecordAuditorAttribute(invocation.TargetType);

            logger.Info("开始:  " + invocation.TargetType.Name + "." + invocation.Method.Name);


            DateTime operateTime = System.DateTime.Now;

            int operateUserID = SystemUserWrapper.GetCurrentOperateUserID();

            switch (invocation.Method.Name)
            {
            case "Save":
                SetCreateInfo(invocation.Arguments[0], operateTime, operateUserID, invocation.Method.Name);
                break;

            case "Update":
                SetUpdateInfo(invocation.Arguments[0], operateTime, operateUserID, invocation.Method.Name);
                break;

            case "SaveOrUpdate":
                break;
            }


            object result = invocation.Proceed();

            logger.Info("结束:  " + invocation.TargetType.Name + "." + invocation.Method.Name);

            return(result);
        }
Exemplo n.º 2
0
        public RecordAuditorClassAttribute GetRecordAuditorAttribute(Type type)
        {
            if (recordAuditors.ContainsKey(type))
            {
                return(recordAuditors[type]);
            }

            var attr = type.GetCustomAttributes(typeof(RecordAuditorClassAttribute), false).FirstOrDefault() as RecordAuditorClassAttribute;

            if (attr != null)
            {
                recordAuditors[type] = attr;
            }
            else
            {
                recordAuditors[type] = new RecordAuditorClassAttribute()
                {
                    EnableVersion = false
                };
            }


            return(recordAuditors[type]);
        }