コード例 #1
0
 public SDownloadEventResult(DownloadEventType eventType, SDownloadFileResult fileResult, SDownloadModuleConfig info, string error)
 {
     Error      = error;
     Info       = info;
     FileResult = fileResult;
     EventType  = eventType;
 }
コード例 #2
0
ファイル: HttpWeb.cs プロジェクト: MaYiMaMa/TD3_ProBase
        private void DownloadFileCallback(object obj)
        {
            _handler          = new HttpDownloadFileHandler(_currParams.download_url, _currParams.localPath_url);
            _handler.Progress = result => _fileResult = result;
            _request          = WebRequest.Create(_currParams.download_url) as HttpWebRequest;
            _request.Timeout  = _currParams.timeout;
            _request.AddRange(_handler.DownloadedLength);
            _request.Proxy = WebRequest.DefaultWebProxy;
            try
            {
                _response = _request.GetResponse() as HttpWebResponse;
                _handler.ReceiveContentLength((int)_response.ContentLength);

                //byte[] buffer = new byte[1024*200];
                byte[] buffer = new byte[1024];
                using (Stream stream = _response.GetResponseStream())
                {
                    int dataLength = stream.Read(buffer, 0, buffer.Length);
                    while (dataLength > 0)
                    {
                        if (isStop || _handler.ReceiveData(buffer, dataLength) == false)
                        {
                            return;
                        }
                        dataLength = stream.Read(buffer, 0, buffer.Length);
                    }
                }
                _handler.Dispose();
                _EventQueue.Enqueue(new SWebDownloadEvent(DownloadEventType.OneComplete, (int)_response.StatusCode));
            }
            catch (WebException e)
            {
                //Debug.LogError(e.Message);
                int code = 0;
                _response = e.Response as HttpWebResponse;
                if (_response != null)
                {
                    code = (int)_response.StatusCode;
                }
                _handler.Dispose();
                _EventQueue.Enqueue(new SWebDownloadEvent(DownloadEventType.OneComplete, code));
            }
            finally
            {
                if (_response != null)
                {
                    _response.Close();
                }
                _request.Abort();
                _fileResult = new SDownloadFileResult();
            }
        }
コード例 #3
0
ファイル: HttpWeb.cs プロジェクト: MaYiMaMa/TD3_ProBase
 public void DownloadFile(string download_url, string localPath_url, int timeout, Action <SDownloadFileResult> progress, Action <int> complete)
 {
     _EventQueue.Clear();
     _currParams = new SWebDownloadParams();
     _currParams.download_url  = download_url;
     _currParams.localPath_url = localPath_url;
     _currParams.timeout       = timeout;
     _currParams.OnProgress    = progress;
     _currParams.OnComplete    = complete;
     _fileResult = new SDownloadFileResult();
     ThreadPool.SetMaxThreads(5, 5);
     ThreadPool.QueueUserWorkItem(new WaitCallback(DownloadFileCallback), null);
 }
コード例 #4
0
        public HttpDownloadFileHandler(string download_url, string localPath_url)
        {
            _download_url       = download_url;
            _localPath_url      = localPath_url;
            _downloadFileResult = new SDownloadFileResult();
            string dir = Path.GetDirectoryName(localPath_url);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            _fileStream      = new FileStream(localPath_url + ".tmp", FileMode.Append, FileAccess.Write);
            DownloadedLength = (int)_fileStream.Length;
            ContentLength    = 0;
            _downloadFileResult.downloadedLength    = DownloadedLength;
            _downloadFileResult.downloadedLengthStr = Util.HumanReadableFilesize(DownloadedLength);
        }
コード例 #5
0
 private void OnProgress(SDownloadFileResult result)
 {
     Progress(new SDownloadEventResult(DownloadEventType.Progress, result));
 }
コード例 #6
0
ファイル: AppStart.cs プロジェクト: luodongfu/TD3_ProBase
 private void DownloadProgress(string moduleName, SDownloadFileResult result)
 {
 }
コード例 #7
0
 public SDownloadEventResult(DownloadEventType eventType, SDownloadFileResult fileResult)
     : this(eventType, fileResult, new SDownloadModuleConfig(), string.Empty)
 {
 }