public override void OnEntry(MethodExecutionEventArgs eventArgs)
 {
     //ignore call from reflection
     if (eventArgs.GetReadOnlyArgumentArray() != null)
     {
         //check for null
         if (eventArgs.GetReadOnlyArgumentArray()[0] == null)
             throw new ValidationException("Value was null.", eventArgs);
     }
     base.OnEntry(eventArgs);
 }
        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            if (eventArgs.GetReadOnlyArgumentArray() != null)
            {
                string value = (string)eventArgs.GetReadOnlyArgumentArray()[0];

                if (Regex.IsMatch(value, RegularExpression) != this.MustMatch)
                    throw new ValidationException("Value did not match the specified regular expression [" + RegularExpression + "]", eventArgs);
            }

            base.OnEntry(eventArgs);
        }
        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            if (eventArgs.Instance == null)
                throw new InvalidOperationException("Cannot decorate UpdateForm on static classes");

            if (!(eventArgs.Instance is Form))
                throw new InvalidOperationException("UpdateForm requires a Form to operate");

            object sender = eventArgs.GetReadOnlyArgumentArray()[0];
            ElementEventArgs ea = (ElementEventArgs)eventArgs.GetReadOnlyArgumentArray()[1];

            Form frm = (Form)eventArgs.Instance;
            frm.Text = ea.Element + " -said by " + sender;
        }
        public override void OnSuccess(MethodExecutionEventArgs eventArgs)
        {
            MethodBase fctName = eventArgs.Method;
            Dictionary<int, bool> fctCache = cache[fctName];
            int param = (int)eventArgs.GetReadOnlyArgumentArray()[0];
            bool retVal = (bool)eventArgs.ReturnValue;

            fctCache.Add(param, retVal);
        }
        //event bubbling
        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            PropertyInfo pi = eventArgs.Instance.GetType().GetProperty(propertyName,
                                                                       BindingFlags.Public | BindingFlags.NonPublic |
                                                                       BindingFlags.Instance);

            oldValue = pi.GetValue(eventArgs.Instance, null);
            newValue = eventArgs.GetReadOnlyArgumentArray()[0]; // will work only for simple properties!

            base.OnEntry(eventArgs);
        }
 public override void OnEntry(MethodExecutionEventArgs eventArgs)
 {
     var arguments = eventArgs.GetReadOnlyArgumentArray();
     for (var i = 0; i < arguments.Length; ++i)
     {
         var argumentValue = arguments[i];
         var parameterRules = _parameterRules[i];
         
         foreach (var rule in parameterRules.RulesToApply)
         {
             rule.ValidateParameter(parameterRules.Parameter, argumentValue);
         }
     }
 }
        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            var arguments = eventArgs.GetReadOnlyArgumentArray();

            for (var i = 0; i < arguments.Length; ++i)
            {
                var argumentValue  = arguments[i];
                var parameterRules = _parameterRules[i];

                foreach (var rule in parameterRules.RulesToApply)
                {
                    rule.ValidateParameter(parameterRules.Parameter, argumentValue);
                }
            }
        }
    public override void OnException(MethodExecutionEventArgs eventArgs)
    {
        Console.WriteLine(eventArgs.Method.DeclaringType.Name);
        Console.WriteLine(eventArgs.Method.Name);
        Console.WriteLine(eventArgs.Exception.StackTrace);

        ParameterInfo[] parameterInfos = eventArgs.Method.GetParameters();
        object[]        paramValues    = eventArgs.GetReadOnlyArgumentArray();

        for (int i = 0; i < parameterInfos.Length; i++)
        {
            Console.WriteLine(parameterInfos[i].Name + "=" + paramValues[i]);
        }

        eventArgs.FlowBehavior = FlowBehavior.Default;
    }
