Пример #1
0
        public async Task <bool> ApplyUpdatesToStorage(IReadOnlyList <IEvent> updates, int expectedversion)
        {
            List <PersistedEvent> newEvents = new List <PersistedEvent>();
            int version = Version;

            foreach (var update in updates)
            {
                var ts = DateTime.UtcNow;
                version++;
                var newEvent = new PersistedEvent(_ids.Create(update.Timestamp), IdentityString, update, version, update.Timestamp);
                newEvents.Add(newEvent);
            }

            await _events.WriteAsync(IdentityString, newEvents);

            var streams = updates
                          .GroupBy(e => new { e.StreamProviderName, e.StreamId, e.StreamNamespace })
                          .ToDictionary(
                e => string.Join(":", e.Key.StreamProviderName, e.Key.StreamId, e.Key.StreamNamespace),
                e => GetStreamProvider(e.Key.StreamProviderName).GetStream <IEvent>(e.Key.StreamId, e.Key.StreamNamespace)
                );

            foreach (var update in updates)
            {
                var   streamKey = string.Join(":", update.StreamProviderName, update.StreamId, update.StreamNamespace);
                await streams[streamKey].OnNextAsync(update);
            }

            return(true);
        }
Пример #2
0
        public async Task <PostBoardResponse> Post(PostBoardRequest request)
        {
            var boardId = _ids.Create();
            var command = new CreateBoard(boardId, request.Name, request.UserId);
            var user    = _cluster.GetGrain <IUserAggregate>(request.UserId);
            await user.CreateBoard(command);

            return(new PostBoardResponse(boardId));
        }
Пример #3
0
        public async Task <PostEnvelopeResponse> Post(PostEnvelopeRequest request)
        {
            PostEnvelopeResponse response = new PostEnvelopeResponse();

            response.Id = _ids.Create();

            await _cluster.GetGrain <IBoardAggregate>(request.BoardId)
            .AddEnvelope(new AddEnvelope(response.Id, request.Name, request.Categories, request.BoardId, request.UserId));

            return(response);
        }
Пример #4
0
        public async Task <string> CreateOrReplaceUserAsync(string authenticationType, string userId, string userName, string email)
        {
            if (!_actors.IsInitialized)
            {
                await _actors.Connect();
            }

            var commandId = _ids.Create();

            try
            {
                var user = _actors.GetGrain <IUserAggregate>(userId);
                await user.LoginUser(new LoginUser(commandId, userId, authenticationType, userId, userName, email));
            }
            catch (Exception ex)
            {
                throw;
            }
            return(userId);
        }