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


C# IInvocation.SetArgumentValue方法代码示例

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


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

示例1: Intercept

        public void Intercept(IInvocation invocation)
        {
            var methodInfo = invocation.Method;
            Object[] attributes = methodInfo.GetCustomAttributes(true);

            var directoryAttri = attributes.SingleOrDefault(a => a is DirectoryAttribute) as DirectoryAttribute;

            var clusterAttri = attributes.SingleOrDefault(a => a is ClusterAttribute) as ClusterAttribute;

            var loadBalanceAttri = attributes.SingleOrDefault(a => a is LoadBalanceAttribute) as LoadBalanceAttribute;

            var protocolAttri = attributes.SingleOrDefault(a => a is ProtocolAttribute) as ProtocolAttribute;

            ConstructorInfo constr = protocolAttri.ContextType.GetConstructors()[0];

            ParameterInfo[] parameters = constr.GetParameters();

            object[] constrParamters = new Object[parameters.Length];
            constrParamters[0] = new DirectoryContext(directoryAttri.Path, directoryAttri.Directory);
            constrParamters[1] = new ClusterContext(clusterAttri.Name);
            constrParamters[2] = new LoadBalanceContext(loadBalanceAttri.Name);

            for (var i = 3; i < parameters.Length; i++)
            {
                Object value = PropertyHelper.GetPropertyValue(protocolAttri.GetType(), protocolAttri, parameters[i].Name);

                constrParamters[i] = value;
            }

            var invokeContext = Activator.CreateInstance(protocolAttri.ContextType, constrParamters) as InvokerContext;

            invocation.SetArgumentValue(invocation.Arguments.Length - 1, invokeContext);
            invocation.Proceed();
        }
开发者ID:hahalixiaojing,项目名称:easy.rpc,代码行数:34,代码来源:RPCServiceInterceptor.cs

示例2: Intercept

		public void Intercept (IInvocation invocation)
		{
			if (invocation.Method.DeclaringType == typeof (IProxy)) {
				invocation.ReturnValue = Behaviors;
				return;
			}

			var input = new MethodInvocation(invocation.InvocationTarget, invocation.Method, invocation.Arguments);
			var returns = pipeline.Invoke(input, (i, next) => {
				try  {
					invocation.Proceed();
					var returnValue = invocation.ReturnValue;
					return input.CreateValueReturn(returnValue, invocation.Arguments);
				} catch (Exception ex) {
					return input.CreateExceptionReturn(ex);
				}
			});

			var exception = returns.Exception;
			if (exception != null)
				throw exception;

			invocation.ReturnValue = returns.ReturnValue;
			for (int i = 0; i < returns.Outputs.Count; i++) {
				var name = returns.Outputs.GetName(i);
				var index = input.Arguments.IndexOf (name);
				invocation.SetArgumentValue (index, returns.Outputs[index]);
			}
		}
开发者ID:moq,项目名称:moq.proxy,代码行数:29,代码来源:Interceptor.cs

示例3: Intercept

        public void Intercept(IInvocation invocation)
        {
            ParameterInfo[] paras = invocation.Method.GetParameters();
            int argLength = paras.Length;
            if (argLength > 0)
            {
                for (int i = 0; i < argLength; i++)
                {
                    ParameterInfo para = paras[i];
                    Type paraType = para.ParameterType;
                    if (paraType == typeof(String))
                    {
                        string paraOriginalValue = Convert.ToString(invocation.GetArgumentValue(i));
                        string paraConveredValue = SQLInjectionHelper.GetSafeSqlBeforeSave(paraOriginalValue);
                        invocation.SetArgumentValue(i, paraConveredValue);
                    }
                }
            }

            invocation.Proceed();
        }
开发者ID:notinmood,项目名称:hiland,代码行数:21,代码来源:SQLInjectionInterceptor.cs

