Esempio n. 1
0
        /// <summary>
        /// Dispatch unprocessed messages.
        /// </summary>
        /// <param name="processManager">Dispatches all process manager commands.</param>
        private void DispatchMessages(IProcessManager processManager)
        {
            if (processManager.Commands != null)
            {
                var undispatched = new UndispatchedMessage(processManager.Id);

                context.Set <UndispatchedMessage>().Add(undispatched);// We create a undispatched object previous processing case of system crash.

                try
                {
                    while (processManager.Commands.Count > 0)
                    {// We process each command.
                        var command = processManager.Commands.Dequeue();
                        messagingRandomRetry.ExecuteAction(() => this.commandBus.Publish(command));
                    }
                }
                catch (Exception ex)
                {// Any kind of exception we recreate commands and update in database.
                    Exception outEx1 = null;
                    CQRSExceptionProcessor.HandleException(ex, out outEx1);

                    undispatched.Commands = this.serializer.Serialize(processManager.Commands);
                    sqlIncrementalRetry.ExecuteAction(() =>
                    {
                        context.SaveChanges();
                    });

                    throw outEx1;
                }
            }
        }
Esempio n. 2
0
        public void CQRSTestCheckEmptyCommand()
        {
            UndispatchedMessage ud = new UndispatchedMessage();

            Assert.AreEqual(DateTime.Now.Year, ud.CreatedTime.Year, "Time is not now.");
            Assert.AreEqual(DateTime.Now.Month, ud.CreatedTime.Month, "Time is not now.");
            Assert.AreEqual(DateTime.Now.Day, ud.CreatedTime.Day, "Time is not now.");
        }