public void increaseNoContestants(Race race)
        {
            Console.WriteLine("aici");
            RaceDTO dTO = DTOUtils.getDTO(race);

            try
            {
                sendResponse(new IncreaseNoPResponse(dTO));
            }catch (Exception e)
            {
                throw new RaceException("Sending error..." + e.Message);
            }
        }
Exemplo n.º 2
0
        public void logout(OfficePers user, IClient client)
        {
            OfficePersonDTO officePersonDTO = DTOUtils.getDTO(user);

            sendRequest(new LogoutRequest(officePersonDTO));
            Response response = readResponse();

            closeConnection();
            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                throw new RaceException(err.Message);
            }
        }
Exemplo n.º 3
0
        public void notifyTicketSold(Show show)
        {
            ShowDTO  showdto = DTOUtils.getDTO(show);
            Response resp    = new Response.Builder().Type(ResponseType.UPDATED_SHOWS).Data(showdto).Build();

            logger.Debug("PROXY SERVER: ticketsSold BUILT RESPONSE @" + DateTime.Now);
            Console.WriteLine("Tickets sold for match " + show);
            try
            {
                sendResponse(resp);
                logger.DebugFormat("PROXY SERVER: ticketsSold SENT RESPONSE @" + DateTime.Now, resp);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
Exemplo n.º 4
0
        public void login(OfficePers user, IClient client)
        {
            initializeConnection();
            OfficePersonDTO udto = DTOUtils.getDTO(user);

            sendRequest(new LoginRequest(udto));
            Response response = readResponse();

            if (response is OKResponse)
            {
                this.client = client;
                return;
            }
            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                closeConnection();
                throw new RaceException(err.Message);
            }
        }
        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);
        }
Exemplo n.º 6
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);
        }