示例4: CreateNextLevel

        public Func<object[], object> CreateNextLevel(IInvocation invocation, IEnumerable<IAspect> restOfAspects, IAspectEnvironment method)
        {
            return args =>
                       {
                           IAspect nextAspect = restOfAspects.FirstOrDefault();
                           if (nextAspect != null)
                           {
                               //Recursion
                               return nextAspect.Execute(
                                   CreateNextLevel(invocation, restOfAspects.Skip(1), method),
                                   args, method
                                   );
                           }

                           for (int i = 0; i < args.Length; i++)
                           {
                               invocation.SetArgumentValue(i, args[i]);
                           }
                           //Enter the body of the concrete Method
                           invocation.Proceed();
                           return invocation.ReturnValue;
                       };
        }
开发者ID:chrido,项目名称:NAdvisor,代码行数:23,代码来源:AdviceInterceptor.cs

示例5: MapResponseResult

        private static void MapResponseResult(IInvocation invocation, List<ParameterInfo> @params, RpcResponse response)
        {
            if (response.Exception != null)
            {
                throw response.Exception;
            }

            if (invocation.Method.ReturnType != typeof(void) && response.ReturnValue != null)
            {
                invocation.ReturnValue = response.ReturnValue.ConvertToCorrectTypeValue(invocation.Method.ReturnType);
            }

            var outParams = @params.Where(x => x.IsOut).Select(x => x.Name);
            var missingOutValue = outParams.FirstOrDefault(param => !(response.ChangedParams ?? new Dictionary<string, object>()).ContainsKey(param));
            if (missingOutValue != null)
            {
                throw new Exception(string.Format("RpcResponse does not contain the modified value for param {0} which is an 'out' param. Probably there's something wrong with the bloody Coordinator", missingOutValue));
            }

            for (var i = 0; i < @params.Count; i++)
            {
                if (@params[i].IsOut)
                {
                    invocation.SetArgumentValue(i, response.ChangedParams[@params[i].Name].ConvertToCorrectTypeValue(@params[i].ParameterType.GetElementType()));
                }
                else if (@params[i].ParameterType.IsByRef && response.ChangedParams.ContainsKey(@params[i].Name))
                {
                    invocation.SetArgumentValue(i, response.ChangedParams[@params[i].Name].ConvertToCorrectTypeValue(@params[i].ParameterType.GetElementType()));
                }
            }
        }
开发者ID:kangkot,项目名称:Burrow.NET,代码行数:31,代码来源:RpcClientInterceptor.cs

示例6: 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;
			}
			else
			{
				TransactionAttribute transactionAtt = metaInfo.GetTransactionAttributeFor(methodInfo);

				ITransactionManager manager = kernel.Resolve<ITransactionManager>();

				ITransaction transaction = manager.CreateTransaction(
					transactionAtt.TransactionMode, transactionAtt.IsolationMode, transactionAtt.Distributed);

				if (transaction == null)
				{
					invocation.Proceed();
					return;
				}

				transaction.Begin();

				bool rolledback = false;

				try
				{
					if (metaInfo.ShouldInject(methodInfo))
					{
						var parameters = methodInfo.GetParameters();

						for (int i = 0; i < parameters.Length; i++)
						{
							if (parameters[i].ParameterType == typeof(ITransaction))
							{
								invocation.SetArgumentValue(i, transaction);
							}
						}
					}
					invocation.Proceed();

					if (transaction.IsRollbackOnlySet)
					{
						logger.DebugFormat("Rolling back transaction {0}", transaction.GetHashCode());

						rolledback = true;
						transaction.Rollback();
					}
					else
					{
						logger.DebugFormat("Committing transaction {0}", transaction.GetHashCode());

						transaction.Commit();
					}
				}
				catch(TransactionException ex)
				{
					// Whoops. Special case, let's throw without 
					// attempt to rollback anything

					if (logger.IsFatalEnabled)
					{
						logger.Fatal("Fatal error during transaction processing", ex);
					}

					throw;
				}
				catch(Exception)
				{
					if (!rolledback)
					{
						if (logger.IsDebugEnabled)
							logger.DebugFormat("Rolling back transaction {0} due to exception on method {2}.{1}", transaction.GetHashCode(), methodInfo.Name, methodInfo.DeclaringType.Name);

						transaction.Rollback();
					}

					throw;
				}
				finally
				{
					manager.Dispose(transaction); 
				}
			}
		}
