Entry point for document generation. Setup your generation environment using the right constructor and run the process with Generate() method.
示例#1
0
        public void FullGeneration(string templateFileName, string expectedHtmlFileName, string expectedPdfFileName, string generatedHtmlFileName, string generatedPdfFileName)
        {
            // Perform generation
            GenerationError[] errors = new ProjbookEngine("../../Projbook.Tests.csproj", "Resources/FullGeneration/" + templateFileName, "Resources/testConfig.json", ".").Generate();

            // Read expected ouput
            string expectedContent = this.LoadFile("Resources/FullGeneration/" + expectedHtmlFileName);

            // Read expected ouput
            string expectedPdfContent = this.LoadFile("Resources/FullGeneration/" + expectedPdfFileName);

            // Read generated ouput
            string generatedContent = this.LoadFile(generatedHtmlFileName);

            // Read generated pdf ouput
            string generatedPdfContent = this.LoadFile(generatedPdfFileName);

            // Remove line return for cross platform platform testing
            expectedContent = expectedContent.Replace("\r", string.Empty).Replace("\n", string.Empty);
            expectedPdfContent = expectedPdfContent.Replace("\r", string.Empty).Replace("\n", string.Empty);
            generatedContent = generatedContent.Replace("\r", string.Empty).Replace("\n", string.Empty);
            generatedPdfContent = generatedPdfContent.Replace("\r", string.Empty).Replace("\n", string.Empty);

            // Assert result
            Assert.IsNotNull(errors);
            Assert.AreEqual(0, errors.Length);
            Assert.AreEqual(expectedContent, generatedContent);
            Assert.AreEqual(expectedPdfContent, generatedPdfContent);
        }
        public void FullGenerationErrorInPdfTemplate(string templateFileName, string errorFile)
        {
            // Perform generation
            GenerationError[] errors = new ProjbookEngine("../../Projbook.Tests.csproj", "Resources/FullGeneration/" + templateFileName, "Resources/testConfig.json", ".").Generate();

            // Assert result
            Assert.IsNotNull(errors);
            Assert.AreEqual(1, errors.Length);
            Assert.IsTrue(errors[0].SourceFile.EndsWith(errorFile));
            Assert.AreEqual(@"Error during PDF generation: (17:4) - Encountered end tag ""Anchors"" with no matching start tag.  Are your start/end tags properly balanced?", errors[0].Message);
        }
示例#3
0
        public void FullGenerationErrorInConfiguration(string configFile, string errorMessage)
        {
            // Perform generation
            GenerationError[] errors = new ProjbookEngine("../../Projbook.Tests.csproj", "Resources/FullGeneration/testTemplate.txt", "Resources/" + configFile, ".").Generate();

            // Assert result
            Assert.IsNotNull(errors);
            Assert.AreEqual(1, errors.Length);
            Assert.IsTrue(errors[0].SourceFile.EndsWith(configFile));
            Console.WriteLine(errors[0].Message);
            Assert.IsTrue(errors[0].Message.StartsWith(errorMessage));
        }
示例#4
0
        /// <summary>
        /// Trigger task execution.
        /// </summary>
        /// <returns>True if the task succeeded.</returns>
        public override bool Execute()
        {
            // Run generation
            ProjbookEngine projbookEngine = new ProjbookEngine(this.ProjectPath, this.TemplateFile, this.ConfigurationFile, this.OutputDirectory);
            GenerationError[] errors = projbookEngine.Generate();

            // Report generation errors
            foreach (GenerationError error in errors)
            {
                this.Log.LogError(string.Empty, string.Empty, string.Empty, error.SourceFile, -1, -1, -1, -1, error.Message);
            }

            // Return output
            return errors.Length <= 0;
        }
示例#5
0
        /// <summary>
        /// Trigger task execution.
        /// </summary>
        /// <returns>True if the task succeeded.</returns>
        public override bool Execute()
        {
            // Load configuration
            FileSystem fileSystem = new FileSystem();
            ConfigurationLoader configurationLoader = new ConfigurationLoader(fileSystem);
            IndexConfiguration indexConfiguration;
            try
            {
                indexConfiguration = configurationLoader.Load(fileSystem.Path.GetDirectoryName(this.ProjectPath), this.ConfigurationFile);
            }
            catch (ConfigurationException configurationException)
            {
                // Report generation errors
                this.ReportErrors(configurationException.GenerationErrors);
                return false;
            }
            catch (Exception exception)
            {
                this.Log.LogError(string.Empty, string.Empty, string.Empty, this.ConfigurationFile, 0, 0, 0, 0, string.Format("Error during loading configuration: {0}", exception.Message));
                return false;
            }

            // Parse compilation symbols
            string[] compilationSymbols = new string[0];
            if (!string.IsNullOrWhiteSpace(this.CompilationSymbols))
            {
                compilationSymbols = this.CompilationSymbols
                    .Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(x => x.Trim()).ToArray();
            }

            // Instantiate a ProjBook engine
            ProjbookEngine projbookEngine = new ProjbookEngine(fileSystem, this.ProjectPath, this.ExtensionPath, indexConfiguration, this.OutputDirectory, compilationSymbols.Contains(NOPDF_SYMBOL));

            // Run generation
            bool success = true;
            GenerationError[] errors = projbookEngine.GenerateAll();

            // Report generation errors
            this.ReportErrors(errors);

            // Stop processing in case of error
            if (errors.Length > 0)
                success = false;

            return success;
        }
