Пример #1
0
            public void login(Employee user, IAppObserver client)
            {
                if (!isInitialized)
                {
                    initializeConnection();
                    this.isInitialized = true;
                }
                UserDTO udto = DTOUtils.getDTO(user);
                Request req  = new Request.Builder().Type(RequestType.LOGIN).Data(udto).Build();

                sendRequest(req);
                logger.Debug("PROXY CLIENT: login SENT REQUEST");
                Response response = readResponse();

                logger.Debug("PROXY CLIENT: login RECEIVED RESPONSE @");
                if (response.Type() == ResponseType.OK)
                {
                    this.client = client;
                    logger.Debug("PROXY CLIENT: SUCCESSFUL login");
                    return;
                }
                if (response.Type() == ResponseType.ERROR)
                {
                    String err = response.Data().ToString();
                    closeConnection();
                    logger.Debug("PROXY CLIENT: FAILED login");
                    throw new ServicesException(err);
                }
            }
Пример #2
0
            public Show ticketsSold(Show show, Ticket t)
            {
                ShowDTO   showDTO   = DTOUtils.getDTO(show);
                TicketDTO ticketDTO = DTOUtils.getDTO(t);

                Object[] sendData = new Object[2];
                sendData[0] = showDTO;
                sendData[1] = ticketDTO;
                Request req = new Request.Builder().Type(RequestType.TICKETS_SOLD).Data(sendData).Build();

                sendRequest(req);
                logger.Debug("PROXY CLIENT: ticketsSold SENT REQUEST WARNING: THIS FUNCTION HAS NO RESPONSE!!!");
                Response response = readResponse();

                if (response.Type() == ResponseType.UPDATED_SHOWS)
                {
                    logger.Debug("PROXY CLIENT: SUCCESSFUL update");
                    return(null);
                }
                if (response.Type() == ResponseType.ERROR)
                {
                    String err = response.Data().ToString();
                    throw new ServicesException(err);
                }
                logger.Debug("PROXY CLIENT: SUCCESSFUL ticketsSold WARNING: THIS FUNCTION HAS NO RESPONSE!!!");
                return(null);
            }
Пример #3
0
 public virtual void resultAdded(Result result)
 {
     Networking.ResultDTO resultDto = DTOUtils.getDTO(result);
     Console.WriteLine("Result added  " + result);
     try
     {
         sendResponse(ProtoUtils.createNewResultResponse(resultDto));
     }
     catch (Exception e)
     {
         throw new TriatlonException("Sending error: " + e);
     }
 }
Пример #4
0
        public virtual void sendMessage(Message message)
        {
            MessageDTO mdto = DTOUtils.getDTO(message);

            sendRequest(new SendMessageRequest(mdto));
            Response response = readResponse();

            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                throw new ChatException(err.Message);
            }
        }
