summaryrefslogtreecommitdiffstats
path: root/tools/Sandcastle/Source/BuildAssembler/BuildComponents/HxfGeneratorComponent.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-09-20 21:18:59 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-09-21 08:06:22 -0700
commitbbe3f9cc9c8a1e5909273c1a162a63ea7a66afd8 (patch)
treec91f66e642c4d26fca266e226b3f2765f546d700 /tools/Sandcastle/Source/BuildAssembler/BuildComponents/HxfGeneratorComponent.cs
parent627014f0bbc3fd576277375e70f8391d150b0a67 (diff)
downloadDotNetOpenAuth-bbe3f9cc9c8a1e5909273c1a162a63ea7a66afd8.zip
DotNetOpenAuth-bbe3f9cc9c8a1e5909273c1a162a63ea7a66afd8.tar.gz
DotNetOpenAuth-bbe3f9cc9c8a1e5909273c1a162a63ea7a66afd8.tar.bz2
Switched out the Sandcastle binaries for the source code.
Diffstat (limited to 'tools/Sandcastle/Source/BuildAssembler/BuildComponents/HxfGeneratorComponent.cs')
-rw-r--r--tools/Sandcastle/Source/BuildAssembler/BuildComponents/HxfGeneratorComponent.cs127
1 files changed, 127 insertions, 0 deletions
diff --git a/tools/Sandcastle/Source/BuildAssembler/BuildComponents/HxfGeneratorComponent.cs b/tools/Sandcastle/Source/BuildAssembler/BuildComponents/HxfGeneratorComponent.cs
new file mode 100644
index 0000000..65ba716
--- /dev/null
+++ b/tools/Sandcastle/Source/BuildAssembler/BuildComponents/HxfGeneratorComponent.cs
@@ -0,0 +1,127 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+using System;
+using System.IO;
+using System.Text;
+using System.Xml;
+using System.Xml.XPath;
+using System.Collections.Generic;
+
+namespace Microsoft.Ddue.Tools {
+
+ public class FileCreatedEventArgs : EventArgs {
+
+ private string filePath;
+ private string hxfPath;
+
+ public FileCreatedEventArgs(string filePath, string hxfPath) {
+ this.filePath = filePath;
+ this.hxfPath = hxfPath;
+ }
+
+ public string FilePath {
+ get {
+ return(filePath);
+ }
+ }
+
+ public string HxfPath {
+ get {
+ return (hxfPath);
+ }
+ }
+
+ }
+
+ public class HxfGeneratorComponent : BuildComponent {
+
+ public HxfGeneratorComponent (BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) {
+
+ // get configuration data
+ inputValue = configuration.GetAttribute("input", String.Empty);
+ if (!String.IsNullOrEmpty(inputValue)) inputValue = Environment.ExpandEnvironmentVariables(inputValue);
+ outputValue = configuration.GetAttribute("output", String.Empty);
+ if (!String.IsNullOrEmpty(outputValue)) outputValue = Environment.ExpandEnvironmentVariables(outputValue);
+
+ // subscribe to component events
+ assembler.ComponentEvent += new EventHandler(FileCreatedHandler);
+ }
+
+ private string inputValue;
+
+ private string outputValue;
+
+ private XmlWriter writer;
+
+ private Dictionary<string, XmlWriter> writers = new Dictionary<string, XmlWriter>();
+
+ private void FileCreatedHandler (Object o, EventArgs e) {
+ FileCreatedEventArgs fe = e as FileCreatedEventArgs;
+ if (fe == null) return;
+
+ string path = Path.Combine(fe.HxfPath, outputValue);
+
+ XmlWriter tempWriter;
+ if (!writers.TryGetValue(path, out tempWriter)) {
+ if (writer != null) {
+ writer.WriteEndDocument();
+ writer.Close();
+ }
+ WriteFile(path);
+ }
+
+ WriteFileElement(fe.FilePath);
+
+ }
+
+ private void WriteFileElement (string url) {
+ writer.WriteStartElement("File");
+ writer.WriteAttributeString("Url", url);
+ writer.WriteEndElement();
+ }
+
+ public override void Dispose() {
+ writer.WriteEndDocument();
+ writer.Close();
+ base.Dispose();
+ }
+
+ public void WriteFile(string path) {
+ XmlWriterSettings writerSettings = new XmlWriterSettings();
+ writerSettings.Indent = true;
+ writer = XmlWriter.Create(path);
+ writer.WriteStartDocument();
+ writer.WriteStartElement("HelpFileList");
+ writer.WriteAttributeString("DTDVersion", "1.0");
+
+ // use the input to seed the output
+ if (!String.IsNullOrEmpty(inputValue)) {
+
+ try {
+ TextReader reader = File.OpenText(inputValue);
+
+ try {
+ while (true) {
+ string line = reader.ReadLine();
+ if (line == null) break;
+ WriteFileElement(line);
+ }
+ }
+ finally {
+ reader.Close();
+ }
+ }
+ catch (IOException ex) {
+ WriteMessage(MessageLevel.Error, String.Format("An access error occured while attempting to copy the input HxF data. The error message is:", ex.Message));
+ }
+ }
+
+ writers.Add(path, writer);
+ }
+
+ // don't do anything for individual files
+ public override void Apply (XmlDocument document, string key) {}
+
+ }
+
+} \ No newline at end of file