Example #1
0
 public QueuesExtensionConfigProvider(StorageAccountProvider storageAccountProvider, IContextGetter <IMessageEnqueuedWatcher> contextGetter,
                                      QueueTriggerAttributeBindingProvider triggerProvider)
 {
     _contextGetter          = contextGetter;
     _storageAccountProvider = storageAccountProvider;
     _triggerProvider        = triggerProvider;
 }
Example #2
0
            public void Initialize(ExtensionConfigContext context, QueueServiceClientProvider queueServiceClientProvider, IContextGetter <IMessageEnqueuedWatcher> contextGetter)
            {
                _queueServiceClientProvider   = queueServiceClientProvider;
                _messageEnqueuedWatcherGetter = contextGetter;

                // TODO: FACAVAL replace this with queue options. This should no longer be needed.
                //context.ApplyConfig(context.Config.Queues, "queues");

                // IStorageQueueMessage is the core testing interface
                var binding = context.AddBindingRule <QueueAttribute>();

                binding
                .AddConverter <byte[], QueueMessage>(ConvertByteArrayToCloudQueueMessage)
                .AddConverter <string, QueueMessage>(ConvertStringToCloudQueueMessage)
                .AddOpenConverter <OpenType.Poco, QueueMessage>(ConvertPocoToCloudQueueMessage);

                context // global converters, apply to multiple attributes.
                .AddConverter <QueueMessage, byte[]>(ConvertCloudQueueMessageToByteArray)
                .AddConverter <QueueMessage, string>(ConvertCloudQueueMessageToString);

                var builder = new QueueBuilder(this);

                binding.AddValidator(ValidateQueueAttribute);

                binding.BindToCollector <QueueMessage>(this);

                binding.BindToInput <QueueClient>(builder);

                binding.BindToInput <QueueClient>(builder);
            }
Example #3
0
 // Use the static Build method to create.
 // Constructor is just for capturing instance fields used in func closures.
 private QueueBindingProvider(
     IStorageAccountProvider accountProvider,
     IContextGetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherGetter)
 {
     _accountProvider = accountProvider;
     _messageEnqueuedWatcherGetter = messageEnqueuedWatcherGetter;
 }
Example #4
0
 public QueuesExtensionConfigProvider(QueueServiceClientProvider queueServiceClientProvider, IContextGetter <IMessageEnqueuedWatcher> contextGetter,
                                      QueueTriggerAttributeBindingProvider triggerProvider)
 {
     _contextGetter = contextGetter;
     _queueServiceClientProvider = queueServiceClientProvider;
     _triggerProvider            = triggerProvider;
 }
Example #5
0
        private static IBlobArgumentBindingProvider CreateBlobArgumentProvider(IEnumerable <Type> cloudBlobStreamBinderTypes,
                                                                               IContextGetter <IBlobWrittenWatcher> blobWrittenWatcherGetter)
        {
            List <IBlobArgumentBindingProvider> innerProviders = new List <IBlobArgumentBindingProvider>();

            innerProviders.Add(CreateConverterProvider <ICloudBlob, StorageBlobToCloudBlobConverter>());
            innerProviders.Add(CreateConverterProvider <CloudBlockBlob, StorageBlobToCloudBlockBlobConverter>());
            innerProviders.Add(CreateConverterProvider <CloudPageBlob, StorageBlobToCloudPageBlobConverter>());
            innerProviders.Add(new StreamArgumentBindingProvider(blobWrittenWatcherGetter));
            innerProviders.Add(new CloudBlobStreamArgumentBindingProvider(blobWrittenWatcherGetter));
            innerProviders.Add(new TextReaderArgumentBindingProvider());
            innerProviders.Add(new TextWriterArgumentBindingProvider(blobWrittenWatcherGetter));
            innerProviders.Add(new StringArgumentBindingProvider());
            innerProviders.Add(new ByteArrayArgumentBindingProvider());
            innerProviders.Add(new OutStringArgumentBindingProvider(blobWrittenWatcherGetter));
            innerProviders.Add(new OutByteArrayArgumentBindingProvider(blobWrittenWatcherGetter));

            if (cloudBlobStreamBinderTypes != null)
            {
                innerProviders.AddRange(cloudBlobStreamBinderTypes.Select(
                                            t => CloudBlobStreamObjectBinder.CreateReadBindingProvider(t)));

                innerProviders.AddRange(cloudBlobStreamBinderTypes.Select(
                                            t => CloudBlobStreamObjectBinder.CreateWriteBindingProvider(t, blobWrittenWatcherGetter)));
            }

            return(new CompositeBlobArgumentBindingProvider(innerProviders));
        }
