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 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);
        }
Beispiel #3
0
        public async Task <IBinding> TryCreateAsync(BindingProviderContext context)
        {
            ParameterInfo  parameter      = context.Parameter;
            TableAttribute tableAttribute = parameter.GetCustomAttribute <TableAttribute>(inherit: false);

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

            string          tableName = Resolve(tableAttribute.TableName);
            IStorageAccount account   = await _accountProvider.GetStorageAccountAsync(context.Parameter, context.CancellationToken, _nameResolver);

            // requires storage account with table support
            account.AssertTypeOneOf(StorageAccountType.GeneralPurpose);

            StorageClientFactoryContext clientFactoryContext = new StorageClientFactoryContext
            {
                Parameter = context.Parameter
            };
            IStorageTableClient client = account.CreateTableClient(clientFactoryContext);

            bool     bindsToEntireTable = tableAttribute.RowKey == null;
            IBinding binding;

            if (bindsToEntireTable)
            {
                IBindableTablePath path = BindableTablePath.Create(tableName);
                path.ValidateContractCompatibility(context.BindingDataContract);

                IStorageTableArgumentBinding argumentBinding = _tableBindingProvider.TryCreate(parameter);

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

                binding = new TableBinding(parameter.Name, argumentBinding, client, path);
            }
            else
            {
                string partitionKey           = Resolve(tableAttribute.PartitionKey);
                string rowKey                 = Resolve(tableAttribute.RowKey);
                IBindableTableEntityPath path = BindableTableEntityPath.Create(tableName, partitionKey, rowKey);
                path.ValidateContractCompatibility(context.BindingDataContract);

                IArgumentBinding <TableEntityContext> argumentBinding = _entityBindingProvider.TryCreate(parameter);

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

                binding = new TableEntityBinding(parameter.Name, argumentBinding, client, path);
            }

            return(binding);
        }
Beispiel #4
0
            protected override IStorageBlobContainer GetContainer(string accountName)
            {
                // Get the container via a full connection string
                Task <IStorageAccount> task           = _accountProvider.GetStorageAccountAsync(accountName, CancellationToken.None);
                IStorageAccount        storageAccount = task.Result;

                // singleton requires block blobs, cannot be premium
                storageAccount.AssertTypeOneOf(StorageAccountType.GeneralPurpose, StorageAccountType.BlobOnly);
                IStorageBlobClient blobClient = storageAccount.CreateBlobClient();
                var container = blobClient.GetContainerReference(HostContainerNames.Hosts);

                return(container);
            }
        public async Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            ParameterInfo parameter    = context.Parameter;
            var           queueTrigger = TypeUtility.GetResolvedAttribute <QueueTriggerAttribute>(context.Parameter);

            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(queueTrigger, context.CancellationToken, _nameResolver);

            // requires storage account with queue support
            account.AssertTypeOneOf(StorageAccountType.GeneralPurpose);

            StorageClientFactoryContext clientFactoryContext = new StorageClientFactoryContext
            {
                Parameter = parameter
            };
            IStorageQueueClient client = account.CreateQueueClient(clientFactoryContext);
            IStorageQueue       queue  = client.GetQueueReference(queueName);

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

            return(binding);
        }
Beispiel #6
0
        internal IStorageBlobDirectory GetLockDirectory(string accountName)
        {
            if (string.IsNullOrEmpty(accountName))
            {
                accountName = ConnectionStringNames.Storage;
            }

            IStorageBlobDirectory storageDirectory = null;

            if (!_lockDirectoryMap.TryGetValue(accountName, out storageDirectory))
            {
                Task <IStorageAccount> task           = _accountProvider.GetStorageAccountAsync(accountName, CancellationToken.None);
                IStorageAccount        storageAccount = task.Result;
                // singleton requires block blobs, cannot be premium
                storageAccount.AssertTypeOneOf(StorageAccountType.GeneralPurpose, StorageAccountType.BlobOnly);
                IStorageBlobClient blobClient = storageAccount.CreateBlobClient();
                storageDirectory = blobClient.GetContainerReference(HostContainerNames.Hosts)
                                   .GetDirectoryReference(HostDirectoryNames.SingletonLocks);
                _lockDirectoryMap[accountName] = storageDirectory;
            }

            return(storageDirectory);
        }
Beispiel #7
0
        public async Task <IStorageAccount> GetAccountAsync(string connectionStringName, CancellationToken cancellationToken)
        {
            IStorageAccount account   = null;
            var             isPrimary = true;

            if (connectionStringName == ConnectionStringNames.Dashboard)
            {
                account = DashboardAccount;
            }
            else if (connectionStringName == ConnectionStringNames.Storage)
            {
                account = StorageAccount;
            }
            else
            {
                // see if this is a user connnection string (i.e. for multi-account scenarios)
                string connectionString = _ambientConnectionStringProvider.GetConnectionString(connectionStringName);
                if (!string.IsNullOrEmpty(connectionString))
                {
                    account   = ParseAccount(connectionStringName, connectionString);
                    isPrimary = false;
                }
            }

            if (account != null)
            {
                // On the first attempt, this will make a network call to verify the credentials work.
                await _storageCredentialsValidator.ValidateCredentialsAsync(account, cancellationToken);

                if (isPrimary)
                {
                    account.AssertTypeOneOf(StorageAccountType.GeneralPurpose);
                }
            }

            return(account);
        }
 public void AssertTypeOneOf_Succeeds()
 {
     account.AssertTypeOneOf(StorageAccountType.GeneralPurpose);
 }