/// <summary>
        /// Exports the full contained documentation.
        /// </summary>
        public override void Export()
        {
            // we do not need the temp staging folder with this export so write direct from temp to publish.

            try
            {
                PrepareForExport();

                // calculate the export steps
                int numberOfSteps = 0;
                numberOfSteps += 1;                                                    // toc and index steps
                numberOfSteps += Document.Map.Count;                                   // top level entries for recursive export
                numberOfSteps += 1;                                                    // output files
                numberOfSteps += ((Document.Map.NumberOfEntries / XmlExportStep) * 3); // xml export stage
                numberOfSteps += 1;                                                    // cleanup files

                OnExportCalculated(new ExportCalculatedEventArgs(numberOfSteps));
                CurrentExportStep = 1;

                ExportContentAsXml();
                ConvertXmlToWebsite();

                // clean up the temp directory
                OnExportStep(new ExportStepEventArgs("Cleaning up", ++CurrentExportStep));
                Cleanup();
            }
            catch (Exception ex)
            {
                Cleanup(); // attempt to clean up our mess before dying
                ExportException exception = new ExportException(ex.Message, ex);
                OnExportException(new ExportExceptionEventArgs(exception));
            }
        }
Exemple #2
0
        /// <summary>
        /// Exports the <paramref name="current"/> entry to intermediate XML format.
        /// </summary>
        /// <include file='../code-documentation/exporter.xml' path='docs/exporter[@name="export"]'/>
        protected virtual string Export(Entry current)
        {
            string filename = string.Format("{0}{1}{2}.xml",
                                            this.TempDirectory,
                                            current.Key,
                                            string.IsNullOrEmpty(current.SubKey) ? string.Empty : "-" + this.IllegalFileCharacters.Replace(current.SubKey, string.Empty)
                                            );

            try
            {
                Rendering.XmlRenderer r = Rendering.XmlRenderer.Create(current, Document);

                if (null == r)
                {
                    ExportExceptions.Add(new Exception($"No XML renderer for the Entry {current.Name}"));
                }

                using (System.Xml.XmlWriter writer = XmlWriter.Create(filename))
                {
                    r.Render(writer);
                }
            }
            catch (Exception ex)
            {
                if (_fileSystem.FileExists(filename))
                {
                    _fileSystem.DeleteFile(filename);
                }

                // ignore it and add it to the list of exceptions, try and add more details
                if (current != null)
                {
                    ExportException issue = new ExportException(
                        $"Failed to export member '{current.Name}'.",
                        ex);
                    ex = issue;
                }

                ExportExceptions.Add(ex);
            }

            return(filename);
        }
