aboutsummaryrefslogtreecommitdiff
path: root/src/wix/WixToolset.Core/AssignDefaultFeatureCommand.cs
blob: 9904d740a2dcced7b2c88c964ebe3a2bad2b06e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 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.

namespace WixToolset.Core
{
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using WixToolset.Data;
    using WixToolset.Data.Symbols;

    internal class AssignDefaultFeatureCommand
    {
        public AssignDefaultFeatureCommand(IntermediateSection entrySection, IEnumerable<IntermediateSection> sections)
        {
            this.EntrySection = entrySection;
            this.Sections = sections;
        }

        public IntermediateSection EntrySection { get; }

        public IEnumerable<IntermediateSection> Sections { get; }

        public void Execute()
        {
            foreach (var section in this.Sections)
            {
                var components = section.Symbols.OfType<ComponentSymbol>().ToList();
                foreach (var component in components)
                {
                    this.EntrySection.AddSymbol(new WixComplexReferenceSymbol(component.SourceLineNumbers)
                    {
                        Parent = WixStandardLibraryIdentifiers.DefaultFeatureName,
                        ParentType = ComplexReferenceParentType.Feature,
                        ParentLanguage = null,
                        Child = component.Id.Id,
                        ChildType = ComplexReferenceChildType.Component,
                        IsPrimary = true,
                    });

                    this.EntrySection.AddSymbol(new WixGroupSymbol(component.SourceLineNumbers)
                    {
                        ParentId = WixStandardLibraryIdentifiers.DefaultFeatureName,
                        ParentType = ComplexReferenceParentType.Feature,
                        ChildId = component.Id.Id,
                        ChildType = ComplexReferenceChildType.Component,
                    });
                }
            }

            this.EntrySection.AddSymbol(new WixSimpleReferenceSymbol()
            {
                Table = "Feature",
                PrimaryKeys = WixStandardLibraryIdentifiers.DefaultFeatureName,
            });
        }
    }
}