コード例 #1
0
        public void addRezervare(Rezervare r)
        {
            RezervareDTO        rezervareDto = DTOUtils.getDTO(r);
            AddRezervareRequest addRequest   = new AddRezervareRequest(rezervareDto);

            sendRequest(addRequest);
            IResponse response = readResponse();

            if (response is ErrorResponse)
            {
                ErrorResponse resp = (ErrorResponse)response;
                throw  new ServicesException(resp.Message);
            }
        }
コード例 #2
0
        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);
        }