public override string GetLast <TResult>()
        {
            try
            {
                var            streamNameStartWith = string.Format("{0}-{1}", Category, typeof(TResult).Name);
                AllEventsSlice slice;
                var            nextSliceStart = Position.End;
                do
                {
                    slice = _connection.ReadAllEventsBackwardAsync(nextSliceStart, 1, false).Result;
                    foreach (var e in slice.Events)
                    {
                        if (e.Event.EventStreamId.StartsWith(streamNameStartWith))
                        {
                            return(e.Event.EventStreamId);
                        }
                    }
                } while (!slice.IsEndOfStream);

                return(null);
            }
            catch (System.Exception ex)
            {
                throw new RepositoryException("Unable to retrieve from eventStore", ex);
            }
        }
        private void UpgradeProjectionPartitionCheckpoints()
        {
            Log("Looking for projection partition checkpoint streams");
            var from = Position.Start;

            _oldTfScanPercent = 0d;
            var lastSlice = _connection.ReadAllEventsBackwardAsync(Position.End, 1, false, _credentials).Result;

            if (lastSlice.Events.Length == 0)
            {
                throw new Exception("Empty TF");
            }
            _lastTfPosition = lastSlice.Events[0].OriginalPosition.Value.PreparePosition;
            AllEventsSlice slice;

            do
            {
                slice = _connection.ReadAllEventsForwardAsync(@from, 100, false, _credentials).Result;
                DisplayTfScanProgress(slice);
                foreach (var @event in slice.Events)
                {
                    if (@event.OriginalEventNumber == 0)
                    {
                        UpgradeStreamIfPartitionCheckpoint(@event.OriginalStreamId);
                    }
                }
                from = slice.NextPosition;
            } while (!slice.IsEndOfStream);
            Log("Completed looking for partition checkpoint streams");
        }
Exemple #3
0
        public async Task <long> GetCurrentGlobalStreamPosition()
        {
            await Connect();

            var slice = await _connection.ReadAllEventsBackwardAsync(Position.End, 1, false);

            return(slice.FromPosition.CommitPosition);
        }
Exemple #4
0
        public async Task <IEnumerable <EventModel> > ReadAllEventsBackwardAsync()
        {
            var records =
                await eventStoreConnection.ReadAllEventsBackwardAsync(Position.Start, PageSize, false,
                                                                      CredentialsHelper.Default);

            return(records.Events.Select(@event => @event.Event.ParseEvent()).ToList());
        }
        public void read_all_existing_events_and_keep_listening_to_new_ones()
        {
            using (var store = BuildConnection())
            {
                store.ConnectAsync().Wait();
                var position = _conn.ReadAllEventsBackwardAsync(Position.End, 1, false).Result.NextPosition;
                var events   = new List <ResolvedEvent>();
                var appeared = new CountdownEvent(20);
                var dropped  = new CountdownEvent(1);

                for (int i = 0; i < 10; ++i)
                {
                    store.AppendToStreamAsync("all_read_all_existing_events_and_keep_listening_to_new_ones-" + i.ToString(), -1, new EventData(Guid.NewGuid(), "et-" + i.ToString(), false, new byte[3], null)).Wait();
                }

                var subscription = store.SubscribeToAllFrom(position,
                                                            CatchUpSubscriptionSettings.Default,
                                                            (x, y) =>
                {
                    if (!SystemStreams.IsSystemStream(y.OriginalEvent.EventStreamId))
                    {
                        events.Add(y);
                        appeared.Signal();
                    }
                },
                                                            _ => Log.Info("Live processing started."),
                                                            (x, y, z) => dropped.Signal());
                for (int i = 10; i < 20; ++i)
                {
                    store.AppendToStreamAsync("all_read_all_existing_events_and_keep_listening_to_new_ones-" + i.ToString(), -1, new EventData(Guid.NewGuid(), "et-" + i.ToString(), false, new byte[3], null)).Wait();
                }

                if (!appeared.Wait(Timeout))
                {
                    Assert.IsFalse(dropped.Wait(0), "Subscription was dropped prematurely.");
                    Assert.Fail("Could not wait for all events.");
                }

                Assert.AreEqual(20, events.Count);
                for (int i = 0; i < 20; ++i)
                {
                    Assert.AreEqual("et-" + i.ToString(), events[i].OriginalEvent.EventType);
                }

                Assert.IsFalse(dropped.Wait(0));
                subscription.Stop(Timeout);
                Assert.IsTrue(dropped.Wait(Timeout));
            }
        }
        private static void ReadAllEventsBackward(IEventStoreConnection connection)
        {
            UserCredentials credentials = new UserCredentials("admin", "changeit");
            AllEventsSlice slice = connection.ReadAllEventsBackwardAsync(Position.End, 100, false, credentials).Result;

            if (slice.Events.Length > 0)
            {
                Console.WriteLine("id: " + slice.Events[0].Event.EventId);

                string data = Encoding.UTF8.GetString(slice.Events[0].Event.Data);
                Console.WriteLine("data: " + data);

                string metadata = Encoding.UTF8.GetString(slice.Events[0].Event.Metadata);
                Console.WriteLine("metadata: " + metadata);
            }
        }
 protected void ReadAllBackward(string login, string password)
 {
     Connection.ReadAllEventsBackwardAsync(Position.End, 1, false,
                                           login == null && password == null ? null : new UserCredentials(login, password))
     .Wait();
 }
Exemple #8
0
 protected Task ReadAllBackward(string login, string password)
 {
     return(Connection.ReadAllEventsBackwardAsync(Position.End, 1, false,
                                                  login == null && password == null ? null : new UserCredentials(login, password)));
 }
        public async Task <long> GetLastPosition(CancellationToken cancellationToken)
        {
            var last = await _connection.ReadAllEventsBackwardAsync(Position.End, 1, false).ConfigureAwait(false);

            return(last.NextPosition.CommitPosition);
        }
        public async Task <IDomainEvent[]> GetAggregateHistory()
        {
            var allEvents = await _connection.ReadAllEventsBackwardAsync(Position.End, 4096, false, _userCredentials);

            return(allEvents.Events.Where(e => MappingKeyToEventType.ContainsKey(e.Event.EventType)).Select(ToDomainEvent).ToArray());
        }