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

                if (string.IsNullOrEmpty(_sendGridConfig.ApiKey))
                {
                    throw new InvalidOperationException(
                              string.Format("The SendGrid ApiKey must be set either via a '{0}' app setting, via a '{0}' environment variable, or directly in code via SendGridConfiguration.ApiKey.",
                                            SendGridConfiguration.AzureWebJobsSendGridApiKeyName));
                }
                _sendGrid = new Web(_sendGridConfig.ApiKey);

                IConverterManager converterManager = context.Config.GetService <IConverterManager>();

                converterManager.AddConverter <JObject, SendGridMessage>(SendGridHelpers.CreateMessage);

                INameResolver    nameResolver   = context.Config.GetService <INameResolver>();
                BindingFactory   factory        = new BindingFactory(nameResolver, converterManager);
                IBindingProvider outputProvider = factory.BindToAsyncCollector <SendGridAttribute, SendGridMessage>((attr) =>
                {
                    return(new SendGridMessageAsyncCollector(_sendGridConfig, attr, _sendGrid));
                });

                IExtensionRegistry extensions = context.Config.GetService <IExtensionRegistry>();

                extensions.RegisterBindingRules <SendGridAttribute>(outputProvider);
            }
        public FunctionIndexProvider(ITypeLocator typeLocator,
                                     ITriggerBindingProvider triggerBindingProvider,
                                     IBindingProvider bindingProvider,
                                     IJobActivator activator,
                                     IFunctionExecutor executor,
                                     IExtensionRegistry extensions,
                                     SingletonManager singletonManager,
                                     TraceWriter trace,
                                     ILoggerFactory loggerFactory)
        {
            if (typeLocator == null)
            {
                throw new ArgumentNullException("typeLocator");
            }

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

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

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

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

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

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

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

            _typeLocator            = typeLocator;
            _triggerBindingProvider = triggerBindingProvider;
            _bindingProvider        = bindingProvider;
            _activator        = activator;
            _executor         = executor;
            _extensions       = extensions;
            _singletonManager = singletonManager;
            _trace            = trace;
            _loggerFactory    = loggerFactory;
        }
        public static FunctionIndexer Create(CloudStorageAccount account          = null, INameResolver nameResolver = null,
                                             IExtensionRegistry extensionRegistry = null, TraceWriter traceWriter    = null, ILoggerFactory loggerFactory = null)
        {
            IStorageAccountProvider storageAccountProvider = GetStorageAccountProvider(account);

            var config   = TestHelpers.NewConfig(storageAccountProvider, nameResolver, extensionRegistry);
            var services = config.CreateStaticServices();

            ITriggerBindingProvider triggerBindingProvider = services.GetService <ITriggerBindingProvider>();
            IBindingProvider        bindingProvider        = services.GetService <IBindingProvider>();
            IJobActivator           activator = services.GetService <IJobActivator>();

            extensionRegistry = services.GetService <IExtensionRegistry>();

            SingletonManager              singletonManager     = new SingletonManager();
            TraceWriter                   logger               = traceWriter ?? new TestTraceWriter(TraceLevel.Verbose);
            IWebJobsExceptionHandler      exceptionHandler     = new WebJobsExceptionHandler();
            IFunctionOutputLoggerProvider outputLoggerProvider = new NullFunctionOutputLoggerProvider();
            IFunctionOutputLogger         outputLogger         = outputLoggerProvider.GetAsync(CancellationToken.None).Result;

            IFunctionExecutor executor = new FunctionExecutor(new NullFunctionInstanceLogger(), outputLogger, exceptionHandler, logger);

            return(new FunctionIndexer(triggerBindingProvider, bindingProvider, DefaultJobActivator.Instance, executor,
                                       extensionRegistry, singletonManager, logger, loggerFactory));
        }
Example #4
0
        /// <inheritdoc />
        public void Initialize(ExtensionConfigContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            INameResolver nameResolver = context.Config.NameResolver;

            _defaultApiKey = nameResolver.Resolve(AzureWebJobsSendGridApiKeyName);

            IConverterManager converterManager = context.Config.GetService <IConverterManager>();

            converterManager.AddConverter <string, Mail>(SendGridHelpers.CreateMessage);
            converterManager.AddConverter <JObject, Mail>(SendGridHelpers.CreateMessage);

            BindingFactory   factory        = new BindingFactory(nameResolver, converterManager);
            IBindingProvider outputProvider = factory.BindToAsyncCollector <SendGridAttribute, Mail>((attr) =>
            {
                string apiKey            = FirstOrDefault(attr.ApiKey, ApiKey, _defaultApiKey);
                ISendGridClient sendGrid = _sendGridClientCache.GetOrAdd(apiKey, a => ClientFactory.Create(a));
                return(new SendGridMailAsyncCollector(this, attr, sendGrid));
            });

            IExtensionRegistry extensions = context.Config.GetService <IExtensionRegistry>();

            extensions.RegisterBindingRules <SendGridAttribute>(ValidateBinding, nameResolver, outputProvider);
        }
