当前位置: 首页>>代码示例>>C#>>正文


C# IInvocation类代码示例

本文整理汇总了C#中IInvocation的典型用法代码示例。如果您正苦于以下问题:C# IInvocation类的具体用法?C# IInvocation怎么用?C# IInvocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IInvocation类属于命名空间,在下文中一共展示了IInvocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CacheInvocation

        /// <summary>
        /// Caches the invocation.
        /// </summary>
        /// <param name="invocation">The invocation.</param>
        /// <param name="cacheKeyProvider">The cache key provider.</param>
        /// <param name="cacheItemSerializer">The cache item serializer.</param>
        /// <param name="cacheStorageMode">The cache storage mode.</param>
        private void CacheInvocation(IInvocation invocation, ICacheKeyProvider cacheKeyProvider, ICacheItemSerializer cacheItemSerializer)
        {
            string hash = cacheKeyProvider.GetCacheKeyForMethod(invocation.InvocationTarget,
                invocation.MethodInvocationTarget, invocation.Arguments);

            string hashedObjectDataType = string.Format(HASHED_DATA_TYPE_FORMAT, hash);

            var cacheProvider = CacheProviderFactory.Default.GetCacheProvider();

            Type type = cacheProvider[hashedObjectDataType] as Type;
            object data = null;
            if (type != null && cacheProvider[hash] != null)
                data = cacheItemSerializer.Deserialize(cacheProvider[hash].ToString(), type,
                    invocation.InvocationTarget, invocation.Method, invocation.Arguments);

            if (data == null)
            {
                invocation.Proceed();
                data = invocation.ReturnValue;
                if (data != null)
                {
                    cacheProvider.Add(hashedObjectDataType, invocation.Method.ReturnType);
                    cacheProvider.Add(hash, cacheItemSerializer.Serialize(data, invocation.InvocationTarget,
                        invocation.Method, invocation.Arguments));
                }
            }
            else
                invocation.ReturnValue = data;
        }
开发者ID:eallegretta,项目名称:LtaBlog,代码行数:36,代码来源:CachingInterceptor.cs

示例2: Intercept

        public void Intercept(IInvocation invocation)
        {
            switch (invocation.Method.Name)
              {
            case "Close":
              _closedSubscribers(invocation.InvocationTarget, EventArgs.Empty);
              _closedSubscribers = delegate { };
              break;
            case "add_Closed":
              {
            var propertyChangedEventHandler = (EventHandler) invocation.Arguments[0];
            _closedSubscribers += propertyChangedEventHandler;
              }
              break;
            case "remove_Closed":
              {
            var propertyChangedEventHandler = (EventHandler) invocation.Arguments[0];
            _closedSubscribers -= propertyChangedEventHandler;
              }
              break;
              }

              if (invocation.TargetType != null)
            invocation.Proceed();
        }
开发者ID:leloulight,项目名称:magicgrove,代码行数:25,代码来源:CloseInterceptor.cs

示例3: Intercept

        public override void Intercept(IInvocation invocation)
        {
            // WPF will call a method named add_PropertyChanged to subscribe itself to the property changed events of
            // the given entity. The method to call is stored in invocation.Arguments[0]. We get this and add it to the
            // proxy subscriber list.
            if (invocation.Method.Name.Contains("PropertyChanged"))
            {
                PropertyChangedEventHandler propertyChangedEventHandler = (PropertyChangedEventHandler)invocation.Arguments[0];
                if (invocation.Method.Name.StartsWith("add_"))
                {
                    subscribers += propertyChangedEventHandler;
                }
                else
                {
                    subscribers -= propertyChangedEventHandler;
                }
            }

            // Here we call the actual method of the entity
            base.Intercept(invocation);

            // If the method that was called was actually a proeprty setter (set_Line1 for example) we generate the
            // PropertyChanged event for the property but with event generator the proxy. This must do the trick.
            if (invocation.Method.Name.StartsWith("set_"))
            {
                subscribers(invocation.InvocationTarget, new PropertyChangedEventArgs(invocation.Method.Name.Substring(4)));
            }
        }
开发者ID:MatiasBjorling,项目名称:EcoLoad,代码行数:28,代码来源:DataBindingIntercepter.cs

示例4: getKey

 private string getKey(IInvocation invocation, CacheAttribute attribute)
 {
     if (attribute.IsKey)
     {
         if (attribute.IsResolve)
         {
             throw new NotSupportedException();
         }
         else
         {
             return attribute.Key;
         }
     }
     else//if (attribute.IsArg)
     {
         if (attribute.IsResolve)
         {
             throw new NotSupportedException();
         }
         else
         {
             object[] args = InterceptorHelper.GetInvocationMethodArgs(invocation);
             if (attribute.Arg <= args.Length)
             {
                 return args[attribute.Arg].ToString();
             }
             else
             {
                 throw new IndexOutOfRangeException();
             }
         }
     }
 }
