Beispiel #1
0
        private static FunctionDescriptor CreateFunctionDescriptor(MethodInfo method, string triggerParameterName,
                                                                   ITriggerBinding triggerBinding, IReadOnlyDictionary <string, IBinding> nonTriggerBindings)
        {
            List <ParameterDescriptor> parameters = new List <ParameterDescriptor>();

            foreach (ParameterInfo parameter in method.GetParameters())
            {
                string name = parameter.Name;

                if (name == triggerParameterName)
                {
                    parameters.Add(triggerBinding.ToParameterDescriptor());
                }
                else
                {
                    parameters.Add(nonTriggerBindings[name].ToParameterDescriptor());
                }
            }

            // Determine the TraceLevel for this function (affecting both Console as well as Dashboard logging)
            TraceLevelAttribute traceAttribute = TypeUtility.GetHierarchicalAttributeOrNull <TraceLevelAttribute>(method);

            return(new FunctionDescriptor
            {
                Id = method.GetFullName(),
                Method = method,
                FullName = method.GetFullName(),
                ShortName = method.GetShortName(),
                Parameters = parameters,
                TraceLevel = traceAttribute?.Level ?? TraceLevel.Verbose,
                TriggerParameterDescriptor = parameters.OfType <TriggerParameterDescriptor>().FirstOrDefault(),
                TimeoutAttribute = TypeUtility.GetHierarchicalAttributeOrNull <TimeoutAttribute>(method),
                SingletonAttributes = method.GetCustomAttributes <SingletonAttribute>()
            });
        }
        internal static TraceLevel GetFunctionTraceLevel(IFunctionInstance functionInstance)
        {
            TraceLevel functionTraceLevel = TraceLevel.Verbose;

            // Determine the TraceLevel for this function (affecting both Console as well as Dashboard logging)
            TraceLevelAttribute attribute = TypeUtility.GetHierarchicalAttributeOrNull <TraceLevelAttribute>(functionInstance.FunctionDescriptor.Method);

            if (attribute != null)
            {
                functionTraceLevel = attribute.Level;
            }

            return(functionTraceLevel);
        }
Beispiel #3
0
        // Expose internally for testing purposes
        internal static FunctionDescriptor FromMethod(
            MethodInfo method,
            IJobActivator jobActivator = null,
            INameResolver nameResolver = null)
        {
            var disabled = HostListenerFactory.IsDisabled(method, nameResolver, jobActivator);

            // Determine the TraceLevel for this function (affecting both Console as well as Dashboard logging)
            TraceLevelAttribute traceAttribute = TypeUtility.GetHierarchicalAttributeOrNull <TraceLevelAttribute>(method);

            bool hasCancellationToken = method.GetParameters().Any(p => p.ParameterType == typeof(CancellationToken));

            string logName   = method.Name;
            string shortName = method.GetShortName();
            FunctionNameAttribute nameAttribute = method.GetCustomAttribute <FunctionNameAttribute>();

            if (nameAttribute != null)
            {
                logName   = nameAttribute.Name;
                shortName = logName;
                if (!FunctionNameAttribute.FunctionNameValidationRegex.IsMatch(logName))
                {
                    throw new InvalidOperationException(string.Format("'{0}' is not a valid function name.", logName));
                }
            }

            return(new FunctionDescriptor
            {
                Id = method.GetFullName(),
                LogName = logName,
                FullName = method.GetFullName(),
                ShortName = shortName,
                IsDisabled = disabled,
                HasCancellationToken = hasCancellationToken,
                TraceLevel = traceAttribute?.Level ?? TraceLevel.Verbose,
                TimeoutAttribute = TypeUtility.GetHierarchicalAttributeOrNull <TimeoutAttribute>(method),
                SingletonAttributes = method.GetCustomAttributes <SingletonAttribute>(),
                MethodLevelFilters = method.GetCustomAttributes().OfType <IFunctionFilter>(),
                ClassLevelFilters = method.DeclaringType.GetCustomAttributes().OfType <IFunctionFilter>()
            });
        }