Exemplo n.º 1
0
        /// <summary>
        /// Reorders Any WixSearch items.
        /// </summary>
        /// <param name="output">Output containing the tables to process.</param>
        private void ReorderWixSearch(Output output)
        {
            Table wixSearchTable = output.Tables["WixSearch"];

            if (null == wixSearchTable || wixSearchTable.Rows.Count == 0)
            {
                // nothing to do!
                return;
            }

            RowDictionary rowDictionary = new RowDictionary();

            foreach (Row row in wixSearchTable.Rows)
            {
                rowDictionary.AddRow(row);
            }

            Constraints constraints            = new Constraints();
            Table       wixSearchRelationTable = output.Tables["WixSearchRelation"];

            if (null != wixSearchRelationTable && wixSearchRelationTable.Rows.Count > 0)
            {
                // add relational info to our data...
                foreach (Row row in wixSearchRelationTable.Rows)
                {
                    constraints.AddConstraint((string)row[0], (string)row[1]);
                }
            }

            this.FindCircularReference(constraints);

            if (this.Core.EncounteredError)
            {
                return;
            }

            this.FlattenDependentReferences(constraints);

            // Reorder by topographical sort (http://en.wikipedia.org/wiki/Topological_sorting)
            // We use a variation of Kahn (1962) algorithm as described in
            // Wikipedia, with the additional criteria that start nodes are sorted
            // lexicographically at each step to ensure a deterministic ordering
            // based on 'after' dependencies and ID.
            TopologicalSort sorter    = new TopologicalSort();
            List <string>   sortedIds = sorter.Sort(rowDictionary.Keys, constraints);

            // Now, re-write the table with the searches in order...
            wixSearchTable.Rows.Clear();
            foreach (string id in sortedIds)
            {
                wixSearchTable.Rows.Add(rowDictionary[id]);
            }
        }
        public void Execute()
        {
            this.ExtensionSearchSymbolsByExtensionId = new Dictionary <string, IList <IntermediateSymbol> >();
            this.OrderedSearchFacades = new List <ISearchFacade>();

            var searchRelationSymbols = this.Section.Symbols.OfType <WixSearchRelationSymbol>().ToList();
            var searchSymbols         = this.Section.Symbols.OfType <WixSearchSymbol>().ToList();

            if (searchSymbols.Count == 0)
            {
                // nothing to do!
                return;
            }

            var symbolDictionary = searchSymbols.ToDictionary(t => t.Id.Id);

            var constraints = new Constraints();

            if (searchRelationSymbols.Count > 0)
            {
                // add relational info to our data...
                foreach (var searchRelationSymbol in searchRelationSymbols)
                {
                    constraints.AddConstraint(searchRelationSymbol.Id.Id, searchRelationSymbol.ParentSearchRef);
                }
            }

            this.FindCircularReference(constraints);

            if (this.Messaging.EncounteredError)
            {
                return;
            }

            this.FlattenDependentReferences(constraints);

            // Reorder by topographical sort (http://en.wikipedia.org/wiki/Topological_sorting)
            // We use a variation of Kahn (1962) algorithm as described in
            // Wikipedia, with the additional criteria that start nodes are sorted
            // lexicographically at each step to ensure a deterministic ordering
            // based on 'after' dependencies and ID.
            var sorter    = new TopologicalSort();
            var sortedIds = sorter.Sort(symbolDictionary.Keys, constraints);

            // Now, create the search facades with the searches in order...
            this.OrderSearches(sortedIds, symbolDictionary);
        }