Example #1
0
        /// <summary>
        /// Generate the auto-documentation at the given output path.
        /// </summary>
        /// <param name="path">Path to which the file will be generated.</param>
        public void Generate(string path)
        {
            // This document instance will be used to write all of the input files'
            // documentation to a single document.
            Document   document = PdfWriter.CreateStandardDocument();
            PdfBuilder builder  = new PdfBuilder(document, options);

            // Read the file.
            Simulations rootNode = FileFormat.ReadFromFile <Simulations>(filePath, e => throw e, false);

            // Attempt to resolve the model path inside the file.
            IVariable variable = rootNode.FindByPath(modelPath);

            // Ensure that we found a model.
            object result = variable?.Value;
            IModel model  = result as IModel;

            if (variable == null)
            {
                throw new Exception($"Failed to resolve path {modelPath} in file {filePath}");
            }
            if (result == null)
            {
                throw new Exception($"When resolving path {modelPath} in file {filePath}: {modelPath} resolved to null");
            }
            if (model == null)
            {
                throw new Exception($"Attempted to read model from path {modelPath} in file {filePath}, but the path resolves to an object of type {result.GetType()}");
            }

            // Attempt to resolve links for the given model.
            rootNode.Links.Resolve(model, true, true, false);

            // Document the model.
            IEnumerable <ITag> tags = model.Document();

            // Document the rest of the file afterwards if necessary.
            if (documentRestOfFile)
            {
                tags = tags.AppendMany(rootNode.Document());
            }

            // Write tags to document.
            foreach (ITag tag in tags)
            {
                builder.Write(tag);
            }

            // Write bibliography at end of document.
            builder.WriteBibliography();

            // Write to PDF file at the specified path.
            string outFile = Path.Combine(path, OutputFileName);

            PdfWriter.Save(document, outFile);
        }