Пример #5
0
        public virtual void friendLoggedIn(User friend)
        {
            UserDTO udto = DTOUtils.getDTO(friend);

            Console.WriteLine("Friend logged in " + friend);
            try
            {
                sendResponse(new FriendLoggedInResponse(udto));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
Пример #6
0
        public virtual void messageReceived(Message message)
        {
            MessageDTO mdto = DTOUtils.getDTO(message);

            Console.WriteLine("Message received  " + message);
            try
            {
                sendResponse(new NewMessageResponse(mdto));
            }
            catch (Exception e)
            {
                throw new ChatException("Sending error: " + e);
            }
        }
Пример #7
0
        public virtual void logout(User user, IChatObserver client)
        {
            UserDTO udto = DTOUtils.getDTO(user);

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

            closeConnection();
            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                throw new ChatException(err.Message);
            }
        }
        public bool logIn(string userName, string password)
        {
            initializeConnection();
            AngajatDTO udto = DTOUtils.getDTO(new Angajat(1, userName, password));

            sendRequest(new LogInRequest(udto));
            IResponse response = readResponse();

            if (response is OkResponse)
            {
                //this.client=client;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #9
0
        public virtual User[] getLoggedFriends(User user)
        {
            UserDTO udto = DTOUtils.getDTO(user);

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

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

            UserDTO[] frDTO   = resp.Friends;
            User[]    friends = DTOUtils.getFromDTO(frDTO);
            return(friends);
        }
Пример #10
0
            public void logout(Employee user, IAppObserver client)
            {
                UserDTO udto = DTOUtils.getDTO(user);
                Request req  = new Request.Builder().Type(RequestType.LOGOUT).Data(udto).Build();

                sendRequest(req);
                logger.Debug("PROXY CLIENT: logout SENT REQUEST");
                Response response = readResponse();

                logger.Debug("PROXY CLIENT: logout RECEIVED RESPONSE");
                closeConnection();
                this.isInitialized = false;
                logger.Debug("PROXY CLIENT: SUCCESSFUL logout");
                if (response.Type() == ResponseType.ERROR)
                {
                    String err = response.Data().ToString();
                    logger.Debug("PROXY CLIENT: FAILED logout");
                    throw new ServicesException(err);
                }
            }
Пример #11
0
        public virtual void login(User user, IChatObserver client)
        {
            initializeConnection();
            UserDTO udto = DTOUtils.getDTO(user);

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

            if (response is OkResponse)
            {
                this.client = client;
                return;
            }
            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                closeConnection();
                throw new ChatException(err.Message);
            }
        }
Пример #12
0
            public Show[] findAllShowsForArtist(Artist artist)
            {
                ArtistDTO adto = DTOUtils.getDTO(artist);
                Request   req  = new Request.Builder().Type(RequestType.GET_SHOWS_W_ARTIST).Data(adto).Build();

                sendRequest(req);
                logger.Debug("PROXY CLIENT: findAllShowWithTickets SENT REQUES");
                Response response = readResponse();

                logger.Debug("PROXY CLIENT: findAllShowWithTickets RECEIVED RESPONSE");
                if (response.Type() == ResponseType.ERROR)
                {
                    String err = response.Data().ToString();
                    logger.Debug("PROXY CLIENT: FAILED");
                    throw new ServicesException(err);
                }
                ShowDTO[] showDTOS = (ShowDTO[])response.Data();
                Show[]    meciuri  = DTOUtils.getFromDTO(showDTOS);
                logger.Debug("PROXY CLIENT: SUCCESSFUL");
                return(meciuri);
            }
Пример #13
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);
                try
                {
                    lock (server)
                    {
                        server.login(user, this);
                    }
                    return(new OkResponse());
                }
                catch (ChatException 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 (ChatException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is SendMessageRequest)
            {
                Console.WriteLine("SendMessageRequest ...");
                SendMessageRequest senReq  = (SendMessageRequest)request;
                MessageDTO         mdto    = senReq.Message;
                Message            message = DTOUtils.getFromDTO(mdto);
                try
                {
                    lock (server)
                    {
                        server.sendMessage(message);
                    }
                    return(new OkResponse());
                }
                catch (ChatException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetLoggedFriendsRequest)
            {
                Console.WriteLine("GetLoggedFriends Request ...");
                GetLoggedFriendsRequest getReq = (GetLoggedFriendsRequest)request;
                UserDTO udto = getReq.User;
                User    user = DTOUtils.getFromDTO(udto);
                try
                {
                    User[] friends;
                    lock (server)
                    {
                        friends = server.getLoggedFriends(user);
                    }
                    UserDTO[] frDTO = DTOUtils.getDTO(friends);
                    return(new GetLoggedFriendsResponse(frDTO));
                }
                catch (ChatException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }
            return(response);
        }
Пример #14
0
        private IResponse handleRequest(IRequest request)
        {
            IResponse response = null;

            if (request is LogInRequest)
            {
                Console.WriteLine("Login request ...");
                LogInRequest logReq = (LogInRequest)request;
                AngajatDTO   udto   = logReq.User;
                Angajat      user   = DTOUtils.getFromDTO(udto);

                try
                {
                    lock (server)
                    {
                        bool ok = server.logIn(user.User, user.Parola);
                        if (ok == true)
                        {
                            response = new OkResponse();
                        }
                        else
                        {
                            response = new ErrorResponse("log in error");
                        }
                    }
                }
                catch (Exception e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }
            else
            if (request is GetFlightsRequest)
            {
                List <Zbor> flights = new List <Zbor>();
                flights  = server.getAllFlight();
                response = new GetFlightsResponse(DTOUtils.getDTO(flights));
            }
            else
            if (request is SearchFlightsRequest)
            {
                SearchFlightsRequest r       = (SearchFlightsRequest)request;
                List <Zbor>          flights = new List <Zbor>();
                flights  = server.findByDestinatieDataplecareFlight(r.Destinatie, r.DataPlecare);
                response = new SearchFlightsResponse(DTOUtils.getDTO(flights));
            }
            else
            if (request is AddBiletRequest)
            {
                AddBiletRequest r = (AddBiletRequest)request;
                server.addBilet(r.Client, r.Turisti, r.Adresa, r.IdDestinatie);
                response = new AddBiletResponse();
            }
            else
            {
                if (request is FindByIdZborRequest)
                {
                    FindByIdZborRequest r = (FindByIdZborRequest)request;
                    Zbor z = server.findByIdZbor(r.IdZbor);
                    response = new FindByIdResponse(DTOUtils.getDTO(z));
                }
            }
            return(response);
        }