Пример #1
0
        private bool DispatchEventNow()
        {
            DispatchEvent theEvent;

            if (_queue.TryDequeue(out theEvent))
            {
                _context.SendDownstream(theEvent);
                return(true);
            }

            return(false);
        }
Пример #2
0
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            var msg = message as DispatchCommand;
            if (msg != null)
            {
                _storage.Add(msg);
            }
            if (message is StartHandlers)
            {
                context.SendDownstream(message);

                var commands = _storage.FindFailedCommands(DateTime.Now.AddSeconds(-5));
                foreach (var command in commands)
                {
                    context.SendDownstream(command);
                }

                return;
            }
            context.SendDownstream(message);
        }
Пример #3
0
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            var msg = message as DispatchCommand;

            if (msg != null)
            {
                _storage.Add(msg);
            }
            if (message is StartHandlers)
            {
                context.SendDownstream(message);

                var commands = _storage.FindFailedCommands(DateTime.Now.AddSeconds(-5));
                foreach (var command in commands)
                {
                    context.SendDownstream(command);
                }

                return;
            }
            context.SendDownstream(message);
        }
Пример #4
0
        /// <summary>
        /// A UoW has been released for the current thread.
        /// </summary>
        /// <param name="unitOfWork">UoW which was released. Must be same as in <see cref="IUnitOfWorkObserver.Create"/>.</param>
        /// <param name="successful"><c>true</c> if the UoW was saved successfully; otherwise <c>false</c>.</param>
        public void Released(object unitOfWork, bool successful)
        {
            var guid = _threadBatchIdMapper.Release(unitOfWork);

            if (successful)
            {
                var jobs = _storage.Release(guid);
                foreach (var job in jobs)
                {
                    _context.SendDownstream(new DispatchEvent(job));
                }
            }
            else
            {
                _storage.Delete(guid);
            }
        }
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            _context = context;

            var msg = message as DispatchEvent;
            if (msg != null)
            {
                var batchId = _threadBatchIdMapper.GetBatchId();
                if (batchId != Guid.Empty)
                {
                    _storage.Hold(batchId, msg.DomainEvent);
                    return;
                }
            }


            context.SendDownstream(message);
        }
Пример #6
0
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            _context = context;

            var msg = message as DispatchEvent;

            if (msg != null)
            {
                var batchId = _threadBatchIdMapper.GetBatchId();
                if (batchId != Guid.Empty)
                {
                    _storage.Hold(batchId, msg.DomainEvent);
                    return;
                }
            }


            context.SendDownstream(message);
        }
Пример #7
0
        /// <summary>
        /// Dispatch a single command
        /// </summary>
        private bool DispatchCommand()
        {
            DispatchCommand command;

            if (!_commands.TryDequeue(out command))
            {
                return(false);
            }

            try
            {
                _context.SendDownstream(command);
            }
            catch (Exception err)
            {
                _context.SendUpstream(new PipelineFailure(this, command, "AsyncHandler failed to dispatch commands.",
                                                          err));
            }
            return(true);
        }
Пример #8
0
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            _context = context;

            var sendCmd = message as DispatchCommand;
            if (sendCmd != null)
            {
                EnqueueCommand(sendCmd);
                return;
            }
            if (message is Shutdown)
            {
                Close();
            }
            if (message is StartHandlers)
            {
                StartWorker();
            }

            context.SendDownstream(message);
        }
Пример #9
0
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            _context = context;

            var sendCmd = message as DispatchCommand;

            if (sendCmd != null)
            {
                EnqueueCommand(sendCmd);
                return;
            }
            if (message is Shutdown)
            {
                Close();
            }
            if (message is StartHandlers)
            {
                StartWorker();
            }

            context.SendDownstream(message);
        }
Пример #10
0
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            var msg = message as DispatchCommand;

            if (msg != null)
            {
                try
                {
                    _method.MakeGenericMethod(msg.Command.GetType()).Invoke(this, new object[] { msg.Command });
                    context.SendUpstream(new CommandCompleted(msg));
                }
                catch (Exception err)
                {
                    msg.AddFailedAttempt();
                    context.SendUpstream(new CommandFailed(msg, err));
                    return;
                }

                return;
            }

            context.SendDownstream(message);
        }
 /// <summary>
 /// Send a message to the command handler
 /// </summary>
 /// <param name="context">my context</param>
 /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
 public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
 {
     Invoked = true;
     context.SendDownstream(message);
 }
 /// <summary>
 /// Send a message to the command handler
 /// </summary>
 /// <param name="context">my context</param>
 /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
 public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
 {
     Invoked = true;
     context.SendDownstream(message);
 }