main
cs 66 lines 2.19 KB
Raw
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
4 {
5 using System.Collections.Generic;
6 using System.Linq;
7 using WixToolset.Data;
8 using WixToolset.Data.Symbols;
9 using WixToolset.Extensibility.Services;
10
11 internal class GetBootstrapperApplicationSymbolsCommand
12 {
13 public GetBootstrapperApplicationSymbolsCommand(IMessaging messaging, IntermediateSection section)
14 {
15 this.Messaging = messaging;
16 this.Section = section;
17 }
18
19 private IMessaging Messaging { get; }
20
21 private IntermediateSection Section { get; }
22
23 public WixBootstrapperApplicationSymbol Primary { get; private set; }
24
25 public WixBootstrapperApplicationSymbol Secondary { get; private set; }
26
27 public void Execute()
28 {
29 var applications = this.Section.Symbols.OfType<WixBootstrapperApplicationSymbol>().ToList();
30
31 var primaries = applications.Where(a => a.Secondary != true).ToList();
32
33 var secondaries = applications.Where(a => a.Secondary == true).ToList();
34
35 if (primaries.Count > 1)
36 {
37 this.ReportTooManyBootstrapperApplications(primaries);
38 }
39 else if (primaries.Count == 0)
40 {
41 this.Messaging.Write(BurnBackendErrors.MissingPrimaryBootstrapperApplication());
42 }
43 else
44 {
45 this.Primary = primaries[0];
46 }
47
48 if (secondaries.Count > 1)
49 {
50 this.ReportTooManyBootstrapperApplications(secondaries);
51 }
52 else if (secondaries.Count == 1)
53 {
54 this.Secondary = secondaries[0];
55 }
56 }
57
58 public void ReportTooManyBootstrapperApplications(IEnumerable<WixBootstrapperApplicationSymbol> symbols)
59 {
60 foreach (var symbol in symbols)
61 {
62 this.Messaging.Write(BurnBackendErrors.TooManyBootstrapperApplications(symbol.SourceLineNumbers, symbol));
63 }
64 }
65 }
66 }