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


C# IInvocation.Proceed方法代码示例

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


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

示例1: Intercept

 public void Intercept(IInvocation invocation)
 {
     //// 判断目前方法是否有需要启用Cache,若有加上标记表示需要
     var attributes = invocation.Method.GetCustomAttributes(typeof(CacheAttribute), true);
     if (attributes.Count() > 0)
     {
         //// Cache key
         var key = string.Format("{0}.{1}.{2}", invocation.TargetType.FullName,
                                                invocation.MethodInvocationTarget.Name,
                                                JsonConvert.SerializeObject(invocation.Arguments));
         //// Expire Time
         var expireTime = (attributes.First() as CacheAttribute).ExpireTime;
         IDatabase cache = this.RedisConnection.GetDatabase();
         //// Cache是否存在,不存在产生新的
         var result = cache.Get(key);
         if (result != null)
         {
             invocation.ReturnValue = result;
             return;
         }
         invocation.Proceed();
         if (invocation.ReturnValue != null)
         {
             //存在返回值,添加到缓存。
             cache.Set(key, invocation.ReturnValue, TimeSpan.FromSeconds(expireTime));
         }
     }
     else
     {
         invocation.Proceed();
     }
 }
开发者ID:SaylorChung,项目名称:Intelligent.Community,代码行数:32,代码来源:CacheBehavior.cs

示例2: InterceptAsync

 private void InterceptAsync(IInvocation invocation, IEnumerable<OwAuthorizeAttribute> authorizeAttributes)
 {
     if (invocation.Method.ReturnType == typeof(Task))
     {
         invocation.ReturnValue = InternalAsyncHelper
             .AwaitTaskWithPreActionAndPostActionAndFinally(
                 () =>
                 {
                     invocation.Proceed();
                     return (Task)invocation.ReturnValue;
                 },
                 preAction: () => AuthorizeAsync(authorizeAttributes)
             );
     }
     else //Task<TResult>
     {
         invocation.ReturnValue = InternalAsyncHelper
             .CallAwaitTaskWithPreActionAndPostActionAndFinallyAndGetResult(
                 invocation.Method.ReturnType.GenericTypeArguments[0],
                 () =>
                 {
                     invocation.Proceed();
                     return invocation.ReturnValue;
                 },
                 preAction: async () => await AuthorizeAsync(authorizeAttributes)
             );
     }
 }
开发者ID:zhongkai1010,项目名称:OneWork,代码行数:28,代码来源:AuthorizationInterceptor.cs

示例3: cacheMethod

        private static void cacheMethod(IInvocation invocation)
        {
            var cacheMethodAttribute = getCacheMethodAttribute(invocation);
            if (cacheMethodAttribute == null)
            {
                invocation.Proceed();
                return;
            }

            var cacheDuration = ((CacheMethodAttribute)cacheMethodAttribute).SecondsToCache;

            var cacheKey = getCacheKey(invocation);

            var cache = HttpRuntime.Cache;
            var cachedResult = cache.Get(cacheKey);


            if (cachedResult != null)
            {
                invocation.ReturnValue = cachedResult;
            }
            else
            {
                lock (lockObject)
                {
                    invocation.Proceed();
                    if (invocation.ReturnValue == null)
                        return;

                    cache.Insert(cacheKey, invocation.ReturnValue, null, DateTime.Now.AddSeconds(cacheDuration), TimeSpan.Zero);
                }
            }
        }
开发者ID:wria7,项目名称:IrisCms,代码行数:33,代码来源:CacheInterceptor.cs

示例4: Intercept

        public void Intercept(IInvocation invocation)
        {
            var method = invocation.Method;
            var attributes = method.GetCustomAttributes(typeof(AuthorizeAttribute), true);

            if(attributes.Length == 0)
            {
                invocation.Proceed();
                return;
            }

            var authorization = attributes[0] as AuthorizeAttribute;
            if (authorization != null)
            {
                var requiredRole = authorization.Role;

                if(authorizationManager.CurrentPrincipal == null)
                {
                    throw new UnauthorizedAccessException("You are not logged into the system.");
                }

                if(!string.IsNullOrEmpty(requiredRole) && !authorizationManager.CurrentPrincipal.IsInRole(requiredRole)) //Has requested role
                {
                    throw new UnauthorizedAccessException(string.Format("Invalid access. You need {0} role for this operation.", requiredRole));
                }

                //Logged-in and has necessary roles, continue
                invocation.Proceed();
            }
        }
开发者ID:HEskandari,项目名称:Castle-Windsor-Examples,代码行数:30,代码来源:AuthorizationBehavior.cs

