Exemple #1
0
 void ResponseCallback(IAsyncResult ar)
 {
     try
     {
         HttpWebRequest req = ar.AsyncState as HttpWebRequest;
         if (req == null)
         {
             return;
         }
         HttpWebResponse response = req.EndGetResponse(ar) as HttpWebResponse;
         if (response.StatusCode != HttpStatusCode.OK)
         {
             response.Close();
             IsDownAsseting = false;
             return;
         }
         Debuger.Log(path + "/" + assetName);
         WebReqState st = new WebReqState(path + "/" + assetName);
         st.WebResponse = response;
         Stream responseStream = response.GetResponseStream();
         st.OrginalStream = responseStream;
         responseStream.BeginRead(st.Buffer, 0, WebReqState.BufferSize, new AsyncCallback(ReadDataCallback), st);
     }
     catch (Exception e)
     {
         Debuger.Log(e);
         Debuger.LogError("ResponseCallback");
         Init();
     }
 }
Exemple #2
0
    void ResponseCallback(IAsyncResult ar)
    {
        HttpWebRequest req = ar.AsyncState as HttpWebRequest;

        if (req == null)
        {
            Debug.Log("Request equal to null");
            return;
        }
        HttpWebResponse response = req.EndGetResponse(ar) as HttpWebResponse;

        if (response.StatusCode != HttpStatusCode.OK)
        {
            Debug.Log("Response not OK");
            response.Close();
            return;
        }

        WebReqState st = new WebReqState(GetLocalFilePath());

        st.WebResponse = response;
        Stream responseStream = response.GetResponseStream();

        st.OrginalStream = responseStream;
        responseStream.BeginRead(st.Buffer, 0, WebReqState.BufferSize, new AsyncCallback(ReadDataCallback), st);
    }
Exemple #3
0
        void ReadDataCallback(IAsyncResult ar)
        {
            WebReqState rs   = ar.AsyncState as WebReqState;
            int         read = rs.OrginalStream.EndRead(ar);

            if (bCancelDownLoad)
            {
                rs.Close();
                return;
            }

            if (read > 0)
            {
                rs.fs.Write(rs.Buffer, 0, read);
                rs.fs.Flush();
                Process = (float)rs.fs.Length / rs.WebResponse.ContentLength;
                if (ProcessFunc != null)
                {
                    ProcessFunc(Process);
                }
                rs.OrginalStream.BeginRead(rs.Buffer, 0, WebReqState.BufferSize, new AsyncCallback(ReadDataCallback), rs);
            }
            else
            {
                if (rs.fs.Length == rs.WebResponse.ContentLength && rs.WebResponse.ContentLength > 0)
                {
                    IsDownAsseting = false;
                    IsDownSucceed  = true;
                    if (Oncomplete != null)
                    {
                        Oncomplete();
                    }

                    rs.Close();

                    Debuger.Log(assetName + ":::: success");
                }
                else
                {
                    tryCount++;
                    if (tryCount >= 50)
                    {
                        Init();
                        Debuger.Log("DownLoad Failed! Read Length:" + rs.fs.Length + " TotalLen:" + rs.WebResponse.ContentLength);

                        rs.Close();
                    }
                    System.Threading.Thread.Sleep(1);
                }
            }
        }
Exemple #4
0
    void ReadDataCallback(IAsyncResult ar)
    {
        WebReqState rs   = ar.AsyncState as WebReqState;
        int         read = rs.OrginalStream.EndRead(ar);

        if (read > 0)
        {
            rs.fs.Write(rs.Buffer, 0, read);
            rs.fs.Flush();
            rs.OrginalStream.BeginRead(rs.Buffer, 0, WebReqState.BufferSize, new AsyncCallback(ReadDataCallback), rs);
        }
        else
        {
            rs.fs.Close();
            rs.OrginalStream.Close();
            rs.WebResponse.Close();
//			Debug.Log(assetName+":::: success");
            m_Done = true;
            if (downloadingInfo.ContainsKey(m_url))
            {
                downloadingInfo[m_url] = true;
            }
        }
    }