Exemple #3
0
        /// <summary>
        /// Exports the documentation as HTML Help 1 compiled help.
        /// </summary>
        public override void Export()
        {
            if (!FindHtmlHelpCompiler())
            {
                OnExportFailed(new ExportFailedEventArgs("The HTML Help 1 compiler could not be located, please check that it is installed."));
                return; // can not continue
            }

            try
            {
                PrepareForExport();

                // calculate the export steps
                int numberOfSteps = 0;
                numberOfSteps += 1;                                                    // toc and index steps
                numberOfSteps += Document.Map.Count;                                   // top level entries for recursive export
                numberOfSteps += 1;                                                    // output files
                numberOfSteps += ((Document.Map.NumberOfEntries / XmlExportStep) * 3); // xml export stage
                numberOfSteps += 1;                                                    // publish files
                numberOfSteps += 1;                                                    // cleanup files

                OnExportCalculated(new ExportCalculatedEventArgs(numberOfSteps));
                CurrentExportStep = 1;

                if (!IsCancelled)
                {
                    // export the document map
                    OnExportStep(new ExportStepEventArgs("Export as XML...", ++CurrentExportStep));
                    using (XmlWriter writer = XmlWriter.Create(string.Format("{0}/toc.xml", TempDirectory)))
                    {
                        Rendering.DocumentMapXmlRenderer map = new Rendering.DocumentMapXmlRenderer(
                            Document.Map
                            );
                        map.Render(writer);
                    }

                    // export the project xml
                    ProjectXmlRenderer projectXml = new ProjectXmlRenderer(Document.Map);
                    using (XmlWriter writer = XmlWriter.Create(string.Format("{0}/project.xml", TempDirectory)))
                    {
                        projectXml.Render(writer);
                    }

                    // export the index xml
                    IndexXmlRenderer indexXml = new IndexXmlRenderer(Document.Map);
                    using (XmlWriter writer = XmlWriter.Create(string.Format("{0}/index.xml", TempDirectory)))
                    {
                        indexXml.Render(writer);
                    }

                    // export each of the members
                    foreach (Entry current in Document.Map)
                    {
                        RecursiveEntryExport(current);
                        OnExportStep(new ExportStepEventArgs("Export as XML...", ++CurrentExportStep));
                        if (IsCancelled)
                        {
                            break;
                        }
                    }
                    GC.Collect();
                }

                if (!IsCancelled)
                {
                    List <Task>    conversionTasks = new List <Task>();
                    IXsltProcessor xsltProcessor   = new MsXsltProcessor(TempDirectory);

                    using (Stream xsltStream = Config.GetXslt())
                    {
                        xsltProcessor.CompileXslt(xsltStream);
                    }

                    // set output files
                    OnExportStep(new ExportStepEventArgs("Saving output files...", ++CurrentExportStep));
                    Config.SaveOutputFilesTo(OutputDirectory);

                    OnExportStep(new ExportStepEventArgs("Transforming XML...", ++CurrentExportStep));

                    // export the project file
                    string inputFile  = $"{TempDirectory}/project.xml";
                    string outputFile = OutputDirectory + "project.hhp";
                    conversionTasks.Add(xsltProcessor.TransformAsync(inputFile, outputFile));

                    // export the index file
                    inputFile  = $"{TempDirectory}/index.xml";
                    outputFile = OutputDirectory + "index.hhk";
                    conversionTasks.Add(xsltProcessor.TransformAsync(inputFile, outputFile));

                    // export the content file
                    inputFile  = $"{TempDirectory}/toc.xml";
                    outputFile = OutputDirectory + "toc.hhc";
                    conversionTasks.Add(xsltProcessor.TransformAsync(inputFile, outputFile));

                    // export the content files
                    int      counter = 0;
                    string[] exclude = { "toc.xml", "index.xml", "project.xml" };
                    foreach (string current in Directory.GetFiles(TempDirectory))
                    {
                        if (exclude.Contains(current.Substring(TempDirectory.Length)))
                        {
                            continue;
                        }

                        outputFile = OutputDirectory + Path.GetFileNameWithoutExtension(current) + ".htm";
                        conversionTasks.Add(xsltProcessor.TransformAsync(current, outputFile).ContinueWith(
                                                (Task outer) =>
                        {
                            counter++;
                            if (counter % XmlExportStep == 0)
                            {
                                OnExportStep(new ExportStepEventArgs("Transforming XML...", CurrentExportStep += 3));
                            }
                        }
                                                ));

                        if (IsCancelled)
                        {
                            break;
                        }
                    }

                    Task.WaitAll(conversionTasks.ToArray());
                }

                if (!IsCancelled)
                {
                    // compile the html help file
                    OnExportStep(new ExportStepEventArgs("Compiling help...", ++CurrentExportStep));
                    CompileHelp(OutputDirectory + "project.hhp");

                    // publish the compiled help file
                    OnExportStep(new ExportStepEventArgs("Publishing help...", ++CurrentExportStep));
                    File.Copy(OutputDirectory + "project.chm", PublishDirectory + "documentation.chm");
                }

                // clean up the temp directory
                OnExportStep(new ExportStepEventArgs("Cleaning up", ++CurrentExportStep));
                Cleanup();
            }
            catch (Exception ex)
            {
                Cleanup(); // attempt to clean up our mess before dying
                ExportException exception = new ExportException(ex.Message, ex);
                OnExportException(new ExportExceptionEventArgs(exception));
            }
        }
