public void Load(HttpDownload.LoadThread loadThread)
        {
            _isComplete = false;
            if (IsComplete)
            {
                downloadFile.OnLoadBlock(this);
                return;
            }

            downloadFile.state = DownloadFile.StateType.Loading;

            MLog.LogFormat("", "HttpDownloadFileBlock Load downloadFile.state={0}", downloadFile.state);

            this.loadThread = loadThread;



            Byte[] buffer   = new Byte[1024];
            int    readSize = 0;

            httpRequest = WebRequest.Create(downloadFile.url) as HttpWebRequest;
            if (end > 0)
            {
                httpRequest.AddRange((int)(begin + loadedSize), (int)end);
            }

            httpResponse = httpRequest.GetResponse() as HttpWebResponse;
            httpStream   = httpResponse.GetResponseStream();

            outStream = new FileStream(tmpPath, loadedSize == 0 ? FileMode.Create : FileMode.Append);

            while (true)
            {
                readSize = httpStream.Read(buffer, 0, buffer.Length);
                if (readSize <= 0)
                {
                    break;
                }
                outStream.Write(buffer, 0, readSize);
                loadedSize += readSize;

                lock (downloadFile)
                {
                    downloadFile.loadedSize += readSize;
                }
            }

            Abort();

            if (end <= 0)
            {
                lock (downloadFile)
                {
                    downloadFile.size = downloadFile.loadedSize;
                }
            }
            IsComplete      = true;
            this.loadThread = null;
            downloadFile.OnLoadBlock(this);
        }
예제 #2
0
            private void Run()
            {
                while (!isExit)
                {
                    MLog.LogFormat("[LoadThread]", "Run Doing Before {0}, httpDownload.waitBlockList.Count={1}", this, httpDownload.waitBlockList.Count);

                    lock (httpDownload.waitBlockList)
                    {
                        if (httpDownload.waitBlockList.Count <= 0)
                        {
                            break;
                        }

                        block = httpDownload.waitBlockList[0];
                        httpDownload.waitBlockList.RemoveAt(0);
                    }

                    block.Load(this);
                    block = null;

                    MLog.LogFormat("[LoadThread]", "Run Doing After {0}, httpDownload.waitBlockList.Count={1}, block={2}", this, httpDownload.waitBlockList.Count, block);
                }

                state  = StateType.End;
                thread = null;

                MLog.LogFormat("[LoadThread]", "Run End {0}", this);
            }
예제 #3
0
        private void Complete()
        {
            state = StateType.End;
            MLog.LogFormat("", "DownloadFile Complete {0}", this);

            if (completeCallback != null)
            {
                HttpDownload.AddLoaded(this);
            }
        }
예제 #4
0
        private void CheckLoadSizeThreadStart()
        {
            MLog.LogFormat("[Main]", "HttpDownload.CheckLoadSizeThreadStart waitFileList.Count={0}, loadSizeThread.state={1}", waitFileList.Count, loadSizeThread.state);

            if (waitFileList.Count == 0)
            {
                return;
            }

            if (loadSizeThread.state != LoadSizeThread.StateType.Runing)
            {
                loadSizeThread.Start();
            }
        }
예제 #5
0
            public void Start()
            {
                MLog.LogFormat("[LoadSizeThread]", "Start Before {0}", this);

                if (state == StateType.Runing)
                {
                    return;
                }

                Exit();

                thread = new Thread(new ThreadStart(Run));
                state  = StateType.Runing;
                isExit = false;
                thread.Start();

                MLog.LogFormat("[LoadSizeThread]", "Start After {0}", this);
            }
예제 #6
0
        private void CheckLoadThreadStart()
        {
            MLog.LogFormat("[Main]", "HttpDownload.CheckLoadThreadStart waitBlockList.Count={0}", waitBlockList.Count);


            if (waitBlockList.Count == 0)
            {
                return;
            }

            for (int i = 0; i < loadThreadList.Count; i++)
            {
                if (loadThreadList[i].state != LoadThread.StateType.Runing)
                {
                    loadThreadList[i].Start();
                }
            }
        }
