Beispiel #1
0
        public void updateCazCaritabil(CazCaritabil nou)
        {
            CazCaritabilDTO newDTO = DTOUtils.getDTO(nou);

            sendRequest(new UpdateCazRequest(newDTO));
            Response response = readResponse();

            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                throw new MyException(err.Message);
            }
        }
Beispiel #2
0
        public void addDonatie(Donatie donatie)
        {
            DonatieDTO donatieDTO = DTOUtils.getDTO(donatie);

            sendRequest(new SaveDonatieRequest(donatieDTO));
            Response response = readResponse();

            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                throw new MyException(err.Message);
            }
        }
Beispiel #3
0
        public virtual void logout(Voluntar voluntar, IObserver client)
        {
            VoluntarDTO udto = DTOUtils.getDTO(voluntar);

            sendRequest(new LogoutRequest(udto));
            Response response = readResponse();

            closeConnection();
            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                throw new MyException(err.Message);
            }
        }
Beispiel #4
0
        public void updateDonator(Donator donator)
        {
            DonatorDTO dto = DTOUtils.getDTO(donator);

            Console.WriteLine("Donator received  " + donator);
            try
            {
                sendResponse(new SaveDonatorResponse(dto));
            }
            catch (Exception e)
            {
                throw new MyException("Sending error: " + e);
            }
        }
Beispiel #5
0
        public void donatieAdded(Donatie donatie)
        {
            DonatieDTO dto = DTOUtils.getDTO(donatie);

            Console.WriteLine("Donatie received  " + donatie);
            try
            {
                sendResponse(new SaveDonatieResponse(dto));
            }
            catch (Exception e)
            {
                throw new MyException("Sending error: " + e);
            }
        }
Beispiel #6
0
        public void updateSC(CazCaritabil caz)
        {
            CazCaritabilDTO dto = DTOUtils.getDTO(caz);

            Console.WriteLine("CazCaritabil received  " + caz);
            try
            {
                sendResponse(new UpdateCazResponse(dto));
            }
            catch (Exception e)
            {
                throw new MyException("Sending error: " + e);
            }
        }
Beispiel #7
0
        public virtual CazCaritabil[] getCazuri()
        {
            sendRequest(new GetCazuriRequest());
            Response response = readResponse();

            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                throw new MyException(err.Message);
            }
            GetCazuriResponse resp = (GetCazuriResponse)response;

            CazCaritabilDTO[] frDTO = resp.Cazuri;

            CazCaritabil[] donatori = DTOUtils.getFromDTO(frDTO);
            return(donatori);
        }
Beispiel #8
0
        public virtual Donatie[] getDonatii()
        {
            sendRequest(new GetDonatiiRequest());
            Response response = readResponse();

            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                throw new MyException(err.Message);
            }
            GetDonatiiResponse resp = (GetDonatiiResponse)response;

            DonatieDTO[] frDTO = resp.Donatii;

            Donatie[] donatii = DTOUtils.getFromDTO(frDTO);
            return(donatii);
        }
