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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
                Operator op = logReq.Operator;
                try
                {
                    lock (server)
                    {
                        server.Login(op, this);
                    }
                    return(new OkResponse());
                }
                catch (FirmaTransportException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is GetCurseRequest)
            {
                Console.WriteLine("Get curse request");
                List <Cursa> curse;
                try
                {
                    lock (server)
                    {
                        curse = server.GetAllCurse();
                    }
                    connected = false;
                    return(new AllCurseResponse(curse));
                }
                catch (FirmaTransportException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetRezervariByCursaRequest)
            {
                Console.WriteLine("GetRezervariByCursaRequest ...");
                GetRezervariByCursaRequest senReq = (GetRezervariByCursaRequest)request;
                int idCUrsa = senReq.IdCursa;
                try
                {
                    List <Rezervare> rezervari;
                    lock (server)
                    {
                        rezervari = server.GetAllByCursa(idCUrsa);
                    }
                    return(new RezervariByCursaResponse(rezervari));
                }
                catch (FirmaTransportException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetClientByIdRequest)
            {
                Console.WriteLine("GetClientById Request ...");
                GetClientByIdRequest getReq = (GetClientByIdRequest)request;
                int idClient = getReq.IdClient;
                try
                {
                    Client client;
                    lock (server)
                    {
                        client = server.FindClient(idClient);
                    }
                    return(new ClientResponse(client));
                }
                catch (FirmaTransportException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is AddRezervareRequest)
            {
                Console.WriteLine("AddRezervare request ...");
                AddRezervareRequest addRezReq = (AddRezervareRequest)request;
                //UserDTO udto = logReq.User;
                // User user = DTOUtils.getFromDTO(udto);
                Rezervare rezervare = addRezReq.Rezervare;
                try
                {
                    lock (server)
                    {
                        server.AddRezervare(rezervare);
                    }
                    return(new OkResponse());
                }
                catch (FirmaTransportException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetClientByNameRequest)
            {
                Console.WriteLine("GetClientById Request ...");
                GetClientByNameRequest getReq = (GetClientByNameRequest)request;
                String NumeClient             = getReq.Nume;
                try
                {
                    Client client;
                    lock (server)
                    {
                        client = server.FindClient(NumeClient);
                    }
                    return(new ClientResponse(client));
                }
                catch (FirmaTransportException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is AddClientRequest)
            {
                Console.WriteLine("AddClient request ...");
                AddClientRequest addRezReq = (AddClientRequest)request;
                //UserDTO udto = logReq.User;
                // User user = DTOUtils.getFromDTO(udto);
                Client client = addRezReq.Client;
                try
                {
                    lock (server)
                    {
                        server.AddClient(client);
                    }
                    return(new OkResponse());
                }
                catch (FirmaTransportException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is UpdateCursaRequest)
            {
                Console.WriteLine("UpdateCursa request ...");
                UpdateCursaRequest addRezReq = (UpdateCursaRequest)request;
                //UserDTO udto = logReq.User;
                // User user = DTOUtils.getFromDTO(udto);
                Cursa cursa = addRezReq.cursa;
                try
                {
                    lock (server)
                    {
                        server.UpdateCursa(cursa);
                    }
                    return(new OkResponse());
                }
                catch (FirmaTransportException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }
            return(response);
        }