Exemplo n.º 1
0
 public virtual void resultAdded(Result result)
 {
     Networking.ResultDTO resultDto = DTOUtils.getDTO(result);
     Console.WriteLine("Result added  " + result);
     try
     {
         sendResponse(ProtoUtils.createNewResultResponse(resultDto));
     }
     catch (Exception e)
     {
         throw new TriatlonException("Sending error: " + e);
     }
 }
Exemplo n.º 2
0
        private Response handleRequest(Request request)
        {
            Response response = null;

            Request.Types.RequestType reqType = request.Type;

            switch (reqType)
            {
            case Request.Types.RequestType.Login:
            {
                Console.WriteLine("Login request ...");
                User user = ProtoUtils.getUser(request);
                try
                {
                    lock (server)
                    {
                        server.login(user, this);
                    }

                    return(ProtoUtils.createOkResponse());
                }
                catch (TriatlonException e)
                {
                    connected = false;
                    return(ProtoUtils.createErrorResponse(e.Message));
                }
            }

            case Request.Types.RequestType.Logout:
            {
                Console.WriteLine("Logout request ...");
                User user = ProtoUtils.getUser(request);
                try
                {
                    lock (server)
                    {
                        server.logout(user, this);
                    }

                    connected = false;
                    return(ProtoUtils.createOkResponse());
                }
                catch (TriatlonException e)
                {
                    return(ProtoUtils.createErrorResponse(e.Message));
                }
            }

            case Request.Types.RequestType.AddResult:
            {
                Console.WriteLine("AddResult Request ...");
                Result result = ProtoUtils.getResult(request);
                try
                {
                    lock (server)
                    {
                        server.addResult(result);
                    }

                    return(ProtoUtils.createOkResponse());
                }
                catch (TriatlonException e)
                {
                    return(ProtoUtils.createErrorResponse(e.Message));
                }
            }

            case Request.Types.RequestType.GetParticipantsByScore:
            {
                Console.WriteLine("GetParticipantsByScore Request ...");
                int idStage = ProtoUtils.getIdStage(request);
                try
                {
                    Triatlon_CSharp.Domain.Participant[] participants;
                    lock (server)
                    {
                        participants = server.getParticipantsByScore(idStage);
                    }

                    return(ProtoUtils.createGetParticipantsByScoreResponse(participants));
                }
                catch (TriatlonException e)
                {
                    return(ProtoUtils.createErrorResponse(e.Message));
                }
            }

            case Request.Types.RequestType.GetParticipantsAndScore:
            {
                Console.WriteLine("GetParticipantsAndScore Request ...");
                try
                {
                    Triatlon_CSharp.Domain.ParticipantDTO[] participants;
                    lock (server)
                    {
                        participants = server.getParticipantsAndScore();
                    }

                    return(ProtoUtils.createGetParticipantsAndScoreResponse(participants));
                }
                catch (TriatlonException e)
                {
                    return(ProtoUtils.createErrorResponse(e.Message));
                }
            }
            }

            return(response);
        }