| 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.Native.Msi |
| 4 | { |
| 5 | /// <summary> |
| 6 | /// Controls the installation process. |
| 7 | /// </summary> |
| 8 | public sealed class Session : MsiHandle |
| 9 | { |
| 10 | /// <summary> |
| 11 | /// Instantiate a new Session. |
| 12 | /// </summary> |
| 13 | /// <param name="database">The database to open.</param> |
| 14 | public Session(Database database) |
| 15 | { |
| 16 | var packagePath = "#" + database.Handle; |
| 17 | |
| 18 | var error = MsiInterop.MsiOpenPackage(packagePath, out var handle); |
| 19 | if (0 != error) |
| 20 | { |
| 21 | throw new MsiException(error); |
| 22 | } |
| 23 | |
| 24 | this.Handle = handle; |
| 25 | } |
| 26 | |
| 27 | /// <summary> |
| 28 | /// Executes a built-in action, custom action, or user-interface wizard action. |
| 29 | /// </summary> |
| 30 | /// <param name="action">Specifies the action to execute.</param> |
| 31 | public void DoAction(string action) |
| 32 | { |
| 33 | var error = MsiInterop.MsiDoAction(this.Handle, action); |
| 34 | if (0 != error) |
| 35 | { |
| 36 | throw new MsiException(error); |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | } |