public async Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            ParameterInfo parameter            = context.Parameter;
            var           blobTriggerAttribute = TypeUtility.GetResolvedAttribute <BlobTriggerAttribute>(context.Parameter);

            if (blobTriggerAttribute == null)
            {
                return(null);
            }

            string          resolvedCombinedPath = Resolve(blobTriggerAttribute.BlobPath);
            IBlobPathSource path = BlobPathSource.Create(resolvedCombinedPath);

            IStorageAccount hostAccount = await _accountProvider.GetStorageAccountAsync(context.CancellationToken);

            IStorageAccount dataAccount = await _accountProvider.GetStorageAccountAsync(blobTriggerAttribute, context.CancellationToken, _nameResolver);

            // premium does not support blob logs, so disallow for blob triggers
            dataAccount.AssertTypeOneOf(StorageAccountType.GeneralPurpose, StorageAccountType.BlobOnly);

            ITriggerBinding binding = new BlobTriggerBinding(parameter, hostAccount, dataAccount, path,
                                                             _hostIdProvider, _queueConfiguration, _blobsConfiguration, _exceptionHandler, _blobWrittenWatcherSetter,
                                                             _messageEnqueuedWatcherSetter, _sharedContextProvider, _singletonManager, _loggerFactory);

            return(binding);
        }
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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

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

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

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

            return(Task.FromResult <ITriggerBinding>(new HttpTriggerBinding(attribute, context.Parameter, isUserTypeBinding, _responseHook)));
        }
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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

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

            string eventHubName      = attribute.EventHubName;
            string resolvedName      = _nameResolver.ResolveWholeString(eventHubName);
            var    eventHostListener = _eventHubConfig.GetEventProcessorHost(resolvedName);

            var options = _eventHubConfig.GetOptions();
            var hooks   = new EventHubTriggerBindingStrategy();

            Func <ListenerFactoryContext, bool, Task <IListener> > createListener =
                (factoryContext, singleDispatch) =>
            {
                IListener listener = new EventHubListener(factoryContext.Executor, eventHostListener, options, singleDispatch);
                return(Task.FromResult(listener));
            };

            ITriggerBinding binding = BindingFactory.GetTriggerBinding <EventData, EventHubTriggerInput>(hooks, parameter, _converterManager, createListener);

            return(Task.FromResult <ITriggerBinding>(binding));
        }
예제 #4
0
        /// <summary>
        /// Create the <see cref="ITriggerBinding"/> (being the <see cref="ResilientEventHubBinding"/>).
        /// </summary>
        /// <param name="context">The <see cref="TriggerBindingProviderContext"/>.</param>
        /// <returns></returns>
        public Task <ITriggerBinding?> TryCreateAsync(TriggerBindingProviderContext context)
        {
            // Get the required attribuite.
            var att = context.Parameter.GetCustomAttribute <ResilientEventHubTriggerAttribute>(false);

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

            // Resolve the attribute parameters.
            var resolvedEventHubName  = _nameResolver.ResolveWholeString(att.EventHubName);
            var resolvedConsumerGroup = _nameResolver.ResolveWholeString(att.ConsumerGroup ?? PartitionReceiver.DefaultConsumerGroupName);

            if (!string.IsNullOrWhiteSpace(att.Connection))
            {
                var connectionString = _config.GetConnectionStringOrSetting(_nameResolver.ResolveWholeString(att.Connection));
                _options.Value.AddEventHub(resolvedEventHubName, connectionString);
            }

            // Capture the name of the function being executed.
            _options.Value.FunctionName = context.Parameter.Member.GetCustomAttribute <FunctionNameAttribute>().Name;
            _options.Value.FunctionType = context.Parameter.Member.DeclaringType.FullName + "." + context.Parameter.Member.Name;

            // Create the event hub processor.
            var host = _options.Value.GetEventProcessorHost(_config, resolvedEventHubName, resolvedConsumerGroup);

            // Create and return the binding.
            return(Task.FromResult <ITriggerBinding?>(new ResilientEventHubBinding(host, context.Parameter, _options.Value, _config, _logger)));
        }
