コード例 #1
0
 private void CheckAfterAspect(RealTypeResponseArgument _realTypeResponse, object[] _aspects)
 {
     foreach (AspectBase itemAttribute in _aspects)
     {
         itemAttribute.OnAfter(_realTypeResponse, this.MethodContext);
     }
 }
コード例 #2
0
        public override IMessage Invoke(IMessage msg)
        {
            IMethodCallMessage _methodCallMessage = msg as IMethodCallMessage;
            ReturnMessage      _returnMessage     = null;

            try
            {
                Type       _realServiceType = typeof(T);
                MethodInfo _mInfo           = _realServiceType.GetMethod(_methodCallMessage.MethodName);
                object[]   _aspects         = this.GetAspects(_mInfo, _realServiceType); // _mInfo.GetCustomAttributes(typeof(AspectBase), true);


                _aspects = _aspects.OrderBy(o => (o as AspectBase).Priority).ToArray();

                //
                FillMethodContext(_methodCallMessage, _mInfo.ReturnType, _realServiceType);

                //önce araya  giriyoruz.
                //JOIN POINT 1 : BEFORE ASPECTS
                object _response = CheckBeforeAspect(_aspects);

                //
                //real type method before aspect' de calısmadıysa çalışsın (if real type method for before don't work. let the method work )
                if (!this.MethodContext.IsInvoke)
                {
                    _response = this.MethodContext.Invoke();
                }

                //return message dolduruldu.
                _returnMessage = new ReturnMessage(_response, null, 0, _methodCallMessage.LogicalCallContext, _methodCallMessage);

                //
                //bu bölüme kadar olanda real type method çalışmasını kesinlikle bitirdi.
                //

                //sonraki işlemler için real type doğrulama işlemi yapılıyor.
                RealTypeResponseArgument _realTypeResponseArgumentItem = new RealTypeResponseArgument()
                {
                    Value           = _response,
                    IsRealTypeValue = _response != null && _response.GetType().GUID == this.MethodContext.RealReturnType.GUID
                };

                //sonra araya giriyoruz
                CheckAfterAspect(_realTypeResponseArgumentItem, _aspects);

                //son olarak geri dönüş değeri vaadedilen geri dönüş değeri değilse null göndermek mantıklı olacaktır :)
                if (!_realTypeResponseArgumentItem.IsRealTypeValue)
                {
                    _returnMessage = new ReturnMessage(null, null, 0, _methodCallMessage.LogicalCallContext, _methodCallMessage);
                }

                return(_returnMessage);
            }
            catch (Exception ex)
            {
                return(new ReturnMessage(null, null, 0, _methodCallMessage.LogicalCallContext, _methodCallMessage));
            }
        }
コード例 #3
0
        public virtual void OnAfterAddToCache(RealTypeResponseArgument param, MethodContext _methodContext)
        {
            string cacheKey = string.Format("{0}_{1}", _methodContext.MethodName, string.Join("_", _methodContext.Arguments));

            if (MemoryCache.Default.Get(cacheKey) == null && param.Value != null && param.IsRealTypeValue)
            {
                MemoryCache.Default.Add(cacheKey, param.Value, DateTimeOffset.Now.AddMinutes(DurationMinute));
            }
        }
コード例 #4
0
        public virtual void OnAfterlogProcess(RealTypeResponseArgument param, MethodContext _methodContext)
        {
            AspectExplorerLogAttributeModel _aspectLogModel = new AspectExplorerLogAttributeModel();

            _aspectLogModel.InvokeMethodName = _methodContext.MethodName;
            _aspectLogModel.InvokeStackTrace = "";
            _aspectLogModel.InvokeTime       = DateTime.Now;
            if (param != null)
            {
                _aspectLogModel.ResponseType = param.Value.GetType().ToString();
            }

            // _aspectLogModel.RequestTypes = _methodContext.MethodBase.Args

            //
            try
            {
                StringBuilder sbRequestTypes = new StringBuilder();
                StringBuilder sbRequestArgs  = new StringBuilder();
                foreach (var item in _methodContext.MethodBase.Args)
                {
                    sbRequestTypes.Append(item.GetType().ToString());

                    sbRequestArgs.Append(item.GetType().ToString()).Append(" : ");
                    foreach (PropertyInfo eachItem in item.GetType().GetProperties())
                    {
                        if (eachItem.GetValue(item) != null)
                        {
                            sbRequestArgs.Append(string.Format("{0} : {1}", eachItem.Name, eachItem.GetValue(item).ToString()));
                        }
                    }
                }
                _aspectLogModel.RequestTypes   = sbRequestTypes.ToString();
                _aspectLogModel.RequestArgsStr = sbRequestArgs.ToString();
            }
            catch { }
            //
            try
            {
                if (param != null)
                {
                    StringBuilder sbResponseValue = new StringBuilder();
                    foreach (PropertyInfo item in param.Value.GetType().GetProperties())
                    {
                        if (item.GetValue(param.Value) != null)
                        {
                            sbResponseValue.Append(string.Format("{0} : {1}", item.Name, item.GetValue(param.Value).ToString()));
                        }
                    }
                    _aspectLogModel.ResponseArgsStr = sbResponseValue.ToString();
                }
            }
            catch { }
            //

            //
            try
            {
                StringBuilder sbJsonResult = new StringBuilder();
                sbJsonResult.Append(" # ").Append(DateTime.Now.ToString()).Append(" : ");
                sbJsonResult.Append(new JavaScriptSerializer().Serialize(_aspectLogModel));

                string _directoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AspectExplorerLog/");
                if (!Directory.Exists(_directoryPath))
                {
                    Directory.CreateDirectory(_directoryPath);
                }
                File.AppendAllText(_directoryPath + DateTime.Now.ToString("yyyyMMdd") + "log.txt", sbJsonResult.ToString());
            }
            catch { }
        }
コード例 #5
0
 public override void OnAfter(RealTypeResponseArgument param, MethodContext _methodContext)
 {
     this.OnAfterlogProcess(param.Value == null ? null : param, _methodContext);
 }
コード例 #6
0
 public override void OnAfter(RealTypeResponseArgument param, MethodContext _methodContext)
 {
     this.OnAfterAddToCache(param, _methodContext);
 }
コード例 #7
0
 //JOIN POINTS ON AFTER
 public virtual void OnAfter(RealTypeResponseArgument _param, MethodContext _methodContext)
 {
 }