Example #1
0
        public void handleUpdate(UpdateResponse update)
        {
            if (update is IncreaseNoPResponse)
            {
                IncreaseNoPResponse incResp = (IncreaseNoPResponse)update;
                Race r = DTOUtils.getFromDTO(incResp.Race);

                try
                {
                    client.increaseNoContestants(r);
                }catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }
        }
Example #2
0
        public List <Race> getAllRaces()
        {
            sendRequest(new GetRacesRequest());
            Response response = readResponse();

            if (response is GetRacesResponse)
            {
                GetRacesResponse resp = (GetRacesResponse)response;

                IList <Race> races = new List <Race>();
                foreach (RaceDTO race in resp.RaceDTOs)
                {
                    races.Add(DTOUtils.getFromDTO(race));
                }
                return((List <Race>)races);
            }
            return(null);
        }
Example #3
0
        public List <Contestant> getAllContestants()
        {
            sendRequest(new GetContestantsRequest());
            Response response = readResponse();

            if (response is GetContestantsResponse)
            {
                GetContestantsResponse resp = (GetContestantsResponse)response;

                IList <Contestant> contestants = new List <Contestant>();
                foreach (ContestantDTO c in resp.ContestantDTOs)
                {
                    contestants.Add(DTOUtils.getFromDTO(c));
                }
                return((List <Contestant>)contestants);
            }
            return(null);
        }
Example #4
0
        public List <Race> getRacesByEngine(int engine)
        {
            sendRequest(new GetRacesRequest());
            Response response = readResponse();

            if (response is GetRacesResponse)
            {
                GetRacesResponse resp  = (GetRacesResponse)response;
                IList <Race>     races = new List <Race>();
                foreach (RaceDTO r in resp.RaceDTOs)
                {
                    if (r.Engine == engine)
                    {
                        races.Add(DTOUtils.getFromDTO(r));
                    }
                }
                return((List <Race>)races);
            }
            return(null);
        }