Example #6
0
            public void Initialize(
                ExtensionConfigContext context,
                QueueServiceClientProvider queueServiceClientProvider,
                IContextGetter <IMessageEnqueuedWatcher> contextGetter,
                QueueCausalityManager queueCausalityManager)
            {
                _queueServiceClientProvider   = queueServiceClientProvider;
                _messageEnqueuedWatcherGetter = contextGetter;
                _queueCausalityManager        = queueCausalityManager;

                // IStorageQueueMessage is the core testing interface
                var binding = context.AddBindingRule <QueueAttribute>();

                binding
                .AddConverter <byte[], QueueMessage>(ConvertByteArrayToCloudQueueMessage)
                .AddConverter <string, QueueMessage>(ConvertStringToCloudQueueMessage)
                .AddConverter <BinaryData, QueueMessage>(ConvertBinaryDataToCloudQueueMessage)
                .AddOpenConverter <OpenType.Poco, QueueMessage>(ConvertPocoToCloudQueueMessage);

                context // global converters, apply to multiple attributes.
                .AddConverter <QueueMessage, byte[]>(ConvertCloudQueueMessageToByteArray)
                .AddConverter <QueueMessage, string>(ConvertCloudQueueMessageToString)
                .AddConverter <QueueMessage, BinaryData>(ConvertCloudQueueMessageToBinaryData);

                var builder = new QueueBuilder(this);

                binding.AddValidator(ValidateQueueAttribute);

                binding.BindToCollector <QueueMessage>(this);

                binding.BindToInput <QueueClient>(builder);

                binding.BindToInput <QueueClient>(builder);
            }
        public static IBindingProvider Create(INameResolver nameResolver,
            IStorageAccountProvider storageAccountProvider,
            IExtensionTypeLocator extensionTypeLocator,
            IContextGetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherGetter,
            IContextGetter<IBlobWrittenWatcher> blobWrittenWatcherGetter,
            IExtensionRegistry extensions)
        {
            List<IBindingProvider> innerProviders = new List<IBindingProvider>();
            innerProviders.Add(new QueueAttributeBindingProvider(nameResolver, storageAccountProvider, messageEnqueuedWatcherGetter));
            innerProviders.Add(new BlobAttributeBindingProvider(nameResolver, storageAccountProvider, extensionTypeLocator, blobWrittenWatcherGetter));
            innerProviders.Add(new TableAttributeBindingProvider(nameResolver, storageAccountProvider, extensions));

            // add any registered extension binding providers
            foreach (IBindingProvider provider in extensions.GetExtensions(typeof(IBindingProvider)))
            {
                innerProviders.Add(provider);
            }

            innerProviders.Add(new CloudStorageAccountBindingProvider(storageAccountProvider));
            innerProviders.Add(new CancellationTokenBindingProvider());

            // The console output binder below will handle all remaining TextWriter parameters. It must come after the
            // Blob binding provider; otherwise bindings like Do([Blob("a/b")] TextWriter blob) wouldn't work.
            innerProviders.Add(new ConsoleOutputBindingProvider());

            ContextAccessor<IBindingProvider> bindingProviderAccessor = new ContextAccessor<IBindingProvider>();
            innerProviders.Add(new RuntimeBindingProvider(bindingProviderAccessor));
            innerProviders.Add(new DataBindingProvider());

            IBindingProvider bindingProvider = new CompositeBindingProvider(innerProviders);
            bindingProviderAccessor.SetValue(bindingProvider);
            return bindingProvider;
        }
        public OutStringArgumentBindingProvider(IContextGetter<IBlobWrittenWatcher> blobWrittenWatcherGetter)
        {
            if (blobWrittenWatcherGetter == null)
            {
                throw new ArgumentNullException("blobWrittenWatcherGetter");
            }

            _blobWrittenWatcherGetter = blobWrittenWatcherGetter;
        }
