Example #1
0
    private void WriteCallBack(IAsyncResult asyncResult)
    {
        this.myRequestState = (Downloader.RequestState)asyncResult.get_AsyncState();
        Stream streamResponse = this.myRequestState.streamResponse;

        this.fs.EndWrite(asyncResult);
        int read = this.myRequestState.read;

        this.localFileSize += read;
        this.alreadyread   += read;
        Loom.Current.QueueOnMainThread(delegate
        {
            this.SetDetails();
        });
        if (!this.pause)
        {
            this.Result = streamResponse.BeginRead(this.myRequestState.BufferRead, 0, 524288, new AsyncCallback(this.ReadCallBack), this.myRequestState);
        }
        else
        {
            this.ManualHandle = true;
            this.myRequestState.Reset();
            this.ManualHandle = false;
            this.fs.Dispose();
        }
    }
Example #2
0
 private void RespCallback(IAsyncResult asynchronousResult)
 {
     try
     {
         this.myRequestState                = (Downloader.RequestState)asynchronousResult.get_AsyncState();
         this.myRequestState.response       = (HttpWebResponse)this.myRequestState.request.EndGetResponse(asynchronousResult);
         this.myRequestState.streamResponse = this.myRequestState.response.GetResponseStream();
         Debug.Log("BeginRead:");
         this.Result = this.myRequestState.streamResponse.BeginRead(this.myRequestState.BufferRead, 0, 524288, new AsyncCallback(this.ReadCallBack), this.myRequestState);
     }
     catch (Exception ex)
     {
         TimerHeap.DelTimer(this.timeOutTimer);
         if (this.Handle != null)
         {
             this.Handle.Unregister(this.Result.get_AsyncWaitHandle());
             this.Handle = null;
         }
         if (!this.ManualHandle)
         {
             Debug.LogError("RespCallback WebException raised!");
             Debug.LogError(ex.ToString());
             Loom.Current.QueueOnMainThread(delegate
             {
                 this.ExceptionHandle();
             });
         }
     }
 }
Example #3
0
 private void GetSizeRes(IAsyncResult getSizeRes)
 {
     TimerHeap.DelTimer(this.getSizeTimer);
     try
     {
         this.myRequestState          = (Downloader.RequestState)getSizeRes.get_AsyncState();
         this.myRequestState.response = (HttpWebResponse)this.myRequestState.request.EndGetResponse(getSizeRes);
         this.downloadFileSize        = this.myRequestState.response.get_ContentLength();
         Debug.Log(string.Concat(new object[]
         {
             "GetDownloadFileSize : ",
             this.downloadFileSize,
             "  _URL  : ",
             this.URL
         }));
         this.ManualHandle = true;
         this.myRequestState.Reset();
         this.ManualHandle = false;
         Loom.Current.QueueOnMainThread(delegate
         {
             this.StartDownload();
         });
     }
     catch (Exception ex)
     {
         if (this.Handle != null)
         {
             this.Handle.Unregister(this.Result.get_AsyncWaitHandle());
             this.Handle = null;
         }
         Debug.LogErrorFormat("GetSizeRes WebException raised: {0}", new object[]
         {
             ex.ToString()
         });
         if (!this.ManualHandle)
         {
             Loom.Current.QueueOnMainThread(delegate
             {
                 this.ExceptionHandle();
             });
         }
     }
 }
Example #4
0
    private void ReadCallBack(IAsyncResult asyncResult)
    {
        this.myRequestState = (Downloader.RequestState)asyncResult.get_AsyncState();
        Stream streamResponse = this.myRequestState.streamResponse;
        int    num            = streamResponse.EndRead(asyncResult);

        this.myRequestState.read = num;
        try
        {
            if (num > 0)
            {
                this.Result = this.fs.BeginWrite(this.myRequestState.BufferRead, 0, num, new AsyncCallback(this.WriteCallBack), this.myRequestState);
                return;
            }
        }
        catch (Exception ex)
        {
            TimerHeap.DelTimer(this.timeOutTimer);
            if (this.Handle != null)
            {
                this.Handle.Unregister(this.Result.get_AsyncWaitHandle());
                this.Handle = null;
            }
            if (this.ManualHandle)
            {
                return;
            }
            Debug.LogError("ReadCallBack Exception raised!");
            Debug.LogError(ex.ToString());
            if (this.ManualHandle)
            {
                return;
            }
            Loom.Current.QueueOnMainThread(delegate
            {
                this.ExceptionHandle();
            });
            return;
        }
        string md5FilePath = Downloader.GetMd5FilePath(this.fileFullName);

        FileHelper.DeleteIfExist(md5FilePath);
        TimerHeap.DelTimer(this.timeOutTimer);
        long length = this.fs.get_Length();

        this.fs.Dispose();
        if (this.Handle != null)
        {
            this.Handle.Unregister(this.Result.get_AsyncWaitHandle());
        }
        this.myRequestState.response.Close();
        Debug.LogFormat("localFileLen: {0} localFileSize: {1} downloadFileSize: {2}", new object[]
        {
            length,
            this.localFileSize,
            this.downloadFileSize
        });
        if ((long)this.localFileSize == this.downloadFileSize && length == this.downloadFileSize)
        {
            if (++this.downloadFileIndex < this.urls.get_Count())
            {
                Loom.Current.QueueOnMainThread(delegate
                {
                    this.SetDetails();
                });
                this.fs.Close();
                this.retryTime = 0;
                Loom.Current.QueueOnMainThread(delegate
                {
                    this.Download(this.urls.get_Item(this.downloadFileIndex), this.localPaths.get_Item(this.downloadFileIndex));
                });
            }
            else
            {
                this.fs.Close();
                this.allIsFinish = true;
                Loom.Current.QueueOnMainThread(delegate
                {
                    this.DoFinished();
                });
            }
        }
        else
        {
            this.fs.Dispose();
            File.Delete(this.LocalPath);
            this.retryTime = 0;
            Loom.Current.QueueOnMainThread(delegate
            {
                this.Download(this.urls.get_Item(this.downloadFileIndex), this.localPaths.get_Item(this.downloadFileIndex));
            });
        }
    }