Example #5
0
        public FunctionIndexer(ITriggerBindingProvider triggerBindingProvider, IBindingProvider bindingProvider, IJobActivator activator, IFunctionExecutor executor, IExtensionRegistry extensions)
        {
            if (triggerBindingProvider == null)
            {
                throw new ArgumentNullException("triggerBindingProvider");
            }

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

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

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

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

            _triggerBindingProvider = triggerBindingProvider;
            _bindingProvider        = bindingProvider;
            _activator         = activator;
            _executor          = executor;
            _jobTypeAssemblies = new HashSet <Assembly>(GetJobTypeAssemblies(extensions, typeof(ITriggerBindingProvider), typeof(IBindingProvider)));
        }
        /// <inheritdoc />
        public void Initialize(ExtensionConfigContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            INameResolver     nameResolver     = context.Config.GetService <INameResolver>();
            IConverterManager converterManager = context.Config.GetService <IConverterManager>();

            BindingFactory factory = new BindingFactory(nameResolver, converterManager);

            IBindingProvider outputProvider = factory.BindToGenericAsyncCollector <MobileTableAttribute>(BindForOutput, ThrowIfInvalidOutputItemType);

            IBindingProvider clientProvider = factory.BindToExactType <MobileTableAttribute, IMobileServiceClient>(BindForClient);

            IBindingProvider queryProvider = factory.BindToGenericItem <MobileTableAttribute>(BindForQueryAsync);

            queryProvider = factory.AddFilter <MobileTableAttribute>(IsQueryType, queryProvider);

            IBindingProvider jObjectTableProvider = factory.BindToExactType <MobileTableAttribute, IMobileServiceTable>(BindForTable);

            IBindingProvider tableProvider = factory.BindToGenericItem <MobileTableAttribute>(BindForTableAsync);

            tableProvider = factory.AddFilter <MobileTableAttribute>(IsTableType, tableProvider);

            IBindingProvider itemProvider = factory.BindToGenericValueProvider <MobileTableAttribute>(BindForItemAsync);

            itemProvider = factory.AddFilter <MobileTableAttribute>(IsItemType, itemProvider);

            IExtensionRegistry extensions = context.Config.GetService <IExtensionRegistry>();

            extensions.RegisterBindingRules <MobileTableAttribute>(ValidateMobileAppUri, nameResolver, outputProvider, clientProvider, jObjectTableProvider, queryProvider, tableProvider, itemProvider);
        }
Example #7
0
        /// <summary>
        /// Registers the specified binding extension. The instance must implement one of the supported
        /// binding interfaces (e.g. <see cref="IBindingProvider"/> or <see cref="ITriggerBindingProvider"/>).
        /// </summary>
        /// <param name="config">The <see cref="JobHostConfiguration"/> to register the extension with.</param>
        /// <param name="extension">The extension to register.</param>
        public static void RegisterBindingExtension(this JobHostConfiguration config, object extension)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (extension == null)
            {
                throw new ArgumentNullException("extension");
            }

            IBindingProvider bindingProvider = extension as IBindingProvider;

            if (bindingProvider != null)
            {
                config.RegisterExtension <IBindingProvider>(bindingProvider);
                return;
            }

            ITriggerBindingProvider triggerBindingProvider = extension as ITriggerBindingProvider;

            if (triggerBindingProvider != null)
            {
                config.RegisterExtension <ITriggerBindingProvider>(triggerBindingProvider);
                return;
            }

            throw new ArgumentException(string.Format("'{0}' is not a valid binding extension.", extension.GetType()));
        }
Example #8
0
        public void Initialize(ExtensionConfigContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            INameResolver nameResolver = context.Config.GetService <INameResolver>();

            _defaultAccountSid = nameResolver.Resolve(AzureWebJobsTwilioAccountSidKeyName);
            _defaultAuthToken  = nameResolver.Resolve(AzureWebJobsTwilioAccountAuthTokenName);

            IConverterManager converterManager = context.Config.GetService <IConverterManager>();

            converterManager.AddConverter <JObject, SMSMessage>(CreateSmsMessage);

            BindingFactory   factory        = new BindingFactory(nameResolver, converterManager);
            IBindingProvider outputProvider = factory.BindToAsyncCollector <TwilioSmsAttribute, SMSMessage>((attr) =>
            {
                return(new TwilioSmsMessageAsyncCollector(CreateContext(attr)));
            });

            IExtensionRegistry extensions = context.Config.GetService <IExtensionRegistry>();

            extensions.RegisterBindingRules <TwilioSmsAttribute>(ValidateBinding, nameResolver, outputProvider);
        }
Example #9
0
        public Task <IBinding> TryCreateAsync(BindingProviderContext 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));
        }
