Ejemplo n.º 1
0
        private BodySizeQuery CalculateBodySizeStats(Har har)
        {
            Entry[] entries = har.Log.Entries;

            int length = entries.Length;

            int totalBodySize = 0;

            for (int i = 0; i < length; ++i)
            {
                totalBodySize += entries[i].Request.BodySize;
            }

            float average = 0.0f;

            if (length != 0)
            {
                average = ((float)totalBodySize) / length;
            }

            BodySizeQuery toReturn = new BodySizeQuery
            {
                AverageSize = average,
                TotalSize   = totalBodySize
            };


            return(toReturn);
        }
Ejemplo n.º 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 }));
            }
        }