Beispiel #1
0
        /// <inheritdoc />
        public async Task<Dictionary<IStream, IEnumerable<IEvent>>> GetChanges(ICommand command, Time time)
        {
            var activeBranch = _manager.ActiveBranch;
            var branch = $"{command.GetType().Name}-{time.ToUnixTimeMilliseconds()}";

            await _manager.Branch(branch, time, deleteExisting: true);

            var copy = command;
            copy.Timeline = branch;
            
            var handler = _commandRegistry.GetHandler(copy);
            if (handler == null)
                throw new InvalidOperationException($"No handler found for command {command.GetType().Name}");
            await handler.Handle(copy);
            
            await _manager.Branch(activeBranch);
            
            var dict = new Dictionary<IStream, IEnumerable<IEvent>>();

            var changes = await _manager.GetChanges(branch);
            _log.StopWatch.Start("GetChanges.Read");
            foreach (var c in changes)
            {
                var stream = await _streamLocator.FindBranched(c.Key, branch);
                var e = await _eventStore.ReadStream<IEvent>(stream, stream.Version - c.Value + 1, c.Value).ToList();

                dict[c.Key] = e;
            }
            
            _log.StopWatch.Stop("GetChanges.Read");

            await _manager.DeleteBranch(branch);
            return dict;
        }
Beispiel #2
0
        public IHttpActionResult DeleteBranch(int id)
        {
            bool status = _BranchManager.DeleteBranch(id);

            if (status == false)
            {
                return(NotFound());
            }
            return(Ok(status));
        }