Ejemplo n.º 1
0
        public string DispatchCommand(string[] commandParameters)
        {
            var userService     = new UserService();
            var townService     = new TownService();
            var tagService      = new TagService();
            var albumService    = new AlbumService();
            var pictureService  = new PictureService();
            var securityService = new SecurityService();

            string command = commandParameters[0];

            commandParameters = commandParameters.Skip(1).ToArray();
            string result = string.Empty;

            switch (command)
            {
            case "RegisterUser":
                var registerUser = new RegisterUserCommand(userService);
                result = registerUser.Execute(commandParameters);
                break;

            case "AddTown":
                var addTown = new AddTownCommand(townService);
                result = addTown.Execute(commandParameters);
                break;

            case "ModifyUser":
                var modifyUser = new ModifyUserCommand(userService, townService);
                result = modifyUser.Execute(commandParameters);
                break;

            case "Exit":
                ExitCommand exit = new ExitCommand();
                exit.Execute();
                break;

            case "DeleteUser":
                var deleteUser = new DeleteUser(userService);
                result = deleteUser.Execute(commandParameters);
                break;

            case "AddTag":
                var addTag = new AddTagCommand(tagService);
                result = addTag.Execute(commandParameters);
                break;

            case "CreateAlbum":
                var createAlbum = new CreateAlbumCommand(albumService, userService, tagService);
                result = createAlbum.Execute(commandParameters);
                break;

            case "AddTagTo":
                var addTagTo = new AddTagToCommand(tagService, albumService);
                result = addTagTo.Execute(commandParameters);
                break;

            case "MakeFriends":
                var makeFriends = new MakeFriendsCommand(userService);
                result = makeFriends.Execute(commandParameters);
                break;

            case "ListFriends":
                var listFriends = new ListFriendsCommand(userService);
                result = listFriends.Execute(commandParameters);
                break;

            case "ShareAlbum":
                var shareAlbum = new ShareAlbumCommand(albumService, userService);
                result = shareAlbum.Execute(commandParameters);
                break;

            case "UploadPicture":
                var uploadPicture = new UploadPictureCommand(pictureService, albumService);
                result = uploadPicture.Execute(commandParameters);
                break;

            case "Login":
                var loginCommand = new LoginCommand(securityService);
                result = loginCommand.Execute(commandParameters);
                break;

            case "Logout":
                var logoutCommand = new LogoutCommand(securityService);
                result = logoutCommand.Execute();
                break;
            }
            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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }