Esempio n. 1
0
        public async Task DoTest(BaseUrl url, RequestType type, IEnumerable <BaseParameter> parameters, long count, CancellationToken token)
        {
            ResetCounters();
            IsRunning     = true;
            RequestsCount = count;
            var responseTasks = new ConfiguredTaskAwaitable <HttpResponseMessage> [count];

            //Send all requests
            for (var i = 0; i < RequestsCount; i++)
            {
                if (token.IsCancellationRequested)
                {
                    IsRunning = false;
                    UpdateProperties();
                    await Logger.Flush();

                    return;
                }

                responseTasks[i] = Task.Run(() => HttpExecutor.Execute(url.Value, type, parameters, token), token).ConfigureAwait(false);
            }

            //Get all responses
            for (var i = 0; i < RequestsCount; i++)
            {
                if (token.IsCancellationRequested)
                {
                    IsRunning = false;
                    UpdateProperties();
                    await Logger.Flush();

                    return;
                }

                HttpResponseMessage response;
                try
                {
                    DoneCount++;
                    response = await responseTasks[i];
                }
                catch (Exception)
                {
                    FaliedCount++;
                    continue;
                }

                if ((int)response.StatusCode >= 100 && (int)response.StatusCode < 200)
                {
                    Code1++;
                }
                else if ((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
                {
                    Code2++;
                }
                else if ((int)response.StatusCode >= 300 && (int)response.StatusCode < 400)
                {
                    Code3++;
                }
                else if ((int)response.StatusCode >= 400 && (int)response.StatusCode < 500)
                {
                    Code4++;
                }
                else if ((int)response.StatusCode >= 500 && (int)response.StatusCode < 600)
                {
                    Code5++;
                }
                SuccessCount++;
                await Logger.Log(response);
            }
            await Logger.Flush();

            IsRunning = false;
        }
Esempio n. 2
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     StopButton_Click(null, null);
     HttpExecutor.Stop();
     Engine.Dispose();
 }