Esempio n. 1
0
        public void login(string username, string pass)
        {
            Organizer user = new Organizer(username, pass);

            server.login(user, this);
            Console.WriteLine("Login succeeded ....");
            currentUser = user;
            Console.WriteLine("Current user {0}", user);
        }
        private Response handleRequest(Request request)
        {
            Response response = null;

            if (request is LoginRequest)
            {
                Console.WriteLine("Login request ...");
                LoginRequest logReq = (LoginRequest)request;
                Organizer    org    = logReq.Organizer;

                try {
                    lock (server) {
                        server.login(org, this);
                    }
                    return(new OkResponse());
                } catch (SwimException e) {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is LogoutRequest)
            {
                Console.WriteLine("Logout request");
                LogoutRequest logReq = (LogoutRequest)request;
                Organizer     org    = logReq.Organizer;
                try {
                    lock (server) {
                        server.logout(org, this);
                    }
                    connected = false;
                    return(new OkResponse());
                } catch (SwimException e) {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetEventsNosPartRequest)
            {
                Console.WriteLine("GetEventsNosPartRequest request ...");
                try {
                    lock (server) {
                        return(new GetEventsNosPartResponse(server.findEventsNosParticipants()));
                    }
                } catch (SwimException e) {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is GetAllPart4EventRequest)
            {
                Console.WriteLine("Searching participants for event...");
                GetAllPart4EventRequest partReq = (GetAllPart4EventRequest)request;
                Event ev = partReq.Event;
                try {
                    lock (server) {
                        return(new GetAllPart4EventResponse(server.findPartForEvent(ev)));
                    }
                } catch (SwimException e) {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is GetAllPartRequest)
            {
                Console.WriteLine("Searching all participants...");
                try {
                    lock (server) {
                        return(new GetAllPartResponse(server.findAllParticipants()));
                    }
                } catch (SwimException e) {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is AddPart2EventRequest)
            {
                Console.WriteLine("Adding participant to event...");
                AddPart2EventRequest partReq = (AddPart2EventRequest)request;
                EventPartDTO         ev      = partReq.EventPartDTOent;
                try {
                    lock (server) {
                        server.addPart2Event(ev);
                    }
                    return(new OkResponse());
                } catch (SwimException e) {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is AddParticipantRequest)
            {
                Console.WriteLine("Adding participant...");
                AddParticipantRequest partReq = (AddParticipantRequest)request;
                Participant           part    = partReq.Participant;
                try {
                    lock (server) {
                        server.addParticipant(part);
                    }
                    return(new OkResponse());
                } catch (SwimException e) {
                    return(new ErrorResponse(e.Message));
                }
            }

            return(response);
        }