aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Harvester.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/Harvester.cs')
-rw-r--r--src/WixToolset.Core/Harvester.cs80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/WixToolset.Core/Harvester.cs b/src/WixToolset.Core/Harvester.cs
new file mode 100644
index 00000000..0f79a2d6
--- /dev/null
+++ b/src/WixToolset.Core/Harvester.cs
@@ -0,0 +1,80 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset
4{
5 using System;
6 using System.Collections;
7 using System.Diagnostics.CodeAnalysis;
8 using WixToolset.Data;
9 using Wix = WixToolset.Data.Serialize;
10
11 /// <summary>
12 /// The WiX Toolset harvester.
13 /// </summary>
14 public sealed class Harvester
15 {
16 private HarvesterExtension harvesterExtension;
17
18 /// <summary>
19 /// Gets or sets the harvester core for the extension.
20 /// </summary>
21 /// <value>The harvester core for the extension.</value>
22 public IHarvesterCore Core { get; set; }
23
24 /// <summary>
25 /// Gets or sets the extension.
26 /// </summary>
27 /// <value>The extension.</value>
28 [SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "System.InvalidOperationException.#ctor(System.String)")]
29 public HarvesterExtension Extension
30 {
31 get
32 {
33 return this.harvesterExtension;
34 }
35 set
36 {
37 if (null != this.harvesterExtension)
38 {
39 throw new InvalidOperationException(WixStrings.EXP_MultipleHarvesterExtensionsSpecified);
40 }
41
42 this.harvesterExtension = value;
43 }
44 }
45
46 /// <summary>
47 /// Harvest wix authoring.
48 /// </summary>
49 /// <param name="argument">The argument for harvesting.</param>
50 /// <returns>The harvested wix authoring.</returns>
51 public Wix.Wix Harvest(string argument)
52 {
53 if (null == argument)
54 {
55 throw new ArgumentNullException("argument");
56 }
57
58 if (null == this.harvesterExtension)
59 {
60 throw new WixException(WixErrors.HarvestTypeNotFound());
61 }
62
63 this.harvesterExtension.Core = this.Core;
64
65 Wix.Fragment[] fragments = this.harvesterExtension.Harvest(argument);
66 if (null == fragments || 0 == fragments.Length)
67 {
68 return null;
69 }
70
71 Wix.Wix wix = new Wix.Wix();
72 foreach (Wix.Fragment fragment in fragments)
73 {
74 wix.AddChild(fragment);
75 }
76
77 return wix;
78 }
79 }
80}