Example #1
0
        CommandProcessingResult GetLastResult()
        {
            var eventStore = new MongoDbEventStore(_database, "Events");
            var nextGlobalSequenceNumber = eventStore.GetNextGlobalSequenceNumber();
            var lastGlobalSequenceNumber = nextGlobalSequenceNumber - 1;

            return(CommandProcessingResult.WithNewPosition(lastGlobalSequenceNumber));
        }
Example #2
0
        /// <summary>
        /// Waits for views managing the specified <see cref="TViewInstance"/> to catch up with the entire history of events, timing out if that takes longer than 10 seconds
        /// </summary>
        public void WaitForViewToCatchUp <TViewInstance>(int timeoutSeconds = 10) where TViewInstance : IViewInstance
        {
            var allGlobalSequenceNumbers = History.Select(h => h.GetGlobalSequenceNumber()).ToArray();

            if (!allGlobalSequenceNumbers.Any())
            {
                return;
            }

            var result = CommandProcessingResult.WithNewPosition(allGlobalSequenceNumbers.Max());

            _waitHandle.WaitFor <TViewInstance>(result, TimeSpan.FromSeconds(timeoutSeconds)).Wait();
        }
Example #3
0
        /// <summary>
        /// Waits for views managing the specified <see cref="TViewInstance"/> to catch up with the entire history of events, timing out if that takes longer than 10 seconds
        /// </summary>
        public void WaitForViewToCatchUp <TViewInstance>(int timeoutSeconds = 10) where TViewInstance : IViewInstance
        {
            var allGlobalSequenceNumbers = History.Select(h => h.GetGlobalSequenceNumber()).ToArray();

            if (!allGlobalSequenceNumbers.Any())
            {
                return;
            }

            var result = CommandProcessingResult.WithNewPosition(allGlobalSequenceNumbers.Max());

            WithEventDispatcherOfType <IAwaitableEventDispatcher>(x => x.WaitUntilProcessed <TViewInstance>(result, TimeSpan.FromSeconds(timeoutSeconds)).Wait());
        }
Example #4
0
        /// <summary>
        /// Waits for all views to catch up with the entire history of events, timing out if that takes longer than 10 seconds
        /// </summary>
        public void WaitForViewsToCatchUp(int timeoutSeconds = 10)
        {
            var allGlobalSequenceNumbers = History.Select(h => h.GetGlobalSequenceNumber()).ToArray();

            if (!allGlobalSequenceNumbers.Any())
            {
                return;
            }

            var result = CommandProcessingResult.WithNewPosition(allGlobalSequenceNumbers.Max());

            try
            {
                _waitHandle.WaitForAll(result, TimeSpan.FromSeconds(timeoutSeconds)).Wait();
            }
            catch (TimeoutException exception)
            {
                throw new TimeoutException(string.Format(@"One or more views did not catch up within {0} s timeout

Current view positions:
{1}", timeoutSeconds, string.Join(Environment.NewLine, _addedViews.Select(viewManager => string.Format("    {0}: {1}", viewManager.GetPosition().ToString().PadRight(5), viewManager.GetType().FullName)))), exception);
            }
        }