Пример #1
0
        public void StartLisen()
        {
            if (IsLisening)
            {
                return;
            }

            int tempLoopCount = Setting.LoopCount;

            _executionTimer = new Timer(Setting.LoopInterval * 1000);

            _executionTimer.Elapsed += (a, b) =>
            {
                if (Interlocked.Decrement(ref tempLoopCount) <= 0)
                {
                    StopLisen();
                }
                else
                {
                    var args = new InvokeNextEventArgs("");

                    if (InvokeNext != null)
                    {
                        InvokeNext.Invoke(args);
                    }
                }
            };

            _executionTimer.Start();

            IsLisening = true;
        }
Пример #2
0
        public Task <MessageBusOutput> Invoke(InvokeNext <TInput, MessageBusOutput> next, TInput input)
        {
            var commandType       = input.GetType();
            var actionDescriptors = _handlerMethodsMapping.Find(commandType);

            if (actionDescriptors == null)
            {
                throw new HandlerNotRegistredException($"No handler registred for message {input.GetType()}");
            }
            return(Task.WhenAll(actionDescriptors.Select(x => CallHandler(input, x)).ToArray()).ContinueWith(x => new MessageBusOutput()));
        }
Пример #3
0
 public Task <MessageBusOutput> Invoke(InvokeNext <Command, MessageBusOutput> next, Command context)
 {
     System.Console.WriteLine("Middleware 2");
     return(next(context));
 }