Example #10
0
 public JobHostMetadataProvider(IFunctionIndexProvider functionIndexProvider, IExtensionRegistry extensionRegistry, IBindingProvider bindingProvider, IConverterManager converter)
 {
     _functionIndexProvider = functionIndexProvider;
     _extensionRegistry = extensionRegistry;
     _bindingProvider = bindingProvider;
     _converter = converter;
 }
        public Task <JobHostContext> CreateAndLogHostStartedAsync(CancellationToken shutdownToken,
                                                                  CancellationToken cancellationToken)
        {
            IFunctionIndexProvider functionIndexProvider = null;
            IHostIdProvider        hostIdProvider        = _hostId != null ? (IHostIdProvider) new FixedHostIdProvider(_hostId)
                : new DynamicHostIdProvider(_storageAccountProvider, () => functionIndexProvider);
            IExtensionTypeLocator                     extensionTypeLocator           = new ExtensionTypeLocator(_typeLocator);
            IBackgroundExceptionDispatcher            backgroundExceptionDispatcher  = BackgroundExceptionDispatcher.Instance;
            ContextAccessor <IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor =
                new ContextAccessor <IMessageEnqueuedWatcher>();
            ContextAccessor <IBlobWrittenWatcher> blobWrittenWatcherAccessor =
                new ContextAccessor <IBlobWrittenWatcher>();
            ISharedContextProvider  sharedContextProvider  = new SharedContextProvider();
            ITriggerBindingProvider triggerBindingProvider = DefaultTriggerBindingProvider.Create(_nameResolver,
                                                                                                  _storageAccountProvider, _serviceBusAccountProvider, extensionTypeLocator, hostIdProvider,
                                                                                                  _queueConfiguration, backgroundExceptionDispatcher, messageEnqueuedWatcherAccessor,
                                                                                                  blobWrittenWatcherAccessor, sharedContextProvider, _consoleProvider.Out);
            IBindingProvider bindingProvider = DefaultBindingProvider.Create(_nameResolver, _storageAccountProvider,
                                                                             _serviceBusAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor,
                                                                             blobWrittenWatcherAccessor);

            functionIndexProvider = new FunctionIndexProvider(_typeLocator, triggerBindingProvider, bindingProvider,
                                                              _activator);
            DefaultLoggerProvider loggerProvider = new DefaultLoggerProvider(_storageAccountProvider);

            return(CreateAndLogHostStartedAsync(_storageAccountProvider, functionIndexProvider, bindingProvider,
                                                hostIdProvider, loggerProvider, loggerProvider, loggerProvider, _queueConfiguration,
                                                backgroundExceptionDispatcher, _consoleProvider,
                                                shutdownToken, cancellationToken));
        }
        /// <summary>
        /// Add a general binder.
        /// </summary>
        /// <param name="binder"></param>
        /// <returns></returns>
        public FluentBinder Bind(IBindingProvider binder)
        {
            if (this._hook != null)
            {
                var fluidBinder = (FluentBindingProvider <TAttribute>)binder;
                fluidBinder.BuildParameterDescriptor = _hook;
                _hook = null;
            }

            // Apply filters
            if (this._filterDescription.Count > 0)
            {
                binder = new FilteringBindingProvider <TAttribute>(
                    _configuration,
                    this._nameResolver,
                    binder,
                    FilterNode.And(this._filterDescription));

                this._filterDescription.Clear();
            }

            var opts = new FluentBinder(_configuration, _nameResolver, binder);

            _binders.Add(opts);
            return(opts);
        }
 public static void Initialize(IBindingProvider bindingProvider          = null, IBindingManager bindingManager = null,
                               IBindingResourceResolver resourceResolver = null, IBindingMemberProvider memberProvider = null, IVisualTreeManager visualTreeManager  = null,
                               IWeakEventManager weakEventManager        = null, IObserverProvider observerProvider    = null, IBindingContextManager contextManager = null, IBindingErrorProvider errorProvider = null,
                               Func <IBindingMemberInfo, Type, object, object> converter = null, Func <string, IBindingPath> bindingPathFactory = null,
                               Func <Type, string, IBindingMemberInfo> findUpdateEvent   = null, Func <CultureInfo> bindingCultureInfo          = null, IDictionary <string, IBindingBehavior> bindingModeBehaviors = null)
 {
     ValueConverter     = converter ?? ((info, type, arg3) => arg3);
     BindingProvider    = bindingProvider ?? new BindingProvider();
     BindingManager     = bindingManager ?? new BindingManager();
     ResourceResolver   = resourceResolver ?? new BindingResourceResolver();
     MemberProvider     = memberProvider ?? new BindingMemberProvider();
     VisualTreeManager  = visualTreeManager ?? new VisualTreeManager();
     WeakEventManager   = weakEventManager ?? new WeakEventManager();
     ObserverProvider   = observerProvider ?? new ObserverProvider();
     ContextManager     = contextManager ?? new BindingContextManager();
     BindingPathFactory = bindingPathFactory ?? BindingPathFactoryDefaultImpl;
     UpdateEventFinder  = findUpdateEvent ?? FindUpdateEventDefaultImpl;
     BindingCultureInfo = bindingCultureInfo ?? BindingCultureInfoDefaultImpl;
     ErrorProvider      = errorProvider;
     if (bindingModeBehaviors == null)
     {
         InitializeDefaultBindingModeBehaviors();
     }
     else
     {
         foreach (var behavior in bindingModeBehaviors)
         {
             BindingModeToBehavior[behavior.Key] = behavior.Value;
         }
     }
 }