开发者ID:ThatExtraBit,项目名称:Castle.Facilities.AutomaticTransactionManagement,代码行数:98,代码来源:TransactionInterceptor.cs

示例7: InterceptMethod

        public override void InterceptMethod(IInvocation invocation, MethodBase method, Attribute attribute)
        {
            var svcCacheAttribute = (ServiceCacheAttribute)attribute;
            var parameters = invocation.Method.GetParameters();

            if (svcCacheAttribute.TimeoutSecs == 0)
                //|| (!invocation.Method.ReturnType.IsEnumerableType() && !invocation.Method.ReturnType.IsSerializable)
                //|| !invocation.Method.ReturnType.IsSerializableEnumerableType())
            {
                invocation.Proceed();
                return;
            }

            #region check gloable white list
            if (invocation.InvocationTarget.GetType().Equals(typeof(AppStoreService))
                || invocation.InvocationTarget.GetType().Equals(typeof(OTAService)))
            {
                int moibleParameterIndex = -1;
                for (int i = 0; i < parameters.Length; i++)
                {
                    if (parameters[i].ParameterType.Equals(typeof(MobileParam)))
                    {
                        moibleParameterIndex = i;
                        break;
                    }
                }

                if (moibleParameterIndex != -1)
                {
                    var moibleParam = invocation.Arguments[moibleParameterIndex] as MobileParam;
                    if (moibleParam != null)
                    {
                        var redis = default(IRedisService);
                        if (invocation.InvocationTarget.GetType().Equals(typeof(OTAService)))
                        {
                            redis = ObjectFactory.GetInstance<IOTARedisService>();
                        }
                        else
                        {
                            redis = ObjectFactory.GetInstance<IRedisService>();
                        }

                        if (redis.IsExistInHash("WhiteList", string.IsNullOrEmpty(moibleParam.IMEI) ? string.Empty : moibleParam.IMEI)
                               || redis.IsExistInHash("WhiteList", string.IsNullOrEmpty(moibleParam.IMSI) ? string.Empty : moibleParam.IMSI))
                        {
                            invocation.Proceed();
                            return;
                        }
                    }
                }
            }
            #endregion

            var cacheKey = GetCacheKey(invocation);
            var redisCacheHepler = ObjectFactory.GetInstance<ICacheManagerHelper>();

            if (redisCacheHepler.Contains(cacheKey))
            {
                invocation.ReturnValue = redisCacheHepler.GetNullableData(cacheKey, invocation.Method.ReturnType);

                if (invocation.Method.ReturnType.Equals(typeof(OTAUpdateInfoView)))
                {
                    var otaUpdateInfoView = invocation.ReturnValue as OTAUpdateInfoView;
                    Random OTARandom = new Random();
                    otaUpdateInfoView.NextCheckTime = otaUpdateInfoView.NextCheckTime.AddMilliseconds(OTARandom.Next(86400000));
                    invocation.ReturnValue = otaUpdateInfoView;
                }

                for (int i = 0; i < parameters.Length; i++)
                {
                    if (parameters[i].ParameterType.IsByRef)
                    {
                        object argVal = redisCacheHepler.GetData(cacheKey + parameters[i].Name, parameters[i].ParameterType.GetElementType());
                        invocation.SetArgumentValue(i, argVal);
                    }
                }
            }
            else
            {
                invocation.Proceed();

                redisCacheHepler.AddNullableData(cacheKey, invocation.ReturnValue, svcCacheAttribute.TimeoutSecs);

                for (int i = 0; i < parameters.Length; i++)
                {
                    if (parameters[i].ParameterType.IsByRef && invocation.Arguments[i] != null)
                    {
                        redisCacheHepler.Add(cacheKey + parameters[i].Name, invocation.Arguments[i], svcCacheAttribute.TimeoutSecs);
                    }
                }
            }
        }
开发者ID:itabas016,项目名称:AppStores,代码行数:92,代码来源:ServiceCacheInterceptor.cs