开发者ID:hitechie,项目名称:IocCore,代码行数:33,代码来源:CacheInterceptor.cs

示例5: Intercept

        public void Intercept(IInvocation invocation)
        {
            if (AbpCrossCuttingConcerns.IsApplied(invocation.InvocationTarget, AbpCrossCuttingConcerns.Auditing))
            {
                invocation.Proceed();
                return;
            }

            if (!_auditingHelper.ShouldSaveAudit(invocation.MethodInvocationTarget))
            {
                invocation.Proceed();
                return;
            }

            var auditInfo = _auditingHelper.CreateAuditInfo(invocation.MethodInvocationTarget, invocation.Arguments);

            if (AsyncHelper.IsAsyncMethod(invocation.Method))
            {
                PerformAsyncAuditing(invocation, auditInfo);
            }
            else
            {
                PerformSyncAuditing(invocation, auditInfo);
            }
        }
开发者ID:vytautask,项目名称:aspnetboilerplate,代码行数:25,代码来源:AuditingInterceptor.cs

示例6: OnException

        protected override void OnException(IInvocation invocation)
        {
            ExceptionContext arg;
            arg = invocation.Arguments[0] as ExceptionContext;
            var args = string.Join(",", arg.RouteData.Values.Select(x => x.Key + " = " + x.Value));
            string message = arg.Exception.Message;
            if(arg.Exception.InnerException != null)
            {
                message = message +" "+ arg.Exception.InnerException.Message;
            }

            if (arg.Exception.GetType() ==  typeof(DbEntityValidationException))
            {
                DbEntityValidationException dbEx = arg.Exception as DbEntityValidationException;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        message = message + "," + string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }

            message = message + arg.Exception.StackTrace;
            _logger.Fatal(createRecord("Exception"
                            , arg.Controller.GetType().Name
                            , arg.Result.ToString()
                            , args
                            , message));
        }
开发者ID:AleksanderGalkin,项目名称:MyBlog,代码行数:30,代码来源:LogInterceptor.cs

示例7: Intercept

        public void Intercept(IInvocation invocation)
        {

            ICommand cmd = invocation.Arguments[0] as ICommand;
            ExecutedCommand executedCommand;
            if (cmd == null)
            {
               
                invocation.Proceed();
            }
            else
            {
                //this is a method that accepts a command invoker, should be intercepted
                 executedCommand = new ExecutedCommand()
                {
                    Command = cmd,
                    Id = cmd.Id,
                };
                try
                {
                    invocation.Proceed();
                    _commandStore.Store(executedCommand);
                }
                catch (Exception ex)
                {
                    executedCommand.IsSuccess = false;
                    executedCommand.Error = ex.ToString();
                    _commandStore.Store(executedCommand);
                    throw;
                }

            }


        }
开发者ID:AGiorgetti,项目名称:Prxm.Cqrs,代码行数:35,代码来源:CommandStoreInterceptor.cs

示例8: Intercept

		public void Intercept(IInvocation invocation)
		{
			if (invocation.Method.ReturnType.IsValueType)
			{
				invocation.ReturnValue = Activator.CreateInstance(invocation.Method.ReturnType);
			}
		}
开发者ID:vbedegi,项目名称:Castle.InversionOfControl,代码行数:7,代码来源:ReturnDefaultInterceptor.cs

示例9: Intercept

        public void Intercept(IInvocation invocation)
        {
            foreach (var matchVsReturnValue in _invocationVersusReturnValue)
            {
                if (matchVsReturnValue.Key.Matches(invocation.Method, invocation.Arguments))
                {
                    invocation.ReturnValue = matchVsReturnValue.Value.Produce(invocation.Arguments);
                    return;
                }
            }

            if (Fallback != null)
            {
                invocation.ReturnValue = invocation.Method.Invoke(Fallback, invocation.Arguments);
            }
            else
            {
                if (invocation.Method.ReturnType != typeof(void))
                {
                    if (invocation.Method.ReturnType.IsValueType)
                        invocation.ReturnValue = Activator.CreateInstance(invocation.Method.ReturnType);
                    else
                        invocation.ReturnValue = null;
                }
            }
        }
开发者ID:ToshB,项目名称:nservicestub,代码行数:26,代码来源:WcfCallsInterceptor.cs

