コード例 #1
0
        public static csharpMusicFestival.domain.User GetUser(Request request)
        {
            var user = new csharpMusicFestival.domain.User {
                Name = request.User.Username, Password = request.User.Password
            };

            return(user);
        }
コード例 #2
0
        public static Request createLogoutRequest(csharpMusicFestival.domain.User user)
        {
            Proto.User userDTO = new Proto.User {
                Username = user.Name, Password = user.Password
            };
            Request request = new Request {
                Type = Request.Types.Type.Logout, User = userDTO
            };

            return(request);
        }
コード例 #3
0
 public static csharpMusicFestival.domain.User GetUser(Response response)
 {
     csharpMusicFestival.domain.User user = new csharpMusicFestival.domain.User(response.User.Username, response.User.Password);
     return(user);
 }
コード例 #4
0
        private Response handleRequest(Request request)
        {
            Response response = null;

            Request.Types.Type reqType = request.Type;
            switch (reqType)
            {
            case Request.Types.Type.Login:
            {
                Console.WriteLine("Login request ...");
                csharpMusicFestival.domain.User user = ProtoUtils.GetUser(request);
                try
                {
                    lock (server)
                    {
                        server.Login(user, this);
                    }

                    return(ProtoUtils.createOkResponse());
                }
                catch (Error e)
                {
                    connected = false;
                    return(ProtoUtils.createErrorResponse(e.Message));
                }
            }

            case Request.Types.Type.Logout:
            {
                Console.WriteLine("Logout request");
                csharpMusicFestival.domain.User user = ProtoUtils.GetUser(request);
                try
                {
                    lock (server)
                    {
                        server.Logout(user, this);
                    }

                    connected = false;
                    return(ProtoUtils.createOkResponse());
                }
                catch (Error e)
                {
                    return(ProtoUtils.createErrorResponse(e.Message));
                }
            }

            case Request.Types.Type.GetShows:
            {
                Console.WriteLine("Get shows request");
                try
                {
                    csharpMusicFestival.domain.Show[] shows = server.GetAll();
                    return(ProtoUtils.CreateGetShowsResponse(shows));
                }
                catch (Error e)
                {
                    return(ProtoUtils.createErrorResponse(e.Message));
                }
            }

            case Request.Types.Type.GetArtistsByDate:
            {
                Console.WriteLine("Get artists by date request");
                String date = request.Date;
                try
                {
                    csharpMusicFestival.domain.Artist[] artists = server.GetArtists(date);
                    return(ProtoUtils.CreateGetArtistsByDateResponse(artists));
                }
                catch (Error e)
                {
                    return(ProtoUtils.createErrorResponse(e.Message));
                }
            }

            case Request.Types.Type.BuyTicket:
            {
                Console.WriteLine("Buy ticket request");
                csharpMusicFestival.domain.Ticket ticket = ProtoUtils.GetTicket(request);
                try
                {
                    lock (server)
                    {
                        server.SellTickets(ticket);
                    }

                    return(ProtoUtils.createOkResponse());
                }
                catch (InvalidPurchaseException e)
                {
                    return(ProtoUtils.createErrorResponse(e.Message));
                }
                catch (Error e)
                {
                    return(ProtoUtils.createErrorResponse(e.Message));
                }
            }
            }
            return(response);
        }