public void Open()
 {
     try
     {
         this.RequestFileStream = new FileStream(this.FilePath, FileMode.Open, FileAccess.Read);
         this.Request           = (HttpWebRequest)WebRequest.Create(AssetStoreClient.APIUri(this.URI, this.m_extraParams));
         this.Request.AllowWriteStreamBuffering = false;
         this.Request.Timeout = 36000000;
         this.Request.Headers.Set("X-Unity-Session", AssetStoreClient.ActiveOrUnauthSessionID);
         this.Request.KeepAlive     = false;
         this.Request.ContentLength = this.RequestFileStream.Length;
         this.Request.Method        = "PUT";
         this.BytesToSend           = this.RequestFileStream.Length;
         this.BytesSent             = 0L;
         this.RequestStream         = this.Request.GetRequestStream();
         if (this.Buffer == null)
         {
             this.Buffer = new byte[32768];
         }
     }
     catch (Exception ex)
     {
         AssetStoreResponse job = AssetStoreClient.parseAssetStoreResponse(null, null, ex, null);
         this.RequestDoneCallback(job);
         this.Close();
         throw ex;
     }
 }
 public static void AbortLargeFilesUpload()
 {
     if (AssetStoreClient.s_PendingLargeFiles.Count == 0)
     {
         return;
     }
     AssetStoreClient.s_PendingLargeFiles.RemoveAll(delegate(AssetStoreClient.LargeFilePending assetUpload)
     {
         if (assetUpload == null)
         {
             return(true);
         }
         AssetStoreResponse job = AssetStoreClient.parseAssetStoreResponse(null, null, null, null);
         job.HttpStatusCode     = -2;
         if (assetUpload.RequestDoneCallback != null)
         {
             assetUpload.RequestDoneCallback(job);
         }
         assetUpload.Close();
         return(true);
     });
 }
        public static void Update()
        {
            List <AssetStoreClient.Pending> obj = AssetStoreClient.pending;

            lock (obj)
            {
                AssetStoreClient.pending.RemoveAll(delegate(AssetStoreClient.Pending p)
                {
                    if (p.conn == null)
                    {
                        if (p.queueDelegate == null)
                        {
                            DebugUtils.LogWarning("Invalid pending state while communicating with asset store");
                            return(true);
                        }
                        if (!p.queueDelegate() && p.conn == null)
                        {
                            return(false);
                        }
                        p.queueDelegate = null;
                    }
                    if (!p.conn.IsBusy)
                    {
                        if (p.ex == null && p.data == null)
                        {
                            if (p.binData == null)
                            {
                                goto IL_19F;
                            }
                        }
                        try
                        {
                            AssetStoreResponse job = AssetStoreClient.parseAssetStoreResponse(p.data, p.binData, p.ex, (p.conn != null) ? p.conn.ResponseHeaders : null);
                            if (AssetStoreManager.sDbg)
                            {
                                DebugUtils.Log(string.Concat(new string[]
                                {
                                    "Pending done: ",
                                    Thread.CurrentThread.ManagedThreadId.ToString(),
                                    " ",
                                    p.id,
                                    " ",
                                    job.data ?? "<nodata>"
                                }));
                                if (job.HttpHeaders != null && job.HttpHeaders.Get("X-Unity-Reason") != null)
                                {
                                    DebugUtils.LogWarning("X-Unity-Reason: " + job.HttpHeaders.Get("X-Unity-Reason"));
                                }
                            }
                            p.callback(job);
                        }
                        catch (Exception ex)
                        {
                            DebugUtils.LogError("Uncaught exception in async net callback: " + ex.Message);
                            DebugUtils.LogError(ex.StackTrace);
                        }
                        AssetStoreClient.ReleaseClient(p.conn);
                        p.conn = null;
                        return(true);
                    }
                    IL_19F:
                    if (p.progressCallback != null && p.statsUpdated)
                    {
                        p.statsUpdated = false;
                        double pctUp   = (p.totalBytesToSend <= 0)
                            ? 0
                            : p.bytesSend / p.totalBytesToSend * 100.0;

                        double pctDown = (p.totalBytesToReceive <= 0)
                            ? 0
                            : p.bytesReceived / p.totalBytesToReceive * 100.0;

                        try
                        {
                            p.progressCallback(pctUp, pctDown);
                        }
                        catch (Exception ex2)
                        {
                            DebugUtils.LogError("Uncaught exception in async net progress callback: " + ex2.Message);
                        }
                    }
                    return(false);
                });
            }
            AssetStoreClient.UpdateLargeFilesUpload();
        }
        private static string UpdateLargeFilesUpload()
        {
            if (AssetStoreClient.s_UploadingLargeFile == null)
            {
                if (AssetStoreClient.s_PendingLargeFiles.Count == 0)
                {
                    return(null);
                }
                AssetStoreClient.s_UploadingLargeFile = AssetStoreClient.s_PendingLargeFiles[0];
                try
                {
                    AssetStoreClient.s_UploadingLargeFile.Open();
                }
                catch (Exception ex)
                {
                    DebugUtils.LogError("Unable to start uploading:" + AssetStoreClient.s_UploadingLargeFile.FilePath + " Reason: " + ex.Message);
                    AssetStoreClient.s_PendingLargeFiles.Remove(AssetStoreClient.s_UploadingLargeFile);
                    AssetStoreClient.s_PendingLargeFiles = null;
                    return(null);
                }
            }
            AssetStoreClient.LargeFilePending largeFilePending = AssetStoreClient.s_UploadingLargeFile;
            StreamReader streamReader = null;
            WebResponse  webResponse  = null;

            try
            {
                if (largeFilePending == null || largeFilePending.Request == null)
                {
                    return(null);
                }
                byte[] buffer = largeFilePending.Buffer;
                int    num    = 0;
                for (int i = 0; i < 2; i++)
                {
                    num = largeFilePending.RequestFileStream.Read(buffer, 0, buffer.Length);
                    if (num == 0)
                    {
                        break;
                    }
                    largeFilePending.RequestStream.Write(buffer, 0, num);
                    largeFilePending.BytesSent += (long)num;
                }
                if (num != 0)
                {
                    try
                    {
                        double num2  = (double)largeFilePending.BytesSent;
                        double num3  = (double)largeFilePending.BytesToSend;
                        double pctUp = num2 / num3 * 100.0;
                        if (largeFilePending.RequestProgressCallback != null)
                        {
                            largeFilePending.RequestProgressCallback(pctUp, 0.0);
                        }
                    }
                    catch (Exception ex2)
                    {
                        DebugUtils.LogWarning("Progress update error " + ex2.Message);
                    }
                    return(null);
                }
                AssetStoreClient.s_PendingLargeFiles.Remove(largeFilePending);
                AssetStoreClient.s_UploadingLargeFile = null;
                DebugUtils.Log("Finished Uploading: " + largeFilePending.Id);
                webResponse = largeFilePending.Request.GetResponse();
                Stream responseStream = webResponse.GetResponseStream();
                string text;
                try
                {
                    streamReader = new StreamReader(responseStream);
                    text         = streamReader.ReadToEnd();
                    streamReader.Close();
                }
                catch (Exception ex3)
                {
                    DebugUtils.LogError("StreamReader sr");
                    throw ex3;
                }
                AssetStoreResponse job = AssetStoreClient.parseAssetStoreResponse(text, null, null, webResponse.Headers);
                largeFilePending.Close();
                largeFilePending.RequestDoneCallback(job);
                return(text);
            }
            catch (Exception ex4)
            {
                DebugUtils.LogError("UploadingLarge Files Exception:" + ex4.Source);
                if (streamReader != null)
                {
                    streamReader.Close();
                }
                AssetStoreResponse job2 = AssetStoreClient.parseAssetStoreResponse(null, null, ex4, (webResponse == null) ? null : webResponse.Headers);
                largeFilePending.RequestDoneCallback(job2);
                largeFilePending.Close();
                AssetStoreClient.s_PendingLargeFiles.Remove(largeFilePending);
            }
            return(null);
        }