Example #9
0
        public RuntimeBindingProvider(IContextGetter<IBindingProvider> bindingProviderGetter)
        {
            if (bindingProviderGetter == null)
            {
                throw new ArgumentNullException("bindingProviderGetter");
            }

            _bindingProviderGetter = bindingProviderGetter;
        }
            public TextWriterArgumentBinding(IContextGetter <IBlobWrittenWatcher> blobWrittenWatcherGetter)
            {
                if (blobWrittenWatcherGetter == null)
                {
                    throw new ArgumentNullException("blobWrittenWatcherGetter");
                }

                _blobWrittenWatcherGetter = blobWrittenWatcherGetter;
            }
            public StringArgumentBinding(IContextGetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherGetter)
            {
                if (messageEnqueuedWatcherGetter == null)
                {
                    throw new ArgumentNullException("messageEnqueuedWatcherGetter");
                }

                _messageEnqueuedWatcherGetter = messageEnqueuedWatcherGetter;
            }
            public OutputByteArrayBinding(IContextGetter<IBlobWrittenWatcher> blobWrittenWatcherGetter)
            {
                if (blobWrittenWatcherGetter == null)
                {
                    throw new ArgumentNullException("blobWrittenWatcherGetter");
                }

                _blobWrittenWatcherGetter = blobWrittenWatcherGetter;
            }
        public ByteArrayArgumentBindingProvider(IContextGetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherGetter)
        {
            if (messageEnqueuedWatcherGetter == null)
            {
                throw new ArgumentNullException("messageEnqueuedWatcherGetter");
            }

            _messageEnqueuedWatcherGetter = messageEnqueuedWatcherGetter;
        }
Example #14
0
        public StreamArgumentBindingProvider(IContextGetter <IBlobWrittenWatcher> blobWrittenWatcherGetter)
        {
            if (blobWrittenWatcherGetter == null)
            {
                throw new ArgumentNullException("blobWrittenWatcherGetter");
            }

            _blobWrittenWatcherGetter = blobWrittenWatcherGetter;
        }
Example #15
0
            public OutputByteArrayBinding(IContextGetter <IBlobWrittenWatcher> blobWrittenWatcherGetter)
            {
                if (blobWrittenWatcherGetter == null)
                {
                    throw new ArgumentNullException("blobWrittenWatcherGetter");
                }

                _blobWrittenWatcherGetter = blobWrittenWatcherGetter;
            }
            public CloudBlobStreamArgumentBinding(IContextGetter<IBlobWrittenWatcher> blobWrittenWatcherGetter)
            {
                if (blobWrittenWatcherGetter == null)
                {
                    throw new ArgumentNullException("blobWrittenWatcherGetter");
                }

                _blobWrittenWatcherGetter = blobWrittenWatcherGetter;
            }
        public RuntimeBindingProvider(IContextGetter <IBindingProvider> bindingProviderGetter)
        {
            if (bindingProviderGetter == null)
            {
                throw new ArgumentNullException("bindingProviderGetter");
            }

            _bindingProviderGetter = bindingProviderGetter;
        }
        public RuntimeBinding(string parameterName, IContextGetter<IBindingProvider> bindingProviderGetter)
        {
            if (bindingProviderGetter == null)
            {
                throw new ArgumentNullException("bindingProviderGetter");
            }

            _parameterName = parameterName;
            _bindingProviderGetter = bindingProviderGetter;
        }
