예제 #1
0
        private BlockedQuery CalculateBlockedStats(Har har)
        {
            Entry[] entries = har.Log.Entries;

            int length = entries.Length;

            Entry longest = null, shortest = null, secondShortest = null;

            for (int i = 0; i < length; ++i)
            {
                double blocked = entries[i].Timings.Blocked;

                if (blocked < 0.0)
                {
                    continue;
                }

                if (longest == null)
                {
                    longest  = entries[i];
                    shortest = entries[i];
                    continue;
                }


                if (blocked > longest.Timings.Blocked)
                {
                    longest = entries[i];
                }
                else if (blocked < shortest.Timings.Blocked)
                {
                    secondShortest = shortest;
                    shortest       = entries[i];
                }
                else if (secondShortest == null)
                {
                    secondShortest = entries[i];
                }
                else if (blocked < secondShortest.Timings.Blocked)
                {
                    secondShortest = entries[i];
                }
            }

            BlockedQuery toReturn = new BlockedQuery
            {
                Longest        = longest,
                Shortest       = shortest,
                SecondShortest = secondShortest
            };

            return(toReturn);
        }
예제 #2
0
        public IActionResult Get(int id, string query)
        {
            try
            {
                if (!_cache.TryGetValue(id, out Har value))
                {
                    return(StatusCode(404, new { Success = false, Status = 404, Id = id }));
                }

                if (query == null)
                {
                    return(StatusCode(200, new { Success = true, Id = id, Status = 200, Model = value }));
                }

                if (query == "blocked")
                {
                    BlockedQuery bq = CalculateBlockedStats(value);
                    return(StatusCode(200, new { Success = true, Id = id, Status = 200, Model = value, Query = bq }));
                }
                else if (query == "bodysize")
                {
                    BodySizeQuery bq = CalculateBodySizeStats(value);
                    return(StatusCode(200, new { Success = true, Id = id, Status = 200, Model = value, Query = bq }));
                }
                else if (query == "querystring")
                {
                    List <string> urls = GetUrlsWithInputString(value);
                    return(StatusCode(200, new { Success = true, Id = id, Status = 200, Model = value, Query = urls }));
                }
                else if (query == "slowestpage")
                {
                    var slowest = GetUrlsWithSlowestPage(value);
                    return(StatusCode(200, new { Success = true, Id = id, Status = 200, Model = value, Query = slowest }));
                }


                return(StatusCode(400, new { Success = false, Status = 400, Message = "Unknown Query: " + query }));
            }
            catch (Exception ex)
            {
                return(StatusCode(200, new { Success = false, Status = 500, Message = ex.Message }));
            }
        }