Esempio n. 1
0
        public Participant[] getParticipantsByTeam(string teamName)
        {
            Console.WriteLine("Prxy----sending participants request....");

            Request request = new GetParticipantsRequest(teamName);

            sendRequest(request);

            Response response = readResponse();

            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                throw new AppException(err.Message);
            }

            GetParticipantsResponse resp = (GetParticipantsResponse)response;

            ParticipantDTO[] participants  = resp.Participanti;
            Participant[]    participants1 = transformer.getFromDTO(participants);

            return(participants1);
        }
        private object handleRequest(Request request)
        {
            Response response = null;

            if (request is LoginRequest)
            {
                Console.WriteLine("Login request ...");
                LoginRequest logReq = (LoginRequest)request;
                UserDTO      udto   = logReq.Userdto;
                User         user   = transformer.getFromDTO(udto);
                try
                {
                    lock (server)
                    {
                        server.login(user, this);
                    }
                    return(new OkResponse());
                }
                catch (AppException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is LogoutRequest)
            {
                Console.WriteLine("Logout request");
                LogoutRequest logReq = (LogoutRequest)request;
                UserDTO       udto   = logReq.Userdto;
                User          user   = transformer.getFromDTO(udto);
                try
                {
                    lock (server)
                    {
                        server.logout(user, this);
                    }
                    connected = false;
                    return(new OkResponse());
                }
                catch (AppException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is GetCurseRequest)
            {
                Console.WriteLine("Get curse request....");
                Cursa[] curse;
                try
                {
                    lock (server)
                    {
                        curse = server.getAllRaces();
                    }
                    CursaDTO[] cursa = transformer.getDTO(curse);
                    return(new GetCursaResponse(cursa));
                }
                catch (Exception ex)
                {
                    return(new ErrorResponse(ex.Message));
                }
            }
            if (request is GetParticipantsRequest)
            {
                Console.WriteLine("Get participants request.....");
                Participant[] part;

                GetParticipantsRequest req = (GetParticipantsRequest)request;
                String teamName            = req.Team;
                try
                {
                    lock (server)
                    {
                        part = server.getParticipantsByTeam(teamName);
                    }

                    ParticipantDTO[] parts = transformer.getDTO(part);
                    return(new GetParticipantsResponse(parts));
                }
                catch (Exception ex)
                {
                    return(new ErrorResponse(ex.Message));
                }
            }
            if (request is SaveParticipantRequest)
            {
                Console.WriteLine("Save participant request......");

                String nume, echipa, cc;
                SaveParticipantRequest save = (SaveParticipantRequest)request;
                nume = save.Name; echipa = save.Team; cc = save.CC;

                try
                {
                    lock (server)
                    {
                        server.saveParticipant(cc, echipa, nume);
                    }
                    return(new OkResponse());
                }
                catch (Exception ex)
                {
                    return(new ErrorResponse(ex.Message));
                }
            }
            if (request is GetEchipeRequest)
            {
                Console.WriteLine("Getting teams request......");
                Echipa[] echipa;
                try
                {
                    lock (server)
                    {
                        echipa = server.getAllTeams();
                    }
                    return(new GetEchipeResponse(transformer.getDTO(echipa)));
                }
                catch (Exception ex)
                {
                    return(new ErrorResponse(ex.Message));
                }
            }
            return(null);
        }