Example #19
0
        public RuntimeBinding(string parameterName, IContextGetter <IBindingProvider> bindingProviderGetter)
        {
            if (bindingProviderGetter == null)
            {
                throw new ArgumentNullException("bindingProviderGetter");
            }

            _parameterName         = parameterName;
            _bindingProviderGetter = bindingProviderGetter;
        }
 public static IBlobArgumentBindingProvider CreateWriteBindingProvider(Type binderType,
     IContextGetter<IBlobWrittenWatcher> blobWrittenWatcherGetter)
 {
     VerifyDefaultConstructor(binderType);
     Type valueType = GetBindingValueType(binderType);
     Type bindingProviderType = typeof(OutObjectArgumentBindingProvider<,>).MakeGenericType(valueType,
         binderType);
     return (IBlobArgumentBindingProvider)Activator.CreateInstance(bindingProviderType,
         blobWrittenWatcherGetter);
 }
        public static IBlobArgumentBindingProvider CreateWriteBindingProvider(Type binderType,
                                                                              IContextGetter <IBlobWrittenWatcher> blobWrittenWatcherGetter)
        {
            VerifyDefaultConstructor(binderType);
            Type valueType           = GetBindingValueType(binderType);
            Type bindingProviderType = typeof(OutObjectArgumentBindingProvider <,>).MakeGenericType(valueType,
                                                                                                    binderType);

            return((IBlobArgumentBindingProvider)Activator.CreateInstance(bindingProviderType,
                                                                          blobWrittenWatcherGetter));
        }
Example #22
0
        public static IBindingProvider Build(
            IStorageAccountProvider accountProvider,
            IContextGetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherGetter,
            INameResolver nameResolver,
            IConverterManager converterManager)
        {
            var closure         = new QueueBindingProvider(accountProvider, messageEnqueuedWatcherGetter);
            var bindingProvider = closure.New(nameResolver, converterManager);

            return(bindingProvider);
        }
 public BlobsExtensionConfigProvider(
     BlobServiceClientProvider blobServiceClientProvider,
     BlobTriggerAttributeBindingProvider triggerBinder,
     IContextGetter <IBlobWrittenWatcher> contextAccessor,
     INameResolver nameResolver,
     IConverterManager converterManager,
     BlobTriggerQueueWriterFactory blobTriggerQueueWriterFactory,
     HttpRequestProcessor httpRequestProcessor,
     ILoggerFactory loggerFactory) : this(blobServiceClientProvider, triggerBinder, contextAccessor, nameResolver, converterManager, blobTriggerQueueWriterFactory, httpRequestProcessor, null, loggerFactory)
 {
 }
Example #24
0
 public BlobsExtensionConfigProvider(StorageAccountProvider accountProvider,
                                     BlobTriggerAttributeBindingProvider triggerBinder,
                                     IContextGetter <IBlobWrittenWatcher> contextAccessor,
                                     INameResolver nameResolver,
                                     IConverterManager converterManager)
 {
     _accountProvider          = accountProvider;
     _triggerBinder            = triggerBinder;
     _blobWrittenWatcherGetter = contextAccessor;
     _nameResolver             = nameResolver;
     _converterManager         = converterManager;
 }
 private static IQueueArgumentBindingProvider CreateInnerProvider(
     IContextGetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherGetter)
 {
     return(new CompositeArgumentBindingProvider(
                new StorageQueueArgumentBindingProvider(),
                new CloudQueueArgumentBindingProvider(),
                new CloudQueueMessageArgumentBindingProvider(messageEnqueuedWatcherGetter),
                new StringArgumentBindingProvider(messageEnqueuedWatcherGetter),
                new ByteArrayArgumentBindingProvider(messageEnqueuedWatcherGetter),
                new UserTypeArgumentBindingProvider(messageEnqueuedWatcherGetter),
                new CollectorArgumentBindingProvider(),
                new AsyncCollectorArgumentBindingProvider()));
 }
 private static IQueueArgumentBindingProvider CreateInnerProvider(
     IContextGetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherGetter)
 {
     return new CompositeArgumentBindingProvider(
         new StorageQueueArgumentBindingProvider(),
         new CloudQueueArgumentBindingProvider(),
         new CloudQueueMessageArgumentBindingProvider(messageEnqueuedWatcherGetter),
         new StringArgumentBindingProvider(messageEnqueuedWatcherGetter),
         new ByteArrayArgumentBindingProvider(messageEnqueuedWatcherGetter),
         new UserTypeArgumentBindingProvider(messageEnqueuedWatcherGetter),
         new CollectorArgumentBindingProvider(),
         new AsyncCollectorArgumentBindingProvider());
 }
