예제 #1
0
파일: Setup.cs 프로젝트: pdelvo/virtue-1
        private static Project SetUpProject(Program instance)
        {
            var project = new Project();

            Console.Write("Project name: ");
            project.Name = Console.ReadLine();
            var root = Path.Combine("projects", SanitizeFileName(project.Name));
            Console.Write("Local repository path (enter for default): ");
            project.LocalRepository = Console.ReadLine();
            if (string.IsNullOrWhiteSpace(project.LocalRepository))
                project.LocalRepository = Path.Combine(root, "source");
            if (!Directory.Exists(root))
                Directory.CreateDirectory(root);
            if (!Directory.Exists(project.LocalRepository))
                Directory.CreateDirectory(project.LocalRepository);

            var providers = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetTypes()).Aggregate((a, b) =>
                a.Concat(b).ToArray()).Where(t => typeof(IVersionControlProvider).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface)
                .Select(t => Activator.CreateInstance(t) as IVersionControlProvider).ToArray();
            IVersionControlProvider provider;

            while (true)
            {
                Console.WriteLine("The following version control providers are available:");
                for (int i = 0; i < providers.Length; i++)
                    Console.WriteLine("[{0}]: {1}", i, providers[i].FriendlyName);
                Console.Write("> ");
                var selection = Console.ReadLine();
                int index;
                if (int.TryParse(selection, out index))
                {
                    provider = providers[index];
                    break;
                }
            }

            project.VCSProvider = project.GetType().AssemblyQualifiedName;

            Console.WriteLine("Do I need any credentials to clone this repository (yes/no)?");
            Console.Write("> ");
            string input;
            do
            {
                input = Console.ReadLine();
            } while (input != "yes" && input != "no");
            if (input == "yes")
                provider.GetIdentity(instance, project);

            Console.WriteLine("Enter the URL to clone the repository from:");
            Console.Write("> ");
            project.RepositoryURL = Console.ReadLine();

            provider.Clone(project.RepositoryURL, project.LocalRepository);

            return project;
        }
예제 #2
0
 public Configuration()
 {
     Projects = new Project[0];
     Plugins = new string[0];
 }