示例#6
0
        public void FullGeneration(string configFileName, string expectedHtmlFileName, string expectedHtmlIndexFileName, string expectedPdfFileName, string generatedHtmlFileName, string generatedHtmlIndexFileName, string generatedPdfFileName, bool readOnly)
        {
            // Process path separator
            configFileName = configFileName.Replace('/', this.FileSystem.Path.DirectorySeparatorChar);
            expectedHtmlFileName = expectedHtmlFileName.Replace('/', this.FileSystem.Path.DirectorySeparatorChar);
            expectedPdfFileName = expectedPdfFileName.Replace('/', this.FileSystem.Path.DirectorySeparatorChar);
            expectedHtmlIndexFileName = expectedHtmlIndexFileName.Replace('/', this.FileSystem.Path.DirectorySeparatorChar);

            // Prepare configuration
            IndexConfiguration indexConfiguration = new ConfigurationLoader(this.FileSystem).Load(".", configFileName);
            Configuration[] configurations = indexConfiguration.Configurations;
            Configuration configuration = configurations[0];
            string htmlTemplatePath = configuration.TemplateHtml;
            string pdfTemplatePath = configuration.TemplatePdf;
            string firstPagePath = new FileInfo(configuration.Pages.First().Path).FullName;

            // Retrieve attribute of html template
            FileAttributes? htmlTemplateFileAttributes = null;
            if (this.FileSystem.File.Exists(htmlTemplatePath))
            {
                htmlTemplateFileAttributes = this.FileSystem.File.GetAttributes(htmlTemplatePath);
            }

            // Retrieve attribute of pdf template
            FileAttributes? pdfTemplateFileAttributes = null;
            if (this.FileSystem.File.Exists(pdfTemplatePath))
            {
                pdfTemplateFileAttributes = this.FileSystem.File.GetAttributes(pdfTemplatePath);
            }

            // Retrieve attribute of the first markdown page
            FileAttributes? firstPageFileAttributes = null;
            if (this.FileSystem.File.Exists(firstPagePath))
            {
                firstPageFileAttributes = this.FileSystem.File.GetAttributes(firstPagePath);
            }

            // Make the file read only
            if (readOnly)
            {
                if (null != htmlTemplateFileAttributes)
                {
                    this.FileSystem.File.SetAttributes(htmlTemplatePath, htmlTemplateFileAttributes.Value | FileAttributes.ReadOnly);
                }
                if (null != pdfTemplateFileAttributes)
                {
                    this.FileSystem.File.SetAttributes(pdfTemplatePath, pdfTemplateFileAttributes.Value | FileAttributes.ReadOnly);
                }
                if (null != firstPageFileAttributes)
                {
                    this.FileSystem.File.SetAttributes(firstPagePath, firstPageFileAttributes.Value | FileAttributes.ReadOnly);
                }
            }

            // Execute test
            try
            {
                // Ensure right working directory
                Environment.CurrentDirectory = Path.GetDirectoryName(typeof(FullGenerationTests).Assembly.Location);

                // Execute generation
                GenerationError[] errors = new ProjbookEngine(this.FileSystem, this.FileSystem.Path.Combine(".", "Project.csproj"), this.ExtensionDirectory.FullName, indexConfiguration, ".", false).GenerateAll();

                // Read expected output
                string expectedContent = string.IsNullOrWhiteSpace(expectedHtmlFileName) ? string.Empty : this.FileSystem.File.ReadAllText(expectedHtmlFileName);

                // Read expected output for index
                string expectedIndexContent = string.IsNullOrWhiteSpace(expectedHtmlIndexFileName) ? string.Empty : this.FileSystem.File.ReadAllText(expectedHtmlIndexFileName);

                // Read expected output
                string expectedPdfContent = string.IsNullOrWhiteSpace(expectedPdfFileName) ? string.Empty : this.FileSystem.File.ReadAllText(expectedPdfFileName);

                // Read generated output
                string generatedContent = !this.FileSystem.File.Exists(generatedHtmlFileName) ? string.Empty : this.FileSystem.File.ReadAllText(generatedHtmlFileName);

                // Read generated output for index
                string generatedIndexContent = !this.FileSystem.File.Exists(generatedHtmlIndexFileName) ? string.Empty : this.FileSystem.File.ReadAllText(generatedHtmlIndexFileName);

                // Read generated pdf ouput
                string generatedPdfContent = !this.FileSystem.File.Exists(generatedPdfFileName) ? string.Empty : this.FileSystem.File.ReadAllText(generatedPdfFileName);

                // Remove line return for cross platform platform testing
                expectedContent = expectedContent.Replace("\r", string.Empty).Replace("\n", string.Empty);
                expectedIndexContent = expectedIndexContent.Replace("\r", string.Empty).Replace("\n", string.Empty);
                expectedPdfContent = expectedPdfContent.Replace("\r", string.Empty).Replace("\n", string.Empty);
                generatedContent = generatedContent.Replace("\r", string.Empty).Replace("\n", string.Empty);
                generatedIndexContent = generatedIndexContent.Replace("\r", string.Empty).Replace("\n", string.Empty);
                generatedPdfContent = generatedPdfContent.Replace("\r", string.Empty).Replace("\n", string.Empty);

                // Assert result
                Assert.IsNotNull(errors);
                Assert.AreEqual(0, errors.Length);
                Assert.AreEqual(expectedContent, generatedContent);
                Assert.AreEqual(expectedIndexContent, generatedIndexContent);
                Assert.AreEqual(expectedPdfContent, generatedPdfContent);

            #if !NOPDF
                Assert.AreEqual(configuration.GeneratePdf, this.FileSystem.File.Exists(this.FileSystem.Path.ChangeExtension(configuration.OutputPdf, "pdf")));
            #endif
            }
            finally
            {
                if (readOnly)
                {
                    if (null != htmlTemplateFileAttributes)
                    {
                        this.FileSystem.File.SetAttributes(htmlTemplatePath, htmlTemplateFileAttributes.Value);
                    }
                    if (null != pdfTemplateFileAttributes)
                    {
                        this.FileSystem.File.SetAttributes(pdfTemplatePath, pdfTemplateFileAttributes.Value);
                    }
                    if (null != firstPageFileAttributes)
                    {
                        this.FileSystem.File.SetAttributes(firstPagePath, firstPageFileAttributes.Value);
                    }
                }
            }
        }