Example #27
0
        public RuntimeBinding(ParameterInfo parameter, IContextGetter <IBindingProvider> bindingProviderGetter)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }
            if (bindingProviderGetter == null)
            {
                throw new ArgumentNullException("bindingProviderGetter");
            }

            _memberInfo            = parameter.Member;
            _parameter             = parameter;
            _bindingProviderGetter = bindingProviderGetter;
        }
Example #28
0
        public RuntimeBinding(ParameterInfo parameter, IContextGetter<IBindingProvider> bindingProviderGetter)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }
            if (bindingProviderGetter == null)
            {
                throw new ArgumentNullException("bindingProviderGetter");
            }

            _memberInfo = parameter.Member;
            _parameter = parameter;
            _bindingProviderGetter = bindingProviderGetter;
        }
Example #29
0
            public ObjectArgumentBinding(ICloudBlobStreamBinder <TValue> objectBinder,
                                         IContextGetter <IBlobWrittenWatcher> blobWrittenWatcherGetter)
            {
                if (objectBinder == null)
                {
                    throw new ArgumentNullException("objectBinder");
                }

                if (blobWrittenWatcherGetter == null)
                {
                    throw new ArgumentNullException("blobWrittenWatcherGetter");
                }

                _objectBinder             = objectBinder;
                _blobWrittenWatcherGetter = blobWrittenWatcherGetter;
            }
Example #30
0
        public static IBindingProvider Create(
            INameResolver nameResolver,
            IConverterManager converterManager,
            IStorageAccountProvider storageAccountProvider,
            IExtensionTypeLocator extensionTypeLocator,
            IContextGetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherGetter,
            IContextGetter <IBlobWrittenWatcher> blobWrittenWatcherGetter,
            IExtensionRegistry extensions)
        {
            List <IBindingProvider> innerProviders = new List <IBindingProvider>();

            if (converterManager == null)
            {
                converterManager = new ConverterManager();
            }

            // Wire up new bindings
            var ruleQueueOutput = QueueBindingProvider.Build(storageAccountProvider, messageEnqueuedWatcherGetter, nameResolver, converterManager);

            innerProviders.Add(ruleQueueOutput);

            innerProviders.Add(new BlobAttributeBindingProvider(nameResolver, storageAccountProvider, extensionTypeLocator, blobWrittenWatcherGetter));
            innerProviders.Add(TableAttributeBindingProvider.Build(nameResolver, converterManager, storageAccountProvider, extensions));

            // add any registered extension binding providers
            foreach (IBindingProvider provider in extensions.GetExtensions(typeof(IBindingProvider)))
            {
                innerProviders.Add(provider);
            }

            innerProviders.Add(new CloudStorageAccountBindingProvider(storageAccountProvider));
            innerProviders.Add(new CancellationTokenBindingProvider());

            // The TraceWriter binder handles all remaining TraceWriter/TextWriter parameters. It must come after the
            // Blob binding provider; otherwise bindings like Do([Blob("a/b")] TextWriter blob) wouldn't work.
            innerProviders.Add(new TraceWriterBindingProvider());

            ContextAccessor <IBindingProvider> bindingProviderAccessor = new ContextAccessor <IBindingProvider>();

            innerProviders.Add(new RuntimeBindingProvider(bindingProviderAccessor));
            innerProviders.Add(new DataBindingProvider());

            IBindingProvider bindingProvider = new CompositeBindingProvider(innerProviders);

            bindingProviderAccessor.SetValue(bindingProvider);
            return(bindingProvider);
        }
        public QueueAttributeBindingProvider(INameResolver nameResolver, IStorageAccountProvider accountProvider,
            IContextGetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherGetter)
        {
            if (accountProvider == null)
            {
                throw new ArgumentNullException("accountProvider");
            }

            if (messageEnqueuedWatcherGetter == null)
            {
                throw new ArgumentNullException("messageEnqueuedWatcherGetter");
            }

            _nameResolver = nameResolver;
            _accountProvider = accountProvider;
            _innerProvider = CreateInnerProvider(messageEnqueuedWatcherGetter);
        }
        public QueueAttributeBindingProvider(INameResolver nameResolver, IStorageAccountProvider accountProvider,
                                             IContextGetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherGetter)
        {
            if (accountProvider == null)
            {
                throw new ArgumentNullException("accountProvider");
            }

            if (messageEnqueuedWatcherGetter == null)
            {
                throw new ArgumentNullException("messageEnqueuedWatcherGetter");
            }

            _nameResolver    = nameResolver;
            _accountProvider = accountProvider;
            _innerProvider   = CreateInnerProvider(messageEnqueuedWatcherGetter);
        }
