public Task<IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } IReadOnlyDictionary<string, Type> bindingDataContract = context.BindingDataContract; string parameterName = context.Parameter.Name; if (bindingDataContract == null || !bindingDataContract.ContainsKey(parameterName)) { return Task.FromResult<IBinding>(null); } Type bindingDataType = bindingDataContract[parameterName]; if (bindingDataType.IsByRef) { return Task.FromResult<IBinding>(null); } if (bindingDataType.ContainsGenericParameters) { return Task.FromResult<IBinding>(null); } IBindingProvider typedProvider = CreateTypedBindingProvider(bindingDataType); return typedProvider.TryCreateAsync(context); }
public async Task<IBinding> TryCreateAsync(BindingProviderContext context) { ParameterInfo parameter = context.Parameter; if (context.Parameter.ParameterType != typeof(CloudStorageAccount)) { return null; } IStorageAccount account = await _accountProvider.GetStorageAccountAsync(context.Parameter, context.CancellationToken); IBinding binding = new CloudStorageAccountBinding(parameter.Name, account.SdkObject); return binding; }
public Task<IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } ParameterInfo parameter = context.Parameter; if (parameter.ParameterType != typeof(IBinder)) { return Task.FromResult<IBinding>(null); } IBinding binding = new RuntimeBinding(context.Parameter, _bindingProviderGetter); return Task.FromResult(binding); }
public Task<IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } ParameterInfo parameter = context.Parameter; if (parameter.ParameterType != typeof(CancellationToken)) { return Task.FromResult<IBinding>(null); } IBinding binding = new CancellationTokenBinding(parameter.Name); return Task.FromResult(binding); }
private IBinding TryCreate(BindingProviderContext context) { ParameterInfo parameter = context.Parameter; var tableAttribute = TypeUtility.GetResolvedAttribute <TableAttribute>(context.Parameter); if (tableAttribute == null) { return(null); } // JArray is bound by the next binding if (parameter.ParameterType == typeof(JArray)) { return(null); } string tableName = Resolve(tableAttribute.TableName); var account = _accountProvider.Get(tableAttribute.Connection, _nameResolver); bool bindsToEntireTable = tableAttribute.RowKey == null; if (bindsToEntireTable) { // This should have been caught by the other rule-based binders. // We never expect this to get thrown. throw new InvalidOperationException("Can't bind Table to type '" + parameter.ParameterType + "'."); } string partitionKey = Resolve(tableAttribute.PartitionKey); string rowKey = Resolve(tableAttribute.RowKey); IBindableTableEntityPath path = BindableTableEntityPath.Create(tableName, partitionKey, rowKey); path.ValidateContractCompatibility(context.BindingDataContract); IArgumentBinding <TableEntityContext> argumentBinding = TryCreatePocoBinding(parameter, _converterManager); if (argumentBinding == null) { throw new InvalidOperationException("Can't bind Table entity to type '" + parameter.ParameterType + "'."); } return(new TableEntityBinding(parameter.Name, argumentBinding, account, path)); }
public static async Task <bool> CanBindAsync(IBindingProvider provider, Attribute attribute, Type t) { ParameterInfo parameterInfo = new FakeParameterInfo( t, new FakeMemberInfo(), attribute, null); BindingProviderContext bindingProviderContext = new BindingProviderContext( parameterInfo, bindingDataContract: null, cancellationToken: CancellationToken.None); try { var binding = await provider.TryCreateAsync(bindingProviderContext); } catch (Exception) { return(false); } return(true); }
/// <inheritdoc/> public Task <IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } // Determine whether we should bind to the current parameter ParameterInfo parameter = context.Parameter; FileAttribute attribute = parameter.GetCustomAttribute <FileAttribute>(inherit: false); if (attribute == null) { return(Task.FromResult <IBinding>(null)); } // first, verify the file path binding (if it contains binding parameters) string path = attribute.Path; if (_nameResolver != null) { path = _nameResolver.ResolveWholeString(path); } BindingTemplate bindingTemplate = BindingTemplate.FromString(path); bindingTemplate.ValidateContractCompatibility(context.BindingDataContract); IEnumerable <Type> types = StreamValueBinder.GetSupportedTypes(attribute.Access) .Union(new Type[] { typeof(FileStream), typeof(FileInfo) }); if (!ValueBinder.MatchParameterType(context.Parameter, types)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Can't bind FileAttribute to type '{0}'.", parameter.ParameterType)); } return(Task.FromResult <IBinding>(new FileBinding(_options, parameter, bindingTemplate))); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } ParameterInfo parameter = context.Parameter; ServiceBusAttribute attribute = parameter.GetCustomAttribute <ServiceBusAttribute>(inherit: false); if (attribute == null) { return(Task.FromResult <IBinding>(null)); } string queueOrTopicName = Resolve(attribute.QueueOrTopicName); IBindableServiceBusPath path = BindableServiceBusPath.Create(queueOrTopicName); ValidateContractCompatibility(path, context.BindingDataContract); IArgumentBinding <ServiceBusEntity> argumentBinding = InnerProvider.TryCreate(parameter); if (argumentBinding == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Can't bind ServiceBus to type '{0}'.", parameter.ParameterType)); } string connectionName = ServiceBusAccount.GetAccountOverrideOrNull(context.Parameter); ServiceBusAccount account = new ServiceBusAccount { MessagingFactory = _config.MessagingProvider.CreateMessagingFactory(queueOrTopicName, connectionName), NamespaceManager = _config.MessagingProvider.CreateNamespaceManager(connectionName) }; IBinding binding = new ServiceBusBinding(parameter.Name, argumentBinding, account, path, attribute.Access); return(Task.FromResult <IBinding>(binding)); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } //Get the resolver starting with method then class MethodInfo method = context.Parameter.Member as MethodInfo; DependencyInjectionConfigAttribute attribute = method.DeclaringType.GetCustomAttribute <DependencyInjectionConfigAttribute>(); if (attribute == null) { throw new MissingAttributeException(); } //Initialize DependencyInjection Activator.CreateInstance(attribute.Config, new Object[] { method.DeclaringType.Name }); //Check if there is a name property InjectAttribute injectAttribute = context.Parameter.GetCustomAttribute <InjectAttribute>(); //This resolves the binding IBinding binding = new InjectBinding(context.Parameter.ParameterType, injectAttribute.Name, method.DeclaringType.Name); return(Task.FromResult(binding)); }
// Called once at each parameter. public async Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context) { // Determine whether we should bind to the current parameter ParameterInfo parameter = context.Parameter; var attribute = parameter.GetCustomAttribute <TAttribute>(inherit: false); if (attribute == null) { return(null); } string path = attribute.Path; var binding = new GenericTriggerbinding(parameter, attribute, _trace, this); var bindingContract = binding.BindingDataContract; BindingProviderContext bindingContext2 = new BindingProviderContext(parameter, bindingContract, context.CancellationToken); var regularBinding = await _provider.BindDirect(bindingContext2); binding.Binding = regularBinding; return(binding); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } ParameterInfo parameter = context.Parameter; EasyTableAttribute attribute = parameter.GetEasyTableAttribute(); if (attribute == null) { return(Task.FromResult <IBinding>(null)); } if (_easyTableConfig.MobileAppUri == null && string.IsNullOrEmpty(attribute.MobileAppUri)) { throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, "The Easy Tables Uri must be set either via a '{0}' app setting, via the EasyTableAttribute.MobileAppUri property or via EasyTableConfiguration.MobileAppUri.", EasyTablesConfiguration.AzureWebJobsMobileAppUriName)); } EasyTableContext easyTableContext = CreateContext(_easyTableConfig, attribute, _nameResolver); IBindingProvider compositeProvider = new CompositeBindingProvider(new IBindingProvider[] { new EasyTableOutputBindingProvider(_jobHostConfig, easyTableContext), new EasyTableQueryBinding(context.Parameter, easyTableContext), new EasyTableTableBinding(parameter, easyTableContext), new EasyTableItemBinding(parameter, easyTableContext, context) }); return(compositeProvider.TryCreateAsync(context)); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { ParameterInfo parameter = context.Parameter; FakeQueueAttribute attribute = parameter.GetCustomAttribute <FakeQueueAttribute>(inherit: false); if (attribute == null) { return(Task.FromResult <IBinding>(null)); } string resolvedName = "fakequeue"; Func <string, FakeQueueClient> invokeStringBinder = (invokeString) => _client; IBinding binding = BindingFactory.BindCollector <FakeQueueData, FakeQueueClient>( parameter, _converterManager, (client, valueBindingContext) => client, resolvedName, invokeStringBinder ); return(Task.FromResult(binding)); }
public async Task Create_HandlesNullableString() { // Arrange IBindingProvider product = new DataBindingProvider(); string parameterName = "p"; Type parameterType = typeof(string); BindingProviderContext context = CreateBindingContext(parameterName, parameterType); // Act IBinding binding = await product.TryCreateAsync(context); // Assert Assert.NotNull(binding); var functionBindingContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None, null); var valueBindingContext = new ValueBindingContext(functionBindingContext, CancellationToken.None); var bindingData = new Dictionary <string, object> { { "p", "Testing" } }; var bindingContext = new BindingContext(valueBindingContext, bindingData); var valueProvider = await binding.BindAsync(bindingContext); var value = await valueProvider.GetValueAsync(); Assert.Equal("Testing", value); bindingData["p"] = null; bindingContext = new BindingContext(valueBindingContext, bindingData); valueProvider = await binding.BindAsync(bindingContext); value = await valueProvider.GetValueAsync(); Assert.Null(value); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } ParameterInfo parameter = context.Parameter; IArgumentBinding <TBindingData> argumentBinding = InnerProvider.TryCreate(parameter); string parameterName = parameter.Name; Type parameterType = parameter.ParameterType; if (argumentBinding == null) { throw new InvalidOperationException( "Can't bind parameter '" + parameterName + "' to type '" + parameterType + "'."); } IBinding binding = new ClassDataBinding <TBindingData>(parameterName, argumentBinding); return(Task.FromResult(binding)); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var parameter = context.Parameter; var attribute = parameter.GetCustomAttribute <FunctionTokenAttribute>(inherit: false); if (attribute == null) { throw new ArgumentNullException(nameof(attribute)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } IBinding binding = new FunctionTokenBinding(options, attribute); return(Task.FromResult(binding)); }
/// <inheritdoc/> public Task <IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } // Determine whether we should bind to the current parameter ParameterInfo parameter = context.Parameter; FileAttribute attribute = parameter.GetCustomAttribute <FileAttribute>(inherit: false); if (attribute == null) { return(Task.FromResult <IBinding>(null)); } if (!CanBind(context)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Can't bind FileAttribute to type '{0}'.", parameter.ParameterType)); } return(Task.FromResult <IBinding>(new FileBinding(_config, parameter))); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { return(Task.FromResult <IBinding>(new InjectAttributeBinding(context.Parameter, _container))); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { IBinding binding = new ServiceFactoryBinding(this._container, context.Parameter.ParameterType); return(Task.FromResult(binding)); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { IBinding binding = new TeamsFxBinding(context, _logger); return(Task.FromResult(binding)); }
public EasyTableItemBinding(ParameterInfo parameter, EasyTableContext context, BindingProviderContext bindingContext) { _parameter = parameter; _context = context; // set up binding for '{ItemId}'-type bindings if (_context.ResolvedId != null) { _bindingTemplate = BindingTemplate.FromString(_context.ResolvedId); _bindingTemplate.ValidateContractCompatibility(bindingContext.BindingDataContract); } }
/// <summary>Tries to create an instance of the <see cref="AzureFunctionsCustomBindingSample.Binding.Document.DocumentBinding"/> class.</summary> /// <param name="context">An object that represents detail of a binding provider context.</param> /// <returns>An instance of the <see cref="AzureFunctionsCustomBindingSample.Binding.Document.DocumentBinding"/> class.</returns> public Task <IBinding> TryCreateAsync(BindingProviderContext context) => Task.FromResult <IBinding>(new DocumentBinding(context.Parameter.ParameterType));
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { return(Task.Run(() => TryCreate(context))); }
public SmtpBinding(ParameterInfo parameter, SmtpAttribute attribute, SmtpConfiguration config, INameResolver nameResolver, BindingProviderContext context) { _parameter = parameter; _attribute = attribute; _config = config; _nameResolver = nameResolver; _smtpClient = new SmtpClient(); _smtpClient.Host = _config.Host; _smtpClient.Port = _config.Port; _smtpClient.EnableSsl = _config.EnableSsl; _smtpClient.Credentials = new NetworkCredential(_config.User, _config.Password); if (!string.IsNullOrEmpty(_attribute.To)) { _toFieldBindingTemplate = CreateBindingTemplate(_attribute.To, context.BindingDataContract); } if (!string.IsNullOrEmpty(_attribute.Cc)) { _ccFieldBindingTemplate = CreateBindingTemplate(_attribute.Cc, context.BindingDataContract); } if (!string.IsNullOrEmpty(_attribute.Bcc)) { _bccFieldBindingTemplate = CreateBindingTemplate(_attribute.Bcc, context.BindingDataContract); } if (!string.IsNullOrEmpty(_attribute.From)) { _fromFieldBindingTemplate = CreateBindingTemplate(_attribute.From, context.BindingDataContract); } if (!string.IsNullOrEmpty(_attribute.Subject)) { _subjectFieldBindingTemplate = CreateBindingTemplate(_attribute.Subject, context.BindingDataContract); } if (!string.IsNullOrEmpty(_attribute.Body)) { _bodyFieldBindingTemplate = CreateBindingTemplate(_attribute.Body, context.BindingDataContract); } }
public Task <IBinding> TryCreateAsync( BindingProviderContext context) { context = context ?? throw new ArgumentNullException(nameof(context)); if (_serviceProvider == null) { var services = new ServiceCollection(); var parameter = context.Parameter; var attribute = parameter.GetCustomAttribute <InjectAttribute>(inherit: false); Type serviceRegistrationType = null; if (serviceRegistrationType == null) { var assembly = context.Parameter.Member.DeclaringType.Assembly; var serviceRegistrationTypeList = assembly .GetExportedTypes() .Where( t => typeof(IServiceRegistration).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract); serviceRegistrationType = serviceRegistrationTypeList.FirstOrDefault(); if (serviceRegistrationTypeList.Take(2).Count() == 2) { serviceRegistrationType = null; _logger.LogWarning($"Found 2 or more service registrations."); } } if (serviceRegistrationType != null) { if (typeof(IServiceRegistration).IsAssignableFrom(serviceRegistrationType)) { var serviceRegistration = (IServiceRegistration)Activator .CreateInstance(serviceRegistrationType); serviceRegistration.ConfigureServices(services); } else { _logger.LogWarning($"Type '{serviceRegistrationType}' must be an implementation of {typeof(IServiceRegistration).AssemblyQualifiedName}."); } } else { _logger.LogWarning($"Did not find a service registration."); } services.AddSingleton <IServiceProviderAccessor>(sp => new ServiceProviderAccessor(sp)); _serviceProvider = services.BuildServiceProvider(); } var binding = new InjectBinding(_serviceProvider, context.Parameter.ParameterType) as IBinding; return(Task.FromResult(binding)); }
public SendGridBinding(ParameterInfo parameter, SendGridAttribute attribute, SendGridConfiguration config, INameResolver nameResolver, BindingProviderContext context) { _parameter = parameter; _attribute = attribute; _config = config; _nameResolver = nameResolver; _sendGrid = new Web(_config.ApiKey); if (!string.IsNullOrEmpty(_attribute.To)) { _toFieldBindingTemplate = CreateBindingTemplate(_attribute.To, context.BindingDataContract); } if (!string.IsNullOrEmpty(_attribute.From)) { _fromFieldBindingTemplate = CreateBindingTemplate(_attribute.From, context.BindingDataContract); } if (!string.IsNullOrEmpty(_attribute.Subject)) { _subjectFieldBindingTemplate = CreateBindingTemplate(_attribute.Subject, context.BindingDataContract); } if (!string.IsNullOrEmpty(_attribute.Text)) { _textFieldBindingTemplate = CreateBindingTemplate(_attribute.Text, context.BindingDataContract); } }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { IBinding binding = CreateBodyBinding(logger, context.Parameter.ParameterType); return(Task.FromResult(binding)); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) => Task.FromResult((IBinding) new InjectBinding(_serviceProvider, context.Parameter.ParameterType));
public SlackBinding(ParameterInfo parameter, SlackAttribute attribute, SlackConfiguration config, INameResolver nameResolver, BindingProviderContext context) { _parameter = parameter; _attribute = attribute; _config = config; _nameResolver = nameResolver; if (!string.IsNullOrEmpty(_attribute.WebHookUrl)) { _webHookUrlBindingTemplate = CreateBindingTemplate(_attribute.WebHookUrl, context.BindingDataContract); } if (!string.IsNullOrEmpty(_attribute.Text)) { _textBindingTemplate = CreateBindingTemplate(_attribute.Text, context.BindingDataContract); } if (!string.IsNullOrEmpty(_attribute.Username)) { _usernameBindingTemplate = CreateBindingTemplate(_attribute.Username, context.BindingDataContract); } if (!string.IsNullOrEmpty(_attribute.IconEmoji)) { _iconEmojiBindingTemplate = CreateBindingTemplate(_attribute.IconEmoji, context.BindingDataContract); } if (!string.IsNullOrEmpty(_attribute.Channel)) { _channelBindingTemplate = CreateBindingTemplate(_attribute.Channel, context.BindingDataContract); } }
/// <summary> /// Gets an <see cref="InjectBinding"/> fro a parameter /// </summary> /// <param name="context"></param> /// <returns></returns> public Task <IBinding> TryCreateAsync(BindingProviderContext context) { return(Task.FromResult <IBinding>(new InjectBinding(InjectionScopeManager, context.Parameter))); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { IBinding binding = new NotificationSubscriberBinding(); return(Task.FromResult(binding)); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { throw new NotImplementedException(); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { IBinding binding = new AccessTokenBinding(authConfig); return(Task.FromResult(binding)); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { IBinding binding = new InjectBinding(_serviceProvider, context.Parameter.ParameterType); return(Task.FromResult(binding)); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { IBinding binding = new FromBodyBinding(this.logger); return(Task.FromResult(binding)); }