private void AddFiles(Project project, ProjectRewriteCacheEntry projectInfos)
        {
            /**
             * project.vstemplate TemplateContent like
             *
             *      <Project TargetFileName="$ext_safeprojectname$.ViewModels.csproj" File="Company.Desktop.ViewModels.csproj" ReplaceParameters="true">
             *        <Folder Name="Common" TargetFolderName="Common">
             *          <ProjectItem ReplaceParameters="true" TargetFileName="RegionNames.cs">RegionNames.cs</ProjectItem>
             *        </Folder>
             *        <Folder Name="Controls" TargetFolderName="Controls">
             *          <ProjectItem ReplaceParameters="true" TargetFileName="SampleDataOverviewViewModel.cs">SampleDataOverviewViewModel.cs</ProjectItem>
             *          <ProjectItem ReplaceParameters="true" TargetFileName="SampleDataViewModel.cs">SampleDataViewModel.cs</ProjectItem>
             *        </Folder>
             *        <Folder Name="Windows" TargetFolderName="Windows">
             *          <ProjectItem ReplaceParameters="true" TargetFileName="MainViewModel.cs">MainViewModel.cs</ProjectItem>
             *          <ProjectItem ReplaceParameters="true" TargetFileName="SecondaryWindowViewModel.cs">SecondaryWindowViewModel.cs</ProjectItem>
             *        </Folder>
             *      </Project>
             */

            var allowedDocuments = Enumerable.Concat(
                Context.Explorer.GetAdditiontalDocuments(Context.ProjectPath),
                Context.Explorer.GetReferencedDocuments(Context.ProjectPath)
                );
            var whiteList = new HashSet <string>(allowedDocuments);

            var openInEditorFiles = new HashSet <Uri>(GetOpenInEditorFiles(projectInfos));

            if (openInEditorFiles.Count > 0)
            {
                Log.Debug(nameof(openInEditorFiles) + " " + string.Join(", ", openInEditorFiles));
            }

            project.Children = GetProjectMembers(Path.GetDirectoryName(Context.ProjectPath), whiteList, openInEditorFiles).ToArray();
        }
        private ProjectRewriteCacheEntry BuildCacheEntry(Project project)
        {
            var item = new ProjectRewriteCacheEntry();

            item.ProjectFilePath        = project.FilePath;
            item.OriginalAssemblyName   = project.AssemblyName;
            item.RelativeVsTemplatePath = BuildRelativeTemplatePath(project.FilePath, RootTemplatePath);
            return(item);
        }
        private TemplateContent CreateContent(ProjectRewriteCacheEntry projectInfos)
        {
            var content = new TemplateContent();
            var project = new Project();

            project.ReplaceParameters = true;
            project.File           = Path.GetFileName(projectInfos.ProjectFilePath);
            project.TargetFileName = projectInfos.ProjectTemplateReference;
            AddFiles(project, projectInfos);
            content.Children = new NestableContent[]
            {
                project
            };
            return(content);
        }
        private VsTemplate CreateTemplate(ProjectRewriteCacheEntry projectInfos)
        {
            var template = new VsTemplate();

            template.Type                            = Constants.VsTemplate.ProjectTypes.Project;
            template.TemplateData                    = new TemplateData();
            template.TemplateData.Icon               = PackageHelper.GetConfigurationIcon(Context.Configuration);
            template.TemplateData.Name               = "$safeprojectname$";
            template.TemplateData.DefaultName        = "Project";
            template.TemplateData.ProvideDefaultName = true;
            template.TemplateData.CreateNewFolder    = true;
            template.TemplateData.CreateInPlace      = true;
            template.TemplateData.CodeLanguage       = Context.Configuration.CodeLanguage;
            template.TemplateContent                 = CreateContent(projectInfos);
            return(template);
        }
        private IEnumerable <Uri> GetOpenInEditorFiles(ProjectRewriteCacheEntry projectInfos)
        {
            Uri MakeFullUri(string relative)
            {
                return(new Uri(
                           new Uri(Context.Explorer.SolutionPath, UriKind.Absolute),
                           new Uri(relative, UriKind.Relative)
                           ));
            }

            var projectBase   = new Uri(Path.GetDirectoryName(projectInfos.ProjectFilePath) + Path.DirectorySeparatorChar, UriKind.Absolute);
            var referenceUris = Context.Configuration
                                .OpenInEditorReferences
                                .Select(MakeFullUri);

            return(referenceUris.Where(d => projectBase.IsBaseOf(d)));
        }
Ejemplo n.º 6
0
 private static ProjectTemplateLink ToProjectTemplateLink(ProjectRewriteCacheEntry reference)
 {
     return(new ProjectTemplateLink(reference.RootTemplateNamespace, reference.RelativeVsTemplatePath, reference.OriginalAssemblyName));
 }