Example #14
0
        public FunctionIndexProvider(ITypeLocator typeLocator,
                                     ITriggerBindingProvider triggerBindingProvider,
                                     IBindingProvider bindingProvider,
                                     IJobActivator activator,
                                     IFunctionExecutor executor,
                                     IExtensionRegistry extensions,
                                     SingletonManager singletonManager,
                                     ILoggerFactory loggerFactory,
                                     SharedQueueHandler sharedQueue,
                                     TimeoutAttribute defaultTimeout,
                                     bool allowPartialHostStartup = false)
        {
            _typeLocator            = typeLocator ?? throw new ArgumentNullException(nameof(typeLocator));
            _triggerBindingProvider = triggerBindingProvider ?? throw new ArgumentNullException(nameof(triggerBindingProvider));
            _bindingProvider        = bindingProvider ?? throw new ArgumentNullException(nameof(bindingProvider));
            _activator        = activator ?? throw new ArgumentNullException(nameof(activator));
            _executor         = executor ?? throw new ArgumentNullException(nameof(executor));
            _extensions       = extensions ?? throw new ArgumentNullException(nameof(extensions));
            _singletonManager = singletonManager ?? throw new ArgumentNullException(nameof(singletonManager));
            _sharedQueue      = sharedQueue ?? throw new ArgumentNullException(nameof(sharedQueue));

            _loggerFactory           = loggerFactory;
            _defaultTimeout          = defaultTimeout;
            _allowPartialHostStartup = allowPartialHostStartup;
        }
Example #15
0
 public Wrapper(
     IBindingProvider inner,
     Func <string, FunctionDescriptor> funcLookup)
 {
     _inner      = inner;
     _funcLookup = funcLookup;
 }
Example #16
0
 public void Apply(IBindingProvider bindings, IntPtr data)
 {
     foreach (var binding in Bindings)
     {
         binding.Apply(bindings, data);
     }
 }
Example #17
0
        public static FunctionIndexer Create(CloudStorageAccount account, INameResolver nameResolver = null)
        {
            IStorageAccount         storageAccount         = account != null ? new StorageAccount(account) : null;
            IStorageAccountProvider storageAccountProvider = new SimpleStorageAccountProvider
            {
                StorageAccount = account
            };
            IServiceBusAccountProvider serviceBusAccountProvider = null;
            IExtensionTypeLocator      extensionTypeLocator      = new NullExtensionTypeLocator();
            ContextAccessor <IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor =
                new ContextAccessor <IMessageEnqueuedWatcher>();
            ContextAccessor <IBlobWrittenWatcher> blobWrittenWatcherAccessor =
                new ContextAccessor <IBlobWrittenWatcher>();
            ISharedContextProvider  sharedContextProvider  = new SharedContextProvider();
            ITriggerBindingProvider triggerBindingProvider = DefaultTriggerBindingProvider.Create(nameResolver,
                                                                                                  storageAccountProvider, serviceBusAccountProvider, extensionTypeLocator,
                                                                                                  new FixedHostIdProvider("test"), new SimpleQueueConfiguration(maxDequeueCount: 5),
                                                                                                  BackgroundExceptionDispatcher.Instance, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor,
                                                                                                  sharedContextProvider, TextWriter.Null);
            IBindingProvider bindingProvider = DefaultBindingProvider.Create(nameResolver, storageAccountProvider,
                                                                             serviceBusAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor,
                                                                             blobWrittenWatcherAccessor);

            return(new FunctionIndexer(triggerBindingProvider, bindingProvider, DefaultJobActivator.Instance));
        }
Example #18
0
 public ValidatingWrapperBindingProvider(Action <TAttribute, Type> validator, IConfiguration configuration, INameResolver nameResolver, IBindingProvider inner)
 {
     _validator     = validator;
     _inner         = inner;
     _configuration = configuration;
     _nameResolver  = nameResolver;
 }
        public FunctionIndexProvider(ITypeLocator typeLocator,
                                     ITriggerBindingProvider triggerBindingProvider,
                                     IBindingProvider bindingProvider,
                                     IJobActivator activator)
        {
            if (typeLocator == null)
            {
                throw new ArgumentNullException("typeLocator");
            }

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

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

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

            _typeLocator            = typeLocator;
            _triggerBindingProvider = triggerBindingProvider;
            _bindingProvider        = bindingProvider;
            _activator = activator;
        }
        /// <inheritdoc />
        public void Initialize(ExtensionConfigContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            INameResolver     nameResolver     = context.Config.GetService <INameResolver>();
            IConverterManager converterManager = context.Config.GetService <IConverterManager>();

            // Use this if there is no other connection string set.
            _defaultConnectionString = nameResolver.Resolve(AzureWebJobsDocumentDBConnectionStringName);

            BindingFactory factory = new BindingFactory(nameResolver, converterManager);

            IBindingProvider outputProvider = factory.BindToGenericAsyncCollector <DocumentDBAttribute>((attr, t) => BindForOutput(attr, t, context.Trace));

            IBindingProvider clientProvider = factory.BindToExactType <DocumentDBAttribute, DocumentClient>(BindForClient);

            IBindingProvider itemProvider = factory.BindToGenericValueProvider <DocumentDBAttribute>((attr, t) => BindForItemAsync(attr, t, context.Trace));

            IExtensionRegistry extensions = context.Config.GetService <IExtensionRegistry>();

            extensions.RegisterBindingRules <DocumentDBAttribute>(ValidateConnection, nameResolver, outputProvider, clientProvider, itemProvider);
        }