예제 #5
0
        /// <inheritdoc/>
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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

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

            // next, verify that the type is one of the types we support
            IEnumerable <Type> types = StreamValueBinder.GetSupportedTypes(FileAccess.Read)
                                       .Union(new Type[] { typeof(FileStream), typeof(FileSystemEventArgs), typeof(FileInfo) });

            if (!ValueBinder.MatchParameterType(context.Parameter, types))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  "Can't bind FileTriggerAttribute to type '{0}'.", parameter.ParameterType));
            }

            return(Task.FromResult <ITriggerBinding>(new FileTriggerBinding(_config, parameter, _logger)));
        }
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var parameter = context.Parameter;
            var attribute = parameter.GetCustomAttribute <MqttTriggerAttribute>(inherit: false);

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

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

            var binding = new MqttTriggerBinding(
                context.Parameter,
                _config,
                attribute.TopicName);

            return(Task.FromResult <ITriggerBinding>(binding));
        }
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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

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

            // Can bind to user types, and all the Read Types supported by StreamValueBinder
            IEnumerable <Type> supportedTypes = StreamValueBinder.GetSupportedTypes(FileAccess.Read);
            bool isSupportedTypeBinding       = ValueBinder.MatchParameterType(parameter, supportedTypes);
            bool isUserTypeBinding            = !isSupportedTypeBinding && Utility.IsValidUserType(parameter.ParameterType);

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

            return(Task.FromResult <ITriggerBinding>(new ManualTriggerBinding(context.Parameter, isUserTypeBinding)));
        }
예제 #8
0
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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

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

            if (parameter.ParameterType != typeof(TraceFilter) &&
                parameter.ParameterType != typeof(TraceEvent) &&
                parameter.ParameterType != typeof(IEnumerable <TraceEvent>))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  "Can't bind ErrorTriggerAttribute to type '{0}'.", parameter.ParameterType));
            }

            return(Task.FromResult <ITriggerBinding>(new ErrorTriggerBinding(_config, context.Parameter)));
        }
예제 #9
0
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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

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

            // TODO: Define the types your binding supports here
            if (parameter.ParameterType != typeof(SampleTriggerValue) &&
                parameter.ParameterType != typeof(string))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  "Can't bind SampleTriggerAttribute to type '{0}'.", parameter.ParameterType));
            }

            return(Task.FromResult <ITriggerBinding>(new SampleTriggerBinding(context.Parameter)));
        }
예제 #10
0
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            ParameterInfo parameter = context.Parameter;
            OrchestrationTriggerAttribute trigger = parameter.GetCustomAttribute <OrchestrationTriggerAttribute>(inherit: false);

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

            // The orchestration name defaults to the method name.
            string orchestrationName = trigger.Orchestration ?? parameter.Member.Name;

            // TODO: Support for per-function connection string and task hub names
            var binding = new OrchestrationTriggerBinding(
                this.config,
                parameter,
                orchestrationName,
                trigger.Version);

            return(Task.FromResult <ITriggerBinding>(binding));
        }
        public async Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            ParameterInfo         parameter    = context.Parameter;
            QueueTriggerAttribute queueTrigger = parameter.GetCustomAttribute <QueueTriggerAttribute>(inherit: false);

            if (queueTrigger == null)
            {
                return(null);
            }

            string queueName = Resolve(queueTrigger.QueueName);

            queueName = NormalizeAndValidate(queueName);

            ITriggerDataArgumentBinding <IStorageQueueMessage> argumentBinding = _innerProvider.TryCreate(parameter);

            if (argumentBinding == null)
            {
                throw new InvalidOperationException(
                          "Can't bind QueueTrigger to type '" + parameter.ParameterType + "'.");
            }

            IStorageAccount account = await _accountProvider.GetStorageAccountAsync(context.CancellationToken);

            IStorageQueueClient client = account.CreateQueueClient();
            IStorageQueue       queue  = client.GetQueueReference(queueName);

            ITriggerBinding binding = new QueueTriggerBinding(parameter.Name, queue, argumentBinding,
                                                              _queueConfiguration, _backgroundExceptionDispatcher, _messageEnqueuedWatcherSetter,
                                                              _sharedContextProvider, _log);

            return(binding);
        }
