Ejemplo n.º 1
0
        private List <DownloadRange> GetFileRanges()
        {
            var ranges = new List <DownloadRange>();

            // Add all ranges except for the last one
            for (int chunkNumber = 0; chunkNumber < NumberOfParallelConnections - 1; chunkNumber++)
            {
                var range = new DownloadRange()
                {
                    Start = chunkNumber * (FileSize / NumberOfParallelConnections),
                    End   = ((chunkNumber + 1) * (FileSize / NumberOfParallelConnections)) - 1
                };

                ranges.Add(range);
            }

            // Add the last range
            ranges.Add(new DownloadRange()
            {
                Start = ranges.Any() ? ranges.Last().End + 1 : 0,
                End   = FileSize - 1
            });

            return(ranges);
        }
Ejemplo n.º 2
0
        private HttpWebRequest CreateFileDownloadRequest(DownloadRange range)
        {
            var request = HttpWebRequest.Create(FileUri) as HttpWebRequest;

            request.Method = "GET";
            request.AddRange(range.Start, range.End);

            return(request);
        }