public void logout(string username, IObserver user) { AgentDTO adto = new AgentDTO(username, ""); LogoutRequest logoutRequest = new LogoutRequest(adto); sendRequest(logoutRequest); IResponse response = readResponse(); if (response is OkResponse) { closeConnection(); } if (response is ErrorResponse) { ErrorResponse resp = (ErrorResponse)response; throw new ServicesException(resp.Message); } }
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); }
private object handleRequest(Request request) { Response response = null; if (request is LoginRequest) { Console.WriteLine("Login request ..."); LoginRequest logReq = (LoginRequest)request; AgencyUser agencyUser = logReq.AgencyUser; try { lock (server) { server.Login(agencyUser, this); } return(new OkResponse()); } catch (TouristAttractiontException e) { connected = false; return(new ErrorResponse(e.Message)); } } if (request is LogoutRequest) { Console.WriteLine("Logout request ..."); LogoutRequest logReq = (LogoutRequest)request; AgencyUser agencyUser = logReq.AgencyUser; try { lock (server) { server.Logout(agencyUser, this); } return(new OkResponse()); } catch (TouristAttractiontException e) { connected = false; return(new ErrorResponse(e.Message)); } } if (request is GetTripsRequest) { Console.WriteLine("Get Trips request"); GetTripsRequest getReq = (GetTripsRequest)request; IEnumerable <Trip> trips; try { lock (server) { trips = server.FindAllTrips(); } return(new GetTripsResponse(trips)); } catch (TouristAttractiontException e) { connected = false; return(new ErrorResponse(e.Message)); } } if (request is GetSearchedTripsRequest) { Console.WriteLine("Find searched trips request"); GetSearchedTripsRequest getReq = (GetSearchedTripsRequest)request; TripDTO tripDTO = getReq.TripDTO; List <Trip> trips; try { lock (server) { trips = (List <Trip>)server.SearchTripByTouristAttractionAndLeavingHour(tripDTO.TouristAttraction, tripDTO.Hour1, tripDTO.Hour2); } return(new GetSearchedTripsResponse(trips)); } catch (TouristAttractiontException e) { connected = false; return(new ErrorResponse(e.Message)); } } if (request is FindAgencyUserRequest) { Console.WriteLine("Finding agency user"); FindAgencyUserRequest findReq = (FindAgencyUserRequest)request; AgencyUserDTO agencyUserDTO = findReq.AgencyUser; AgencyUser agencyUser; try { lock (server) { agencyUser = server.SearchAgencyUserByUserNameAndPassword(agencyUserDTO.userName, agencyUserDTO.password); } return(new FindAgencyUserResponse(agencyUser)); } catch (TouristAttractiontException e) { connected = false; return(new ErrorResponse(e.Message)); } } if (request is AddReservationRequest) { Console.WriteLine("Add Reservation Request"); AddReservationRequest findReq = (AddReservationRequest)request; Reservation reservation = findReq.Reservation; try { lock (server) { server.AddReservation(reservation); } return(new OkResponse()); } catch (TouristAttractiontException e) { connected = false; return(new ErrorResponse(e.Message)); } } if (request is UpdateTripRequest) { Console.WriteLine("Update Trip Request"); UpdateTripRequest findReq = (UpdateTripRequest)request; Trip trip = findReq.Trip; try { lock (server) { server.UpdateTrip(trip); } return(new OkResponse()); } catch (TouristAttractiontException e) { connected = false; return(new ErrorResponse(e.Message)); } } if (request is GetReservsationSizeRequest) { Console.WriteLine("Reservation Size Request"); GetReservsationSizeRequest findReq = (GetReservsationSizeRequest)request; int size = 0; try { lock (server) { size = server.GetReservationsSize(); } return(new GetReservationSizeRespons(size)); } catch (TouristAttractiontException e) { connected = false; return(new ErrorResponse(e.Message)); } } return(response); }
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 (Error 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 (Error e) { return(new ErrorResponse(e.Message)); } } if (request is GetShowsRequest) { Console.WriteLine("Get shows request"); GetShowsRequest getShowsRequest = (GetShowsRequest)request; try { Show[] shows = server.GetAll(); ShowDto[] showDtos = DtoUtils.getDto(shows); return(new GetShowsResponse(showDtos)); } catch (Error e) { return(new ErrorResponse(e.Message)); } } if (request is GetArtistsByDateRequest) { Console.WriteLine("Get artists by date request"); GetArtistsByDateRequest getArtistsByDateRequest = (GetArtistsByDateRequest)request; String date = getArtistsByDateRequest.Date; try { Artist[] artists = server.GetArtists(date); ArtistDto[] artistDtos = DtoUtils.GetDto(artists); return(new GetArtistsByDateResponse(artistDtos)); } catch (Error e) { return(new ErrorResponse(e.Message)); } } if (request is BuyTicketRequest) { Console.WriteLine("Buy ticket request"); BuyTicketRequest buyTicketRequest = (BuyTicketRequest)request; TicketDto ticketDto = buyTicketRequest.TicketDto; Ticket ticket = DtoUtils.GetFromDto(ticketDto); try { lock (server) { server.SellTickets(ticket); } return(new OkResponse()); } catch (InvalidPurchaseException e) { return(new ErrorResponse(e.Message)); } catch (Error e) { return(new ErrorResponse(e.Message)); } } return(response); }
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); User loggedUser = null; UserDTO userDto = null; try { lock (server) { loggedUser = server.login(user, this); userDto = DTOUtils.getDTO(loggedUser); } return(new OkResponse(userDto)); } catch (TriatlonException 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 (TriatlonException e) { return(new ErrorResponse(e.Message)); } } if (request is AddResultRequest) { Console.WriteLine("SendMessageRequest ..."); AddResultRequest addReq = (AddResultRequest)request; ResultDTO resultDto = addReq.Result; Result result = DTOUtils.getFromDTO(resultDto); try { lock (server) { server.addResult(result); } return(new OkResponse()); } catch (TriatlonException e) { return(new ErrorResponse(e.Message)); } } if (request is GetParticipantsByScoreRequest) { Console.WriteLine("GetParticipantsByScore Request ..."); GetParticipantsByScoreRequest getReq = (GetParticipantsByScoreRequest)request; int idStage = getReq.IdStage; try { Participant[] participants; lock (server) { participants = server.getParticipantsByScore(idStage); } // UserDTO[] frDTO =DTOUtils.getDTO(friends); return(new GetParticipantsByScoreResponse(participants)); } catch (TriatlonException e) { return(new ErrorResponse(e.Message)); } } if (request is GetParticipantsAndScoreRequest) { Console.WriteLine("GetParticipantsAndScore Request ..."); GetParticipantsAndScoreRequest getReq = (GetParticipantsAndScoreRequest)request; try { ParticipantDTO[] participants; lock (server) { participants = server.getParticipantsAndScore(); } // UserDTO[] frDTO =DTOUtils.getDTO(friends); return(new GetParticipantsAndScoreResponse(participants)); } catch (TriatlonException e) { return(new ErrorResponse(e.Message)); } } if (request is FindParticipantRequest) { Console.WriteLine("FindParticipant Request ..."); FindParticipantRequest getReq = (FindParticipantRequest)request; int id = getReq.Id; try { Participant participant; lock (server) { participant = server.findParticipant(id); } return(new FindParticipantResponse(participant)); } catch (TriatlonException e) { return(new ErrorResponse(e.Message)); } } if (request is FindUserRequest) { Console.WriteLine("FindUser Request ..."); FindUserRequest getReq = (FindUserRequest)request; int id = getReq.Id; try { User user; lock (server) { user = server.findUser(id); } return(new FindUserResponse(user)); } catch (TriatlonException e) { return(new ErrorResponse(e.Message)); } } if (request is FindUserByUsernameRequest) { Console.WriteLine("FindUser Request ..."); FindUserByUsernameRequest getReq = (FindUserByUsernameRequest)request; UserDTO udto = getReq.User; User user = DTOUtils.getFromDTO(udto); try { User user1; lock (server) { user1 = server.findUserByUsername(user); } return(new FindUserByUsernameResponse(user1)); } catch (TriatlonException e) { return(new ErrorResponse(e.Message)); } } return(response); }
private ObjectResponseProtocol.Response handleRequest(Request request) { ObjectResponseProtocol.Response response = null; if (request is LoginRequest) { LoginRequest loginRequest = (LoginRequest)request; Employee employee = loginRequest.Employee; try { Employee loggedEmployee; lock (server) { loggedEmployee = server.LoginEmployee(employee.Username, employee.Password, this); } return(new ObjectResponseProtocol.LoggedReponse(loggedEmployee)); } catch (ValidationException e) { connected = false; return(new ObjectResponseProtocol.ErrorResponse(e.Message)); } } if (request is LogoutRequest) { LogoutRequest logoutRequest = (LogoutRequest)request; Employee employee = logoutRequest.Employee; try { lock (server) { server.Logout(employee, this); } connected = false; return(new ObjectResponseProtocol.OkResponse()); } catch (ValidationException e) { return(new ObjectResponseProtocol.ErrorResponse(e.Message)); } } if (request is RegisterRequest) { RegisterRequest registerRequest = (RegisterRequest)request; Employee employee = registerRequest.Employee; try { Employee registeredEmployee; lock (server) { registeredEmployee = server.RegisterEmployee(employee.Username, employee.Password); } return(new ObjectResponseProtocol.RegisteredResponse(registeredEmployee)); } catch (ValidationException e) { return(new ObjectResponseProtocol.ErrorResponse(e.Message)); } } if (request is GetAllChallengesRequest) { GetAllChallengesRequest getAllChallengesRequest = (GetAllChallengesRequest)request; try { List <ChallengeDTO> challenges; lock (server) { challenges = server.GetAllChallenges(); } return(new ObjectResponseProtocol.GetAllChallengesResponse(challenges)); } catch (ValidationException e) { return(new ObjectResponseProtocol.ErrorResponse(e.Message)); } } if (request is GetAllChildrenRequest) { GetAllChildrenRequest getAllChildrenRequest = (GetAllChildrenRequest)request; try { List <ChildDTO> children; lock (server) { children = server.GetAllChildren(); } return(new ObjectResponseProtocol.GetAllChildrenResponse(children)); } catch (ValidationException e) { return(new ObjectResponseProtocol.ErrorResponse(e.Message)); } } if (request is RegisterChildRequest) { RegisterChildRequest registerChildRequest = (RegisterChildRequest)request; RegistrationDTO registration = registerChildRequest.Registration; try { Child child; lock (server) { child = server.RegisterChild(registration.Name, registration.Age, registration.Challenge1, registration.Challenge2); } return(new ObjectResponseProtocol.RegisteredChildResponse(child)); } catch (ValidationException e) { return(new ObjectResponseProtocol.ErrorResponse(e.Message)); } } if (request is GetChallengeByPropertiesRequest) { GetChallengeByPropertiesRequest getChallengeByPropertiesRequest = (GetChallengeByPropertiesRequest)request; Challenge challenge = getChallengeByPropertiesRequest.Challenge; try { Challenge foundChallenge; lock (server) { foundChallenge = server.GetChallengeByProperties(challenge.MinimumAge, challenge.MaximumAge, challenge.Name); } return(new ObjectResponseProtocol.GetChallengeByPropertiesResponse(foundChallenge)); } catch (ValidationException e) { return(new ObjectResponseProtocol.ErrorResponse(e.Message)); } } if (request is GetChildrenByIdRequest) { GetChildrenByIdRequest getChildrenByIdRequest = (GetChildrenByIdRequest)request; long cid = getChildrenByIdRequest.Cid; try { List <Child> children; lock (server) { children = server.GetChildrenById(cid); } return(new ObjectResponseProtocol.GetChildrenByIdResponse(children)); } catch (ValidationException e) { return(new ObjectResponseProtocol.ErrorResponse(e.Message)); } } return(response); }
private IResponse handleRequest(IRequest request) { if (request is LoginRequest) { Console.WriteLine("login request;"); LoginRequest loginRequest = (LoginRequest)request; AgentDTO adto = loginRequest.Agent; try { bool check; lock (server) { check = server.login(adto.User, adto.Password, this); } if (check == true) { return(new OkResponse()); } else { return(new ErrorResponse("USER SAUY PAROLA GRESITE")); } } catch (ServicesException e) { connected = false; return(new ErrorResponse(e.Message)); } } if (request is GetAllExcursiiRequest) { Console.WriteLine("getAllExcursii request;"); try { Excursie[] excursii = null; lock (server) { excursii = server.findAll().ToArray(); } ExcursieDTO[] excursiiDTO = DTOUtils.getDTO(excursii); return(new GetAllExcursiiResponse(excursiiDTO)); } catch (ServicesException e) { return(new ErrorResponse(e.Message)); } } if (request is GetByDateRequest) { Console.WriteLine("getByDate request;"); GetByDateRequest getRequest = (GetByDateRequest)request; FilterDTO fdto = getRequest.Filter; try { Excursie[] excursii = null; lock (server) { excursii = server.findByDate(fdto.Destination, fdto.Begin, fdto.End).ToArray(); } ExcursieDTO[] excursiiDTO = DTOUtils.getDTO(excursii); return(new GetByDateResponse(excursiiDTO)); } catch (ServicesException e) { return(new ErrorResponse(e.Message)); } } if (request is AddRezervareRequest) { Console.WriteLine("addRezervare request;"); AddRezervareRequest addRequest = (AddRezervareRequest)request; RezervareDTO rdto = addRequest.Rezervare; Rezervare rezervare = DTOUtils.getFromDTO(rdto); try { lock (server) { server.addRezervare(rezervare); } return(new OkResponse()); } catch (ServicesException e) { return(new ErrorResponse(e.Message)); } } if (request is LogoutRequest) { Console.WriteLine("logout request;"); LogoutRequest logoutRequest = (LogoutRequest)request; AgentDTO adto = logoutRequest.Agent; try { lock (server) { server.logout(adto.User, this); } connected = false; return(new OkResponse()); } catch (ServicesException e) { return(new ErrorResponse(e.Message)); } } return(null); }
private Response handleRequest(Request request) { Response response = null; if (request is LoginRequest) { Console.WriteLine("Login request ..."); LoginRequest logReq = (LoginRequest)request; User user = logReq.User; try { lock (server) { server.login(user, this); } return(new OkResponse()); } catch (PersistenceException e) { connected = false; return(new ErrorResponse(e.Message)); } } if (request is LogoutRequest) { Console.WriteLine("Logout request"); LogoutRequest logReq = (LogoutRequest)request; User user = logReq.User; try { lock (server) { server.logout(user); } connected = false; return(new OkResponse()); } catch (PersistenceException e) { return(new ErrorResponse(e.Message)); } } if (request is getExcursiiRequest) { Console.WriteLine("Get trips request"); try { List <Excursie> list; lock (server) { list = server.findAllExcursii(); } return(new getExcursiiResponse(list)); } catch (PersistenceException exc) { return(new ErrorResponse(exc.Message)); } } if (request is getExcursiiFilteredRequest) { getExcursiiFilteredRequest request1 = (getExcursiiFilteredRequest)request; try { List <Excursie> all; lock (server) { all = server.getExcursiiTableFiltru(request1.getObiectiv(), request1.getDupaOra().ToString(), request1.getInainteDe().ToString()); } return(new getExcursiiFilteredResponse(all)); } catch (PersistenceException e) { return(new ErrorResponse(e.Message)); } } if (request is findExcursieRequest) { try { Excursie exc; lock (server) { exc = server.findOneExcursie(((findExcursieRequest)request).getIdExc()); } return(new findExcursieResponse(exc)); } catch (PersistenceException exc) { return(new ErrorResponse(exc.Message)); } } if (request is updateExcursieRequest) { try { updateExcursieRequest request1 = (updateExcursieRequest)request; lock (server) { server.updateExcursie(request1.getExcursie1()); } return(new OkResponse()); } catch (PersistenceException exc) { return(new ErrorResponse(exc.Message)); } } if (request is addRezervareRequest) { try { lock (server) { server.addRezervare(((addRezervareRequest)request).getRezervare()); } return(new OkResponse()); } catch (PersistenceException exc) { return(new ErrorResponse(exc.Message)); } } return(null); }