Пример #1
0
        private string SaveJMeterOutputDataToDb(string jMeterInputFileUrl)
        {
            // Save JMeter output data to db
            using (rockEntities entities = new rockEntities())
            {

                JMeterOutputFileParser parser = new JMeterOutputFileParser(_jmeterOutputFile);

                // Get all the httpSample data from the JMeter output file, save them to database
              int numInSameSeq = 0;
                foreach (var httpSample in parser.GetHttpSamples())
                {
                    // Jemter has a bug that sometimes will store empty responseData

                    numInSameSeq++;
                    var newRecord = new rock_jmeter();
                    if (httpSample.AssertionResult != null)
                    {
                        newRecord.AssertionResult_Error = httpSample.AssertionResult.Error;
                        newRecord.AssertionResult_Failure = httpSample.AssertionResult.Failure;
                        newRecord.AssertionResult_Name = httpSample.AssertionResult.Name;
                    }
                    FileInfo fi = new FileInfo(jMeterInputFileUrl);
                    newRecord.numInSameSeq = numInSameSeq;
                    newRecord.JmxFileName = fi.Name;
                    newRecord.exeUser = _userName;
                    newRecord.CGIName = httpSample.CGIName;
                    newRecord.Cookies = httpSample.Cookies;
                    newRecord.Method = httpSample.Method;
                    newRecord.QueryString = httpSample.QueryString;
                    newRecord.RequestHeader = httpSample.RequestHeader;
                    newRecord.ResponseData = httpSample.ResponseData;
                    newRecord.ResponseHeader = httpSample.ResponseHeader;
                    newRecord.ResponseTime = int.Parse(httpSample.ResponseTime);
                    int returnCode = -1;
                    int.TryParse(httpSample.ReturnCode, out returnCode);
                    newRecord.ReturnCode = returnCode;
                    newRecord.Url = httpSample.Url;
                    newRecord.RecordTimeStamp = new DateTimeOffset(DateTime.Now);
                    newRecord.ThreadName = httpSample.ThreadName;
                    newRecord.ParentCGIName = httpSample.ParentCGIName;
                    newRecord.AppName = this._appName;
                    newRecord.SeqNum = _batchSeqNum;
                    StringBuilder sbForIp = new StringBuilder();
                    IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());

                    foreach (IPAddress addr in localIPs)
                    {
                        sbForIp.Append(addr);
                        sbForIp.AppendLine();
                    }
                    newRecord.TestMachineIP = sbForIp.ToString();

                        entities.AddTorock_jmeter(newRecord);

                }
                // start saving

                    entities.SaveChanges();

                // save done
            }
            return _batchSeqNum;
        }
Пример #2
0
        private string SaveJMeterOutputDataToDb(string jMeterInputFileUrl)
        {
            // Save JMeter output data to db
            using (rockEntities entities = new rockEntities())
            {
                JMeterOutputFileParser parser = new JMeterOutputFileParser(_jmeterOutputFile);

                // Get all the httpSample data from the JMeter output file, save them to database
                int numInSameSeq = 0;
                foreach (var httpSample in parser.GetHttpSamples())
                {
                    // Jemter has a bug that sometimes will store empty responseData


                    numInSameSeq++;
                    var newRecord = new rock_jmeter();
                    if (httpSample.AssertionResult != null)
                    {
                        newRecord.AssertionResult_Error   = httpSample.AssertionResult.Error;
                        newRecord.AssertionResult_Failure = httpSample.AssertionResult.Failure;
                        newRecord.AssertionResult_Name    = httpSample.AssertionResult.Name;
                    }
                    FileInfo fi = new FileInfo(jMeterInputFileUrl);
                    newRecord.numInSameSeq   = numInSameSeq;
                    newRecord.JmxFileName    = fi.Name;
                    newRecord.exeUser        = _userName;
                    newRecord.CGIName        = httpSample.CGIName;
                    newRecord.Cookies        = httpSample.Cookies;
                    newRecord.Method         = httpSample.Method;
                    newRecord.QueryString    = httpSample.QueryString;
                    newRecord.RequestHeader  = httpSample.RequestHeader;
                    newRecord.ResponseData   = httpSample.ResponseData;
                    newRecord.ResponseHeader = httpSample.ResponseHeader;
                    newRecord.ResponseTime   = int.Parse(httpSample.ResponseTime);
                    int returnCode = -1;
                    int.TryParse(httpSample.ReturnCode, out returnCode);
                    newRecord.ReturnCode      = returnCode;
                    newRecord.Url             = httpSample.Url;
                    newRecord.RecordTimeStamp = new DateTimeOffset(DateTime.Now);
                    newRecord.ThreadName      = httpSample.ThreadName;
                    newRecord.ParentCGIName   = httpSample.ParentCGIName;
                    newRecord.AppName         = this._appName;
                    newRecord.SeqNum          = _batchSeqNum;
                    StringBuilder sbForIp  = new StringBuilder();
                    IPAddress[]   localIPs = Dns.GetHostAddresses(Dns.GetHostName());

                    foreach (IPAddress addr in localIPs)
                    {
                        sbForIp.Append(addr);
                        sbForIp.AppendLine();
                    }
                    newRecord.TestMachineIP = sbForIp.ToString();


                    entities.AddTorock_jmeter(newRecord);
                }
                // start saving

                entities.SaveChanges();

                // save done
            }
            return(_batchSeqNum);
        }