public Show[] findAllShows() { if (!isInitialized) { initializeConnection(); this.isInitialized = true; } Request req = new Request.Builder().Type(RequestType.GET_SHOWS).Build(); sendRequest(req); logger.Debug("PROXY CLIENT: findAllShow SENT REQUEST"); Response response = readResponse(); logger.Debug("PROXY CLIENT: findAllShow RECEIVED RESPONSE"); if (response.Type() == ResponseType.ERROR) { String err = response.Data().ToString(); logger.Debug("PROXY CLIENT: FAILED findAllSho"); throw new ServicesException(err); } ShowDTO[] showsDTOS = (ShowDTO[])response.Data(); Show[] shows = DTOUtils.getFromDTO(showsDTOS); logger.Debug("PROXY CLIENT: SUCCESSFUL findAllShow"); return(shows); }
public Zbor findByIdZbor(int id) { Zbor z = null; sendRequest(new FindByIdZborRequest(id)); IResponse response = readResponse(); if (response is FindByIdResponse) { FindByIdResponse r = (FindByIdResponse)response; z = DTOUtils.getFromDTO(r.Zbor); } return(z); }
public List <Zbor> getAllFlight() { List <Zbor> res = new List <Zbor>(); sendRequest(new GetFlightsRequest()); IResponse response = readResponse(); if (response is GetFlightsResponse) { GetFlightsResponse r = (GetFlightsResponse)response; res = DTOUtils.getFromDTO(r.Flights); } return(res); }
public List <Zbor> findByDestinatieDataplecareFlight(string destinatie, string dataPlecare) { List <Zbor> res = new List <Zbor>(); sendRequest(new SearchFlightsRequest(destinatie, dataPlecare)); IResponse response = readResponse(); if (response is SearchFlightsResponse) { SearchFlightsResponse r = (SearchFlightsResponse)response; res = DTOUtils.getFromDTO(r.Flights); } return(res); }
private void handleUpdate(Response response) { if (response.Type() == ResponseType.UPDATED_SHOWS) { // this is the handler for the TICKETS_SOLD request Show show = DTOUtils.getFromDTO((ShowDTO)response.Data()); try { client.notifyTicketSold(show); } catch (ServicesException e) { Console.WriteLine(e.StackTrace); } } }
private void handleUpdate(UpdateResponse update) { if (update is FriendLoggedInResponse) { FriendLoggedInResponse frUpd = (FriendLoggedInResponse)update; User friend = DTOUtils.getFromDTO(frUpd.Friend); Console.WriteLine("Friend logged in " + friend); try { client.friendLoggedIn(friend); } catch (ChatException e) { Console.WriteLine(e.StackTrace); } } if (update is FriendLoggedOutResponse) { FriendLoggedOutResponse frOutRes = (FriendLoggedOutResponse)update; User friend = DTOUtils.getFromDTO(frOutRes.Friend); Console.WriteLine("Friend logged out " + friend); try { client.friendLoggedOut(friend); } catch (ChatException e) { Console.WriteLine(e.StackTrace); } } if (update is NewMessageResponse) { NewMessageResponse msgRes = (NewMessageResponse)update; Message message = DTOUtils.getFromDTO(msgRes.Message); try { client.messageReceived(message); } catch (ChatException e) { Console.WriteLine(e.StackTrace); } } }
public virtual User[] getLoggedFriends(User user) { UserDTO udto = DTOUtils.getDTO(user); sendRequest(new GetLoggedFriendsRequest(udto)); Response response = readResponse(); if (response is ErrorResponse) { ErrorResponse err = (ErrorResponse)response; throw new ChatException(err.Message); } GetLoggedFriendsResponse resp = (GetLoggedFriendsResponse)response; UserDTO[] frDTO = resp.Friends; User[] friends = DTOUtils.getFromDTO(frDTO); return(friends); }
public Show[] findAllShowsForArtist(Artist artist) { ArtistDTO adto = DTOUtils.getDTO(artist); Request req = new Request.Builder().Type(RequestType.GET_SHOWS_W_ARTIST).Data(adto).Build(); sendRequest(req); logger.Debug("PROXY CLIENT: findAllShowWithTickets SENT REQUES"); Response response = readResponse(); logger.Debug("PROXY CLIENT: findAllShowWithTickets RECEIVED RESPONSE"); if (response.Type() == ResponseType.ERROR) { String err = response.Data().ToString(); logger.Debug("PROXY CLIENT: FAILED"); throw new ServicesException(err); } ShowDTO[] showDTOS = (ShowDTO[])response.Data(); Show[] meciuri = DTOUtils.getFromDTO(showDTOS); logger.Debug("PROXY CLIENT: SUCCESSFUL"); return(meciuri); }
private Response handleRequest(Request request) { Response response = null; if (request is LoginRequest) { Console.WriteLine("Login request ..."); LoginRequest logReq = (LoginRequest)request; UserDTO udto = logReq.User; User user = DTOUtils.getFromDTO(udto); try { lock (server) { server.login(user, this); } return(new OkResponse()); } catch (ChatException e) { connected = false; return(new ErrorResponse(e.Message)); } } if (request is LogoutRequest) { Console.WriteLine("Logout request"); LogoutRequest logReq = (LogoutRequest)request; UserDTO udto = logReq.User; User user = DTOUtils.getFromDTO(udto); try { lock (server) { server.logout(user, this); } connected = false; return(new OkResponse()); } catch (ChatException e) { return(new ErrorResponse(e.Message)); } } if (request is SendMessageRequest) { Console.WriteLine("SendMessageRequest ..."); SendMessageRequest senReq = (SendMessageRequest)request; MessageDTO mdto = senReq.Message; Message message = DTOUtils.getFromDTO(mdto); try { lock (server) { server.sendMessage(message); } return(new OkResponse()); } catch (ChatException e) { return(new ErrorResponse(e.Message)); } } if (request is GetLoggedFriendsRequest) { Console.WriteLine("GetLoggedFriends Request ..."); GetLoggedFriendsRequest getReq = (GetLoggedFriendsRequest)request; UserDTO udto = getReq.User; User user = DTOUtils.getFromDTO(udto); try { User[] friends; lock (server) { friends = server.getLoggedFriends(user); } UserDTO[] frDTO = DTOUtils.getDTO(friends); return(new GetLoggedFriendsResponse(frDTO)); } catch (ChatException e) { return(new ErrorResponse(e.Message)); } } return(response); }
private IResponse handleRequest(IRequest request) { IResponse response = null; if (request is LogInRequest) { Console.WriteLine("Login request ..."); LogInRequest logReq = (LogInRequest)request; AngajatDTO udto = logReq.User; Angajat user = DTOUtils.getFromDTO(udto); try { lock (server) { bool ok = server.logIn(user.User, user.Parola); if (ok == true) { response = new OkResponse(); } else { response = new ErrorResponse("log in error"); } } } catch (Exception e) { connected = false; return(new ErrorResponse(e.Message)); } } else if (request is GetFlightsRequest) { List <Zbor> flights = new List <Zbor>(); flights = server.getAllFlight(); response = new GetFlightsResponse(DTOUtils.getDTO(flights)); } else if (request is SearchFlightsRequest) { SearchFlightsRequest r = (SearchFlightsRequest)request; List <Zbor> flights = new List <Zbor>(); flights = server.findByDestinatieDataplecareFlight(r.Destinatie, r.DataPlecare); response = new SearchFlightsResponse(DTOUtils.getDTO(flights)); } else if (request is AddBiletRequest) { AddBiletRequest r = (AddBiletRequest)request; server.addBilet(r.Client, r.Turisti, r.Adresa, r.IdDestinatie); response = new AddBiletResponse(); } else { if (request is FindByIdZborRequest) { FindByIdZborRequest r = (FindByIdZborRequest)request; Zbor z = server.findByIdZbor(r.IdZbor); response = new FindByIdResponse(DTOUtils.getDTO(z)); } } return(response); }