예제 #12
0
        /// <summary>
        /// Creates a SqlTriggerBinding using the information provided in "context"
        /// </summary>
        /// <param name="context">
        /// Contains the SqlTriggerAttribute used to build up a SqlTriggerBinding
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if context is null
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// If the SqlTriggerAttribute is bound to an invalid Type. Currently only IEnumerable<SqlChangeTrackingEntry<T>>
        /// is supported, where T is a user-defined POCO representing a row of their table
        /// </exception>
        /// <returns>
        /// Null if "context" does not contain a SqlTriggerAttribute. Otherwise returns a SqlTriggerBinding{T} associated
        /// with the SqlTriggerAttribute in "context", where T is the user-defined POCO
        /// </returns>
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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

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

            if (!IsValidType(parameter.ParameterType))
            {
                throw new InvalidOperationException($"Can't bind SqlTriggerAttribute to type {parameter.ParameterType}. Only IEnumerable<SqlChangeTrackingEntry<T>>" +
                                                    $" is supported, where T is a user-defined POCO that matches the schema of the tracked table");
            }

            Type            type = parameter.ParameterType.GetGenericArguments()[0].GetGenericArguments()[0];
            Type            typeOfTriggerBinding = typeof(SqlTriggerBinding <>).MakeGenericType(type);
            ConstructorInfo constructor          = typeOfTriggerBinding.GetConstructor(new Type[] { typeof(string), typeof(string), typeof(ParameterInfo), typeof(ILogger) });

            return(Task.FromResult <ITriggerBinding>((ITriggerBinding)constructor.Invoke(new object[] { attribute.TableName,
                                                                                                        SqlBindingUtilities.GetConnectionString(attribute.ConnectionStringSetting, _configuration), parameter, _logger })));
        }
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var parameterInfo = context.Parameter;
            var attribute     = parameterInfo.GetCustomAttribute <SignalRTriggerAttribute>(false);

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

            if (_webhookException != null)
            {
                throw new NotSupportedException($"SignalR trigger is disabled due to 'AzureWebJobsStorage' connection string is not set or invalid. {_webhookException}");
            }

            var resolvedAttribute = GetParameterResolvedAttribute(attribute, parameterInfo);

            ValidateSignalRTriggerAttributeBinding(resolvedAttribute);

            return(Task.FromResult <ITriggerBinding>(new SignalRTriggerBinding(parameterInfo, resolvedAttribute, _dispatcher)));
        }
예제 #14
0
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            ParameterInfo parameter = context.Parameter;

            EthTriggerAttribute triggerAttribute = parameter.GetCustomAttribute <EthTriggerAttribute>(inherit: false);

            if (triggerAttribute is null)
            {
                return(_nullTriggerBindingTask);
            }

            var contractABI     = _configuration.GetSection(triggerAttribute.ABI).Value;
            var contractAddress = _configuration.GetSection(triggerAttribute.Address).Value;
            var networkUrl      = _configuration.GetSection(triggerAttribute.NetworkUrl).Value;

            Web3 web3 = new Nethereum.Web3.Web3(networkUrl);

            Contract contract = web3.Eth.GetContract(contractABI, contractAddress);

            var filterClass = (IEventFilter)Activator.CreateInstance(Type.GetType(triggerAttribute.TypeName));

            return(Task.FromResult <ITriggerBinding>(
                       new EthTriggerBinding(parameter, web3, contract, filterClass.Filter)
                       ));
        }
