Skip to content

Commit

Permalink
fixe speed test
Browse files Browse the repository at this point in the history
  • Loading branch information
DevoTalk committed May 4, 2024
1 parent b5012a5 commit 958d164
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions fast cf ip scanner/Services/IPService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,17 @@ public async Task<double> 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);
}
}
Expand Down
6 changes: 4 additions & 2 deletions fast cf ip scanner/ViewModels/ScanPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion fast cf ip scanner/Views/IpOptionsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<Label Text="Count of IP for test"/>
<Entry x:Name="CountOfIpForTest" Text="{Binding CountOfIpForTest}"/>

<Label Text="Download size for speed test"/>
<Label Text="Download size for speed test (MB)"/>
<Entry x:Name="DownloadSizeForSpeedTest" Text="{Binding DownloadSizeForSpeedTest}"/>

<Button Text="Save" Command="{Binding SaveCommand}"/>
Expand Down

0 comments on commit 958d164

Please sign in to comment.