Example #9
0
        /// <summary>
        /// Method executed <b>after</b> the body of methods
        /// to which this aspect is applied, when the method ends with an exception.
        /// </summary>
        /// <param name="eventArgs">Event arguments specifying which method
        /// is being executed and which are its arguments.</param>
        public override void OnException(MethodExecutionEventArgs eventArgs)
        {
#if !MONO
            //Trace.Unindent();
#endif

            Trace.TraceWarning(
                this.prefix + "Leaving " +
                this.formatStrings.Format(
                    eventArgs.Instance,
                    eventArgs.Method,
                    eventArgs.GetReadOnlyArgumentArray()
                    ) +
                Formatter.FormatString(" with exception {0} : {{{1}}}.", eventArgs.Exception.GetType().Name,
                                       eventArgs.Exception.Message));
        }
        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            // create fct dict if not exists
            if (!cache.ContainsKey(eventArgs.Method))
                cache.Add(eventArgs.Method, new Dictionary<int, bool>());

            // get fct-dict and fct-parameter
            Dictionary<int, bool> fctCache = cache[eventArgs.Method];
            int param = (int)eventArgs.GetReadOnlyArgumentArray()[0];

            // lookup calculated result
            if (fctCache.ContainsKey(param))
            {
                eventArgs.ReturnValue = fctCache[param];
                eventArgs.FlowBehavior = FlowBehavior.Return;
            }
        }
Example #11
0
        /// <summary>
        /// Method executed <b>after</b> the body of methods
        /// to which this aspect is applied, when the method succeeds.
        /// </summary>
        /// <param name="eventArgs">Event arguments specifying which method
        /// is being executed and which are its arguments.</param>
        public override void OnSuccess(MethodExecutionEventArgs eventArgs)
        {
            //if (this.prefix.Length > 0)
            //    this.prefix = this.prefix.Substring(0, this.prefix.Length - 1);
            //Trace.Write("< " + this.prefix + eventArgs.Instance + " - " + eventArgs.Method);

            //Trace.Write("< " + this.prefix + eventArgs.Method.DeclaringType.FullName + " - " + eventArgs.Method);
            //return;            //Trace.TraceInformation(

            Trace.Write(
                this.prefix + "< Leaving " +
                this.formatStrings.Format(
                    eventArgs.Instance,
                    eventArgs.Method,
                    eventArgs.GetReadOnlyArgumentArray()) +
                (this.isVoid ? "" : Formatter.FormatString(" : {{{0}}}.", eventArgs.ReturnValue)));
        }
Example #12
0
        /// <summary>
        /// Method executed <b>before</b> the body of methods to which this aspect is applied.
        /// We just trace and increment indentation.
        /// </summary>
        /// <param name="context">Event arguments specifying which method
        /// is being executed and which are its arguments.</param>
        public override void OnEntry(MethodExecutionEventArgs context)
        {
            //this.prefix_ += ".";
            //Trace.Write(">>>> " + this.prefix + context.Method.DeclaringType.FullName + " - " + context.Method);

            //return;


            //Trace.TraceInformation(
            Trace.Write(
                this.prefix + "> Entering " +
                this.formatStrings.Format(
                    context.Instance,
                    context.Method,
                    context.GetReadOnlyArgumentArray()));

            //Patches.applyPatch(context.GetReadOnlyArgumentArray(), context);
        }
        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            ILog logger = LogManager.GetLogger(eventArgs.Method.DeclaringType);
            if (ShouldLog(logger, EntryLevel, eventArgs)) {
                var logMessage = new StringBuilder();
                logMessage.Append(string.Format("{0}(", eventArgs.Method.Name));

                object[] argumentValues = eventArgs.GetReadOnlyArgumentArray();
                ParameterInfo[] parameterInfos = eventArgs.Method.GetParameters();
                if (argumentValues != null && parameterInfos != null) {
                    for (int i = 0; i < argumentValues.Length; i++) {
                        if (i > 0) {
                            logMessage.Append(" ");
                        }
                        logMessage.Append(string.Format("{0}:[{1}]", parameterInfos[i].Name, argumentValues[i]));
                    }
                }
                logMessage.Append(")");
                logger.Log(EntryLevel, logMessage.ToString());
            }
        }
