private IAsyncCollector <Notification> BuildFromAttribute(NotificationHubAttribute attribute) { string resolvedConnectionString = ResolveConnectionString(ConnectionString, attribute.ConnectionString); string resolvedHubName = ResolveHubName(HubName, attribute.HubName); INotificationHubClientService service = new NotificationHubClientService(resolvedConnectionString, resolvedHubName); return(new NotificationHubAsyncCollector(service, attribute.TagExpression)); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } ParameterInfo parameter = context.Parameter; NotificationHubAttribute attribute = parameter.GetCustomAttribute <NotificationHubAttribute>(inherit: false); if (attribute == null) { return(Task.FromResult <IBinding>(null)); } if (string.IsNullOrEmpty(_config.ConnectionString) && string.IsNullOrEmpty(attribute.ConnectionString)) { throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, "The Notification Hub connection string must be set either via a '{0}' app setting, via the NotificationHubAttribute.ConnectionString property or via NotificationHubsConfiguration.ConnectionString.", NotificationHubsConfiguration.NotificationHubConnectionStringName)); } if (string.IsNullOrEmpty(_config.HubName) && string.IsNullOrEmpty(attribute.HubName)) { throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, "The Notification Hub hub name must be set either via a '{0}' app setting, via the NotificationHubAttribute.HubName property or via NotificationHubsConfiguration.HubName.", NotificationHubsConfiguration.NotificationHubSettingName)); } string resolvedConnectionString = ResolveConnectionString(_config.ConnectionString, attribute.ConnectionString); string resolvedHubName = ResolveHubName(_config.HubName, attribute.HubName); INotificationHubClientService service = new NotificationHubClientService(resolvedConnectionString, resolvedHubName); Func <string, INotificationHubClientService> invokeStringBinder = (invokeString) => service; IBinding binding = BindingFactory.BindCollector( parameter, _converterManager, (nhClientService, valueBindingContext) => new NotificationHubAsyncCollector(service, attribute.TagExpression), "NotificationHubs", invokeStringBinder); return(Task.FromResult(binding)); }