Exemple #4
0
        /// <summary>
        /// Performs the export to HTML Help 2.
        /// </summary>
        public override void Export()
        {
            if (!FindHtmlHelpCompiler())
            {
                OnExportFailed(new ExportFailedEventArgs("The HTML Help 2 compiler could not be located, please check that it is installed."));
                return; // can not continue
            }

            try
            {
                PrepareForExport();

                // calculate the export steps
                int numberOfSteps = 0;
                numberOfSteps += 1;                                                    // toc and index steps
                numberOfSteps += Document.Map.Count;                                   // top level entries for recursive export
                numberOfSteps += 1;                                                    // output files
                numberOfSteps += ((Document.Map.NumberOfEntries / XmlExportStep) * 3); // xml export stage
                numberOfSteps += 1;                                                    // publish files
                numberOfSteps += 1;                                                    // cleanup files

                OnExportCalculated(new ExportCalculatedEventArgs(numberOfSteps));
                CurrentExportStep = 1;

                if (!IsCancelled)
                {
                    // export the document map
                    OnExportStep(new ExportStepEventArgs("Export as XML...", ++CurrentExportStep));
                    using (XmlWriter writer = XmlWriter.Create(string.Format("{0}/toc.xml", TempDirectory)))
                    {
                        Rendering.DocumentMapXmlRenderer map = new Rendering.DocumentMapXmlRenderer(
                            Document.Map
                            );
                        map.Render(writer);
                    }

                    // export each of the members
                    foreach (Entry current in Document.Map)
                    {
                        RecursiveEntryExport(current);
                        OnExportStep(new ExportStepEventArgs("Export as XML...", ++CurrentExportStep));
                        if (IsCancelled)
                        {
                            break;
                        }
                    }
                    GC.Collect();
                }

                if (!IsCancelled)
                {
                    List <Task>    conversionTasks = new List <Task>();
                    IXsltProcessor xsltProcessor   = new MsXsltProcessor(TempDirectory);

                    using (Stream xsltStream = Config.GetXslt())
                    {
                        xsltProcessor.CompileXslt(xsltStream);
                    }

                    // set output files
                    OnExportStep(new ExportStepEventArgs("Saving output files...", ++CurrentExportStep));
                    Config.SaveOutputFilesTo(OutputDirectory);

                    OnExportStep(new ExportStepEventArgs("Transforming XML...", ++CurrentExportStep));

                    // export the project xml, we cant render the XML because the DTD protocol causes loads of probs with Saxon
                    CollectionXmlRenderer collectionXml = new CollectionXmlRenderer(Document.Map, string.Empty);
                    using (XmlWriter writer = XmlWriter.Create(string.Format("{0}/Documentation.HxC", OutputDirectory)))
                    {
                        collectionXml.Render(writer);
                    }

                    // export the incldue file xml
                    IncludeFileXmlRenderer includeXml = new IncludeFileXmlRenderer(Config);
                    using (XmlWriter writer = XmlWriter.Create(string.Format("{0}/Documentation.HxF", OutputDirectory)))
                    {
                        includeXml.Render(writer);
                    }

                    string outputFile = OutputDirectory + "Documentation.HxT";
                    string inputFile  = $"{TempDirectory}/toc.xml";
                    conversionTasks.Add(xsltProcessor.TransformAsync(inputFile, outputFile));

                    // export the content files
                    int counter = 0;
                    foreach (string current in Directory.GetFiles(TempDirectory))
                    {
                        if (current.Substring(TempDirectory.Length) == "toc.xml")
                        {
                            continue;
                        }

                        outputFile = OutputDirectory + Path.GetFileNameWithoutExtension(current) + ".htm";
                        conversionTasks.Add(xsltProcessor.TransformAsync(current, outputFile).ContinueWith(
                                                (Task outer) =>
                        {
                            counter++;
                            if (counter % XmlExportStep == 0)
                            {
                                OnExportStep(new ExportStepEventArgs("Transforming XML...", CurrentExportStep += 3));
                            }
                        }
                                                ));

                        if (IsCancelled)
                        {
                            break;
                        }
                    }

                    Task.WaitAll(conversionTasks.ToArray());
                }

                if (!IsCancelled)
                {
                    // compile the html help file
                    OnExportStep(new ExportStepEventArgs("Compiling help...", ++CurrentExportStep));
                    CompileHelp(OutputDirectory + "/Documentation.HxC");

                    // publish the help
                    OnExportStep(new ExportStepEventArgs("Publishing help...", ++CurrentExportStep));
                    string[] files =
                    {
                        "Documentation.HxC",          "Documentation.HxF",   "Documentation.HxT",   "Documentation.HxS",
                        "Documentation_A.HxK",        "Documentation_B.HxK", "Documentation_F.HxK", "Documentation_K.HxK",
                        "Documentation_NamedUrl.HxK", "Documentation_S.HxK", "stopwords.txt"
                    };
                    for (int i = 0; i < files.Length; i++)
                    {
                        string from = Path.Combine(OutputDirectory, files[i]);

                        if (!File.Exists(from))
                        {
                            continue;
                        }
                        File.Move(
                            from,
                            Path.Combine(PublishDirectory, files[i])
                            );;
                    }
                }

                // clean up the temp directory
                OnExportStep(new ExportStepEventArgs("Cleaning up", ++CurrentExportStep));
                Cleanup();
            }
            catch (Exception ex)
            {
                Cleanup(); // attempt to clean up our mess before dying
                ExportException exception = new ExportException(ex.Message, ex);
                OnExportException(new ExportExceptionEventArgs(exception));
            }
        }
        /// <summary>
        /// Exports the full contained documentation.
        /// </summary>
        public override void Export()
        {
            // we do not need the temp staging folder with this export so write direct from temp to publish.
            try
            {
                this.PrepareForExport();

                // calculate the export steps
                int numberOfSteps = 0;
                numberOfSteps += 1;                                 // toc and index steps
                numberOfSteps += this.Document.Map.Count;           // top level entries for recursive export
                numberOfSteps += 1;                                 // output files
                numberOfSteps += this.Document.Map.NumberOfEntries; // xml export stage
                numberOfSteps += 1;                                 // cleanup files

                this.OnExportCalculated(new ExportCalculatedEventArgs(numberOfSteps));
                this.CurrentExportStep = 1;

                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent      = true;
                settings.IndentChars = "\t";

                // export the document map
                if (!this.IsCancelled)
                {
                    this.OnExportStep(new ExportStepEventArgs("Export as XML...", ++this.CurrentExportStep));
                    using (XmlWriter writer = XmlWriter.Create(string.Format("{0}/toc.xml", this.TempDirectory), this.outputSettings))
                    {
                        Rendering.DocumentMapXmlRenderer map = new Rendering.DocumentMapXmlRenderer(this.Document.Map);
                        map.Render(writer);
                    }

                    // export the index page
                    IndexXmlRenderer indexPage = new IndexXmlRenderer(this.Document.Map);
                    using (XmlWriter writer = XmlWriter.Create(string.Format("{0}/index.xml", this.TempDirectory), this.outputSettings))
                    {
                        indexPage.Render(writer);
                    }

                    // export each of the members
                    foreach (Entry current in this.Document.Map)
                    {
                        this.RecursiveEntryExport(current);
                        this.OnExportStep(new ExportStepEventArgs("Export as XML...", ++this.CurrentExportStep));
                        if (this.IsCancelled)
                        {
                            break;
                        }
                    }
                    GC.Collect();
                }

                if (!this.IsCancelled)
                {
                    // set output files
                    this.OnExportStep(new ExportStepEventArgs("Saving output files...", ++this.CurrentExportStep));
                    this.Config.SaveOutputFilesTo(this.PublishDirectory);

                    // move all the temporary export files to the publish directory
                    foreach (string file in Directory.GetFiles(this.TempDirectory))
                    {
                        File.Copy(file, Path.Combine(this.PublishDirectory, Path.GetFileName(file)));
                        this.OnExportStep(new ExportStepEventArgs("Publishing XML files...", ++this.CurrentExportStep));
                    }
                }

                // clean up the temp directory
                this.OnExportStep(new ExportStepEventArgs("Cleaning up", ++this.CurrentExportStep));
                this.Cleanup();
            }
            catch (Exception ex)
            {
                this.Cleanup(); // attempt to clean up our mess before dying
                ExportException exception = new ExportException(ex.Message, ex);
                this.OnExportException(new ExportExceptionEventArgs(exception));
            }
        }
