public void Download(byte[] data, int bufferSize, DownloadSegmentPositions[] segmentPositionInfos) { BeforeDownload(); DownloadStream inputStream = new DownloadStream(data); IList <ISegmentDownloadTask> segmentDownloadTasks = new List <ISegmentDownloadTask>(segmentPositionInfos.Length); IList <DownloadStream> downloadStreams = new List <DownloadStream>(segmentPositionInfos.Length); MemoryStream outputStream = new MemoryStream(); for (int i = 0; i < segmentPositionInfos.Length; i++) { DownloadSegmentPositions segmentPosition = segmentPositionInfos[i]; byte[] dataPart = data.Skip((int)segmentPosition.StartPosition).Take((int)(segmentPosition.EndPosition - segmentPosition.StartPosition + 1)).ToArray(); DownloadStream downloadStream = new DownloadStream(dataPart); segmentDownloadTasks.Add(CreateSegmentDownloadTask(bufferSize, CreateSegmentDownloader(downloadStream, segmentPosition), CreateSegmentWriter(outputStream))); downloadStreams.Add(downloadStream); } SegmentDownloadManager segmentDownloadManager = new SegmentDownloadManager(new SegmentDownloadTaskCollection(segmentDownloadTasks)); segmentDownloadManager.Start(); segmentDownloadManager.Finish(true); AfterDownload(); long totalDownloads = downloadStreams.Sum(x => x.TotalDownloads); Assert.AreEqual(data.Length, totalDownloads); Assert.AreEqual(inputStream.ToArray().Take(data.Length).ToArray(), outputStream.ToArray().Take(data.Length).ToArray()); Assert.AreEqual(inputStream.ToArray(), outputStream.ToArray()); }
public void Download(byte[] data, int bufferSize, DownloadSegmentPositions[] segmentPositionInfos) { BeforeDownload(); DownloadStream inputStream = new DownloadStream(data); IList<ISegmentDownloadTask> segmentDownloadTasks = new List<ISegmentDownloadTask>(segmentPositionInfos.Length); IList<DownloadStream> downloadStreams = new List<DownloadStream>(segmentPositionInfos.Length); MemoryStream outputStream = new MemoryStream(); for (int i = 0; i < segmentPositionInfos.Length; i++) { DownloadSegmentPositions segmentPosition = segmentPositionInfos[i]; byte[] dataPart = data.Skip((int) segmentPosition.StartPosition).Take((int)(segmentPosition.EndPosition - segmentPosition.StartPosition + 1)).ToArray(); DownloadStream downloadStream = new DownloadStream(dataPart); segmentDownloadTasks.Add(CreateSegmentDownloadTask(bufferSize, CreateSegmentDownloader(downloadStream, segmentPosition), CreateSegmentWriter(outputStream))); downloadStreams.Add(downloadStream); } SegmentDownloadManager segmentDownloadManager = new SegmentDownloadManager(new SegmentDownloadTaskCollection(segmentDownloadTasks)); segmentDownloadManager.Start(); segmentDownloadManager.Finish(true); AfterDownload(); long totalDownloads = downloadStreams.Sum(x => x.TotalDownloads); Assert.AreEqual(data.Length, totalDownloads); Assert.AreEqual(inputStream.ToArray().Take(data.Length).ToArray(), outputStream.ToArray().Take(data.Length).ToArray()); Assert.AreEqual(inputStream.ToArray(), outputStream.ToArray()); }
public void Download(byte[] data, int bufferSize, int endPosition) { BeforeDownload(); DownloadStream inputStream = new DownloadStream(data); MemoryStream outputStream = new MemoryStream(); DownloadSegmentPositions downloadSegmentPositions = new DownloadSegmentPositions(0, endPosition); ISegmentDownloadTask task = CreateSegmentDownloadTask(bufferSize, CreateSegmentDownloader(inputStream, downloadSegmentPositions), CreateSegmentWriter(outputStream)); task.Download(); AfterDownload(); Assert.AreEqual(endPosition + 1, inputStream.TotalDownloads); Assert.AreEqual(inputStream.ToArray().Take(endPosition).ToArray(), outputStream.ToArray().Take(endPosition).ToArray()); }