Exemplo n.º 1
0
        /// <summary>
        /// List the latest profiling results.
        /// </summary>
        /// <param name="maxResults">The maximum number of results to return.</param>
        /// <param name="start">(Optional) The start of the date range to fetch.</param>
        /// <param name="finish">(Optional) The end of the date range to fetch.</param>
        /// <param name="orderBy">(Optional) The order to fetch profiler IDs in.</param>
        public IEnumerable <Guid> List(
            int maxResults,
            DateTime?start           = null,
            DateTime?finish          = null,
            ListResultsOrder orderBy = ListResultsOrder.Descending)
        {
            var guids = new List <Guid>();

            lock (_profiles)
            {
                int idxStart  = 0;
                int idxFinish = _profiles.Count - 1;
                if (start != null)
                {
                    idxStart = _profiles.BinaryClosestSearch(start.Value);
                }
                if (finish != null)
                {
                    idxFinish = _profiles.BinaryClosestSearch(finish.Value);
                }

                if (idxStart < 0)
                {
                    idxStart = 0;
                }
                if (idxFinish >= _profiles.Count)
                {
                    idxFinish = _profiles.Count - 1;
                }

                var keys = _profiles.Keys;

                if (orderBy == ListResultsOrder.Ascending)
                {
                    for (int i = idxStart; i <= idxFinish; i++)
                    {
                        guids.Add(keys[i].Id);
                        if (guids.Count == maxResults)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    for (int i = idxFinish; i >= idxStart; i--)
                    {
                        guids.Add(keys[i].Id);
                        if (guids.Count == maxResults)
                        {
                            break;
                        }
                    }
                }
            }
            return(guids);
        }