private string FindModuleTemplatesRootDirectory(string solutionRoot, string globalTemplatesFolder)
        {
            var locateTemplateFolderService = new TemplateFolderService(solutionRoot);

            if (locateTemplateFolderService.TryGetAbsolutePath(_solutionScopeSettings.RelativeTemplatesFolder,
                                                               out var templateFolderfullpath))
            {
                return(templateFolderfullpath);
            }

            var moduleTemplateFolder = locateTemplateFolderService.Locate();

            if (!string.IsNullOrWhiteSpace(moduleTemplateFolder))
            {
                _solutionScopeSettings.RelativeTemplatesFolder = moduleTemplateFolder;
                _solutionScopeSettings.SaveSettings();
                return(moduleTemplateFolder);
            }

            if (_solutionScopeSettings.SkipCreateFolderDialog)
            {
                return(globalTemplatesFolder);
            }

            var createFolderResult = MessageBox.Show(
                "The current solution does not have a local module templates folder with valid templates.\n\nDo you want to create one and unzip the example templates?",
                "Create solution scope Helix modules template folder", MessageBoxButton.YesNo);

            if (createFolderResult != MessageBoxResult.Yes)
            {
                var skipDialogResult = MessageBox.Show(
                    "It is recommended to keep module templates under source control together with the solution.\n\nYou can manually create a folder in the solution root directory and copy in your Helix module templates.\n\nDo you want to skip this dialog in the future for the current solution?",
                    "Create a solution scope Helix modules template folder", MessageBoxButton.YesNo);
                _solutionScopeSettings.SkipCreateFolderDialog  = skipDialogResult == MessageBoxResult.Yes;
                _solutionScopeSettings.RelativeTemplatesFolder = string.Empty;
                _solutionScopeSettings.SaveSettings();
                return(globalTemplatesFolder);
            }

            moduleTemplateFolder = TemplateInstallService.CreateTemplateFolder(solutionRoot);

            var globalManifests = new ReadAllManifestFilesService(globalTemplatesFolder, _initialTokens).Read();

            foreach (var manifest in globalManifests.Where(m => m.TemplateType != TemplateType.Solution))
            {
                TemplateInstallService.CopyDirectory(new DirectoryInfo(manifest.ManifestRootPath), moduleTemplateFolder);
            }
            _solutionScopeSettings.RelativeTemplatesFolder = moduleTemplateFolder;
            return(moduleTemplateFolder);
        }
Пример #2
0
        private string FindModuleTemplatesRootDirectory(string solutionRoot, string globalRootDirectory)
        {
            var solutionScopeSettingsRepository = new SolutionScopeSettingsRepository(solutionRoot);
            var locateTemplateFolderService     = new TemplateFolderService(solutionRoot);
            var solutionScopeSettings           = solutionScopeSettingsRepository.Get();

            if (solutionScopeSettings != null &&
                locateTemplateFolderService.TryGetAbsolutePath(solutionScopeSettings.ModuleTemplatesFolder,
                                                               out var templateFolderfullpath))
            {
                return(templateFolderfullpath);
            }

            var moduleTemplateFolder = locateTemplateFolderService.Locate();

            if (!string.IsNullOrWhiteSpace(moduleTemplateFolder))
            {
                solutionScopeSettingsRepository.CreateSettingsFile(moduleTemplateFolder);
                return(moduleTemplateFolder);
            }

            if (solutionScopeSettings != null && solutionScopeSettings.SkipCreateFolderDialog)
            {
                return(globalRootDirectory);
            }

            var createFolderResult = MessageBox.Show(
                "The current solution does not have a local module templates folder with valid templates.\n\nDo you want to create one and unzip the example templates?",
                "Create solution scope Helix modules template folder", MessageBoxButton.YesNo);

            if (createFolderResult != MessageBoxResult.Yes)
            {
                var skipDialogResult = MessageBox.Show(
                    "It is recommended to keep module templates under source control together with the solution.\n\nYou can manually create a folder in the solution root directory and copy in your Helix module templates.\n\nDo you want to skip this dialog in the future for the current solution?",
                    "Create solution scope Helix modules template folder", MessageBoxButton.YesNo);
                solutionScopeSettingsRepository.CreateSettingsFile(string.Empty, skipDialogResult == MessageBoxResult.Yes);
                return(globalRootDirectory);
            }

            moduleTemplateFolder = BuiltInTemplatesService.CreateTemplateFolder(solutionRoot);
            BuiltInTemplatesService.Unzip(moduleTemplateFolder, TemplateType.Module);
            solutionScopeSettingsRepository.CreateSettingsFile(moduleTemplateFolder);
            return(moduleTemplateFolder);
        }