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 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) { 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) { 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 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 void TestToString() { IBlobPathSource path1 = BlobPathSource.Create(@"container/dir/subdir/{name}.csv"); IBlobPathSource path2 = BlobPathSource.Create(@"container/dir/subdir/{name}.csv"); IBlobPathSource path3 = BlobPathSource.Create(@"container/dir/subdir/other.csv"); Assert.Equal(path1.ToString(), path2.ToString()); Assert.NotEqual(path2.ToString(), path3.ToString()); }
public void GetNames() { var path = BlobPathSource.Create(@"container/{name}-{date}.csv"); var d = path.ParameterNames; var names = d.ToArray(); Assert.Equal(2, names.Length); Assert.Equal("name", names[0]); Assert.Equal("date", names[1]); }
public void ExecuteAsync_IfBlobDoesNotMatchPattern_ReturnsTrue() { // Arrange IStorageAccount account = CreateAccount(); IStorageBlobClient client = account.CreateBlobClient(); string containerName = "container"; IStorageBlobContainer container = client.GetContainerReference(containerName); IStorageBlobContainer otherContainer = client.GetContainerReference("other"); IBlobPathSource input = BlobPathSource.Create(containerName + "/{name}"); ITriggerExecutor <IStorageBlob> product = CreateProductUnderTest(input); IStorageBlob blob = otherContainer.GetBlockBlobReference("nonmatch"); // Act Task <bool> task = product.ExecuteAsync(blob, CancellationToken.None); // Assert Assert.True(task.Result); }
public void ExecuteAsync_IfBlobDoesNotMatchPattern_ReturnsSuccessfulResult() { // Arrange var account = CreateAccount(); var client = account.CreateCloudBlobClient(); string containerName = "container"; var container = client.GetContainerReference(containerName); var otherContainer = client.GetContainerReference("other"); IBlobPathSource input = BlobPathSource.Create(containerName + "/{name}"); ITriggerExecutor <ICloudBlob> product = CreateProductUnderTest(input); var blob = otherContainer.GetBlockBlobReference("nonmatch"); // Act Task <FunctionResult> task = product.ExecuteAsync(blob, CancellationToken.None); // Assert Assert.True(task.Result.Succeeded); }
private static IDictionary <string, string> Match(string a, string b) { var pathA = BlobPathSource.Create(a); var pathB = BlobPath.Parse(b, false); IReadOnlyDictionary <string, object> bindingData = pathA.CreateBindingData(pathB); if (bindingData == null) { return(null); } IDictionary <string, string> matches = new Dictionary <string, string>(); foreach (KeyValuePair <string, object> item in bindingData) { matches.Add(item.Key, item.Value.ToString()); } return(matches); }
public void ExecuteAsync_IfBlobDoesNotMatchPattern_ReturnsSuccessfulResult() { // Arrange var client = account.CreateBlobServiceClient(); string containerName = ContainerName; var container = client.GetBlobContainerClient(containerName); var otherContainer = client.GetBlobContainerClient("other"); IBlobPathSource input = BlobPathSource.Create(containerName + "/{name}"); ITriggerExecutor <BlobTriggerExecutorContext> product = CreateProductUnderTest(input); // Note: this test does not set the PollId. This ensures that we work okay with null values for these. var blob = otherContainer.GetBlockBlobClient("nonmatch"); var context = new BlobTriggerExecutorContext { Blob = new BlobWithContainer <BlobBaseClient>(otherContainer, blob), TriggerSource = BlobTriggerSource.ContainerScan }; // Act Task <FunctionResult> task = product.ExecuteAsync(context, CancellationToken.None); // Assert Assert.True(task.Result.Succeeded); // Validate log is written var logMessage = _loggerProvider.GetAllLogMessages().Single(); Assert.Equal("BlobDoesNotMatchPattern", logMessage.EventId.Name); Assert.Equal(LogLevel.Debug, logMessage.Level); Assert.Equal(6, logMessage.State.Count()); Assert.Equal("FunctionIdLogName", logMessage.GetStateValue <string>("functionName")); Assert.Equal(containerName + "/{name}", logMessage.GetStateValue <string>("pattern")); Assert.Equal(blob.Name, logMessage.GetStateValue <string>("blobName")); Assert.Null(logMessage.GetStateValue <string>("pollId")); Assert.Equal(context.TriggerSource, logMessage.GetStateValue <BlobTriggerSource>("triggerSource")); Assert.True(!string.IsNullOrWhiteSpace(logMessage.GetStateValue <string>("{OriginalFormat}"))); }
public void BlobPathSource_Throws_OnContainerResolves() { var exc = Assert.Throws <FormatException>(() => BlobPathSource.Create("container{resolve}/blob")); Assert.Contains("Container paths cannot contain {resolve} tokens.", exc.Message); }
public void BlobPathSource_Throws_OnEmpty() { var exc = Assert.Throws <FormatException>(() => BlobPathSource.Create("/")); Assert.Contains("Paths must be in the format 'container/blob'", exc.Message); }
public void BlobPathSource_Throws_OnBackslash() { var exc = Assert.Throws <FormatException>(() => BlobPathSource.Create("container\\blob")); StringAssert.Contains("Paths must be in the format 'container/blob'", exc.Message); }