private void ExportContentAsXml()
        {
            List <Task> conversionTasks = new List <Task>();

            if (!IsCancelled)
            {
                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 index page
                IndexXmlRenderer indexPage = new 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;
                    }
                }
            }
            Task.WaitAll(conversionTasks.ToArray());
            GC.Collect();
        }
Example #2
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));
            }
        }
        /// <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));
            }
        }