public async Task <ProjectLobbyState> UpsertProjectLobbyStateAsync(Guid projectId, ProjectLobbyState projectLobbyState)
        {
            string key = LobbyStateKeyResolver.GetProjectLobbyStateKey(projectId);

            await _cacheSelector[CacheConnection.General].ItemSetAsync(key, projectLobbyState, _expirationTime);

            _eventService.Publish(EventNames.ProjectStatusUpdated, projectLobbyState);

            return(projectLobbyState);
        }
        /// <inheritdoc />
        public async Task CreateProjectLobbyStateAsync(Guid projectId)
        {
            var validationResult = _validatorLocator.Validate <ProjectIdValidator>(projectId);

            if (!validationResult.IsValid)
            {
                throw new ValidationFailedException(validationResult.Errors);
            }

            var state = new ProjectLobbyState
            {
                ProjectId  = projectId,
                LobbyState = LobbyState.Normal
            };

            await _cacheSelector[CacheConnection.General].ItemSetAsync(LobbyStateKeyResolver.GetProjectLobbyStateKey(projectId), state, _expirationTime);
        }
        /// <inheritdoc />
        public async Task <ProjectLobbyState> GetProjectLobbyStateAsync(Guid projectId)
        {
            var validationResult = _validatorLocator.Validate <ProjectIdValidator>(projectId);

            if (!validationResult.IsValid)
            {
                throw new ValidationFailedException(validationResult.Errors);
            }

            var result = await _cacheSelector[CacheConnection.General].ItemGetAsync(LobbyStateKeyResolver.GetProjectLobbyStateKey(projectId), typeof(ProjectLobbyState));

            if (result != null)
            {
                return(result as ProjectLobbyState);
            }

            return(await RecalculateProjectLobbyStateAsync(projectId));
        }
 /// <inheritdoc />
 public async Task DeleteProjectLobbyStateAsync(Guid projectId)
 {
     await _cacheSelector[CacheConnection.General].KeyDeleteAsync(LobbyStateKeyResolver.GetProjectLobbyStateKey(projectId));
 }