示例5: Intercept

		public void Intercept(IInvocation invocation)
		{
			var initialCulture = Thread.CurrentThread.CurrentCulture;
			var initialUiCulture = Thread.CurrentThread.CurrentUICulture;

			CultureInfo clientCulture, clientUiCulture;
			var cultureDirective = ReadMessageHeaders(OperationContext.Current);

			// if a culture directive was specified, use it
			if (ParseCultureDirective(cultureDirective, out clientCulture, out clientUiCulture))
			{
				Platform.Log(LogLevel.Debug, "Client Culture Header [{0}]: Culture={1}, UICulture={2}",
					invocation.MethodInvocationTarget.Name, cultureDirective.Culture, cultureDirective.UICulture);
				try
				{
					Thread.CurrentThread.CurrentCulture = clientCulture;
					Thread.CurrentThread.CurrentUICulture = clientUiCulture;
					invocation.Proceed();
				}
				finally
				{
					// always return the thread to its original culture
					Thread.CurrentThread.CurrentCulture = initialCulture;
					Thread.CurrentThread.CurrentUICulture = initialUiCulture;
				}
			}
			else
			{
				invocation.Proceed();
			}
		}
开发者ID:m-berkani,项目名称:ClearCanvas,代码行数:31,代码来源:CultureServerSideAdvice.cs

示例6: Intercept

        public void Intercept(IInvocation invocation)
        {
            // Pull the custom attribute class
            var attributes = invocation.Request.Method.GetAttribute<CachedResultAttribute>();
            if (attributes == null)
            {
                invocation.Proceed();
                return;
            }

            // Determine the expiration minutes
            int expirationMinutes = attributes.ExpirationMinutes != 0 ? attributes.ExpirationMinutes : 480; //480 = 8 hours

            // Generate the cache key
            string key = GenerateKey(invocation, attributes.CacheKey);

            // Pull data from cache or execute the method and store the result
            if(Cache.Contains(key))
            {
                invocation.ReturnValue = Cache[key];
            }
            else
            {
                invocation.Proceed();
                if(invocation.ReturnValue != null)
                {
                    Cache.Add(key, invocation.ReturnValue, DateTime.Now.AddMinutes(expirationMinutes));
                }
            }
        }
开发者ID:bpittner,项目名称:AOPCaching,代码行数:30,代码来源:CachedResultInterceptor.cs

示例7: Intercept

		public void Intercept(IInvocation invocation)
		{
			switch (invocation.Method.Name)
			{
				case "BeginEdit":
					BeginEdit();
					return;
				case "CancelEdit":
					CancelEdit();
					return;
				case "EndEdit":
					EndEdit(target);
					return;
				default:
					break;
			}

			if ((!invocation.Method.Name.StartsWith("get_") &&
			     !invocation.Method.Name.StartsWith("set_")) || !IsEditing)
			{
				invocation.Proceed();
				return;
			}

			if (_properties == null)
			{
				IEnumerable<PropertyInfo> propertyInfos = invocation.InvocationTarget.GetType().GetProperties(BindingFlags.Public |
				                                                                                              BindingFlags.Instance)
					.Where(p => p.CanWrite);
				//TODO: Enhance this.
				_properties = new Dictionary<string, PropertyInfo>();
				foreach (PropertyInfo propertyInfo in propertyInfos)
				{
					if (!_properties.ContainsKey(propertyInfo.Name))
						_properties[propertyInfo.Name] = propertyInfo;
				}
				target = invocation.InvocationTarget;
			}

			bool isSet = invocation.Method.Name.StartsWith("set_");
			string propertyName = invocation.Method.Name.Substring(4);
			PropertyInfo property;
			if (!_properties.TryGetValue(propertyName, out property))
			{
				invocation.Proceed();
				return;
			}

			if (isSet)
			{
				_tempValues[property] = invocation.Arguments[0];
			}
			else
			{
				invocation.Proceed();
				object value;
				if (_tempValues.TryGetValue(property, out value))
					invocation.ReturnValue = value;
			}
		}
开发者ID:Mrding,项目名称:Ribbon,代码行数:60,代码来源:EditableBehavior.cs

