コード例 #1
0
        public async Task SaveData <TData>(string key, TData data, CancellationToken cancellationToken)
        {
            await using var context = contextFactory.CreateDbContext();
            var dataEntity = await FindSessionData(context, key, cancellationToken);

            var serializedData = SerializeData(data);

            if (dataEntity != null)
            {
                dataEntity.Data = serializedData;
                context.Update(dataEntity);
            }
            else
            {
                dataEntity = new SessionDataEntity
                {
                    Key  = key,
                    Data = serializedData,
                };

                await context.AddAsync(dataEntity, cancellationToken);
            }

            await context.SaveChangesAsync(cancellationToken);
        }
コード例 #2
0
ファイル: GameSessionHandler.cs プロジェクト: Feigh/SoundBang
        public SessionDataEntity ConnectNewPlayerToSession(SessionDataEntity body)
        {
            if (sessionList.Find(x => x.SessionName == body.SessionName) == null)
            {
                throw new InvalidOperationException("Could not find Session");
            }

            var          session = sessionList.Find(x => x.SessionName == body.SessionName);
            PlayerEntity player  = new PlayerEntity()
            {
                PlayerId = Guid.NewGuid()
            };

            session.PlayerList.Add(player);

            body.SessionId = session.SessionId;
            body.Player    = player;
            return(body);
        }
コード例 #3
0
ファイル: GameSessionHandler.cs プロジェクト: Feigh/SoundBang
        public SessionDataEntity UpdatePlayerInSession(SessionDataEntity body)
        {
            if (sessionList.Find(x => x.SessionName == body.SessionName) == null)
            {
                throw new InvalidOperationException("Could not find Session");
            }

            var session = sessionList.Find(x => x.SessionName == body.SessionName);

            if (session.PlayerList.Find(x => x.PlayerId == body.Player.PlayerId) == null)
            {
                throw new InvalidOperationException("Could not find Session");
            }

            var player = session.PlayerList.Find(x => x.PlayerId == body.Player.PlayerId);

            player.PlayerName = body.Player.PlayerName;

            body.Player = player;
            return(body);
        }
コード例 #4
0
ファイル: GameSessionHandler.cs プロジェクト: Feigh/SoundBang
 public string HandleGet(SessionDataEntity body)
 {
     throw new NotImplementedException();
 }