summaryrefslogtreecommitdiffstats
path: root/tools/Sandcastle/Source/BuildAssembler/BuildComponents/IfThenComponent.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/IfThenComponent.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/IfThenComponent.cs')
-rw-r--r--tools/Sandcastle/Source/BuildAssembler/BuildComponents/IfThenComponent.cs82
1 files changed, 82 insertions, 0 deletions
diff --git a/tools/Sandcastle/Source/BuildAssembler/BuildComponents/IfThenComponent.cs b/tools/Sandcastle/Source/BuildAssembler/BuildComponents/IfThenComponent.cs
new file mode 100644
index 0000000..7d8f423
--- /dev/null
+++ b/tools/Sandcastle/Source/BuildAssembler/BuildComponents/IfThenComponent.cs
@@ -0,0 +1,82 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Xml;
+using System.Xml.XPath;
+using System.Xml.Xsl;
+
+using System.Reflection;
+
+namespace Microsoft.Ddue.Tools {
+
+ public class IfThenComponent : BuildComponent {
+
+ private XPathExpression condition;
+
+ private IEnumerable<BuildComponent> true_branch = new List<BuildComponent>();
+
+ private IEnumerable<BuildComponent> false_branch = new List<BuildComponent>();
+
+ public IfThenComponent (BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) {
+
+ // get the condition
+ XPathNavigator if_node = configuration.SelectSingleNode("if");
+ if (if_node == null) throw new ConfigurationErrorsException("You must specify a condition using the <if> element.");
+ string condition_xpath = if_node.GetAttribute("condition", String.Empty);
+ if (String.IsNullOrEmpty(condition_xpath)) throw new ConfigurationErrorsException();
+ condition = XPathExpression.Compile(condition_xpath);
+
+ // construct the true branch
+ XPathNavigator then_node = configuration.SelectSingleNode("then");
+ if (then_node != null) true_branch = BuildAssembler.LoadComponents(then_node);
+
+ // construct the false branch
+ XPathNavigator else_node = configuration.SelectSingleNode("else");
+ if (else_node != null) false_branch = BuildAssembler.LoadComponents(else_node);
+
+ // keep a pointer to the context for future use
+ context = assembler.Context;
+
+ }
+
+ private BuildContext context;
+
+ public override void Apply (XmlDocument document, string key) {
+
+ // set up the test
+ context["key"] = key;
+ XPathExpression test = condition.Clone();
+ test.SetContext(context.XsltContext);
+
+ // evaluate the condition
+ bool result = (bool) document.CreateNavigator().Evaluate(test);
+
+ // on the basis of the condition, execute either the true or the false branch
+ if (result) {
+ foreach (BuildComponent component in true_branch) {
+ component.Apply(document, key);
+ }
+ } else {
+ foreach (BuildComponent component in false_branch) {
+ component.Apply(document, key);
+ }
+ }
+
+ }
+
+ public override void Dispose () {
+ foreach (BuildComponent component in true_branch) {
+ component.Dispose();
+ }
+ foreach (BuildComponent component in false_branch) {
+ component.Dispose();
+ }
+ base.Dispose();
+ }
+
+ }
+
+
+} \ No newline at end of file