public string Dispatch(string input) { string[] args = input.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = args.Length > 0 ? args[0] : String.Empty; string[] commandArgs = args.Skip(1).ToArray(); switch (commandName) { case "Exit": ExitCommand exitCommand = new ExitCommand(); return(exitCommand.Execute(new string[0])); case "RegisterUser": RegisterUserCommand registerUserCommand = new RegisterUserCommand(authenticationManager); return(registerUserCommand.Execute(commandArgs)); case "Login": LoginCommand loginCommand = new LoginCommand(authenticationManager); return(loginCommand.Execute(commandArgs)); case "Logout": LogoutCommand logoutCommand = new LogoutCommand(authenticationManager); return(logoutCommand.Execute(commandArgs)); case "DeleteUser": DeleteUserCommand deleteUserCommand = new DeleteUserCommand(authenticationManager); return(deleteUserCommand.Execute(commandArgs)); default: throw new NotSupportedException($"Command {commandName} is not supported"); } }
public string DispatchCommand(string[] commandParameters) { string command = commandParameters[0]; commandParameters = commandParameters.Skip(1).ToArray() `; switch (command) { case "RegisterUser": return(RegisterUserCommand.Execute(commandParameters)); case "AddTown": return(AddTownCommand.Execute(commandParameters)); case "ModifyUser": return(ModifyUserCommand.Execute(commandParameters)); case "DeleteUser": return(DeleteUserCommand.Execute(commandParameters)); case "AddTag": return(AddTagCommand.Execute(commandParameters)); default: throw new InvalidOperationException($"Command {command} not valid!"); } }
public void ReturnSuccessMessage_WhenPassedValidParameters() { // Arrange var sessionMock = new Mock <IUserSession>(); var currentUser = new User() { UserType = UserType.User }; sessionMock.Setup(s => s.CurrentUser).Returns(currentUser); Mock <IUserService> userServiceMock = new Mock <IUserService>(); var user = new User() { Id = 1 }; userServiceMock .Setup(c => c.GetUserByCredentials(It.IsAny <string>(), It.IsAny <string>())) .Returns(user); var sut = new DeleteUserCommand(sessionMock.Object, userServiceMock.Object); var parameters = new string[2] { "1", "pass" }; // Act var result = sut.Execute(parameters); // Assert StringAssert.Contains(result, "successfully deleted"); }
public void Execute_IntegrationTest_SQLite() { string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest"); using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath)) { dbContext.Initialise(); dbContext.BeginTransaction(); IUserRepository userRepo = new UserRepository(dbContext); ICreateUserCommand createUserCommand = new CreateUserCommand(dbContext, new UserValidator(userRepo), new PasswordProvider()); IDeleteUserCommand deleteUserCommand = new DeleteUserCommand(dbContext); // create the user UserModel user = createUserCommand.Execute("test", Guid.NewGuid().ToString(), Roles.User); int rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM Users"); Assert.AreEqual(1, rowCount); // run the delete command and check the end tables - should be 0 records deleteUserCommand.Execute(user.Id); rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM Users"); Assert.AreEqual(0, rowCount); } }
public Task DeleteUser( [FromQuery] DeleteUserRequest request, CancellationToken cancellationToken) { var deleteUserCommand = new DeleteUserCommand( request.UserId, _repository); return(deleteUserCommand.Execute(cancellationToken)); }
private string TryDeleteUser(string command, string[] commandParams) { if (commandParams.Length != 1) { ThrowInvalidCommand(command); } var commandObj = new DeleteUserCommand(); return(commandObj.Execute(commandParams)); }
public void ShouldDeleteUser() { var existingUsers = SetupUsers(2, Role.Admin).ToList(); var userToBeDeleted = existingUsers[0]; var userNotToBeDeleted = existingUsers[1]; var testInstances = SetupOdsInstanceRegistrations(6).OrderBy(x => x.Name).ToList(); var testInstancesAssignedToDeletedUser = testInstances.Take(3).ToList(); var testInstancesAssignedToNotDeletedUser = testInstances.Skip(3).Take(3).ToList(); SetupUserWithOdsInstanceRegistrations(userToBeDeleted.Id, testInstancesAssignedToDeletedUser); SetupUserWithOdsInstanceRegistrations(userNotToBeDeleted.Id, testInstancesAssignedToNotDeletedUser); Scoped <IGetOdsInstanceRegistrationsByUserIdQuery>(queryInstances => { queryInstances.Execute(userToBeDeleted.Id).Count().ShouldBe(3); queryInstances.Execute(userNotToBeDeleted.Id).Count().ShouldBe(3); }); var deleteModel = new DeleteUserModel { Email = userToBeDeleted.Email, UserId = userToBeDeleted.Id }; Scoped <AdminAppIdentityDbContext>(identity => { var command = new DeleteUserCommand(identity); command.Execute(deleteModel); }); Scoped <IGetOdsInstanceRegistrationsByUserIdQuery>(queryInstances => { queryInstances.Execute(userToBeDeleted.Id).Count().ShouldBe(0); queryInstances.Execute(userNotToBeDeleted.Id).Count().ShouldBe(3); }); Scoped <AdminAppIdentityDbContext>(identity => { var queryRoles = new GetRoleForUserQuery(identity); var deletedUser = Query(userToBeDeleted.Id); deletedUser.ShouldBeNull(); queryRoles.Execute(userToBeDeleted.Id).ShouldBeNull(); var notDeletedUser = Query(userNotToBeDeleted.Id); notDeletedUser.UserName.ShouldBe(userNotToBeDeleted.UserName); notDeletedUser.Email.ShouldBe(userNotToBeDeleted.Email); queryRoles.Execute(userNotToBeDeleted.Id).ShouldBe(Role.Admin); }); }
public string Dispatch(string input) { string result = string.Empty; string[] inputArgs = input.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = inputArgs.Length > 0 ? inputArgs[0] : string.Empty; inputArgs = inputArgs.Skip(1).ToArray(); ICommand command; switch (commandName) { case "Exit": command = new ExitCommand(); command.Execute(inputArgs); break; case "RegisterUser": RegisterUserCommand registerUser = new RegisterUserCommand(); result = registerUser.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; default: throw new NotSupportedException($"Command {commandName} not supported!"); } return(result); }
public string Dispatch(string input) { string result = string.Empty; string[] inputTokens = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); string commandName = inputTokens[0]; string[] commandArgs = inputTokens.Skip(1).ToArray(); switch (commandName) { case "DeleteUser": DeleteUserCommand delete = new DeleteUserCommand(); result = delete.Execute(commandArgs); break; case "Logout": LogoutCommand logout = new LogoutCommand(); result = logout.Execute(commandArgs); break; case "Login": LoginCommand login = new LoginCommand(); result = login.Execute(commandArgs); break; case "RegisterUser": RegisterUserCommand registerUser = new RegisterUserCommand(); result = registerUser.Execute(commandArgs); break; case "Exit": ExitCommand exit = new ExitCommand(); result = exit.Execute(commandArgs); break; default: throw new NotSupportedException($"Command {commandName} is not supported!"); } return(result); }
public string Dispatch(string input) { string result = string.Empty;; string[] inputArgs = input .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = inputArgs.Length > 0 ? inputArgs[0].ToLower() : string.Empty; inputArgs = inputArgs.Skip(1).ToArray(); switch (commandName) { case "registeruser": result = RegisterUserCommand.Execute(inputArgs); break; case "deleteuser": result = DeleteUserCommand.Execute(inputArgs); break; case "login": result = LoginCommand.Execute(inputArgs); break; case "logout": result = LogoutCommand.Execute(inputArgs); break; case "createevent": result = CreateEventInternalCommand.Execute(inputArgs); break; case "createteam": result = CreateTeamCommand.Execute(inputArgs); break; case "showevent": result = ShowEventCommand.Execute(inputArgs); break; case "showteam": result = ShowTeamCommand.Execute(inputArgs); break; case "kickmember": result = KickMemberInternalCommand.Execute(inputArgs); break; case "invitetoteam": result = InviteToTeamCommand.Execute(inputArgs); break; case "acceptinvite": result = AcceptInviteCommand.Execute(inputArgs); break; case "declineinvite": result = DeclineInvitartionCommand.Execute(inputArgs); break; case "disband": result = DisbandCommand.Execute(inputArgs); break; case "addteamto": result = AddTeamToCommand.Execute(inputArgs); break; case "exit": result = ExitCommand.Execute(inputArgs); break; default: throw new NotSupportedException($"Command {commandName} not supported!"); } return(result); }
public string Dispatch(string input) { string result = string.Empty; string[] inputArgs = input.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = inputArgs.Length > 0 ? inputArgs[0] : string.Empty; inputArgs = inputArgs.Skip(1).ToArray(); switch (commandName) { case "RegisterUser": var registerUser = new RegisterUserCommand(); result = registerUser.Execute(inputArgs); break; case "Login": var login = new LoginCommand(); result = login.Execute(inputArgs); break; case "Logout": var logout = new LogoutCommand(); result = logout.Execute(inputArgs); break; case "DeleteUser": var deleteUser = new DeleteUserCommand(); result = deleteUser.Execute(inputArgs); break; case "CreateEvent": var createEvent = new CreateEventCommand(); result = createEvent.Execute(inputArgs); break; case "CreateTeam": var createTeam = new CreateTeamCommand(); result = createTeam.Execute(inputArgs); break; case "InviteToTeam": var inviteToTeam = new InviteToTeamCommand(); result = inviteToTeam.Execute(inputArgs); break; case "AcceptInvite": var acceptInvite = new AcceptInviteCommand(); result = acceptInvite.Execute(inputArgs); break; case "DeclineInvite": var declineInvite = new DeclineInviteCommand(); result = declineInvite.Execute(inputArgs); break; case "KickMember": var kickMember = new KickMemberCommand(); result = kickMember.Execute(inputArgs); break; case "Disband": var disband = new DisbandCommand(); result = disband.Execute(inputArgs); break; case "AddTeamTo": var addTeamTo = new AddTeamToCommand(); result = addTeamTo.Execute(inputArgs); break; case "ShowEvent": var showEvent = new ShowEventCommand(); result = showEvent.Execute(inputArgs); break; case "ShowTeam": var showTeam = new ShowTeamCommand(); result = showTeam.Execute(inputArgs); break; case "Exit": var exit = new ExitCommand(); exit.Execute(inputArgs); break; default: throw new NotSupportedException($"Command {commandName} not supported!"); } return(result); }
public string DispatchCommand(string[] commandParameters) { string commandName = commandParameters[0]; commandParameters = commandParameters.Skip(1).ToArray(); // skipping commandName string result = string.Empty; UserService userService = new UserService(); TownService townService = new TownService(); TagService tagService = new TagService(); AlbumService albumService = new AlbumService(); PictureService pictureService = new PictureService(); switch (commandName) { // 1. Photo Share System case "RegisterUser": ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 4); RegisterUserCommand registerUser = new RegisterUserCommand(userService); result = registerUser.Execute(commandParameters); break; case "AddTown": ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 2); AddTownCommand addTown = new AddTownCommand(townService); result = addTown.Execute(commandParameters); break; case "ModifyUser": ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 3); ModifyUserCommand modifyUser = new ModifyUserCommand(userService, townService); result = modifyUser.Execute(commandParameters); break; case "DeleteUser": ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 1); DeleteUserCommand deleteUser = new DeleteUserCommand(userService); result = deleteUser.Execute(commandParameters); break; case "AddTag": ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 1); AddTagCommand addTag = new AddTagCommand(tagService); result = addTag.Execute(commandParameters); break; case "CreateAlbum": ValidateInput.CheckMinInputArgsCount(commandName, commandParameters.Count(), 4); CreateAlbumCommand createAlbum = new CreateAlbumCommand(userService, albumService, tagService); result = createAlbum.Execute(commandParameters); break; case "AddTagTo": ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 2); AddTagToCommand addTagTo = new AddTagToCommand(albumService, tagService); result = addTagTo.Execute(commandParameters); break; case "MakeFriends": ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 2); MakeFriendsCommand makeFriends = new MakeFriendsCommand(userService); result = makeFriends.Execute(commandParameters); break; case "ListFriends": ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 1); ListFriendsCommand listFriends = new ListFriendsCommand(userService); result = listFriends.Execute(commandParameters); break; case "ShareAlbum": ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 3); ShareAlbumCommand shareAlbum = new ShareAlbumCommand(userService, albumService); result = shareAlbum.Execute(commandParameters); break; case "UploadPicture": ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 3); UploadPictureCommand uploadPicture = new UploadPictureCommand(albumService, pictureService); result = uploadPicture.Execute(commandParameters); break; case "Exit": ExitCommand exit = new ExitCommand(); result = exit.Execute(); break; // 2. Extend Photo Share System case "Login": ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 2); LoginCommand login = new LoginCommand(userService); result = login.Execute(commandParameters); break; case "Logout": LogoutCommand logout = new LogoutCommand(); result = logout.Execute(); break; // 1. Photo Share System default: throw new InvalidOperationException($"Command <{commandName}> not valid!"); } return(result); }
public string Dispatch(string input) { string result = string.Empty; string[] inputArgs = input.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = inputArgs.Length > 0 ? inputArgs[0] : string.Empty; inputArgs = inputArgs.Skip(1).ToArray(); switch (commandName) { case "RegisterUser": RegisterUserCommand registerCmd = new RegisterUserCommand(); result = registerCmd.Execute(inputArgs); break; case "Login": LoginCommand loginCmd = new LoginCommand(); result = loginCmd.Execute(inputArgs); break; case "Logout": LogoutCommand logoutCmd = new LogoutCommand(); result = logoutCmd.Execute(inputArgs); break; case "DeleteUser": DeleteUserCommand deleteUserCmd = new DeleteUserCommand(); result = deleteUserCmd.Execute(inputArgs); break; //try to make description as a one argument case "CreateEvent": CreateEventCommand createEventCmd = new CreateEventCommand(); result = createEventCmd.Execute(inputArgs); break; case "CreateTeam": CreateTeamCommand createTeamCmd = new CreateTeamCommand(); result = createTeamCmd.Execute(inputArgs); break; case "InviteToTeam": InviteToTeamCommand inviteToTeamCmd = new InviteToTeamCommand(); result = inviteToTeamCmd.Execute(inputArgs); break; case "AcceptInvite": AcceptInviteCommand acceptInviteCmd = new AcceptInviteCommand(); result = acceptInviteCmd.Execute(inputArgs); break; case "DeclineInvite": DeclineInviteCommand declineInviteCmd = new DeclineInviteCommand(); result = declineInviteCmd.Execute(inputArgs); break; case "KickMember": KickMemberCommand kickMemberCmd = new KickMemberCommand(); result = kickMemberCmd.Execute(inputArgs); break; case "Disband": DisbandCommand disbandCmd = new DisbandCommand(); result = disbandCmd.Execute(inputArgs); break; // case "AddTeamTo": // AddTeamToEventCommand addTeamToCmd = new AddTeamToEventCommand(); // result = addTeamToCmd.Execute(inputArgs); // break; case "ShowEvent": ShowEventCommand showEventCmd = new ShowEventCommand(); result = showEventCmd.Execute(inputArgs); break; case "ShowTeam": ShowTeamCommand showTeamCmd = new ShowTeamCommand(); result = showTeamCmd.Execute(inputArgs); break; case "Exit": ExitCommand exitCmd = new ExitCommand(); result = exitCmd.Execute(inputArgs); break; default: result = $"Command {commandName} not supported!"; throw new NotSupportedException(result); } return(result); }
public string Dispatch(string input) { string result = string.Empty; string[] inputArgs = input.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = inputArgs.Length > 0 ? inputArgs[0] : string.Empty; inputArgs = inputArgs.Skip(1).ToArray(); switch (commandName.ToLower()) { case "exit": ExitCommand exit = new ExitCommand(); exit.Execute(inputArgs); break; case "registeruser": RegisterUserCommand registerUser = new RegisterUserCommand(); result = registerUser.Execute(inputArgs); break; case "login": LoginCommand loginUser = new LoginCommand(); result = loginUser.Execute(inputArgs); break; case "logout": LogoutCommand logoutUser = new LogoutCommand(); result = logoutUser.Execute(inputArgs); break; case "deleteuser": DeleteUserCommand deleteUser = new DeleteUserCommand(); result = deleteUser.Execute(inputArgs); break; case "createevent": CreateEventCommand createEvent = new CreateEventCommand(); result = createEvent.Execute(inputArgs); break; case "createteam": CreateTeamCommand createTeam = new CreateTeamCommand(); result = createTeam.Execute(inputArgs); break; case "showevent": ShowEventCommand showEvent = new ShowEventCommand(); result = showEvent.Execute(inputArgs); break; case "invitetoteam": InviteToTeamCommand inviteToTeam = new InviteToTeamCommand(); result = inviteToTeam.Execute(inputArgs); break; case "showteam": ShowTeamCommand showTeam = new ShowTeamCommand(); result = showTeam.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": DisbandCommand disband = new DisbandCommand(); result = disband.Execute(inputArgs); break; case "addteamto": AddTeamToCommand addTeamTo = new AddTeamToCommand(); result = addTeamTo.Execute(inputArgs); break; default: throw new NotSupportedException($"Command {commandName} not supported!"); } return(result); }
public ActionResult DeleteUser(DeleteUserModel model) { _deleteUserCommand.Execute(model); return(RedirectToActionJson <GlobalSettingsController>(x => x.Users(), "User deleted successfully.")); }
public string DispatchCommand(string[] commandParameters) { string commandName = commandParameters[0]; commandParameters = commandParameters.Skip(1).ToArray(); string result = string.Empty; switch (commandName) { case "RegisterUser": if (commandParameters.Count() != 4) { throw new InvalidOperationException($"Command {commandName} not valid!"); } RegisterUserCommand registerUser = new RegisterUserCommand(new UserService()); result = registerUser.Execute(commandParameters); break; case "AddTown": if (commandParameters.Count() != 2) { throw new InvalidOperationException($"Command {commandName} not valid!"); } AddTownCommand addTown = new AddTownCommand(new TownService()); result = addTown.Execute(commandParameters); break; case "ModifyUser": if (commandParameters.Count() != 3) { throw new InvalidOperationException($"Command {commandName} not valid!"); } ModifyUserCommand modifyUser = new ModifyUserCommand(new UserService(), new TownService()); result = modifyUser.Execute(commandParameters); break; case "DeleteUser": if (commandParameters.Count() != 1) { throw new InvalidOperationException($"Command {commandName} not valid!"); } DeleteUserCommand deleteUser = new DeleteUserCommand(new UserService()); result = deleteUser.Execute(commandParameters); break; case "AddTag": if (commandParameters.Count() != 1) { throw new InvalidOperationException($"Command {commandName} not valid!"); } AddTagCommand addTag = new AddTagCommand(new TagService()); result = addTag.Execute(commandParameters); break; case "CreateAlbum": if (commandParameters.Count() < 4) { throw new InvalidOperationException($"Command {commandName} not valid!"); } CreateAlbumCommand createAlbum = new CreateAlbumCommand(new AlbumService(), new UserService(), new TagService()); result = createAlbum.Execute(commandParameters); break; case "AddTagTo": if (commandParameters.Count() != 2) { throw new InvalidOperationException($"Command {commandName} not valid!"); } AddTagToCommand addTagTo = new AddTagToCommand(new TagService(), new AlbumService()); result = addTagTo.Execute(commandParameters); break; case "MakeFriends": if (commandParameters.Count() != 2) { throw new InvalidOperationException($"Command {commandName} not valid!"); } MakeFriendsCommand makeFriends = new MakeFriendsCommand(new UserService()); result = makeFriends.Execute(commandParameters); break; case "ListFriends": if (commandParameters.Count() != 1) { throw new InvalidOperationException($"Command {commandName} not valid!"); } PrintFriendsListCommand printFriends = new PrintFriendsListCommand(new UserService()); result = printFriends.Execute(commandParameters); break; case "ShareAlbum": if (commandParameters.Count() != 3) { throw new InvalidOperationException($"Command {commandName} not valid!"); } ShareAlbumCommand shareAlbum = new ShareAlbumCommand(new UserService(), new AlbumService()); result = shareAlbum.Execute(commandParameters); break; case "UploadPicture": if (commandParameters.Count() != 3) { throw new InvalidOperationException($"Command {commandName} not valid!"); } UploadPictureCommand uploadPicture = new UploadPictureCommand(new AlbumService(), new PictureService()); result = uploadPicture.Execute(commandParameters); break; case "Login": if (commandParameters.Count() != 2) { throw new InvalidOperationException($"Command {commandName} not valid!"); } LoginCommand loginCommand = new LoginCommand(new AuthenticationService(), new UserService()); result = loginCommand.Execute(commandParameters); break; case "Logout": if (commandParameters.Count() > 0) { throw new InvalidOperationException($"Command {commandName} not valid!"); } LogoutCommand logoutCommand = new LogoutCommand(new AuthenticationService(), new UserService()); result = logoutCommand.Execute(); break; case "Exit": ExitCommand exit = new ExitCommand(); exit.Execute(); break; default: throw new InvalidOperationException($"Command {commandName} not valid!"); break; } return(result); }
public string Dispatch(string input) { string[] args = input.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = args.Length > 0 ? args[0] : string.Empty; string[] commandArgs = args.Skip(1).ToArray(); switch (commandName) { case "ShowTeam": ShowTeamCommand showTeamCommand = new ShowTeamCommand(); return(showTeamCommand.Execute(commandArgs)); case "ShowEvent": ShowEventCommand showEventCommand = new ShowEventCommand(); return(showEventCommand.Execute(commandArgs)); case "AddTeamTo": AddTeamToCommand addTeamToCommand = new AddTeamToCommand(this._authManager); return(addTeamToCommand.Execute(commandArgs)); case "Disband": DisbandCommand disbandCommand = new DisbandCommand(this._authManager); return(disbandCommand.Execute(commandArgs)); case "KickMember": KickMemberCommand kickMemberCommand = new KickMemberCommand(this._authManager); return(kickMemberCommand.Execute(commandArgs)); case "AcceptInvite": AcceptInviteCommand acceptInviteCommand = new AcceptInviteCommand(this._authManager); return(acceptInviteCommand.Execute(commandArgs)); case "DeclineInvite": DeclineInviteCommand declineInviteCommand = new DeclineInviteCommand(this._authManager); return(declineInviteCommand.Execute(commandArgs)); case "InviteToTeam": InviteToTeamCommand inviteToTeamCommand = new InviteToTeamCommand(this._authManager); return(inviteToTeamCommand.Execute(commandArgs)); case "CreateTeam": CreateTeamCommand createTeamCommand = new CreateTeamCommand(this._authManager); return(createTeamCommand.Execute(commandArgs)); case "CreateEvent": CreateEventCommand createEventCommand = new CreateEventCommand(this._authManager); return(createEventCommand.Execute(commandArgs)); case "Exit": ExitCommand exitCommand = new ExitCommand(); return(exitCommand.Execute(new string[0])); case "RegisterUser": RegisterUserCommand registerUserCommand = new RegisterUserCommand(_authManager); return(registerUserCommand.Execute(commandArgs)); case "Login": LoginCommand loginCommand = new LoginCommand(this._authManager); return(loginCommand.Execute(commandArgs)); case "Logout": LogoutCommand logoutCommand = new LogoutCommand(this._authManager); return(logoutCommand.Execute(commandArgs)); case "DeleteUser": DeleteUserCommand deleteUserCommand = new DeleteUserCommand(this._authManager); return(deleteUserCommand.Execute(commandArgs)); default: throw new NotSupportedException($"Command {commandName} not supported!"); } }
public string Dispatch(string input) { string result = ""; var commandArgs = Regex.Split(input.Trim(), @"\s"); var command = commandArgs.Length > 0 ? commandArgs[0] : string.Empty; var args = commandArgs.Skip(1).ToArray(); switch (command) { case "Login": result = LoginCommand.Execute(args); break; case "Logout": result = LogoutCommand.Execute(args); break; case "RegisterUser": result = RegisterUserCommand.Execute(args); break; case "DeleteUser": result = DeleteUserCommand.Execute(args); break; case "CreateEvent": result = CreateEventCommand.Execute(args); break; case "CreateTeam": result = CreateTeamCommand.Execute(args); break; case "InviteToTeam": result = InviteToTeamCommand.Execute(args); break; case "AcceptInvite": result = AcceptInviteCommand.Execute(args); break; case "DeclineInvite": result = DeclineInviteCommand.Execute(args); break; case "KickMember": result = KickMemberCommand.Execute(args); break; case "Exit": result = ExitCommand.Execute(args); break; case "Disband": result = DisbandCommand.Execute(args); break; case "AddTeamTo": result = AddTeamToCommand.Execute(args); break; case "ShowTeam": result = ShowTeamCommand.Execute(args); break; case "ShowEvent": result = ShowEventCommand.Execute(args); break; default: throw new NotSupportedException($"Command {command} not supported!"); } return(result); }
public string DispatchCommand(string[] commandParameters) { string command = commandParameters[0].ToLower(); commandParameters = commandParameters.Skip(1).ToArray(); string result = null; switch (command) { case "registeruser": result = RegisterUserCommand.Execute(commandParameters); break; case "addtown": Session.CheckValidity(); result = AddTownCommand.Execute(commandParameters); break; case "modifyuser": Session.CheckValidity(); result = ModifyUserCommand.Execute(commandParameters); break; case "deleteuser": Session.CheckValidity(); result = DeleteUserCommand.Execute(commandParameters); break; case "addtag": Session.CheckValidity(); result = AddTagCommand.Execute(commandParameters); break; case "addfriend": Session.CheckValidity(); result = AddFriendCommand.Execute(commandParameters); break; case "acceptfriend": Session.CheckValidity(); result = AcceptFriendCommand.Execute(commandParameters); break; case "addtagto": Session.CheckValidity(); result = AddTagToCommand.Execute(commandParameters); break; case "listfriends": result = ListFriendsCommand.Execute(commandParameters); break; case "createalbum": Session.CheckValidity(); result = CreateAlbumCommand.Execute(commandParameters); break; case "sharealbum": Session.CheckValidity(); result = ShareAlbumCommand.Execute(commandParameters); break; case "uploadpicture": Session.CheckValidity(); result = UploadPictureCommand.Execute(commandParameters); break; case "login": result = LoginCommand.Execute(commandParameters); break; case "logout": result = LogoutCommand.Execute(); break; case "exit": result = ExitCommand.Execute(); break; default: throw new InvalidOperationException($"Command {command} is 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); }
public string Dispatch(string input) { string result = string.Empty; string[] inputArgs = input.Split(new[] { ' ', '\t', '\'' }, StringSplitOptions.RemoveEmptyEntries); string commandName = inputArgs.Length > 0 ? inputArgs[0] : string.Empty; inputArgs = inputArgs.Skip(1).ToArray(); switch (commandName) { case "help": HelpCommand help = new HelpCommand(); result = help.Execute(inputArgs); break; case "ExportToJson": ExportToJsonCommand exportToJson = new ExportToJsonCommand(); result = exportToJson.Execute(inputArgs); break; case "ChangeRole": ChangeRoleCommand changeRole = new ChangeRoleCommand(); result = changeRole.Execute(inputArgs); break; case "clear": ClearCommand clear = new ClearCommand(); result = clear.Execute(inputArgs); break; case "ShowAllUsers": ShowAllUserCommand showAllUsers = new ShowAllUserCommand(); result = showAllUsers.Execute(inputArgs); break; case "AddTown": AddTownCommand addTown = new AddTownCommand(); result = addTown.Execute(inputArgs); break; case "ModifyUser": ModifyUserCommand modifyUser = new ModifyUserCommand(); result = modifyUser.Execute(inputArgs); break; case "AddBook": AddBookCommand addBook = new AddBookCommand(); result = addBook.Execute(inputArgs); break; case "DeleteUser": DeleteUserCommand deleteUser = new DeleteUserCommand(); result = deleteUser.Execute(inputArgs); break; case "Logout": LogoutCommand logout = new LogoutCommand(); result = logout.Execute(inputArgs); break; case "Login": LoginCommand login = new LoginCommand(); result = login.Execute(inputArgs); break; case "RegisterUser": RegisterUserCommand registerUser = new RegisterUserCommand(); result = registerUser.Execute(inputArgs); break; case "Exit": ExitCommand exit = new ExitCommand(); exit.Execute(inputArgs); break; default: throw new NotSupportedException($"Command {commandName} not supported!"); } return(result); }
public string DispatchCommand(string[] commandParameters) { PictureService pictureService = new PictureService(); AlbumService albumService = new AlbumService(); UserService userService = new UserService(); TownService townService = new TownService(); TagService tagService = new TagService(); string commandName = commandParameters[0]; commandParameters = commandParameters.Skip(1).ToArray(); string result = string.Empty; switch (commandName) { case "RegisterUser": RegisterUserCommand registerUser = new RegisterUserCommand(userService); result = registerUser.Execute(commandParameters); break; case "AddTown": AddTownCommand addTown = new AddTownCommand(townService); result = addTown.Execute(commandParameters); break; case "ModifyUser": ModifyUserCommand modifyUser = new ModifyUserCommand(userService, townService); result = modifyUser.Execute(commandParameters); break; case "DeleteUser": DeleteUserCommand deleteUser = new DeleteUserCommand(userService); result = deleteUser.Execute(commandParameters); break; case "AddTag": AddTagCommand addTag = new AddTagCommand(tagService); result = addTag.Execute(commandParameters); break; case "CreateAlbum": CreateAlbumCommand createAlbum = new CreateAlbumCommand(albumService, userService, tagService); result = createAlbum.Execute(commandParameters); break; case "AddTagTo": AddTagToCommand addTagTo = new AddTagToCommand(albumService, tagService); result = addTagTo.Execute(commandParameters); break; case "MakeFriends": MakeFriendsCommand makeFriends = new MakeFriendsCommand(userService); result = makeFriends.Execute(commandParameters); break; case "ListFriends": ListFriendsCommand listFriends = new ListFriendsCommand(userService); result = listFriends.Execute(commandParameters); break; case "ShareAlbum": ShareAlbumCommand shareAlbum = new ShareAlbumCommand(albumService, userService); result = shareAlbum.Execute(commandParameters); break; case "UploadPicture": UploadPictureCommand uploadPicture = new UploadPictureCommand(albumService, pictureService); result = uploadPicture.Execute(commandParameters); break; case "Exit": ExitCommand exit = new ExitCommand(); exit.Execute(); break; case "Login": LoginUserCommand loginUser = new LoginUserCommand(); result = loginUser.Execute(commandParameters); break; case "Logout": LogoutUserCommand logoutUser = new LogoutUserCommand(); result = logoutUser.Execute(commandParameters); break; default: result = $"Command {commandName} not valid!"; break; } return(result); }
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(); result = registerUser.Execute(commandParameters); break; case "AddTown": AddTownCommand addTown = new AddTownCommand(); result = addTown.Execute(commandParameters); break; case "ModifyUser": ModifyUserCommand modifyUser = new ModifyUserCommand(); result = modifyUser.Execute(commandParameters); break; case "DeleteUser": DeleteUserCommand deleteUser = new DeleteUserCommand(); result = deleteUser.Execute(commandParameters); break; case "AddTag": AddTagCommand addTag = new AddTagCommand(); result = addTag.Execute(commandParameters); break; case "CreateAlbum": CreateAlbumCommand createAlbum = new CreateAlbumCommand(); result = createAlbum.Execute(commandParameters); break; case "AddTagTo": AddTagToCommand addTagTo = new AddTagToCommand(); result = addTagTo.Execute(commandParameters); break; case "MakeFriends": MakeFriendsCommand makeFriend = new MakeFriendsCommand(); result = makeFriend.Execute(commandParameters); break; case "ListFriends": PrintFriendsListCommand listFriends = new PrintFriendsListCommand(); result = listFriends.Execute(commandParameters); break; case "UploadPicture": UploadPictureCommand uploadPicture = new UploadPictureCommand(); result = uploadPicture.Execute(commandParameters); break; case "ShareAlbum": ShareAlbumCommand shareAlbum = new ShareAlbumCommand(); result = shareAlbum.Execute(commandParameters); break; case "Login": LoginCommand login = new LoginCommand(); result = login.Execute(commandParameters); break; case "Logout": LogoutCommand logout = new LogoutCommand(); result = logout.Execute(commandParameters); break; case "Exit": ExitCommand exit = new ExitCommand(); exit.Execute(); break; default: Console.WriteLine($"Command {commandName} not valid!"); break; } return(result); }
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 DispatchCommand(string[] commandParameters) { string result; switch (commandParameters[0]) { case "RegisterUser": //// if (commandParameters.Length != 5) { goto default; } AccessAsLoggedOut(); Commands.RegisterUserCommand registerUser = new RegisterUserCommand(); result = registerUser.Execute(commandParameters.Skip(1).ToArray()); break; case "AddTown": //// if (commandParameters.Length != 3) { goto default; } AccessAsLoggedIn(commandParameters); Commands.AddTownCommand addTown = new AddTownCommand(); result = addTown.Execute(commandParameters.Skip(1).ToArray()); break; case "ModifyUser": //// if (commandParameters.Length != 3) { goto default; } AccessAsLoggedIn(commandParameters); Commands.ModifyUserCommand modifyUser = new ModifyUserCommand(); result = modifyUser.Execute(commandParameters.Skip(1).ToArray()); break; case "DeleteUser": //// if (commandParameters.Length != 1) { goto default; } AccessAsLoggedIn(commandParameters); Commands.DeleteUserCommand deleteUser = new DeleteUserCommand(); result = deleteUser.Execute(); break; case "AddTag": //// if (commandParameters.Length != 2) { goto default; } AccessAsLoggedIn(commandParameters); Commands.AddTagCommand addTag = new AddTagCommand(); result = addTag.Execute(commandParameters.Skip(1).ToArray()); break; case "CreateAlbum": //// if (commandParameters.Length < 2) { goto default; } AccessAsLoggedIn(commandParameters); Commands.CreateAlbumCommand createAlbum = new CreateAlbumCommand(); result = createAlbum.Execute(commandParameters.Skip(1).ToArray()); break; case "AddTagTo": //// if (commandParameters.Length != 3) { goto default; } AccessAsLoggedIn(commandParameters); Commands.AddTagToCommand addTagTo = new AddTagToCommand(); result = addTagTo.Execute(commandParameters.Skip(1).ToArray()); break; case "MakeFriends": //// if (commandParameters.Length != 2) { goto default; } AccessAsLoggedIn(commandParameters); Commands.MakeFriendsCommand makeFriends = new MakeFriendsCommand(); result = makeFriends.Execute(commandParameters.Skip(1).ToArray()); break; case "ListFriends": //// if (commandParameters.Length != 2) { goto default; } // both users can Commands.PrintFriendsListCommand printFriends = new PrintFriendsListCommand(); result = printFriends.Execute(commandParameters.Skip(1).ToArray()); break; case "ShareAlbum": //// if (commandParameters.Length != 3) { goto default; } AccessAsLoggedIn(commandParameters); Commands.ShareAlbumCommand shareAlbum = new ShareAlbumCommand(); result = shareAlbum.Execute(commandParameters.Skip(1).ToArray()); break; case "UploadPicture": //// if (commandParameters.Length != 4) { goto default; } AccessAsLoggedIn(commandParameters); Commands.UploadPictureCommand uppCommand = new UploadPictureCommand(); result = uppCommand.Execute(commandParameters.Skip(1).ToArray()); break; case "Exit": //// if (commandParameters.Length != 1) { goto default; } // both users can Commands.ExitCommand exit = new ExitCommand(); result = exit.Execute(); break; case "Login": //// if (commandParameters.Length != 3) { goto default; } AccessAsLoggedOut(); Commands.LoginCommand login = new LoginCommand(); result = login.Execute(commandParameters.Skip(1).ToArray()); break; case "Logout": /// if (commandParameters.Length != 1) { goto default; } AccessAsLoggedIn(commandParameters); Commands.LogoutCommand logout = new LogoutCommand(); result = logout.Execute(); break; default: throw new InvalidOperationException($"Command {commandParameters[0]} not valid!"); } return(result); }