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