private string GenerateProgressMessage(Uri uri, long?bytesDownloaded = null, long?totalBytes = null, int?progressPercentage = null, double?speed = null) { var strBldr = new StringBuilder(); strBldr.AppendFormat("Downloading: {0}", uri); if (bytesDownloaded.HasValue && totalBytes.HasValue) { // A workaround for a bug in Mono misreporting TotalBytesToReceive // https://github.com/mono/mono/issues/9808 if (totalBytes == -1) { strBldr.AppendFormat("\nProgress: {0}B downloaded", Misc.NormalizeBinary(bytesDownloaded.Value)); } else { strBldr.AppendFormat("\nProgress: {0}% ({1}B/{2}B)", progressPercentage, Misc.NormalizeBinary(bytesDownloaded.Value), Misc.NormalizeBinary(totalBytes.Value)); } } if (speed != null) { double val; string unit; Misc.CalculateUnitSuffix(speed.Value, out val, out unit); strBldr.AppendFormat("\nSpeed: {0:F2}{1}/s", val, unit); } return(strBldr.Append(".").ToString()); }
private string GenerateProgressMessage(Uri uri, long?bytesDownloaded = null, long?totalBytes = null, int?progressPercentage = null, double?speed = null) { var strBldr = new StringBuilder(); strBldr.AppendFormat("Downloading: {0}", uri); if (bytesDownloaded.HasValue && totalBytes.HasValue) { strBldr.AppendFormat("\nProgress: {0}% ({1}B/{2}B)", progressPercentage, Misc.NormalizeBinary(bytesDownloaded.Value), Misc.NormalizeBinary(totalBytes.Value)); } if (speed != null) { double val; string unit; Misc.CalculateUnitSuffix(speed.Value, out val, out unit); strBldr.AppendFormat("\nSpeed: {0:F2}{1}/s", val, unit); } return(strBldr.Append(".").ToString()); }