예제 #15
0
        public async Task GetServiceBusOptions_AutoCompleteDisabledOnTrigger()
        {
            var listenerContext = new ListenerFactoryContext(
                new Mock <FunctionDescriptor>().Object,
                new Mock <ITriggeredFunctionExecutor>().Object,
                CancellationToken.None);
            var parameters = new object[] { listenerContext };
            var entityPath = "autocomplete";

            var _mockMessageProcessor = new Mock <MessageProcessor>(MockBehavior.Strict, new MessageReceiver(_connectionString, entityPath), _options.MessageHandlerOptions);

            _mockMessagingProvider
            .Setup(p => p.CreateMessageProcessor(entityPath, _connectionString))
            .Returns(_mockMessageProcessor.Object);

            var parameter = GetType().GetMethod("TestAutoCompleteDisbledOnTrigger").GetParameters()[0];
            var context   = new TriggerBindingProviderContext(parameter, CancellationToken.None);
            var binding   = await _provider.TryCreateAsync(context);

            var createListenerTask = binding.GetType().GetMethod("CreateListenerAsync");
            var listener           = await(Task <IListener>) createListenerTask.Invoke(binding, parameters);
            var listenerOptions    = (ServiceBusOptions)listener.GetType().GetField("_serviceBusOptions", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(listener);

            Assert.NotNull(listenerOptions);
            Assert.True(_options.MessageHandlerOptions.AutoComplete);
            Assert.True(_options.SessionHandlerOptions.AutoComplete);
            Assert.True(_options.BatchOptions.AutoComplete);
            Assert.False(listenerOptions.MessageHandlerOptions.AutoComplete);
            Assert.False(listenerOptions.SessionHandlerOptions.AutoComplete);
            Assert.False(listenerOptions.BatchOptions.AutoComplete);
        }
예제 #16
0
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            // Tries to parse the context parameters and see if it belongs to this [CosmosDBTrigger] binder
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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

            if (attribute == null)
            {
                return(null);
            }

            string contactPoint = ResolveConfigurationValue(attribute.ContactPoint, nameof(attribute.ContactPoint));
            string user         = ResolveConfigurationValue(attribute.User, nameof(attribute.User));
            string password     = ResolveConfigurationValue(attribute.Password, nameof(attribute.Password));

            ICosmosDBCassandraService cosmosDBCassandraService = _configProvider.GetService(contactPoint, user, password);

            return(Task.FromResult((ITriggerBinding) new CosmosDBCassandraTriggerBinding(
                                       parameter,
                                       ResolveAttributeValue(attribute.KeyspaceName),
                                       ResolveAttributeValue(attribute.TableName),
                                       attribute.StartFromBeginning,
                                       attribute.FeedPollDelay,
                                       cosmosDBCassandraService,
                                       _logger)));
        }
        public async Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            ParameterInfo        parameter            = context.Parameter;
            BlobTriggerAttribute blobTriggerAttribute = parameter.GetCustomAttribute <BlobTriggerAttribute>(inherit: false);

            if (blobTriggerAttribute == null)
            {
                return(null);
            }

            string          resolvedCombinedPath = Resolve(blobTriggerAttribute.BlobPath);
            IBlobPathSource path = BlobPathSource.Create(resolvedCombinedPath);

            IArgumentBinding <IStorageBlob> argumentBinding = _provider.TryCreate(parameter, access: null);

            if (argumentBinding == null)
            {
                throw new InvalidOperationException("Can't bind BlobTrigger to type '" + parameter.ParameterType + "'.");
            }

            IStorageAccount hostAccount = await _accountProvider.GetStorageAccountAsync(context.CancellationToken);

            IStorageAccount dataAccount = await _accountProvider.GetStorageAccountAsync(context.Parameter, context.CancellationToken, _nameResolver);

            // premium does not support blob logs, so disallow for blob triggers
            dataAccount.AssertTypeOneOf(StorageAccountType.GeneralPurpose, StorageAccountType.BlobOnly);

            ITriggerBinding binding = new BlobTriggerBinding(parameter, argumentBinding, hostAccount, dataAccount, path,
                                                             _hostIdProvider, _queueConfiguration, _exceptionHandler, _blobWrittenWatcherSetter,
                                                             _messageEnqueuedWatcherSetter, _sharedContextProvider, _singletonManager, _trace);

            return(binding);
        }
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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

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

            string queueName = Resolve(attribute.QueueName);

            string hostName = Resolve(attribute.HostName);

            ushort batchNumber = attribute.BatchNumber;

            IRabbitMQService service = _provider.GetService(hostName, queueName);

            return(Task.FromResult <ITriggerBinding>(new RabbitMQTriggerBinding(service, hostName, queueName, batchNumber)));
        }
