private void SaveSettings_Click(object sender, RoutedEventArgs e)
        {
            var selectedRootpath = RootDirectoryPath.Text;

            if (string.IsNullOrEmpty(selectedRootpath))
            {
                MessageBox.Show(this, "It is required to select a root directory.", "Error", MessageBoxButton.OK);
                return;
            }
            if (!Directory.Exists(selectedRootpath))
            {
                var confirmResult = MessageBox.Show("Directory does not exist. Do you want to create it?", "Confirm", MessageBoxButton.YesNo);
                if (confirmResult != MessageBoxResult.Yes)
                {
                    return;
                }
                Directory.CreateDirectory(selectedRootpath);
            }
            if (!AppScopeSettingsRepository.SetGlobalRootDirectory(selectedRootpath))
            {
                MessageBox.Show("Could not save settings. Please ensure that you are running this Visual Studio instance as administrator.", "Error", MessageBoxButton.OK);
                return;
            }
            if (!RootHasTemplateManifests(selectedRootpath))
            {
                var confirmResult = MessageBox.Show("Selected root does not contain templates.\n\nDo you want to install the default templates (recommended)?", "Confirm", MessageBoxButton.YesNo);
                if (confirmResult != MessageBoxResult.Yes)
                {
                    return;
                }
                BuiltInTemplatesService.UnzipAll(selectedRootpath);
            }
            DialogResult = true;
            Close();
        }
예제 #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);
        }
        private void UnpackTemplates_Clicked(object sender, RoutedEventArgs e)
        {
            var rootDirectory = AppScopeSettingsRepository.GetGlobalRootDirectory();

            if (string.IsNullOrEmpty(rootDirectory) || !Directory.Exists(rootDirectory))
            {
                MessageBox.Show(this, "You need to set a valid root directory.", "Error", MessageBoxButton.OK);
                return;
            }
            UnpackBuiltInButton.IsEnabled = false;
            if (Directory.EnumerateDirectories(rootDirectory).Any())
            {
                var overwriteConfirmResult = MessageBox.Show("This will overwrite changes made to built-in templates in this root folder.\nAre you sure you want to continue?\n\nNote: Always make your modifications changes in copies and never directly in the built-in example templates.", "Confirm", MessageBoxButton.YesNo);
                if (overwriteConfirmResult != MessageBoxResult.Yes)
                {
                    UnpackBuiltInButton.IsEnabled = true;
                    return;
                }
                BuiltInTemplatesService.DeleteExistingTemplates(rootDirectory);
            }
            BuiltInTemplatesService.UnzipAll(rootDirectory);
            MessageBox.Show("Built-in templates updated", "", MessageBoxButton.OK);
            UnpackBuiltInButton.IsEnabled = true;
        }