Example #5
0
        public List <Contestant> getContestantsByTeam(string team)
        {
            sendRequest(new GetContestantsRequest());
            Response response = readResponse();

            if (response is GetContestantsResponse)
            {
                GetContestantsResponse resp = (GetContestantsResponse)response;

                IList <Contestant> contestants = new List <Contestant>();
                foreach (ContestantDTO c in resp.ContestantDTOs)
                {
                    if (c.Team.Equals(team))
                    {
                        contestants.Add(DTOUtils.getFromDTO(c));
                    }
                }
                return((List <Contestant>)contestants);
            }
            return(null);
        }
        private Response handleRequest(Request request)
        {
            Console.WriteLine("Handle request pentru..." + request);
            Response response = null;

            if (request is LoginRequest)
            {
                Console.WriteLine("Login request...");
                LoginRequest    loginRequest = (LoginRequest)request;
                OfficePersonDTO userDTO      = loginRequest.OfficePersonDTO();
                OfficePers      pers         = DTOUtils.getFromDTO(userDTO);
                try
                {
                    lock (server)
                    {
                        server.login(pers, this);
                        username = pers.Username;
                    }
                    return(new OKResponse());
                }catch (RaceException ex)
                {
                    connected = false;
                    return(new ErrorResponse(ex.Message));
                }
            }

            if (request is LogoutRequest)
            {
                Console.WriteLine("Logout request...");
                LogoutRequest   logReq = (LogoutRequest)request;
                OfficePersonDTO dTO    = logReq.OfficePersonDTO();
                OfficePers      user   = DTOUtils.getFromDTO(dTO);
                try
                {
                    lock (server)
                    {
                        server.logout(user, this);
                    }
                    connected = false;
                    return(new OKResponse());
                }catch (RaceException ex)
                {
                    return(new ErrorResponse(ex.Message));
                }
            }

            if (request is GetRacesRequest)
            {
                Console.WriteLine("Get all races request");
                GetRacesRequest req = (GetRacesRequest)request;
                try
                {
                    IList <Race> races = new List <Race>();
                    lock (server)
                    {
                        races = server.getAllRaces();
                    }
                    IList <RaceDTO> raceDTOs = new List <RaceDTO>();
                    foreach (Race r in races)
                    {
                        RaceDTO raceDTO = DTOUtils.getDTO(r);
                        raceDTOs.Add(raceDTO);
                    }
                    return(new GetRacesResponse((List <RaceDTO>)raceDTOs));
                }catch (Exception ex)
                {
                    throw new RaceException(ex.Message);
                }
            }

            if (request is GetContestantsRequest)
            {
                GetContestantsRequest req = (GetContestantsRequest)request;
                try
                {
                    IList <Contestant> contestants = new List <Contestant>();
                    lock (server)
                    {
                        contestants = server.getAllContestants();
                    }
                    IList <ContestantDTO> contestantDTOs = new List <ContestantDTO>();
                    foreach (Contestant c in contestants)
                    {
                        ContestantDTO dTO = DTOUtils.getDTO(c);
                        contestantDTOs.Add(dTO);
                    }
                    return(new GetContestantsResponse((List <ContestantDTO>)contestantDTOs));
                }catch (Exception e)
                {
                    throw new RaceException(e.Message);
                }
            }

            if (request is SaveRegistrationRequest)
            {
                Console.WriteLine("Saving registration...");
                SaveRegistrationRequest req             = (SaveRegistrationRequest)request;
                RegistrationDTO         registrationDTO = req.RegistrationDTO;
                try
                {
                    lock (server)
                    {
                        server.addContestant(registrationDTO.Contestant.Name, registrationDTO.Contestant.Engine, registrationDTO.Contestant.Team, username);
                    }
                    return(new OKResponse());
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }
            return(response);
        }
Example #7
0
        private Response handleRequest(Request request)
        {
            Response response = null;

            if (request.Type() == RequestType.LOGIN)
            {
                logger.Debug("PROXY SERVER: handleRequest RECEIVED REQUEST type==RequestType.LOGIN");
                Console.WriteLine("Login request ..." + request.Type());
                UserDTO  udto = (UserDTO)request.Data();
                Employee user = DTOUtils.getFromDTO(udto);
                try
                {
                    server.login(user, this);
                    logger.Debug("PROXY SERVER: handleRequest SENT COMMAND TO SERVER server.login");
                    return(okResponse);
                }
                catch (ServicesException e)
                {
                    connected = false;
                    logger.Debug("PROXY SERVER: FAILED handleRequest type==RequestType.LOGIN");
                    return(new Response.Builder().Type(ResponseType.ERROR).Data(e.Message).Build());
                }
            }
            if (request.Type() == RequestType.LOGOUT)
            {
                logger.Debug("PROXY SERVER: handleRequest RECEIVED REQUEST type==RequestType.LOGOUT");
                Console.WriteLine("Logout request");
                UserDTO  udto = (UserDTO)request.Data();
                Employee user = DTOUtils.getFromDTO(udto);
                try
                {
                    server.logout(user, this);
                    connected = false;
                    logger.Debug("PROXY SERVER: handleRequest SENT COMMAND TO SERVER server.logou");
                    return(okResponse);
                }
                catch (ServicesException e)
                {
                    logger.Debug("PROXY SERVER: FAILED handleRequest type==RequestType.LOGOUT");
                    return(new Response.Builder().Type(ResponseType.ERROR).Data(e.Message).Build());
                }
            }

            if (request.Type() == RequestType.GET_SHOWS)
            {
                logger.Debug("PROXY SERVER: handleRequest RECEIVED REQUEST type==RequestType.GET_MATCHES @" + DateTime.Now);
                Console.WriteLine("Get Matches request");
                try
                {
                    Show[]    shows    = server.findAllShows();
                    ShowDTO[] showdtos = DTOUtils.getDTO(shows);
                    logger.Debug("PROXY SERVER: handleRequest SENT COMMAND TO SERVER server.findAllMeci @" + DateTime.Now);
                    return(new Response.Builder().Type(ResponseType.GET_SHOWS).Data(showdtos).Build());
                }
                catch (ServicesException e)
                {
                    logger.Debug("PROXY SERVER: FAILED handleRequest type==RequestType.GET_MATCHES @" + DateTime.Now);
                    return(new Response.Builder().Type(ResponseType.ERROR).Data(e.Message).Build());
                }
            }


            if (request.Type() == RequestType.TICKETS_SOLD)
            {
                logger.Debug("PROXY SERVER: handleRequest RECEIVED REQUEST type==RequestType.TICKETS_SOLD @" + DateTime.Now);
                Console.WriteLine("TICKETS_SOLD update meci request");
                Object[]  data    = (Object[])request.Data();
                ShowDTO   showDTO = (ShowDTO)data[0];
                TicketDTO tcket   = (TicketDTO)data[1];
                Show      s       = DTOUtils.getFromDTO(showDTO);
                Ticket    ticket  = DTOUtils.getFromDTO(tcket);
                try
                {
                    Show shU = server.ticketsSold(s, ticket); // this is the response of the TICKETS_SOLD request
                    logger.Debug("PROXY SERVER: handleRequest SENT COMMAND TO SERVER server.ticketsSold @" + DateTime.Now);
                    ShowDTO sDTO = DTOUtils.getDTO(shU);
                    //return new Response.Builder().Type(ResponseType.UPDATED_SHOWS).Data(sDTO).Build();
                    return(okResponse); // de aici vine double update-ul bun (aici trimiteai bine)
                    //aici trimiti doar o confirmare, nu un update. AICI era. pentru ca el astepta in continuare ok-ul, dar notificarea ta era prinsa in update . asa zic
                }
                catch (ServicesException e)
                {
                    logger.Debug("PROXY SERVER: FAILED handleRequest type==RequestType.TICKETS_SOLD @" + DateTime.Now);
                    return(new Response.Builder().Type(ResponseType.ERROR).Data(e.Message).Build());
                }
            }

            logger.DebugFormat("PROXY SERVER: RETURN RESPONSE handleRequest @" + DateTime.Now + " WARNING: should never reach this point: request type not found !!!", response);
            return(response);
        }