Exemple #1
0
        public bool UpdateTaskState(DownloadSubTask task, byte state)
        {
            if (taskState_[task.Id] != state)
            {
                taskState_[task.Id] = state;
                if (state == 2)
                {
                    lock (writeFile_)
                    {
                        FileStream fsA = new FileStream(cacheFile_, FileMode.Open);
                        fsA.Seek(task.from, SeekOrigin.Begin);
                        fsA.Write(task.data, 0, task.data.Length);
                        fsA.Close();
                    }

                    finishCount++;
                    if (finishCount == split_.blockCount_)
                    {
                        lock (writeFile_)
                        {
                            FileInfo fi = new FileInfo(cacheFile_);
                            fi.MoveTo(LocalPath);
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #2
0
        public bool UpdateTaskState(DownloadSubTask task, byte state)
        {
            if (taskState_[task.Id] != state)
            {
                taskState_[task.Id] = state;
                if (state == 2)
                {
                    lock(writeFile_)
                    {
                        FileStream fsA = new FileStream(cacheFile_, FileMode.Open);
                        fsA.Seek(task.from, SeekOrigin.Begin);
                        fsA.Write(task.data, 0, task.data.Length);
                        fsA.Close();
                    }

                    finishCount++;
                    if (finishCount == split_.blockCount_)
                    {
                        lock (writeFile_)
                        {
                            FileInfo fi = new FileInfo(cacheFile_);
                            fi.MoveTo(LocalPath);
                        }
                        return true;
                    }
                }
            }
            return false;
        }
Exemple #3
0
 public override void Decode(byte[] buffer, int offset, int length)
 {
     task_ = new DownloadSubTask();
     ReadInt(buffer, ref offset);
     ReadInt(buffer, ref offset);
     task_.Id = ReadInt(buffer, ref offset);
     task_.from = ReadLong(buffer, ref offset);
     task_.to = ReadLong(buffer, ref offset);
     var len = ReadInt(buffer, ref offset);
     task_.RemotePath = ReadString(buffer, offset, len);
 }
Exemple #4
0
 public FileBlockTask(DownloadSubTask task)
 {
     task_ = task;
 }