public override Collection <Attribute> GetAttributes() { Collection <Attribute> attributes = new Collection <Attribute>(); string path = Context.GetMetadataValue <string>("path"); Attribute attribute = null; if (Context.IsTrigger) { attribute = new BlobTriggerAttribute(path); } else { attribute = new BlobAttribute(path, Context.Access); } attributes.Add(attribute); var connectionProvider = (IConnectionProvider)attribute; string connection = Context.GetMetadataValue <string>("connection"); if (!string.IsNullOrEmpty(connection)) { connectionProvider.Connection = connection; } return(attributes); }
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); }
// BlobClient is simplified version of BlockBlobClient, i.e. upload results in creation of block blob. private BlobClient ConvertBlobBaseClientToBlobClient(BlobBaseClient input, BlobTriggerAttribute attr) { if (input is BlockBlobClient) { var client = _blobServiceClientProvider.Get(attr.Connection); var blob = client.GetBlobContainerClient(input.BlobContainerName).GetBlobClient(input.Name); return(blob); } else { throw new InvalidOperationException($"The blob is not an {typeof(BlockBlobClient).Name}."); } }
public void GenerateBlobTriggerFunction() { BlobBindingMetadata trigger = new BlobBindingMetadata { Type = BindingType.BlobTrigger, Path = "foo/bar" }; MethodInfo method = GenerateMethod(trigger); VerifyCommonProperties(method); // verify trigger parameter ParameterInfo parameter = method.GetParameters()[0]; Assert.Equal("input", parameter.Name); Assert.Equal(typeof(Stream), parameter.ParameterType); BlobTriggerAttribute attribute = parameter.GetCustomAttribute <BlobTriggerAttribute>(); Assert.Equal("foo/bar", attribute.BlobPath); }
public void GenerateBlobTriggerFunction() { BindingMetadata trigger = BindingMetadata.Create(new JObject { { "type", "blobTrigger" }, { "name", "input" }, { "direction", "in" }, { "path", "foo/bar" } }); MethodInfo method = GenerateMethod(trigger); VerifyCommonProperties(method); // verify trigger parameter ParameterInfo parameter = method.GetParameters()[0]; Assert.Equal("input", parameter.Name); Assert.Equal(typeof(Stream), parameter.ParameterType); BlobTriggerAttribute attribute = parameter.GetCustomAttribute <BlobTriggerAttribute>(); Assert.Equal("foo/bar", attribute.BlobPath); }