public async Task <IBinding> TryCreateAsync(BindingProviderContext context) { ParameterInfo parameter = context.Parameter; BlobAttribute blob = parameter.GetCustomAttribute <BlobAttribute>(inherit: false); if (blob == null) { return(null); } string resolvedCombinedPath = Resolve(blob.BlobPath); IBindableBlobPath path = BindableBlobPath.Create(resolvedCombinedPath); path.ValidateContractCompatibility(context.BindingDataContract); IBlobArgumentBinding argumentBinding = _provider.TryCreate(parameter, blob.Access); if (argumentBinding == null) { throw new InvalidOperationException("Can't bind Blob to type '" + parameter.ParameterType + "'."); } IStorageAccount account = await _accountProvider.GetStorageAccountAsync(context.CancellationToken); IStorageBlobClient client = account.CreateBlobClient(); IBinding binding = new BlobBinding(parameter.Name, argumentBinding, client, path); return(binding); }
public BlobBinding(string parameterName, IBlobArgumentBinding argumentBinding, IStorageBlobClient client, IBindableBlobPath path) { _parameterName = parameterName; _argumentBinding = argumentBinding; _client = client; _accountName = BlobClient.GetAccountName(client); _path = path; _converter = CreateConverter(_client, path, argumentBinding.ValueType); }
public IBlobArgumentBinding TryCreate(ParameterInfo parameter, FileAccess?access) { foreach (IBlobArgumentBindingProvider provider in _providers) { IBlobArgumentBinding binding = provider.TryCreate(parameter, access); if (binding != null) { return(binding); } } return(null); }
public async Task <IBinding> TryCreateAsync(BindingProviderContext context) { ParameterInfo parameter = context.Parameter; BlobAttribute blobAttribute = parameter.GetCustomAttribute <BlobAttribute>(inherit: false); if (blobAttribute == null) { return(null); } string resolvedPath = Resolve(blobAttribute.BlobPath); IBindableBlobPath path = null; IStorageAccount account = await _accountProvider.GetStorageAccountAsync(context.Parameter, context.CancellationToken); StorageClientFactoryContext clientFactoryContext = new StorageClientFactoryContext { Parameter = context.Parameter }; IStorageBlobClient client = account.CreateBlobClient(clientFactoryContext); // first try to bind to the Container IArgumentBinding <IStorageBlobContainer> containerArgumentBinding = _blobContainerArgumentProvider.TryCreate(parameter); if (containerArgumentBinding == null) { // if this isn't a Container binding, try a Blob binding IBlobArgumentBinding blobArgumentBinding = _blobArgumentProvider.TryCreate(parameter, blobAttribute.Access); if (blobArgumentBinding == null) { throw new InvalidOperationException("Can't bind Blob to type '" + parameter.ParameterType + "'."); } path = BindableBlobPath.Create(resolvedPath); path.ValidateContractCompatibility(context.BindingDataContract); return(new BlobBinding(parameter.Name, blobArgumentBinding, client, path)); } path = BindableBlobPath.Create(resolvedPath, isContainerBinding: true); path.ValidateContractCompatibility(context.BindingDataContract); BlobContainerBinding.ValidateContainerBinding(blobAttribute, parameter.ParameterType, path); return(new BlobContainerBinding(parameter.Name, containerArgumentBinding, client, path)); }