Example #33
0
        public static IBindingProvider Create(INameResolver nameResolver,
                                              IStorageAccountProvider storageAccountProvider,
                                              IServiceBusAccountProvider serviceBusAccountProvider,
                                              IExtensionTypeLocator extensionTypeLocator,
                                              IContextGetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherGetter,
                                              IContextGetter <IBlobWrittenWatcher> blobWrittenWatcherGetter)
        {
            List <IBindingProvider> innerProviders = new List <IBindingProvider>();

            innerProviders.Add(new QueueAttributeBindingProvider(nameResolver, storageAccountProvider,
                                                                 messageEnqueuedWatcherGetter));
            innerProviders.Add(new BlobAttributeBindingProvider(nameResolver, storageAccountProvider,
                                                                extensionTypeLocator, blobWrittenWatcherGetter));

            innerProviders.Add(new TableAttributeBindingProvider(nameResolver, storageAccountProvider));

            Type serviceBusProviderType = ServiceBusExtensionTypeLoader.Get(
                "Microsoft.Azure.WebJobs.ServiceBus.Bindings.ServiceBusAttributeBindingProvider");

            if (serviceBusProviderType != null)
            {
                IBindingProvider serviceBusAttributeBindingProvider =
                    (IBindingProvider)Activator.CreateInstance(serviceBusProviderType, nameResolver,
                                                               serviceBusAccountProvider);
                innerProviders.Add(serviceBusAttributeBindingProvider);
            }

            innerProviders.Add(new CloudStorageAccountBindingProvider(storageAccountProvider));
            innerProviders.Add(new CancellationTokenBindingProvider());

            // The console output binder below will handle all remaining TextWriter parameters. It must come after the
            // Blob binding provider; otherwise bindings like Do([Blob("a/b")] TextWriter blob) wouldn't work.
            innerProviders.Add(new ConsoleOutputBindingProvider());

            ContextAccessor <IBindingProvider> bindingProviderAccessor = new ContextAccessor <IBindingProvider>();

            innerProviders.Add(new RuntimeBindingProvider(bindingProviderAccessor));
            innerProviders.Add(new DataBindingProvider());

            IBindingProvider bindingProvider = new CompositeBindingProvider(innerProviders);

            bindingProviderAccessor.SetValue(bindingProvider);
            return(bindingProvider);
        }
 public BlobsExtensionConfigProvider(
     BlobServiceClientProvider blobServiceClientProvider,
     BlobTriggerAttributeBindingProvider triggerBinder,
     IContextGetter <IBlobWrittenWatcher> contextAccessor,
     INameResolver nameResolver,
     IConverterManager converterManager,
     BlobTriggerQueueWriterFactory blobTriggerQueueWriterFactory,
     HttpRequestProcessor httpRequestProcessor,
     ILoggerFactory loggerFactory)
 {
     _blobServiceClientProvider = blobServiceClientProvider;
     _triggerBinder             = triggerBinder;
     _blobWrittenWatcherGetter  = contextAccessor;
     _nameResolver     = nameResolver;
     _converterManager = converterManager;
     _blobTriggerQueueWriterFactory = blobTriggerQueueWriterFactory;
     _httpRequestProcessor          = httpRequestProcessor;
     _logger = loggerFactory.CreateLogger <BlobsExtensionConfigProvider>();
 }
        public void Initialize(ExtensionConfigContext context)
        {
            _accountProvider = context.Config.GetService <IStorageAccountProvider>();

            _blobWrittenWatcherGetter = context.PerHostServices.GetService <ContextAccessor <IBlobWrittenWatcher> >();
            _nameResolver             = context.Config.NameResolver;
            _converterManager         = context.Config.ConverterManager;

            var rule = context.AddBindingRule <BlobAttribute>();

            // Bind to multiple blobs (either via a container; a blob directory, an IEnumerable<T>)
            rule.BindToInput <CloudBlobDirectory>(this);

            rule.BindToInput <CloudBlobContainer>(this);

            rule.BindToInput <MultiBlobContext>(this); // Intermediate private context to capture state
            rule.AddOpenConverter <MultiBlobContext, IEnumerable <BlobCollectionType> >(typeof(BlobCollectionConverter <>), this);

            // BindToStream will also handle the custom Stream-->T converters.
            rule.SetPostResolveHook(ToBlobDescr).
            BindToStream(CreateStreamAsync, FileAccess.ReadWrite);     // Precedence, must beat CloudBlobStream

            // Normal blob
            // These are not converters because Blob/Page/Append affects how we *create* the blob.
            rule.SetPostResolveHook(ToBlobDescr).
            BindToInput <CloudBlockBlob>((attr, cts) => CreateBlobReference <CloudBlockBlob>(attr, cts));

            rule.SetPostResolveHook(ToBlobDescr).
            BindToInput <CloudPageBlob>((attr, cts) => CreateBlobReference <CloudPageBlob>(attr, cts));

            rule.SetPostResolveHook(ToBlobDescr).
            BindToInput <CloudAppendBlob>((attr, cts) => CreateBlobReference <CloudAppendBlob>(attr, cts));

            rule.SetPostResolveHook(ToBlobDescr).
            BindToInput <ICloudBlob>((attr, cts) => CreateBlobReference <ICloudBlob>(attr, cts));

            // CloudBlobStream's derived functionality is only relevant to writing.
            rule.When("Access", FileAccess.Write).
            SetPostResolveHook(ToBlobDescr).
            BindToInput <CloudBlobStream>(ConvertToCloudBlobStreamAsync);
        }
