コード例 #1
0
        public async Task <HttpResponseMessage> PostAsync([FromBody] Participant details)
        {
            HttpResponseMessage httpResponse = new HttpResponseMessage();

            try
            {
                Game game = fileAccess.GetGame(details.roomCode);
                game.participants.Add(details);
                game.participantCount++;
                fileAccess.UpdateGame(game);
                httpResponse.StatusCode = System.Net.HttpStatusCode.OK;
                //await _hub.Clients.All.SendAsync("participantUpdate", game.participants);
                //await this.room.SendMessage("Hello","World");
                return(httpResponse);
            }
            catch (InvalidOperationException)
            {
                Game game = new Game(details.roomCode);
                game.participantCount++;
                game.participants.Add(details);
                fileAccess.AddGame(game);
                httpResponse.StatusCode = System.Net.HttpStatusCode.Created;
                //await _hub.Clients.All.SendAsync("participantUpdate", game.participants);
                //await this.room.SendMessage("Hello", "World");
                return(httpResponse);
            }
            catch (Exception E)
            {
                Console.WriteLine(E.StackTrace);
                httpResponse.StatusCode = System.Net.HttpStatusCode.InternalServerError;
                return(httpResponse);
            }
        }
コード例 #2
0
        public async Task <List <Participant> > joinGameRoom(string roomCode, Participant self)
        {
            List <Participant> retVal;

            try
            {
                Game game = fileAccess.GetGame(roomCode);
                self.setSerialNumber(game.participantCount++);
                game.participants.Add(self);
                fileAccess.UpdateGame(game);
                retVal = game.participants;
                await Groups.AddToGroupAsync(Context.ConnectionId, roomCode);

                await Clients.Group(roomCode).SendAsync("participantUpdate", game.participants);
            }
            catch (InvalidOperationException)
            {
                Game game = new Game(roomCode);
                self.setSerialNumber(game.participantCount++);
                game.participants.Add(self);
                fileAccess.AddGame(game);
                retVal = game.participants;
                await Groups.AddToGroupAsync(Context.ConnectionId, roomCode);

                await Clients.Group(roomCode).SendAsync("participantUpdate", game.participants);
            }
            return(retVal);
        }
コード例 #3
0
        public HttpResponseMessage Post([FromBody] Participant details)
        {
            HttpResponseMessage httpResponse = new HttpResponseMessage();

            try
            {
                Game game = fileAccess.GetGame(details.roomCode);
                game.participants.Add(details);
                game.participantCount++;
                fileAccess.UpdateGame(game);
                httpResponse.StatusCode = System.Net.HttpStatusCode.OK;
                return(httpResponse);
            }
            catch (InvalidOperationException E)
            {
                Game game = new Game(details.roomCode);
                game.participantCount++;
                game.participants.Add(details);
                fileAccess.AddGame(game);
                httpResponse.StatusCode = System.Net.HttpStatusCode.Created;
                return(httpResponse);
            }
            catch (Exception E)
            {
                Console.WriteLine(E.StackTrace);
                httpResponse.StatusCode = System.Net.HttpStatusCode.InternalServerError;
                return(httpResponse);
            }
        }