private StressResult PerformRequest(StressRequest req)
        {
            HttpWebRequest  request  = null;
            HttpWebResponse response = null;

            Stopwatch    watch  = new Stopwatch();
            StressResult result = new StressResult(req);

            try
            {
                watch.Start();
                request           = (HttpWebRequest)WebRequest.Create(req.Url);
                request.Method    = "GET";
                request.KeepAlive = true;
                response          = (HttpWebResponse)request.GetResponse();
                using (Stream stream = response.GetResponseStream())
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        stream.CopyTo(ms);
                        result.ContentLength = ms.Length;
                    }
                }
                watch.Stop();

                result.TimeTaken      = watch.ElapsedMilliseconds;
                result.HttpStatusCode = response.StatusCode;
                result.Success        = true;
                if (this.KeepHeaders.Count > 0)
                {
                    result.ResponseHeaders = new List <string>();
                    Dictionary <string, string> dic = response.Headers.AllKeys.ToDictionary(h => h, h => response.Headers[h]);
                    foreach (var kh in this.KeepHeaders)
                    {
                        string value = String.Empty;
                        dic.TryGetValue(kh, out value);
                        result.ResponseHeaders.Add(value);
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                // TODO: Consider including exception in result
                result.Success = false;
                return(result);;
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }
        }
        public IEnumerable <StressRequest> Parse(string file)
        {
            DateTime startTime = DateTime.MinValue;

            foreach (string line in System.IO.File.ReadLines(file))
            {
                string[] columns     = line.Split(";".ToCharArray());
                DateTime requestTime = ParseDateTime(columns[timeIndex]);
                if (startTime == DateTime.MinValue)
                {
                    startTime = requestTime;
                }
                StressRequest r = new StressRequest();
                r.RelativeTime = requestTime - startTime;
                r.Url          = this.Host + columns[urlIndex];
                r.Id           = columns[this.idIndex];
                yield return(r);
            }
        }
Beispiel #3
0
        public IEnumerable <StressRequest> Parse(string file)
        {
            DateTime startTime = DateTime.MinValue;

            foreach (string line in System.IO.File.ReadLines(file))
            {
                Match m = regex.Match(line);
                if (m.Success)
                {
                    DateTime requestTime = ParseDateTime(m.Groups[timeIndex].Value);
                    if (startTime == DateTime.MinValue)
                    {
                        startTime = requestTime;
                    }
                    StressRequest r = new StressRequest();
                    r.RelativeTime = requestTime - startTime;
                    r.Url          = this.Host + m.Groups[urlIndex].Value;
                    yield return(r);
                }
            }
        }
 public StressResult(StressRequest request)
 {
     this.Request = request;
 }