Exemple #6
0
        /// <summary>
        /// Exports the documentation to the MS Help Viewer 1 documention type.
        /// </summary>
        public override void Export()
        {
            try
            {
                PrepareForExport();

                // calculate the export steps
                int numberOfSteps = 0;
                numberOfSteps += 1;                                                    // toc and index steps
                numberOfSteps += Document.Map.Count;                                   // top level entries for recursive export
                numberOfSteps += 1;                                                    // output files
                numberOfSteps += ((Document.Map.NumberOfEntries / XmlExportStep) * 3); // xml export stage
                numberOfSteps += 1;                                                    // publish files
                numberOfSteps += 1;                                                    // cleanup files

                OnExportCalculated(new ExportCalculatedEventArgs(numberOfSteps));
                CurrentExportStep = 1;

                if (!IsCancelled)
                {
                    // export the document map
                    OnExportStep(new ExportStepEventArgs("Export as XML...", ++CurrentExportStep));
                    using (XmlWriter writer = XmlWriter.Create(string.Format("{0}/toc.xml", TempDirectory)))
                    {
                        Rendering.DocumentMapXmlRenderer map = new Rendering.DocumentMapXmlRenderer(
                            Document.Map
                            );
                        map.Render(writer);
                    }

                    Website.IndexXmlRenderer indexPage = new Website.IndexXmlRenderer(Document.Map);
                    using (XmlWriter writer = XmlWriter.Create(string.Format("{0}/index.xml", TempDirectory)))
                    {
                        indexPage.Render(writer);
                    }

                    // export each of the members
                    foreach (Entry current in Document.Map)
                    {
                        RecursiveEntryExport(current);
                        OnExportStep(new ExportStepEventArgs("Export as XML...", ++CurrentExportStep));
                        if (IsCancelled)
                        {
                            break;
                        }
                    }
                    GC.Collect();
                }

                // perform the transform of the full XML files produced to the Help Viewer 1 format.
                if (!IsCancelled)
                {
                    List <Task> conversionTasks = new List <Task>();
                    string      outputFile      = string.Empty;

                    IXsltProcessor xsltProcessor = new MsXsltProcessor(TempDirectory);
                    using (Stream xsltStream = Config.GetXslt())
                    {
                        xsltProcessor.CompileXslt(xsltStream);
                    }

                    // set output files
                    OnExportStep(new ExportStepEventArgs("Saving output files...", ++CurrentExportStep));
                    Config.SaveOutputFilesTo(OutputDirectory);

                    OnExportStep(new ExportStepEventArgs("Transforming XML...", ++CurrentExportStep));

                    // export the content files
                    int counter = 0;
                    foreach (string current in Directory.GetFiles(TempDirectory))
                    {
                        if (current.Substring(TempDirectory.Length) == "toc.xml")
                        {
                            continue;
                        }
                        outputFile = OutputDirectory + Path.GetFileNameWithoutExtension(current) + ".htm";

                        conversionTasks.Add(xsltProcessor.TransformAsync(current, outputFile).ContinueWith(
                                                (Task outer) =>
                        {
                            counter++;
                            if (counter % XmlExportStep == 0)
                            {
                                OnExportStep(new ExportStepEventArgs("Transforming XML...", CurrentExportStep += 3));
                            }
                        }
                                                ));

                        if (IsCancelled)
                        {
                            break;
                        }
                    }
                    Task.WaitAll(conversionTasks.ToArray());
                }

                if (!IsCancelled)
                {
                    // compile the html help file
                    OnExportStep(new ExportStepEventArgs("Compiling help...", ++CurrentExportStep));
                    CompileHelp(TempDirectory + "\\Documentation.mshc");
                    File.Copy(ApplicationDirectory + "\\ApplicationData\\Documentation.msha", TempDirectory + "\\Documentation.msha");

                    // publish the documentation
                    OnExportStep(new ExportStepEventArgs("Publishing help...", ++CurrentExportStep));
                    string[] files = { "Documentation.mshc", "Documentation.msha" };
                    for (int i = 0; i < files.Length; i++)
                    {
                        File.Move(
                            Path.Combine(TempDirectory, files[i]),
                            Path.Combine(PublishDirectory, files[i])
                            );;
                    }
                }

                // clean up the temp directory
                OnExportStep(new ExportStepEventArgs("Cleaning up", ++CurrentExportStep));
                Cleanup();
            }
            catch (Exception ex)
            {
                Cleanup(); // attempt to clean up our mess before dying
                ExportException exception = new ExportException(ex.Message, ex);
                OnExportException(new ExportExceptionEventArgs(exception));
            }
        }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExportExceptionEventArgs"/> class.
 /// </summary>
 /// <param name="exception">The exception.</param>
 public ExportExceptionEventArgs(ExportException exception)
 {
     this.Exception = exception;
 }