示例8: Intercept

        /// <summary>
        /// Intercepts the DAO calls to reference tables and caches them to minimize DB round trips
        /// </summary>
        /// <param name="invocation">
        /// The invocation.
        /// </param>
        public void Intercept(IInvocation invocation)
        {
            // if the interface is decorated with cache attribute
            var cacheDecorators = invocation.Method.GetCustomAttributes(typeof(CacheAttribute), true);
            if (cacheDecorators.Any())
            {
                var keyForCache = CreateInvocationKeyString(invocation);
                var cachedReturnValue = ObjectCacheWrapper.Get(keyForCache);
                if (cachedReturnValue != null)
                {
                    invocation.ReturnValue = cachedReturnValue == DBNull.Value ? null : cachedReturnValue; // since nulls can't cached - they are converted to dummy values
                    return;
                }

                invocation.Proceed();

                // add to cache
                var objectToCache = invocation.ReturnValue ?? DBNull.Value;
                var propInfo = cacheDecorators[0].GetType().GetProperty("CacheTimeSpanInSeconds");
                var cacheTimeSpanInSeconds = (long)propInfo.GetValue(cacheDecorators[0], null);
                ObjectCacheWrapper.Set(objectToCache, keyForCache, cacheTimeSpanInSeconds);
            }
            else
            {
                invocation.Proceed();
            }
        }
开发者ID:Krishna-Desiraju,项目名称:CacheInterceptor,代码行数:33,代码来源:CacheInterceptor.cs

示例9: Intercept

		/// <summary>
		/// Invoke the actual Property/Method using the Proxy or instantiate the actual
		/// object and use it when the Proxy can't handle the method. 
		/// </summary>
		/// <param name="invocation">The <see cref="IInvocation"/> from the generated Castle.DynamicProxy.</param>
		/// <param name="args">The parameters for the Method/Property</param>
		/// <returns>The result just like the actual object was called.</returns>
		public object Intercept( IInvocation invocation, params object[ ] args )
		{
			if( _constructed )
			{
				// let the generic LazyInitializer figure out if this can be handled
				// with the proxy or if the real class needs to be initialized
				object result = base.Invoke( invocation.Method, args, invocation.Proxy );

				// the base LazyInitializer could not handle it so we need to Invoke
				// the method/property against the real class
				if( result == InvokeImplementation )
				{
					invocation.InvocationTarget = GetImplementation();
					return invocation.Proceed( args );
				}
				else
				{
					return result;
				}
			}
			else
			{
				// TODO: Find out equivalent to CGLIB's 'method.invokeSuper'.
				return invocation.Proceed( args );
			}
		}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:33,代码来源:CastleLazyInitializer.cs

示例10: Intercept

        /// <summary>
        /// Intercepts a method.
        /// </summary>
        /// <param name="invocation">Method invocation arguments</param>
        public void Intercept(IInvocation invocation)
        {
            if (_unitOfWorkManager.Current != null)
            {
                //Continue with current uow
                invocation.Proceed();
                return;
            }

            var unitOfWorkAttr = UnitOfWorkAttribute.GetUnitOfWorkAttributeOrNull(invocation.MethodInvocationTarget);
            if (unitOfWorkAttr == null || unitOfWorkAttr.IsDisabled)
            {
                //No need to a uow
                invocation.Proceed();
                return;
            }
            
            if (typeof(Abp.Domain.Repositories.IRepository).IsAssignableFrom(invocation.MethodInvocationTarget.DeclaringType))
            {
                // Disable Transaction
                // for example:I only read some data in the action of controller,at the moment ,I don't need a transaction.
                // If need uow in the action of controller,I must set the UnitOfWOrkAttribute on the action of controller.
                // The transaction is the important,need to indicate by UnitOfWOrkAttribute,not auto in the system.
                unitOrWorkAttr.IsTransactional = false;
            }
            
            //No current uow, run a new one
            PerformUow(invocation, unitOfWorkAttr.CreateOptions());
        }
开发者ID:bendan365,项目名称:aspnetboilerplate,代码行数:33,代码来源:UnitOfWorkInterceptor.cs

示例11: Intercept

		/// <summary>
		/// Invoke the actual Property/Method using the Proxy or instantiate the actual
		/// object and use it when the Proxy can't handle the method. 
		/// </summary>
		/// <param name="invocation">The <see cref="IInvocation"/> from the generated Castle.DynamicProxy.</param>
		/// <param name="args">The parameters for the Method/Property</param>
		/// <returns>The result just like the actual object was called.</returns>
		public object Intercept(IInvocation invocation, params object[] args)
		{
			try
			{
				if (_constructed)
				{
					// let the generic LazyInitializer figure out if this can be handled
					// with the proxy or if the real class needs to be initialized
					object result = base.Invoke(invocation.Method, args, invocation.Proxy);

					// the base LazyInitializer could not handle it so we need to Invoke
					// the method/property against the real class
					if (result == InvokeImplementation)
					{
						invocation.InvocationTarget = GetImplementation();
						return invocation.Proceed(args);
					}
					else
					{
						return result;
					}
				}
				else
				{
					// TODO: Find out equivalent to CGLIB's 'method.invokeSuper'.
					return invocation.Proceed(args);
				}
			}
			catch (TargetInvocationException tie)
			{
				// Propagate the inner exception so that the proxy throws the same exception as
				// the real object would (though of course the stack trace will be probably lost).
				throw tie.InnerException;
			}
		}
