private void GenerateXamlFile(string xamlFile) { var projectSourceFolder = Path.GetDirectoryName(ProjectFilePath); if (!Path.IsPathRooted(xamlFile)) { xamlFile = Path.Combine(Path.GetDirectoryName(ProjectFilePath), xamlFile); } xamlFile = Path.GetFullPath(xamlFile); var sourceXmlFile = xamlFile; if (!File.Exists(sourceXmlFile)) { return; } var relativePath = Paths.MakeRelativeToFolder(sourceXmlFile, projectSourceFolder); relativePath = relativePath.Replace("..", "parent"); var destinationHtmlFile = Path.Combine(ProjectDestinationFolder, relativePath) + ".html"; var xamlSupport = new XamlSupport(this); xamlSupport.GenerateXaml(sourceXmlFile, destinationHtmlFile, relativePath); OtherFiles.Add(relativePath); AddDeclaredSymbolToRedirectMap(SymbolIDToListOfLocationsMap, SymbolIdService.GetId(relativePath), relativePath, 0); }
/// <summary> /// コンストラクタ /// </summary> /// <param name="target">セマンティックモデル</param> /// <param name="container">イベントコンテナ</param> public FileRoot(SemanticModel target, EventContainer container) { // ファイルパス取得 FilePath = target.SyntaxTree.FilePath; // 外部参照イベント登録 container.Register <OtherFileReferenced>(this, (ev) => { if (!OtherFiles.ContainsKey(ev.ClassName)) { OtherFiles.Add(ev.ClassName, ev.FilePath); } }); // 解析処理 var rootNode = target.SyntaxTree.GetRoot().ChildNodes().Where(syntax => syntax.IsKind(SyntaxKind.NamespaceDeclaration)).First(); foreach (var item in (rootNode as NamespaceDeclarationSyntax).Members) { var memberResult = ItemFactory.Create(item, target, container); if (memberResult != null) { Members.Add(memberResult); } } // 外部参照イベント登録解除 container.Unregister <OtherFileReferenced>(this); }
private void GenerateProjectFile() { var projectExtension = Path.GetExtension(ProjectFilePath); if (!File.Exists(ProjectFilePath) || ".dll".Equals(projectExtension, StringComparison.OrdinalIgnoreCase) || ".winmd".Equals(projectExtension, StringComparison.OrdinalIgnoreCase)) { return; } ProjectCollection projectCollection = null; try { var title = Path.GetFileName(ProjectFilePath); var destinationFileName = Path.Combine(ProjectDestinationFolder, title) + ".html"; AddDeclaredSymbolToRedirectMap(SymbolIDToListOfLocationsMap, SymbolIdService.GetId(title), title, 0); // ProjectCollection caches the environment variables it reads at startup // and doesn't re-get them later. We need a new project collection to read // the latest set of environment variables. projectCollection = new ProjectCollection(); this.msbuildProject = new Project( ProjectFilePath, null, null, projectCollection, ProjectLoadSettings.IgnoreMissingImports); var msbuildSupport = new MSBuildSupport(this); msbuildSupport.Generate(ProjectFilePath, destinationFileName, msbuildProject, true); GenerateXmlFiles(msbuildProject); GenerateXamlFiles(msbuildProject); GenerateResxFiles(msbuildProject); GenerateTypeScriptFiles(msbuildProject); OtherFiles.Add(title); } catch (Exception ex) { Log.Exception("Exception during Project file generation: " + ProjectFilePath + "\r\n" + ex.ToString()); } finally { if (projectCollection != null) { projectCollection.UnloadAllProjects(); projectCollection.Dispose(); } } }
private string AddOtherFileRelativeToProject(string filePath) { var relativePath = Paths.MakeRelativeToFile(filePath, ProjectFilePath); relativePath = relativePath.Replace("..", "parent"); OtherFiles.Add(relativePath); return(relativePath); }
private void AddHtmlFilesToRedirectMap() { var files = Directory .GetFiles(ProjectDestinationFolder, "*.html", SearchOption.AllDirectories); foreach (var file in files) { var relativePath = file.Substring(ProjectDestinationFolder.Length + 1).Replace('\\', '/'); relativePath = relativePath.Substring(0, relativePath.Length - 5); // strip .html AddFileToRedirectMap(relativePath); OtherFiles.Add(relativePath); } }
private void GenerateTypeScriptFile(string filePath) { var projectSourceFolder = Path.GetDirectoryName(ProjectFilePath); if (!Path.IsPathRooted(filePath)) { filePath = Path.Combine(Path.GetDirectoryName(ProjectFilePath), filePath); } SolutionGenerator.AddTypeScriptFile(filePath); var relativePath = Paths.MakeRelativeToFile(filePath, ProjectFilePath); relativePath = relativePath.Replace("..", "parent"); OtherFiles.Add(relativePath); }
public async Task Generate() { try { if (string.IsNullOrEmpty(ProjectFilePath)) { Log.Exception("ProjectFilePath is empty: " + Project.ToString()); return; } ProjectDestinationFolder = GetProjectDestinationPath(Project, SolutionGenerator.SolutionDestinationFolder); if (ProjectDestinationFolder == null) { Log.Exception("Errors evaluating project: " + Project.Id); return; } Log.Write(ProjectDestinationFolder, ConsoleColor.DarkCyan); if (SolutionGenerator.SolutionSourceFolder is string solutionFolder) { ProjectSourcePath = Paths.MakeRelativeToFolder(ProjectFilePath, solutionFolder); } else { ProjectSourcePath = ProjectFilePath; } if (File.Exists(Path.Combine(ProjectDestinationFolder, Constants.DeclaredSymbolsFileName + ".txt"))) { // apparently someone already generated a project with this assembly name - their assembly wins Log.Exception(string.Format( "A project with assembly name {0} was already generated, skipping current project: {1}", this.AssemblyName, this.ProjectFilePath), isSevere: false); return; } if (Configuration.CreateFoldersOnDisk) { Directory.CreateDirectory(ProjectDestinationFolder); } var documents = Project.Documents.Where(IncludeDocument).ToList(); var generationTasks = Partitioner.Create(documents) .GetPartitions(Environment.ProcessorCount) .Select(partition => Task.Run(async() => { using (partition) { while (partition.MoveNext()) { await GenerateDocument(partition.Current); } } })); await Task.WhenAll(generationTasks); foreach (var document in documents) { OtherFiles.Add(Paths.GetRelativeFilePathInProject(document)); } if (Configuration.WriteProjectAuxiliaryFilesToDisk) { GenerateProjectFile(); GenerateDeclarations(); GenerateBaseMembers(); GenerateImplementedInterfaceMembers(); GenerateProjectInfo(); GenerateReferencesDataFiles( this.SolutionGenerator.SolutionDestinationFolder, ReferencesByTargetAssemblyAndSymbolId); GenerateSymbolIDToListOfDeclarationLocationsMap( ProjectDestinationFolder, SymbolIDToListOfLocationsMap); GenerateReferencedAssemblyList(); GenerateUsedReferencedAssemblyList(); GenerateProjectExplorer(); GenerateNamespaceExplorer(); GenerateIndex(); } var compilation = Project.GetCompilationAsync().Result; var diagnostics = compilation.GetDiagnostics().Select(d => d.ToString()).ToArray(); if (diagnostics.Length > 0) { var diagnosticsTxt = Path.Combine(this.ProjectDestinationFolder, "diagnostics.txt"); File.WriteAllLines(diagnosticsTxt, diagnostics); } } catch (Exception ex) { Log.Exception(ex, "Project generation failed for: " + ProjectSourcePath); } }