public string DispatchCommand(string[] commandParameters) { string commandName = commandParameters[0]; commandParameters = commandParameters.Skip(1).ToArray(); string result = string.Empty; switch (commandName) { case "RegisterUser": RegisterUserCommand registerUser = new RegisterUserCommand(new UserService()); result = registerUser.Execute(commandParameters); break; case "Login": LoginCommand loginCommand = new LoginCommand(new UserService()); result = loginCommand.Execute(commandParameters); break; case "Logout": LogoutCommand logoutCommand = new LogoutCommand(new UserService()); result = logoutCommand.Execute(commandParameters); break; case "DeleteUser": DeleteUserCommand deleteUser = new DeleteUserCommand(new UserService()); result = deleteUser.Execute(commandParameters); break; case "CreateEvent": CreateEventCommand createEvent = new CreateEventCommand(new EventService()); result = createEvent.Execute(commandParameters); break; case "CreateTeam": CreateTeamCommand createTeam = new CreateTeamCommand(new TeamService()); result = createTeam.Execute(commandParameters); break; case "InviteToTeam": InviteToTeamCommand invToTeam = new InviteToTeamCommand(new TeamService(), new UserService()); result = invToTeam.Execute(commandParameters); break; case "AcceptInvite": AcceptInviteCommand acceptInvite = new AcceptInviteCommand(new TeamService(), new UserService()); result = acceptInvite.Execute(commandParameters); break; case "DeclineInvite": DeclineInviteCommand declineInvite = new DeclineInviteCommand(new TeamService(), new UserService()); result = declineInvite.Execute(commandParameters); break; case "KickMember": KickMemberCommand kickMember = new KickMemberCommand(new TeamService(), new UserService()); result = kickMember.Execute(commandParameters); break; case "Disband": DisbandCommand disbandTeam = new DisbandCommand(new TeamService(), new UserService()); result = disbandTeam.Execute(commandParameters); break; case "AddTeamTo": AddTeamToCommand addTeam = new AddTeamToCommand(new EventService(), new TeamService()); result = addTeam.Execute(commandParameters); break; case "ShowEvent": ShowEventCommand showEvent = new ShowEventCommand(new EventService()); result = showEvent.Execute(commandParameters); break; case "ShowTeam": ShowTeamCommand showTeam = new ShowTeamCommand(new TeamService()); result = showTeam.Execute(commandParameters); break; case "ImportUsers": ImportUsersCommand importUsers = new ImportUsersCommand(new UserService()); result = importUsers.Execute(commandParameters); break; case "ImportTeams": ImportTeamsCommand importTeams = new ImportTeamsCommand(new TeamService()); result = importTeams.Execute(commandParameters); break; case "ExportTeam": ExportTeamCommand exportTeam = new ExportTeamCommand(new TeamService()); result = exportTeam.Execute(commandParameters); break; case "Exit": ExitCommand exit = new ExitCommand(); exit.Execute(commandParameters); break; default: throw new NotSupportedException($"Command {commandName} not valid!"); } return(result); }
public string Dispatch(string input) { string result = string.Empty; string[] inputArgs = Regex.Split(input.Trim(), @"\s+"); //string[] args = input.Trim().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = inputArgs.Length > 0 ? inputArgs[0] : string.Empty; inputArgs = inputArgs.Skip(1).ToArray(); switch (commandName) { // Basic Logic case "RegisterUser": RegisterUserCommand register = new RegisterUserCommand(); result = register.Execute(inputArgs); break; case "Login": LoginCommand login = new LoginCommand(); result = login.Execute(inputArgs); break; case "Logout": LogoutCommand logout = new LogoutCommand(); result = logout.Execute(inputArgs); break; case "DeleteUser": DeleteUserCommand deleteUser = new DeleteUserCommand(); result = deleteUser.Execute(inputArgs); break; case "Exit": ExitCommand exit = new ExitCommand(); result = exit.Execute(inputArgs); break; // Advanced Logic case "CreateEvent": CreateEventCommand createEvent = new CreateEventCommand(); result = createEvent.Execute(inputArgs); break; case "CreateTeam": CreateTeamCommand createTeam = new CreateTeamCommand(); result = createTeam.Execute(inputArgs); break; case "InviteToTeam": InviteToTeamCommand inviteToTeam = new InviteToTeamCommand(); result = inviteToTeam.Execute(inputArgs); break; case "AcceptInvite": AcceptInviteCommand acceptInvite = new AcceptInviteCommand(); result = acceptInvite.Execute(inputArgs); break; case "DeclineInvite": DeclineInviteCommand declineInvite = new DeclineInviteCommand(); result = declineInvite.Execute(inputArgs); break; case "KickMember": KickMemberCommand kickMember = new KickMemberCommand(); result = kickMember.Execute(inputArgs); break; case "Disband": DisbandTeamCommand disband = new DisbandTeamCommand(); result = disband.Execute(inputArgs); break; case "AddTeamTo": AddTeamToCommand addTeamTo = new AddTeamToCommand(); result = addTeamTo.Execute(inputArgs); break; case "ShowEvent": ShowEventCommand showEvent = new ShowEventCommand(); result = showEvent.Execute(inputArgs); break; case "ShowTeam": ShowTeamCommand showTeam = new ShowTeamCommand(); result = showTeam.Execute(inputArgs); break; // Import Data case "ImportUsers": ImportUsersCommand importUsers = new ImportUsersCommand(); result = importUsers.Execute(inputArgs); break; case "ImportTeams": ImportTeamsCommand importTeams = new ImportTeamsCommand(); result = importTeams.Execute(inputArgs); break; // Export Data case "ExportTeam": ExportTeamCommand exportTeam = new ExportTeamCommand(); result = exportTeam.Execute(inputArgs); break; // Basic Logic default: throw new NotSupportedException($"Command {commandName} not supported!"); } return(result); }