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);
        }
        public void Initialize(string rootDirectory, string solutionRoot, IDictionary <string, string> initialTokens, bool?isSolutionCreation)
        {
            _initialTokens      = initialTokens.ToDictionary(t => t.Key, t => t.Value);
            _isSolutionCreation = isSolutionCreation;
            SolutionRoot        = solutionRoot;
            var readAllManifestService = new ReadAllManifestFilesService(rootDirectory, initialTokens);

            _manifests = readAllManifestService.Read();
            if (isSolutionCreation.HasValue)
            {
                _manifests = _manifests.Where(m => isSolutionCreation.Value ? m.TemplateType == TemplateType.Solution : m.TemplateType != TemplateType.Solution).ToArray();
            }

            if (!_manifests.Any())
            {
                MessageBox.Show("No valid templates found in root directory", "Information", MessageBoxButton.OK);
                return;
            }
            SetAvailableManifestsCollection(_manifests);
            AvailableManifestsComboBox.Items.Refresh();
            AvailableManifestsComboBox.SelectedIndex = 0;
        }
Example #3
0
        public void Initialize(string rootDirectory, string solutionRoot, IDictionary <string, string> initialTokens, bool?isSolutionCreation)
        {
            _initialTokens      = initialTokens.ToDictionary(t => t.Key, t => t.Value);
            _isSolutionCreation = isSolutionCreation;
            SolutionRoot        = solutionRoot;

            if (isSolutionCreation.HasValue && !isSolutionCreation.Value)
            {
                _moduleTemplateFolderService = new TemplateSettingsService(solutionRoot);
                var relativeModuleTemplateFolder = _moduleTemplateFolderService.Locate();

                //TODO: Ask if local module template folder should be created in sln root
                if (!string.IsNullOrWhiteSpace(relativeModuleTemplateFolder))
                {
                    rootDirectory = relativeModuleTemplateFolder;
                }
            }

            var readAllManifestService = new ReadAllManifestFilesService(rootDirectory, initialTokens);

            _manifests = readAllManifestService.Read();

            if (isSolutionCreation.HasValue)
            {
                _manifests = _manifests.Where(m => isSolutionCreation.Value ? m.TemplateType == TemplateType.Solution : m.TemplateType != TemplateType.Solution).ToArray();
            }

            if (!_manifests.Any())
            {
                MessageBox.Show("No valid templates found in root directory", "Information", MessageBoxButton.OK);
                return;
            }
            SetAvailableManifestsCollection(_manifests);
            AvailableManifestsComboBox.Items.Refresh();
            AvailableManifestsComboBox.SelectedIndex = 0;
        }