Example #21
0
        /// <summary>
        /// Ctor.
        /// </summary>
        public Notifier(ILogger logger, IBindingProvider bindingProvider, ConsulServicesProvider consulServiceProvider)
        {
            _bindingProvider       = bindingProvider;
            _consulServiceProvider = consulServiceProvider;
            _logger = logger.ForContext <Notifier>();

            InitializeConfiguraiton();
        }
        public FunctionIndexProvider(ITypeLocator typeLocator,
            ITriggerBindingProvider triggerBindingProvider,
            IBindingProvider bindingProvider,
            IJobActivator activator,
            IFunctionExecutor executor,
            IExtensionRegistry extensions,
            SingletonManager singletonManager,
            TraceWriter trace)
        {
            if (typeLocator == null)
            {
                throw new ArgumentNullException("typeLocator");
            }

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

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

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

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

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

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

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

            _typeLocator = typeLocator;
            _triggerBindingProvider = triggerBindingProvider;
            _bindingProvider = bindingProvider;
            _activator = activator;
            _executor = executor;
            _extensions = extensions;
            _singletonManager = singletonManager;
            _trace = trace;
        }
Example #23
0
        public static IBindingProvider SetPostResolveHook <TAttribute>(
            this IBindingProvider binder,
            Func <TAttribute, ParameterInfo, INameResolver, ParameterDescriptor> buildParameterDescriptor = null)
        {
            var fluidBinder = (FluentBindingProvider <TAttribute>)binder;

            fluidBinder.BuildParameterDescriptor = buildParameterDescriptor;
            return(binder);
        }
Example #24
0
 public FilteringBindingProvider(
     Func <TAttribute, Type, bool> predicate,
     INameResolver nameResolver,
     IBindingProvider inner)
 {
     _predicate    = predicate;
     _nameResolver = nameResolver;
     _inner        = inner;
 }
Example #25
0
 public FilteringBindingProvider(
     INameResolver nameResolver,
     IBindingProvider inner,
     FilterNode description)
 {
     _nameResolver = nameResolver;
     _inner        = inner;
     _description  = description;
 }
Example #26
0
        public FunctionIndexer(
            ITriggerBindingProvider triggerBindingProvider,
            IBindingProvider bindingProvider,
            IJobActivator activator,
            IFunctionExecutor executor,
            IExtensionRegistry extensions,
            SingletonManager singletonManager,
            TraceWriter trace,
            ILoggerFactory loggerFactory,
            INameResolver nameResolver = null)
        {
            if (triggerBindingProvider == null)
            {
                throw new ArgumentNullException("triggerBindingProvider");
            }

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

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

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

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

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

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

            _triggerBindingProvider = triggerBindingProvider;
            _bindingProvider        = bindingProvider;
            _activator              = activator;
            _executor               = executor;
            _singletonManager       = singletonManager;
            _jobAttributeAssemblies = GetJobAttributeAssemblies(extensions);
            _nameResolver           = nameResolver;
            _trace  = trace;
            _logger = loggerFactory?.CreateLogger(LogCategories.Startup);
        }
Example #27
0
        public void Apply(IBindingProvider bindings, IntPtr data)
        {
            var structure = bindings[Key];

            if (structure != null)
            {
                // No deletion of old data because we only allow value types.
                Marshal.StructureToPtr(structure, data + Offset, false);
            }
        }
Example #28
0
        public TargetPlatform(IEditorProvider editorProvider, IResourceProvider resourceProvider, IBindingProvider bindingProvider)
            : this(editorProvider, resourceProvider)
        {
            if (bindingProvider == null)
            {
                throw new ArgumentNullException(nameof(bindingProvider));
            }

            BindingProvider = bindingProvider;
        }
 public XmlSiteMapResultFactoryContainer(ConfigurationSettings settings)
 {
     var siteMapLoaderContainer = new SiteMapLoaderContainer(settings);
     this.siteMapLoader = siteMapLoaderContainer.ResolveSiteMapLoader();
     this.mvcContextFactory = new MvcContextFactory();
     this.bindingFactory = new BindingFactory();
     this.bindingProvider = new BindingProvider(this.bindingFactory, this.mvcContextFactory);
     this.urlPath = new UrlPath(this.mvcContextFactory, this.bindingProvider);
     this.cultureContextFactory = new CultureContextFactory();
 }
Example #30
0
        public FunctionIndexer(
            ITriggerBindingProvider triggerBindingProvider,
            IBindingProvider bindingProvider,
            IJobActivator activator,
            IFunctionExecutor executor,
            IExtensionRegistry extensions,
            SingletonManager singletonManager,
            ILoggerFactory loggerFactory,
            INameResolver nameResolver      = null,
            SharedQueueHandler sharedQueue  = null,
            TimeoutAttribute defaultTimeout = null,
            bool allowPartialHostStartup    = false)
        {
            if (triggerBindingProvider == null)
            {
                throw new ArgumentNullException("triggerBindingProvider");
            }

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

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

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

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

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

            _triggerBindingProvider = triggerBindingProvider;
            _bindingProvider        = bindingProvider;
            _activator              = activator;
            _executor               = executor;
            _singletonManager       = singletonManager;
            _jobAttributeAssemblies = GetJobAttributeAssemblies(extensions);
            _nameResolver           = nameResolver;
            _logger                  = loggerFactory?.CreateLogger(LogCategories.Startup);
            _sharedQueue             = sharedQueue;
            _defaultTimeout          = defaultTimeout;
            _allowPartialHostStartup = allowPartialHostStartup;
        }
 public FilteringBindingProvider(
     Func <TAttribute, Type, bool> predicate,
     INameResolver nameResolver,
     IBindingProvider inner,
     string description = null)
 {
     _predicate    = predicate;
     _nameResolver = nameResolver;
     _inner        = inner;
     _description  = description;
 }
