public void LogOut(Employee employee) { var employeeDto = DTOUtils.GetEmployeeDto(employee); SendRequest(new LogOutRequest(employeeDto)); var response = ReadResponse(); if (response is ErrorResponse) { throw new Exception("Error Log Out"); } }
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); } }
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); } }
public bool LogIn(Employee employee, ITransportObserver client) { InitializeConnection(); var udto = DTOUtils.GetEmployeeDto(employee); SendRequest(new LoginRequest(udto)); var response = ReadResponse(); if (response is OkResponse) { _client = client; return(true); } CloseConnection(); return(false); }
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); } } }
public List <Ride> AddBooking(Ride ride, Booking booking, Employee employee, Client client) { var clientDto = DTOUtils.GetClientDto(client); var bookingDto = DTOUtils.GetBookingDto(booking); var rideDto = DTOUtils.GetRideDto(ride); var employeeDto = DTOUtils.GetEmployeeDto(employee); SendRequest(new BookingRequest(bookingDto, rideDto, employeeDto, clientDto)); var response = ReadResponse(); if (response is ErrorResponse) { throw new Exception("Error add reservation"); } return(((GetRidesResponse)response).Rides.Select(DTOUtils.GetFromDto).ToList()); }
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); } }
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); }
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); }
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); } }
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); }
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); }
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); }