コード例 #1
0
        /// <summary>
        /// Determines the optimal page on which <paramref name="dataSource"/> should be run, by interrogating the
        /// <see cref="F:ResponseFieldMap"/> to find the earliest page which contains a mapped control,
        /// and returns the id of the optimal page.
        /// </summary>
        /// <param name="dataSource">The data source to interrogate.</param>
        /// <param name="pageList">The page list containing the full control definitions.</param>
        /// <returns>The id of the optimal page on which <paramref name="dataSource"/> should be run.</returns>
        private int DetermineOptimalPageId(ProductDataSource dataSource, PageList pageList)
        {
            const int defaultVal = int.MaxValue;
            Dictionary<string, int> controlPageIndexes = pageList.AccumulateControlPageIndexes();
            List<string> targetFields = dataSource.ResponseFieldMap.Select(map => map.Target).ToList();
            int min = defaultVal;
            foreach (string target in targetFields)
            {
                if (controlPageIndexes.Keys.Contains(target))
                {
                    min = Math.Min(controlPageIndexes[target], min);
                }
            }

            return min == defaultVal ? -1 : pageList[min].PageId;
        }