From 958d164fa98533cc1fe8da7a509d0ce13ac4eb9f Mon Sep 17 00:00:00 2001 From: ali h Date: Sat, 4 May 2024 20:28:32 +0330 Subject: [PATCH] fixe speed test --- fast cf ip scanner/Services/IPService.cs | 7 ++++--- fast cf ip scanner/ViewModels/ScanPageViewModel.cs | 6 ++++-- fast cf ip scanner/Views/IpOptionsPage.xaml | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/fast cf ip scanner/Services/IPService.cs b/fast cf ip scanner/Services/IPService.cs index c65730e..70d3c6c 100644 --- a/fast cf ip scanner/Services/IPService.cs +++ b/fast cf ip scanner/Services/IPService.cs @@ -367,16 +367,17 @@ public async Task GetDownloadSpeedAsync(string testUrl, string ipAddress var stopwatch = Stopwatch.StartNew(); var response = await httpClient.GetAsync(targetUrl, HttpCompletionOption.ResponseHeadersRead); response.EnsureSuccessStatusCode(); - stopwatch.Stop(); // Read the content as byte array to ensure the download is completed. var contentBytes = await response.Content.ReadAsByteArrayAsync(); + stopwatch.Stop(); + // Calculate download speed in Mbps (Mega bits per second). double fileSizeInMegabytes = contentBytes.Length / (1024d * 1024d); double durationInSeconds = stopwatch.Elapsed.TotalSeconds; - double speedMbps = (fileSizeInMegabytes / durationInSeconds) * 8; // Convert MBps to Mbps - + double speedMBps = fileSizeInMegabytes / durationInSeconds; // Convert MBps to Mbps + var speedMbps = speedMBps * 8; return Math.Round(speedMbps, 2); } } diff --git a/fast cf ip scanner/ViewModels/ScanPageViewModel.cs b/fast cf ip scanner/ViewModels/ScanPageViewModel.cs index 428960e..9b83564 100644 --- a/fast cf ip scanner/ViewModels/ScanPageViewModel.cs +++ b/fast cf ip scanner/ViewModels/ScanPageViewModel.cs @@ -98,8 +98,8 @@ async Task ShowSelectedIPOption(IPModel ipModel) string[] Options; if(workers.Count == 0) { - Options = new string[2]; - Options[1] = "Please add a worker"; + Options = new string[3]; + Options[2] = "Please add a worker"; } else { @@ -125,8 +125,10 @@ async Task ShowSelectedIPOption(IPModel ipModel) } else if(reslut== "speed test") { + IsBusy = true; var downloadSizeForSpeedTestToMB = _ipOption.DownloadSizeForSpeedTest * 1024 * 1024; var speed = await _iPServices.GetDownloadSpeedAsync($"https://speed.cloudflare.com/__down?bytes={downloadSizeForSpeedTestToMB}", ipModel.IP); + IsBusy = false; await App.Current.MainPage.DisplayAlert("speed", $"{speed} Mb", "ok"); } else if(reslut == "Please add a worker") diff --git a/fast cf ip scanner/Views/IpOptionsPage.xaml b/fast cf ip scanner/Views/IpOptionsPage.xaml index bbf57ad..ab8ed96 100644 --- a/fast cf ip scanner/Views/IpOptionsPage.xaml +++ b/fast cf ip scanner/Views/IpOptionsPage.xaml @@ -68,7 +68,7 @@