private Dictionary <string, object> CreateScriptExecutionContext(object input, TraceWriter traceWriter, TraceWriter fileTraceWriter, IBinder binder, ExecutionContext functionExecutionContext)
        {
            // create a TraceWriter wrapper that can be exposed to Node.js
            var log = (Func <object, Task <object> >)((text) =>
            {
                traceWriter.Verbose((string)text);
                fileTraceWriter.Verbose((string)text);
                return(Task.FromResult <object>(null));
            });

            var context = new Dictionary <string, object>()
            {
                { "invocationId", functionExecutionContext.InvocationId },
                { "log", log }
            };

            Type triggerParameterType = input.GetType();

            if (triggerParameterType == typeof(string))
            {
                // if the input is json, convert to a json object
                Dictionary <string, object> jsonObject;
                if (TryDeserializeJsonObject((string)input, out jsonObject))
                {
                    input = jsonObject;
                }
            }
            else if (triggerParameterType == typeof(HttpRequestMessage))
            {
                // convert the request to a json object
                HttpRequestMessage request = (HttpRequestMessage)input;
                var requestObject          = CreateRequestObject(request);
                input = requestObject;

                // If this is a WebHook function, the input should be the
                // request body
                HttpBindingMetadata httpBinding = _trigger as HttpBindingMetadata;
                if (httpBinding != null &&
                    !string.IsNullOrEmpty(httpBinding.WebHookType))
                {
                    input = requestObject["body"];

                    // make the entire request object available as well
                    context["req"] = requestObject;
                }
            }

            if (!_omitInputParameter)
            {
                context["input"] = input;
            }

            return(context);
        }
        public void GenerateHttpTriggerFunction()
        {
            HttpBindingMetadata trigger = new HttpBindingMetadata
            {
                Type = BindingType.HttpTrigger
            };
            MethodInfo method = GenerateMethod(trigger);

            VerifyCommonProperties(method);

            // verify trigger parameter
            ParameterInfo parameter = method.GetParameters()[0];
            Assert.Equal("req", parameter.Name);
            Assert.Equal(typeof(HttpRequestMessage), parameter.ParameterType);
            NoAutomaticTriggerAttribute attribute = method.GetCustomAttribute<NoAutomaticTriggerAttribute>();
            Assert.NotNull(attribute);
        }
Пример #3
0
        protected ParameterDescriptor ParseHttpTrigger(HttpBindingMetadata trigger, Collection <CustomAttributeBuilder> methodAttributes, Type triggerParameterType = null)
        {
            if (triggerParameterType == null)
            {
                triggerParameterType = typeof(string);
            }

            ConstructorInfo        ctorInfo         = typeof(NoAutomaticTriggerAttribute).GetConstructor(new Type[0]);
            CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(ctorInfo, new object[0]);

            methodAttributes.Add(attributeBuilder);

            ctorInfo         = typeof(TraceLevelAttribute).GetConstructor(new Type[] { typeof(TraceLevel) });
            attributeBuilder = new CustomAttributeBuilder(ctorInfo, new object[] { TraceLevel.Off });
            methodAttributes.Add(attributeBuilder);

            string parameterName = trigger.Name;

            return(new ParameterDescriptor(parameterName, triggerParameterType));
        }
        protected ParameterDescriptor ParseHttpTrigger(HttpBindingMetadata trigger, Collection<CustomAttributeBuilder> methodAttributes, Type triggerParameterType = null)
        {
            if (triggerParameterType == null)
            {
                triggerParameterType = typeof(string);
            }

            ConstructorInfo ctorInfo = typeof(NoAutomaticTriggerAttribute).GetConstructor(new Type[0]);
            CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(ctorInfo, new object[0]);
            methodAttributes.Add(attributeBuilder);

            ctorInfo = typeof(TraceLevelAttribute).GetConstructor(new Type[] { typeof(TraceLevel) });
            attributeBuilder = new CustomAttributeBuilder(ctorInfo, new object[] { TraceLevel.Off });
            methodAttributes.Add(attributeBuilder);

            string parameterName = trigger.Name;
            return new ParameterDescriptor(parameterName, triggerParameterType);
        }