public async Task<IListener> CreateAsync(CancellationToken cancellationToken)
        {
            List<IListener> listeners = new List<IListener>();

            foreach (IFunctionDefinition functionDefinition in _functionDefinitions)
            {
                IListenerFactory listenerFactory = functionDefinition.ListenerFactory;
                if (listenerFactory == null)
                {
                    continue;
                }

                // Determine if the function is disabled
                MethodInfo method = functionDefinition.Descriptor.Method;
                if (IsDisabled(method, _nameResolver, _activator))
                {
                    _trace.Info(string.Format("Function '{0}' is disabled", functionDefinition.Descriptor.ShortName), TraceSource.Host);
                    continue;
                }

                IListener listener = await listenerFactory.CreateAsync(cancellationToken);

                // if the listener is a Singleton, wrap it with our SingletonListener
                SingletonAttribute singletonAttribute = SingletonManager.GetListenerSingletonOrNull(listener.GetType(), method);
                if (singletonAttribute != null)
                {
                    listener = new SingletonListener(method, singletonAttribute, _singletonManager, listener);
                }

                listeners.Add(listener);
            }

            return new CompositeListener(listeners);
        }
        public async Task<IListener> CreateAsync(CancellationToken cancellationToken)
        {
            List<IListener> listeners = new List<IListener>();

            foreach (IFunctionDefinition functionDefinition in _functionDefinitions)
            {
                IListenerFactory listenerFactory = functionDefinition.ListenerFactory;

                if (listenerFactory == null)
                {
                    continue;
                }

                IListener listener = await listenerFactory.CreateAsync(cancellationToken);

                // if the listener is a Singleton, wrap it with our SingletonListener
                SingletonAttribute singletonAttribute = listener.GetType().GetCustomAttribute<SingletonAttribute>();
                if (singletonAttribute != null)
                {
                    if (!string.IsNullOrEmpty(singletonAttribute.Scope))
                    {
                        throw new InvalidOperationException("SingletonAttribute.Scope values are not supported for singleton listeners.");
                    }
                    listener = new SingletonListener(functionDefinition.Descriptor.Method, singletonAttribute, _singletonManager, listener);
                }

                listeners.Add(listener);
            }

            return new CompositeListener(listeners);
        }
        public async Task<IListener> CreateAsync(CancellationToken cancellationToken)
        {
            List<IListener> listeners = new List<IListener>();

            foreach (IFunctionDefinition functionDefinition in _functionDefinitions)
            {
                IListenerFactory listenerFactory = functionDefinition.ListenerFactory;

                if (listenerFactory == null)
                {
                    continue;
                }

                IListener listener = await listenerFactory.CreateAsync(cancellationToken);

                // if the listener is a Singleton, wrap it with our SingletonListener
                SingletonAttribute singletonAttribute = SingletonManager.GetListenerSingletonOrNull(listener.GetType(), functionDefinition.Descriptor.Method);
                if (singletonAttribute != null)
                {
                    listener = new SingletonListener(functionDefinition.Descriptor.Method, singletonAttribute, _singletonManager, listener);
                }

                listeners.Add(listener);
            }

            return new CompositeListener(listeners);
        }
 public SingletonListenerTests()
 {
     MethodInfo methodInfo = this.GetType().GetMethod("TestJob", BindingFlags.Static|BindingFlags.NonPublic);
     _attribute = new SingletonAttribute();
     _config = new SingletonConfiguration
     {
         LockPeriod = TimeSpan.FromSeconds(20)
     };
     _mockSingletonManager = new Mock<SingletonManager>(MockBehavior.Strict, null, null, null, null, new FixedHostIdProvider(TestHostId), null);
     _mockSingletonManager.SetupGet(p => p.Config).Returns(_config);
     _mockInnerListener = new Mock<IListener>(MockBehavior.Strict);
     _listener = new SingletonListener(methodInfo, _attribute, _mockSingletonManager.Object, _mockInnerListener.Object);
     _lockId = SingletonManager.FormatLockId(methodInfo, SingletonScope.Function, TestHostId, _attribute.ScopeId) + ".Listener";
 }
示例#5
0
        public async Task <IListener> CreateAsync(CancellationToken cancellationToken)
        {
            List <IListener> listeners = new List <IListener>();

            foreach (IFunctionDefinition functionDefinition in _functionDefinitions)
            {
                // Determine if the function is disabled
                if (functionDefinition.Descriptor.IsDisabled)
                {
                    string msg = string.Format("Function '{0}' is disabled", functionDefinition.Descriptor.ShortName);
                    _trace.Info(msg, TraceSource.Host);
                    _logger?.LogInformation(msg);
                    continue;
                }

                IListenerFactory listenerFactory = functionDefinition.ListenerFactory;
                if (listenerFactory == null)
                {
                    continue;
                }

                IListener listener = await listenerFactory.CreateAsync(cancellationToken);

                // if the listener is a Singleton, wrap it with our SingletonListener
                SingletonAttribute singletonAttribute = SingletonManager.GetListenerSingletonOrNull(listener.GetType(), functionDefinition.Descriptor);
                if (singletonAttribute != null)
                {
                    listener = new SingletonListener(functionDefinition.Descriptor, singletonAttribute, _singletonManager, listener, _trace, _loggerFactory);
                }

                // wrap the listener with a function listener to handle exceptions
                listener = new FunctionListener(listener, functionDefinition.Descriptor, _trace, _loggerFactory);
                listeners.Add(listener);
            }

            return(new CompositeListener(listeners));
        }