Ejemplo n.º 1
0
            public override string GetTriggerReason(IDictionary <string, string> arguments)
            {
                string invokeString = null;

                if (arguments != null && arguments.TryGetValue(Name, out invokeString))
                {
                    HttpRequestMessage request = WebHookTriggerBinding.FromInvokeString(invokeString);
                    return(string.Format("WebHook triggered by request to '{0}'", request.RequestUri));
                }
                return(null);
            }
Ejemplo n.º 2
0
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ParameterInfo           parameter = context.Parameter;
            WebHookTriggerAttribute attribute = parameter.GetCustomAttribute <WebHookTriggerAttribute>(inherit: false);

            if (attribute == null)
            {
                return(Task.FromResult <ITriggerBinding>(null));
            }

            // Can bind to user types, HttpRequestMessage, WebHookContext, and all the Read
            // Types supported by StreamValueBinder
            IEnumerable <Type> supportedTypes = StreamValueBinder.GetSupportedTypes(FileAccess.Read)
                                                .Union(new Type[] { typeof(HttpRequestMessage), typeof(WebHookContext) });
            bool isSupportedTypeBinding = ValueBinder.MatchParameterType(parameter, supportedTypes);
            bool isUserTypeBinding      = !isSupportedTypeBinding && WebHookTriggerBinding.IsValidUserType(parameter.ParameterType);

            if (!isSupportedTypeBinding && !isUserTypeBinding)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  "Can't bind WebHookTriggerAttribute to type '{0}'.", parameter.ParameterType));
            }

            if (!isUserTypeBinding && attribute.FromUri)
            {
                throw new InvalidOperationException("'FromUri' can only be set to True when binding to custom Types.");
            }

            // Validate route format
            if (!string.IsNullOrEmpty(attribute.Route))
            {
                string[] routeSegements = attribute.Route.Split('/');
                if (routeSegements.Length > 2)
                {
                    throw new InvalidOperationException("WebHook routes can only have a maximum of two segments.");
                }
            }

            return(Task.FromResult <ITriggerBinding>(new WebHookTriggerBinding(_dispatcher, context.Parameter, isUserTypeBinding, attribute)));
        }