public void DoWork(Solution solution)
        {
            Argument.IsNotNull(() => solution);

            Log.Info("Generating solution '{0}'", solution);

            // create folders under root path
            var rootDirectoryInfo = new DirectoryInfo(solution.RootPath);
            CreateFolderStructure(rootDirectoryInfo);
            CreateSolutionAssets(rootDirectoryInfo, solution);

            // create files under root/src path
            var sourceDirectoryInfo = new DirectoryInfo(string.Format("{0}/src/", solution.RootPath));
            CreateSolutionFile(sourceDirectoryInfo, solution);
            CreateProjectFile(sourceDirectoryInfo, solution);
            if (solution.IncludeTestProject)
            {
                CreateTestProjectFile(sourceDirectoryInfo, solution);
            }

            CreateProjectAssets(sourceDirectoryInfo, solution);

            if (solution.InitializeGit)
            {
                _gitService.InitGitRepository(rootDirectoryInfo.FullName);
            }
        }
        public MainWindowViewModel(IMessageService messageService, ISolutionGeneratorService solutionGeneratorService, IProcessService processService)
        {
            Argument.IsNotNull(() => messageService);
            Argument.IsNotNull(() => solutionGeneratorService);
            Argument.IsNotNull(() => processService);

            _messageService = messageService;
            _solutionGeneratorService = solutionGeneratorService;
            _processService = processService;

            Generate = new Command(OnGenerateExecute, OnGenerateCanExecute);

            Solution = new Solution();
        }
        public SolutionOptionsViewModel(Solution solution, ISelectDirectoryService selectDirectoryService)
        {
            Argument.IsNotNull(() => solution);
            Argument.IsNotNull(() => selectDirectoryService);

            Solution = solution;
            _selectDirectoryService = selectDirectoryService;
            _selectDirectoryService.ShowNewFolderButton = true;

            AvailableLicenseNames = Solution.AvailableLicenses;
            AvailableProjectTypes = new ObservableCollection<ProjectTypes>(Enum<ProjectTypes>.GetValues());

            // TODO: Read from registry instead in service
            AvailableTargetFrameworks = new ObservableCollection<string>(new[] { "v2.0", "v3.0", "v3.5", "v4.0", "v4.5" });

            SelectSolutionDirectory = new Command(OnSelectSolutionDirectoryExecute);
        }
        public GeneratorForm()
        {
            InitializeComponent();

            _solutionModel = new Solution();

            _solutionModel.PropertyChanged += (sender, args) =>
                {
                    errorProvider1.UpdateBinding();

                    switch (args.PropertyName)
                    {
                        case "SolutionName":
                            _solutionModel.ProjectName = string.IsNullOrEmpty(_solutionModel.ProjectName)
                                                             ? _solutionModel.SolutionName
                                                             : _solutionModel.ProjectName;
                            _solutionModel.ProjectRootNameSpace = string.IsNullOrEmpty(_solutionModel.ProjectRootNameSpace)
                                                                      ? _solutionModel.SolutionName
                                                                      : _solutionModel.ProjectRootNameSpace;
                            _solutionModel.ProjectAssemblyName = string.IsNullOrEmpty(_solutionModel.ProjectAssemblyName)
                                                                     ? _solutionModel.SolutionName
                                                                     : _solutionModel.ProjectAssemblyName;
                            break;
                        case "ProjectName":
                            _solutionModel.ProjectRootNameSpace = _solutionModel.ProjectName;
                            _solutionModel.ProjectAssemblyName = _solutionModel.ProjectName;
                            break;
                        case "LicenseName":
                            _solutionModel.LicenseText = File.ReadAllText(string.Format("./Licenses/{0}.txt", _solutionModel.LicenseName));
                            break;
                    }
                };

            solutionModelBindingSource.DataSource = _solutionModel;

            btnGenerate.Enabled = Controls.OfType<Control>().Select(x => errorProvider1.GetError(x)).All(string.IsNullOrWhiteSpace);

            _solutionModel.PropertyChanged += (sender, args) =>
                {
                    btnGenerate.Enabled = Controls.OfType<Control>().Select(x => errorProvider1.GetError(x)).All(string.IsNullOrWhiteSpace);
                    readmeRichTextBox.Enabled = _solutionModel.IncludeReadme;
                };
        }
        public IncludeOptionsViewModel(Solution solution)
        {
            Argument.IsNotNull(() => solution);

            Solution = solution;
        }
        private FileInfo CreateTestProjectFile(DirectoryInfo root, Solution solution)
        {
            string projectRoot = string.Format("{0}/{1}.Tests/", root.FullName, solution.ProjectName);
            var directoryInfo = new DirectoryInfo(projectRoot);

            if (!directoryInfo.Exists)
            {
                directoryInfo.Create();
            }

            var projectName = string.Format("{0}.Tests", solution.ProjectName);
            var project = new Project(solution.TestProjectGuid)
            {
                ProjectAssemblyName = string.Format("{0}.Tests", solution.ProjectAssemblyName),
                ProjectName = projectName,
                ProjectRootNameSpace = string.Format("{0}.Tests", solution.ProjectRootNameSpace),
                TargetFramework = solution.TargetFramework,
                ReleaseOutputPath = string.Format("../../output/Release/{0}", projectName),
                DebugOutputPath = string.Format("../../output/Debug/{0}", projectName),
                ProjectOutputType = ProjectOutputTypes.Library
            };

            if (string.Equals(solution.TargetFramework, "v4.5"))
            {
                project.ProjectType = ProjectTypes.Test;
                var packagesFile = new FileInfo(projectRoot + "packages.config");
                File.WriteAllText(packagesFile.FullName, _templateRenderer.RenderFile(PackagesTemplate, project));
            }

            _referencesService.AddRequiredReferences(project);

            var projectFile = new FileInfo(projectRoot + project.ProjectName + ".csproj");
            File.WriteAllText(projectFile.FullName, _templateRenderer.RenderFile(ProjectTemplate, project));

            return projectFile;
        }
        private FileInfo CreateSolutionFile(DirectoryInfo root, Solution model)
        {
            Log.Info("Creating solution file");

            var templateToRender = model.IncludeTestProject ? SolutionWithTestTemplate : SolutionTemplate;
            var solutionFile = new FileInfo(string.Format("{0}{1}.sln", root.FullName, model.SolutionName));

            File.WriteAllText(solutionFile.FullName, _templateRenderer.RenderFile(templateToRender, model));

            return solutionFile;
        }
        private FileInfo[] CreateSolutionAssets(DirectoryInfo root, Solution solution)
        {
            var files = new List<FileInfo>();

            if (solution.IncludeGitAttribute)
            {
                var solutionFile = new FileInfo(Path.Combine(root.FullName, ".gitattributes"));
                File.WriteAllText(solutionFile.FullName, _templateRenderer.RenderFile(GitAttributeTemplate, solution));
                files.Add(solutionFile);
            }

            if (solution.IncludeGitIgnore)
            {
                var solutionFile = new FileInfo(Path.Combine(root.FullName, ".gitignore"));
                File.WriteAllText(solutionFile.FullName, _templateRenderer.RenderFile(GitIgnoreTemplate, solution));
                files.Add(solutionFile);
            }

            if (solution.IncludeReadme)
            {
                var solutionFile = new FileInfo(Path.Combine(root.FullName, "README.md"));
                File.WriteAllText(solutionFile.FullName, _templateRenderer.RenderContent(solution.SolutionReadme, solution));
                files.Add(solutionFile);
            }

            if (solution.IncludeLicense)
            {
                var assemblyDirectory = GetType().Assembly.GetDirectory();
                string licenseTemplateFileName = Path.Combine(assemblyDirectory, "Templates", "Licenses", string.Format("{0}.txt", solution.LicenseName));
                string licenseContent = File.ReadAllText(licenseTemplateFileName);

                var solutionFile = new FileInfo(Path.Combine(root.FullName, "License.txt"));
                File.WriteAllText(solutionFile.FullName, licenseContent);
                files.Add(solutionFile);
            }

            return files.ToArray();
        }
        private FileInfo CreateProjectFile(DirectoryInfo root, Solution solution)
        {
            Log.Info("Creating project file");

            string projectRoot = string.Format("{0}/{1}/", root.FullName, solution.ProjectName);
            var directoryInfo = new DirectoryInfo(projectRoot);
            var projectTemplate = ProjectTemplate;

            if (!directoryInfo.Exists)
            {
                directoryInfo.Create();
            }

            var project = new Project(solution.TestProjectGuid)
            {
                ProjectAssemblyName = solution.ProjectAssemblyName,
                ProjectName = solution.ProjectName,
                ProjectRootNameSpace = solution.ProjectRootNameSpace,
                TargetFramework = solution.TargetFramework,
                ReleaseOutputPath = string.Format("../../output/Release/{0}", solution.ProjectName),
                DebugOutputPath = string.Format("../../output/Debug/{0}", solution.ProjectName),
                ProjectType = solution.ProjectType
            };

            project.ProjectOutputType = _projectTypeConverterService.Convert(solution.ProjectType);
            _referencesService.AddRequiredReferences(project);

            if (string.Equals(project.ProjectOutputType, "Exe"))
            {
                File.WriteAllText(projectRoot + "Program.cs", _templateRenderer.RenderFile(ConsoleProgramClass, project));
            }
            else if (string.Equals(solution.ProjectType, "WPF"))
            {
                projectTemplate = WpfProjectTemplate;
                File.WriteAllText(projectRoot + "App.xaml", _templateRenderer.RenderFile(AppXaml, project));
                File.WriteAllText(projectRoot + "App.xaml.cs", _templateRenderer.RenderFile(AppXamlCs, project));
                File.WriteAllText(projectRoot + "MainWindow.xaml", _templateRenderer.RenderFile(MainWindowXaml, project));
                File.WriteAllText(projectRoot + "MainWindow.xaml.cs", _templateRenderer.RenderFile(MainWindowXamlCs, project));
            }
            else if (string.Equals(solution.ProjectType, "WinForms"))
            {
                File.WriteAllText(projectRoot + "Form1.cs", _templateRenderer.RenderFile(Form1Cs, project));
                File.WriteAllText(projectRoot + "Form1.Designer.cs", _templateRenderer.RenderFile(Form1DesignerCs, project));
                File.WriteAllText(projectRoot + "Program.cs", _templateRenderer.RenderFile(ProgramCs, project));
            }

            var projectFile = new FileInfo(projectRoot + project.ProjectName + ".csproj");
            File.WriteAllText(projectFile.FullName, _templateRenderer.RenderFile(ProjectTemplate, project));

            return projectFile;
        }
        private FileInfo[] CreateProjectAssets(DirectoryInfo root, Solution model)
        {
            Log.Info("Creating project assets");

            var files = new List<FileInfo>();

            FileInfo solutionFile;
            if (model.IncludeReSharper)
            {
                solutionFile = new FileInfo(string.Format("{0}/resharper.settings", root.FullName));
                File.WriteAllText(solutionFile.FullName, _templateRenderer.RenderFile(ResharperSettingsTemplate, model));
                files.Add(solutionFile);
            }

            if (model.IncludeStylecop)
            {
                solutionFile = new FileInfo(string.Format("{0}/Settings.StyleCop", root.FullName));
                File.WriteAllText(solutionFile.FullName, _templateRenderer.RenderFile(StyleCopTemplate, model));
                files.Add(solutionFile);
            }

            return files.ToArray();
        }