Ejemplo n.º 1
0
 public static ShowDTO[] getDTO(Show[] shows)
 {
     ShowDTO[] showsDTO = new ShowDTO[shows.Length];
     for (int i = 0; i < shows.Length; i++)
     {
         showsDTO[i] = getDTO(shows[i]);
     }
     return(showsDTO);
 }
Ejemplo n.º 2
0
 public static Show getFromDTO(ShowDTO showDTO)
 {
     return(new Show()
     {
         Id = showDTO.Id,
         Location = showDTO.Location,
         ShowDateTime = showDTO.ShowDateTime,
         NrAvailableSeats = showDTO.NrAvailableSeats,
         NrSoldSeats = showDTO.NrSoldSeats,
         ArtistName = showDTO.ArtistName
     });
 }
Ejemplo n.º 3
0
        public void notifyTicketSold(Show show)
        {
            ShowDTO  showdto = DTOUtils.getDTO(show);
            Response resp    = new Response.Builder().Type(ResponseType.UPDATED_SHOWS).Data(showdto).Build();

            logger.Debug("PROXY SERVER: ticketsSold BUILT RESPONSE @" + DateTime.Now);
            Console.WriteLine("Tickets sold for match " + show);
            try
            {
                sendResponse(resp);
                logger.DebugFormat("PROXY SERVER: ticketsSold SENT RESPONSE @" + DateTime.Now, resp);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
Ejemplo n.º 4
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);
        }