예제 #7
0
        public void RemoveFile(DownloadFile file)
        {
            MLog.LogFormat("[Main]", "HttpDownload.RemoveFile Before {0}, waitFileList.Count={1}, loadSizeFileList.Count={2}", file, waitFileList.Count, loadSizeFileList.Count);
            if (loadSizeThread != null && loadSizeThread.file == file)
            {
                loadSizeThread.Exit();
            }

            if (waitFileList.Contains(file))
            {
                waitFileList.Remove(file);
            }


            if (loadSizeFileList.Contains(file))
            {
                loadSizeFileList.Remove(file);
            }


            for (int i = 0; i < file.blockList.Count; i++)
            {
                if (file.blockList[i].loadThread != null)
                {
                    file.blockList[i].loadThread.Exit();
                }

                if (waitBlockList.Contains(file.blockList[i]))
                {
                    waitBlockList.Remove(file.blockList[i]);
                }
            }

            MLog.LogFormat("[Main]", "HttpDownload.RemoveFile RemoveComplete {0}, waitFileList.Count={1}, loadSizeFileList.Count={2}", file, waitFileList.Count, loadSizeFileList.Count);


            CheckLoadSizeThreadStart();
            CheckLoadThreadStart();

            MLog.LogFormat("[Main]", "HttpDownload.RemoveFile End {0}, waitFileList.Count={1}, loadSizeFileList.Count={2}", file, waitFileList.Count, loadSizeFileList.Count);
        }
예제 #8
0
            public void Exit()
            {
                MLog.LogFormat("[LoadSizeThread]", "Exit Before {0}", this);

                if (thread != null)
                {
                    thread.Abort();
                    thread = null;
                }

                if (file != null)
                {
                    file.AbortSizeRequest();
                }

                file   = null;
                state  = StateType.End;
                isExit = true;

                MLog.LogFormat("[LoadSizeThread]", "Exit After {0}", this);
            }
예제 #9
0
            public void Exit()
            {
                MLog.LogFormat("[LoadThread]", "Exit Before {0}", this);

                if (block != null)
                {
                    block.Abort();
                    block = null;
                }

                if (thread != null)
                {
                    thread.Abort();
                    thread = null;
                }


                state  = StateType.End;
                isExit = true;

                MLog.LogFormat("[LoadThread]", "Exit After {0}", this);
            }
예제 #10
0
            private void Run()
            {
                while (!isExit)
                {
                    MLog.LogFormat("[LoadSizeThread]", "Run Doing Before {0}, httpDownload.waitFileList.Count={1}, httpDownload.loadSizeFileList.Count={2}", this, httpDownload.waitFileList.Count, httpDownload.loadSizeFileList.Count);

                    lock (httpDownload.waitFileList)
                    {
                        if (httpDownload.waitFileList.Count <= 0)
                        {
                            break;
                        }

                        file = httpDownload.waitFileList[0];
                        httpDownload.waitFileList.RemoveAt(0);
                    }

                    if (file.size <= 0)
                    {
                        file.GetSize();
                    }

                    file.Cut();

                    lock (httpDownload.loadSizeFileList)
                    {
                        httpDownload.loadSizeFileList.Add(file);
                    }
                    file = null;

                    MLog.LogFormat("[LoadSizeThread]", "Run Doing After {0}, httpDownload.waitFileList.Count={1}, httpDownload.loadSizeFileList.Count={2}", this, httpDownload.waitFileList.Count, httpDownload.loadSizeFileList.Count);
                }

                state  = StateType.End;
                thread = null;

                MLog.LogFormat("[LoadSizeThread]", "Run End {0}", this);
            }
예제 #11
0
 public void AddFile(DownloadFile file)
 {
     MLog.LogFormat("[Main]", "HttpDownload.AddFile {0}", file);
     waitFileList.Add(file);
     CheckLoadSizeThreadStart();
 }