2
0
mirror of synced 2025-02-09 07:04:47 +00:00

68 lines
1.7 KiB
C#
Raw Normal View History

using Logging;
namespace AutoClient
2024-09-12 14:38:15 +02:00
{
public class Performance
{
private readonly ILog log;
public Performance(ILog log)
{
this.log = log;
}
public void DownloadFailed(Exception ex)
{
Log($"Download failed: {ex}");
}
2024-10-30 11:09:13 +01:00
public void DownloadSuccessful(long? size, TimeSpan time)
2024-09-12 14:38:15 +02:00
{
2024-10-30 11:09:13 +01:00
if (!size.HasValue) return;
2024-09-12 15:14:15 +02:00
long milliseconds = Convert.ToInt64(time.TotalMilliseconds);
if (milliseconds < 1) milliseconds = 1;
2024-10-30 11:09:13 +01:00
long bytesPerSecond = 1000 * (size.Value / milliseconds);
Log($"Download successful: {bytesPerSecond} bytes per second");
2024-09-12 14:38:15 +02:00
}
public void StorageContractCancelled()
2024-09-12 14:38:15 +02:00
{
Log("Contract cancelled");
2024-09-12 14:38:15 +02:00
}
public void StorageContractErrored(string error)
2024-09-12 14:38:15 +02:00
{
Log($"Contract errored: {error}");
2024-09-12 14:38:15 +02:00
}
public void StorageContractFinished()
2024-09-12 14:38:15 +02:00
{
Log("Contract finished");
2024-09-12 14:38:15 +02:00
}
public void StorageContractStarted()
2024-09-12 14:38:15 +02:00
{
Log("Contract started");
2024-09-12 14:38:15 +02:00
}
public void UploadFailed(Exception ex)
2024-09-12 14:38:15 +02:00
{
Log($"Upload failed: {ex}");
2024-09-12 14:38:15 +02:00
}
public void UploadSuccessful(long size, TimeSpan time)
2024-09-12 14:38:15 +02:00
{
2024-09-12 15:14:15 +02:00
long milliseconds = Convert.ToInt64(time.TotalMilliseconds);
if (milliseconds < 1) milliseconds = 1;
long bytesPerSecond = 1000 * (size / milliseconds);
Log($"Upload successful: {bytesPerSecond} bytes per second");
2024-09-12 14:38:15 +02:00
}
private void Log(string msg)
2024-09-12 14:38:15 +02:00
{
log.Log(msg);
2024-09-12 14:38:15 +02:00
}
}
}