aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/BinderFileManagerCore.cs
blob: 5780983ab28768477868be736e9c98278eb80dda (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// 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
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using WixToolset.Data;
    using WixToolset.Data.Bind;
    using WixToolset.Extensibility;

    public class BinderFileManagerCore : IBinderFileManagerCore
    {
        private Dictionary<string, List<string>>[] bindPaths;

        /// <summary>
        /// Instantiate a new BinderFileManager.
        /// </summary>
        public BinderFileManagerCore()
        {
            this.bindPaths = new Dictionary<string, List<string>>[3];
            this.bindPaths[(int)BindStage.Normal] = new Dictionary<string, List<string>>();
            this.bindPaths[(int)BindStage.Target] = new Dictionary<string, List<string>>();
            this.bindPaths[(int)BindStage.Updated] = new Dictionary<string, List<string>>();
        }

        /// <summary>
        /// Gets or sets the path to cabinet cache.
        /// </summary>
        /// <value>The path to cabinet cache.</value>
        public string CabCachePath { get; set; }

        /// <summary>
        /// Gets or sets the active subStorage used for binding.
        /// </summary>
        /// <value>The subStorage object.</value>
        //public SubStorage ActiveSubStorage { get; set; }

        /// <summary>
        /// Gets or sets the output object used for binding.
        /// </summary>
        /// <value>The output object.</value>
        public Intermediate Intermediate { get; set; }

        /// <summary>
        /// Gets or sets the path to the temp files location.
        /// </summary>
        /// <value>The path to the temp files location.</value>
        public string TempFilesLocation { get; set; }

        /// <summary>
        /// Gets the property if re-basing target is true or false
        /// </summary>
        /// <value>It returns true if target bind path is to be replaced, otherwise false.</value>
        public bool RebaseTarget
        {
            get { return this.bindPaths[(int)BindStage.Target].Any(); }
        }

        /// <summary>
        /// Gets the property if re-basing updated build is true or false
        /// </summary>
        /// <value>It returns true if updated bind path is to be replaced, otherwise false.</value>
        public bool RebaseUpdated
        {
            get { return this.bindPaths[(int)BindStage.Updated].Any(); }
        }

        public void AddBindPaths(IEnumerable<BindPath> paths, BindStage stage)
        {
            Dictionary<string, List<string>> dict = this.bindPaths[(int)stage];

            foreach (BindPath bindPath in paths)
            {
                List<string> values;
                if (!dict.TryGetValue(bindPath.Name, out values))
                {
                    values = new List<string>();
                    dict.Add(bindPath.Name, values);
                }

                if (!values.Contains(bindPath.Path))
                {
                    values.Add(bindPath.Path);
                }
            }
        }

        public IEnumerable<string> GetBindPaths(BindStage stage = BindStage.Normal, string name = null)
        {
            List<string> paths;
            if (this.bindPaths[(int)stage].TryGetValue(name ?? String.Empty, out paths))
            {
                return paths;
            }

            return Enumerable.Empty<string>();
        }

        /// <summary>
        /// Sends a message to the message delegate if there is one.
        /// </summary>
        /// <param name="e">Message event arguments.</param>
        public void OnMessage(MessageEventArgs e)
        {
            Messaging.Instance.OnMessage(e);
        }
    }
}