Beispiel #9
0
        private void handleUpdate(UpdateResponse update)
        {
            if (update is UpdateCazResponse)
            {
                UpdateCazResponse frUpd = (UpdateCazResponse)update;
                CazCaritabil      caz   = DTOUtils.getFromDTO(frUpd.Caz);
                Console.WriteLine("Updated caz " + caz);
                try
                {
                    client.updateSC(caz);
                }
                catch (MyException e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }
            if (update is SaveDonatorResponse)
            {
                SaveDonatorResponse donRes  = (SaveDonatorResponse)update;
                Donator             donator = DTOUtils.getFromDTO(donRes.Donator);
                try
                {
                    client.updateDonator(donator);
                }
                catch (MyException e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }

            if (update is SaveDonatieResponse)
            {
                SaveDonatieResponse donRes  = (SaveDonatieResponse)update;
                Donatie             donatie = DTOUtils.getFromDTO(donRes.Add);
                try
                {
                    client.donatieAdded(donatie);
                }
                catch (MyException e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }
        }
Beispiel #10
0
        public virtual void login(Voluntar voluntar, IObserver client)
        {
            initializeConnection();
            VoluntarDTO vdto = DTOUtils.getDTO(voluntar);

            sendRequest(new LoginRequest(vdto));
            Response response = readResponse();

            if (response is OkResponse)
            {
                this.client = client;

                return;
            }
            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                closeConnection();
                throw new MyException(err.Message);
            }
        }
Beispiel #11
0
        private Response handleRequest(Request request)
        {
            Response response = null;

            if (request is GetCazuriRequest)
            {
                Console.WriteLine("GetCazuriRequest.....");
                GetCazuriRequest getReq = (GetCazuriRequest)request;
                try
                {
                    CazCaritabil[] allCazuri;
                    lock (server)
                    {
                        allCazuri = server.getCazuri();
                    }

                    CazCaritabilDTO[] frDTO = DTOUtils.getDTO(allCazuri);
                    return(new GetCazuriResponse(frDTO));
                }
                catch (MyException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetDonatiiRequest)
            {
                Console.WriteLine("GetDonatiiRequest.....");
                GetDonatiiRequest getReq = (GetDonatiiRequest)request;
                try
                {
                    Donatie[] allDonatii;
                    lock (server)
                    {
                        allDonatii = server.getDonatii();
                    }

                    DonatieDTO[] frDTO = DTOUtils.getDTO(allDonatii);
                    return(new GetDonatiiResponse(frDTO));
                }
                catch (MyException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }


            if (request is GetDonatoriRequest)
            {
                Console.WriteLine("GetDonatoriRequest.....");
                GetDonatoriRequest getReq = (GetDonatoriRequest)request;
                try
                {
                    Donator[] allDonatori;
                    lock (server)
                    {
                        allDonatori = server.getDonatori();
                    }

                    DonatorDTO[] frDTO = DTOUtils.getDTO(allDonatori);
                    return(new GetDonatoriResponse(frDTO));
                }
                catch (MyException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is LoginRequest)
            {
                Console.WriteLine("Login request ...");
                LoginRequest logReq = (LoginRequest)request;
                VoluntarDTO  udto   = logReq.User;
                Voluntar     user   = DTOUtils.getFromDTO(udto);
                try
                {
                    lock (server)
                    {
                        server.login(user, this);
                    }
                    return(new OkResponse());
                }
                catch (MyException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is LogoutRequest)
            {
                Console.WriteLine("Logout request");
                LogoutRequest logReq = (LogoutRequest)request;
                VoluntarDTO   udto   = logReq.User;
                Voluntar      user   = DTOUtils.getFromDTO(udto);
                try
                {
                    lock (server)
                    {
                        server.logout(user, this);
                    }
                    connected = false;
                    return(new OkResponse());
                }
                catch (MyException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is SaveDonatorRequest)
            {
                Console.WriteLine("SaveDonatorRequest ...");
                SaveDonatorRequest senReq  = (SaveDonatorRequest)request;
                DonatorDTO         mdto    = senReq.Add;
                Donator            message = DTOUtils.getFromDTO(mdto);
                try
                {
                    lock (server)
                    {
                        server.addDonator(message);
                    }
                    return(new OkResponse());
                }
                catch (MyException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is SaveDonatieRequest)
            {
                Console.WriteLine("SaveDonatieRequest ...");
                SaveDonatieRequest senReq  = (SaveDonatieRequest)request;
                DonatieDTO         mdto    = senReq.Add;
                Donatie            message = DTOUtils.getFromDTO(mdto);
                try
                {
                    lock (server)
                    {
                        server.addDonatie(message);
                    }
                    return(new OkResponse());
                }
                catch (MyException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is UpdateCazRequest)
            {
                Console.WriteLine("UpdateCazRequest ...");
                UpdateCazRequest upReq  = (UpdateCazRequest)request;
                CazCaritabilDTO  cazDTO = upReq.Caz;
                CazCaritabil     caz    = DTOUtils.getFromDTO(cazDTO);
                try
                {
                    lock (server)
                    {
                        server.updateCazCaritabil(caz);
                    }
                    return(new OkResponse());
                }
                catch (MyException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }
            return(response);
        }