예제 #1
0
 public void login(User u)
 {
     Console.WriteLine("-- Client Ctrl > Login" + u.username + " " + u.passwd);
     server.Login(u, this);
     Console.WriteLine("--Client ctrl > Sosit de la server raspuns");
     currentUser = u;
     Console.WriteLine("Current user : {0}", u);
 }
예제 #2
0
        private object handleRequest(Request request)
        {
            Response resp = null;

            if (request is LoginRequest)
            {
                Console.WriteLine("Processing a login request ... ");
                LoginRequest logR = (LoginRequest)request;
                User         u    = logR.user;
                try
                {
                    Console.WriteLine("-- Sending request...");
                    lock (server)
                    {
                        server.Login(u, this);
                    }
                    return(new OkResponse("Utilizator logat "));
                }
                catch (Exception e)
                {
                    connected = false;
                    return(new ErrorResponse("Credentiale invalide"));
                }
            }

            if (request is LogoutRequest)
            {
                Console.WriteLine("Processing a logout request ... ");
                LogoutRequest logR = (LogoutRequest)request;
                User          u    = logR.user;
                try
                {
                    lock (server)
                    {
                        server.Logout(u, this);
                    }
                    connected = false;
                    return(new OkResponse("User logged out"));
                }
                catch (Exception e)
                {
                    return(new ErrorResponse("Ceva nu-i ok"));
                }
            }

            if (request is GetAllConcertsRequest)
            {
                Console.WriteLine("Processing request : get all concerts");
                try
                {
                    List <ConcertDTO> c = new List <ConcertDTO>();
                    lock (server)
                    {
                        c = server.getAllConcerts();
                    }
                    GetAllConcertsResponse r = new GetAllConcertsResponse(c);
                    sendResponse(r);
                    //return new GetAllConcertsResponse(c);
                }
                catch (Exception e)
                {
                    return(new ErrorResponse("Ceva nu-i ok"));
                }
            }

            if (request is FilterConcertsRequest)
            {
                Console.WriteLine("Processing request : filter concerts");
                try
                {
                    FilterConcertsRequest re = (FilterConcertsRequest)request;
                    List <ConcertDTO>     c  = new List <ConcertDTO>();
                    lock (server)
                    {
                        c = server.filterConcerts(re.data);
                    }
                    FilterConcertsResponse r = new FilterConcertsResponse(c);
                    sendResponse(r);
                    //return new FilterConcertsResponse(c);
                }
                catch (Exception e)
                {
                    return(new ErrorResponse("nu-i ok"));
                }
            }

            if (request is SellTicketRequest)
            {
                try
                {
                    //List<ConcertDTO> L = new List<ConcertDTO>();
                    SellTicketRequest r = (SellTicketRequest)request;
                    Bilet             b = r.bilet;
                    lock (server)
                    {
                        server.sellTicket(b);
                    }
                    return(new OkResponse("Vandut bilet"));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(new ErrorResponse("ticket sold error"));
                }
            }
            return(resp);
        }