private Response handleRequest(Request request)
        {
            Response response = null;

            if (request is LoginRequest)
            {
                Console.WriteLine("Login request ...");
                LoginRequest logReq = (LoginRequest)request;
                Organizer    org    = logReq.Organizer;

                try {
                    lock (server) {
                        server.login(org, this);
                    }
                    return(new OkResponse());
                } catch (SwimException e) {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is LogoutRequest)
            {
                Console.WriteLine("Logout request");
                LogoutRequest logReq = (LogoutRequest)request;
                Organizer     org    = logReq.Organizer;
                try {
                    lock (server) {
                        server.logout(org, this);
                    }
                    connected = false;
                    return(new OkResponse());
                } catch (SwimException e) {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetEventsNosPartRequest)
            {
                Console.WriteLine("GetEventsNosPartRequest request ...");
                try {
                    lock (server) {
                        return(new GetEventsNosPartResponse(server.findEventsNosParticipants()));
                    }
                } catch (SwimException e) {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is GetAllPart4EventRequest)
            {
                Console.WriteLine("Searching participants for event...");
                GetAllPart4EventRequest partReq = (GetAllPart4EventRequest)request;
                Event ev = partReq.Event;
                try {
                    lock (server) {
                        return(new GetAllPart4EventResponse(server.findPartForEvent(ev)));
                    }
                } catch (SwimException e) {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is GetAllPartRequest)
            {
                Console.WriteLine("Searching all participants...");
                try {
                    lock (server) {
                        return(new GetAllPartResponse(server.findAllParticipants()));
                    }
                } catch (SwimException e) {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is AddPart2EventRequest)
            {
                Console.WriteLine("Adding participant to event...");
                AddPart2EventRequest partReq = (AddPart2EventRequest)request;
                EventPartDTO         ev      = partReq.EventPartDTOent;
                try {
                    lock (server) {
                        server.addPart2Event(ev);
                    }
                    return(new OkResponse());
                } catch (SwimException e) {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is AddParticipantRequest)
            {
                Console.WriteLine("Adding participant...");
                AddParticipantRequest partReq = (AddParticipantRequest)request;
                Participant           part    = partReq.Participant;
                try {
                    lock (server) {
                        server.addParticipant(part);
                    }
                    return(new OkResponse());
                } catch (SwimException e) {
                    return(new ErrorResponse(e.Message));
                }
            }

            return(response);
        }
        private Response handleRequest(Request request)
        {
            Response response = null;

            //LOGIN
            if (request is LoginRequest)
            {
                Console.WriteLine("Login request... ");
                LoginRequest loginRequest = (LoginRequest)request;
                Volunteer    volunteer    = loginRequest.Volunteer;
                try
                {
                    lock (server)
                    {
                        server.login(this, volunteer.Username, volunteer.Password);
                    }

                    return(new OKResponse());
                }
                catch (TeledonException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            //LOGOUT
            if (request is LogoutRequest)
            {
                Console.WriteLine("Logout request... ");
                LogoutRequest logoutRequest = (LogoutRequest)request;
                try
                {
                    lock (server)
                    {
                        server.logout(this);
                    }

                    connected = false;
                    return(new OKResponse());
                }
                catch (TeledonException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            //GET ALL CASES
            if (request is GetAllCasesRequest)
            {
                Console.WriteLine("Get all cases request... ");
                GetAllCasesRequest getAllCasesRequest = (GetAllCasesRequest)request;
                try
                {
                    lock (server)
                    {
                        IEnumerable <Case> cases = server.getAllCases();
                        return(new GetAllCasesResponse(cases));
                    }
                }
                catch (TeledonException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            //GET ALL DONORS
            if (request is GetAllDonorsRequest)
            {
                Console.WriteLine("Get all donors request...");
                GetAllDonorsRequest getAllDonorsRequest = (GetAllDonorsRequest)request;
                string subtring = getAllDonorsRequest.Substring;
                try
                {
                    lock (server)
                    {
                        IEnumerable <Donor> donors = server.searchDonorByName(subtring);
                        return(new GetAllDonorsResponse(donors));
                    }
                }
                catch (TeledonException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            //NEW DONATION
            if (request is NewDonationRequest)
            {
                Console.WriteLine("New donation request...");
                NewDonationRequest newDonationRequest = (NewDonationRequest)request;
                int    donorId   = newDonationRequest.DonorId;
                String name      = newDonationRequest.Name;
                String address   = newDonationRequest.Address;
                String telephone = newDonationRequest.Telephone;
                Double sum       = newDonationRequest.Sum;
                int    caseId    = newDonationRequest.CaseId;
                try
                {
                    lock (server)
                    {
                        server.saveDonation(donorId, name, address, telephone, sum, caseId);
                        return(new OKResponse());
                    }
                }
                catch (TeledonException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            return(response);
        }
        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);
        }
Beispiel #4
0
        private object handleRequest(Request request)
        {
            Response response = null;

            if (request is LoginRequest)
            {
                Console.WriteLine("Login request ...");
                LoginRequest logReq  = (LoginRequest)request;
                Angajat      angajat = logReq.Angajat;
                try
                {
                    lock (server)
                    {
                        server.LogIn(angajat, this);
                    }
                    return(new OkResponse());
                }
                catch (FlightException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }


            if (request is LogoutRequest)
            {
                Console.WriteLine("Logout request ...");
                LogoutRequest logReq  = (LogoutRequest)request;
                Angajat       angajat = logReq.User;
                try
                {
                    lock (server)
                    {
                        server.LogOut(angajat, this);
                    }
                    return(new OkResponse());
                }
                catch (FlightException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetZboruriRequest)
            {
                Console.WriteLine("Flights get request");
                GetZboruriRequest  getReq = (GetZboruriRequest)request;
                IEnumerable <Zbor> zboruri;
                try
                {
                    lock (server)
                    {
                        zboruri = server.GetZboruri();
                    }
                    return(new GetZboruriResponse(zboruri));
                }
                catch (FlightException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetZboruriCautareRequest)
            {
                Console.WriteLine("Find fligts request");
                GetZboruriCautareRequest getReq = (GetZboruriCautareRequest)request;
                ZborDTO2 zbor = getReq.zborDTO2;
                IEnumerable <ZborDTO> zborDTOs;
                try
                {
                    lock (server)
                    {
                        zborDTOs = server.GetZboruriCautare(zbor.destinatie, zbor.data);
                    }
                    return(new GetZboruriCautareResponse(zborDTOs));
                }
                catch (FlightException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is FindClientRequest)
            {
                Console.WriteLine("Finding client");
                FindClientRequest findReq   = (FindClientRequest)request;
                ClientDTO         clientDTO = findReq.Client;
                Client            client;
                try
                {
                    lock (server)
                    {
                        client = server.FindClient(clientDTO.nume, clientDTO.adresa);
                    }
                    return(new FindClientResponse(client));
                }
                catch (FlightException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is FindZborRequest)
            {
                Console.WriteLine("Finding flight");
                FindZborRequest findReq  = (FindZborRequest)request;
                ZborDTO3        zborDTO3 = findReq.ZborDTO3;
                Zbor            zbor;
                try
                {
                    lock (server)
                    {
                        zbor = server.FindZbor(zborDTO3.destinatie, zborDTO3.data, zborDTO3.ora);
                    }
                    return(new FindZborResponse(zbor));
                }
                catch (FlightException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is FindIndexRequest)
            {
                Console.WriteLine("Finding index");
                FindIndexRequest findReq = (FindIndexRequest)request;
                int index;
                try
                {
                    lock (server)
                    {
                        index = server.FindIndex();
                    }
                    return(new FindIndexResponse(index));
                }
                catch (FlightException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is BuyTickeRequest)
            {
                Console.WriteLine("Ticket bought");
                BuyTickeRequest req   = (BuyTickeRequest)request;
                Bilet           bilet = req.Bilet;
                int             id    = req.Id;
                int             nr    = req.NrLocuri;
                try
                {
                    lock (server)
                    {
                        server.CumparaBilet(bilet, id, nr);
                    }
                    return(new OkResponse());
                }catch (FlightException e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            return(response);
        }
        private Response handleRequest(Request request)
        {
            Response response = null;

            if (request is LoginRequest)
            {
                Console.WriteLine("Login request ...");
                LoginRequest logReq = (LoginRequest)request;

                Angajat user = logReq.getUser();

                try
                {
                    lock (server)
                    {
                        server.login(user, this);
                    }
                    return(new OkResponse());
                }
                catch (TeledonException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is LogoutRequest)
            {
                Console.WriteLine("Logout request");
                LogoutRequest logReq = (LogoutRequest)request;
                Angajat       udto   = logReq.getUser();


                try
                {
                    lock (server)
                    {
                        server.logout(udto, this);
                    }
                    connected = false;
                    return(new OkResponse());
                }
                catch (TeledonException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is DoDonationRequest)
            {
                DoDonationRequest senReq = (DoDonationRequest)request;
                Int32             cazId  = senReq.getCazId();
                //            String numeDonator = senReq.getNumeDonator();
                //            String adresa = senReq.getAdresa();
                //            String nrTel = senReq.getNrTel();
                float suma      = senReq.getSumaDonata();
                Int32 idDonator = senReq.getIdDonator();
                try
                {
                    //server.donatieS(cazId,numeDonator,adresa,nrTel,suma);
                    server.donatieS(suma, idDonator, cazId);
                    return(new OkResponse());
                }
                catch (TeledonException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetCazuriDTORequest)
            {
                GetCazuriDTORequest getReq = (GetCazuriDTORequest)request;


                try
                {
                    List <CazDTO> cauriDTO = server.getCauriDTO();
                    return(new GetCazuriDTOResponse(cauriDTO));
                }
                catch (TeledonException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetDonatoriRequest)
            {
                Console.WriteLine("intrat in obj worker getdonator reqest");

                GetDonatoriRequest getReq = (GetDonatoriRequest)request;
                try
                {
                    List <string> cauriDTO = server.getDonators();
                    Console.WriteLine("se trimite" + cauriDTO);
                    return(new GetDonatoriResponse(cauriDTO));
                }
                catch (TeledonException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }


            if (request is GetCazIdRequest)
            {
                GetCazIdRequest getreq = (GetCazIdRequest)request;
                try
                {
                    Int32 id = server.getCazId(getreq.getCazCaritabilDTO());
                    return(new GetCazIdResponse(id));
                }
                catch (TeledonException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetDonatorRequest)
            {
                GetDonatorRequest getReq = (GetDonatorRequest)request;
                try
                {
                    string  nume    = getReq.getNume();
                    Donator donator = server.getDonator(nume);
                    return(new GetDonatorResponse(donator));
                }
                catch (TeledonException exeption)
                {
                    return(new ErrorResponse(exeption.Message));
                }
            }

            if (request is UpdateDonatorRequest)
            {
                UpdateDonatorRequest req = (UpdateDonatorRequest)request;
                try
                {
                    server.updateDonator(req.getDonator());
                    return(new OkResponse());
                }
                catch (TeledonException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is SaveDonatorRequest)
            {
                SaveDonatorRequest req = (SaveDonatorRequest)request;
                try
                {
                    server.saveDonator(req.getDonator());
                    return(new OkResponse());
                }
                catch (TeledonException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is commitDonatoriRequest)
            {
                commitDonatoriRequest req = (commitDonatoriRequest)request;
                try
                {
                    server.commitDonatori(req.getNume(), req.getNrTel(), req.getAdresa());
                    return(new OkResponse());
                }
                catch (TeledonException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is CheckRequest)
            {
                CheckRequest req = (CheckRequest)request;
                try
                {
                    server.check(req.getAngajat());
                    return(new OkResponse());
                }
                catch (TeledonException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            return(response);
        }
Beispiel #6
0
        private Response handleRequest(Request request)
        {
            Response response = null;

            if (request is LoginRequest)
            {
                Console.WriteLine("Login request ...");
                LoginRequest loginRequest = (LoginRequest)request;
                UserDTO      userDto      = loginRequest.UserDto;
                try
                {
                    User user = null;
                    lock (server)
                    {
                        user = server.login(userDto.UserName, userDto.Password, this);
                    }
                    return(new UserLoggedInResponse(user));
                }
                catch (LibraryException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is LogoutRequest)
            {
                Console.WriteLine("Logout request");
                LogoutRequest logoutRequest = (LogoutRequest)request;
                int           userId        = logoutRequest.UserId;
                try
                {
                    lock (server)
                    {
                        server.logout(userId, this);
                    }
                    connected = false;
                    return(new OkResponse());
                }
                catch (LibraryException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetAvailableBooksRequest)
            {
                Console.WriteLine("SendMessageRequest ...");
                try
                {
                    List <Book> availableBooks = null;
                    lock (server)
                    {
                        availableBooks = server.getAvailableBooks();
                    }
                    return(new GetAvailableBooksResponse(availableBooks));
                }
                catch (LibraryException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetUserBooksRequest)
            {
                Console.WriteLine("GetLoggedFriends Request ...");
                GetUserBooksRequest getUserBooksRequest = (GetUserBooksRequest)request;
                int userId = getUserBooksRequest.UserId;
                try
                {
                    List <Book> userBooks = null;
                    lock (server)
                    {
                        userBooks = server.getUserBooks(userId);
                    }
                    return(new GetUserBooksResponse(userBooks));
                }
                catch (LibraryException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is SearchBooksRequest)
            {
                Console.WriteLine("GetLoggedFriends Request ...");
                SearchBooksRequest searchBooksRequest = (SearchBooksRequest)request;
                String             searchKey          = searchBooksRequest.SearchKey;
                try
                {
                    List <Book> foundBooks = null;
                    lock (server)
                    {
                        foundBooks = server.searchBooks(searchKey);
                    }
                    return(new SearchBooksResponse(foundBooks));
                }
                catch (LibraryException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is BorrowBookRequest)
            {
                Console.WriteLine("GetLoggedFriends Request ...");
                BorrowBookRequest borrowBookRequest = (BorrowBookRequest)request;
                UserBookDTO       userBookDto       = borrowBookRequest.UserBookDto;
                try
                {
                    lock (server)
                    {
                        server.borrowBook(userBookDto.UserId, userBookDto.BookId);
                    }
                    return(new OkResponse());
                }
                catch (LibraryException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is ReturnBookRequest)
            {
                Console.WriteLine("GetLoggedFriends Request ...");
                ReturnBookRequest returnBookRequest = (ReturnBookRequest)request;
                UserBookDTO       userBookDto       = returnBookRequest.UserBookDto;
                try
                {
                    lock (server)
                    {
                        server.returnBook(userBookDto.UserId, userBookDto.BookId);
                    }
                    return(new OkResponse());
                }
                catch (LibraryException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            return(response);
        }