public void Initialize(ExtensionConfigContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // rules for single entity.
            var original = new TableAttributeBindingProvider(_nameResolver, _accountProvider);

            var builder = new JObjectBuilder(this);

            var binding = context.AddBindingRule <TableAttribute>();

            binding
            .AddConverter <JObject, ITableEntity>(JObjectToTableEntityConverterFunc)
            .AddOpenConverter <object, ITableEntity>(typeof(ObjectToITableEntityConverter <>));

            binding.WhenIsNull(RowKeyProperty)
            .SetPostResolveHook(ToParameterDescriptorForCollector)
            .BindToInput <CloudTable>(builder);

            binding.BindToCollector <ITableEntity>(BuildFromTableAttribute);

            binding.WhenIsNotNull(PartitionKeyProperty).WhenIsNotNull(RowKeyProperty)
            .BindToInput <JObject>(builder);
            binding.BindToInput <JArray>(builder);
            binding.Bind(original);
        }
Esempio n. 2
0
        public void Create_ReturnsBinding_IfImplementsITableEntity()
        {
            var converterMock = CreateConverterMock(typeof(SimpleITableEntity));
            // Act
            IArgumentBinding <TableEntityContext> binding = TableAttributeBindingProvider.TryCreatePocoBinding(_parameters[2], converterMock.Object);

            // Assert
            Assert.NotNull(binding);
        }
Esempio n. 3
0
        public void Create_ReturnsBinding_IfContainsResolvedGenericParameter()
        {
            var converterMock = CreateConverterMock(typeof(GenericClass <SimpleTableEntity>));
            // Act
            IArgumentBinding <TableEntityContext> binding = TableAttributeBindingProvider.TryCreatePocoBinding(_parameters[1], converterMock.Object);

            // Assert
            Assert.NotNull(binding);
        }
Esempio n. 4
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);
        }