string BuildCacheKey(CacheMeta cacheMeta, IParameterCollection inputs)
        {
            StringBuilder cacheKeyBuilder = new StringBuilder();

            cacheKeyBuilder.Append(cacheMeta.Name);

            for (int i = 0; i < inputs.Count; i++)
            {
                ParameterInfo  parameterInfo = inputs.GetParameterInfo(0);
                PropertyInfo[] propertyInfos = cacheMeta.GetCacheKey(parameterInfo);

                if (propertyInfos != null)
                {
                    if (propertyInfos.Length == 0)
                    {
                        cacheKeyBuilder.Append(";");
                        cacheKeyBuilder.Append(parameterInfo.Name).Append("=").Append(inputs[i]);
                    }
                    else
                    {
                        foreach (PropertyInfo propertyInfo in propertyInfos)
                        {
                            cacheKeyBuilder.Append(";");
                            cacheKeyBuilder.Append(propertyInfo.Name).Append("=").Append(propertyInfo.GetValue(
                                                                                             inputs[i], null));
                        }
                    }
                }
            }

            return(cacheKeyBuilder.ToString().Replace(" ", "").ToUpper());
        }
Esempio n. 2
0
        string CreateCacheKey(MethodBase methodBase, IParameterCollection inputs)
        {
            StringBuilder cacheKey = new StringBuilder();

            CacheAttribute[] cacheAttrs = (CacheAttribute[])methodBase.GetCustomAttributes(typeof(CacheAttribute), false);
            cacheKey.Append(cacheAttrs[0].Name);
            int index = 0;

            for (int i = 0; i < inputs.Count; i++)
            {
                ParameterInfo       parameterInfo = inputs.GetParameterInfo(i);
                CacheKeyAttribute[] attributes    = (CacheKeyAttribute[])parameterInfo.GetCustomAttributes(typeof(CacheKeyAttribute), false);
                if (attributes != null && attributes.Length > 0)
                {
                    if (index > 0)
                    {
                        cacheKey.Append(";");
                    }
                    else
                    {
                        cacheKey.Append("[");
                    }
                    if (parameterInfo.ParameterType.IsPrimitive || parameterInfo.ParameterType == typeof(Type))
                    {
                        cacheKey.Append(parameterInfo.Name).Append("=").Append(inputs[i]);
                        index++;
                    }
                    else
                    {
                        PropertyInfo[] properties = cacheMetaLoader.FindCacheKeyProperties(parameterInfo.ParameterType);
                        if (properties.Length == 0)
                        {
                            cacheKey.Append(parameterInfo.Name).Append("=").Append(inputs[i]);
                            index++;
                        }
                        else
                        {
                            foreach (PropertyInfo propertyInfo in properties)
                            {
                                if (index > 0)
                                {
                                    cacheKey.Append(";");
                                }
                                cacheKey.Append(propertyInfo.Name).Append("=").Append(
                                    propertyInfo.GetValue(inputs[i], null));
                                index++;
                            }
                        }
                    }
                }
            }
            if (index > 0)
            {
                cacheKey.Append("]");
            }

            return(cacheKey.ToString().Replace(" ", "").ToUpper());
        }
Esempio n. 3
0
        private static IEnumerable <ResolverOverride> GetDependencyOverrides(IParameterCollection arguments)
        {
            for (var parameterIndex = 0; parameterIndex < arguments.Count; ++parameterIndex)
            {
                var parameterInfo  = arguments.GetParameterInfo(parameterIndex);
                var parameterValue = arguments[parameterIndex];

                yield return(new DependencyOverride(parameterInfo.ParameterType, new InjectionParameter(parameterInfo.ParameterType, parameterValue)));
            }
        }
        /// <summary>
        /// Parses the parameter.
        /// </summary>
        /// <param name="inputParameterCollection">The input parameter collection.</param>
        /// <param name="parameterInfos">The parameter infos.</param>
        private void ParseParameter(IParameterCollection inputParameterCollection, ref IList <ParameterInfo> parameterInfos)
        {
            for (int i = 0; i < inputParameterCollection.Count; i++)
            {
                ParameterInfo tempParameterInfo = inputParameterCollection.GetParameterInfo(i);

                if (tempParameterInfo == null)
                {
                    continue;
                }

                parameterInfos.Add(tempParameterInfo);
            }
        }
