| 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.Burn.Bind |
| 4 | { |
| 5 | using System; |
| 6 | using System.Linq; |
| 7 | using WixToolset.Data; |
| 8 | using WixToolset.Data.Symbols; |
| 9 | using WixToolset.Extensibility.Services; |
| 10 | |
| 11 | internal class NormalizeRelatedBundlesCommand |
| 12 | { |
| 13 | public NormalizeRelatedBundlesCommand(IMessaging messaging, WixBundleSymbol bundleSymbol, IntermediateSection section) |
| 14 | { |
| 15 | this.Messaging = messaging; |
| 16 | this.BundleSymbol = bundleSymbol; |
| 17 | this.Section = section; |
| 18 | } |
| 19 | |
| 20 | private IMessaging Messaging { get; } |
| 21 | |
| 22 | private WixBundleSymbol BundleSymbol { get; } |
| 23 | |
| 24 | private IntermediateSection Section { get; } |
| 25 | |
| 26 | public void Execute() |
| 27 | { |
| 28 | foreach (var relatedBundleSymbol in this.Section.Symbols.OfType<WixRelatedBundleSymbol>()) |
| 29 | { |
| 30 | var elementName = "RelatedBundle"; |
| 31 | var attributeName = "Id"; |
| 32 | |
| 33 | if (this.BundleSymbol.UpgradeCode == relatedBundleSymbol.BundleId) |
| 34 | { |
| 35 | elementName = "Bundle"; |
| 36 | attributeName = "UpgradeCode"; |
| 37 | } |
| 38 | |
| 39 | relatedBundleSymbol.BundleId = this.NormalizeBundleRelatedBundleId(relatedBundleSymbol.SourceLineNumbers, relatedBundleSymbol.BundleId, elementName, attributeName); |
| 40 | } |
| 41 | |
| 42 | this.BundleSymbol.UpgradeCode = this.NormalizeBundleRelatedBundleId(this.BundleSymbol.SourceLineNumbers, this.BundleSymbol.UpgradeCode, null, null); |
| 43 | } |
| 44 | |
| 45 | private string NormalizeBundleRelatedBundleId(SourceLineNumber sourceLineNumber, string relatedBundleId, string elementName, string attributeName) |
| 46 | { |
| 47 | if (Guid.TryParse(relatedBundleId, out var guid)) |
| 48 | { |
| 49 | return guid.ToString("B").ToUpperInvariant(); |
| 50 | } |
| 51 | else if (!String.IsNullOrEmpty(elementName)) |
| 52 | { |
| 53 | this.Messaging.Write(ErrorMessages.IllegalGuidValue(sourceLineNumber, elementName, attributeName, relatedBundleId)); |
| 54 | } |
| 55 | |
| 56 | return relatedBundleId; |
| 57 | } |
| 58 | } |
| 59 | } |