Example #14
0
        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            base.OnEntry(eventArgs);

            var logMessage = new StringBuilder()
                .Append("Begin ")
                .Append(eventArgs.Method.Name)
                .Append("(");

            var arguments = eventArgs.GetReadOnlyArgumentArray();
            for (var i = 0; i < arguments.Length; i++)
            {
                logMessage.Append(eventArgs.Method.GetParameters()[i].Name);
                logMessage.Append(" = ");
                logMessage.Append(arguments[i]);
                if (i < arguments.Length - 1)
                {
                    logMessage.Append(", ");
                }
            }
            logMessage.Append(")");
            Trace.WriteLine(logMessage);
            Trace.Indent();
        }
        //event bubbling
        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            PropertyInfo pi = eventArgs.Instance.GetType().GetProperty(propertyName,
                                                                       BindingFlags.Public | BindingFlags.NonPublic |
                                                                       BindingFlags.Instance);

            oldValue = pi.GetValue(eventArgs.Instance, null);
            newValue = eventArgs.GetReadOnlyArgumentArray()[0]; // will work only for simple properties!

            base.OnEntry(eventArgs);
        }
        /// <summary>
        /// Method executed <b>before</b> the body of methods to which this aspect is applied.
        /// We just trace and increment indentation.
        /// </summary>
        /// <param name="context">Event arguments specifying which method
        /// is being executed and which are its arguments.</param>
        public override void OnEntry( MethodExecutionEventArgs context )
        {            
            //this.prefix_ += ".";
            //Trace.Write(">>>> " + this.prefix + context.Method.DeclaringType.FullName + " - " + context.Method);

            //return;


            //Trace.TraceInformation(
            Trace.Write(
                this.prefix + "> Entering " +
                this.formatStrings.Format(
                    context.Instance,
                    context.Method,
                    context.GetReadOnlyArgumentArray()));

            //Patches.applyPatch(context.GetReadOnlyArgumentArray(), context);

        }
