diff options
Diffstat (limited to 'src/ext/Bal/WixToolset.Mba.Host/BootstrapperApplicationFactory.cs')
-rw-r--r-- | src/ext/Bal/WixToolset.Mba.Host/BootstrapperApplicationFactory.cs | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/src/ext/Bal/WixToolset.Mba.Host/BootstrapperApplicationFactory.cs b/src/ext/Bal/WixToolset.Mba.Host/BootstrapperApplicationFactory.cs deleted file mode 100644 index 78e68bd9..00000000 --- a/src/ext/Bal/WixToolset.Mba.Host/BootstrapperApplicationFactory.cs +++ /dev/null | |||
@@ -1,86 +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 | |||
3 | namespace WixToolset.Mba.Host | ||
4 | { | ||
5 | using System; | ||
6 | using System.Configuration; | ||
7 | using System.Reflection; | ||
8 | using System.Runtime.InteropServices; | ||
9 | using WixToolset.Mba.Core; | ||
10 | |||
11 | /// <summary> | ||
12 | /// Entry point for the managed host to create and return the BA to the engine. | ||
13 | /// </summary> | ||
14 | [ClassInterface(ClassInterfaceType.None)] | ||
15 | public sealed class BootstrapperApplicationFactory : MarshalByRefObject, IBootstrapperApplicationFactory | ||
16 | { | ||
17 | /// <summary> | ||
18 | /// Creates a new instance of the <see cref="BootstrapperApplicationFactory"/> class. | ||
19 | /// Entry point for the MBA host. | ||
20 | /// </summary> | ||
21 | public BootstrapperApplicationFactory() | ||
22 | { | ||
23 | } | ||
24 | |||
25 | /// <summary> | ||
26 | /// Loads the bootstrapper application assembly and calls its IBootstrapperApplicationFactory.Create method. | ||
27 | /// </summary> | ||
28 | /// <param name="pArgs">Pointer to BOOTSTRAPPER_CREATE_ARGS struct.</param> | ||
29 | /// <param name="pResults">Pointer to BOOTSTRAPPER_CREATE_RESULTS struct.</param> | ||
30 | /// <exception cref="MissingAttributeException">The bootstrapper application assembly | ||
31 | /// does not define the <see cref="BootstrapperApplicationFactoryAttribute"/>.</exception> | ||
32 | public void Create(IntPtr pArgs, IntPtr pResults) | ||
33 | { | ||
34 | // Get the wix.boostrapper section group to get the name of the bootstrapper application assembly to host. | ||
35 | var section = ConfigurationManager.GetSection("wix.bootstrapper/host") as HostSection; | ||
36 | if (null == section) | ||
37 | { | ||
38 | throw new MissingAttributeException(); // TODO: throw a more specific exception than this. | ||
39 | } | ||
40 | |||
41 | // Load the BA's IBootstrapperApplicationFactory. | ||
42 | var baFactoryType = BootstrapperApplicationFactory.GetBAFactoryTypeFromAssembly(section.AssemblyName); | ||
43 | var baFactory = (IBootstrapperApplicationFactory)Activator.CreateInstance(baFactoryType); | ||
44 | if (null == baFactory) | ||
45 | { | ||
46 | throw new InvalidBootstrapperApplicationFactoryException(); | ||
47 | } | ||
48 | |||
49 | baFactory.Create(pArgs, pResults); | ||
50 | } | ||
51 | |||
52 | /// <summary> | ||
53 | /// Locates the <see cref="BootstrapperApplicationFactoryAttribute"/> and returns the specified type. | ||
54 | /// </summary> | ||
55 | /// <param name="assemblyName">The assembly that defines the IBootstrapperApplicationFactory implementation.</param> | ||
56 | /// <returns>The bootstrapper application factory <see cref="Type"/>.</returns> | ||
57 | private static Type GetBAFactoryTypeFromAssembly(string assemblyName) | ||
58 | { | ||
59 | Type baFactoryType = null; | ||
60 | |||
61 | // Load the requested assembly. | ||
62 | Assembly asm = AppDomain.CurrentDomain.Load(assemblyName); | ||
63 | |||
64 | // If an assembly was loaded and is not the current assembly, check for the required attribute. | ||
65 | // This is done to avoid using the BootstrapperApplicationFactoryAttribute which we use at build time | ||
66 | // to specify the BootstrapperApplicationFactory assembly in the manifest. | ||
67 | if (!Assembly.GetExecutingAssembly().Equals(asm)) | ||
68 | { | ||
69 | // There must be one and only one BootstrapperApplicationFactoryAttribute. | ||
70 | // The attribute prevents multiple declarations already. | ||
71 | var attrs = (BootstrapperApplicationFactoryAttribute[])asm.GetCustomAttributes(typeof(BootstrapperApplicationFactoryAttribute), false); | ||
72 | if (null != attrs) | ||
73 | { | ||
74 | baFactoryType = attrs[0].BootstrapperApplicationFactoryType; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | if (null == baFactoryType) | ||
79 | { | ||
80 | throw new MissingAttributeException(); | ||
81 | } | ||
82 | |||
83 | return baFactoryType; | ||
84 | } | ||
85 | } | ||
86 | } | ||