private void CalcNextChunkRanges()
{
BytesUploaded = 0;
currentChunkStartPos = 0;
currentChunkEndPos = (currentChunkStartPos + ChunkSize < FileLength ? currentChunkStartPos + ChunkSize : FileLength - 1);
if (ResponseText != null && ResponseText.Length != 0)
{
// We can not check response.StatusCode, see comments in constructor of FileUploadControl
if (Regex.IsMatch(ResponseText, @"^\d+-\d+/\d+")) // we got 201 response
// response can be 0-66211/6621184,6554988-6621183/6621184, so we do not include string end in regexp
{
long holeStart = 0, holeEnd = 0;
// let's find first hole in ranges
foreach(string str in ResponseText.Split(','))
{
string[] r = str.Split('/')[0].Split('-');
long start = long.Parse(r[0]);
long end = long.Parse(r[1]);
BytesUploaded += end - start;
if (holeEnd != 0)
{
continue;
}
if (start != 0)
{
holeEnd = start - 1;
}
else
{
holeStart = end + 1;
}
}
currentChunkStartPos = holeStart;
if (holeEnd == 0)
{
holeEnd = FileLength - 1;
}
currentChunkEndPos = (holeEnd - holeStart < ChunkSize ? holeEnd : currentChunkStartPos + ChunkSize);
}
else // we got 200 response
{
BytesUploaded = FileLength;
}
}
}