This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static string GetFriendlyByteString(long bytes) | |
{ | |
string[] units = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; | |
double runningTotal = bytes; | |
foreach (var unit in units) | |
{ | |
double dividedTotal = runningTotal / 1024; | |
if (dividedTotal < 1) | |
{ | |
return $"{runningTotal:F2} {unit}"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static double ConvertIeeeExtendedToDouble(byte[] bytes) | |
{ | |
int e = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF); | |
ulong h = ((ulong)bytes[2] << 24) | |
| ((ulong)bytes[3] << 16) | |
| ((ulong)bytes[4] << 8) | |
| bytes[5]; | |
ulong l = ((ulong)(bytes[6]) << 24) | |
| ((ulong)(bytes[7]) << 16) | |
| ((ulong)(bytes[8]) << 8) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task<Task> WithTimeout(this Task task, TimeSpan timeout) | |
{ | |
Task delayTask = Task.Delay(TimeSpan.FromSeconds(1)); | |
Task firstCompleted = await Task.WhenAny(task, delayTask); | |
if (firstCompleted == delayTask) | |
{ | |
throw new Exception("Task timed out"); | |
} | |
return task; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
namespace DolomiteWcfService.MultipartParser | |
{ | |
public abstract class MultiPartPart | |
{ |