Esempio n. 1
0
        /// <summary>
        /// Shoulds the intercept.
        /// </summary>
        /// <param name="invocation">The invocation.</param>
        /// <param name="auditLog">The audit log.</param>
        /// <param name="auditLogAction">The audit log action.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        protected virtual bool ShouldIntercept(
            IMethodInvocation invocation,
            out AuditLogInfo auditLog,
            out AuditLogActionInfo auditLogAction)
        {
            auditLog       = null;
            auditLogAction = null;

            if (CrossCuttingConcerns.IsApplied(invocation.TargetObject, CrossCuttingConcerns.Auditing))
            {
                return(false);
            }
            // 如果没有获取到 Scop,则返回 false。
            var auditLogScope = _auditingManager.Current;

            if (auditLogScope == null)
            {
                return(false);
            }
            // 进行二次判断是否需要存储审计日志。
            if (!_auditingHelper.ShouldSaveAudit(invocation.Method))
            {
                return(false);
            }
            // 构建审计日志信息。
            auditLog       = auditLogScope.Log;
            auditLogAction = _auditingHelper.CreateAuditLogAction(
                auditLog,
                invocation.TargetObject.GetType(),
                invocation.Method,
                invocation.Arguments
                );

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the audit log action.
        /// </summary>
        /// <param name="auditLog">The audit log.</param>
        /// <param name="type">The type.</param>
        /// <param name="method">The method.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>AuditLogActionInfo.</returns>
        public virtual AuditLogActionInfo CreateAuditLogAction(
            AuditLogInfo auditLog,
            Type type,
            MethodInfo method,
            IDictionary <string, object> arguments)
        {
            var actionInfo = new AuditLogActionInfo
            {
                ServiceName = type != null
                    ? type.FullName
                    : "",
                MethodName = method.Name,
                // 序列化参数信息。
                Parameters    = SerializeConvertArguments(arguments),
                ExecutionTime = DateTime.Now
            };

            //TODO Execute contributors

            return(actionInfo);
        }