Пример #1
0
        internal Task <IBinding> CreateBinding(ParameterInfo parameter)
        {
            Type coreType = TypeUtility.GetCoreType(parameter.ParameterType);

            IBinding genericBinding = BindingFactory.BindGenericCollector(parameter, typeof(EasyTableAsyncCollector <>), coreType,
                                                                          _jobHostConfig.GetService <IConverterManager>(), (s) => _easyTableContext);

            return(Task.FromResult(genericBinding));
        }
        public async Task <IBinding> TryCreateAsync(BindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ParameterInfo       parameter = context.Parameter;
            DocumentDBAttribute attribute = parameter.GetCustomAttribute <DocumentDBAttribute>(inherit: false);

            if (attribute == null)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(_docDBConfig.ConnectionString) &&
                string.IsNullOrEmpty(attribute.ConnectionString))
            {
                throw new InvalidOperationException(
                          string.Format(CultureInfo.CurrentCulture,
                                        "The DocumentDB connection string must be set either via a '{0}' app setting, via the DocumentDBAttribute.ConnectionString property or via DocumentDBConfiguration.ConnectionString.",
                                        DocumentDBConfiguration.AzureWebJobsDocumentDBConnectionStringName));
            }

            DocumentDBContext documentDBContext = CreateContext(_docDBConfig, attribute, _jobHostConfig.NameResolver);

            if (attribute.CreateIfNotExists)
            {
                await CreateIfNotExistAsync(documentDBContext.Service, documentDBContext.ResolvedDatabaseName, documentDBContext.ResolvedCollectionName);
            }

            Type coreType = TypeUtility.GetCoreType(parameter.ParameterType);

            IBinding binding = null;

            try
            {
                binding = BindingFactory.BindGenericCollector(parameter, typeof(DocumentDBAsyncCollector <>), coreType,
                                                              _jobHostConfig.GetService <IConverterManager>(), (s) => documentDBContext);
            }
            catch (Exception ex)
            {
                // BindingFactory uses a couple levels of reflection so we get TargetInvocationExceptions here.
                // This pulls out the root exception and rethrows it.
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }

                ExceptionDispatchInfo.Capture(ex).Throw();
            }

            return(binding);
        }