예제 #19
0
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            ParameterInfo parameter    = context.Parameter;
            var           queueTrigger = TypeUtility.GetResolvedAttribute <QueueTriggerAttribute>(context.Parameter);

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

            string queueName = Resolve(queueTrigger.QueueName);

            queueName = NormalizeAndValidate(queueName);

            ITriggerDataArgumentBinding <QueueMessage> argumentBinding = InnerProvider.TryCreate(parameter);

            if (argumentBinding == null)
            {
                throw new InvalidOperationException(
                          "Can't bind QueueTrigger to type '" + parameter.ParameterType + "'.");
            }

            QueueServiceClient client = _queueServiceClientProvider.Get(queueTrigger.Connection, _nameResolver);
            var queue = client.GetQueueClient(queueName);

            ITriggerBinding binding = new QueueTriggerBinding(parameter.Name, client, queue, argumentBinding,
                                                              _queueOptions, _exceptionHandler, _messageEnqueuedWatcherSetter,
                                                              _loggerFactory, _queueProcessorFactory);

            return(Task.FromResult(binding));
        }
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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

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

            bool isSupportedTypeBinding = ValueBinder.MatchParameterType(parameter, _supportedTypes);
            bool isUserTypeBinding      = !isSupportedTypeBinding && IsValidUserType(parameter.ParameterType);

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

            return(Task.FromResult <ITriggerBinding>(new HttpTriggerBinding(attribute, context.Parameter, isUserTypeBinding, _responseHook)));
        }
예제 #21
0
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var mqttTriggerAttribute = GetMqttTriggerAttribute(context.Parameter);

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

            _logger.LogDebug($"Creating binding for parameter '{context.Parameter.Name}'");
            try
            {
                var mqttTriggerBinding = GetMqttTriggerBinding(context.Parameter, mqttTriggerAttribute);

                _logger.LogDebug($"Succesfully created binding for parameter '{context.Parameter.Name}'");

                return(Task.FromResult(mqttTriggerBinding));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Unhandled exception while binding trigger '{context.Parameter.Name}'");
                throw;
            }
        }
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var parameter  = context.Parameter;
            var attributes = parameter.GetCustomAttributes(false);

            if (attributes == null || attributes.Length == 0)
            {
                return(Task.FromResult <ITriggerBinding>(null));
            }

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

            return
                (Task.FromResult <ITriggerBinding>(new MqttMessageTriggerBinding(context.Parameter,
                                                                                 _extensionConfigProvider, context.Parameter.Member.Name)));
        }
예제 #23
0
        public async Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var parameterInfo = context.Parameter;
            var attribute     = parameterInfo.GetCustomAttribute <SignalRTriggerAttribute>(false);

            if (attribute == null)
            {
                return(null);
            }

            if (_webhookException != null)
            {
                throw new NotSupportedException($"SignalR trigger is disabled due to 'AzureWebJobsStorage' connection string is not set or invalid. {_webhookException}");
            }

            var resolvedAttribute = GetParameterResolvedAttribute(attribute, parameterInfo);

            ValidateSignalRTriggerAttributeBinding(resolvedAttribute);

            var accessKeys = _managerStore.GetOrAddByConnectionStringKey(resolvedAttribute.ConnectionStringSetting).AccessKeys;

            var hubContext = await _managerStore.GetOrAddByConnectionStringKey(resolvedAttribute.ConnectionStringSetting).GetAsync(resolvedAttribute.HubName).ConfigureAwait(false);

            return(new SignalRTriggerBinding(parameterInfo, resolvedAttribute, _dispatcher, accessKeys, hubContext as ServiceHubContext));
        }
