Minor code clean up
Rob Mensching committed
Mar 23, 2021 at 01:24 UTC
734be59ad7edaa1444f713338fcdbc0c4b9c273b
5 files changed
+33
-88
src/WixToolset.Core.Burn/Bind/GenerateManifestDataFromIRCommand.cs
+2
-2
@@ -16,7 +16,7 @@ namespace WixToolset.Core.Burn.Bind
16
17
internal class GenerateManifestDataFromIRCommand
18
{
19
- public GenerateManifestDataFromIRCommand(IMessaging messaging, IntermediateSection section, IEnumerable<IBurnBackendBinderExtension> backendExtensions, IBurnBackendHelper backendHelper, IDictionary<string, IList<IntermediateSymbol>> extensionSearchSymbolsById)
19
+ public GenerateManifestDataFromIRCommand(IMessaging messaging, IntermediateSection section, IEnumerable<IBurnBackendBinderExtension> backendExtensions, IBurnBackendHelper backendHelper, IDictionary<string, IEnumerable<IntermediateSymbol>> extensionSearchSymbolsById)
20
{
21
this.Messaging = messaging;
22
this.Section = section;
@@ -29,7 +29,7 @@ namespace WixToolset.Core.Burn.Bind
29
30
private IBurnBackendHelper BackendHelper { get; }
31
32
- private IDictionary<string, IList<IntermediateSymbol>> ExtensionSearchSymbolsById { get; }
32
+ private IDictionary<string, IEnumerable<IntermediateSymbol>> ExtensionSearchSymbolsById { get; }
33
34
private IMessaging Messaging { get; }
35
src/WixToolset.Core.Burn/Bundles/OrderSearchesCommand.cs
+30
-26
@@ -23,33 +23,28 @@ namespace WixToolset.Core.Burn.Bundles
23
24
private IntermediateSection Section { get; }
25
26
- public IDictionary<string, IList<IntermediateSymbol>> ExtensionSearchSymbolsByExtensionId { get; private set; }
26
+ public IDictionary<string, IEnumerable<IntermediateSymbol>> ExtensionSearchSymbolsByExtensionId { get; private set; }
27
28
- public IList<ISearchFacade> OrderedSearchFacades { get; private set; }
28
+ public IEnumerable<ISearchFacade> OrderedSearchFacades { get; private set; }
29
30
public void Execute()
31
{
32
- this.ExtensionSearchSymbolsByExtensionId = new Dictionary<string, IList<IntermediateSymbol>>();
33
- this.OrderedSearchFacades = new List<ISearchFacade>();
32
+ this.ExtensionSearchSymbolsByExtensionId = new Dictionary<string, IEnumerable<IntermediateSymbol>>();
33
+ this.OrderedSearchFacades = Array.Empty<ISearchFacade>();
34
35
- var searchRelationSymbols = this.Section.Symbols.OfType<WixSearchRelationSymbol>().ToList();
36
- var searchSymbols = this.Section.Symbols.OfType<WixSearchSymbol>().ToList();
35
+ var searchSymbols = this.Section.Symbols.OfType<WixSearchSymbol>().ToDictionary(t => t.Id.Id);
36
if (searchSymbols.Count == 0)
37
{
39
- // nothing to do!
38
+ // Nothing to do!
39
return;
40
}
41
43
- var symbolDictionary = searchSymbols.ToDictionary(t => t.Id.Id);
44
-
42
var constraints = new Constraints();
46
- if (searchRelationSymbols.Count > 0)
43
+
44
+ // Add relational info to our data...
45
+ foreach (var searchRelationSymbol in this.Section.Symbols.OfType<WixSearchRelationSymbol>())
46
{
48
- // add relational info to our data...
49
- foreach (var searchRelationSymbol in searchRelationSymbols)
50
- {
51
- constraints.AddConstraint(searchRelationSymbol.Id.Id, searchRelationSymbol.ParentSearchRef);
52
- }
47
+ constraints.AddConstraint(searchRelationSymbol.Id.Id, searchRelationSymbol.ParentSearchRef);
48
}
49
50
this.FindCircularReference(constraints);
@@ -67,10 +62,13 @@ namespace WixToolset.Core.Burn.Bundles
62
// lexicographically at each step to ensure a deterministic ordering
63
// based on 'after' dependencies and ID.
64
var sorter = new TopologicalSort();
70
- var sortedIds = sorter.Sort(symbolDictionary.Keys, constraints);
65
+ var sortedIds = sorter.Sort(searchSymbols.Keys, constraints);
66
67
// Now, create the search facades with the searches in order...
73
- this.OrderSearches(sortedIds, symbolDictionary);
68
+ (var orderedSearchFacades, var extensionSearchSymbolsByExtensionId) = this.OrderSearches(sortedIds, searchSymbols);
69
+
70
+ this.OrderedSearchFacades = orderedSearchFacades;
71
+ this.ExtensionSearchSymbolsByExtensionId = extensionSearchSymbolsByExtensionId;
72
}
73
74
/// <summary>
@@ -102,11 +100,11 @@ namespace WixToolset.Core.Burn.Bundles
100
/// <remarks>This is not particularly performant, but it works.</remarks>
101
private void FindCircularReference(Constraints constraints)
102
{
105
- foreach (string id in constraints.Keys)
103
+ foreach (var id in constraints.Keys)
104
{
105
var seenIds = new List<string>();
108
- string chain = null;
109
- if (this.FindCircularReference(constraints, id, id, seenIds, out chain))
106
+
107
+ if (this.FindCircularReference(constraints, id, id, seenIds, out var chain))
108
{
109
// We will show a separate message for every ID that's in
110
// the loop. We could bail after the first one, but then
@@ -313,8 +311,11 @@ namespace WixToolset.Core.Burn.Bundles
311
}
312
}
313
316
- private void OrderSearches(List<string> sortedIds, Dictionary<string, WixSearchSymbol> searchSymbolDictionary)
314
+ private (IEnumerable<ISearchFacade>, Dictionary<string, IEnumerable<IntermediateSymbol>>) OrderSearches(IEnumerable<string> sortedIds, Dictionary<string, WixSearchSymbol> searchSymbolDictionary)
315
{
316
+ var orderedSearchFacades = new List<ISearchFacade>();
317
+ var extensionSearchSymbolsByExtensionId = new Dictionary<string, List<IntermediateSymbol>>();
318
+
319
// TODO: Although the WixSearch tables are defined in the Util extension,
320
// the Bundle Binder has to know all about them. We hope to revisit all
321
// of this in the 4.0 timeframe.
@@ -334,22 +335,23 @@ namespace WixToolset.Core.Burn.Bundles
335
foreach (var searchId in sortedIds)
336
{
337
var searchSymbol = searchSymbolDictionary[searchId];
338
+
339
if (legacySearchesById.TryGetValue(searchId, out var specificSearchSymbol))
340
{
339
- this.OrderedSearchFacades.Add(new LegacySearchFacade(searchSymbol, specificSearchSymbol));
341
+ orderedSearchFacades.Add(new LegacySearchFacade(searchSymbol, specificSearchSymbol));
342
}
343
else if (setVariablesById.TryGetValue(searchId, out var setVariableSymbol))
344
{
343
- this.OrderedSearchFacades.Add(new SetVariableSearchFacade(searchSymbol, setVariableSymbol));
345
+ orderedSearchFacades.Add(new SetVariableSearchFacade(searchSymbol, setVariableSymbol));
346
}
347
else if (extensionSearchesById.TryGetValue(searchId, out var extensionSearchSymbol))
348
{
347
- this.OrderedSearchFacades.Add(new ExtensionSearchFacade(searchSymbol));
349
+ orderedSearchFacades.Add(new ExtensionSearchFacade(searchSymbol));
350
349
- if (!this.ExtensionSearchSymbolsByExtensionId.TryGetValue(searchSymbol.BundleExtensionRef, out var extensionSearchSymbols))
351
+ if (!extensionSearchSymbolsByExtensionId.TryGetValue(searchSymbol.BundleExtensionRef, out var extensionSearchSymbols))
352
{
353
extensionSearchSymbols = new List<IntermediateSymbol>();
352
- this.ExtensionSearchSymbolsByExtensionId[searchSymbol.BundleExtensionRef] = extensionSearchSymbols;
354
+ extensionSearchSymbolsByExtensionId[searchSymbol.BundleExtensionRef] = extensionSearchSymbols;
355
}
356
extensionSearchSymbols.Add(extensionSearchSymbol);
357
}
@@ -358,6 +360,8 @@ namespace WixToolset.Core.Burn.Bundles
360
this.Messaging.Write(ErrorMessages.MissingBundleSearch(searchSymbol.SourceLineNumbers, searchId));
361
}
362
}
363
+
364
+ return (orderedSearchFacades, extensionSearchSymbolsByExtensionId.ToDictionary(kvp => kvp.Key, kvp => (IEnumerable<IntermediateSymbol>)kvp.Value));
365
}
366
}
367
}
src/WixToolset.Core.Burn/Bundles/ProcessPayloadsCommand.cs
+1
-5
@@ -15,10 +15,8 @@ namespace WixToolset.Core.Burn.Bundles
15
16
internal class ProcessPayloadsCommand
17
{
18
- public ProcessPayloadsCommand(IServiceProvider serviceProvider, IBackendHelper backendHelper, IPayloadHarvester payloadHarvester, IEnumerable<WixBundlePayloadSymbol> payloads, PackagingType defaultPackaging, string layoutDirectory)
18
+ public ProcessPayloadsCommand(IBackendHelper backendHelper, IPayloadHarvester payloadHarvester, IEnumerable<WixBundlePayloadSymbol> payloads, PackagingType defaultPackaging, string layoutDirectory)
19
{
20
- this.Messaging = serviceProvider.GetService<IMessaging>();
21
-
20
this.BackendHelper = backendHelper;
21
this.PayloadHarvester = payloadHarvester;
22
this.Payloads = payloads;
@@ -30,8 +28,6 @@ namespace WixToolset.Core.Burn.Bundles
28
29
public IEnumerable<ITrackedFile> TrackedFiles { get; private set; }
30
33
- private IMessaging Messaging { get; }
34
-
31
private IBackendHelper BackendHelper { get; }
32
33
private IPayloadHarvester PayloadHarvester { get; }
src/WixToolset.Core/Link/ConnectToFeature.cs
-10
@@ -10,16 +10,6 @@ namespace WixToolset.Core.Link
10
/// </summary>
11
internal class ConnectToFeature
12
{
13
- /// <summary>
14
- /// Creates a new connect to feature.
15
- /// </summary>
16
- /// <param name="section">Section this connect belongs to.</param>
17
- /// <param name="childId">Id of the child.</param>
18
- public ConnectToFeature(IntermediateSection section, string childId) :
19
- this(section, childId, null, false)
20
- {
21
- }
22
-
13
/// <summary>
14
/// Creates a new connect to feature.
15
/// </summary>
src/WixToolset.Core/Linker.cs
-45
@@ -901,51 +901,6 @@ namespace WixToolset.Core
901
}
902
}
903
904
-#if DEAD_CODE
905
- /// <summary>
906
- /// Copies a table's rows to an output table.
907
- /// </summary>
908
- /// <param name="table">Source table to copy rows from.</param>
909
- /// <param name="outputTable">Destination table in output to copy rows into.</param>
910
- /// <param name="sectionId">Id of the section that the table lives in.</param>
911
- private void CopyTableRowsToOutputTable(Table table, Table outputTable, string sectionId)
912
- {
913
- int[] localizedColumns = new int[table.Definition.Columns.Count];
914
- int localizedColumnCount = 0;
915
-
916
- // if there are localization strings, figure out which columns can be localized in this table
917
- if (null != this.Localizer)
918
- {
919
- for (int i = 0; i < table.Definition.Columns.Count; i++)
920
- {
921
- if (table.Definition.Columns[i].IsLocalizable)
922
- {
923
- localizedColumns[localizedColumnCount++] = i;
924
- }
925
- }
926
- }
927
-
928
- // process each row in the table doing the string resource substitutions
929
- // then add the row to the output
930
- foreach (Row row in table.Rows)
931
- {
932
- for (int j = 0; j < localizedColumnCount; j++)
933
- {
934
- Field field = row.Fields[localizedColumns[j]];
935
-
936
- if (null != field.Data)
937
- {
938
- field.Data = this.WixVariableResolver.ResolveVariables(row.SourceLineNumbers, (string)field.Data, true);
939
- }
940
- }
941
-
942
- row.SectionId = (this.sectionIdOnRows ? sectionId : null);
943
- outputTable.Rows.Add(row);
944
- }
945
- }
946
-#endif
947
-
948
-
904
/// <summary>
905
/// Resolve features for columns that have null guid placeholders.
906
/// </summary>