public void CreateFileWithinProject([NotNull] TestCopProjectItem projectItem, [NotNull] string targetFile) { var desiredTemplateName = LookupTemplateName(projectItem.Project); var boundSettingsStore = _settingsStore.BindToContextTransient(ContextRange.ApplicationWide); var context = _dataContexts.CreateOnActiveControl(_lifetime); var applicableFileTemplateScopes = _scopeManager.EnumerateRealScopePoints(new TemplateAcceptanceContext(new ProjectFolderWithLocation(projectItem.Project))); applicableFileTemplateScopes = applicableFileTemplateScopes.Distinct().Where(s => s is InLanguageSpecificProject).ToList(); var classTemplate = _storedTemplatesProvider.EnumerateTemplates(boundSettingsStore, TemplateApplicability.File) .Where(x => x.Description == desiredTemplateName && TemplateScopeManager.TemplateIsAvailable(x, applicableFileTemplateScopes)) .Select(x => x) .FirstOrDefault(); if (classTemplate == null) { ResharperHelper.AppendLineToOutputWindow(string.Format("File Template for '{0}' not found with default to 'Class'", desiredTemplateName)); classTemplate = LoadTemplateFromQuickList(context, "Class"); } IProjectFolder folder = (IProjectFolder)projectItem.Project.FindProjectItemByLocation(projectItem.SubNamespaceFolder) ?? GetOrCreateProjectFolder(projectItem); if (folder == null) { ResharperHelper.AppendLineToOutputWindow("Error failed to create/location project folder" + projectItem.SubNamespaceFolder); return; } string extension = Enumerable.First(_fileExtensions.GetExtensions(projectItem.Project.ProjectProperties.DefaultLanguage.DefaultProjectFileType)); FileTemplatesManager.Instance.CreateFileFromTemplate(targetFile + extension, new ProjectFolderWithLocation(folder), classTemplate); }
public TestCopOptionPage(Lifetime lifetime, OptionsSettingsSmartContext settings, TemplateScopeManager scopeManager , IThemedIconManager iconManager, UIApplication application , StoredTemplatesProvider storedTemplatesProvider, ILiveTemplatesUIHelper templatesUiHelper, FileTemplatesManager fileTemplatesManager, ISolution solution = null) { _lifetime = lifetime; _settings = settings; _scopeManager = scopeManager; _application = application; _solution = solution; _fileTemplatesManager = fileTemplatesManager; _storedTemplatesProvider = storedTemplatesProvider; _templatesUiHelper = templatesUiHelper; InitializeComponent(); var testFileAnalysisSettings = settings.GetKey <TestFileAnalysisSettings>(SettingsOptimization.DoMeSlowly); InitializeComponent(); BuildTestStrategyCombo(testFileAnalysisSettings); //Do this first as it is reference by other display fields testClassSuffixTextBox.BindWithRegexMatchesValidation(testFileAnalysisSettings, P(x => x.TestClassSuffix), "^[_a-zA-Z,]*$"); //Regex Config for Multiple Test Assemply Logic via project naming testProjectNameRegExTextBox.BindWithValidationMustBeARegex(testFileAnalysisSettings, P(x => x.TestProjectNameToCodeProjectNameRegEx)); testProjectNameRegExReplaceTextBox.BindWithRegexMatchesValidation(testFileAnalysisSettings, P(x => x.TestProjectNameToCodeProjectNameRegExReplace), "^[\\$\\.a-zA-Z1-9]*$"); //Regex Config for Multiple Test Assemply Logic via namespace naming testNamespaceRegExTextBox.BindWithValidationMustBeARegex(testFileAnalysisSettings, P(x => x.TestProjectToCodeProjectNameSpaceRegEx)); testNamespaceRegExReplaceTextBox.BindWithRegexMatchesValidation(testFileAnalysisSettings, P(x => x.TestProjectToCodeProjectNameSpaceRegExReplace), "^[\\$\\.a-zA-Z1-9]*$"); // //Regex Config for Single Test Assemply Logic SingleTestNamespaceRegExTextBox.BindWithValidationMustBeARegex(testFileAnalysisSettings, P(x => x.SingleTestRegexTestToAssembly)); SingleTestNamespaceToAssemblyRegExReplaceTextBox.BindWithRegexMatchesValidation(testFileAnalysisSettings, P(x => x.SingleTestRegexTestToAssemblyProjectReplace), "^[\\$\\.a-zA-Z1-9]*$"); SingleTestNamespaceToAssemblySubNameSpaceRegExReplaceTextBox.BindWithRegexMatchesValidation(testFileAnalysisSettings, P(x => x.SingleTestRegexTestToAssemblyProjectSubNamespaceReplace), "^[\\$\\.a-zA-Z1-9]*$"); SingleTestCodeNamespaceRegExTextBox.BindWithValidationMustBeARegex(testFileAnalysisSettings, P(x => x.SingleTestRegexCodeToTestAssembly)); SingleTestCodeNamespaceToTestRegExReplaceTextBox.BindWithRegexMatchesValidation(testFileAnalysisSettings, P(x => x.SingleTestRegexCodeToTestReplace), "^[\\$\\.a-zA-Z1-9]*$"); // testFileAnalysisSettings.TestingAttributes().ForEach(p => testingAttributesListBox.Items.Add(p)); testFileAnalysisSettings.BddPrefixes().ForEach(p => contextPrefixesListBox.Items.Add(p)); SwitchBetweenFilesShortcutTextBox.Text = testFileAnalysisSettings.ShortcutToSwitchBetweenFiles; RunTestsShortcutTextBox.Text = testFileAnalysisSettings.ShortcutToRunTests; OrphanedFilesPatternsTextBox.Text = testFileAnalysisSettings.OrphanedFilesPatterns; BindWithValidationMustBeAFileTemplate(testFileAnalysisSettings, codeTemplateTextBox, P(x => x.CodeFileTemplateName)); BindWithValidationMustBeAFileTemplate(testFileAnalysisSettings, unitTestTemplateTextBox, P(x => x.UnitTestFileTemplateName)); ShowAllTestsWithUsageCheckBox.IsChecked = testFileAnalysisSettings.FindAnyUsageInTestAssembly; CheckTestNamespaces.IsChecked = testFileAnalysisSettings.CheckTestNamespaces; CheckSearchForOrphanedCodeFiles.IsChecked = testFileAnalysisSettings.FindOrphanedProjectFiles; SupportRenameRefactor.IsChecked = testFileAnalysisSettings.SupportRenameRefactor; OutputPanelOpenOnKeyboardMapping.IsChecked = testFileAnalysisSettings.OutputPanelOpenOnKeyboardMapping; TestCopLogoImage.Source = (ImageSource) new BitmapToImageSourceConverter().Convert( iconManager.Icons[UnnamedThemedIcons.Agent64x64.Id].CurrentGdipBitmap96, null, null, null); }
public TestCopFileCreater(StoredTemplatesProvider storedTemplatesProvider , ISettingsStore settingsStore , IProjectFileExtensions fileExtensions , DataContexts dataContexts, Lifetime lifetime, FileTemplatesManager fileTemplatesManager, TemplateScopeManager scopeManager) { _storedTemplatesProvider = storedTemplatesProvider; _settingsStore = settingsStore; _dataContexts = dataContexts; _lifetime = lifetime; _fileTemplatesManager = fileTemplatesManager; _fileExtensions = fileExtensions; _scopeManager = scopeManager; }
private IEnumerable <Template> GetTemplatesForName(string templateDescription) { IList <ITemplateScopePoint> applicableFileTeamplateScope = new List <ITemplateScopePoint>(); applicableFileTeamplateScope.Add(new InAnyProject()); applicableFileTeamplateScope.Add(new InCSharpProjectFile()); applicableFileTeamplateScope.Add(new InVBProjectFile()); var template = _storedTemplatesProvider.EnumerateTemplates(_settingsStore, TemplateApplicability.File) .Where(x => x.Description == templateDescription && TemplateScopeManager.TemplateIsAvailable(x, applicableFileTeamplateScope)) .Select(x => x); return(template); }