예제 #24
0
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            ParameterInfo parameter            = context.Parameter;
            var           blobTriggerAttribute = TypeUtility.GetResolvedAttribute <BlobTriggerAttribute>(context.Parameter);

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

            string          resolvedCombinedPath = Resolve(blobTriggerAttribute.BlobPath);
            IBlobPathSource path = BlobPathSource.Create(resolvedCombinedPath);

            var hostAccount = _accountProvider.GetHost();
            var dataAccount = _accountProvider.Get(blobTriggerAttribute.Connection, _nameResolver);

            // premium does not support blob logs, so disallow for blob triggers
            // $$$
            // dataAccount.AssertTypeOneOf(StorageAccountType.GeneralPurpose, StorageAccountType.BlobOnly);

            ITriggerBinding binding = new BlobTriggerBinding(parameter, hostAccount, dataAccount, path,
                                                             _hostIdProvider, _queueOptions, _blobsOptions, _exceptionHandler, _blobWrittenWatcherSetter,
                                                             _messageEnqueuedWatcherSetter, _sharedContextProvider, _singletonManager, _loggerFactory);

            return(Task.FromResult(binding));
        }
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            ParameterInfo parameter            = context.Parameter;
            var           blobTriggerAttribute = TypeUtility.GetResolvedAttribute <BlobTriggerAttribute>(context.Parameter);

            if (parameter.ParameterType == typeof(PageBlobClient) && blobTriggerAttribute.Source == BlobTriggerSource.EventGrid)
            {
                _logger.LogError($"PageBlobClient is not supported with {nameof(BlobTriggerSource.EventGrid)}");
                return(Task.FromResult <ITriggerBinding>(null));
            }

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

            string          resolvedCombinedPath = Resolve(blobTriggerAttribute.BlobPath);
            IBlobPathSource path = BlobPathSource.Create(resolvedCombinedPath);

            var hostBlobServiceClient  = _blobServiceClientProvider.GetHost();
            var dataBlobServiceClient  = _blobServiceClientProvider.Get(blobTriggerAttribute.Connection, _nameResolver);
            var hostQueueServiceClient = _queueServiceClientProvider.GetHost();
            var dataQueueServiceClient = _queueServiceClientProvider.Get(blobTriggerAttribute.Connection, _nameResolver);

            // premium does not support blob logs, so disallow for blob triggers
            // $$$
            // dataAccount.AssertTypeOneOf(StorageAccountType.GeneralPurpose, StorageAccountType.BlobOnly);

            ITriggerBinding binding = new BlobTriggerBinding(parameter, hostBlobServiceClient, hostQueueServiceClient,
                                                             dataBlobServiceClient, dataQueueServiceClient, path, blobTriggerAttribute.Source,
                                                             _hostIdProvider, _blobsOptions, _exceptionHandler, _blobWrittenWatcherSetter,
                                                             _blobTriggerQueueWriterFactory, _sharedContextProvider, _singletonManager, _loggerFactory);

            return(Task.FromResult(binding));
        }
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            ParameterInfo            parameter = context.Parameter;
            ActivityTriggerAttribute trigger   = parameter.GetCustomAttribute <ActivityTriggerAttribute>(inherit: false);

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

            // Priority for getting the name is [ActivityTrigger], [FunctionName], method name
            string name = trigger.Activity;

            if (string.IsNullOrEmpty(name))
            {
                MemberInfo method = context.Parameter.Member;
                name = method.GetCustomAttribute <FunctionNameAttribute>()?.Name ?? method.Name;
            }

            // The activity name defaults to the method name.
            var activityName = new FunctionName(name, trigger.Version);

            this.durableTaskConfig.RegisterActivity(activityName, null);
            var binding = new ActivityTriggerBinding(this, parameter, trigger, activityName);

            return(Task.FromResult <ITriggerBinding>(binding));
        }