示例10: OnError

        protected override void OnError(IInvocation invocation, Exception exception)
        {
            string sw = string.Format("********** {0} **********\n Message: {1}", DateTime.Now, exception.Message);
            if (exception.InnerException != null)
            {
                sw += string.Format(
                    "Inner Exception Type: {0} \n Inner Exception: {1} \n Inner Source: {2}",
                    exception.InnerException.GetType(),
                    exception.InnerException.Message,
                    exception.InnerException.Source);
                if (exception.InnerException.StackTrace != null)
                {
                    sw += string.Format("\n Inner Stack Trace: {0}", exception.InnerException.StackTrace);
                }
            }
            sw += string.Format(
                "\n Exception Type: {0}\n Exception: {1}\n Source: {2}\n Stack Trace: ",
                exception.GetType(),
                exception.Message,
                MethodNameFor(invocation));
            if (exception.StackTrace != null)
            {
                sw += (exception.StackTrace);
            }

            this._logger.Error(
                exception, "There was an error invoking {0} Error details is:{1}.\r\n", MethodNameFor(invocation), sw);

            this._hasError = true;
            base.OnError(invocation, exception);
        }
开发者ID:jzinedine,项目名称:Cedar,代码行数:31,代码来源:LoggingInterceptor.cs

示例11: Intercept

        public void Intercept(IInvocation invocation)
        {
            string methodName = invocation.Method.Name;

            // if target method is property getter and return value is null - do interception.
            if (!methodName.StartsWith(PropertyGetMethodPefix) || invocation.ReturnValue != null)
            {
                return;
            }

            // logic here for illustration purpose only and should be moved to separate service.
            if (methodName.StartsWith(PropertyGetMethodPefix))
            {
                object value = null;
                string propertyName = methodName.Substring(PropertyGetMethodPefix.Count());

                PropertyInfo propertyInfo = invocation.TargetType.GetProperty(propertyName);
                var defaultValueAttr = (DefaultValueAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(DefaultValueAttribute));
                if (defaultValueAttr != null)
                {
                    var defaultValue = defaultValueAttr.Value;
                    if (defaultValue != null && invocation.Method.ReturnType.IsInstanceOfType(defaultValue))
                    {
                        value = defaultValue;
                    }
                }

                invocation.ReturnValue = value;
            }
        }
开发者ID:Romanets,项目名称:EPiInterceptors,代码行数:30,代码来源:DefaultPropertyValueInterceptor.cs

示例12: AfterInvoke

 protected override void AfterInvoke(IInvocation invocation)
 {
     this._logger.Info(
         "{0} finished {1}.",
         MethodNameFor(invocation),
         (this._hasError ? "with an error state" : "successfully"));
 }
开发者ID:jzinedine,项目名称:Cedar,代码行数:7,代码来源:LoggingInterceptor.cs

示例13: PreProceed

        public void PreProceed(IInvocation invocation)
        {
            Console.WriteLine("before action executed");

            int indent = 0;

            if (indent > 0)
            {
                Console.Write(" ".PadRight(indent * 4, ' '));
            }

            indent++;

            Console.Write("Intercepting: " + invocation.Method.Name + "(");

            if (invocation.Arguments != null && invocation.Arguments.Length > 0)
            {
                for (int i = 0; i < invocation.Arguments.Length; i++)
                {
                    if (i != 0) Console.Write(", ");
                    Console.Write(invocation.Arguments[i] == null
                        ? "null"
                        : invocation.Arguments[i].GetType() == typeof(string)
                           ? "\"" + invocation.Arguments[i].ToString() + "\""
                           : invocation.Arguments[i].ToString());
                }
            }

            Console.WriteLine(")");
        }
开发者ID:HK-Zhang,项目名称:Grains,代码行数:30,代码来源:CastleDynamicProxy.cs

示例14: Intercept

        public void Intercept(IInvocation invocation)
        {
            var methodName = invocation.Method.Name;
            var arguments = invocation.Arguments;
            var proxy = invocation.Proxy;
            var isEditableObject = proxy is IEditableObject;

            if (invocation.Method.DeclaringType.Equals(typeof (INotifyPropertyChanged)))
            {
                if (methodName == "add_PropertyChanged")
                {
                    StoreHandler((Delegate) arguments[0]);
                }
                if (methodName == "remove_PropertyChanged")
                {
                    RemoveHandler((Delegate) arguments[0]);
                }
            }

            if (!ShouldProceedWithInvocation(methodName))
                return;

            invocation.Proceed();

            NotifyPropertyChanged(methodName, proxy, isEditableObject);
        }
开发者ID:kkozmic,项目名称:Castle-Windsor-Examples,代码行数:26,代码来源:NotifyPropertyChangedBehavior.cs

示例15: PreProcess

        public virtual void PreProcess(IInvocation invocation, CoreInterceptContext context)
        {
            if (invocation.Method.Name.StartsWith("get_") || "ToString".Equals(invocation.Method.Name))
                return;

            context.ActionListener.ActionPerforming((UIItem)context.UiItem);
        }
开发者ID:huangzhichong,项目名称:White,代码行数:7,代码来源:ScrollInterceptor.cs


注:本文中的IInvocation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。