示例8: Intercept

        public void Intercept(IInvocation invocation)
        {
            var objectKey = new RedisKeyObject(invocation.InvocationTarget.GetType(), _commonData.Id);

            if (invocation.Arguments[0] is IRedisObject)
            {
                var redisObject = (IRedisObject) invocation.Arguments[0];

                // Get or create the new key for the new RedisObject
                var key = new RedisKeyObject(redisObject.GetType(), string.Empty);
                _commonData.RedisDatabase.GenerateId(key, redisObject, _commonData.RedisObjectManager.RedisBackup);

                if (!(invocation.Arguments[0] is IProxyTargetAccessor))
                {
                    // Need to make it into a proxy, so it can be saved
                    var proxy = _commonData.RedisObjectManager.RetrieveObjectProxy(redisObject.GetType(), key.Id,
                        _commonData.RedisDatabase, redisObject);
                    invocation.SetArgumentValue(0, proxy);
                    redisObject = proxy as IRedisObject;
                }

                // Check to see if there is an ID set in the database (if not it has never been saved)

                if (!_commonData.Processed)
                {
                    if (_commonData.RedisDatabase.KeyExists(key.RedisKey))
                    {
                        invocation.Proceed();
                        return;
                    }
                }

                var property =
                    invocation.Method.ReflectedType?.GetProperties()
                        .SingleOrDefault(x => x.SetMethod != null && x.SetMethod.Name == invocation.Method.Name);

                if (property != null)
                {
                    bool deleteCascade = true;
                    // Need to check if the item is currently set (ie are we replacing a value)
                    if (property.HasAttribute<RedisDeleteCascade>())
                    {
                        deleteCascade = property.GetAttribute<RedisDeleteCascade>().Cascade;
                    }

                    if (deleteCascade)
                    {
                        object currentValue = property.GetValue(invocation.Proxy);
                        if (currentValue is IRedisObject)
                        {
                            RedisKeyObject originalKey = new RedisKeyObject(currentValue.GetType(), string.Empty);
                            _commonData.RedisDatabase.GenerateId(originalKey, currentValue, _commonData.RedisObjectManager.RedisBackup);

                            if (originalKey != key)
                            {
                                ((IRedisObject)currentValue).DeleteRedisObject();
                            }
                        }
                    }
                    // Need to check is there is a RedisDeleteCascade on property
                    _commonData.RedisObjectManager.RedisBackup?.UpdateHashValue(new HashEntry(property.Name, key.RedisKey), objectKey);

                    _commonData.RedisDatabase.HashSet(objectKey.RedisKey, property.Name, key.RedisKey);
                    _commonData.RedisObjectManager.SaveObject(redisObject, key.Id, _commonData.RedisDatabase);
                }
            }
            else
            {
                if (!_commonData.Processed)
                {
                    if (!_commonData.Processing)
                    {
                        //invocation.Proceed();
                        //return;

                        _commonData.Processing = true;
                        // Process the proxy (do a retrieveObject)
                        _commonData.RedisObjectManager.RetrieveObject(invocation.Proxy, _commonData.Id, _commonData.RedisDatabase, null);
                        _commonData.Processed = true;
                        _commonData.Processing = false;
                    }
                }
                // Set the individual item
                var property =
                        invocation.Method.ReflectedType?.GetProperties()
                            .SingleOrDefault(x => x.SetMethod.Name == invocation.Method.Name);

                ITypeConverter converter;
                if (property != null && _commonData.RedisObjectManager.TypeConverters.TryGetValue(property.PropertyType, out converter))
                {
                    var ret = new HashEntry(property.Name, converter.ToWrite(invocation.Arguments[0]));

                    //Need to check if the value already stored is different

                    _commonData.RedisObjectManager.RedisBackup?.RestoreHash(_commonData.RedisDatabase, objectKey);

                    if (_commonData.RedisDatabase.HashGet(objectKey.RedisKey, ret.Name) != ret.Value)
                    {
                        _commonData.RedisObjectManager.RedisBackup?.UpdateHashValue(ret, objectKey);
                        _commonData.RedisDatabase.HashSet(objectKey.RedisKey, ret.Name, ret.Value);
//.........这里部分代码省略.........
开发者ID:DemgelOpenSource,项目名称:DemgelRedis,代码行数:101,代码来源:RedisObjectSetInterceptor.cs


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