Exemple #1
0
 private void CreateClient()
 {
     try
     {
         Uri uri = new Uri(Setting.Host);
         for (int i = 0; i < Setting.Connections; i++)
         {
             HttpTcpClient httpTcpClient = new HttpTcpClient(uri.Host, uri.Port);
             httpTcpClient.Client.Connect();
             if (!httpTcpClient.Client.IsConnected)
             {
                 throw httpTcpClient.Client.LastError;
             }
             httpTcpClients.Add(httpTcpClient);
         }
         Status = LoaderStatus.Runing;
     }
     catch (Exception e_)
     {
         Error  = e_;
         Status = LoaderStatus.Error;
         foreach (var item in httpTcpClients)
         {
             item.Dispose();
         }
         Status = LoaderStatus.Error;
     }
 }
Exemple #2
0
 public Request(HttpTcpClient clientAgent)
 {
     mTransferEncoding = false;
     mRequestLength    = 0;
     Code    = 0;
     mClient = clientAgent;
     mClient.Client.ClientError = OnSocketError;
     mClient.Client.DataReceive = OnReveive;
     mBuffer    = mClient.Buffer;
     Status     = RequestStatus.None;
     mStartTime = TimeWatch.GetElapsedMilliseconds();
     mRequestID = System.Threading.Interlocked.Increment(ref mRequestIDSqueue);
 }
        public async Task <Request.TestResult> TestCase(RequestSetting requestSetting, string host)
        {
            Uri uri = new Uri(host);

            using (HttpTcpClient httpTcpClient = new HttpTcpClient(uri.Host, uri.Port))
            {
                requestSetting.Build(uri.Host, httpTcpClient.Port);
                Request request = new Request(httpTcpClient);
                var     result  = await request.Execute(requestSetting);

                return(request.GetResult());
            }
        }
        public async Task <int> UnitTest(string c, string host)
        {
            var requestSetting = UseCaseStorage.Default.Get(c);

            if (requestSetting == null)
            {
                return(404);
            }
            Uri uri = new Uri(host);

            using (HttpTcpClient httpTcpClient = new HttpTcpClient(uri.Host, uri.Port))
            {
                requestSetting.Build(uri.Host, httpTcpClient.Port);
                Request request = new Request(httpTcpClient);
                var     result  = await request.Execute(requestSetting);

                return(result.Code);
            }
        }
Exemple #5
0
        private async void OnTest(HttpTcpClient httpTcp)
        {
            try
            {
                while (!OnCompleted())
                {
                    var     rsetting = GetTestRequestSetting();
                    Request request  = new Request(httpTcp);
                    var     result   = await request.Execute(rsetting.RequestSetting);

                    All.Add(result.Code, result.Time);
                    rsetting.Statistics.Add(result.Code, result.Time);
                }
            }
            catch (Exception e_)
            {
                Error = e_;
            }
            finally
            {
                httpTcp.Dispose();
            }
        }