public async Task Output_before() { /* Given */ var md = @" before #include::xref://section:file.md "; var reader = new Pipe(); var writer = new Pipe(); var sut = new IncludeProcessor(xref => CreateContentItem("file.md", "included")); reader.Writer.Write(Encoding.UTF8.GetBytes(md)); await reader.Writer.FlushAsync(); await reader.Writer.CompleteAsync(); /* When */ await sut.Process(new IncludeProcessorContext(reader.Reader, writer.Writer)); /* Then */ await using var stream = new MemoryStream(); await writer.Reader.CopyToAsync(stream); stream.Position = 0; using var streamWriter = new StreamReader(stream); var actual = await streamWriter.ReadToEndAsync(); Assert.Equal(@" before included ", actual); }
// Generate a student grade report as a Word document. public void GenerateStudentReport(LocalStudent studentData, string reportPath) { // Ensure that the WordWrapper is disposed when the method finishes using (var wrapper = new WordWrapper()) { // Create a new Word document in memory wrapper.CreateBlankDocument(); // Add a heading to the document wrapper.AppendHeading(String.Format("Grade Report: {0} {1}", studentData.FirstName, studentData.LastName)); wrapper.InsertCarriageReturn(); wrapper.InsertCarriageReturn(); // Output the details of each grade for the student foreach (var grade in SessionContext.CurrentGrades) { // Use the IncludeProcessor to determine which fields in the Grade object are tagged List <FormatField> itemsToReport = IncludeProcessor.GetItemsToInclude(grade); // Output each tagged item, using the format specified by the properties of the IncludeInReport attribute for each item foreach (FormatField item in itemsToReport) { wrapper.AppendText(item.Label == string.Empty ? item.Value : item.Label + ": " + item.Value, item.IsBold, item.IsUnderlined); wrapper.InsertCarriageReturn(); } wrapper.InsertCarriageReturn(); } // Encrypt and save the Word document wrapper.EncryptAndSaveToDisk(reportPath); } }
public async Task Mixed_content_with_headers() { /* Given */ var md = @" # header #include::xref://src:DocsTool/Program.cs?f=Main "; var reader = new Pipe(); var writer = new Pipe(); var sut = new IncludeProcessor(xref => CreateContentItem("file.md", "included")); reader.Writer.Write(Encoding.UTF8.GetBytes(md)); await reader.Writer.FlushAsync(); await reader.Writer.CompleteAsync(); /* When */ await sut.Process(new IncludeProcessorContext(reader.Reader, writer.Writer)); /* Then */ await using var stream = new MemoryStream(); await writer.Reader.CopyToAsync(stream); stream.Position = 0; using var streamWriter = new StreamReader(stream); var actual = await streamWriter.ReadToEndAsync(); Assert.Equal(@" # header included ", actual); }
internal void Compile() { var fileName = _fileName; var device = _device; if (!File.Exists(fileName)) { throw new FileNotFoundException($"Effect file '{fileName}' is not found.", fileName); } var fileInfo = new FileInfo(fileName); using (var includeProcessor = new IncludeProcessor(fileInfo.DirectoryName)) { // SharpDX 当前(2016-04-04)使用的D3DCompiler版本为47,fx目标只支持 fx_5_0。 // 详见 https://msdn.microsoft.com/en-us/library/windows/desktop/hh446869.aspx 和 https://msdn.microsoft.com/en-us/library/windows/desktop/jj215820.aspx。 // 例如,使用 fx_4_0 的配置进行编译和设置,语法上没问题,但是无法创建 Effect。也就是说,D3DCompile2 是支持 fx_4_0 编译的,但是编译状态中有过时选项警告, // 导致能生成 bytecode(Bytecode 属性非空),但是 Effect 创建时抛出异常。 using (var compilationResult = ShaderBytecode.CompileFromFile(fileName, null, "fx_5_0", ShaderFlags.None, EffectFlags.None, null, includeProcessor)) { _dxEffect = new Effect(device, compilationResult.Bytecode, EffectFlags.None, fileName); } } }
public MarkdownProcessor( IReadOnlyDictionary <string, IReadOnlyList <Snippet> > snippets, IReadOnlyList <Include> includes, AppendSnippetGroupToMarkdown appendSnippetGroup, IReadOnlyList <string> snippetSourceFiles, int tocLevel, bool writeHeader, string rootDirectory, bool validateContent, string?header = null, IEnumerable <string>?tocExcludes = null) { Guard.AgainstNull(snippets, nameof(snippets)); Guard.AgainstNull(appendSnippetGroup, nameof(appendSnippetGroup)); Guard.AgainstNull(snippetSourceFiles, nameof(snippetSourceFiles)); Guard.AgainstNull(includes, nameof(includes)); Guard.AgainstEmpty(header, nameof(header)); Guard.AgainstNegativeAndZero(tocLevel, nameof(tocLevel)); Guard.AgainstNullAndEmpty(rootDirectory, nameof(rootDirectory)); rootDirectory = Path.GetFullPath(rootDirectory); this.snippets = snippets; this.appendSnippetGroup = appendSnippetGroup; this.writeHeader = writeHeader; this.validateContent = validateContent; this.header = header; this.tocLevel = tocLevel; if (tocExcludes == null) { this.tocExcludes = new List <string>(); } else { this.tocExcludes = tocExcludes.ToList(); } this.snippetSourceFiles = snippetSourceFiles .Select(x => x.Replace('\\', '/')) .ToList(); includeProcessor = new IncludeProcessor(includes, rootDirectory); }
internal void Compile() { var device = _device; if (_sourceIsText) { var textSource = _textSource; // https://github.com/hozuki/noire_history/blob/f74fa79d4cc6355d2561a7259663b52f69d7ee80/Noire.Graphics.D3D11/FX/EffectBase11.cs#L24-L27 using (var compilationResult = ShaderBytecode.Compile(textSource, null, "fx_5_0")) { if (compilationResult.HasErrors || compilationResult.Bytecode == null) { throw new SharpDXException(compilationResult.ResultCode, compilationResult.Message); } _effect = new Effect(device, compilationResult.Bytecode); } } else { var fileName = _textSource; fileName = Path.GetFullPath(fileName); if (!File.Exists(fileName)) { throw new FileNotFoundException($"Effect file '{fileName}' is not found.", fileName); } var fileInfo = new FileInfo(fileName); using (var includeProcessor = new IncludeProcessor(fileInfo.DirectoryName)) { using (var compilationResult = ShaderBytecode.CompileFromFile(fileName, null, "fx_5_0", ShaderFlags.None, EffectFlags.None, null, includeProcessor)) { if (compilationResult.HasErrors || compilationResult.Bytecode == null) { throw new SharpDXException(compilationResult.ResultCode, compilationResult.Message); } _effect = new Effect(device, compilationResult.Bytecode, EffectFlags.None, fileName); } } } }
public MarkdownProcessor( DocumentConvention convention, IReadOnlyDictionary <string, IReadOnlyList <Snippet> > snippets, IReadOnlyList <Include> includes, AppendSnippetsToMarkdown appendSnippets, IReadOnlyList <string> snippetSourceFiles, int tocLevel, bool writeHeader, string rootDirectory, bool validateContent, string?header = null, IEnumerable <string>?tocExcludes = null, string newLine = "\n") { Guard.AgainstNull(snippets, nameof(snippets)); Guard.AgainstNull(appendSnippets, nameof(appendSnippets)); Guard.AgainstNull(snippetSourceFiles, nameof(snippetSourceFiles)); Guard.AgainstNull(includes, nameof(includes)); Guard.AgainstNull(newLine, nameof(newLine)); Guard.AgainstEmpty(header, nameof(header)); Guard.AgainstNegativeAndZero(tocLevel, nameof(tocLevel)); Guard.AgainstNullAndEmpty(rootDirectory, nameof(rootDirectory)); if (convention == DocumentConvention.InPlaceOverwrite && writeHeader) { throw new SnippetException("WriteHeader is not allowed with InPlaceOverwrite convention."); } this.rootDirectory = Path.GetFullPath(rootDirectory).Replace('\\', '/'); if (Directory.Exists(rootDirectory)) { allFiles = Directory.EnumerateFiles(rootDirectory, "*.*", SearchOption.AllDirectories) .Select(x => x.Replace('\\', '/')) .ToList(); } else { allFiles = new List <string>(); } this.convention = convention; this.snippets = snippets; this.appendSnippets = appendSnippets; this.writeHeader = writeHeader; this.validateContent = validateContent; this.newLine = newLine; this.header = header; this.tocLevel = tocLevel; if (tocExcludes == null) { this.tocExcludes = new List <string>(); } else { this.tocExcludes = tocExcludes.ToList(); } this.snippetSourceFiles = snippetSourceFiles .Select(x => x.Replace('\\', '/')) .ToList(); includeProcessor = new IncludeProcessor(convention, includes, rootDirectory, allFiles); }
public async Task Process_full_example() { /* Given */ var md = @"## Syntax ### Include csharp code snippets #### Include file ```markdown \#include::xref://src:DocsTool/Program.cs ``` ```csharp #include::xref://src:DocsTool/Program.cs ``` #### Include function ```markdown \#include::xref://src:DocsTool/Program.cs?f=Main ``` ```csharp #include::xref://src:DocsTool/Program.cs?f=Main ``` "; var reader = new Pipe(); var writer = new Pipe(); var sut = new IncludeProcessor(xref => CreateContentItem("file.md", "included")); reader.Writer.Write(Encoding.UTF8.GetBytes(md)); await reader.Writer.FlushAsync(); await reader.Writer.CompleteAsync(); /* When */ await sut.Process(new IncludeProcessorContext(reader.Reader, writer.Writer)); /* Then */ await using var stream = new MemoryStream(); await writer.Reader.CopyToAsync(stream); stream.Position = 0; using var streamWriter = new StreamReader(stream); var actual = await streamWriter.ReadToEndAsync(); Assert.Equal(@"## Syntax ### Include csharp code snippets #### Include file ```markdown \#include::xref://src:DocsTool/Program.cs ``` ```csharp included ``` #### Include function ```markdown \#include::xref://src:DocsTool/Program.cs?f=Main ``` ```csharp included ``` ", actual); }