开发者ID:Novthirteen,项目名称:sconit_timesseiko,代码行数:42,代码来源:CastleLazyInitializer.cs

示例12: Intercept

        public void Intercept(IInvocation invocation)
        {
            if (invocation.Method.ReturnParameter == null || invocation.Method.ReturnParameter.ParameterType == typeof(void))
            {
                invocation.Proceed();
                return;
            }

            var attribute = ReflectionHelper.GetCustomAttribute<MethodCacheAttribute>(invocation.Method);
            
            string key = GetCacheKey(invocation);
            object value = CacheHelper.GetFromCache(key, attribute);

            if (value != null)
            {
                invocation.ReturnValue = value;
                Debug.WriteLine(string.Format("> {0} returned cached value from {1} : key {2}", invocation.Method.Name, attribute.CacheLocation.ToString(), key));
            }
            else
            {
                invocation.Proceed();
                Debug.WriteLine(string.Format("> {0} called and did not return from cache with key {1}", invocation.Method.Name, key));
                value = invocation.ReturnValue;

                if (value != null)
                    CacheHelper.AddToCache(key, value, attribute);
            }
        }
开发者ID:markeverard,项目名称:FortuneCookie.BuildStatus,代码行数:28,代码来源:MethodCacheInterceptor.cs

示例13: Intercept

		/// <summary>
		/// Intercepts the specified invocation and creates a transaction
		/// if necessary.
		/// </summary>
		/// <param name="invocation">The invocation.</param>
		/// <returns></returns>
		public void Intercept(IInvocation invocation)
		{
			MethodInfo methodInfo;
			if (invocation.Method.DeclaringType.IsInterface)
				methodInfo = invocation.MethodInvocationTarget;
			else
				methodInfo = invocation.Method;

			if (metaInfo == null || !metaInfo.Contains(methodInfo))
			{
				invocation.Proceed();
				return;
			}

			var session = sessionManager.OpenSession();

			try
			{
				invocation.Proceed();
			}
			finally
			{
				session.Dispose();
			}
		}
开发者ID:RookieX,项目名称:Windsor,代码行数:31,代码来源:NHSessionInterceptor.cs

示例14: Intercept

        public void Intercept(IInvocation invocation)
        {
            try
            {
                if (CheckTransactionalStatus(invocation.Method))
                {
                    if (UnitOfWork.Current == null)
                        UnitOfWork.Current = new UnitOfWork(Context);

                    using (UnitOfWork.Current)
                    {
                        invocation.Proceed();

                        //Log xml
                        Logger(invocation, null);

                        UnitOfWork.Current.Commit();
                    }
                }
                else
                {
                    invocation.Proceed();
                }
            }
            catch (Exception ex)
            {
                //Exception Handling xml
                Logger(invocation, ex);
            }
            finally
            {
                UnitOfWork.Current = null;
            }
        }
开发者ID:bilalislam,项目名称:SimpleSoaFx,代码行数:34,代码来源:UnitOfWorkInterceptor.cs

示例15: Intercept

        public void Intercept(IInvocation invocation)
        {
            var property = invocation.GetPropertyIfSetInvocation();
            if (invocation.InvocationTarget == null || property == null)
            {
                invocation.Proceed();

                var attributes = invocation.Method.GetCustomAttributes(typeof(ModifiesAttribute), true).OfType<ModifiesAttribute>();
                if (invocation.InvocationTarget != null && attributes.Any())
                {
                    foreach (var modifiesAttribute in attributes)
                    {
                        var modified = invocation.InvocationTarget.GetType().GetProperty(modifiesAttribute.PropertyName);
                        RaisePropertyChanged(invocation.InvocationTarget, modified);
                    }
                }

                return;
            }

            RemoveAssociation(invocation.InvocationTarget, property.Value(invocation.InvocationTarget), property);
            invocation.Proceed();

            AddAssociation(invocation.InvocationTarget, property.Value(invocation.InvocationTarget),
                property, RaisePropertyChanged);

            RaisePropertyChanged(invocation.InvocationTarget, property);
        }
开发者ID:oliverhanappi,项目名称:notifui,代码行数:28,代码来源:RaisePropertyChangedInterceptor.cs


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