Esempio n. 5
0
 object GetCacheValue(IParameterCollection inputs)
 {
     for (int i = 0; i < inputs.Count; i++)
     {
         ParameterInfo         parameterInfo = inputs.GetParameterInfo(i);
         CacheValueAttribute[] attributes    =
             (CacheValueAttribute[])parameterInfo.GetCustomAttributes(typeof(CacheValueAttribute), false);
         if (attributes != null && attributes.Length > 0)
         {
             return(inputs[i]);
         }
     }
     return(null);
 }
Esempio n. 6
0
        private IEnumerable <object> GetArguments()
        {
            IParameterCollection arguments = _input.Arguments;

            for (int i = 0; i < arguments.Count; i++)
            {
                string value = IgnoreArgumentValue(arguments.GetParameterInfo(i)) ? "[hidden]" : arguments[i].ToString();
                yield return(new
                {
                    Name = arguments.ParameterName(i),
                    Value = value
                });
            }
        }
Esempio n. 7
0
        public static IEnumerable <object> PeakArguments(this IParameterCollection parameters, Predicate <ParameterInfo> filter)
        {
            var inputArguments = new List <object>();

            for (int i = 0; i < parameters.Count; i++)
            {
                var info = parameters.GetParameterInfo(i);
                if (filter(info))
                {
                    inputArguments.Add(parameters[i]);
                }
            }
            return(inputArguments);
        }
        object GetCacheValue(IParameterCollection inputs)
        {
            for (int i = 0; i < inputs.Count; i++)
            {
                ParameterInfo         parameterInfo        = inputs.GetParameterInfo(i);
                CacheValueAttribute[] cacheValueAttributes = parameterInfo.ParameterType.GetCustomAttributes(typeof(CacheValueAttribute), false) as CacheValueAttribute[];
                if (cacheValueAttributes == null || cacheValueAttributes.Length <= 0)
                {
                    continue;
                }
                return(inputs[i]);
            }

            return(null);
        }
Esempio n. 9
0
        private static string PrintInputParameters(IParameterCollection parameters)
        {
            if (0 == parameters.Count)
            {
                return " without parameters ";
            }

            var parameterString = new StringBuilder();
            parameterString.Append("(");
            for (int i = 0; i < parameters.Count; i++)
            {
                ParameterInfo parameter = parameters.GetParameterInfo(i);

                parameterString.Append(parameter.Name + " = " + parameters[i]);
            }
            parameterString.Append(")");
            return parameterString.ToString();
        }
Esempio n. 10
0
        private static string PrintInputParameters(IParameterCollection parameters)
        {
            if (0 == parameters.Count)
            {
                return(" without parameters ");
            }

            var parameterString = new StringBuilder();

            parameterString.Append("(");
            for (int i = 0; i < parameters.Count; i++)
            {
                ParameterInfo parameter = parameters.GetParameterInfo(i);

                parameterString.Append(parameter.Name + " = " + parameters[i]);
            }
            parameterString.Append(")");
            return(parameterString.ToString());
        }
        private string GenerateValuesInfo(IParameterCollection arguments, bool isParameter)
        {
            StringBuilder builder = new StringBuilder();

            switch (arguments.Count)
            {
                case 0:
                    builder.AppendLine(string.Format("No {0} in the method.",isParameter?"parameter":"output"));
                    break;
                case 1:
                    builder.AppendLine(string.Format("There is 1 {0} in the method: ",isParameter?"parameter":"output"));
                    break;
                default:
                    builder.AppendLine("There are " + arguments.Count + string.Format(" {0} in the method: ", isParameter ? "parameters" : "outputs"));
                    break;
            }

            for (int i = 0; i < arguments.Count; ++i)
            {
                ParameterInfo paramter = arguments.GetParameterInfo(i);

                int depth = 0;
                builder.AppendLine(GenerateValueInfo(paramter.Name, arguments[i], paramter.ParameterType,ref depth));
            }

            return builder.ToString();
        }
Esempio n. 12
0
 public static IEnumerable <IActionParameter> ToActionParameters(this IParameterCollection @this)
 {
     return(Enumerable.Range(0, @this.Count).Select(x => new ActionParameter(x, @this.GetParameterInfo(x), @this[x])));
 }