Example #17
0
        public override void OnSuccess(MethodExecutionEventArgs args)
        {
            int    requestsysno            = 0;
            string ptptdUser               = ConfigurationManager.AppSettings["PTPTDUser"];
            string subject                 = string.Empty;
            ProductPriceRequestInfo entity = new ProductPriceRequestInfo();

            if (EmailType == SendEmailType.ApprovePriceRequest)
            {
                object[] objs = args.GetReadOnlyArgumentArray();
                entity = objs[0] as ProductPriceRequestInfo;

                requestsysno = entity.SysNo.Value;

                if (entity.RequestStatus == ProductPriceRequestStatus.Deny)//拒绝时的邮件发送
                {
                    subject = ResouceManager.GetMessageString("IM.Product", "AuditRejected");
                }
                else
                {
                    subject = ResouceManager.GetMessageString("IM.Product", "AuditPassed");
                }
            }
            else if (EmailType == SendEmailType.CancelPriceRequest)//撤销时的邮件发送
            {
                object[] objs = args.GetReadOnlyArgumentArray();
                entity = objs[0] as ProductPriceRequestInfo;

                requestsysno = entity.SysNo.Value;

                subject = ResouceManager.GetMessageString("IM.Product", "CancelAudit");
            }
            else if (EmailType == SendEmailType.CreatePriceRequest)
            {
                object[] objs = args.GetReadOnlyArgumentArray();
                entity = objs[1] as ProductPriceRequestInfo;

                requestsysno = entity.SysNo.Value;

                subject = ResouceManager.GetMessageString("IM.Product", "RequestAudit");
            }



            ProductPriceRequestInfo requestentity = ObjectFactory <ProductPriceRequestProcessor> .Instance.GetProductPriceRequestInfoBySysNo(requestsysno);


            string toAddress = string.Format("{0};{1}", entity.PMUserEmailAddress, entity.CurrentUserEmailAddress);

            if (!string.IsNullOrEmpty(entity.BackupPMUserEmailAddress))
            {
                toAddress = string.Format("{0};{1}", toAddress, entity.BackupPMUserEmailAddress);
            }
            if (!string.IsNullOrEmpty(ptptdUser))
            {
                toAddress = string.Format("{0};{1}", toAddress, ptptdUser);
            }

            string ccmail     = GetCCEmail(requestentity);
            string updatetime = string.Empty;

            if (requestentity.LastUpdateTime.HasValue)
            {
                updatetime = requestentity.LastUpdateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            }

            //参数设置
            KeyValueVariables keyValueVariables = new KeyValueVariables();

            keyValueVariables.AddKeyValue("Subject", subject);
            keyValueVariables.Add("ProductSysNo", Product.SysNo);
            keyValueVariables.Add("ProductName", Product.ProductName);
            keyValueVariables.Add("UpdateTime", updatetime);
            keyValueVariables.Add("SysNo", requestentity.SysNo);
            keyValueVariables.Add("ProductID", Product.ProductID);
            keyValueVariables.Add("BasicPrice", requestentity.OldPrice.BasicPrice);
            keyValueVariables.Add("BasicPriceNew", requestentity.BasicPrice);
            keyValueVariables.Add("UnitCost", requestentity.UnitCost);
            keyValueVariables.Add("CurrentPrice", requestentity.OldPrice.CurrentPrice);
            keyValueVariables.Add("CurrentPriceNew", requestentity.CurrentPrice);
            keyValueVariables.Add("Discount", requestentity.DiscountAmount);
            keyValueVariables.Add("CashRebate", requestentity.OldPrice.CashRebate);
            keyValueVariables.Add("CashRebateNew", requestentity.CashRebate);
            keyValueVariables.Add("Point", requestentity.OldPrice.Point);
            keyValueVariables.Add("PointNew", requestentity.Point);
            keyValueVariables.Add("ProductPayType", requestentity.OldPrice.PayType.ToString());
            keyValueVariables.Add("MaxPerOrder", requestentity.MinCountPerOrder);
            keyValueVariables.Add("MinMargin", requestentity.OldPrice.Margin);
            keyValueVariables.Add("MinMarginCurrent", requestentity.Margin);
            keyValueVariables.Add("Apply", requestentity.CreateUser.UserName);
            keyValueVariables.Add("PMMemo", requestentity.PMMemo);
            keyValueVariables.Add("TLMemo", requestentity.TLMemo);


            EmailHelper.SendEmailByTemplate(toAddress, ccmail, "", "IM_Product_ChangePrice", keyValueVariables, null, true, true);
            base.OnSuccess(args);
        }
        protected virtual string FormatEntry(MethodExecutionEventArgs eventArgs)
        {
            if (!m_IncludeArguments)
            {
                return MethodName;
            }

            object[] arguments = eventArgs.GetReadOnlyArgumentArray();

            if (arguments == null)
            {
                return MethodName;
            }

            string args = FormatArguments(arguments);
            return String.Concat(MethodName, args);
        }
        /// <summary>
        /// Method executed <b>after</b> the body of methods 
        /// to which this aspect is applied, when the method succeeds.
        /// </summary>
        /// <param name="eventArgs">Event arguments specifying which method
        /// is being executed and which are its arguments.</param>
        public override void OnSuccess( MethodExecutionEventArgs eventArgs )
        {
            //if (this.prefix.Length > 0)
            //    this.prefix = this.prefix.Substring(0, this.prefix.Length - 1);
            //Trace.Write("< " + this.prefix + eventArgs.Instance + " - " + eventArgs.Method);
            
            //Trace.Write("< " + this.prefix + eventArgs.Method.DeclaringType.FullName + " - " + eventArgs.Method);
            //return;            //Trace.TraceInformation(

            Trace.Write(
                this.prefix + "< Leaving " +
                this.formatStrings.Format(
                    eventArgs.Instance,
                    eventArgs.Method,
                    eventArgs.GetReadOnlyArgumentArray()) +
                ( this.isVoid ? "" : Formatter.FormatString( " : {{{0}}}.", eventArgs.ReturnValue ) ) );
        }
 public override void OnEntry(MethodExecutionEventArgs eventArgs)
 {
     MethodLogger.LogEntry(eventArgs.Method, eventArgs.GetReadOnlyArgumentArray(), EntryLevel);
 }
Example #21
0
 public override void OnEntry(MethodExecutionEventArgs eventArgs)
 {
     ILog log = LogManager.GetLogger(eventArgs.Method.DeclaringType.FullName);
     log.Debug("Invoking " + eventArgs.Method.Name + " " +
         GetParameterString(eventArgs.GetReadOnlyArgumentArray()));
 }
