aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Extensibility/HeatExtension.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/WixToolset.Core/Extensibility/HeatExtension.cs200
1 files changed, 0 insertions, 200 deletions
diff --git a/src/WixToolset.Core/Extensibility/HeatExtension.cs b/src/WixToolset.Core/Extensibility/HeatExtension.cs
deleted file mode 100644
index b0da75f1..00000000
--- a/src/WixToolset.Core/Extensibility/HeatExtension.cs
+++ /dev/null
@@ -1,200 +0,0 @@
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.Core.Extensibility
4{
5 using System;
6 using System.IO;
7 using System.Reflection;
8 using WixToolset.Data;
9 using WixToolset.Tools;
10
11 /// <summary>
12 /// A command line option.
13 /// </summary>
14 public struct HeatCommandLineOption
15 {
16 public string Option;
17
18 public string Description;
19
20 /// <summary>
21 /// Instantiates a new CommandLineOption.
22 /// </summary>
23 /// <param name="option">The option name.</param>
24 /// <param name="description">The description of the option.</param>
25 public HeatCommandLineOption(string option, string description)
26 {
27 this.Option = option;
28 this.Description = description;
29 }
30 }
31
32 /// <summary>
33 /// An extension for the WiX Toolset Harvester application.
34 /// </summary>
35 public abstract class HeatExtension
36 {
37 /// <summary>
38 /// Gets or sets the heat core for the extension.
39 /// </summary>
40 /// <value>The heat core for the extension.</value>
41 public IHeatCore Core { get; set; }
42
43 /// <summary>
44 /// Gets the supported command line types for this extension.
45 /// </summary>
46 /// <value>The supported command line types for this extension.</value>
47 public virtual HeatCommandLineOption[] CommandLineTypes
48 {
49 get { return null; }
50 }
51
52 /// <summary>
53 /// Loads a HeatExtension from a type description string.
54 /// </summary>
55 /// <param name="extension">The extension type description string.</param>
56 /// <returns>The loaded HeatExtension.</returns>
57 /// <remarks>
58 /// <paramref name="extension"/> can be in several different forms:
59 /// <list type="number">
60 /// <item><term>AssemblyQualifiedName (TopNamespace.SubNameSpace.ContainingClass+NestedClass, MyAssembly, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b17a5c561934e089)</term></item>
61 /// <item><term>AssemblyName (MyAssembly, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b17a5c561934e089)</term></item>
62 /// <item><term>Absolute path to an assembly (C:\MyExtensions\ExtensionAssembly.dll)</term></item>
63 /// <item><term>Filename of an assembly in the application directory (ExtensionAssembly.dll)</term></item>
64 /// <item><term>Relative path to an assembly (..\..\MyExtensions\ExtensionAssembly.dll)</term></item>
65 /// </list>
66 /// To specify a particular class to use, prefix the fully qualified class name to the assembly and separate them with a comma.
67 /// For example: "TopNamespace.SubNameSpace.ContainingClass+NestedClass, C:\MyExtensions\ExtensionAssembly.dll"
68 /// </remarks>
69 public static HeatExtension Load(string extension)
70 {
71 Type extensionType = null;
72 int commaIndex = extension.IndexOf(',');
73 string className = String.Empty;
74 string assemblyName = extension;
75
76 if (0 <= commaIndex)
77 {
78 className = extension.Substring(0, commaIndex);
79 assemblyName = (extension.Length <= commaIndex + 1 ? String.Empty : extension.Substring(commaIndex + 1));
80 }
81
82 className = className.Trim();
83 assemblyName = assemblyName.Trim();
84
85 if (null == extensionType && 0 < assemblyName.Length)
86 {
87
88 Assembly extensionAssembly;
89
90 // case 3: Absolute path to an assembly
91 if (Path.IsPathRooted(assemblyName))
92 {
93 extensionAssembly = ExtensionLoadFrom(assemblyName);
94 }
95 else
96 {
97 try
98 {
99 // case 2: AssemblyName
100 extensionAssembly = Assembly.Load(assemblyName);
101 }
102 catch (IOException e)
103 {
104 if (e is FileLoadException || e is FileNotFoundException)
105 {
106 try
107 {
108 // case 4: Filename of an assembly in the application directory
109 extensionAssembly = Assembly.Load(Path.GetFileNameWithoutExtension(assemblyName));
110 }
111 catch (IOException innerE)
112 {
113 if (innerE is FileLoadException || innerE is FileNotFoundException)
114 {
115 // case 5: Relative path to an assembly
116
117 // we want to use Assembly.Load when we can because it has some benefits over Assembly.LoadFrom
118 // (see the documentation for Assembly.LoadFrom). However, it may fail when the path is a relative
119 // path, so we should try Assembly.LoadFrom one last time. We could have detected a directory
120 // separator character and used Assembly.LoadFrom directly, but dealing with path canonicalization
121 // issues is something we don't want to deal with if we don't have to.
122 extensionAssembly = ExtensionLoadFrom(assemblyName);
123 }
124 else
125 {
126 throw new WixException(ErrorMessages.InvalidExtension(assemblyName, innerE.Message));
127 }
128 }
129 }
130 else
131 {
132 throw new WixException(ErrorMessages.InvalidExtension(assemblyName, e.Message));
133 }
134 }
135 }
136
137 if (0 < className.Length)
138 {
139 try
140 {
141 // case 1: AssemblyQualifiedName
142 extensionType = extensionAssembly.GetType(className, true /* throwOnError */, true /* ignoreCase */);
143 }
144 catch (Exception e)
145 {
146 throw new WixException(ErrorMessages.InvalidExtensionType(assemblyName, className, e.GetType().ToString(), e.Message));
147 }
148 }
149 else
150 {
151 // if no class name was specified, then let's hope the assembly defined a default WixExtension
152 AssemblyDefaultHeatExtensionAttribute extensionAttribute = (AssemblyDefaultHeatExtensionAttribute)Attribute.GetCustomAttribute(extensionAssembly, typeof(AssemblyDefaultHeatExtensionAttribute));
153
154 if (null != extensionAttribute)
155 {
156 extensionType = extensionAttribute.ExtensionType;
157 }
158 else
159 {
160 throw new WixException(ErrorMessages.InvalidExtensionType(assemblyName, typeof(AssemblyDefaultHeatExtensionAttribute).ToString()));
161 }
162 }
163 }
164
165 if (extensionType.IsSubclassOf(typeof(HeatExtension)))
166 {
167 return Activator.CreateInstance(extensionType) as HeatExtension;
168 }
169 else
170 {
171 throw new WixException(ErrorMessages.InvalidExtensionType(extension, extensionType.ToString(), typeof(HeatExtension).ToString()));
172 }
173 }
174
175 /// <summary>
176 /// Parse the command line options for this extension.
177 /// </summary>
178 /// <param name="type">The active harvester type.</param>
179 /// <param name="args">The option arguments.</param>
180 public virtual void ParseOptions(string type, string[] args)
181 {
182 }
183
184 private static Assembly ExtensionLoadFrom(string assemblyName)
185 {
186 Assembly extensionAssembly = null;
187
188 try
189 {
190 extensionAssembly = Assembly.LoadFrom(assemblyName);
191 }
192 catch (Exception e)
193 {
194 throw new WixException(ErrorMessages.InvalidExtension(assemblyName, e.Message));
195 }
196
197 return extensionAssembly;
198 }
199 }
200}