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);
        }
示例#2
0
        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);
        }