Example #22
0
         /// <summary>Invoked at runtime when the setter is entered.</summary>
         public override void OnEntry(MethodExecutionEventArgs eventArgs) {
            // in compile-time mode, proceed to default setter flow 
            if (BplLanguage.RuntimeMode == BplRuntimeMode.Compiling) {
               eventArgs.FlowBehavior = FlowBehavior.Continue;
               return;
            }

            // get the source object
            var source = eventArgs.Instance as BplObject;
            if (source == null) {
               BplRuntimeException.Throw("Property value is not a valid BPL object.");
            }

            // get the property info
            if (_propertyInfo == null) {
               _propertyInfo = source.Class.GetProperty(_propertyName);
               if (_propertyInfo == null) {
                  BplRuntimeException.Throw("Unknown '" + _propertyName + "' property name.");
               }
            }

            // collection properties can only be updated during initialization
            if (_propertyInfo.IsCollection) {
               if (source.IsInitialized) {
                  BplRuntimeException.Throw("Collection property {1} in {0} cannot be overwritten.");
               }
               return;
            }

            // in batch mode, and property is a scalar, so proceed to default setter flow
            if (BplLanguage.RuntimeMode == BplRuntimeMode.Batch && !_propertyInfo.IsReference) {
               eventArgs.FlowBehavior = FlowBehavior.Continue;
               return;
            }

            // get the old property value from the local storage of the transaction in scope, if there is one. otherwise, get it directly from the source object.
            var oldValue = _propertyInfo.GetValue(source);

            // get the new property value from the setter event object.
            var newValue = eventArgs.GetReadOnlyArgumentArray()[0];

            // check whether the property value has actually changed, and if not abort the setter 
            if (Object.Equals(oldValue, newValue)) {
               eventArgs.FlowBehavior = FlowBehavior.Return;
               return;
            }

            // in batch mode, and property is a reference, so repair the reference and then proceed to default setter flow
            if (BplLanguage.RuntimeMode == BplRuntimeMode.Batch) {
               var oldReference = oldValue as BplContextNode;
               if (oldReference != null) {
                  oldReference.DetachFrom(source, _propertyInfo);
               }
               var newReference = newValue as BplContextNode;
               if (newReference != null) {
                  newReference.AttachTo(source, _propertyInfo);
               }
               eventArgs.FlowBehavior = FlowBehavior.Continue;
               return;
            }

            // create the property change object from the old and new property values
            var change = new BplPropertyChange(source, _propertyInfo, oldValue, newValue);

            // in interactive mode, so confirm the change and proceed to the post-setter flow
            if (BplLanguage.RuntimeMode == BplRuntimeMode.Interactive) {
               if (!change.ConfirmChange()) {
                  eventArgs.FlowBehavior = FlowBehavior.Return;
               } else {
                  eventArgs.MethodExecutionTag = change;
               }
               return;
            }

            // in transaction mode, so get and validate the transaction in scope on the current thread. 
            var transaction = BplTransaction.GetEnclosing(source);
            var transactionPhase = (transaction == null ? BplTransactionPhase.None : transaction.Phase);
            var needsTransaction = (BplContext.GetOwner(source) as BplTransactionalContext) != null;
            var hasTransaction = (transactionPhase != BplTransactionPhase.None);
            if (needsTransaction ^ hasTransaction) {
               BplRuntimeException.Throw("{0} update is not allowed by the containing context.".Substitute(needsTransaction ? "Non-transactional" : "Transactional"));
            }

            // process the change depending on the transaction phase
            switch (transactionPhase) {

               case BplTransactionPhase.Record:
                  // if transaction is in record phase, store the change in the transaction and cancel the change on the source object
                  if (change.ConfirmChange()) {
                     transaction.SetLocalValue(change);
                  }
                  eventArgs.FlowBehavior = FlowBehavior.Return;
                  break;
               
               case BplTransactionPhase.Commit:
                  // if transaction is in commit phase, apply the change to the source object (events will not be raised)
                  eventArgs.MethodExecutionTag = change;
                  break;

               default:
                  BplRuntimeException.Throw("Inconsistent transaction state.");
                  break;
            }

         }
        /// <summary>
        /// Method executed <b>after</b> the body of methods 
        /// to which this aspect is applied, when the method ends with an exception.
        /// </summary>
        /// <param name="eventArgs">Event arguments specifying which method
        /// is being executed and which are its arguments.</param>
        public override void OnException( MethodExecutionEventArgs eventArgs )
        {
#if !MONO
            //Trace.Unindent();
#endif
            
            Trace.TraceWarning(
                this.prefix + "Leaving " +
                this.formatStrings.Format(
                    eventArgs.Instance,
                    eventArgs.Method,
                    eventArgs.GetReadOnlyArgumentArray()
                    ) +
                Formatter.FormatString( " with exception {0} : {{{1}}}.", eventArgs.Exception.GetType().Name,
                                        eventArgs.Exception.Message ) );
        }
Example #24
0
 public override void OnEntry(MethodExecutionEventArgs eventArgs)
 {
     MethodLogger.LogEntry(eventArgs.Method, eventArgs.GetReadOnlyArgumentArray(), EntryLevel);
 }