示例#1
0
        private Response handleRequest(Request request)
        {
            Response response = null;

            if (request.Type() == RequestType.LOGIN)
            {
                logger.Debug("PROXY SERVER: handleRequest RECEIVED REQUEST type==RequestType.LOGIN");
                Console.WriteLine("Login request ..." + request.Type());
                UserDTO  udto = (UserDTO)request.Data();
                Employee user = DTOUtils.getFromDTO(udto);
                try
                {
                    server.login(user, this);
                    logger.Debug("PROXY SERVER: handleRequest SENT COMMAND TO SERVER server.login");
                    return(okResponse);
                }
                catch (ServicesException e)
                {
                    connected = false;
                    logger.Debug("PROXY SERVER: FAILED handleRequest type==RequestType.LOGIN");
                    return(new Response.Builder().Type(ResponseType.ERROR).Data(e.Message).Build());
                }
            }
            if (request.Type() == RequestType.LOGOUT)
            {
                logger.Debug("PROXY SERVER: handleRequest RECEIVED REQUEST type==RequestType.LOGOUT");
                Console.WriteLine("Logout request");
                UserDTO  udto = (UserDTO)request.Data();
                Employee user = DTOUtils.getFromDTO(udto);
                try
                {
                    server.logout(user, this);
                    connected = false;
                    logger.Debug("PROXY SERVER: handleRequest SENT COMMAND TO SERVER server.logou");
                    return(okResponse);
                }
                catch (ServicesException e)
                {
                    logger.Debug("PROXY SERVER: FAILED handleRequest type==RequestType.LOGOUT");
                    return(new Response.Builder().Type(ResponseType.ERROR).Data(e.Message).Build());
                }
            }

            if (request.Type() == RequestType.GET_SHOWS)
            {
                logger.Debug("PROXY SERVER: handleRequest RECEIVED REQUEST type==RequestType.GET_MATCHES @" + DateTime.Now);
                Console.WriteLine("Get Matches request");
                try
                {
                    Show[]    shows    = server.findAllShows();
                    ShowDTO[] showdtos = DTOUtils.getDTO(shows);
                    logger.Debug("PROXY SERVER: handleRequest SENT COMMAND TO SERVER server.findAllMeci @" + DateTime.Now);
                    return(new Response.Builder().Type(ResponseType.GET_SHOWS).Data(showdtos).Build());
                }
                catch (ServicesException e)
                {
                    logger.Debug("PROXY SERVER: FAILED handleRequest type==RequestType.GET_MATCHES @" + DateTime.Now);
                    return(new Response.Builder().Type(ResponseType.ERROR).Data(e.Message).Build());
                }
            }


            if (request.Type() == RequestType.TICKETS_SOLD)
            {
                logger.Debug("PROXY SERVER: handleRequest RECEIVED REQUEST type==RequestType.TICKETS_SOLD @" + DateTime.Now);
                Console.WriteLine("TICKETS_SOLD update meci request");
                Object[]  data    = (Object[])request.Data();
                ShowDTO   showDTO = (ShowDTO)data[0];
                TicketDTO tcket   = (TicketDTO)data[1];
                Show      s       = DTOUtils.getFromDTO(showDTO);
                Ticket    ticket  = DTOUtils.getFromDTO(tcket);
                try
                {
                    Show shU = server.ticketsSold(s, ticket); // this is the response of the TICKETS_SOLD request
                    logger.Debug("PROXY SERVER: handleRequest SENT COMMAND TO SERVER server.ticketsSold @" + DateTime.Now);
                    ShowDTO sDTO = DTOUtils.getDTO(shU);
                    //return new Response.Builder().Type(ResponseType.UPDATED_SHOWS).Data(sDTO).Build();
                    return(okResponse); // de aici vine double update-ul bun (aici trimiteai bine)
                    //aici trimiti doar o confirmare, nu un update. AICI era. pentru ca el astepta in continuare ok-ul, dar notificarea ta era prinsa in update . asa zic
                }
                catch (ServicesException e)
                {
                    logger.Debug("PROXY SERVER: FAILED handleRequest type==RequestType.TICKETS_SOLD @" + DateTime.Now);
                    return(new Response.Builder().Type(ResponseType.ERROR).Data(e.Message).Build());
                }
            }

            logger.DebugFormat("PROXY SERVER: RETURN RESPONSE handleRequest @" + DateTime.Now + " WARNING: should never reach this point: request type not found !!!", response);
            return(response);
        }