예제 #27
0
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            ParameterInfo parameter = context.Parameter;
            OrchestrationTriggerAttribute trigger = parameter.GetCustomAttribute <OrchestrationTriggerAttribute>(inherit: false);

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

            // Priority for getting the name is [OrchestrationTrigger], [FunctionName], method name
            string name = trigger.Orchestration;

            if (string.IsNullOrEmpty(name))
            {
                MemberInfo method = context.Parameter.Member;
                name = method.GetCustomAttribute <FunctionNameAttribute>()?.Name ?? method.Name;
            }

            // The orchestration name defaults to the method name.
            var orchestratorName = new FunctionName(name);

            this.config.RegisterOrchestrator(orchestratorName, null);
            var binding = new OrchestrationTriggerBinding(this.config, parameter, orchestratorName);

            return(Task.FromResult <ITriggerBinding>(binding));
        }
예제 #28
0
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            var parameter = context.Parameter;
            var attribute = parameter.GetCustomAttribute <KafkaTriggerAttribute>(inherit: false);

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

            var consumerConfig = CreateConsumerConfiguration(attribute);

            // TODO: reuse connections if they match with others in same function app
            Task <IListener> listenerCreator(ListenerFactoryContext factoryContext, bool singleDispatch)
            {
                var listener = KafkaListenerFactory.CreateFor(attribute,
                                                              parameter.ParameterType,
                                                              factoryContext.Executor,
                                                              singleDispatch,
                                                              this.options.Value,
                                                              consumerConfig,
                                                              logger);

                return(Task.FromResult(listener));
            }

            #pragma warning disable CS0618 // Type or member is obsolete
            var binding = BindingFactory.GetTriggerBinding(new KafkaTriggerBindingStrategy(), context.Parameter, this.converterManager, listenerCreator);
            #pragma warning restore CS0618 // Type or member is obsolete

            return(Task.FromResult <ITriggerBinding>(binding));
        }
        public async Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            ParameterInfo        parameter            = context.Parameter;
            BlobTriggerAttribute blobTriggerAttribute = parameter.GetCustomAttribute <BlobTriggerAttribute>(inherit: false);

            if (blobTriggerAttribute == null)
            {
                return(null);
            }

            string          resolvedCombinedPath = Resolve(blobTriggerAttribute.BlobPath);
            IBlobPathSource path = BlobPathSource.Create(resolvedCombinedPath);

            IArgumentBinding <IStorageBlob> argumentBinding = _provider.TryCreate(parameter, access: null);

            if (argumentBinding == null)
            {
                throw new InvalidOperationException("Can't bind BlobTrigger to type '" + parameter.ParameterType + "'.");
            }

            IStorageAccount hostAccount = await _accountProvider.GetStorageAccountAsync(context.CancellationToken);

            IStorageAccount dataAccount = await _accountProvider.GetStorageAccountAsync(context.Parameter, context.CancellationToken, _nameResolver);

            ITriggerBinding binding = new BlobTriggerBinding(parameter, argumentBinding, hostAccount, dataAccount, path,
                                                             _hostIdProvider, _queueConfiguration, _backgroundExceptionDispatcher, _blobWrittenWatcherSetter,
                                                             _messageEnqueuedWatcherSetter, _sharedContextProvider, _trace);

            return(binding);
        }
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var parameter = context.Parameter;
            var attribute = parameter.GetCustomAttribute <NoobotTriggerAttribute>(false);

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

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

            var contextParameter = context.Parameter;
            var functionName     = context.Parameter.Member.Name;
            var test             = new NoobotTriggerBinding(
                _configuration,
                contextParameter,
                _extensionConfigProvider,
                functionName);

            return(Task.FromResult <ITriggerBinding>(test));
        }