Example #36
0
            public void Initialize(ExtensionConfigContext context, StorageAccountProvider storageAccountProvider, IContextGetter <IMessageEnqueuedWatcher> contextGetter)
            {
                _accountProvider = storageAccountProvider;
                _messageEnqueuedWatcherGetter = contextGetter;

                // TODO: FACAVAL replace this with queue options. This should no longer be needed.
                //context.ApplyConfig(context.Config.Queues, "queues");

                // IStorageQueueMessage is the core testing interface
                var binding = context.AddBindingRule <QueueAttribute>();

                binding
                .AddConverter <byte[], QueueMessage>(ConvertByteArrayToCloudQueueMessage)
                .AddConverter <string, QueueMessage>(ConvertStringToCloudQueueMessage)
                .AddOpenConverter <OpenType.Poco, QueueMessage>(ConvertPocoToCloudQueueMessage);

                context // global converters, apply to multiple attributes.
                .AddConverter <QueueMessage, byte[]>(ConvertCloudQueueMessageToByteArray)
                .AddConverter <QueueMessage, string>(ConvertCloudQueueMessageToString);

                var builder = new QueueBuilder(this);

                binding.AddValidator(ValidateQueueAttribute);

#pragma warning disable CS0618 // Type or member is obsolete
                binding.SetPostResolveHook(ToWriteParameterDescriptorForCollector)
#pragma warning restore CS0618 // Type or member is obsolete
                .BindToCollector <QueueMessage>(this);

#pragma warning disable CS0618 // Type or member is obsolete
                binding.SetPostResolveHook(ToReadWriteParameterDescriptorForCollector)
#pragma warning restore CS0618 // Type or member is obsolete
                .BindToInput <QueueClient>(builder);

#pragma warning disable CS0618 // Type or member is obsolete
                binding.SetPostResolveHook(ToReadWriteParameterDescriptorForCollector)
#pragma warning restore CS0618 // Type or member is obsolete
                .BindToInput <QueueClient>(builder);
            }
        public static IBindingProvider Create(
            INameResolver nameResolver,
            ILoggerFactory loggerFactory,
            IStorageAccountProvider storageAccountProvider,
            IExtensionTypeLocator extensionTypeLocator,
            IContextGetter <IBlobWrittenWatcher> blobWrittenWatcherGetter,
            IExtensionRegistry extensions)
        {
            List <IBindingProvider> innerProviders = new List <IBindingProvider>();

            innerProviders.Add(new BlobAttributeBindingProvider(nameResolver, storageAccountProvider, extensionTypeLocator, blobWrittenWatcherGetter));

            // add any registered extension binding providers
            // Queue and Table bindings were added as an extension, so those rules get included here.
            foreach (IBindingProvider provider in extensions.GetExtensions(typeof(IBindingProvider)))
            {
                innerProviders.Add(provider);
            }

            innerProviders.Add(new CloudStorageAccountBindingProvider(storageAccountProvider));
            innerProviders.Add(new CancellationTokenBindingProvider());

            // The TraceWriter binder handles all remaining TraceWriter/TextWriter parameters. It must come after the
            // Blob binding provider; otherwise bindings like Do([Blob("a/b")] TextWriter blob) wouldn't work.
            innerProviders.Add(new TraceWriterBindingProvider(loggerFactory));

            innerProviders.Add(new LoggerBindingProvider(loggerFactory));

            ContextAccessor <IBindingProvider> bindingProviderAccessor = new ContextAccessor <IBindingProvider>();

            innerProviders.Add(new RuntimeBindingProvider(bindingProviderAccessor));
            innerProviders.Add(new DataBindingProvider());

            IBindingProvider bindingProvider = new CompositeBindingProvider(innerProviders);

            bindingProviderAccessor.SetValue(bindingProvider);
            return(bindingProvider);
        }
Example #38
0
        public BlobAttributeBindingProvider(INameResolver nameResolver, IStorageAccountProvider accountProvider,
                                            IExtensionTypeLocator extensionTypeLocator, IContextGetter <IBlobWrittenWatcher> blobWrittenWatcherGetter)
        {
            if (accountProvider == null)
            {
                throw new ArgumentNullException("accountProvider");
            }

            if (extensionTypeLocator == null)
            {
                throw new ArgumentNullException("extensionTypeLocator");
            }

            if (blobWrittenWatcherGetter == null)
            {
                throw new ArgumentNullException("blobWrittenWatcherGetter");
            }

            _nameResolver                  = nameResolver;
            _accountProvider               = accountProvider;
            _blobArgumentProvider          = CreateBlobArgumentProvider(extensionTypeLocator.GetCloudBlobStreamBinderTypes(), blobWrittenWatcherGetter);
            _blobContainerArgumentProvider = CreateBlobContainerArgumentProvider();
        }