| 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.Core.WindowsInstaller |
| 4 | { |
| 5 | using WixToolset.Core.WindowsInstaller.Bind; |
| 6 | using WixToolset.Extensibility; |
| 7 | using WixToolset.Extensibility.Data; |
| 8 | using WixToolset.Extensibility.Services; |
| 9 | |
| 10 | internal class MsiBackend : IBackend |
| 11 | { |
| 12 | public IBindResult Bind(IBindContext context) |
| 13 | { |
| 14 | var extensionManager = context.ServiceProvider.GetService<IExtensionManager>(); |
| 15 | |
| 16 | var backendExtensions = extensionManager.GetServices<IWindowsInstallerBackendBinderExtension>(); |
| 17 | |
| 18 | foreach (var extension in backendExtensions) |
| 19 | { |
| 20 | extension.PreBackendBind(context); |
| 21 | } |
| 22 | |
| 23 | IBindResult result = null; |
| 24 | var dispose = true; |
| 25 | try |
| 26 | { |
| 27 | var command = new BindDatabaseCommand(context, backendExtensions); |
| 28 | result = command.Execute(); |
| 29 | |
| 30 | foreach (var extension in backendExtensions) |
| 31 | { |
| 32 | extension.PostBackendBind(result); |
| 33 | } |
| 34 | |
| 35 | dispose = false; |
| 36 | return result; |
| 37 | } |
| 38 | finally |
| 39 | { |
| 40 | if (dispose) |
| 41 | { |
| 42 | result?.Dispose(); |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |