예제 #1
0
        public UserRepositoryAccount selectRepository(UserRepositoryAccount userRepositoryAccount)
        {
            Console.WriteLine("Enter name of repository to work with:");
            string repositoryName = Console.ReadLine();
            var    user           = userRepositoryAccount.User;
            var    repository     = repositoryClient.findRepository(repositoryName);

            if (repository == null)
            {
                throw new RepositoryNotFound(repositoryName);
            }

            var repositoryAccess = user.RepositoryAccesses.Find(it => it.Repository.Name.Equals(repositoryName));

            if (repositoryAccess == null)
            {
                if (!(repository.GetType() == typeof(PublicRepository)))
                {
                    throw new AccessDenied(repositoryName, user.Login);
                }
                repositoryAccess = new RepositoryAccess(repository, RepositoryAccessType.CONTRIBUTOR, user);
            }

            var userRepositorySession = new UserRepositorySession(user, repositoryAccess);

            userRepositorySessionHandler.handle(userRepositorySession);
            return(userRepositoryAccount);
        }
예제 #2
0
        static void Main(string[] args)
        {
            UserOperationsOrchestrator userOperationsOrchestrator = new UserOperationsOrchestrator();

            Console.WriteLine("Welcome to GangOfThree repository!");
            while (true)
            {
                UserRepositoryAccount userRepositoryAccount = userOperationsOrchestrator.anonymousUserRepositoryAccount();
                while (true)
                {
                    Console.WriteLine($"Choose one option:");
                    try
                    {
                        List <UserOperation> userOperations = userRepositoryAccount.UserOperations;
                        userOperations.ForEach(it =>
                                               Console.WriteLine($"{it.Id} - {it.Name}")
                                               );
                        int           choice        = ReadUserInputChoice();
                        UserOperation userOperation = userOperations.Find(it => it.Id == choice);
                        Tuple <string, UserRepositoryAccount> result =
                            userOperationsOrchestrator.handleUserOperation(userRepositoryAccount, userOperation.UserOperationType);
                        userRepositoryAccount = result.Item2;
                        Console.WriteLine(result.Item1);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
        }
예제 #3
0
        private UserRepositoryAccount signUp()
        {
            Tuple <string, string> loginAndPassword = ReadLoginAndPassword();

            userService.createUser(loginAndPassword.Item1, loginAndPassword.Item2);
            UserRepositoryAccount userRepositoryAccount = anonymousUserRepositoryAccount();

            return(userRepositoryAccount);
        }
예제 #4
0
        public string createUserRepository(RepositoryType repositoryType, UserRepositoryAccount userRepositoryAccount)
        {
            Console.WriteLine("Enter name of repository:");
            string     repositoryName = Console.ReadLine();
            Repository repository     = repositoryClient.addNewRepository(repositoryType, repositoryName, userRepositoryAccount.User);

            userRepositoryAccount.User.ClonedRepositories.Add(repository);
            if (repository != null)
            {
                return($"Repository {repository.Name} was created");
            }
            else
            {
                return("Repository failed to be created, try again");
            }
        }
예제 #5
0
 public List <string> listContributedRepositories(UserRepositoryAccount userRepositoryAccount)
 {
     return(userRepositoryAccount.ContributedRepositories.Select(it => it.Name).ToList());
 }
예제 #6
0
        public Tuple <string, UserRepositoryAccount> handleUserOperation(UserRepositoryAccount userRepositoryAccount,
                                                                         UserOperationType type)
        {
            string result = "";
            UserRepositoryAccount resultUserRepositoryAccount = userRepositoryAccount;

            switch (type)
            {
            case UserOperationType.CREATE_PUBLIC_REPOSITORY:
            {
                result = userRepositoryService.createUserRepository(RepositoryType.PUBLIC, userRepositoryAccount);
                resultUserRepositoryAccount = identifiedUserRepositoryAccount(userRepositoryAccount.User);
                break;
            }

            case UserOperationType.CREATE_PRIVATE_REPOSITORY:
            {
                result = userRepositoryService.createUserRepository(RepositoryType.PRIVATE, userRepositoryAccount);
                resultUserRepositoryAccount = identifiedUserRepositoryAccount(userRepositoryAccount.User);
                break;
            }

            case UserOperationType.LIST_OWN_REPOSITORIES:
            {
                result =
                    $"Your repositories:\n{String.Join("\n", userRepositoryService.listOwnRepositories(userRepositoryAccount).ToArray())}";
                resultUserRepositoryAccount = identifiedUserRepositoryAccount(userRepositoryAccount.User);
                break;
            }

            case UserOperationType.LIST_CLONED_REPOSITORIES:
            {
                result =
                    $"Your cloned repositories:\n{String.Join("\n", userRepositoryService.listClonedRepositories(userRepositoryAccount).ToArray())}";
                resultUserRepositoryAccount = identifiedUserRepositoryAccount(userRepositoryAccount.User);
                break;
            }

            case UserOperationType.LIST_CONTRIBUTED_REPOSITORIES:
            {
                var user = userService.getUser(userRepositoryAccount.User.Login);
                userRepositoryAccount = identifiedUserRepositoryAccount(user);
                result =
                    $"Repositories where you made contributions:\n{String.Join("\n", userRepositoryService.listContributedRepositories(userRepositoryAccount).ToArray())}";
                resultUserRepositoryAccount = identifiedUserRepositoryAccount(userRepositoryAccount.User);
                break;
            }

            case UserOperationType.LOG_OUT:
            {
                result = "Thank you for your work! See you later!";
                resultUserRepositoryAccount = logOut(userRepositoryAccount.User);
                break;
            }

            case UserOperationType.SIGN_IN:
            {
                resultUserRepositoryAccount = signIn();
                result = $"Welcome back {resultUserRepositoryAccount.User.Login}! You successfully signed in.";
                break;
            }

            case UserOperationType.SIGN_UP:
            {
                resultUserRepositoryAccount = signUp();
                result = "You successfully signed up";
                break;
            }

            case UserOperationType.LOOK_FOR_USER:
            {
                User existingUser                = lookForUser();
                var  userOwnRepositories         = existingUser.getOwnRepositories().Select(it => it.Name);
                var  userContributedRepositories = existingUser.getContributedRepositories().Select(it => it.Name);
                result = $"Found user:{existingUser.Login}" +
                         $"\nUser own repositories:\n{String.Join("\n", userOwnRepositories)}" +
                         $"\nUser contributed repositories:\n{String.Join("\n", userContributedRepositories)}";
                resultUserRepositoryAccount = identifiedUserRepositoryAccount(userRepositoryAccount.User);
                break;
            }

            case UserOperationType.LOOK_FOR_REPOSITORY:
            {
                RepositoryDetails repositoryDetails = repositoryService.getRepositoryDetails();
                result = $"Repository:{repositoryDetails.Name}\n" +
                         $"Owner:{repositoryDetails.OwnerName}\n" +
                         $"Branches:\n{String.Join("\n", repositoryDetails.Branches)}\n" +
                         $"Contributors:\n{String.Join("\n", repositoryDetails.Contributors)}";
                break;
            }

            case UserOperationType.SELECT_REPOSITORY:
            {
                var account = userRepositoryService.selectRepository(userRepositoryAccount);
                resultUserRepositoryAccount = identifiedUserRepositoryAccount(account.User);
                break;
            }

            case UserOperationType.LIST_ALL_PUBLIC_REPOSITORIES:
            {
                RepositoryCollection collection         = new PublicRepositoryCollection();
                RepositoryIterator   repositoryIterator = collection.RepositoryIterator();
                while (repositoryIterator.hasMore())
                {
                    Repository repository = repositoryIterator.getNext();
                    Console.WriteLine($"Repository:{repository.Name}, owner:{repository.Owner.Login}");
                }
                break;
            }

            case UserOperationType.LIST_RATING_REPOSITORIES:
            {
                RepositoryCollection collection         = new RatingRepositoryCollection(resultUserRepositoryAccount.User);
                RepositoryIterator   repositoryIterator = collection.RepositoryIterator();
                while (repositoryIterator.hasMore())
                {
                    Repository repository = repositoryIterator.getNext();
                    Console.WriteLine($"Repository:{repository.Name}, owner:{repository.Owner.Login}, rating:{repository.getRepositoryRating()}");
                }
                break;
            }

            default:
            {
                result = "Invalid user operation type";
                break;
            }
            }

            return(new Tuple <string, UserRepositoryAccount>(result, resultUserRepositoryAccount));
        }