public void handleStart()
    {
        HttpDownloadRequest mRequest = this.request as HttpDownloadRequest;

        if (threadType == ThreadType.BackGround)
        {
            if (mRequest != null && DownloadStart != null)
            {
                DownloadStart(mRequest.url);
            }
        }
        else
        {
            AsyncTask.QueueOnMainThread(() => { if (mRequest != null && DownloadStart != null)
                                                {
                                                    DownloadStart(mRequest.url);
                                                }
                                        });
        }
    }
示例#2
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);
    }
示例#3
0
 public void EnqueueRequest(HttpDownloadRequest request)
 {
     _requestQueue.Enqueue(request);
 }
示例#4
0
 public static bool FileVerifyHttpDownload(HttpDownloadRequest request, HttpDownloadResponse response) => FileVerify(response.FileInfo, request.Size, request.Sha1);