Example #1
0
    void test_DownloadResource(ConfigResponse res)
    {
        configLoading.SetDescribe(Core.Data.stringManager.getString(9027));
        configLoading.ShowLoading(0);

        HttpDownloadTask task = new HttpDownloadTask(ThreadType.MainThread, TaskResponse.Igonre_Response);

        string url  = res.url;
        string fn   = "Config.zip";
        string path = DeviceInfo.PersistRootPath;

        Debug.Log("path=" + path);
        long size = res.size;

        task.AppendDownloadParam(url, fn, path, res.md5, size);

        task.DownloadStart += (string durl) => { ConsoleEx.DebugLog("Download starts and url = " + durl); };

        task.taskCompeleted += () => { ConsoleEx.DebugLog("Download success."); };
        task.afterCompleted += testDownloadResp;
        task.ErrorOccured   += (s, t) => { step = LoginStep.Download_ERROR; ConsoleEx.DebugLog("Download failure."); };

        task.Report += (cur, total) => {
            ConsoleEx.DebugLog("current Bytes = " + cur + ", total Bytes = " + total);
            configLoading.ShowLoading((float)cur / (float)total);
        };

        task.DispatchToRealHandler();
    }
Example #2
0
        public void AddTask(DownloadItem downloadItem)
        {
            IDownloadTask downloadTask = new HttpDownloadTask(downloadItem);

            downloadTask.ReportProgress += new Action <DownloadItem>(downloadTask_ReportProgress);
            downloadTaskList.Add(downloadTask);

            GetDownloadTaskState.Invoke(DownloadList);
        }
Example #3
0
    void test_DownloadResource(string md5)
    {
        HttpDownloadTask task = new HttpDownloadTask(ThreadType.MainThread, TaskResponse.Igonre_Response);

        string url  = @"http://192.168.1.110:10000/ball/www/image/60101-3.jpg";
        string fn   = "60101-3.jpg";
        string path = Core.Data.guideManger.getBasePath();
        long   size = 103234;

        task.AppendDownloadParam(url, fn, path, md5, size);

        task.DownloadStart += (string durl) => { ConsoleEx.DebugLog("Download starts and url = " + durl); };

        task.taskCompeleted += () => { ConsoleEx.DebugLog("Download success."); };
        task.afterCompleted += testDownloadResp;
        task.ErrorOccured   += (s, t) => { ConsoleEx.DebugLog("Download failure."); };

        task.Report += (cur, total) => { ConsoleEx.DebugLog("current Bytes = " + cur + ", total Bytes = " + total); };

        task.DispatchToRealHandler();
    }
Example #4
0
    void test_DownloadResource()
    {
        HttpDownloadTask task = new HttpDownloadTask(ThreadType.MainThread, TaskResponse.Igonre_Response);
        string           url  = @"http://zhangyuntao.com.cn/phpMyAdmin-4.1.0-all-languages.zip";
        string           fn   = "license.zip";
        string           path = DeviceInfo.PersistRootPath;
        string           md5  = "test md5";
        long             size = 103234;

        task.AppendDownloadParam(url, fn, path, md5, size);

        task.DownloadStart += (string durl) => { ConsoleEx.DebugLog("Download starts and url = " + durl); };

        task.taskCompeleted += () => { ConsoleEx.DebugLog("Download success."); };
        task.afterCompleted += testDownloadResp;
        task.ErrorOccured   += (s, t) => { ConsoleEx.DebugLog("Download failure."); };

        task.Report += (cur, total) => { ConsoleEx.DebugLog("current Bytes = " + cur + ", total Bytes = " + total); };

        task.DispatchToRealHandler();
    }
Example #5
0
    public bool doDownload(HttpDownloadTask task)
    {
        Utils.Assert(task == null, "Download Resources Task in Null.");

        HttpDownloadRequest DownReq = task.request as HttpDownloadRequest;

        string urlDown = DownReq.url, whereToBeSaved = DownReq.whereToBeSaved;

        bool isExceOcurr = false;

        ConsoleEx.Write("Http Download is going out : => " + urlDown);
        task.handleStart();

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlDown);

        request.Method = "GET";
        // Set the 'Timeout' property in Milliseconds.
        request.Timeout = TIME_OUT;
        // execute the request
        // This request will throw a WebException if it reaches the timeout limit before it is able to fetch the resource.
        Stream          resStream = null;
        HttpWebResponse response  = null;
        FileStream      fs        = null;

        try {
            response = (HttpWebResponse)request.GetResponse();

            // we will read data via the response stream
            resStream = response.GetResponseStream();
            // we will open the file stream whatever
            fs = File.Create(whereToBeSaved);

            int  count      = 0;
            long curPrgress = 0;

            do
            {
                // fill the buffer with data
                count       = resStream.Read(buf, 0, buf.Length);
                curPrgress += count;
                task.handleReport(curPrgress);
                // make sure we read some data
                if (count > 0)
                {
                    fs.Write(buf, 0, count);
                }
            } while (count > 0);             // any more data to read?
        } catch (WebException ex) {
            isExceOcurr = true;
            ConsoleEx.DebugLog("###### WebException = " + ex.ToString());
        } catch (System.Exception ex) {
            isExceOcurr = true;
            ConsoleEx.DebugLog("###### Exception = " + ex.ToString());
        } finally {
            if (resStream != null)
            {
                resStream.Close();     resStream = null;
            }
            if (response != null)
            {
                response.Close(); response = null;
            }
            if (request != null)
            {
                request.Abort(); request = null;
            }
            if (fs != null)
            {
                fs.Flush(); fs.Close(); fs = null;
            }

            System.GC.Collect();
        }


        return(isExceOcurr);
    }