/// <summary> /// Start method of the class. This method allows the thread to start the procedure of download of /// a remote resource in a separate thread. It initialize all attributes related to the resource. /// </summary> /// <param name="RID">Identificator of the resource</param> /// <param name="begin">Start point from the beginning of the file to begin download</param> /// <param name="length">>Total length in bytes of the resource</param> /// <param name="peerQueue">PeerQueue of peers containing the resource with a score associated to each peer</param> /// <param name="s">Stream where the resource is written</param> public void Start(string RID, int begin, long length, Dictionary <string, float> peerQueue, Stream s) { this.worker = new Thread(() => doWork()); this.RID = RID; this.peerQueue = new PeerQueue(peerQueue); log.Info("Starting download of Resource identified by " + RID + " from " + begin + " with a len of " + length); this.maxNumber = System.Convert.ToInt32( Math.Floor((double)(length / (this.chunkLength * 1024))) ); this.maxNumber -= begin; this.writer = s; this.buffer = new Dictionary <int, BufferChunk>(); for (int i = begin; i < this.maxNumber; i++) { this.buffer[i] = new BufferChunk(); } this.nextChunkToWrite = begin; this.started = true; this.worker.Start(); }
/// <summary> /// Start method of the class. This method allows the thread to start the procedure of download of /// a remote resource in a separate thread. It initialize all attributes related to the resource. /// </summary> /// <param name="RID">Identificator of the resource</param> /// <param name="begin">Start point from the beginning of the file to begin download</param> /// <param name="length">>Total length in bytes of the resource</param> /// <param name="peerQueue">PeerQueue of peers containing the resource with a score associated to each peer</param> /// <param name="s">Stream where the resource is written</param> public void Start(string RID, int begin, long length, Dictionary<string, float> peerQueue, Stream s) { this.worker = new Thread(() => doWork()); this.RID = RID; this.peerQueue = new PeerQueue(peerQueue); log.Info("Starting download of Resource identified by " + RID + " from " + begin + " with a len of " + length); this.maxNumber = System.Convert.ToInt32( Math.Floor((double)(length / (this.chunkLength * 1024))) ); this.maxNumber -= begin; this.writer = s; this.buffer = new Dictionary<int, BufferChunk>(); for (int i = begin; i < this.maxNumber; i++) { this.buffer[i] = new BufferChunk(); } this.nextChunkToWrite = begin; this.started = true; this.worker.Start(); }