Exemple #1
0
        /// <summary>
        /// Appends the events to the store.
        /// </summary>
        /// <param name="events">The events.</param>
        /// <returns>The new version.</returns>
        public async Task <long> AppendEvents(IList <IEvent> events)
        {
            if (events.Any() == true)
            {
                _transactionId++;
                try
                {
                    await _actorSystem.Create <IEventStoreTransactionActor>(GetTransactionId(_transactionId)).SetEvents(events);
                }
                catch
                {
                    if (await _actorSystem.Create <IEventStoreTransactionActor>(GetTransactionId(_transactionId)).HasEvents())
                    {
                        // The transaction id already exist. Seems that the last transaction id
                        // value is corrupt. Reset the value and retry.
                        await ResetVersion();

                        await _actorSystem.Create <IEventStoreTransactionActor>(GetTransactionId(_transactionId)).SetEvents(events);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            await StateManager.SetStateAsync(_stateName, _transactionId);

            return(_transactionId);
        }
Exemple #2
0
        /// <summary>
        /// Reads the events from the store.
        /// </summary>
        /// <param name="afterVersion">
        /// Ignore all events before the event with the given identifier, including itself.
        /// </param>
        /// <param name="take">Maximum number of events to read.</param>
        /// <returns>The list of the matching events.</returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public async Task <(IList <IEvent>?events, string?version)> Read(string?afterVersion = null, int take = 0)
        {
            long fromVersion   = 0;
            long latestVersion = await StoreActor.GetLastestVersion();

            if (!string.IsNullOrWhiteSpace(afterVersion))
            {
                if (!long.TryParse(afterVersion, out fromVersion) || fromVersion == 0 || fromVersion > latestVersion)
                {
                    // Invalid event store transaction identifier : '%1'.
                    throw new ArgumentOutOfRangeException(nameof(afterVersion), string.Format(CultureInfo.CurrentCulture, ExtenFlow.Messages.Properties.Resources.InvalidEventStoreTransactionId, afterVersion));
                }
            }
            var  events = new List <IEvent>();
            long i      = 0L;

            while (fromVersion + i < latestVersion)
            {
                i++;
                events.AddRange(
                    await _actorSystem
                    .Create <IEventStoreTransactionActor>(
                        EventStoreActor.GetTransactionId(_streamId, fromVersion + i)
                        )
                    .GetEvents()
                    );
                if (take != 0L && i >= take)
                {
                    break;
                }
            }
            if (i == 0L)
            {
                return(null, null);
            }
            return(events, (fromVersion + i).ToString(CultureInfo.InvariantCulture));
        }
Exemple #3
0
        /// <summary>
        /// Finds a client by id
        /// </summary>
        /// <param name="clientId">The client id</param>
        /// <returns>The client</returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public Task <Client> FindClientByIdAsync(string clientId)
        {
            var clientActor = _actorSystem.Create <IClientActor>(clientId);

            clientActor.Ask <ClientDe>
        }