예제 #1
0
        protected ParameterDescriptor ParseTimerTrigger(TimerBindingMetadata trigger, Type triggerParameterType = null)
        {
            if (trigger == null)
            {
                throw new ArgumentNullException("trigger");
            }

            if (triggerParameterType == null)
            {
                triggerParameterType = typeof(string);
            }

            ConstructorInfo ctorInfo     = typeof(TimerTriggerAttribute).GetConstructor(new Type[] { typeof(string) });
            string          schedule     = trigger.Schedule;
            bool            runOnStartup = trigger.RunOnStartup;

            PropertyInfo           runOnStartupProperty = typeof(TimerTriggerAttribute).GetProperty("RunOnStartup");
            CustomAttributeBuilder attributeBuilder     = new CustomAttributeBuilder(ctorInfo,
                                                                                     new object[] { schedule },
                                                                                     new PropertyInfo[] { runOnStartupProperty },
                                                                                     new object[] { runOnStartup });

            string parameterName = trigger.Name;
            var    attributes    = new Collection <CustomAttributeBuilder>
            {
                attributeBuilder
            };

            return(new ParameterDescriptor(parameterName, triggerParameterType, attributes));
        }
        public void GenerateTimerTriggerFunction()
        {
            TimerBindingMetadata trigger = new TimerBindingMetadata
            {
                Type = BindingType.TimerTrigger,
                Schedule = "* * * * * *",
                RunOnStartup = true
            };
            MethodInfo method = GenerateMethod(trigger);

            VerifyCommonProperties(method);

            // verify trigger parameter
            ParameterInfo parameter = method.GetParameters()[0];
            Assert.Equal("input", parameter.Name);
            Assert.Equal(typeof(TimerInfo), parameter.ParameterType);
            TimerTriggerAttribute attribute = parameter.GetCustomAttribute<TimerTriggerAttribute>();
            Assert.Equal("* * * * * *", attribute.ScheduleExpression);
            Assert.True(attribute.RunOnStartup);
        }
        protected ParameterDescriptor ParseTimerTrigger(TimerBindingMetadata trigger, Type triggerParameterType = null)
        {
            if (triggerParameterType == null)
            {
                triggerParameterType = typeof(string);
            }

            ConstructorInfo ctorInfo = typeof(TimerTriggerAttribute).GetConstructor(new Type[] { typeof(string) });
            string schedule = trigger.Schedule;
            bool runOnStartup = trigger.RunOnStartup;

            PropertyInfo runOnStartupProperty = typeof(TimerTriggerAttribute).GetProperty("RunOnStartup");
            CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(ctorInfo,
                new object[] { schedule },
                new PropertyInfo[] { runOnStartupProperty },
                new object[] { runOnStartup });

            string parameterName = trigger.Name;
            var attributes = new Collection<CustomAttributeBuilder>
            {
                attributeBuilder
            };
            return new ParameterDescriptor(parameterName, triggerParameterType, attributes);
        }