예제 #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 void login(User user, IAppObserver client)
        {
            Console.WriteLine("Client == null: " + (client == null));
            initializeConnection();
            Console.WriteLine("Proxy: sending login request..");
            UserDTO userDTO = transformer.getDTO(user);

            sendRequest(new LoginRequest(userDTO));
            Console.WriteLine("Proxy: getting response..");
            Response response = readResponse();

            Console.WriteLine(response);
            if (response != null)
            {
                if (response is OkResponse)
                {
                    this.client = client;
                    Console.WriteLine("PROXY: Client saved");

                    return;
                }

                if (response is ErrorResponse)
                {
                    ErrorResponse err = (ErrorResponse)response;
                    closeConnection();
                    throw new AppException(err.Message);
                }
            }
        }
예제 #3
0
        public void logout(Employee user, IAppObserver client)
        {
            logger.Debug("Server: logout");
            IAppObserver localClient = loggedClients[user.Username];

            if (localClient == null)
            {
                throw new ServicesException("User " + user.Id + " is not logged in.");
            }
            loggedClients.Remove(user.Username);
        }
예제 #4
0
 public void logout(User user, IAppObserver client)
 {
     if (loggedClients.ContainsKey(user.Username))
     {
         loggedClients.Remove(user.Username);
     }
     else
     {
         throw new AppException("User not logged in!");
     }
 }
예제 #5
0
        public void logout(User user, IAppObserver client)
        {
            Console.WriteLine("Proxy: sending logout request....");
            UserDTO userDTO = transformer.getDTO(user);

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

            closeConnection();
            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                throw new AppException(err.Message);
            }
        }
예제 #6
0
        private void notifyTicketsBought(Show show)
        {
            IEnumerable <Employee> users = userRepository.FindAll();

            logger.Debug("Server: notifyTicketsBought Observer");

            foreach (Employee us in users)
            {
                if (loggedClients.ContainsKey(us.Username))
                {
                    IAppObserver chatClient = loggedClients[us.Username];
                    Task.Run(() => chatClient.notifyTicketSold(show));
                }
            }
        }
예제 #7
0
 private void closeConnection()
 {
     finished = true;
     try
     {
         stream.Close();
         //output.close();
         connection.Close();
         _waitHandle.Close();
         client = null;
     }
     catch (Exception e)
     {
         Console.WriteLine(e.StackTrace);
     }
 }
예제 #8
0
        public void login(User user, IAppObserver client)
        {
            User findUser = userRepository.findUser(user.Username, user.Password);

            if (findUser != null)
            {
                if (loggedClients.ContainsKey(user.Username))
                {
                    throw new AppException("User already logged in!");
                }
                loggedClients.Add(user.Username, client);
            }
            else
            {
                throw new AppException("Authentication failed.");
            }
        }
예제 #9
0
        public void login(Employee user, IAppObserver client)
        {
            logger.Debug("Server: login");
            Employee userR = userRepository.FindByUserAndPasswd(user.Username, user.Password);

            if (userR != null)
            {
                if (loggedClients.ContainsKey(userR.Username))
                {
                    throw new ServicesException("User already logged in.");
                }
                loggedClients[userR.Username] = client;
            }
            else
            {
                throw new ServicesException("Authentication failed.");
            }
        }
예제 #10
0
 private void closeConnection()
 {
     finished = true;
     try
     {
         stream.Close();
         //output.close();
         connection.Close();
         _waitHandle.Close();
         client = null;
         logger.Debug("PROXY CLIENT: SUCCESSFUL closeConnection");
     }
     catch (IOException e)
     {
         logger.Debug("PROXY CLIENT: FAILED closeConnection");
         Console.WriteLine(e.StackTrace);
     }
 }
예제 #11
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);
                }
            }