Example #32
0
 public FilteringBindingProvider(
     IConfiguration configuration,
     INameResolver nameResolver,
     IBindingProvider inner,
     FilterNode description)
 {
     _configuration = configuration;
     _nameResolver  = nameResolver;
     _inner         = inner;
     _description   = description;
 }
Example #33
0
		public void RegisterBinding(IBindingProvider bindingProvider)
		{
			if (bindingProvider == null)
			{
				throw new ArgumentNullException("bindingProvider");
			}
			else if (m_bindingProviders.Contains(bindingProvider))
			{
				throw new ArgumentException("BindingProvider has already been registered.");
			}

			m_bindingProviders.Insert(0, bindingProvider);
		}
Example #34
0
        public UrlPath(
            IMvcContextFactory mvcContextFactory,
            IBindingProvider bindingProvider
            )
        {
            if (mvcContextFactory == null)
                throw new ArgumentNullException("mvcContextFactory");
            if (bindingProvider == null)
                throw new ArgumentNullException("bindingProvider");

            this.mvcContextFactory = mvcContextFactory;
            this.bindingProvider = bindingProvider;
        }
 public SiteMapLoaderContainer(ConfigurationSettings settings)
 {
     // Singleton instances
     if (settings.EnableSiteMapFile)
     {
         this.absoluteFileName = HostingEnvironment.MapPath(settings.SiteMapFileName);
     }
     this.mvcContextFactory = new MvcContextFactory();
     #if NET35
     this.siteMapCache = new SiteMapCache(new AspNetCacheProvider<ISiteMap>(this.mvcContextFactory));
     #else
     this.siteMapCache = new SiteMapCache(new RuntimeCacheProvider<ISiteMap>(System.Runtime.Caching.MemoryCache.Default));
     #endif
     this.cacheDependency = this.ResolveCacheDependency(settings);
     this.requestCache = this.mvcContextFactory.GetRequestCache();
     this.bindingFactory = new BindingFactory();
     this.bindingProvider = new BindingProvider(this.bindingFactory, this.mvcContextFactory);
     this.urlPath = new UrlPath(this.mvcContextFactory, this.bindingProvider);
     this.siteMapCacheKeyGenerator = new SiteMapCacheKeyGenerator(this.mvcContextFactory);
     this.siteMapCacheKeyToBuilderSetMapper = new SiteMapCacheKeyToBuilderSetMapper();
     this.reservedAttributeNameProvider = new ReservedAttributeNameProvider(settings.AttributesToIgnore);
     var siteMapNodeFactoryContainer = new SiteMapNodeFactoryContainer(settings, this.mvcContextFactory, this.urlPath, this.reservedAttributeNameProvider);
     this.siteMapNodeToParentRelationFactory = new SiteMapNodeToParentRelationFactory();
     this.nodeKeyGenerator = new NodeKeyGenerator();
     this.siteMapNodeFactory = siteMapNodeFactoryContainer.ResolveSiteMapNodeFactory();
     this.siteMapNodeCreatorFactory = this.ResolveSiteMapNodeCreatorFactory();
     this.cultureContextFactory = new CultureContextFactory();
     this.dynamicSiteMapNodeBuilderFactory = new DynamicSiteMapNodeBuilderFactory(this.siteMapNodeCreatorFactory, this.cultureContextFactory);
     this.siteMapHierarchyBuilder = new SiteMapHierarchyBuilder();
     this.siteMapNodeHelperFactory = this.ResolveSiteMapNodeHelperFactory();
     this.siteMapNodeVisitor = this.ResolveSiteMapNodeVisitor(settings);
     this.siteMapXmlNameProvider = new SiteMapXmlNameProvider();
     this.attributeAssemblyProviderFactory = new AttributeAssemblyProviderFactory();
     this.mvcSiteMapNodeAttributeDefinitionProvider = new MvcSiteMapNodeAttributeDefinitionProvider();
     this.siteMapNodeProvider = this.ResolveSiteMapNodeProvider(settings);
     this.siteMapBuiderSetStrategy = this.ResolveSiteMapBuilderSetStrategy(settings);
     var siteMapFactoryContainer = new SiteMapFactoryContainer(settings, this.mvcContextFactory, this.urlPath);
     this.siteMapFactory = siteMapFactoryContainer.ResolveSiteMapFactory();
     this.siteMapCreator = new SiteMapCreator(this.siteMapCacheKeyToBuilderSetMapper, this.siteMapBuiderSetStrategy, this.siteMapFactory);
 }
        public static async Task<JobHostContext> CreateAndLogHostStartedAsync(
            JobHost host,
            IStorageAccountProvider storageAccountProvider,
            IQueueConfiguration queueConfiguration,
            ITypeLocator typeLocator,
            IJobActivator activator,
            INameResolver nameResolver,
            IConsoleProvider consoleProvider,
            JobHostConfiguration config,
            CancellationToken shutdownToken,
            CancellationToken cancellationToken,
            IHostIdProvider hostIdProvider = null,
            FunctionExecutor functionExecutor = null,
            IFunctionIndexProvider functionIndexProvider = null,
            IBindingProvider bindingProvider = null,
            IHostInstanceLoggerProvider hostInstanceLogerProvider = null,
            IFunctionInstanceLoggerProvider functionInstanceLoggerProvider = null,
            IFunctionOutputLoggerProvider functionOutputLoggerProvider = null,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher = null,
            SingletonManager singletonManager = null)
        {
            if (hostIdProvider == null)
            {
                hostIdProvider = new DynamicHostIdProvider(storageAccountProvider, () => functionIndexProvider);
            }

            IExtensionTypeLocator extensionTypeLocator = new ExtensionTypeLocator(typeLocator);
            if (backgroundExceptionDispatcher == null)
            {
                backgroundExceptionDispatcher = BackgroundExceptionDispatcher.Instance;
            }
            ContextAccessor<IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor = new ContextAccessor<IMessageEnqueuedWatcher>();
            ContextAccessor<IBlobWrittenWatcher> blobWrittenWatcherAccessor = new ContextAccessor<IBlobWrittenWatcher>();
            ISharedContextProvider sharedContextProvider = new SharedContextProvider();

            // Create a wrapper TraceWriter that delegates to both the user 
            // TraceWriter specified on Config (if present), as well as to Console
            TraceWriter trace = new ConsoleTraceWriter(config.Tracing, consoleProvider.Out);

            // Register system services with the service container
            config.AddService<INameResolver>(nameResolver);

            ExtensionConfigContext context = new ExtensionConfigContext
            {
                Config = config,
                Trace = trace,
                Host = host
            };
            InvokeExtensionConfigProviders(context);

            IExtensionRegistry extensions = config.GetExtensions();
            ITriggerBindingProvider triggerBindingProvider = DefaultTriggerBindingProvider.Create(nameResolver,
                storageAccountProvider, extensionTypeLocator, hostIdProvider, queueConfiguration, backgroundExceptionDispatcher,
                messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, sharedContextProvider, extensions, trace);

            if (bindingProvider == null)
            {
                bindingProvider = DefaultBindingProvider.Create(nameResolver, storageAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, extensions);
            }

            DefaultLoggerProvider loggerProvider = new DefaultLoggerProvider(storageAccountProvider, trace);

            if (singletonManager == null)
            {
                singletonManager = new SingletonManager(storageAccountProvider, backgroundExceptionDispatcher, config.Singleton, trace, config.NameResolver);
            }
            
            using (CancellationTokenSource combinedCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, shutdownToken))
            {
                CancellationToken combinedCancellationToken = combinedCancellationSource.Token;

                await WriteSiteExtensionManifestAsync(combinedCancellationToken);

                IStorageAccount dashboardAccount = await storageAccountProvider.GetDashboardAccountAsync(combinedCancellationToken);

                IHostInstanceLogger hostInstanceLogger = null;
                if (hostInstanceLogerProvider != null)
                {
                    hostInstanceLogger = await hostInstanceLogerProvider.GetAsync(combinedCancellationToken);
                }
                else
                {
                    hostInstanceLogger = await((IHostInstanceLoggerProvider)loggerProvider).GetAsync(combinedCancellationToken);
                }

                IFunctionInstanceLogger functionInstanceLogger = null;
                if (functionInstanceLoggerProvider != null)
                {
                    functionInstanceLogger = await functionInstanceLoggerProvider.GetAsync(combinedCancellationToken);
                }
                else
                {
                    functionInstanceLogger = (IFunctionInstanceLogger)(await((IFunctionInstanceLoggerProvider)loggerProvider).GetAsync(combinedCancellationToken));
                }

                IFunctionOutputLogger functionOutputLogger = null;
                if (functionOutputLoggerProvider != null)
                {
                    functionOutputLogger = await functionOutputLoggerProvider.GetAsync(combinedCancellationToken);
                }
                else
                {
                    functionOutputLogger = (IFunctionOutputLogger)(await((IFunctionOutputLoggerProvider)loggerProvider).GetAsync(combinedCancellationToken));
                }

                if (functionExecutor == null)
                {
                    functionExecutor = new FunctionExecutor(functionInstanceLogger, functionOutputLogger, backgroundExceptionDispatcher, trace);
                }

                if (functionIndexProvider == null)
                {
                    functionIndexProvider = new FunctionIndexProvider(typeLocator, triggerBindingProvider, bindingProvider, activator, functionExecutor, extensions, singletonManager);
                }

                IFunctionIndex functions = await functionIndexProvider.GetAsync(combinedCancellationToken);
                IListenerFactory functionsListenerFactory = new HostListenerFactory(functions.ReadAll(), singletonManager, activator, nameResolver, trace);

                IFunctionExecutor hostCallExecutor;
                IListener listener;
                HostOutputMessage hostOutputMessage;

                if (dashboardAccount != null)
                {
                    string hostId = await hostIdProvider.GetHostIdAsync(cancellationToken);

                    string sharedQueueName = HostQueueNames.GetHostQueueName(hostId);
                    IStorageQueueClient dashboardQueueClient = dashboardAccount.CreateQueueClient();
                    IStorageQueue sharedQueue = dashboardQueueClient.GetQueueReference(sharedQueueName);
                    IListenerFactory sharedQueueListenerFactory = new HostMessageListenerFactory(sharedQueue,
                        queueConfiguration, backgroundExceptionDispatcher, trace, functions,
                        functionInstanceLogger, functionExecutor);

                    Guid hostInstanceId = Guid.NewGuid();
                    string instanceQueueName = HostQueueNames.GetHostQueueName(hostInstanceId.ToString("N"));
                    IStorageQueue instanceQueue = dashboardQueueClient.GetQueueReference(instanceQueueName);
                    IListenerFactory instanceQueueListenerFactory = new HostMessageListenerFactory(instanceQueue,
                        queueConfiguration, backgroundExceptionDispatcher, trace, functions,
                        functionInstanceLogger, functionExecutor);

                    HeartbeatDescriptor heartbeatDescriptor = new HeartbeatDescriptor
                    {
                        SharedContainerName = HostContainerNames.Hosts,
                        SharedDirectoryName = HostDirectoryNames.Heartbeats + "/" + hostId,
                        InstanceBlobName = hostInstanceId.ToString("N"),
                        ExpirationInSeconds = (int)HeartbeatIntervals.ExpirationInterval.TotalSeconds
                    };

                    IStorageBlockBlob blob = dashboardAccount.CreateBlobClient()
                        .GetContainerReference(heartbeatDescriptor.SharedContainerName)
                        .GetBlockBlobReference(heartbeatDescriptor.SharedDirectoryName + "/" + heartbeatDescriptor.InstanceBlobName);
                    IRecurrentCommand heartbeatCommand = new UpdateHostHeartbeatCommand(new HeartbeatCommand(blob));

                    IEnumerable<MethodInfo> indexedMethods = functions.ReadAllMethods();
                    Assembly hostAssembly = GetHostAssembly(indexedMethods);
                    string displayName = hostAssembly != null ? hostAssembly.GetName().Name : "Unknown";

                    hostOutputMessage = new DataOnlyHostOutputMessage
                    {
                        HostInstanceId = hostInstanceId,
                        HostDisplayName = displayName,
                        SharedQueueName = sharedQueueName,
                        InstanceQueueName = instanceQueueName,
                        Heartbeat = heartbeatDescriptor,
                        WebJobRunIdentifier = WebJobRunIdentifier.Current
                    };

                    hostCallExecutor = CreateHostCallExecutor(instanceQueueListenerFactory, heartbeatCommand,
                        backgroundExceptionDispatcher, shutdownToken, functionExecutor);
                    IListenerFactory hostListenerFactory = new CompositeListenerFactory(functionsListenerFactory,
                        sharedQueueListenerFactory, instanceQueueListenerFactory);
                    listener = CreateHostListener(hostListenerFactory, heartbeatCommand, backgroundExceptionDispatcher, shutdownToken);

                    // Publish this to Azure logging account so that a web dashboard can see it. 
                    await LogHostStartedAsync(functions, hostOutputMessage, hostInstanceLogger, combinedCancellationToken);
                }
                else
                {
                    hostCallExecutor = new ShutdownFunctionExecutor(shutdownToken, functionExecutor);

                    IListener factoryListener = new ListenerFactoryListener(functionsListenerFactory);
                    IListener shutdownListener = new ShutdownListener(shutdownToken, factoryListener);
                    listener = shutdownListener;

                    hostOutputMessage = new DataOnlyHostOutputMessage();
                }

                functionExecutor.HostOutputMessage = hostOutputMessage;

                IEnumerable<FunctionDescriptor> descriptors = functions.ReadAllDescriptors();
                int descriptorsCount = descriptors.Count();

                if (descriptorsCount == 0)
                {
                    trace.Warning("No functions found. Try making job classes and methods public.", TraceSource.Indexing);
                }
                else
                {
                    StringBuilder functionsTrace = new StringBuilder();
                    functionsTrace.AppendLine("Found the following functions:");
                    
                    foreach (FunctionDescriptor descriptor in descriptors)
                    {
                        functionsTrace.AppendLine(descriptor.FullName);
                    }

                    trace.Info(functionsTrace.ToString(), TraceSource.Indexing);
                }

                return new JobHostContext(functions, hostCallExecutor, listener, trace);
            }
        }
 internal static void SetDefaultValues()
 {
     BindingCultureInfo = null;
     _updateEventFinder = FindUpdateEvent;
     _bindingPathFactory = BindingPath.Create;
     _valueConverter = BindingReflectionExtensions.Convert;
     _resourceResolver = new BindingResourceResolver();
     _memberProvider = new BindingMemberProvider();
     _visualTreeManager = new VisualTreeManager();
     _weakEventManager = new WeakEventManager();
     _bindingManager = new BindingManager();
     _bindingProvider = new BindingProvider();
     _observerProvider = new ObserverProvider();
     _contextManager = new BindingContextManager();
 }
Example #38
0
 public ExchangeUpdater(IBindingProvider bindingProvider, IChannelFactory channelFactory)
 {
     _bindingProvider = bindingProvider;
     _channelFactory = channelFactory;
 }
 protected virtual IBindingParser CreateBindingParser(IVisualTreeManager treeManager = null, IBindingProvider bindingProvider = null, IObserverProvider observerProvider = null)
 {
     if (bindingProvider == null)
         bindingProvider = new BindingProvider();
     BindingServiceProvider.BindingProvider = bindingProvider;
     if (treeManager != null)
         BindingServiceProvider.VisualTreeManager = treeManager;
     if (observerProvider != null)
         BindingServiceProvider.ObserverProvider = observerProvider;
     return new BindingParser();
 }