Esempio n. 1
0
        public IList <EventPartDTO> findAllEvents()
        {
            IList <EventPartDTO> all = new List <EventPartDTO>();

            EventPartDTO[] events = server.findEventsNosParticipants();
            foreach (var p in events)
            {
                all.Add(p);
            }
            return(all);
        }
        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);
        }