示例#7
0
        public void FullGenerationUnexistingMembers()
        {
            // Perform generation
            IndexConfiguration indexConfiguration = new ConfigurationLoader(this.FileSystem).Load(".", this.FileSystem.Path.Combine("Config", "MissingMembersInPage.json"));
            Configuration[] configurations = indexConfiguration.Configurations;
            GenerationError[] errors = new ProjbookEngine(this.FileSystem, this.FileSystem.Path.Combine(".", "Project.csproj"), this.ExtensionDirectory.FullName, indexConfiguration, ".", false).GenerateAll();

            // Assert result
            Assert.IsNotNull(errors);
            Assert.AreEqual(3, errors.Length);
            Assert.AreEqual("Cannot find member: NotFound", errors[0].Message);
            Assert.AreEqual(1, errors[0].Line);
            Assert.AreEqual(27, errors[0].Column);
            Assert.AreEqual("Cannot find member: NotFound", errors[1].Message);
            Assert.AreEqual(7, errors[1].Line);
            Assert.AreEqual(27, errors[1].Column);
            Assert.IsTrue(errors[2].Message.StartsWith("Cannot find target 'Source/NotFound.cs' in any referenced project"));
            Assert.AreEqual(13, errors[2].Line);
            Assert.AreEqual(12, errors[2].Column);
        }
示例#8
0
        public void FullGenerationErrorTemplate()
        {
            // Perform generation
            IndexConfiguration indexConfiguration = new ConfigurationLoader(this.FileSystem).Load(".", this.FileSystem.Path.Combine("Config", "ErrorInHtml.json"));
            Configuration[] configurations = indexConfiguration.Configurations;
            GenerationError[] errors = new ProjbookEngine(this.FileSystem, "Project.csproj", this.ExtensionDirectory.FullName, indexConfiguration, ".", false).GenerateAll();

            // Assert result
            Assert.IsNotNull(errors);
            Assert.AreEqual(2, errors.Length);
            Assert.IsTrue(errors[0].SourceFile.EndsWith("Template/Malformated.txt".Replace('/', this.FileSystem.Path.DirectorySeparatorChar)));
            Assert.IsTrue(errors[1].SourceFile.EndsWith("Template/Malformated.txt".Replace('/', this.FileSystem.Path.DirectorySeparatorChar)));
            Assert.AreEqual(@"Error during HTML generation: (16:1) - Encountered end tag ""Sections"" with no matching start tag.  Are your start/end tags properly balanced?", errors[0].Message);
            Assert.AreEqual(16, errors[0].Line);
            Assert.AreEqual(1, errors[0].Column);
            Assert.AreEqual(@"Error during PDF generation: (16:1) - Encountered end tag ""Sections"" with no matching start tag.  Are your start/end tags properly balanced?", errors[1].Message);
            Assert.AreEqual(16, errors[1].Line);
            Assert.AreEqual(1, errors[1].Column);
        }